This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#926 2012-01-26 13:55:31

sci_test
Scratcher
Registered: 2011-06-22
Posts: 100+

Re: Welcome to your local block library! - Website development thread.

About does have SQL in it.  tongue


[signature removed - please be respectful]
Last edited by scimonster (1970-01-01 00:00:00)

Offline

 

#927 2012-01-26 14:30:48

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Welcome to your local block library! - Website development thread.

I actually currently unable to log in to the block library FTP... anyway, I have decided to share my code so other people can try and debug and work out what I've done wrong with the MySQL that could be causing it to only connect sometimes.

about.php

Code:

<?php 
session_start();
$title = 'Block Library | About'; 
include("header.php");
?>

    <div id="main" class="clearfix">
    
      <div id="content">
        <div id="content-inner" class="inner column center">

          
                      <div id="content-header">

              <div class="breadcrumb"><a href="/">About</a></div>
                              <h1 class="title">About</h1>

              
              
              
               

              
            </div> <!-- /#content-header -->
          
          <div id="content-area">
            <div class="node node node-type-page" id="node-6">
  <div class="node-inner">

    
    
    
    <div class="content">
      <table cellspacing="1" cellpadding="1" border="0" align="left" style="float: none; background-image: none; vertical-align: top; width: 100%; border-collapse: separate;">
<tbody style="vertical-align: top;">
<tr>
<td style="width: 70%;">
<?php
if(isset($_GET['librarian'])){
include("connect.php");
            
            $result = mysql_query("SELECT * FROM aboutme
                WHERE name='$_GET[librarian]'");
                while($row = mysql_fetch_array($result))
                {
                    $aboutme = $row['text'];
                }?>
<p><a href = 'about.php'>Back</a></p>
<h2><?php 
echo $_GET['librarian'];
echo "</h2>";
 echo $aboutme;
}?>
<?php if(!isset($_GET['librarian'])){ ?>
<p>Welcome to your block library! One of the most important and beloved features of Scratch are the blocks, and a great deal of time and effort has gone into making the blocks you see. When building Scratch, the team specifically designed the code so that it would be as easy as possible to add new blocks, and many people have done just that! This resource aims to bring together a collection of useful block code for experimenting Scratchers to try out and learn from, embracing the <i><font color = 'blue'>program</font></i> and <i><font color = 'blue'>share</font></i> parts of the Scratch Motto and hopefully letting users use what they learn here to <i><font color = 'blue'>imagine</font></i> their own blocks!</p>
<h2>The people</h2>
<ul>
<li><a href = '/about.php?librarian=sparks'>Sparks (Miles Fletcher)</a> - Library Founder</li>
</ul>
<h3><strong>Librarians</strong></h3>
<ul>
<li><a href = '/about.php?librarian=SSBBM'>SSBBM</a></li>
<li><a href = '/about.php?librarian=Scimonster'>Scimonster</a></li>
<li><a href = '/about.php?librarian=Pecola1'>Pecola1</a></li>
<li><a href = '/about.php?librarian=meowmeow55'>meowmeow55</a></li>
<li><a href = '/about.php?librarian=TheSuccessor'>TheSuccessor</a></li>
</ul>
<h3>Site developers</h3>
<ul>
<li><a href = 'about.php?librarian=ProgrammingFreak'>ProgrammingFreak</a></li>
<li>meowmeow55</li>
<li><a href = 'about.php?librarian=Magnie'>Magnie</a></li>
<li>TheSuccessor</li>
</ul>
<h2><strong>History</strong></h2>
<p>The Block Library started life as a forum thread in the Scratch Advanced Topics forum created by the Scratch user Sparks on the 15th of July 2010. It consisted of a single post that contained marked sections for Scratch blocks. There were no images or ways to navigate. On the 19th of July BYOB and Panther blocks were supported and several blocks had been shared. Several people pushed to get the library I-Topic'd (a thread status that keeps a link to the thread at the top of the forum page). A "fossil" of the block library as it appeared on the 16th of  August can be found neatly preserved in <a href = 'http://scratch.mit.edu/forums/viewtopic.php?pid=510230#p510230'>stickdude123's post</a>.</p>
<p>On the 11th of September 2010 the Block Library was I-Topic'd by the community moderator Coolstuff and to celebrate, Sparks spent several weeks redesigning the layout of the entire library through suggestions by Scratchers to make the library easier to browse and use including the splitting of the first post into one post per block category on the 16th of September and new graphic navigation (as well as the library header logo still used today) designed by nXIII.</p>
<p>By March Sparks was struggling to keep the library updated due to a huge flood of block submissions. On the 16th of March Coolstuff, fullmoon and Lighnin moved the I-Topic status from the old library thread to a new one created on a shared Scratch account called "YourLocalBlockLib", an account shared by Sparks, meowmeow55, Pecola1, SSBBM, TheSucessor and Scimonster.</p>
<p>On the 15th of July the library website was officially hosted and moved to the blocks.scratchr.org domain thanks to Andr&eacute;s and Amos from the Scratch Team.</p>
<?php } ?>
</td>
</tr>
</tbody>
</table>
    </div>

    
    
  </div> <!-- /node-inner -->
</div> <!-- /node-->          </div> <!-- /#content-area -->

          
          
          </div>
        </div> <!-- /content-inner /content -->

                  <div id="navigation" class="menu  with-sub-menu">
                        <ul id="secondary" class="links sub-menu"><li class="menu-404 first"><a href="http://scratch.mit.edu/download" title="Download the Scratch Software">Download</a></li>
<li class="menu-405"><a href="http://info.scratch.mit.edu/Donate" title="Support the Scratch Project">Donate</a></li>
<li class="menu-406"><a href="http://info.scratch.mit.edu/Privacy_Policy" title="">Privacy Policy</a></li>
<li class="menu-407"><a href="http://info.scratch.mit.edu/Terms_of_use" title="Information about the values of the Scratch Community">Terms of Use</a></li>

<li class="menu-408"><a href="/DMCA" title="">Copyright Policy</a></li>
<li class="menu-409 last"><a href="http://scratch.mit.edu/contact/us" title="">Contact Us</a></li>
</ul>          </div> <!-- /navigation -->
        
                   <div id="sidebar-first" class="column sidebar first">
            <div id="sidebar-first-inner" class="inner">
              <div id="block-locale-0" class="block block-locale odd left clearfix">
  <div class="block-inner">

    
    <div class="content">
        &nbsp
    </div>

    
  </div> <!-- /block-inner -->
</div> <!-- /block -->            </div>

          </div>
         <!-- /sidebar-left -->

         <!-- /sidebar-second -->

      </div> <!-- /main -->
<?php include("footer.php"); ?>

admin.php

Code:

<?php session_start();
$title = 'Block Library | Admin'; 
include("header.php");
?>

    <div id="main" class="clearfix">
    
      <div id="content">
        <div id="content-inner" class="inner column center">

          
                      <div id="content-header">

              <div class="breadcrumb"><a href="/">admin</a></div>
                              <h1 class="title">Librarians' log book</h1>

              
              
              
               

              
            </div> <!-- /#content-header -->
          
          <div id="content-area">
            <div class="node node node-type-page" id="node-6">
  <div class="node-inner">

    
    
    
    <div class="content">
      <table cellspacing="1" cellpadding="1" border="0" align="left" style="float: none; background-image: none; vertical-align: top; width: 100%; border-collapse: separate;">
<tbody style="vertical-align: top;">
<tr>
<td style="width: 70%;">
<?php
            include("connect.php");
            if(isset($_GET['action'])){
            if($_GET['action'] == 'logout'){
            if(isset($_SESSION['username'])){
            echo "<p>Logged out of ". $_SESSION['username'] . "'s account";
            unset($_SESSION['username']);
            }
            }
            }
if(!isset($_SESSION['username'])){?>
    <p>This section of the site requires the Scratch username and password of a block librarian to be viewed. Please login to continue.</p>
    <p>&nbsp </p>
<?php
}
if(isset($_SESSION['username'])){
    if($_SESSION['username'] == 'sparks' | $_SESSION['username'] == 'meowmeow55' | $_SESSION['username'] == 'TheSuccessor' | $_SESSION['username'] == 'Magnie' | $_SESSION['username'] == 'Pecola1' | $_SESSION['username'] == 'scimonster' | $_SESSION['username'] == 'SSBBM' | $_SESSION['username'] == 'ProgrammingFreak'  | $_SESSION['username'] == 'Greenatic'){ #TheSuccessor and meowmeow55 are site developers who have file change access, the rest are librarians?>
            <h3>Logged into the control panel as  <?php echo $_SESSION['username']?>.</h3>
            <hr />
            <p><a href = '/updateAbout.php/'>Update my "about me" message</a></p>
            <hr />
            <h2>Main control Panel</h2>
            <?php
            $query = "SELECT * FROM comments";
            mysql_query($query); 
            $result = mysql_query($query) or die(mysql_error());
            $results = 0;
            while($row = mysql_fetch_array($result)){
                if($row['status'] == 'unapproved'){
                    $status ++;
                }
            }
            ?>
            <p>Use the options here to approve pending blocks and make other site changes.</p>
            <p><a href = '/sanitize.php'>Post sanitizing (<?php echo $status; ?> items to address)</a></p>
            <hr/>
            <p>Librarian Discussions</p>
            <?php
            $commentName = 'admintalk';
            $commentType = 'unmoderated';
            $commentLimit = '5000';
            include("commentSpace.php");
    }
    else{
        echo "Sorry, ". $_SESSION['username'] . ". You're not allowed to view this section of the site as you need to be a block librarian to view use it. If you think you should have been able to enter, try logging in again by clicking <a href = 'admin.php'>here</a> or contact sparks <a href = 'http://scratch.mit.edu/forums/viewtopic.php?id=52709'>here</a>.</p>";
    }
}?>

</td>
</tr>
</tbody>
</table>
    </div>

    
    
  </div> <!-- /node-inner -->
</div> <!-- /node-->          </div> <!-- /#content-area -->

          
          
          </div>
        </div> <!-- /content-inner /content -->

                  <div id="navigation" class="menu  with-sub-menu">
                        <ul id="secondary" class="links sub-menu"><li class="menu-404 first"><a href="http://scratch.mit.edu/download" title="Download the Scratch Software">Download</a></li>
<li class="menu-405"><a href="http://info.scratch.mit.edu/Donate" title="Support the Scratch Project">Donate</a></li>
<li class="menu-406"><a href="http://info.scratch.mit.edu/Privacy_Policy" title="">Privacy Policy</a></li>
<li class="menu-407"><a href="http://info.scratch.mit.edu/Terms_of_use" title="Information about the values of the Scratch Community">Terms of Use</a></li>

<li class="menu-408"><a href="/DMCA" title="">Copyright Policy</a></li>
<li class="menu-409 last"><a href="http://scratch.mit.edu/contact/us" title="">Contact Us</a></li>
</ul>          </div> <!-- /navigation -->
        
                  <div id="sidebar-first" class="column sidebar first">
            <div id="sidebar-first-inner" class="inner">
              <div id="block-locale-0" class="block block-locale odd left clearfix">
  <div class="block-inner">

    
    <div class="content">
        &nbsp
    </div>

    
  </div> <!-- /block-inner -->
</div> <!-- /block -->            </div>

          </div>
         <!-- /sidebar-left -->

         <!-- /sidebar-second -->

      </div> <!-- /main -->
<?php include("footer.php"); ?>

autoupload.php

Code:

<?php
include("connect.php");
mysql_query("TRUNCATE blocks");
mysql_query("ALTER TABLE blocks AUTO_INCREMENT=0");
$count = 0;
while ($count != 60){
    $count ++;
    $count2 = 0;
    $file = fopen("http://dl.dropbox.com/u/6273449/" . $count . ".txt", "r") or exit("Unable to open file!");
    while(!feof($file)){
        $count2 ++;
        if($count2 == 1){
            $creator = fgets($file);
        }
        if($count2 == 2){
            $name = fgets($file);
        }
        if($count2 == 3){
            $type = fgets($file);
        }
        if($count2 == 4){
            $colour = fgets($file);
            if(strpos(fgets($file), '#4A6CD4') != 0){
                $category = 'Motion';
            }
            if(strpos(fgets($file), '#E6A822') != 0){
                $category = 'Control';
            }
            if(strpos(fgets($file),  '#8C52E7') != 0){
                $category = 'Looks';
            }
            if(strpos(fgets($file), '#0494DC') != 0){
                $category = 'Sensing';
            }
            if(strpos(fgets($file), '#CE4ADE') != 0){
                $category = 'Sound';
            }
            if(strpos(fgets($file), '#63C610') != 0){
                $category = 'Operators';
            }
            if(strpos(fgets($file), '#00A57B') != 0){
                $category = 'Pen';
            }
            if(strpos(fgets($file), '#F77318') != 0){
                $category = 'Variables';
            }
            if(strpos(fgets($file), '#297BC6') != 0){
                $category = 'Files';
            }
            if(strpos(fgets($file), '#424242') != 0){
                $category = 'Colors';
            }
        }
        if($count2 == 5){
            $code = fgets($file);
        }
    }
    $sharer = 'sparks';
    $comment = '';
    echo $count2;
    
    
    mysql_query("INSERT INTO `blocks` (id, name, type, category, code, creator, sharer, comment, status, colour)
    VALUES ('', '$name', '$type', '$category', '$code', '$creator', '$sharer', '$comment', 'approved', '$colour')");
    fclose($file);
}

?>

commentspace.php (plugin)

Code:

<?php
#################################################################################################################
###########                         PHP COMMENT PLUGIN BY MILES FLETCHER (SPARKS)                                               ###########
#################################################################################################################
/* This plugin allows a commenting space to be added to any page under the same directory.
(c) Miles Fletcher. Do not use without permission.

THIS VERSION HAS BEEN EDITED SPECIFICALLY BY MILES FLETCHER TO ACT AS A PLUGIN FOR THE BLOCKS.SCRATCHR.ORG SITE

    The plugin supports:
        username access through session variables
        commenting space with character limiter and remaining character display
        display of all comments for that page in ascending or descending chronological order (default newest at top, swap DESC with ASC around line 111 to reverse)
        HTML sanitisation to prevent malicious code being entered into posts
        smilies (with disable tickbox)
        prettydate display on posts.
        
        bbcode
            links (simple and complex)
            images
            bold text
            underlined text
            itallic text
            text colour
            quoting (unfinished, simple and complex)
        
        post deletion
            all posts for moderators
            own posts for regular users
        post report button
        
For full installation details and requirements look at the page I've not done yet.

*/
function nth_position($str, $letter, $n, $offset = 0){
    $str_arr = str_split($str);
    $letter_size = array_count_values(str_split(substr($str, $offset)));
    if( !isset($letter_size[$letter])){
        trigger_error('letter "' . $letter . '" does not exist in ' . $str . ' after ' . $offset . '. position', E_USER_WARNING);
        return false;
    } 
    else if($letter_size[$letter] < $n) {
        trigger_error('letter "' . $letter . '" does not exist ' . $n .' times in ' . $str . ' after ' . $offset . '. position', E_USER_WARNING);
        return false;
    }
    for($i = $offset, $x = 0, $count = (count($str_arr) - $offset); $i < $count, $x != $n; $i++){
        if($str_arr[$i] == $letter){
        $x++;
        }
    }
    return $i - 1;
}
?>

<script type = 'text/javascript'>
function textLimit(field, maxlen){
    if(field.value.length>maxlen){
        field.value = field.value.substring(0, maxlen);
    }
    document.getElementById('characters').innerHTML=field.value.length + "/" + maxlen;
}
</script>
<div id = 'commentContainer' style = 'background-image:url(http://scratch.mit.edu/img/bg_container.png);background-repeat:no-repeat;position:relative;margin-left:10px;width:520px;padding:10px;'>
    <div style = 'background-image:url(http://scratch.mit.edu/img/ic_comments.gif);background-repeat:no-repeat;position:relative;top:10px;'>
        <div style = 'position:relative;left:30px'>
            <h2>Comments</h2>
        </div>
    </div>
<?php
            
            include("prettydate.php");
            
            include("connect.php");
            if($_SESSION['username'] != ''){
                $moderator = False;
                $result = mysql_query("SELECT * FROM aboutme");
                while($row = mysql_fetch_array($result))
                {
                    if($_SESSION['username'] == 'sparks' | $_SESSION['username'] == 'meowmeow55' | $_SESSION['username'] == 'TheSuccessor' | $_SESSION['username'] == 'Magnie' | $_SESSION['username'] == 'Pecola1' | $_SESSION['username'] == 'scimonster' | $_SESSION['username'] == 'SSBBM' | $_SESSION['username'] == 'ProgrammingFreak' | $_SESSION['username'] == 'Greenatic'){
                        $moderator =  True;
                    }
                }
            }
                    
            if (isset($_SESSION['username'])){
                if(!isset($commentLimit)){
                    $commentLimit = 1000;
                }
                echo"<h3>Add a comment</h3>
                <form name='commentForm'  method ='post' action = '" . curPageURL() . "'>
                <div style = 'float:left; margin-right:auto; height:25px;'>
                </div>
                <br/>
                <p><textarea name = 'comment' id = 'comment' rows='3' cols='60' border = '1' tabIndex='1' onkeypress = 'textLimit(this, " . $commentLimit . ");' onkeydown = 'textLimit(this, " . $commentLimit . ");' onkeyup = 'textLimit(this, " . $commentLimit . ");'>
</textarea></p>
                <div style = 'width:150px;height:24px;'>
                <div style = 'width:43px;height:24px;position:relative;background-image:url(charcount.gif);top:-80px;left:541px;'background-repeat:no-repeat;padding:10px;>
                        <center><p id = 'characters' style = 'position:relative;top:70px;left:-540px;'>0/" . $commentLimit . "</p></center>
                    </div>
                    <div style = 'background-image:url(smilestick.gif);background-repeat:no-repeat;height:24px;width:43px;'>
                        <input type = 'checkbox' checked = 'checked' name = 'smilies' tabIndex='3'/> <img src = '/smilies/smile.gif' />
                    </div>
                    <input type='image' name='submit' src = 'add.bmp' alt ='Add' style = 'position:relative;top:-24px;left:50px;' tabIndex='2'/>
                </div>
                </form>
                <br/>
                <br/>";
            }
            else{
                echo "<h3>Login to post a comment.</h3>";
            }

            if(isset($_POST['comment'])){
                if ($_POST['comment'] != '' && isset ($_SESSION['username'])){
                    $username = $_SESSION['username'];
                    $comment = $_POST['comment'];
                    $comment = str_replace("<","&lt",$comment); #'damage' all <'s, removing html and simply displaying as text.
                    $comment = str_replace(">","&gt",$comment);
                    $smilies = isset($_POST['smilies']);
                
                    $comment = str_replace("
","<br />",$comment); #line breaks
                    $ip= $_SERVER['REMOTE_ADDR'];
                    date_default_timezone_set('GMT');
                    $time = date('c'); #Date of post for human reference.
                    $epoch = date('U'); # epoch date. This is the number of seconds since Jan 1st 1970. Used to check how old a post is for deletion.
                    if(!isset($commentType)){
                        $commentType = 'unapproved';
                    }
                    mysql_query("INSERT INTO comments (username, comment, time, ip, epoch, commentName, smilies, status)
                    VALUES ('$username', '$comment', '$time', '$ip', '$epoch', '$commentName', '$smilies', '$commentType')");
                    $URL= curPageURL();
                }
            }        
            $query = "SELECT * FROM comments WHERE `commentName` = '$commentName' AND `status` != 'deleted' ORDER BY commentNo DESC";
            mysql_query($query); 
     
            $result = mysql_query($query) or die(mysql_error());

            while($row = mysql_fetch_array($result)){
                $string = $row['comment'];
                
                $string = preg_replace('#\[img\]([^\[]*?)\[/img\]#', "<img src=\"$1\" style=\"max-width: 570;\"/>", $string); #img tag
                
                $string = preg_replace('#\[url\]([^\[]*?)\[/url\]#', "<a href=\"$1\">$1</a>", $string); #simple url tag
                $string = preg_replace('#\[url=([^\[]+?)\](.*?)\[/url\]#', "<a href=\"$1\">$2</a>", $string); #complex url tag

                $string = preg_replace('#\[colou?r=([a-zA-Z]*|\#[0-9a-fA-F]*)\](.*?)\[/colou?r\]#', "<span style=\"color: $1\">$2</font>", $string); #font colour tag

                $string = preg_replace('#\[b\](.*?)\[/b\]#ms', "<strong>$1</strong>", $string); #bold
                $string = preg_replace('#\[i\](.*?)\[/i\]#ms', "<em>$1</em>", $string); #italics
                $string = preg_replace('#\[u\](.*?)\[/u\]#ms', "<span style=\"text-decoration: underline\">$1</span>", $string); #underline
                If($row['smilies'] == 1){
                    $string = str_replace(">:(", "<img src = '/smilies/mad.gif' alt = '>:(' />", $string);
                    $string = str_replace(":)", "<img src = '/smilies/smile.gif' alt = ':)' />", $string);
                    $string = str_replace(":D", "<img src = '/smilies/biggrin.gif' alt = ':D' />", $string);
                    $string = str_replace(":angel:", "<img src = '/smilies/angel.gif' alt = '0:)' />", $string);
                    $string = str_replace("O_o", "<img src = '/smilies/blink.gif' alt = 'O_o' />", $string);
                    $string = str_replace("o_O", "<img src = '/smilies/blink.gif' alt = 'o_O' />", $string);
                    $string = str_replace(":wave:", "<img src = '/smilies/bye.gif' alt = ':waveface:' />", $string);
                    $string = str_replace(":cool:", "<img src = '/smilies/cool.gif' alt = ':coolface:' />", $string);
                    $string = str_replace("¬_¬", "<img src = '/smilies/dry.gif' alt = '¬_¬' />", $string);
                    $string = str_replace("v_v", "<img src = '/smilies/goodgrief.gif' alt = 'v_v' />", $string);
                    $string = str_replace(":huh:", "<img src = '/smilies/huh.gif' alt = ':huhface:' />", $string);
                    $string = str_replace(":laugh:", "<img src = '/smilies/laugh.gif' alt = ':laughface:' />", $string);
                    $string = str_replace(":lol:", "<img src = '/smilies/lol.gif' alt = ':lolface:' />", $string);
                    $string = str_replace("'-'", "<img src = '/smilies/mellow.gif' alt = ''-'' />", $string);
                    $string = str_replace(":o", "<img src = '/smilies/ohmy.gif' alt = ':o' />", $string);
                    $string = str_replace(":O", "<img src = '/smilies/ohmy.gif' alt = ':o' />", $string);
                    $string = str_replace(":rolleyes:", "<img src = '/smilies/rolleyes.gif' alt = ':rolleyesface:' />", $string);
                    $string = str_replace(":(", "<img src = '/smilies/sad.gif' alt = ':(' />", $string);
                    $string = str_replace(":#", "<img src = '/smilies/shy.gif' alt = ':#' />", $string);
                    $string = str_replace(":'(", "<img src = '/smilies/tears.gif' alt = ':\'(' />", $string);
                    $string = str_replace(":P", "<img src = '/smilies/tongue.gif' alt = ':P' />", $string);
                    $string = str_replace(":p", "<img src = '/smilies/tongue.gif' alt = ':P' />", $string);
                    $string = str_replace(":unsure:", "<img src = '/smilies/unsure.gif' alt = ':unsureface:' />", $string);
                    $string = str_replace(";)", "<img src = '/smilies/wink.gif' alt = ';)' />", $string);
                    
                    $image = ltrim(file_get_contents('http://scratch.mit.edu/api/getinfobyusername/' . $row['username']));
                    $startpos = nth_position($image, ":",1) + 1;
                    $endpos = nth_position($image, ":", 2);
                    $image = substr($image, $startpos, $endpos - $startpos);
                }
                echo "<div style = 'background-image:url(line.gif);background-repeat:repeat-x; height:5px;'>
                    &nbsp
                </div>
                <div style = 'position:relative;height:45px;top:5px;'>
                    <h5><a href = 'http://scratch.mit.edu/users/" . $row['username'] . "' target='_blank'><img src = 'http://scratch.mit.edu/static/icons/buddy/" . $image . "_sm.png' height = '30px' width = '30px' alt = 'User icon' border = '0'/></a> " . $row['username'] . " " . prettydate($row['epoch']) . "</h5>
                </div>
                <div style = 'position:relative;overflow-y:auto;'>
                    " . $string . "
                </div>";
            }
                echo "</div>";
            ?>

competition.php

Code:

    <?php
    /* Contributers so far to this file:
     
    * Sparks
    * Magine
    */
     
    /*
    Progress Diary:
    * Sparks - 28th June 2011 - Created page, built MySQL table for a 1 year anniversary image competiton. Added Space for Scratch username and password
    and a place to paste your image URL. Scratch API not working yet.
    * Sparks - 29th June 2011 - Worked out how to get the API to confirm the Scratch username and password. Still struggling to connect to the MySQL table.
    *Sparks - 2nd July 2011 - Magnie fixed MySQL connectin by finding correct connection details, thanks Magnie! I have added boxes for each entry and a "vote for me!"
    link for each one that will hopefully lead to a vote adding page that allows one vote per IP. (or per Scratcher, both have disadvantages).
    * Sparks - 3rd July 2011 - Added image parsering so that only png, gif, jpg and bmp files are accepted. id is auto inc for the MySQL table so entry numbers are now displayed
    via php counting, not via id. voting is now avaliable - one vote per Scratch user account. I believe this page is finished. voters and entries can be removed via the PHPmyadmin
    supplied with the site!
    *Sparks - 5th July 2011 - Page complete, votes can be changed.
    */
     
    define('PAGE', 'competition');
     
    $title = 'The Block Library - Competition';
    require 'include/header.php';
    ?>
    <div id = 'topPadding' style = 'height:40px;'>
    &nbsp
    </div>
    <div id = 'competitonBox' style = 'background-color:#D18A00; width:900px; height:auto; padding:10px; margin-left:auto; margin-right:auto;'>
    <div id = 'topLeftCorner' style = 'width:1px; height:1px; background-color:#FFFFFF; position:relative; float:left; top:-10px; left:-10px;'>
    &nbsp
    </div>
    <div id = 'topRightCorner' style = 'width:1px; height:1px; background-color:#FFFFFF; position:relative; float:right; top:-10px; left:10px;'>
    &nbsp
    </div>
    <center>
    <h2>The Block Library is celebrating it's first Birthday on July the 15th!</h2>
    <h3>and to celebrate we're having a competition!</h3>
    <?php
    if (isset ($_GET['page'])){
    if($_GET['page'] == 'submit'){
    echo "<div style = 'width:98%; background-color:#FF9923;padding:5px;'>
    <h2><strong>The Rules</strong></h2>
    <ul>
    <li>The image you submit must have the same or very similar dimensions to the <a href = 'http://www.theblocklibrary.site11.com/include/img/BlockLibraryTitle.png'>logo</a> (640 X 210 pixels).</li>
    <li> Each Scratcher may enter <strong>as many images to this competition as they like.</strong></li>
    <li>Each Scratcher may vote for one image out of all the entered images within the competition. Voting with a secondary account as well could cause all your votes to be disregarded.</li>
    <li>Entries may be submitted until 12:00 GMT on Friday the 15th of July 2011.</li>
    </ul>
    </br>
    <h2><strong>How it works</strong></h2>
    <ul>
    <li>Images are displayed on the competitions page anonymously and each Scratcher may vote anonymously for one image of their choice. Should you wish to change your vote simply vote again and confirm that you
    want your original vote to be removed.</li>
    <li>On the 15th of July 2011 at approximately 13:00 GMT the winning image will be revealed along with the name of the winning Scratcher. Individual votes remain anonymous.</li>
    </ul>
    </div>
    <form name='competitonForm' method ='post' action = 'competition.php?page=submitted'>
    <p> Scratch Username <input type = 'text' name = 'scratchUsername' /></p>
    <p> Scratch Password <input type = 'password' name = 'scratchPassword' /></p>
    <p> Link to your image (you'll need to host this yourself!) <input type = 'text' name = 'imageLink' /></p>
    <input type = 'hidden' name = 'formSubmitted' value = 'yes' />
    <p>There is currently no competition open. You cannot enter.</p>";
    #<input type = 'submit' name = 'submit' value = 'Share your entry' />
    echo "</form>
    </br>
    <a href = 'competition.php'><p>Click here to return to the entries page</p></a>";
    }
     
    if($_GET['page'] == 'submitted'){
    $t1 = ltrim(file_get_contents('http://scratch.mit.edu/api/authenticateuser?username=' . $_POST['scratchUsername'] . '&password=' . $_POST['scratchPassword']));
    $t2 = False;
    if(strlen(strpos($_POST['imageLink'], '.gif')) != '0'){
    $t2 = True;
    }
    if(strlen(strpos($_POST['imageLink'], '.GIF')) != '0'){
    $t2 = True;
    }
    if(strlen(strpos($_POST['imageLink'], '.png')) != '0'){
    $t2 = True;
    }
    if(strlen(strpos($_POST['imageLink'], '.PNG')) != '0'){
    $t2 = True;
    }
    if(strlen(strpos($_POST['imageLink'], '.bmp')) != '0'){
    $t2 = True;
    }
    if(strlen(strpos($_POST['imageLink'], '.BMP')) != '0'){
    $t2 = True;
    }
    if(strlen(strpos($_POST['imageLink'], '.jpg')) != '0'){
    $t2 = True;
    }
    if(strlen(strpos($_POST['imageLink'], '.JPG')) != '0'){
    $t2 = True;
    }
     
    if($t1 == 'false' | !$t2){
    if($t1 == 'false'){
    echo "<p>The username or password you entered was incorrect!</p>";
    }
    if(!$t2){
    echo "<p>The image you submitted is not in the accepted formats of gif, png or bmp.</p>";
    }
    echo "<a href = 'competition.php'><p>Click here to return to the entries page</p></a>";
    }
    else{
    echo "Your entry has been submitted.
    <a href = 'competition.php'><p>Click here to return to the entries page</p></a>";
    mysql_connect("mysql13.000webhost.com", "a1110082_lib", "rivella_") or die(mysql_error());
    //echo "Connection to mysql works.";
    mysql_select_db("a1110082_data") or die(mysql_error());
    //echo "Connection and selecting db works...";
    mysql_query("INSERT INTO 1yearcompentries (username, imageLink, votes)
    VALUES ('$_POST[scratchUsername]', '$_POST[imageLink]', '0')");
    }
    }
    if($_GET['page'] == 'vote'){
    echo "<p><img src = '" . $_GET['imageLink'] . "' /></p>
    <p>thanks for choosing to vote for this entry! Please enter your Scratch username and password in the boxes below! to vote!</p>
    <p>Please note, one vote is allowed per Scratcher, test accounts or second accounts belonging to you are not allowed to be used for voting and if you attempt to vote using one neither of your votes will be counted. This is in the interests of a fair voting system for all! Thanks!</p>
    </br>
    <form name='voteForm' method ='post' action = 'competition.php?page=voted'>
    <p> Scratch Username <input type = 'text' name = 'scratchUsername' /></p>
    <p> Scratch Password <input type = 'password' name = 'scratchPassword' /></p>
    <p>Voting is currently closed.</p>
    <input type = 'hidden' name = 'id' value = '" . $_GET['num'] . "'>
    </form>
    </br>
    <a href = 'competition.php'><p>Click here to return to the entries page</p></a>";
    #<input type = 'submit' name = 'submit' value = 'Vote!' />
    }
    if($_GET['page'] == 'voted'){
    mysql_connect("mysql13.000webhost.com", "a1110082_lib", "rivella_") or die(mysql_error());
    mysql_select_db("a1110082_data") or die(mysql_error());
    $permission = True;
    $query = "SELECT * FROM voters";
    mysql_query($query) or die(mysql_error());
    $result = mysql_query($query) or die(mysql_error());
    while($row = mysql_fetch_array($result)){
    if($_POST['scratchUsername'] == $row['ip']){
    $permission = False;
    }
    }
    if($permission){
    $t1 = ltrim(file_get_contents('http://scratch.mit.edu/api/authenticateuser?username=' . $_POST['scratchUsername'] . '&password=' . $_POST['scratchPassword']));
    if($t1 == 'false'){
    echo "<strong><p>The username or password you entered was incorrect!</p></strong>";
    }
    else{
    echo "<strong><p>thanks for voting, " . $_POST['scratchUsername'] . "!</p></strong>";
    mysql_query("INSERT INTO voters (ip, votedFor)
    VALUES ('$_POST[scratchUsername]', '$_POST[id]')");
    mysql_query("UPDATE 1yearcompentries SET votes = votes+1 WHERE id = $_POST[id]");
    }
    echo "<a href = 'competition.php'><p>Click here to return to the entries page</p></a>";
    }
    if(!$permission){
    $query = "SELECT * FROM voters";
    mysql_query($query) or die(mysql_error());
    $result = mysql_query($query) or die(mysql_error());
    while($row = mysql_fetch_array($result)){
    if($_POST['scratchUsername'] == $row['ip']){
    $oldVote = $row['votedFor'];
    }
    }
    echo "<strong><p>You have already voted and only one vote per Scratcher is allowed. Are you sure you want to remove your previous vote and add it to this image instead?
    <form name = 'changeVoteForm' method = 'post' action = 'competition.php?page=changevote'>
    <input type = 'hidden' name = 'oldVoteNo' value = '" . $oldVote . "'/>
    <input type = 'hidden' name = 'newVoteNo' value = '" . $_POST['id'] . "'/>
    <input type = 'hidden' name = 'scratchUsername' value = '" . $_POST['scratchUsername'] . "'/>
    <input type = 'submit' name = 'changeVote' value = 'Change my vote.' />
    </form>
    </p></strong>";
     
    echo "<a href = 'competition.php'><p>Click here to return to the entries page</p></a>";
     
     
    }
    }
    if($_GET['page'] == 'changevote'){
    echo "<p>Thanks " . $_POST['scratchUsername'] . ", Your vote has been changed!</p>";
    mysql_query("UPDATE 1yearcompentries SET votes = votes-1 WHERE id = $_POST[oldVoteNo]");
    mysql_query("UPDATE 1yearcompentries SET votes = votes+1 WHERE id = $_POST[newVoteNo]");
    mysql_query("UPDATE voters SET votedFor = '$_POST[newVoteNo]' WHERE ip = '$_POST[scratchUsername]'");
    echo "<a href = 'competition.php'><p>Click here to return to the entries page</p></a>";
    }
    }
    if (!isset ($_GET['page'])){
    echo "<p>Each Scratcher can vote one one of the images below and may change their vote if they choose to. Each Scratcher may submit as many entries as they wish!</p>
    <h3><a href = 'http://www.theblocklibrary.site11.com/competition.php?page=submit'>Submit an entry</a></h3>
    </br>
    <h3>The entries</h3>
    </br>";
    $count = '0';
    mysql_connect("********", "*******", "*********") or die(mysql_error());
    mysql_select_db("a1110082_data") or die(mysql_error());
    $query = "SELECT * FROM 1yearcompentries ORDER BY id ASC";
    mysql_query($query) or die(mysql_error());
    $result = mysql_query($query) or die(mysql_error());
    while($row = mysql_fetch_array($result)){
    ++$count;
    echo "<div style = 'width:98%; background-color:#FF9923;padding:5px;'>
    <h4>Submission " . $count . "
    </h4>
    <p><img src = '" . $row['imageLink'] . "' border = '0'/></p>
    <a href = 'competition.php?page=vote&num=" . $row['id'] . "&imageLink=" . $row['imageLink'] . "'><p>Vote for me!</p></a>
    </br>
    </div>
    </br>";
    }
    if ($count == '0'){
    echo "<p>No entries have been submitted yet, be the first!</p>";
    }
     
    }
    ?>
    </center>
    <div id = 'bottomLeftCorner' style = 'width:1px; height:1px; background-color:#FFFFFF; position:relative; float:left; top:9px; left:-10px;'>
    &nbsp
    </div>
    <div id = 'bottomRightCorner' style = 'width:1px; height:1px; background-color:#FFFFFF; position:relative; float:right; top:9px; left:10px;'>
    &nbsp
    </div>
    </div>
    <?php require 'include/footer.php'; ?>

connect.php

Code:

<?php
mysql_connect("mysql.blocks.scratchr.org", "scratchrblocksdb", "***********") or die(mysql_error());
            mysql_select_db("scratchrblocks") or die(mysql_error()); ?>

index.php

Code:

<?php 
session_start();
$title = 'Block Library | Home'; 
include("header.php");
?>

    <div id="main" class="clearfix">
    
      <div id="content">
        <div id="content-inner" class="inner column center">

          
                      <div id="content-header">

              <div class="breadcrumb"><a href="/">Home</a></div>
                              <h1 class="title">The Block Library</h1>

              
              
              
               

              
            </div> <!-- /#content-header -->
          
          <div id="content-area">
            <div class="node node node-type-page" id="node-6">
  <div class="node-inner">

    
    
    
    <div class="content">
      <table cellspacing="1" cellpadding="1" border="0" align="left" style="float: none; background-image: none; vertical-align: top; width: 100%; border-collapse: separate;">
<tbody style="vertical-align: top;">
<tr>
<td style="width: 70%;">The Block library is a resource run by several members of the Scratch community that allows users to share and view new blocks for Scratch, <a href = "http://www.pantherprogramming.weebly.com">Panther</a> and <a href = "http://byob.berkeley.edu/">BYOB</a> for free!

<p>The block library is currently a forum thread in the Scratch Advanced topics Forum which you can view and use <a href = 'http://scratch.mit.edu/forums/viewtopic.php?id=52709&p=1'>here</a>. The website, which will allow users to share blocks, download others' blocks and comment on them is still being built but bookmark this page and pop back every now and then to keep an eye on updates!</p>


</td>
</tr>
</tbody>
</table>
    </div>

    
    
  </div> <!-- /node-inner -->
</div> <!-- /node-->          </div> <!-- /#content-area -->

          
          
          </div>
        </div> <!-- /content-inner /content -->

                  <div id="navigation" class="menu  with-sub-menu">
                        <ul id="secondary" class="links sub-menu"><li class="menu-404 first"><a href="http://scratch.mit.edu/download" title="Download the Scratch Software">Download</a></li>
<li class="menu-405"><a href="http://info.scratch.mit.edu/Donate" title="Support the Scratch Project">Donate</a></li>
<li class="menu-406"><a href="http://info.scratch.mit.edu/Privacy_Policy" title="">Privacy Policy</a></li>
<li class="menu-407"><a href="http://info.scratch.mit.edu/Terms_of_use" title="Information about the values of the Scratch Community">Terms of Use</a></li>

<li class="menu-408"><a href="/DMCA" title="">Copyright Policy</a></li>
<li class="menu-409 last"><a href="http://scratch.mit.edu/contact/us" title="">Contact Us</a></li>
</ul>          </div> <!-- /navigation -->
        
                  <div id="sidebar-first" class="column sidebar first">
            <div id="sidebar-first-inner" class="inner">
              <div id="block-locale-0" class="block block-locale odd left clearfix">
  <div class="block-inner">

    
    <div class="content">
        &nbsp
    </div>

    
  </div> <!-- /block-inner -->
</div> <!-- /block -->            </div>

          </div>
         <!-- /sidebar-left -->

         <!-- /sidebar-second -->

      </div> <!-- /main -->
<?php include("footer.php"); ?>

sanitise.php

Code:

<?php session_start();
$title = 'Block Library | Admin'; 
include("header.php");

function nth_position($str, $letter, $n, $offset = 0){
    $str_arr = str_split($str);
    $letter_size = array_count_values(str_split(substr($str, $offset)));
    if( !isset($letter_size[$letter])){
        trigger_error('letter "' . $letter . '" does not exist in ' . $str . ' after ' . $offset . '. position', E_USER_WARNING);
        return false;
    } 
    else if($letter_size[$letter] < $n) {
        trigger_error('letter "' . $letter . '" does not exist ' . $n .' times in ' . $str . ' after ' . $offset . '. position', E_USER_WARNING);
        return false;
    }
    for($i = $offset, $x = 0, $count = (count($str_arr) - $offset); $i < $count, $x != $n; $i++){
        if($str_arr[$i] == $letter){
        $x++;
        }
    }
    return $i - 1;
}
include("prettydate.php");
?>

    <div id="main" class="clearfix">
    
      <div id="content">
        <div id="content-inner" class="inner column center">

          
                      <div id="content-header">

              <div class="breadcrumb"><a href="/">admin</a></div>
                              <h1 class="title">Librarians' log book</h1>

              
              
              
               

              
            </div> <!-- /#content-header -->
          
          <div id="content-area">
            <div class="node node node-type-page" id="node-6">
  <div class="node-inner">

    
    
    
    <div class="content">
      <table cellspacing="1" cellpadding="1" border="0" align="left" style="float: none; background-image: none; vertical-align: top; width: 100%; border-collapse: separate;">
<tbody style="vertical-align: top;">
<tr>
<td style="width: 70%;">

</td>
</tr>
</tbody>
</table>
<?php
            include("connect.php");
if(!isset($_SESSION['username'])){?>
    <p>This section of the site requires the Scratch username and password of a block librarian to be viewed. Please login to continue.</p>
    <p>&nbsp </p>
<?php
}
if(isset($_SESSION['username'])){
    if($_SESSION['username'] == 'sparks' | $_SESSION['username'] == 'meowmeow55' | $_SESSION['username'] == 'TheSuccessor' | $_SESSION['username'] == 'Magnie' | $_SESSION['username'] == 'Pecola1' | $_SESSION['username'] == 'scimonster' | $_SESSION['username'] == 'SSBBM' | $_SESSION['username'] == 'ProgrammingFreak' | $_SESSION['username'] == 'Greenatic'){ #TheSuccessor and meowmeow55 are site developers who have file change access, the rest are librarians?>
            <h3>Logged into the control panel as  <?php echo $_SESSION['username']?>.</h3>
            <p><a href = 'admin.php'>Back to main area</a><p>
            <hr />
            <h3>Running through posts</h3>
            <p>Posts made on this site are automatically added to this list for easy viewing. Skim through posts for dangerous posts, images, links etc and tick any you see that need removing before clicking "update" at the bottom of the page. Any <strong>not</strong> ticked will be marked as safe.</p>
            <p>Note: Posts that you flagged are hidden from the main site but remain in the comments table so flag a comment if you're not sure whether to or not to be on the safe side as it can be recovered. :)</p>
            <hr />
            <?php
            $query = "SELECT * FROM comments WHERE `status` != 'safe' ORDER BY commentNo DESC";
            mysql_query($query); 
            $result = mysql_query($query) or die(mysql_error());
            while($row = mysql_fetch_array($result)){
                if($row['status'] == 'unapproved'){
                $string = $row['comment'];
                
                $string = preg_replace('#\[img\]([^\[]*?)\[/img\]#', "<img src=\"$1\" style=\"max-width: 570;\"/>", $string); #img tag
                
                $string = preg_replace('#\[url\]([^\[]*?)\[/url\]#', "<a href=\"$1\">$1</a>", $string); #simple url tag
                $string = preg_replace('#\[url=([^\[]+?)\](.*?)\[/url\]#', "<a href=\"$1\">$2</a>", $string); #complex url tag

                $string = preg_replace('#\[colou?r=([a-zA-Z]*|\#[0-9a-fA-F]*)\](.*?)\[/colou?r\]#', "<span style=\"color: $1\">$2</font>", $string); #font colour tag

                $string = preg_replace('#\[b\](.*?)\[/b\]#ms', "<strong>$1</strong>", $string); #bold
                $string = preg_replace('#\[i\](.*?)\[/i\]#ms', "<em>$1</em>", $string); #italics
                $string = preg_replace('#\[u\](.*?)\[/u\]#ms', "<span style=\"text-decoration: underline\">$1</span>", $string); #underline
                If($row['smilies'] == 1){
                    $string = str_replace(">:(", "<img src = '/smilies/mad.gif' alt = '>:(' />", $string);
                    $string = str_replace(":)", "<img src = '/smilies/smile.gif' alt = ':)' />", $string);
                    $string = str_replace(":D", "<img src = '/smilies/biggrin.gif' alt = ':D' />", $string);
                    $string = str_replace(":angel:", "<img src = '/smilies/angel.gif' alt = '0:)' />", $string);
                    $string = str_replace("O_o", "<img src = '/smilies/blink.gif' alt = 'O_o' />", $string);
                    $string = str_replace("o_O", "<img src = '/smilies/blink.gif' alt = 'o_O' />", $string);
                    $string = str_replace(":wave:", "<img src = '/smilies/bye.gif' alt = ':waveface:' />", $string);
                    $string = str_replace(":cool:", "<img src = '/smilies/cool.gif' alt = ':coolface:' />", $string);
                    $string = str_replace("¬_¬", "<img src = '/smilies/dry.gif' alt = '¬_¬' />", $string);
                    $string = str_replace("v_v", "<img src = '/smilies/goodgrief.gif' alt = 'v_v' />", $string);
                    $string = str_replace(":huh:", "<img src = '/smilies/huh.gif' alt = ':huhface:' />", $string);
                    $string = str_replace(":laugh:", "<img src = '/smilies/laugh.gif' alt = ':laughface:' />", $string);
                    $string = str_replace(":lol:", "<img src = '/smilies/lol.gif' alt = ':lolface:' />", $string);
                    $string = str_replace("'-'", "<img src = '/smilies/mellow.gif' alt = ''-'' />", $string);
                    $string = str_replace(":o", "<img src = '/smilies/ohmy.gif' alt = ':o' />", $string);
                    $string = str_replace(":O", "<img src = '/smilies/ohmy.gif' alt = ':o' />", $string);
                    $string = str_replace(":rolleyes:", "<img src = '/smilies/rolleyes.gif' alt = ':rolleyesface:' />", $string);
                    $string = str_replace(":(", "<img src = '/smilies/sad.gif' alt = ':(' />", $string);
                    $string = str_replace(":#", "<img src = '/smilies/shy.gif' alt = ':#' />", $string);
                    $string = str_replace(":'(", "<img src = '/smilies/tears.gif' alt = ':\'(' />", $string);
                    $string = str_replace(":P", "<img src = '/smilies/tongue.gif' alt = ':P' />", $string);
                    $string = str_replace(":p", "<img src = '/smilies/tongue.gif' alt = ':P' />", $string);
                    $string = str_replace(":unsure:", "<img src = '/smilies/unsure.gif' alt = ':unsureface:' />", $string);
                    $string = str_replace(";)", "<img src = '/smilies/wink.gif' alt = ';)' />", $string);
                    
                    $image = ltrim(file_get_contents('http://scratch.mit.edu/api/getinfobyusername/' . $row['username']));
                    $startpos = nth_position($image, ":",1) + 1;
                    $endpos = nth_position($image, ":", 2);
                    $image = substr($image, $startpos, $endpos - $startpos);
                }
                echo "<div style = 'background-image:url(line.gif);background-repeat:repeat-x; height:5px;'>
                    &nbsp
                </div>
                <div style = 'position:relative;height:45px;top:5px;'>
                    <h5><a href = 'http://scratch.mit.edu/users/" . $row['username'] . "' target='_blank'><img src = 'http://scratch.mit.edu/static/icons/buddy/" . $image . "_sm.png' height = '30px' width = '30px' alt = 'User icon' border = '0'/></a> " . $row['username'] . " " . prettydate($row['epoch']) . "</h5>
                </div>
                <div style = 'position:relative;overflow-y:auto;'>
                    " . $string . "
                </div>";
                }
            }
            ?>
            <?php
    }
    else{
        echo "Sorry, ". $_SESSION['username'] . ". You're not allowed to view this section of the site as you need to be a block librarian to view use it. If you think you should have been able to enter, try logging in again by clicking <a href = 'admin.php'>here</a> or contact sparks <a href = 'http://scratch.mit.edu/forums/viewtopic.php?id=52709'>here</a>.</p>";
    }
}?>
    </div>

    
    
  </div> <!-- /node-inner -->
</div> <!-- /node-->          </div> <!-- /#content-area -->

          
          
          </div>
        </div> <!-- /content-inner /content -->

                  <div id="navigation" class="menu  with-sub-menu">
                        <ul id="secondary" class="links sub-menu"><li class="menu-404 first"><a href="http://scratch.mit.edu/download" title="Download the Scratch Software">Download</a></li>
<li class="menu-405"><a href="http://info.scratch.mit.edu/Donate" title="Support the Scratch Project">Donate</a></li>
<li class="menu-406"><a href="http://info.scratch.mit.edu/Privacy_Policy" title="">Privacy Policy</a></li>
<li class="menu-407"><a href="http://info.scratch.mit.edu/Terms_of_use" title="Information about the values of the Scratch Community">Terms of Use</a></li>

<li class="menu-408"><a href="/DMCA" title="">Copyright Policy</a></li>
<li class="menu-409 last"><a href="http://scratch.mit.edu/contact/us" title="">Contact Us</a></li>
</ul>          </div> <!-- /navigation -->
        
                  <div id="sidebar-first" class="column sidebar first">
            <div id="sidebar-first-inner" class="inner">
              <div id="block-locale-0" class="block block-locale odd left clearfix">
  <div class="block-inner">

    
    <div class="content">
        &nbsp
    </div>

    
  </div> <!-- /block-inner -->
</div> <!-- /block -->            </div>

          </div>
         <!-- /sidebar-left -->

         <!-- /sidebar-second -->

      </div> <!-- /main -->
<?php include("footer.php"); ?>

and so on. the error occurs in many of those documents. Can anyone see the problem?

Last edited by sparks (2012-01-26 14:32:38)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#928 2012-01-27 10:11:53

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Welcome to your local block library! - Website development thread.

Well, a few suggestions: Assign the $_GETs to actual variables. I also suggest cleaning up your code so it's readable and not mix the HTML and just have PHP echo the HTML code. The indents are also really wacky which makes it hard to know which section of code I'm dealing with (like an if statement, or a while loop).

Once the code is readable, it'll be easier to find all the problems.  smile

Offline

 

#929 2012-01-30 06:51:03

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Welcome to your local block library! - Website development thread.

Sigh. I can't log in to the site at the moment. Aparrantly the password is wrong. Which it isn't. It must have been changed, I've tried three FTP services and they all agree.


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#930 2012-01-30 07:08:40

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Welcome to your local block library! - Website development thread.

which is correct for linking to a page at the same address as the one you're currently on?

about.php

/about.php

or do they both work?


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#931 2012-01-30 07:12:33

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Welcome to your local block library! - Website development thread.

It would be:

about.php

I'm not entirely sure, but I think you can also use:

./about.php

Offline

 

#932 2012-01-30 07:15:18

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Welcome to your local block library! - Website development thread.

okay, thanks. I'm currently editing my local files of the library with the suggestions you made, since I can't upload them atm.


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#933 2012-01-30 07:19:13

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Welcome to your local block library! - Website development thread.

Magnie, when you say do not mix the HTML and PHP, do you mean I should do this:

Code:

<?php
$var1 = 1;
if(something){
     echo "text";
}
?>

or this:

Code:

<?php
$var1 = 1;
if(something){ ?>
     text
<?php } ?>

http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#934 2012-01-30 07:21:54

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Welcome to your local block library! - Website development thread.

I want to see the first one, not the second.  smile

Offline

 

#935 2012-01-30 07:59:41

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Welcome to your local block library! - Website development thread.

why? It makes HTML so much easier to debug because while in " marks it isn't colour coded!


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#936 2012-01-30 08:05:31

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Welcome to your local block library! - Website development thread.

sparks wrote:

why? It makes HTML so much easier to debug because while in " marks it isn't colour coded!

It's the PHP code that is having more problems than the HTML and having some problems with the HTML won't fall apart if there are some problems, unlike the PHP.

And it's really hard to read anyways.  hmm

Offline

 

#937 2012-01-30 08:14:12

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Welcome to your local block library! - Website development thread.

right. Take a look at this. I've edited the layout of this page to a more readable standard:

Code:

<?php 
session_start();
$title = 'Block Library | About'; 
include("header.php");
?>

<div id="main" class="clearfix">
    
    <div id="content">
        <div id="content-inner" class="inner column center">
            <div id="content-header">
                <div class="breadcrumb">
                    <a href="/">About</a>
                </div>
                <h1 class="title">About</h1>
            </div> <!-- /#content-header -->
          
            <div id="content-area">
                <div class="node node node-type-page" id="node-6">
                    <div class="node-inner">
                        <div class="content">
                            <table cellspacing="1" cellpadding="1" border="0" align="left" style="float: none; background-image: none; vertical-align: top; width: 100%; border-collapse: separate;">
                                <tbody style="vertical-align: top;">
                                    <tr>
                                        <td style="width: 70%;">
                                            <?php
                                            if(isset($_GET['librarian'])){
                                                include("connect.php");
                                                $librarian = $_GET['librarian'];
                                                $result = mysql_query("SELECT * FROM aboutme
                                                WHERE name='$librarian'");
                                                while($row = mysql_fetch_array($result)){
                                                    $aboutme = $row['text'];
                                                }
                                                echo '<p><a href = "about.php">Back</a></p>
                                                <h2>' . $librarian . '</h2>' . $aboutme;
                                            }
                                            if(!isset($_GET['librarian'])){
                                                echo '<p>Welcome to your block library! One of the most important and beloved features of Scratch are the blocks, and a great deal of time and effort has gone into making the blocks you see. When building Scratch, the team specifically designed the code so that it would be as easy as possible to add new blocks, and many people have done just that! This resource aims to bring together a collection of useful block code for experimenting Scratchers to try out and learn from, embracing the <i><font color = "blue">program</font></i> and <i><font color = "blue">share</font></i> parts of the Scratch Motto and hopefully letting users use what they learn here to <i><font color = "blue">imagine</font></i> their own blocks!</p>
                                                <h2>The people</h2>
                                                <ul>
                                                <li><a href = "about.php?librarian=sparks">Sparks (Miles Fletcher)</a> - Library Founder</li>
                                                </ul>
                                                <h3><strong>Librarians</strong></h3>
                                                <ul>
                                                <li><a href = "about.php?librarian=SSBBM">SSBBM</a></li>
                                                <li><a href = "about.php?librarian=Scimonster">Scimonster</a></li>
                                                <li><a href = "about.php?librarian=Pecola1">Pecola1</a></li>
                                                <li><a href = "about.php?librarian=meowmeow55">meowmeow55</a></li>
                                                <li><a href = "about.php?librarian=TheSuccessor">TheSuccessor</a></li>
                                                </ul>
                                                <h3>Site developers</h3>
                                                <ul>
                                                <li><a href = "about.php?librarian=ProgrammingFreak">ProgrammingFreak</a></li>
                                                <li>meowmeow55</li>
                                                <li><a href = "about.php?librarian=Magnie">Magnie</a></li>
                                                <li>TheSuccessor</li>
                                                </ul>
                                                <h2><strong>History</strong></h2>
                                                <p>The Block Library started life as a forum thread in the Scratch Advanced Topics forum created by the Scratch user Sparks on the 15th of July 2010. It consisted of a single post that contained marked sections for Scratch blocks. There were no images or ways to navigate. On the 19th of July BYOB and Panther blocks were supported and several blocks had been shared. Several people pushed to get the library I-Topic"d (a thread status that keeps a link to the thread at the top of the forum page). A "fossil" of the block library as it appeared on the 16th of  August can be found neatly preserved in <a href = "http://scratch.mit.edu/forums/viewtopic.php?pid=510230#p510230">stickdude123"s post</a>.</p>
                                                <p>On the 11th of September 2010 the Block Library was I-Topic"d by the community moderator Coolstuff and to celebrate, Sparks spent several weeks redesigning the layout of the entire library through suggestions by Scratchers to make the library easier to browse and use including the splitting of the first post into one post per block category on the 16th of September and new graphic navigation (as well as the library header logo still used today) designed by nXIII.</p>
                                                <p>By March Sparks was struggling to keep the library updated due to a huge flood of block submissions. On the 16th of March Coolstuff, fullmoon and Lighnin moved the I-Topic status from the old library thread to a new one created on a shared Scratch account called "YourLocalBlockLib", an account shared by Sparks, meowmeow55, Pecola1, SSBBM, TheSucessor and Scimonster.</p>
                                                <p>On the 15th of July the library website was officially hosted and moved to the blocks.scratchr.org domain thanks to Andr&eacute;s and Amos from the Scratch Team.</p>';
                                            } ?>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>

    
                    </div> <!-- /node-inner -->
                </div> <!-- /node-->
            </div> <!-- /#content-area -->
        </div>
    </div> <!-- /content-inner /content -->

    <div id="navigation" class="menu  with-sub-menu">
        <ul id="secondary" class="links sub-menu">
            <li class="menu-404 first">
                <a href="http://scratch.mit.edu/download" title="Download the Scratch Software">Download</a>
            </li>
            <li class="menu-405">
                <a href="http://info.scratch.mit.edu/Donate" title="Support the Scratch Project">Donate</a>
            </li>
            <li class="menu-406">
                <a href="http://info.scratch.mit.edu/Privacy_Policy" title="">Privacy Policy</a>
            </li>
            <li class="menu-407">
                <a href="http://info.scratch.mit.edu/Terms_of_use" title="Information about the values of the Scratch Community">Terms of Use</a>
            </li>
            <li class="menu-408">
                <a href="/DMCA" title="">Copyright Policy</a>
            </li>
            <li class="menu-409 last">
                <a href="http://scratch.mit.edu/contact/us" title="">Contact Us</a>
            </li>
        </ul>          
    </div> <!-- /navigation -->
        
    <div id="sidebar-first" class="column sidebar first">
        <div id="sidebar-first-inner" class="inner">
            <div id="block-locale-0" class="block block-locale odd left clearfix">
                <div class="block-inner">
                    <div class="content">
                        &nbsp
                    </div>
                </div> <!-- /block-inner -->
            </div> <!-- /block -->
        </div>
    </div><!-- /sidebar-left -->
<!-- /sidebar-second -->
</div> <!-- /main -->
<?php include("footer.php"); ?>

surprisingly, a lot of the layering problems (such as two </div>'s on one line were in the parts of the code I nicked from the Scratch site!


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#938 2012-01-30 08:41:20

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Welcome to your local block library! - Website development thread.

Yeah, that's a lot easier to read. But I just realized, have we had any problems with the about.php page?  tongue

I think it was admin.php that was having the problems, right?

Offline

 

#939 2012-01-30 09:07:17

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Welcome to your local block library! - Website development thread.

It was any page with SQL in it. However, I've decided I may as well sort out the layout on all these pages and use the correct echoing and speech marks.


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#940 2012-01-30 11:43:48

rookwood101
Scratcher
Registered: 2011-07-29
Posts: 500+

Re: Welcome to your local block library! - Website development thread.

so the url for the mysql is mysql.blocks.scratchr.org?


http://i.imgur.com/zeIZW.png

Offline

 

#941 2012-01-30 11:57:15

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Welcome to your local block library! - Website development thread.

yes


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#942 2012-01-30 15:06:22

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Welcome to your local block library! - Website development thread.

Andres had changed the password... I'm in!


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#943 2012-01-30 15:36:10

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Welcome to your local block library! - Website development thread.

Does anyone else find the entire blocks.scratchr.org site loads very slowly? Even pages like the index without any PHP in them?


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#944 2012-01-30 15:45:34

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Welcome to your local block library! - Website development thread.

Right. The "updateAbout.php" page (moderators only) is still not working. There are no POST or GET variables entered directly into the MySQL queries at all but there is still nothing happening all the time. Please see if you can spot the problem!

Excerpt from updateAbout.php

Code:

<h1 class="title">Librarians' log book</h1>
            </div> <!-- /#content-header -->
            <div id="content-area">
                <div class="node node node-type-page" id="node-6">
                    <div class="node-inner">
                        <div class="content">
                            <table cellspacing="1" cellpadding="1" border="0" align="left" style="float: none; background-image: none; vertical-align: top; width: 100%; border-collapse: separate;">
                                <tbody style="vertical-align: top;">
                                    <tr>
                                        <td style="width: 70%;">
                                            <?php
                                            if(!isset($_SESSION['username'])){
                                                echo "<p>You need to be logged in as a Librarian to view this page. <a href = 'admin.php'>Login</a></p>";
                                            }
                                            if(isset($_SESSION['username'])){
                                                if($_SESSION['username'] == 'sparks' | $_SESSION['username'] == 'meowmeow55' | $_SESSION['username'] == 'TheSuccessor' | $_SESSION['username'] == 'Magnie' | $_SESSION['username'] == 'Pecola1' | $_SESSION['username'] == 'scimonster' | $_SESSION['username'] == 'SSBBM' | $_SESSION['username'] == 'ProgrammingFreak' | $_SESSION['username'] == 'Greenatic'){
                                                    echo '<p><a href = "/admin.php/">Back to main area</a></p>';
                                                    include("connect.php");
                                                    $about = $_POST['about'];
                                                    $adminUsername = $_SESSION['username'];
                                                    if(isset($_POST['updateaboutme'])){
                                                        mysql_query("UPDATE aboutme SET text = '$about'
                                                        WHERE name = '$adminUsername'");
                                                        echo '<p>Updated about me message for $adminUsername </p><hr />';
                                                    }        
                                                    $result = mysql_query("SELECT * FROM aboutme
                                                    WHERE name='$adminUsername'");
                                                    while($row = mysql_fetch_array($result)){
                                                        $aboutme = $row['text'];
                                                    }
                                                    echo '<h2>"about me" message for ' . $adminUsername . '</h2>
                                                    <p>This is the HTML that appears on your library "about" page. You may use HTML. Images, links and content should be in keeping with the Scratch community guidelines. 
                                                    <br/>
                                                    <font color = "#FF0000">WARNING - for some reason updates don\'t always update. I strongly recomment copying your update before updating in case it fails ~ Sparks</font></p>
                                                    <form name = "aboutme" method = "post" action = "updateAbout.php">
                                                    <textarea name = "about" rows = 5 cols = 90>' . $aboutme . '</textarea>
                                                    <input type = "submit" name = "updateaboutme" value = "update" />
                                                    </form>';
                                                }
                                            } ?>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div> <!-- /node-inner -->
                </div> <!-- /node-->          
            </div> <!-- /#content-area -->

connect.php (include()ed file[/b]

Code:

<?php
mysql_connect("mysql.blocks.scratchr.org", "USERNAME", "PASSWORD") or die(mysql_error());
mysql_select_db("scratchrblocks") or die(mysql_error()); ?>

this is frustrating me so much!


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#945 2012-01-30 15:50:49

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Welcome to your local block library! - Website development thread.

The login doesn't seem to work.  hmm  Login page code please?  big_smile

Offline

 

#946 2012-01-30 15:59:12

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Welcome to your local block library! - Website development thread.

try now. I accidentally replaced a $_SESSION variable I was SETTING rather than reading.


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#947 2012-01-30 16:07:35

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Welcome to your local block library! - Website development thread.

Hmm, updating stuff seems to work just fine.  hmm

Offline

 

#948 2012-01-30 16:18:54

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Welcome to your local block library! - Website development thread.

it didn't for me...


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#949 2012-01-30 16:29:28

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Welcome to your local block library! - Website development thread.

sparks wrote:

it didn't for me...

Which, comments or about page? I made a comment and edited my about page 2 times.

Offline

 

#950 2012-01-30 16:32:33

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Welcome to your local block library! - Website development thread.

Humm. I made one comment and the second didn't work. I tried updating about once and it didn't work so clearly there is still a problem (we're back on the blocks SQL server, btw)

EDIT: I updated the prettydate system on my own site so I've brought that across to this site too now!

EDIT: looks like I need to update the commenting system to accept the prettydate too  tongue

Last edited by sparks (2012-01-30 16:36:06)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

Board footer