[ PHPXref.com ] [ Generated: Sun Jul 20 19:19:21 2008 ] [ Parasite 1.0.2 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/ -> functions.php (source)

   1  <?
   2  $GLOBALS['functionsversion']='1.0.2';
   3  require_once( 'DB.php' );
   4  if ( ! class_exists("DB") ){
   5      print("Error: PEAR::DB not found.\n");
   6      exit;
   7  }
   8  
   9  $GLOBALS['defaults']['limit']=5;
  10  $GLOBALS['defaults']['title']="Parasite Weblog";
  11  $GLOBALS['defaults']['url']="http://www.example.com/parasite/";
  12  $GLOBALS['defaults']['cssfile']=$defaults['url']."parasite.css";
  13  $GLOBALS['defaults']['articleurl']=$defaults['url']."article";
  14  $GLOBALS['defaults']['pingback']='1';
  15  $GLOBALS['defaults']['pingbackstr']='checked="checked"';
  16  $GLOBALS['defaults']['useweblogping']='1';
  17  $GLOBALS['defaults']['useweblogpingstr']='checked="checked"';
  18  $GLOBALS['defaults']['description']="My Little Parasite";
  19  $GLOBALS['defaults']['defaultuser']='Mr. Magic';
  20  $GLOBALS['defaults']['usearticletitles']='1';
  21  $GLOBALS['defaults']['usearticletitlesstr']='checked="checked"';
  22  $GLOBALS['defaults']['rssv2']='1';
  23  $GLOBALS['defaults']['rssv2str']='checked="checked"';
  24  $GLOBALS['defaults']['rssv2limit']='5';
  25  $GLOBALS['defaults']['rssimgurl']='http://www.example.com/parasite/rssimg.png';
  26  $GLOBALS['defaults']['articledefinition']='
  27  <div class="articlecontainer">
  28      <div class="ah">
  29          <a name="|thisarticlenumber|"></a>
  30          <div class="articletitle">|thisarticletitle|</div>
  31          <div class="date">|thisarticledate|</div>
  32          <div class="user">by |thisarticleuser|</div>
  33      </div>
  34      <div class="article">
  35          |thisarticlebody|
  36          <div class="permalink">
  37              |thisarticlepermalink|
  38          </div>
  39          <div class="pingbacks">
  40              |thisarticlepingbacktotal|
  41          </div>
  42          <div class="|pingbackclass|" id="|thisarticlepingbackid|" style="display:none;">
  43              |thisarticlepingbacklist| 
  44          </div>
  45      </div>
  46  </div>
  47  ';
  48  $GLOBALS['defaults']['pingbacktotaldefinition']='
  49  <a href="#" onclick="makevis(\'|thisarticlenumber|pingbacks\'); return false;" title="Pingbacks for |thisarticletitle|">pingbacks: |pingbacktotal|</a>
  50  ';
  51  $GLOBALS['defaults']['pingbacklistdefinition']='
  52      <a href="|thispingbackremoteurl|" title="|thispingbackremotetitle|">|thispingbackremotetitle|</a>, |thispingbacktime| <br />
  53  ';
  54  
  55  $GLOBALS['config']['dbstring'] = $GLOBALS['config']['dbtype'].'://'.$GLOBALS['config']['dbuser'].':'.$GLOBALS['config']['dbpass'].'@'.$GLOBALS['config']['dbhost'].'/'.$GLOBALS['config']['dbname'];
  56  getconfig();
  57  if ( $GLOBALS['config']['pingback'] == 1 || $GLOBALS['config']['useweblogping'] == 1 ){
  58      include ("xmlrpc.php");
  59  }
  60  
  61  $GLOBALS['config']['limitconstant']=$GLOBALS['config']['limit'];
  62  $GLOBALS['config']['pingbackserver']=$GLOBALS['config']['url'].'pingback.php';
  63  $GLOBALS['config']['articleurl']=$GLOBALS['config']['url'].'article';
  64  
  65  /* 
  66      This function does the initial entry of an article into the database.
  67      It is used by the maintenence page.
  68      DB structure:
  69                time,body,visible,username,id,title
  70  */
  71  
  72  function 
  73  publish_article($time,$body,$visible,$user,$arttitle,$pingbackcheck){
  74      $error = '';
  75      $db = DB::connect( $GLOBALS['config']['dbstring'] );
  76      // A whole extra table that creates weird sync issues? No thanks.
  77      //$ID = $db->nextID('id',TRUE);
  78      $ID = getmaxid($db);
  79      $ID++;
  80      if ( $usearticletitles == 1 ){
  81          $sql="INSERT INTO articles VALUES ('$time','$body','$visible','$user','$ID','$arttitle')";
  82      }else{
  83          $sql="INSERT INTO articles VALUES ('$time','$body','$visible','$user','$ID','$arttitle')";
  84      }
  85      $result=$db->query($sql) or die($sql);
  86      if ( $GLOBALS['config']['pingback'] == 1 && $visible == 1 && $pingbackcheck == 1 ){
  87          $sql="SELECT id FROM articles where TIME=$time";
  88          $result = $db->query($sql) or die( $sql );
  89          $id = $result->fetchRow();
  90          $id = $id[0];
  91          $error = pingbackcheck($body,$id);
  92      }
  93      $db->disconnect();
  94      return $error;
  95  }
  96  
  97  
  98  /* 
  99      This function updates the content of a specific article
 100      identified by ID. It is used by the post-submission editor.
 101      DB structure:
 102                    time,body,visible,username,id,title
 103  */
 104  
 105  function 
 106  update_article($id,$body,$user,$arttitle,$vis,$pingback){
 107      $db = DB::connect( $GLOBALS['config']['dbstring'] );
 108      $sql="UPDATE articles SET body='$body' WHERE id=$id";
 109      $result=$db->query($sql) or die($sql);
 110      $sql="UPDATE articles SET username='$user' WHERE id=$id";
 111      $result=$db->query($sql) or die($sql);
 112      if ( $GLOBALS['config']['usearticletitles'] == 1 ){
 113          $sql="UPDATE articles SET title='$arttitle' WHERE id=$id";
 114          $result=$db->query($sql) or die($sql);
 115      }
 116      if ( $GLOBALS['config']['pingback'] == 1 && $pingback == 1 && $vis == 1 ){
 117          $error = pingbackcheck($body,$id);
 118      }
 119      $db->disconnect();
 120      return $error;
 121  }
 122  
 123  
 124  /* 
 125      This function updates the time-stamp associated with a specific article
 126      identified by ID. It is used by the post-submission editor.
 127      Since version 0.5 this function is no longer used. It seems a bit
 128      pointless to update a timestamp when the timestamp doesn't change the
 129      presentation order. I leave it here for historical purposes. What 
 130      purposes, you ask? Historical ones.
 131  */
 132  
 133  function 
 134  update_articletime($id,$time){
 135      $db = DB::connect( $GLOBALS['config']['dbstring'] );
 136      $sql="UPDATE articles SET time='$time' WHERE id=$id";
 137      $result=$db->query($sql) or die($sql);
 138      $db->disconnect();
 139      return TRUE;
 140  }
 141  
 142  
 143  /* 
 144      This function changes the visiblity flag for a specific article 
 145      identified by ID. It is used by the post-submission editor.
 146  */
 147  
 148  function
 149  changevisibility($id,$visibility){
 150      $db = DB::connect( $GLOBALS['config']['dbstring'] );
 151      $sql="UPDATE articles SET visible='$visibility' where id=$id";
 152      $result=$db->query($sql) or die($sql);
 153      $db->disconnect();
 154      return TRUE;
 155  }
 156  
 157  
 158  /* 
 159      This function returns an array contaning the ID values returned
 160      by searching for type $vis (0 for postponed, 1 for visible, d for deleted)
 161      It is used by the log, rss and maintenence pages.
 162      This function and getarticle() differ from the other functions, in that
 163      they don't have the DB connect strings in them because they're often
 164      used in loops or at least with each other. Database connections are
 165      the slowest part of database STUFF so minimize them when you can.
 166  */
 167  
 168  function
 169  numvisarticles($vis,$db){
 170      $sql = "SELECT id FROM articles WHERE visible='$vis'";
 171      $articleResult = $db->query($sql) or die( $sql );
 172  
 173      while ($articleRow = $articleResult->fetchRow()) {
 174          $artnums[]=$articleRow[0];
 175      }
 176      
 177      return $artnums;
 178  }
 179  
 180  
 181  /* 
 182      This function returns an associative array containing the various
 183      parts of an article when given a specific ID number. This function is
 184      used by the main page and the post-submission article editor.
 185      This function and numvisarticles() differ from the other functions, in 
 186      that they don't have the DB connect strings in them because they're often
 187      used in loops or at least with each other. Database connections are
 188      the slowest part of database STUFF so minimize them when you can.
 189      DB structure:
 190                    time,body,visible,username,id,title
 191  */
 192  
 193  function
 194  getarticle($id,$db){
 195      $sql = "SELECT * FROM articles WHERE id=$id";
 196      $articleResult = $db->query($sql) or die( $sql );
 197      $articleRow = $articleResult->fetchRow();
 198      $article['time'] = $articleRow[0];
 199      $article['body']=$articleRow[1];
 200      $article['visible']=$articleRow[2];
 201      $article['user']=$articleRow[3];
 202      $article['title']=$articleRow[5];
 203  
 204      return $article;
 205  }
 206  
 207  /* 
 208      getarticleitem() is used to retrieve one particular piece of an article.
 209      That piece is specified in the $item variable. $item can be any of the 
 210      items listed in getarticle() above. It returns a string.
 211  */
 212  
 213  function
 214  getarticleitem($item,$id,$db){
 215      $sql = "SELECT $item FROM articles WHERE id=$id";
 216      $articleResult = $db->query($sql) or die( $sql );
 217      $articleRow = $articleResult->fetchRow();
 218      return stripslashes($articleRow[0]);
 219  }
 220  
 221  function
 222  getmaxid($db){
 223      $sql = "SELECT max(id) FROM articles";
 224      $max = $db->query($sql) or die( $sql );
 225      $maxRow = $max->fetchRow();
 226      return $maxRow[0];
 227  }
 228  
 229  // This function is used for new articles and editing existing articles.
 230  
 231  function
 232  articlemaint($id=NULL,$articlebody=NULL,$user=NULL,$articletitle=NULL){
 233  
 234      // If we have an ID, we'll need to pull it from the database
 235      // UNLESS we have content in $articlebody, which means we're a preview
 236      if ( $id != NULL && empty($articlebody) ){
 237          $db = DB::connect( $GLOBALS['config']['dbstring'] );
 238          $contents=getarticle($id,$db);
 239          $db->disconnect();
 240          // Since our variable names differ, we'll want to make them the same.
 241          $articlebody=$contents['body'];
 242          $articletitle=$contents['title'];
 243          $user=$contents['user'];
 244          $time=$contents['time'];
 245      }
 246  
 247      if ( $user === NULL ){
 248          $user=$GLOBALS['config']['defaultuser'];
 249      }
 250  
 251      $str='<form action="'.$_SERVER['PHP_SELF'].'" method="post" name="fd">'."\n";
 252      if ( $id != NULL ){
 253          $str.='<input type="hidden" name="time" value="'.$time.'" />'."\n";
 254      }
 255      if ( $GLOBALS['config']['usearticletitles'] == 1 ){
 256          $str.='<label accesskey="t" for="title">Title :</label>';
 257          $str.='<input type="text" id="title" name="articletitle" value="'.escape($articletitle).'" class="title" />'."\n";
 258      }
 259      $str.='<label accesskey="u" for="user">User : </label>';
 260      $str.='<input type="text" id="user" name="user" value="'.$user.'" class="user" />'."\n\n";
 261  
 262      $str.="<br /><br />\n";
 263      if ( empty($id) ){
 264          $str.='<label accesskey="a" for="article">New Article:</label><br />'."\n";
 265      }else{
 266          $str.='<label accesskey="a" for="article">Editing Article '.$id.' :</label><br />'."\n";
 267      }
 268      //javascript
 269      $str.='<script language="Javascript">
 270  <!--
 271  function getMozSelection() {
 272    return document.getSelection();
 273  }
 274  
 275  // IE only - stores the current cursor position on any textarea activity
 276    function storeCaret (txtarea) { 
 277      if (txtarea.createTextRange) { 
 278        txtarea.caretPos = document.selection.createRange().duplicate();
 279      } 
 280    } 
 281  
 282  // IE only - wraps selected text with lft and rgt
 283    function WrapIE(lft, rgt) {
 284      strSelection = document.selection.createRange().text;
 285      if (strSelection!="") {
 286        document.selection.createRange().text = lft + strSelection + rgt;
 287      }
 288    }
 289  
 290  // Moz only - wraps selected text with lft and rgt
 291    function wrapMoz(txtarea, lft, rgt) {
 292      var selLength = txtarea.textLength;
 293      var selStart = txtarea.selectionStart;
 294      var selEnd = txtarea.selectionEnd;
 295      if (selEnd==1 || selEnd==2) selEnd=selLength;
 296      var s1 = (txtarea.value).substring(0,selStart);
 297      var s2 = (txtarea.value).substring(selStart, selEnd)
 298      var s3 = (txtarea.value).substring(selEnd, selLength);
 299      txtarea.value = s1 + lft + s2 + rgt + s3;
 300    }
 301    
 302  // Chooses technique based on browser
 303    function wrapTag(txtarea, lft, rgt) {
 304      lft = unescape(lft);
 305      rgt = unescape(rgt);
 306      if (document.all) {
 307        WrapIE(lft, rgt);
 308      }
 309      else if (document.getElementById) {
 310        wrapMoz(txtarea, lft, rgt);
 311      }
 312    }
 313  
 314  // Get a link via a prompt and wrap selected text
 315    function wrapWithLink(txtarea) {
 316      var my_link = prompt("URL (include protcol!):","");
 317      if (my_link == null){
 318          return;
 319      }
 320      var my_title = prompt("Title","");
 321      if (my_link != \'\') {
 322        lft="<a href=\"" + my_link + "\"";
 323      }
 324      if (my_title != \'\') {
 325          lft = lft + " title=\"" + my_title + "\">";
 326      }else{
 327          lft = lft + ">";
 328      }
 329      if (my_link != \'\') {
 330        rgt="</a>";
 331        wrapTag(txtarea, lft, rgt);
 332      }
 333      return;
 334    }
 335  
 336  // IE only - Insert text at caret position or at start of selected text
 337    function insertIE (txtarea, text) {
 338      if (txtarea.createTextRange && txtarea.caretPos) { 
 339        var caretPos = txtarea.caretPos; 
 340        caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == \' \' ? text+caretPos.text + \' \' : text+caretPos.text;
 341      } else {
 342        txtarea.value = txtarea.value + text; 
 343      }
 344      return;
 345    } 
 346  
 347  // Moz only - Insert text at caret position or at start of selected text
 348    function insertMoz(txtarea , lft) {
 349      var rgt="";
 350      wrapTag(txtarea, lft, rgt);
 351      return;
 352    }
 353  
 354  // Switch function based on browser - Insert text at caret position or at start of selected text
 355    function insertTag(txtarea , lft) {
 356      if (document.all) {
 357        insertIE(txtarea, lft);
 358      }
 359      else if (document.getElementById) {
 360        insertMoz(txtarea, lft);
 361      }
 362    }
 363      
 364  // prompt for image name. Insert image at caret position or at start of selected text
 365    function insertImage(txtarea) {
 366      var my_link = prompt("IMG URL (include protocol!):","");
 367      if (my_link == null){
 368          return;
 369      }
 370      if (my_link != \'\') {
 371        lft="<img src=\"" + my_link + "\" />";
 372        insertTag(txtarea, lft);
 373      }
 374      return;
 375    }
 376  
 377  // End Processing code.
 378  
 379  /*
 380    written by meg hourihan
 381    http://www.megnut.com
 382    meg@megnut.com
 383    
 384    warning: it only works for IE4+/Win and Moz1.1+
 385    feel free to take it for your site
 386    but leave this text in place.
 387    any problems, let meg know.
 388    */
 389    
 390    function mouseover(el) {
 391      el.className = "raise";
 392    }
 393    
 394    function mouseout(el) {
 395      el.className = "buttons";
 396    }
 397    
 398    function mousedown(el) {
 399      el.className = "press";
 400    }
 401    
 402    function mouseup(el) {
 403      el.className = "raise";
 404    }
 405    /* end meg script */
 406  
 407  
 408  
 409  //-->
 410  </script>';
 411      // toolbar
 412      $str.='<div id="toolbar">
 413  <img src="tag_p.png" width="16" height="16"
 414    title="Highlight some text and click for Paragraph tags"
 415    class="buttons"  onmouseover="mouseover(this);" onmouseout="mouseout(this);"  onmousedown="mousedown(this);" onmouseup="mouseup(this);"
 416    onclick="wrapTag(elements[\'articlebody\'], \'<p>\', \'</p>\');">
 417  <img src="tag_bold.png" width="16" height="16"
 418    title="Highlight some text and click for bold"
 419    class="buttons"  onmouseover="mouseover(this);" onmouseout="mouseout(this);"  onmousedown="mousedown(this);" onmouseup="mouseup(this);"
 420    onclick="wrapTag(elements[\'articlebody\'], \'<b>\', \'</b>\');">
 421  <img src="tag_i.png" width="16" height="16"
 422    title="Highlight some text and click for italic"
 423    class="buttons"  onmouseover="mouseover(this);" onmouseout="mouseout(this);"  onmousedown="mousedown(this);" onmouseup="mouseup(this);"
 424    onclick="wrapTag(elements[\'articlebody\'], \'<i>\', \'</i>\')">
 425  <img src="tag_u.png" width="16" height="16"
 426    title="Highlight some text and click for underlined"
 427    class="buttons"  onmouseover="mouseover(this);" onmouseout="mouseout(this);"  onmousedown="mousedown(this);" onmouseup="mouseup(this);"
 428    onclick="wrapTag(elements[\'articlebody\'], \'<u>\', \'</u>\')">
 429  <img src="div_center.png" width="16" height="16"
 430    title="Highlight some text and click to center"
 431    class="buttons"  onmouseover="mouseover(this);" onmouseout="mouseout(this);"  onmousedown="mousedown(this);" onmouseup="mouseup(this);"
 432    onclick="wrapTag(elements[\'articlebody\'], \'<div align=%22center%22>\', \'</div>\')">
 433  <img src="div_right.png" width="16" height="16"
 434    title="Highlight some text and click to right align"
 435    class="buttons"  onmouseover="mouseover(this);" onmouseout="mouseout(this);"  onmousedown="mousedown(this);" onmouseup="mouseup(this);"
 436    onclick="wrapTag(elements[\'articlebody\'], \'<div align=%22right%22>\', \'</div>\')">
 437  <img src="blockquote.png" width="16" height="16"
 438    title="Highlight some text and click for a blockquote"
 439    class="buttons"  onmouseover="mouseover(this);" onmouseout="mouseout(this);"  onmousedown="mousedown(this);" onmouseup="mouseup(this);"
 440    onclick="wrapTag(elements[\'articlebody\'], \'<blockquote>\', \'</blockquote>\')">
 441  <img src="tag_li.png" width="16" height="16"
 442    title="Highlight some text and click for a bulleted list"
 443    class="buttons"  onmouseover="mouseover(this);" onmouseout="mouseout(this);" onmousedown="mousedown(this);"  onmouseup="mouseup(this);"
 444    onclick="wrapTag(elements[\'articlebody\'], \'<li>\', \'</li>\')">
 445  <img src="tag_pre.png" width="16" height="16"
 446    title="Highlight some text and click for pre"
 447    class="buttons"  onmouseover="mouseover(this);" onmouseout="mouseout(this);" onmousedown="mousedown(this);" onmouseup="mouseup(this);"
 448    onclick="wrapTag(elements[\'articlebody\'], \'<pre>\', \'</pre>\')">
 449  <img src="tag_image.png" width="16" height="16"
 450    title="Insert an image"
 451    class="buttons" onmouseover="mouseover(this);" onmouseout="mouseout(this);" onmousedown="mousedown(this);" onmouseup="mouseup(this);"
 452    onclick="insertImage(elements[\'articlebody\']);">
 453  <img src="tag_a.png" width="16" height="16"
 454    title="Highlight some text and click to add a link"
 455    class="buttons"  onmouseover="mouseover(this);" onmouseout="mouseout(this);"  onmousedown="mousedown(this);" onmouseup="mouseup(this);"
 456    onclick="wrapWithLink(elements[\'articlebody\']);">
 457  </div>
 458  <!-- End of Toolbar block -->';
 459      //textarea
 460      $str.="\n\n".'<textarea cols="55" rows="25" name="articlebody" id="article" class="articlebody" onselect="storeCaret(this);" onclick="storeCaret(this);" onkeyup="storeCaret(this);">'.escape($articlebody).'</textarea><br />'."\n";
 461  
 462      $str.="<div><div class=\"floaty\">\n<input type=\"image\" src=\"save.png\" height=\"24\" width=\"24\" title=\"Save Changes\" value=\"Save Changes\" accesskey=\"s\" align=\"middle\" class=\"save\" />\n";
 463      $str.='<input type="hidden" name="id" value="'.$id.'" />'."\n";
 464      $str.='<input type="image" src="preview.png" height="24" width="24" name="action" value="Preview" title="Preview" align="middle" accesskey="p" class="preview" />'."\n";
 465      $str.='<input type="image" src="spellcheck.png" height="24" width="24" name="action" value="SpellCheck" title="SpellCheck" align="middle" accesskey="k" class="spellcheck" id="spellcheck" />'."\n";
 466      $str.="</div>\n";
 467  
 468      $str.="<div class=\"floaty\">\n<input type=\"checkbox\" name=\"visible\" value=\"1\" checked=\"checked\" class=\"visible\" onclick=\"checkState();return true;\" id=\"visible\" />Visible<br />\n";
 469      if ( $GLOBALS['config']['pingback'] == '1' && empty($id) ){
 470          $str.='<input type="checkbox" name="pingback" value="1" checked="checked" class="pingback" id="pingback" />Pingback'."\n";
 471      }elseif ( $GLOBALS['config']['pingback'] == '1' ){
 472          $str.='<input type="checkbox" name="pingback" value="1" class="pingback" id="pingback" />Pingback'."\n";
 473      }
 474      if ( $GLOBALS['config']['useweblogping'] == '1' && empty($id) ){
 475          $str.='<br /><input type="checkbox" name="weblogping" value="1" class="weblogping" checked="checked" id="weblog" />Weblog.com&nbsp;Ping'."\n";
 476      }elseif ( $GLOBALS['config']['useweblogping'] == '1' ){
 477          $str.='<br /><input type="checkbox" name="weblogping" value="1" class="weblogping" id="weblog" />Weblog.com&nbsp;Ping'."\n</div>\n";
 478      }
 479      $str.="</div>\n";
 480  
 481      $str.="<a href=\"".$_SERVER['PHP_SELF']."\" accesskey=\"r\" title=\"Reset Page\"><img src=\"reset.png\" height=\"24\" width=\"24\" class=\"reset\"/></a>\n";
 482      if ( $id != NULL ){
 483          $str.='<input class="delete" type="image" src="delete.png" height="24" width="24" title="Delete" name="action" value="Delete" align="middle" class="delete" /></div>'."\n";
 484      }
 485      $str.="</div>\n<div class=\"clear\"> </div>\n</form>\n";
 486      print($str);
 487  }
 488  
 489  /*
 490      config() is the GUI configurator used by user.php
 491      The actual config is stored in the pingback database. As small as it is, there's no reason to dedicate a table to it.
 492  */
 493  function
 494  config(){
 495      $db = DB::connect( $GLOBALS['config']['dbstring'] );
 496      $sql="SELECT * FROM pingback where localid='-1'";
 497      $res = $db->query($sql);
 498      $configstr=$res->fetchRow();
 499      $configstr=$configstr[3];
 500      if ( $configstr == '' ){
 501          print("<p>Welcome to Parasite!</p>\n");
 502          $defaults=$GLOBALS['defaults'];
 503      }else{
 504          $configstr=stripslashes($configstr);
 505          $defaults=unserialize($configstr);
 506      }
 507      $str='<div id="config"><div>'."\n";
 508      $str.='<form action="'.$_SERVER['PHP_SELF'].'" method="post" name="config">'."\n";
 509      $str.='<label accesskey="l" for="limit" title="Limits the number of articles printed to the main page.">Limit: </label>'."\n";
 510      $str.='<input type="text" id="limit" size="1" name="limit" value="'.$defaults['limit'].'" class="limit" /><br />'."\n";
 511      $str.='<label accesskey="t" for="title" title="Your Blog\'s title. Will be used by the RSS feed.">Title: </label>'."\n";
 512      $str.='<input type="text" id="title" name="title" value="'.$defaults['title'].'" class="title" /><br />'."\n";
 513      $str.='<label accesskey="u" for="url" title="The URL for your blog.">URL: </label>'."\n";
 514      $str.='<input type="text" size="50" id="url" name="url" value="'.$defaults['url'].'" class="url" /><br />'."\n";
 515      $str.='<label accesskey="c" for="cssfile" title="Use this if you don\'t modify how main.php links to your CSS">CSS: </label>'."\n";
 516      $str.='<input type="text" size="50" id="cssfile" name="cssfile" value="'.$defaults['cssfile'].'" class="cssfile" /><br />'."\n";
 517      $str.='<label accesskey="d" for="description" title="The description of your blog will be used by your RSS feed.">Description: </label>'."\n";
 518      $str.='<input type="text" id="description" name="description" value="'.$defaults['description'].'" class="description" /><br />'."\n";
 519  
 520      $str.='<label accesskey="d" for="defaultuser" title="The default user that enters articles.">Default User: </label>'."\n";
 521      $str.='<input type="text" id="defaultuser" name="defaultuser" value="'.escape($defaults['defaultuser']).'" class="defaultuser" /><br />'."\n";
 522      $str.='<label accesskey="i" for="rssv2limit" title="The number of articles printed in the RSS V2 feed.">RSS Version 2 Limit: </label>'."\n";
 523      $str.='<input type="text" size="1" id="rssv2limit" name="rssv2limit" value="'.$defaults['rssv2limit'].'" class="rssv2limit" /><br />'."\n";
 524  
 525      $str.='<input type="checkbox" value="1" id="rssv2" name="rssv2" '.$defaults['rssv2str'].' class="rssv2">'."\n";
 526      $str.='<label accesskey="v" for="rssv2" title="See Docs for info on RSS versions.">RSSv2</label><br />'."\n";
 527  
 528      $str.='<input type="checkbox" name="pingback" value="1" '.$defaults['pingbackstr'].' id="usepingback" />';
 529      $str.='<label for="usepingback" title="Enable/Disable pingback feature">Use&nbsp;Pingback</label><br />'."\n";
 530  
 531      $str.='<input type="checkbox" name="useweblogping" value="1" '.$defaults['useweblogpingstr'].' id="useweblogping" />';
 532      $str.='<label for="useweblogping" title="Ping weblogs.com when you update your blog.">Use&nbsp;Weblog.com&nbsp;Ping</label><br />'."\n";
 533  
 534      $str.='<input type="checkbox" name="usearticletitles" value="1" '.$defaults['usearticletitlesstr'].' id="usearticletitles" onclick="rsscheck(); return true;" />';
 535      $str.='<label for="usearticletitles" title="Enable/Disable article titles.">Use&nbsp;Article&nbsp;Titles</label><br />'."\n";
 536  
 537      $str.='<a href="javascript:onclick=makevis(\'legend\');">Legend</a><br />'."\n";
 538      $str.='<div id="legend" class="legend" style="display:none">';
 539      $str.='<p>The definitions can contain any HTML and will replace the following keywords:</p><ul>'."\n";
 540      $str.='<li>|thisarticlenumber| The numeric ID of the article being printed</li>'."\n";
 541      $str.='<li>|thisarticletitle| The title of the article being printed</li>'."\n";
 542      $str.='<li>|thisarticledate| A formated time string of the article being printed</li>'."\n";
 543      $str.='<li>|thisarticleuser| The user that entered the article being printed</li>'."\n";
 544      $str.='<li>|thisarticlebody| The guts of the article being printed</li>'."\n";
 545      $str.='<li>|thisarticlepermalink| The permanent URI of the article being printed</li>'."\n";
 546      $str.='<li>|pingbackclass| This keyword will be replaced with &quot;invisible&quot; if no pingbacks exist and will be replaced with &quot;pingbacklist&quot; if pingbacks exist</li>'."\n";
 547      $str.='<li>|thisarticlepingbackid| This keyword will be replaced with &quot;pb&quot; and then the numeric ID of the article being printed. This keyword is provided to aid in scripting pingback display.</li>'."\n";
 548      $str.='<li>|thisarticlepingbacklist| This keyword will be replaced with the list of pingbacks to the current article. If no pingbacks occurred, this keyword is replaced with an empty string.</li>'."\n";
 549      $str.='<li>|thisarticlepingbacktotal| This keyword will be replaced with &quot;Pingbacks:&nbsp;&quot; and then the number of pingbacks that the current article has received. If no pingbacks have occurred, this keyword is replaced with an empty string.</li>'."\n";
 550      $str.="</ul>\n</div>\n";
 551  
 552      $str.='<label for="articledefinition" title="Defines how articles are printed. See Legend.">Article Definition: </label><br />'."\n";
 553      $str.='<textarea cols="50" rows="10" name="articledefinition" id="articledefinition">'.$defaults['articledefinition']."</textarea><br />\n";
 554      $str.='<label for="pingbacktotaldefinition" title="Defines how pingback totals are printed to articles, if used. See Legend.">Pingback Total Definition: </label><br />'."\n";
 555      $str.='<textarea cols="50" rows="10" name="pingbacktotaldefinition" id="pingbacktotaldefinition">'.$defaults['pingbacktotaldefinition']."</textarea><br />\n";
 556      $str.='<label for="pingbacklistdefinition" title="Defines how the list of pingbacks will be printed.">Pingback List Definition: </label><br />'."\n";
 557      $str.='<textarea cols="50" rows="10" name="pingbacklistdefinition" id="pingbacklistdefinition">'.$defaults['pingbacklistdefinition']."</textarea><br />\n";
 558      $str.='<input type="submit" name="action" class="saveconfig" accesskey="s" value="Save Config">'."\n";
 559      $str.="</form>\n</div>\n</div>\n";
 560      printf("%s",$str);
 561  }
 562  
 563  function
 564  getconfig(){
 565      $db = DB::connect( $GLOBALS['config']['dbstring'] );
 566      $sql="SELECT * FROM pingback where localid='-1'";
 567      $res = $db->query($sql);
 568      $configstr=$res->fetchRow();
 569      if ( sizeof($configstr) == 0 ){
 570          $defaults=$GLOBALS['defaults'];
 571      }else{
 572          $configstr=stripslashes($configstr[3]);
 573          $defaults=unserialize($configstr);
 574      }
 575      $GLOBALS['config']=array_merge($GLOBALS['config'],$defaults);
 576      $db->disconnect();
 577  }
 578  
 579  /* 
 580      saveconfig() gets post data and converts it into a usable config array
 581  */
 582  function
 583  saveconfig($array){
 584      $ssa=array('title','description','defaultuser','articledefinition','pingbacklistdefinition','pingbacktotaldefinition');
 585      foreach( $ssa as $ele ){
 586          $array["$ele"]=stripslashes($array["$ele"]);
 587      }
 588      $hea=array('title','defaultuser','description');
 589      foreach( $hea as $ele ){
 590          $array["$ele"]=htmlspecialchars($array["$ele"]);
 591      }
 592      $ca=array('pingback','useweblogping','usearticletitles');
 593      foreach( $ca as $ele ){
 594          if ( $array["$ele"] == 1 ){