Changeset 59

Show
Ignore:
Timestamp:
27/05/05 22:50:39 (4 years ago)
Author:
rollercow
Message:

Moved admin bits from blog to admin,

WTF has dave done to add comment?

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • admin.lib.php

    r54 r59  
    162162                echo "</div>\n"; 
    163163        } 
     164         
     165        // post an entry to the db 
     166        function postEntry() 
     167        { 
     168                $category = ''; 
     169                $subject = ''; 
     170                $body = ''; 
     171                $err = 0; 
     172 
     173                //sanitise category (make sure it IS a number!) 
     174                if (isset($_POST['category']) && trim($_POST['category']) != "" && (int)$_POST['category'] == 0) { 
     175                        $category = (int)$_POST['category']; 
     176                } else { 
     177                        $this->entryError = _("Undefined Category!"); 
     178                        //error(4,_("Undefined Category.")); 
     179                        $err = 1; 
     180                } 
     181 
     182                //sanitise subject (make sure its not a number!) 
     183                if (isset($_POST['subject']) && trim($_POST['subject']) != "" && (int)$_POST['category'] != 0) { 
     184                        $subject = $_POST['subject']; 
     185                } else { 
     186                        $this->entryError = _("No Subject!"); 
     187                        //error(4,_("No Subject!")); 
     188                        $err = 1; 
     189                } 
     190                         
     191                //sanitise body 
     192                if (isset($_POST['body']) && trim($_POST['body']) != "") { 
     193                        $body = $_POST['body']; 
     194                } else { 
     195                        $this->entryError = _("No Entry!"); 
     196                        //error(4,_("No Entry!")); 
     197                        $err = 1; 
     198                } 
     199 
     200                if ($err == 0) { 
     201                        $shortsubject = makeCleanString($subject); 
     202                 
     203                        // need to check title existence and do the nescessary. 
     204                        $sql = db_query("SELECT shortsubject from entries where user_id = ".$this->id." and (shortsubject = '".$shortsubject."' or shortsubject like '%".$shortsubject."%!_%'escape'!';"); //we're matching == anything-like-this*_ 
     205                        $sqlNum = db_num_rows($sql); 
     206                        if ($sqlNum != 0) { 
     207                                $shortsubject .= $sqlNum; // format this-is-a-title1_ (the _ is so we can LIKE match it.) 
     208                        } 
     209                 
     210                        if (!db_query("INSERT INTO entries (category, subject, shortsubject, body) VALUES ({$category},'{add_slashes($subject)}','{$shortsubject}','{add_slashes($body)}')")) { 
     211                                error(2,"Database commit failed - ".db_error()); 
     212                        } else { 
     213                                // we want to display the post? maybe we just want to return to the page, but this will display it for now :) 
     214                                $sql = db_getrow(db_query("SELECT id from entries where user_id = ".$this->id." and shortsubject = '".$shortsubject."';")); 
     215                                 
     216                                $this->printEntry(shortSubjectToID($shortsubject)); 
     217                        } 
     218                }                
     219        } 
     220         
     221        //update an entry in the db, possibly the body or the post will be updated 
     222        function updateEntry($id) 
     223        {                
     224                $category = ''; 
     225                $subject = ''; 
     226                $body = ''; 
     227                $err = 0; 
     228 
     229                //sanitise category (make sure it IS a number!) 
     230                if (isset($_POST['category']) && trim($_POST['category']) != "" && (int)$_POST['category'] == 0) { 
     231                        $category = (int)$_POST['category']; 
     232                } else { 
     233                        error(4,_("Undefined Category.")); 
     234                        $err = 1; 
     235                } 
     236 
     237                //sanitise subject (make sure its not a number!) 
     238                if (isset($_POST['subject']) && trim($_POST['subject']) != "" && (int)$_POST['subject'] != 0) { 
     239                        $subject = $_POST['subject']; 
     240                } else { 
     241                        error(4,_("No Subject!")); 
     242                        $err = 1; 
     243                } 
     244                         
     245                //sanitise body 
     246                if (isset($_POST['body']) && trim($_POST['body']) != "") { 
     247                        $body = $_POST['body']; 
     248                } else { 
     249                        error(4,_("No Entry!")); 
     250                        $err = 1; 
     251                } 
     252 
     253                if ($err == 0) { 
     254                        $sql = db_query("SELECT id from entries where id = ".$id."';"); 
     255                        $sqlNum = db_num_rows($sql); 
     256                        if ($sqlNum != 0) { //existio? 
     257                                $sql = db_query("UPDATE entries SET (category, subject, body) = ({$category},'{add_slashes($subject)}','{add_slashes($body)}') WHERE id = '{$id}';"); 
     258                                 
     259                                $this->printEntry($id); //printenate it 
     260                                 
     261                        } else { 
     262                                 error(2,_("Cannot update entry - It never existed!".db_error())); 
     263                        }        
     264                } else { 
     265                        error(4,_("You can't change it to be blank :)")); 
     266                } 
     267                 
     268         
     269        } 
     270         
     271        // this will... uh ... print the blog Entry form... 
     272        function printEntryForm()  
     273        { 
     274                echo "<div class=\"entry\">\n"; 
     275                echo "<h2>Write Entry</h2>\n"; 
     276                echo "<form action=\"".$this->blogPath."postentry\" method=\"post\" id=\"entryform\">\n"; 
     277                echo "<p>\n"; 
     278                echo "<input type=\"text\" name=\"subject\" id=\"subject\" value=\"" . (($this->entryError != "") ? strip_tags(trim($_POST['subject'])) : "") . "\" size=\"22\" maxlength=\"50\" tabindex=\"1\" />\n"; 
     279                echo "<label for=\"subject\">Subject</label>\n"; 
     280                echo "</p>\n"; 
     281                echo "<p>\n"; 
     282                // lookup... category...? 
     283                echo "<select name=\"category\" id=\"category\">"; 
     284                $sql = db_query("SELECT name FROM categories"); 
     285                while ($sqlRow = db_getrow($sql)) { 
     286                        echo "<option value=\"{$sqlRow['name']}\">{$sqlRow['name']}</option>"; 
     287                        } 
     288                echo "</select>"; 
     289                //echo "<input type=\"text\" name=\"category\" id=\"category\" value=\"" . (($this->entryError != "") ? strip_tags(trim($_POST['category'])) : "") . "\" size=\"22\" maxlength=\"70\" tabindex=\"2\" />\n"; 
     290                echo "<label for=\"category\">Category</label>\n"; 
     291                echo "</p>\n"; 
     292                echo "<p>\n"; 
     293                echo "<textarea name=\"entry\" id=\"entry\" cols=\"50\" rows=\"10\" tabindex=\"3\">" . (($this->entryError != "") ? strip_tags($_POST['comment'],$entryTags) : "") . "</textarea>\n"; 
     294                echo "</p>\n"; 
     295                echo "<p>\n"; 
     296                echo "<input name=\"submit\" type=\"submit\" id=\"submit\" tabindex=\"4\" value=\"Submit Entry\" />\n"; 
     297                echo "</p>\n"; 
     298                echo "</form>\n"; 
     299                echo "</div>\n"; 
     300                echo "</div>\n"; 
     301        } 
    164302} 
  • blog.lib.php

    r58 r59  
    88$db_type = "pgsql"; 
    99require_once("database.lib.php"); 
     10 
    1011// Some useful validation functions 
    1112require_once("validation.lib.php"); 
     
    2324        echo("Level ".$level." error - ".$error); 
    2425} 
     26 
    2527//Our Blogs Class 
    2628class blogs { 
    27         var $id;                       //Blog ID 
    28         var $userName; //Blogger's User Name 
    29         var $realName;         //Blogger's Real Name 
    30         var $title;                    //Blog Title 
    31         var $description;      //Blog Blurb 
    32         var $cssFile;          //Blog CSS 
    33         var $shortDateFormat;          //Short date format 
    34         var $longDateFormat;           //Long date format 
    35         var $httpPath;         //http Path for files 
    36         var $blogPath;         //path to blog 
    37         var $commentError; //new comment errors 
     29        var $id;//Blog ID 
     30        var $userName; //Blogger's User Name 
     31        var $realName; //Blogger's Real Name 
     32        var $title; //Blog Title 
     33        var $description; //Blog Blurb 
     34        var $cssFile; //Blog CSS 
     35        var $shortDateFormat; //Short date format 
     36        var $longDateFormat; //Long date format 
     37        var $httpPath; //http Path for files 
     38        var $blogPath; //path to blog 
     39        var $commentError; //new comment errors 
    3840        var $entryError; //new entry errors 
    3941        var $entryTags; //what we allow in the entry 
     
    4850                $sql = db_query("SELECT id, name, title, description, css from users where username = '".$user."' and enabled = true;"); 
    4951                $sqlNum = db_num_rows($sql); 
    50                 if ($sqlNum != 1) 
    51                 { 
     52                if ($sqlNum != 1) { 
    5253                        error(1,"No such user"); 
    5354                } 
    54                 else 
    55                 { 
     55                else    { 
    5656                        $sqlRow = db_getrow($sql); 
    5757                        $this->id = $sqlRow['id']; 
     
    7575        { 
    7676                echo "<div class=\"entry\">\n"; 
    77                 if ($titleLink)  
    78                 {                
     77                if ($titleLink) {                
    7978                        echo "<h2><a href=\"{$this->blogPath}entry/{$row['shortsubject']}\">{$row['subject']}</a></h2>\n"; 
    8079                } 
    81                 else 
    82                 { 
     80                else    { 
    8381                        echo "<h2>{$row['subject']}</h2>\n"; 
    8482                } 
     
    8785                echo "</div>\n"; 
    8886                echo "<p class=\"entryfoot\">[ Entry posted at: ".strftime($this->longDateFormat,strtotime($row['timestamp'])); 
    89                 if ($commentLink)  
    90                 {  
     87                if ($commentLink) {  
    9188                        echo " | <a href=\"".$this->blogPath."entry/{$row['shortsubject']}\">Comments</a>: ".$this->commentCount($row['id']); 
    9289                } 
     
    104101                $sql = db_query("SELECT id, category, subject, body, timestamp, shortsubject from entries where user_id = '".$this->id."' ".$constraint." order by timestamp desc limit ".$limit." offset ".$offset.";"); 
    105102                $sqlNum = db_num_rows($sql); 
    106                 if ($sqlNum < 1) 
    107                 { 
     103                if ($sqlNum < 1) { 
    108104                        error(5,"No relevant posts"); 
    109105                } 
    110                 else 
    111                 { 
     106                else    { 
    112107                        while ($sqlRow = db_getrow($sql)) { 
    113108                                $this->printEntry($sqlRow); 
     
    119114        function printEntryAndComments($id)  
    120115        { 
    121         $id  = $this->makeCleanString($id); 
     116               $id  = $this->makeCleanString($id); 
    122117                $sql = db_query("SELECT id, category, subject, body, timestamp from entries where shortsubject='".$id."' and user_id = ".$this->id." LIMIT 1;"); 
    123118                $sqlNum = db_num_rows($sql); 
    124                 if ($sqlNum != 1) 
    125                 { 
     119                if ($sqlNum != 1) { 
    126120                        error(5,"No relevant posts"); 
    127121                } 
    128                 else 
    129                 { 
     122                else    { 
    130123                        $sqlRow = db_getrow($sql); 
    131124                        $this->printEntry($sqlRow, false, false); 
     
    133126                        $this->printCommentForm($id); 
    134127                } 
    135                  
    136128        } 
    137129 
     
    141133                $sql = db_query("SELECT timestamp, name, email, body, host FROM comments WHERE post = ".$postid."  ORDER BY timestamp ASC limit ".$limit." OFFSET ".$offset.";"); 
    142134                $sqlNum = db_num_rows($sql); 
    143                 if ($sqlNum < 1) 
    144                 { 
     135                if ($sqlNum < 1) { 
    145136                        error(5,"No relevent comments"); 
    146137                } 
    147                 else 
    148                 { 
     138                else { 
    149139                        while ($sqlRow = db_getrow($sql)) { 
    150140                                $this->printComment($sqlRow); 
     
    156146        function printComment($row)  
    157147        { 
    158         echo "<div class=\"blogcomment\">\n"; 
     148               echo "<div class=\"blogcomment\">\n"; 
    159149                echo "<h3>" . $row['name'] . " writes:</h3>"; 
    160150                echo "<p>" . $row['body'] . "</p>\n"; 
    161151                echo "<p class=\"entryfoot\">[ " .strftime($this->longDateFormat,strtotime($row['timestamp'])). " ]</p>\n"; 
    162         echo "</div>\n"; 
     152               echo "</div>\n"; 
    163153        } 
    164154 
     
    184174                echo "<h2>Add Comment<a id=\"cmt\"></a></h2>\n"; 
    185175                echo "<div class=\"td\">\n"; 
    186                 if ($this->commentError != "")  
    187                 { 
     176                if ($this->commentError != "") { 
    188177                        echo "<p class=\"invalid\">*** " . $this->commentError . " ***</p>\n"; 
    189178                } 
    190                 elseif (isset($_POST['submit']))  
    191                 { 
     179                elseif (isset($_POST['submit'])) { 
    192180                        echo "<p>Thank you for your comment</p>\n"; 
    193181                } 
     
    226214        function newComment($id)  
    227215        { 
    228         $id  = $this->makeCleanString($id); 
     216               $id  = $this->makeCleanString($id); 
    229217 
    230218                $author = ""; 
     
    242230                        $comment = addslashes(nl2br(trim(strip_tags($_POST['comment'])))); 
    243231                }  
    244                 else  
     232                else
    245233                        $this->commentError = "Please check the comment field"; 
    246234                } 
     
    249237                        $email = addslashes(trim($_POST['email'])); 
    250238                } 
    251                 else  
     239                else
    252240                        $this->commentError = "Check email address"; 
    253241                } 
     
    256244                        $author = addslashes(nl2br(trim(strip_tags($_POST['author'])))); 
    257245                }  
    258                 else  
     246                else
    259247                        $this->commentError = "Check your name."; 
    260248                } 
     
    263251                $sqlNum = db_num_rows($sql); 
    264252                $row = db_getrow($sql); 
    265         $entry_id = $row['id']; 
    266                 if ($sqlNum != 1 || $entry_id<=0) 
    267                 { 
     253                $entry_id = $row['id']; 
     254                if ($sqlNum != 1 || $entry_id<=0) { //wtf? 
    268255                        $this->commenterror = "Invalid blog entry, This entry may have been removed..?"; 
    269256                } 
    270         //if no errors have been raised so far commit to the db 
     257               //if no errors have been raised so far commit to the db 
    271258                if ($this->commentError == "") { 
    272             $query = "INSERT INTO comments (post, name, email, body, host) VALUES ('{$entry_id}','{$author}','{$email}','{$comment}','{$host}')"; 
     259                       $query = "INSERT INTO comments (post, name, email, body, host) VALUES ('{$entry_id}','{$author}','{$email}','{$comment}','{$host}')"; 
    273260                        if(!db_query($query)) { 
    274261                                error(2,"Database commit failed -".db_error()); 
     
    276263                } 
    277264                $this->printEntryAndComments($id); 
    278         } 
    279          
    280         // post an entry to the db 
    281         function postEntry() 
    282         { 
    283                 $category = ''; 
    284                 $subject = ''; 
    285                 $body = ''; 
    286                 $err = 0; 
    287  
    288                 //sanitise category (make sure it IS a number!) 
    289                 if (isset($_POST['category']) && trim($_POST['category']) != "" && (int)$_POST['category'] == 0) { 
    290                         $category = (int)$_POST['category']; 
    291                 } else { 
    292                         $this->entryError = _("Undefined Category!"); 
    293                         //error(4,_("Undefined Category.")); 
    294                         $err = 1; 
    295                 } 
    296  
    297                 //sanitise subject (make sure its not a number!) 
    298                 if (isset($_POST['subject']) && trim($_POST['subject']) != "" && (int)$_POST['category'] != 0) { 
    299                         $subject = $_POST['subject']; 
    300                 } else { 
    301                         $this->entryError = _("No Subject!"); 
    302                         //error(4,_("No Subject!")); 
    303                         $err = 1; 
    304                 } 
    305                          
    306                 //sanitise body 
    307                 if (isset($_POST['body']) && trim($_POST['body']) != "") { 
    308                         $body = $_POST['body']; 
    309                 } else { 
    310                         $this->entryError = _("No Entry!"); 
    311                         //error(4,_("No Entry!")); 
    312                         $err = 1; 
    313                 } 
    314  
    315                 if ($err == 0) { 
    316                         $shortsubject = makeCleanString($subject); 
    317                  
    318                         // need to check title existence and do the nescessary. 
    319                         $sql = db_query("SELECT shortsubject from entries where user_id = ".$this->id." and (shortsubject = '".$shortsubject."' or shortsubject like '%".$shortsubject."%!_%'escape'!';"); //we're matching == anything-like-this*_ 
    320                         $sqlNum = db_num_rows($sql); 
    321                         if ($sqlNum != 0) { 
    322                                 $shortsubject .= $sqlNum; // format this-is-a-title1_ (the _ is so we can LIKE match it.) 
    323                         } 
    324                  
    325                         if (!db_query("INSERT INTO entries (category, subject, shortsubject, body) VALUES ({$category},'{add_slashes($subject)}','{$shortsubject}','{add_slashes($body)}')")) { 
    326                                 error(2,"Database commit failed - ".db_error()); 
    327                         } else { 
    328                                 // we want to display the post? maybe we just want to return to the page, but this will display it for now :) 
    329                                 $sql = db_getrow(db_query("SELECT id from entries where user_id = ".$this->id." and shortsubject = '".$shortsubject."';")); 
    330                                  
    331                                 $this->printEntry(shortSubjectToID($shortsubject)); 
    332                         } 
    333                 }                
    334         } 
    335          
    336         //update an entry in the db, possibly the body or the post will be updated 
    337         function updateEntry($id) 
    338         {                
    339                 $category = ''; 
    340                 $subject = ''; 
    341                 $body = ''; 
    342                 $err = 0; 
    343  
    344                 //sanitise category (make sure it IS a number!) 
    345                 if (isset($_POST['category']) && trim($_POST['category']) != "" && (int)$_POST['category'] == 0) { 
    346                         $category = (int)$_POST['category']; 
    347                 } else { 
    348                         error(4,_("Undefined Category.")); 
    349                         $err = 1; 
    350                 } 
    351  
    352                 //sanitise subject (make sure its not a number!) 
    353                 if (isset($_POST['subject']) && trim($_POST['subject']) != "" && (int)$_POST['subject'] != 0) { 
    354                         $subject = $_POST['subject']; 
    355                 } else { 
    356                         error(4,_("No Subject!")); 
    357                         $err = 1; 
    358                 } 
    359                          
    360                 //sanitise body 
    361                 if (isset($_POST['body']) && trim($_POST['body']) != "") { 
    362                         $body = $_POST['body']; 
    363                 } else { 
    364                         error(4,_("No Entry!")); 
    365                         $err = 1; 
    366                 } 
    367  
    368                 if ($err == 0) { 
    369                         $sql = db_query("SELECT id from entries where id = ".$id."';"); 
    370                         $sqlNum = db_num_rows($sql); 
    371                         if ($sqlNum != 0) { //existio? 
    372                                 $sql = db_query("UPDATE entries SET (category, subject, body) = ({$category},'{add_slashes($subject)}','{add_slashes($body)}') WHERE id = '{$id}';"); 
    373                                  
    374                                 $this->printEntry($id); //printenate it 
    375                                  
    376                         } else { 
    377                                  error(2,_("Cannot update entry - It never existed!".db_error())); 
    378                         }        
    379                 } else { 
    380                         error(4,_("You can't change it to be blank :)")); 
    381                 } 
    382                  
    383          
    384         } 
    385          
    386         // this will... uh ... print the blog Entry form... 
    387         function printEntryForm()  
    388         { 
    389                 echo "<div class=\"entry\">\n"; 
    390                 echo "<h2>Write Entry</h2>\n"; 
    391                 echo "<form action=\"".$this->blogPath."postentry\" method=\"post\" id=\"entryform\">\n"; 
    392                 echo "<p>\n"; 
    393                 echo "<input type=\"text\" name=\"subject\" id=\"subject\" value=\"" . (($this->entryError != "") ? strip_tags(trim($_POST['subject'])) : "") . "\" size=\"22\" maxlength=\"50\" tabindex=\"1\" />\n"; 
    394                 echo "<label for=\"subject\">Subject</label>\n"; 
    395                 echo "</p>\n"; 
    396                 echo "<p>\n"; 
    397                 // lookup... category...? 
    398                 echo "<select name=\"category\" id=\"category\">"; 
    399                 $sql = db_query("SELECT name FROM categories"); 
    400                 while ($sqlRow = db_getrow($sql)) { 
    401                         echo "<option value=\"{$sqlRow['name']}\">{$sqlRow['name']}</option>"; 
    402                         } 
    403                 echo "</select>"; 
    404                 //echo "<input type=\"text\" name=\"category\" id=\"category\" value=\"" . (($this->entryError != "") ? strip_tags(trim($_POST['category'])) : "") . "\" size=\"22\" maxlength=\"70\" tabindex=\"2\" />\n"; 
    405                 echo "<label for=\"category\">Category</label>\n"; 
    406                 echo "</p>\n"; 
    407                 echo "<p>\n"; 
    408                 echo "<textarea name=\"entry\" id=\"entry\" cols=\"50\" rows=\"10\" tabindex=\"3\">" . (($this->entryError != "") ? strip_tags($_POST['comment'],$entryTags) : "") . "</textarea>\n"; 
    409                 echo "</p>\n"; 
    410                 echo "<p>\n"; 
    411                 echo "<input name=\"submit\" type=\"submit\" id=\"submit\" tabindex=\"4\" value=\"Submit Entry\" />\n"; 
    412                 echo "</p>\n"; 
    413                 echo "</form>\n"; 
    414                 echo "</div>\n"; 
    415                 echo "</div>\n"; 
    416265        } 
    417266