This seems to work!
|t1 t2 | t1_ WeakKeyAssociation new value: #('This is a test.'). t1 key: 'test'. t2 _ #() asOrderedCollection. t2 add: t1. ^ HTTPSocket httpPostDocument: 'www.blocks.scratchr.org/postPing.php' args: t2
This code assigns the string "This is a test." to the arg "test" and appears to successfully pass the data.
Offline
Greenatic wrote:
This seems to work!
Code:
|t1 t2 | t1_ WeakKeyAssociation new value: #('This is a test.'). t1 key: 'test'. t2 _ #() asOrderedCollection. t2 add: t1. ^ HTTPSocket httpPostDocument: 'www.blocks.scratchr.org/postPing.php' args: t2This code assigns the string "This is a test." to the arg "test" and appears to successfully pass the data.
Thank you SO much Greenatic. You are amazing. I modified the code a little for 4 arguments and it works. Now sparks and I can start making the upload feature, right sparks?
Offline
dreamod wrote:
Greenatic wrote:
This seems to work!
Code:
|t1 t2 | t1_ WeakKeyAssociation new value: #('This is a test.'). t1 key: 'test'. t2 _ #() asOrderedCollection. t2 add: t1. ^ HTTPSocket httpPostDocument: 'www.blocks.scratchr.org/postPing.php' args: t2This code assigns the string "This is a test." to the arg "test" and appears to successfully pass the data.
Thank you SO much Greenatic. You are amazing. I modified the code a little for 4 arguments and it works. Now sparks and I can start making the upload feature, right sparks?
No problem.
I specifically made t2 an OrderedCollection so that you could add as many args as you needed. If you're going to pass the same number of args each time, using a simple Array should work as well.
Offline
Sparks, I'm pretty much done with my part. Here is the result of POSTing the 'move () steps'
'Array ( [username] => guest [password] => guest [comment] => my comment [block] => ''From MIT Squeak 0.9.4 (June 1, 2003) [No updates present.] on 20 May 2012 at 7:14:17 pm''! !ScratchSpriteMorph methodsFor: ''motion ops'' stamp: ''jens 11/21/2008 09:49''! forward: distance "Move the object forward (i.e., the direction of its heading) by the given distance. Avoid infinite or NaN coordinates" | radians deltaP newPos newX newY | radians _ rotationDegrees degreesToRadians. deltaP _ ((radians cos)@(radians sin)) * distance. newPos _ self position + deltaP. newX _ newPos x. newY _ newPos y. newX isNaN ifTrue: [newX _ 0]. newX isInf ifTrue: [newX _ newX sign * 10000]. newY isNaN ifTrue: [newY _ 0]. newY isInf ifTrue: [newY _ newY sign * 10000]. self position: newX @ newY. self keepOnScreen. ! ! !CustomBlockSpecsDictionary class methodsFor: ''blocks''! getNewestBlock ^ #(''Sprites'' ''motion'' (''move $Number$ steps'' #- #forward:))! ! ) '
so 4 fields:
username
password
comment
block
username has the username.
password has the password.
comment has a comment describing what the block does.
block includes the contents of the block file.
Offline
Greenatic wrote:
dreamod wrote:
Greenatic wrote:
This seems to work!
Code:
|t1 t2 | t1_ WeakKeyAssociation new value: #('This is a test.'). t1 key: 'test'. t2 _ #() asOrderedCollection. t2 add: t1. ^ HTTPSocket httpPostDocument: 'www.blocks.scratchr.org/postPing.php' args: t2This code assigns the string "This is a test." to the arg "test" and appears to successfully pass the data.
Thank you SO much Greenatic. You are amazing. I modified the code a little for 4 arguments and it works. Now sparks and I can start making the upload feature, right sparks?
No problem.
I specifically made t2 an OrderedCollection so that you could add as many args as you needed. If you're going to pass the same number of args each time, using a simple Array should work as well.
Yeah, I understood that. I'm mentioning this in the credits.
"Credit to Greenatic for making uploading blocks possible and beta testing."
Offline
dreamod wrote:
Greenatic wrote:
dreamod wrote:
Thank you SO much Greenatic. You are amazing. I modified the code a little for 4 arguments and it works. Now sparks and I can start making the upload feature, right sparks?No problem.
I specifically made t2 an OrderedCollection so that you could add as many args as you needed. If you're going to pass the same number of args each time, using a simple Array should work as well.Yeah, I understood that. I'm mentioning this in the credits.
"Credit to Greenatic for making uploading blocks possible and beta testing."
Thanks! Now let's see what sparks can come up with.
Offline
Hey guys! I've been ill most of this week and am still pretty under the weather and I have a programming exam on Thursday but I'll do my best to add the upload feature for this!
Since we'll be storing block files on the site as SQL database entries, I'm really worried the whole SQL system is going to cause problems. I think that dreamod, your code should allow for error messages to be sent back from the site should a problem occur so you can display a message to the user. Here are some I can think of:
wrongUsernameOrPass
blockAlreadyExists
SQLConnectionError
For the last one, I suggest entering a loop that tries four or five more times, and if it fails then, display a message along the lines of "The block could not be uploaded to the library right now. Please try again later."
I'll have a stab at the upload code now
Offline
sparks wrote:
Hey guys! I've been ill most of this week and am still pretty under the weather and I have a programming exam on Thursday but I'll do my best to add the upload feature for this!
Since we'll be storing block files on the site as SQL database entries, I'm really worried the whole SQL system is going to cause problems. I think that dreamod, your code should allow for error messages to be sent back from the site should a problem occur so you can display a message to the user. Here are some I can think of:
wrongUsernameOrPass
blockAlreadyExists
SQLConnectionError
For the last one, I suggest entering a loop that tries four or five more times, and if it fails then, display a message along the lines of "The block could not be uploaded to the library right now. Please try again later."
I'll have a stab at the upload code now
How would we get blockAlreadyEsists? We would have to be able to read from the database. Instead, your code could return the errors itself, and our code could just read the echo.
Offline
@Greenatic: yes, the error names I suggested would be worked out by my code and echoed back to the smalltalk The code is nearly done. Oddly enough, the thing that took the longest was parsing spec, type and category from the block file
Offline
Well I finished the code. I get an SQLConnectionError error echoed every time I try it though!
<?php //remoteBlockUploader.php //date created: 20 May 2012 //function: // Allows Dreamod's block mod to connect and upload blocks include("connect.php"); //connect to the SQL database if(isset($_POST['username']) && isset ($_POST['password']) && isset($_POST['comment']) && isset($_POST['block'])){ //check to make sure that all required variables are being received. $usernameStatus = trim(file_get_contents("http://scratch.mit.edu/api/authenticateuser?username=" . $_POST['username'] . "&password=" . $_POST['password'])); //use the Scratch API to determine the username and password status. if($usernameStatus != 'false'){ //check to make sure that the username exists and the password is correct. $username = $_POST['username']; $comment = $_POST['comment']; ############################################################### //PARSE DATA FROM BLOCK FILE $code = $_POST['block']; $startPos = strpos($code, "getNewestBlock") + 22; //locate the spec within the block file $loopCount = 0; while ($loopCount < 4){ $startPos = strpos ($code, "'", $startPos + 1); $loopCount ++; } $category = substr($code, $startPos + 1, strlen($code) - $startPos + 1); $carryOnCode = $category; $endPos = strpos($category, "'"); $category = substr($category, 0, $endPos); #######category gained############## $loopCount = 0; while ($loopCount < 4){ $startPos = strpos ($code, "'", $startPos + 1); $loopCount ++; } $blockSpec = substr($code, $startPos + 1, strlen($code) - $startPos + 1); $carryOnCode = $blockSpec; $endPos = strpos($blockSpec, "'"); $blockSpec = substr($blockSpec, 0, $endPos); #####blockspec gained.################# $startPos = strpos($carryOnCode, "#") + 1; $type = substr($carryOnCode, $startPos, 1); ####type gained##################### ############################################################## //check whether the blockspec already exists $exists = false; //missing until found $result = mysql_query("SELECT * FROM `blocks`"); while($row = mysql_fetch_array($result)){ if($row['name'] == $blockSpec){ $exists = true; } } if($exists){ //if the block already exists echo "blockAlreadyExists"; //echo a "block already exists" message. } if(!$exists){ //if the block doesn't exists yet, add it. $query = "INSERT INTO `blocks` VALUES ('', '$blockSpec', '$type', 'category', '$code', '$username', '$username', '$comment', 'unapproved', '', 'Scratch')"; //insert block values for id, spec, type, category, code, creator, sharer, comment, status, application. } //due to the terrible SQL connection, the code now checks the database to see if the block has appeared. $exists = false; //missing until found $result = mysql_query("SELECT * FROM blocks"); while($row = mysql_fetch_array($result)){ if($row['name'] == $blockSpec){ $exists = true; } } if($exists){ //the block was added echo "success"; //echo a success message; } if(!$exists){ //if the block can't be found, echo "SQLConnectionError"; //echo an SQL connection error, } } if($usernameStatus == 'false'){ //there's a problem with the username or password! echo "wrongUsernameOrPass"; //echo a "wrong username or password" message. } } else{ //one or more required variables are missing from the action! echo "missingArgs"; //echo a "missing arguments" message. } ?>
Offline
sparks wrote:
Then again, I'm not getting an SQL error every time I try the button on the home page of the library site so maybe there's a problem with that code. I'll take a look tomorrow. It's 10:50 here and I'm ill
Hope you get better soon!
You might want to add that PHP upload page to the list of pages librarians can edit. (And where do the block files go, and should we be able to edit them manually?)
And maybe you should add the image uploader to the log book.
Last edited by Greenatic (2012-05-20 18:32:23)
Offline
sparks wrote:
Hey guys! I've been ill most of this week and am still pretty under the weather and I have a programming exam on Thursday but I'll do my best to add the upload feature for this!
Since we'll be storing block files on the site as SQL database entries, I'm really worried the whole SQL system is going to cause problems. I think that dreamod, your code should allow for error messages to be sent back from the site should a problem occur so you can display a message to the user. Here are some I can think of:
wrongUsernameOrPass
blockAlreadyExists
SQLConnectionError
For the last one, I suggest entering a loop that tries four or five more times, and if it fails then, display a message along the lines of "The block could not be uploaded to the library right now. Please try again later."
I'll have a stab at the upload code now
Get well soon. I'll fix that. how about if there is an error on uploading the block, the webpage displays: 'error: message informing what went wrong'. That way the block importer would read the 'error:' line and then display a dialog with the title error and the message after 'error: '.
Offline
@Dreamod: Okay, cool. I'll create more informative errors then
Although really, things like missingArgs are things that YOUR code should respond to (or never get by checking all variables are set to something)... you do have to send a comment, even if the comment is blank.
Another thing, what if say, a librarian or you are uploading a load of blocks from the library to the site? It's not really fair that we then get credited for the creation of that block, which is why my table has a "creator" and a "sharer" field. It might be nice if your upload process could give the option for a user to credit another with the block's creation.
@Greenatic:
"block files" will actually be entries to a database, so yes, a manual viewer and editor could be built. When someone wants to download a block file, the file will be created using the database information as and when it is needed, then deleted when the download is complete. I'll add the remoteBlockUploader.php to the Librarian editor list, and get the image uploader up again, although remember we're not uploading images of blocks now.
Offline
sparks wrote:
@Dreamod: Okay, cool. I'll create more informative errors then
Although really, things like missingArgs are things that YOUR code should respond to (or never get by checking all variables are set to something)... you do have to send a comment, even if the comment is blank.
Another thing, what if say, a librarian or you are uploading a load of blocks from the library to the site? It's not really fair that we then get credited for the creation of that block, which is why my table has a "creator" and a "sharer" field. It might be nice if your upload process could give the option for a user to credit another with the block's creation.
@Greenatic:
"block files" will actually be entries to a database, so yes, a manual viewer and editor could be built. When someone wants to download a block file, the file will be created using the database information as and when it is needed, then deleted when the download is complete. I'll add the remoteBlockUploader.php to the Librarian editor list, and get the image uploader up again, although remember we're not uploading images of blocks now.
I'll add a credit field. But concerning the current blocks I think we should upload them using a 'false ID'. Basically skip the password field until all the blocks are up. I'm not sure how we can do that safely, though.
Offline
dreamod wrote:
I'll add a credit field. But concerning the current blocks I think we should upload them using a 'false ID'. Basically skip the password field until all the blocks are up. I'm not sure how we can do that safely, though.
Hmm, yeah, that or we upload them with the creator's name in the comments. A Librarian will later be able to edit the creator field properly using some editor I'll build.
Offline
sparks wrote:
dreamod wrote:
I'll add a credit field. But concerning the current blocks I think we should upload them using a 'false ID'. Basically skip the password field until all the blocks are up. I'm not sure how we can do that safely, though.
Hmm, yeah, that or we upload them with the creator's name in the comments. A Librarian will later be able to edit the creator field properly using some editor I'll build.
ok. By the way, about the comment field. If it is left blank then it is treated as an empty string basically "". but it's still a field and included. I'm going to see if I can make block files of the library again. All I have to do is import them and upload them when that works.
Offline
sparks wrote:
Okay. I think I'll take away the comment field from the missingArgs message.
Still no idea why I always get the SQLConnectionError message
Keep it, you never know if someone will hack the block importer and remove a field.
Offline
sparks wrote:
Well in that case you should make sure that the comment field contains a space or something if it's empty. (That sentence makes little sense, I mean send a space instead of nothing to the uploader.)
Well, the comment field is automatically initialized to an empty string, and no space is required, because it's still a string object even if it's empty. (does that make any sense?) But if there are fields that have been hacked away then that's when the error would act.
Any ideas for the block uploading?
Offline
sparks wrote:
@Greenatic:
"block files" will actually be entries to a database, so yes, a manual viewer and editor could be built. When someone wants to download a block file, the file will be created using the database information as and when it is needed, then deleted when the download is complete. I'll add the remoteBlockUploader.php to the Librarian editor list, and get the image uploader up again, although remember we're not uploading images of blocks now.
Great! I was thinking about using the image uploader for improving the "Share a Block" page.
Offline
sparks wrote:
Well I finished the code. I get an SQLConnectionError error echoed every time I try it though!
Code:
<?php //remoteBlockUploader.php //date created: 20 May 2012 //function: // Allows Dreamod's block mod to connect and upload blocks include("connect.php"); //connect to the SQL database if(isset($_POST['username']) && isset ($_POST['password']) && isset($_POST['comment']) && isset($_POST['block'])){ //check to make sure that all required variables are being received. $usernameStatus = trim(file_get_contents("http://scratch.mit.edu/api/authenticateuser?username=" . $_POST['username'] . "&password=" . $_POST['password'])); //use the Scratch API to determine the username and password status. if($usernameStatus != 'false'){ //check to make sure that the username exists and the password is correct. $username = $_POST['username']; $comment = $_POST['comment']; ############################################################### //PARSE DATA FROM BLOCK FILE $code = $_POST['block']; $startPos = strpos($code, "getNewestBlock") + 22; //locate the spec within the block file $loopCount = 0; while ($loopCount < 4){ $startPos = strpos ($code, "'", $startPos + 1); $loopCount ++; } $category = substr($code, $startPos + 1, strlen($code) - $startPos + 1); $carryOnCode = $category; $endPos = strpos($category, "'"); $category = substr($category, 0, $endPos); #######category gained############## $loopCount = 0; while ($loopCount < 4){ $startPos = strpos ($code, "'", $startPos + 1); $loopCount ++; } $blockSpec = substr($code, $startPos + 1, strlen($code) - $startPos + 1); $carryOnCode = $blockSpec; $endPos = strpos($blockSpec, "'"); $blockSpec = substr($blockSpec, 0, $endPos); #####blockspec gained.################# $startPos = strpos($carryOnCode, "#") + 1; $type = substr($carryOnCode, $startPos, 1); ####type gained##################### ############################################################## //check whether the blockspec already exists $exists = false; //missing until found $result = mysql_query("SELECT * FROM `blocks`"); while($row = mysql_fetch_array($result)){ if($row['name'] == $blockSpec){ $exists = true; } } if($exists){ //if the block already exists echo "blockAlreadyExists"; //echo a "block already exists" message. } if(!$exists){ //if the block doesn't exists yet, add it. $query = "INSERT INTO `blocks` VALUES ('', '$blockSpec', '$type', 'category', '$code', '$username', '$username', '$comment', 'unapproved', '', 'Scratch')"; //insert block values for id, spec, type, category, code, creator, sharer, comment, status, application. } //due to the terrible SQL connection, the code now checks the database to see if the block has appeared. $exists = false; //missing until found $result = mysql_query("SELECT * FROM blocks"); while($row = mysql_fetch_array($result)){ if($row['name'] == $blockSpec){ $exists = true; } } if($exists){ //the block was added echo "success"; //echo a success message; } if(!$exists){ //if the block can't be found, echo "SQLConnectionError"; //echo an SQL connection error, } } if($usernameStatus == 'false'){ //there's a problem with the username or password! echo "wrongUsernameOrPass"; //echo a "wrong username or password" message. } } else{ //one or more required variables are missing from the action! echo "missingArgs"; //echo a "missing arguments" message. } ?>
Should I change the upload url to 'http://blocks.scratchr.org/remoteBlockUploader.php'?
Offline