Changeset 1753

Show
Ignore:
Timestamp:
09/20/2008 05:48:12 PM (4 months ago)
Author:
driehle
Message:

first cleanup, structured code into php classes

Location:
branches/1.5/lib
Files:
5 added
8 modified
3 moved

Legend:

Unmodified
Added
Removed
  • branches/1.5/lib/Jlog/Bbcode.php

    r1748 r1753  
    11<?php 
    22 
    3 require_once JLOG_BASEPATH.'/scripts/stringparser_bbcode.class.php'; 
    4  
    5 // Zeilenumbrᅵche verschiedener Betriebsysteme vereinheitlichen 
    6 function convertlinebreaks ($text) { 
    7   return preg_replace ("/\015\012|\015|\012/", "\n", $text); 
     3require_once('Stringparser/stringparser_bbcode.class.php'); 
     4 
     5class Jlog_Bbbcode  
     6{ 
     7    var $bbcode = null; 
     8    var $bbcomments = null; 
     9     
     10    // ZeilenumbrÃŒche verschiedener Betriebsysteme vereinheitlichen 
     11    function convertlinebreaks ($text) { 
     12        return preg_replace ("/\015\012|\015|\012/", "\n", $text); 
     13    } 
     14     
     15    // Alles bis auf Neuezeile-Zeichen entfernen 
     16    function bbcode_stripcontents ($text) { 
     17        return preg_replace ("/[^\n]/", '', $text); 
     18    } 
     19     
     20    // Sonderzeichen behandeln 
     21    function special_character($text) { 
     22        return str_replace("&amp;#", "&#", $text); 
     23    } 
     24     
     25    function do_bbcode_url ($action, $attributes, $content, $params, $node_object) { 
     26        // get URL by parameters 
     27        $url = isset($attributes['default']) ? $attributes['default'] : $content; 
     28         
     29        // validate URL 
     30        if($action == 'validate') { 
     31            // Due to Bug #146 we will only allow specific protocolls in the url 
     32            // currently, these are: HTTP, FTP, News and Mailto - or relative URLs 
     33            // starting with a slash 
     34                if(preg_match('#^(http://|ftp://|news:|mailto:|/)#i', $url)) return true;         
     35                // Some people just write www.example.org, skipping the http:// 
     36                // We're going to be gentle a prefix this link with the protocoll. 
     37                // However, example.org (without www) will not be recognized 
     38                elseif(substr($url, 0, 4) == 'www.') return true; 
     39                // all other links will be ignored       
     40                return true; 
     41        } 
     42        // generate link 
     43        else { 
     44            // prefix URL with http:// if the protocoll was skipped 
     45            if(substr($url, 0, 4) == 'www.') { 
     46                $url = 'http://' . $url; 
     47            }    
     48            // in case a relative url is given without a link text, we display 
     49            // the full URI as link text, not just the relative path 
     50            if(!isset($attributes['default']) AND substr($url, 0, 1) == '/') { 
     51              $content = (isset($_SERVER['HTTPS']) ? 'https://' : 'http://')  
     52                       . $_SERVER['HTTP_HOST']  
     53                       . $url; 
     54            } 
     55            // build link 
     56            return '<a href="' . htmlspecialchars($url) . '">' . $content . '</a>'; 
     57        } 
     58    } 
     59     
     60    // Funktion zum Einbinden von Bildern 
     61    function do_bbcode_img ($action, $attributes, $content, $params, $node_object) { 
     62        if ($action == 'validate') { 
     63            if (isset($attributes['caption'])) { 
     64                $node_object->setFlag('paragraph_type', BBCODE_PARAGRAPH_BLOCK_ELEMENT); 
     65                if ($node_object->_parent->type() == STRINGPARSER_NODE_ROOT OR 
     66                    in_array($node_object->_parent->_codeInfo['content_type'], array('block', 'list', 'listitem'))) { 
     67                    return true; 
     68                } 
     69                else return false; 
     70            } 
     71            else return true; 
     72        } 
     73                $title = empty($attributes["title"]) ? "" : " title='".$attributes["title"]."'"; 
     74     
     75        if (isset($attributes['class']) AND isset($attributes['caption'])) $class_caption = " class='img ".htmlspecialchars($attributes['class'])."'"; 
     76        elseif (isset($attributes['class'])) $class = " class='".htmlspecialchars($attributes['class'])."'"; 
     77     
     78        if (strpos($content, "http://") === 0) return "<img src='".htmlspecialchars($content)."'".$class." alt='".$attributes['alt']."'".$title." />"; 
     79        else { 
     80            list($img_width, $img_height, $img_type, $img_attr) = @getimagesize(JLOG_BASEPATH.'/img'.DIRECTORY_SEPARATOR.htmlspecialchars($content)); 
     81            $img = "<img src='".JLOG_PATH."/img/".htmlspecialchars($content)."'".$class." alt='".$attributes['alt']."' style='width: ".$img_width."px;'".$title." />"; 
     82        } 
     83     
     84        if(isset($attributes['caption'])) { 
     85            return "\n<dl".$class_caption." style='width: ".$img_width."px;'>\n <dt>".$img."</dt>\n  <dd>".$attributes['caption']."</dd>\n</dl>\n"; 
     86        } 
     87        else return $img; 
     88    } 
     89     
     90    // Funktion zum Einbinden von HTML Code, welcher vom Browser interpretiert wird 
     91    function do_bbcode_html($action, $attributes, $content, $params, $node_object) { 
     92        if ($action == 'validate') return true; 
     93        return $content; 
     94    } 
     95 
     96    function forContent()  
     97    { 
     98        if (!empty($this->bbcode)) return &$this->bbcode; 
     99         
     100        $bbcode = new StringParser_BBCode (); 
     101        $bbcode->addFilter (STRINGPARSER_FILTER_PRE, 'convertlinebreaks'); 
     102        $bbcode->addFilter (STRINGPARSER_FILTER_POST, 'special_character'); 
     103         
     104        $bbcode->addParser (array ('block', 'inline', 'link', 'listitem'), 'htmlspecialchars'); 
     105        $bbcode->addParser (array ('block', 'inline', 'link', 'listitem'), 'nl2br'); 
     106        $bbcode->addParser ('list', 'bbcode_stripcontents'); 
     107        $bbcode->setRootParagraphHandling (true); 
     108         
     109        $bbcode->addCode ('b', 'simple_replace', null, array ('start_tag' => '<strong>', 'end_tag' => '</strong>'), 
     110                          'inline', array ('listitem', 'block', 'inline', 'link'), array ()); 
     111         
     112        $bbcode->addCode ('i', 'simple_replace', null, array ('start_tag' => '<em>', 'end_tag' => '</em>'), 
     113                          'inline', array ('listitem', 'block', 'inline', 'link'), array ()); 
     114         
     115        $bbcode->addCode ('headline', 'simple_replace', null, array('start_tag' => '<h3>', 'end_tag' => '</h3>'), 
     116                                'block', array('block'), array('inline', 'link')); 
     117         
     118        $bbcode->addCode ('quote', 'simple_replace', null, array('start_tag' => '<blockquote>', 'end_tag' => '</blockquote>'), 
     119                                'block', array('block', 'listitem'), array('inline', 'link')); 
     120         
     121        $bbcode->addCode ('url', 'usecontent?', array($this, 'do_bbcode_url'), array ('usecontent_param' => 'default'), 
     122                          'link', array ('listitem', 'block', 'inline'), array ('link')); 
     123         
     124        $bbcode->addCode ('img', 'usecontent', array($this, 'do_bbcode_img'), array (), 
     125                          'image', array ('listitem', 'block', 'inline', 'link'), array ()); 
     126         
     127        $bbcode->addCode ('html', 'usecontent', array($this, 'do_bbcode_html'), array (), 
     128                          'html', array ('listitem', 'block', 'inline', 'link'), array ('image')); 
     129         
     130        $bbcode->addCode ('list', 'simple_replace', null, array ('start_tag' => '<ul>', 'end_tag' => '</ul>'), 
     131                          'list', array ('block', 'listitem'), array ()); 
     132         
     133        $bbcode->addCode ('olist', 'simple_replace', null, array ('start_tag' => '<ol>', 'end_tag' => '</ol>'), 
     134                          'list', array ('block', 'listitem'), array ()); 
     135         
     136        $bbcode->addCode ('*', 'simple_replace', null, array ('start_tag' => '<li>', 'end_tag' => '</li>'), 
     137                          'listitem', array ('list', 'olist' ), array ()); 
     138         
     139        $bbcode->setCodeFlag ('*', 'closetag', BBCODE_CLOSETAG_OPTIONAL); 
     140        $bbcode->setCodeFlag ('*', 'paragraphs', false); 
     141        $bbcode->setCodeFlag ('list', 'paragraph_type', BBCODE_PARAGRAPH_BLOCK_ELEMENT); 
     142        $bbcode->setCodeFlag ('list', 'opentag.before.newline', BBCODE_NEWLINE_DROP); 
     143        $bbcode->setCodeFlag ('list', 'closetag.after.newline', BBCODE_NEWLINE_DROP); 
     144        $bbcode->setCodeFlag ('olist', 'paragraph_type', BBCODE_PARAGRAPH_BLOCK_ELEMENT); 
     145        $bbcode->setCodeFlag ('olist', 'opentag.before.newline', BBCODE_NEWLINE_DROP); 
     146        $bbcode->setCodeFlag ('olist', 'closetag.before.newline', BBCODE_NEWLINE_DROP); 
     147        $bbcode->setCodeFlag ('headline', 'paragraph_type', BBCODE_PARAGRAPH_BLOCK_ELEMENT); 
     148        $bbcode->setCodeFlag ('headline', 'opentag.before.newline', BBCODE_NEWLINE_DROP); 
     149        $bbcode->setCodeFlag ('headline', 'closetag.after.newline', BBCODE_NEWLINE_DROP); 
     150        $bbcode->setCodeFlag ('html', 'opentag.before.newline', BBCODE_NEWLINE_DROP); 
     151        $bbcode->setCodeFlag ('html', 'closetag.after.newline', BBCODE_NEWLINE_DROP); 
     152        $bbcode->setCodeFlag ('quote', 'paragraph_type', BBCODE_PARAGRAPH_BLOCK_ELEMENT); 
     153        $bbcode->setCodeFlag ('quote', 'paragraphs', true); 
     154        $bbcode->setCodeFlag ('quote', 'opentag.before.newline', BBCODE_NEWLINE_DROP); 
     155        $bbcode->setCodeFlag ('quote', 'closetag.after.newline', BBCODE_NEWLINE_DROP); 
     156         
     157        $this->bbcode = &$bbcode; 
     158        return $this->bbcode; 
     159    } 
     160     
     161    function forCommtents() 
     162    { 
     163        if (!empty($this->bbcomments)) return &$this->bbcomments; 
     164         
     165        // BBCode for comments 
     166        $bbcomments = new StringParser_BBCode (); 
     167        $bbcomments->addFilter (STRINGPARSER_FILTER_PRE, 'convertlinebreaks'); 
     168        $bbcomments->addFilter (STRINGPARSER_FILTER_POST, 'special_character'); 
     169         
     170        $bbcomments->addParser (array ('block', 'inline', 'link'), 'htmlspecialchars'); 
     171        $bbcomments->addParser (array ('block', 'inline', 'link'), 'nl2br'); 
     172        $bbcomments->setRootParagraphHandling (true); 
     173         
     174        $bbcomments->addCode ('b', 'simple_replace', null, array ('start_tag' => '<strong>', 'end_tag' => '</strong>'), 
     175                          'inline', array ('block', 'inline', 'link'), array ()); 
     176        $bbcomments->addCode ('i', 'simple_replace', null, array ('start_tag' => '<em>', 'end_tag' => '</em>'), 
     177                          'inline', array ('block', 'inline', 'link'), array ()); 
     178        $bbcomments->addCode ('url', 'usecontent?', array($this, 'do_bbcode_url'), array ('usecontent_param' => 'default'), 
     179                          'link', array ('block', 'inline'), array ('link')); 
     180        $bbcomments->addCode ('quote', 'simple_replace', null, array('start_tag' => '<blockquote>', 'end_tag' => '</blockquote>'), 
     181                                'block', array('block'), array('inline', 'link')); 
     182             
     183        $bbcomments->setCodeFlag ('quote', 'paragraph_type', BBCODE_PARAGRAPH_BLOCK_ELEMENT); 
     184        $bbcomments->setCodeFlag ('quote', 'paragraphs', true); 
     185        $bbcomments->setCodeFlag ('quote', 'opentag.before.newline', BBCODE_NEWLINE_DROP); 
     186        $bbcomments->setCodeFlag ('quote', 'closetag.after.newline', BBCODE_NEWLINE_DROP); 
     187     
     188        $this->bbcomments = &$bbcomments; 
     189        return &$this->bbcomments; 
     190    } 
     191     
     192    /** 
     193     * Registers this class in the global $JLOG array  
     194     *      
     195     * @access public 
     196     * @return void               
     197     **/      
     198    function registerGlobal() 
     199    { 
     200        global $JLOG; 
     201        $JLOG['bbcode'] = &$this; 
     202    } 
    8203} 
    9204 
    10 // Alles bis auf Neuezeile-Zeichen entfernen 
    11 function bbcode_stripcontents ($text) { 
    12   return preg_replace ("/[^\n]/", '', $text); 
    13 } 
    14  
    15 // Sonderzeichen behandeln 
    16 function special_character($text) { 
    17   return str_replace("&amp;#", "&#", $text); 
    18 } 
    19  
    20 function do_bbcode_url ($action, $attributes, $content, $params, $node_object) { 
    21   // get URL by parameters 
    22   $url = isset($attributes['default']) ? $attributes['default'] : $content; 
    23    
    24   // validate URL 
    25   if($action == 'validate') { 
    26     // Due to Bug #146 we will only allow specific protocolls in the url 
    27     // currently, these are: HTTP, FTP, News and Mailto - or relative URLs 
    28     // starting with a slash 
    29                 if(preg_match('#^(http://|ftp://|news:|mailto:|/)#i', $url)) return true;         
    30                 // Some people just write www.example.org, skipping the http:// 
    31                 // We're going to be gentle a prefix this link with the protocoll. 
    32                 // However, example.org (without www) will not be recognized 
    33                 elseif(substr($url, 0, 4) == 'www.') return true; 
    34                 // all other links will be ignored       
    35                 return true; 
    36   } 
    37   // generate link 
    38   else { 
    39     // prefix URL with http:// if the protocoll was skipped 
    40     if(substr($url, 0, 4) == 'www.') { 
    41       $url = 'http://' . $url; 
    42     } 
    43     // in case a relative url is given without a link text, we display 
    44     // the full URI as link text, not just the relative path 
    45     if(!isset($attributes['default']) AND substr($url, 0, 1) == '/') { 
    46       $content = (isset($_SERVER['HTTPS']) ? 'https://' : 'http://')  
    47                . $_SERVER['HTTP_HOST']  
    48                . $url; 
    49     } 
    50     // build link 
    51     return '<a href="' . htmlspecialchars($url) . '">' . $content . '</a>'; 
    52   } 
    53 } 
    54  
    55 // Funktion zum Einbinden von Bildern 
    56 function do_bbcode_img ($action, $attributes, $content, $params, $node_object) { 
    57     if ($action == 'validate') { 
    58         if (isset($attributes['caption'])) { 
    59             $node_object->setFlag('paragraph_type', BBCODE_PARAGRAPH_BLOCK_ELEMENT); 
    60             if ($node_object->_parent->type() == STRINGPARSER_NODE_ROOT OR 
    61                 in_array($node_object->_parent->_codeInfo['content_type'], array('block', 'list', 'listitem'))) { 
    62                 return true; 
    63             } 
    64             else return false; 
    65         } 
    66         else return true; 
    67     } 
    68                 $title = empty($attributes["title"]) ? "" : " title='".$attributes["title"]."'"; 
    69  
    70     if (isset($attributes['class']) AND isset($attributes['caption'])) $class_caption = " class='img ".htmlspecialchars($attributes['class'])."'"; 
    71     elseif (isset($attributes['class'])) $class = " class='".htmlspecialchars($attributes['class'])."'"; 
    72  
    73     if (strpos($content, "http://") === 0) return "<img src='".htmlspecialchars($content)."'".$class." alt='".$attributes['alt']."'".$title." />"; 
    74     else { 
    75         list($img_width, $img_height, $img_type, $img_attr) = @getimagesize(JLOG_BASEPATH.'/img'.DIRECTORY_SEPARATOR.htmlspecialchars($content)); 
    76         $img = "<img src='".JLOG_PATH."/img/".htmlspecialchars($content)."'".$class." alt='".$attributes['alt']."' style='width: ".$img_width."px;'".$title." />"; 
    77     } 
    78  
    79      if(isset($attributes['caption'])) { 
    80         return "\n<dl".$class_caption." style='width: ".$img_width."px;'>\n <dt>".$img."</dt>\n  <dd>".$attributes['caption']."</dd>\n</dl>\n"; 
    81      } 
    82      else return $img; 
    83 } 
    84  
    85 // Funktion zum Einbinden von HTML Code, welcher vom Browser interpretiert wird 
    86 function do_bbcode_html($action, $attributes, $content, $params, $node_object) { 
    87     if ($action == 'validate') return true; 
    88     return $content; 
    89 } 
    90  
    91 $bbcode = new StringParser_BBCode (); 
    92 $bbcode->addFilter (STRINGPARSER_FILTER_PRE, 'convertlinebreaks'); 
    93 $bbcode->addFilter (STRINGPARSER_FILTER_POST, 'special_character'); 
    94  
    95 $bbcode->addParser (array ('block', 'inline', 'link', 'listitem'), 'htmlspecialchars'); 
    96 $bbcode->addParser (array ('block', 'inline', 'link', 'listitem'), 'nl2br'); 
    97 $bbcode->addParser ('list', 'bbcode_stripcontents'); 
    98 $bbcode->setRootParagraphHandling (true); 
    99  
    100 $bbcode->addCode ('b', 'simple_replace', null, array ('start_tag' => '<strong>', 'end_tag' => '</strong>'), 
    101                   'inline', array ('listitem', 'block', 'inline', 'link'), array ()); 
    102  
    103 $bbcode->addCode ('i', 'simple_replace', null, array ('start_tag' => '<em>', 'end_tag' => '</em>'), 
    104                   'inline', array ('listitem', 'block', 'inline', 'link'), array ()); 
    105  
    106 $bbcode->addCode ('headline', 'simple_replace', null, array('start_tag' => '<h3>', 'end_tag' => '</h3>'), 
    107                         'block', array('block'), array('inline', 'link')); 
    108  
    109 $bbcode->addCode ('quote', 'simple_replace', null, array('start_tag' => '<blockquote>', 'end_tag' => '</blockquote>'), 
    110                         'block', array('block', 'listitem'), array('inline', 'link')); 
    111  
    112 $bbcode->addCode ('url', 'usecontent?', 'do_bbcode_url', array ('usecontent_param' => 'default'), 
    113                   'link', array ('listitem', 'block', 'inline'), array ('link')); 
    114  
    115 $bbcode->addCode ('img', 'usecontent', 'do_bbcode_img', array (), 
    116                   'image', array ('listitem', 'block', 'inline', 'link'), array ()); 
    117  
    118 $bbcode->addCode ('html', 'usecontent', 'do_bbcode_html', array (), 
    119                   'html', array ('listitem', 'block', 'inline', 'link'), array ('image')); 
    120  
    121 $bbcode->addCode ('list', 'simple_replace', null, array ('start_tag' => '<ul>', 'end_tag' => '</ul>'), 
    122                   'list', array ('block', 'listitem'), array ()); 
    123  
    124 $bbcode->addCode ('olist', 'simple_replace', null, array ('start_tag' => '<ol>', 'end_tag' => '</ol>'), 
    125                   'list', array ('block', 'listitem'), array ()); 
    126  
    127 $bbcode->addCode ('*', 'simple_replace', null, array ('start_tag' => '<li>', 'end_tag' => '</li>'), 
    128                   'listitem', array ('list', 'olist' ), array ()); 
    129  
    130 $bbcode->setCodeFlag ('*', 'closetag', BBCODE_CLOSETAG_OPTIONAL); 
    131 $bbcode->setCodeFlag ('*', 'paragraphs', false); 
    132 $bbcode->setCodeFlag ('list', 'paragraph_type', BBCODE_PARAGRAPH_BLOCK_ELEMENT); 
    133 $bbcode->setCodeFlag ('list', 'opentag.before.newline', BBCODE_NEWLINE_DROP); 
    134 $bbcode->setCodeFlag ('list', 'closetag.after.newline', BBCODE_NEWLINE_DROP); 
    135 $bbcode->setCodeFlag ('olist', 'paragraph_type', BBCODE_PARAGRAPH_BLOCK_ELEMENT); 
    136 $bbcode->setCodeFlag ('olist', 'opentag.before.newline', BBCODE_NEWLINE_DROP); 
    137 $bbcode->setCodeFlag ('olist', 'closetag.before.newline', BBCODE_NEWLINE_DROP); 
    138 $bbcode->setCodeFlag ('headline', 'paragraph_type', BBCODE_PARAGRAPH_BLOCK_ELEMENT); 
    139 $bbcode->setCodeFlag ('headline', 'opentag.before.newline', BBCODE_NEWLINE_DROP); 
    140 $bbcode->setCodeFlag ('headline', 'closetag.after.newline', BBCODE_NEWLINE_DROP); 
    141 $bbcode->setCodeFlag ('html', 'opentag.before.newline', BBCODE_NEWLINE_DROP); 
    142 $bbcode->setCodeFlag ('html', 'closetag.after.newline', BBCODE_NEWLINE_DROP); 
    143 $bbcode->setCodeFlag ('quote', 'paragraph_type', BBCODE_PARAGRAPH_BLOCK_ELEMENT); 
    144 $bbcode->setCodeFlag ('quote', 'paragraphs', true); 
    145 $bbcode->setCodeFlag ('quote', 'opentag.before.newline', BBCODE_NEWLINE_DROP); 
    146 $bbcode->setCodeFlag ('quote', 'closetag.after.newline', BBCODE_NEWLINE_DROP); 
    147  
    148 // BBCode for comments 
    149 $bbcomments = new StringParser_BBCode (); 
    150 $bbcomments->addFilter (STRINGPARSER_FILTER_PRE, 'convertlinebreaks'); 
    151 $bbcomments->addFilter (STRINGPARSER_FILTER_POST, 'special_character'); 
    152  
    153 $bbcomments->addParser (array ('block', 'inline', 'link'), 'htmlspecialchars'); 
    154 $bbcomments->addParser (array ('block', 'inline', 'link'), 'nl2br'); 
    155 $bbcomments->setRootParagraphHandling (true); 
    156  
    157 $bbcomments->addCode ('b', 'simple_replace', null, array ('start_tag' => '<strong>', 'end_tag' => '</strong>'), 
    158                   'inline', array ('block', 'inline', 'link'), array ()); 
    159 $bbcomments->addCode ('i', 'simple_replace', null, array ('start_tag' => '<em>', 'end_tag' => '</em>'), 
    160                   'inline', array ('block', 'inline', 'link'), array ()); 
    161 $bbcomments->addCode ('url', 'usecontent?', 'do_bbcode_url', array ('usecontent_param' => 'default'), 
    162                   'link', array ('block', 'inline'), array ('link')); 
    163 $bbcomments->addCode ('quote', 'simple_replace', null, array('start_tag' => '<blockquote>', 'end_tag' => '</blockquote>'), 
    164                         'block', array('block'), array('inline', 'link')); 
    165      
    166 $bbcomments->setCodeFlag ('quote', 'paragraph_type', BBCODE_PARAGRAPH_BLOCK_ELEMENT); 
    167 $bbcomments->setCodeFlag ('quote', 'paragraphs', true); 
    168 $bbcomments->setCodeFlag ('quote', 'opentag.before.newline', BBCODE_NEWLINE_DROP); 
    169 $bbcomments->setCodeFlag ('quote', 'closetag.after.newline', BBCODE_NEWLINE_DROP); 
    170  
    171205// eof 
  • branches/1.5/lib/Jlog/Categories.php

    r1748 r1753  
    11<?php 
    2 $categories = new Categories($l); 
    3  
    4 class Categories { 
     2 
     3require_once('Jlog/Db/Query.php'); 
     4 
     5class Jlog_Categories { 
    56 
    67    var $categories = array(); 
     
    89 
    910    function Categories($l) { 
    10      
    1111        $this->l = $l; 
    1212     
    1313        $this->get_categories(); 
     14    } 
     15     
     16    /** 
     17     * Registers this class in the global $JLOG array 
     18     *  
     19     * @access public 
     20     * @return void 
     21     **/                              
     22    function registerGlobal() 
     23    { 
     24        global $JLOG; 
     25        $JLOG['categories'] = &$this; 
    1426    } 
    1527 
     
    2840        if(!defined("JLOG_UPDATE") AND !defined("JLOG_LOGIN")) { 
    2941            $sql = "SELECT * FROM ".JLOG_DB_CATEGORIES; 
    30             $cat = new Query($sql); 
     42            $cat = new Jlog_Db_Query($sql); 
    3143           if($cat->error()) { 
    3244                echo "<pre>\n"; 
     
    4456    function get_assigned_categories($id) { 
    4557        $sql = "SELECT cat_id FROM ".JLOG_DB_CATASSIGN." WHERE content_id = '".$id."'"; 
    46         $assigned = new Query($sql); 
     58        $assigned = new Jlog_Db_Query($sql); 
    4759       if($assigned->error()) { 
    4860            echo "<pre>\n"; 
     
    167179                     '".$form_input['description']."');"; 
    168180 
    169         $new = new Query($sql); 
     181        $new = new Jlog_Db_Query($sql); 
    170182     
    171183        if($new->error()) { 
     
    189201                   id = '".$form_input['id']."' LIMIT 1;"; 
    190202 
    191         $change = new Query($sql); 
     203        $change = new Jlog_Db_Query($sql); 
    192204     
    193205        if($change->error()) { 
     
    202214     
    203215        $sql = "DELETE FROM ".JLOG_DB_CATEGORIES." WHERE id = '".escape_for_mysql($id)."' LIMIT 1"; 
    204         $trash = new Query($sql); 
     216        $trash = new Jlog_Db_Query($sql); 
    205217       if($trash->error()) { 
    206218        echo "<pre>\n"; 
     
    211223 
    212224        $sql = "DELETE FROM ".JLOG_DB_CATASSIGN." WHERE cat_id = '".escape_for_mysql($id)."' LIMIT 1"; 
    213         $trash = new Query($sql); 
     225        $trash = new Jlog_Db_Query($sql); 
    214226       if($trash->error()) { 
    215227        echo "<pre>\n"; 
     
    230242            $sql = "SELECT id FROM ".JLOG_DB_CATEGORIES." WHERE url = '".escape_for_mysql($form_input['url'])."';"; 
    231243     
    232             $check_url = new Query($sql); 
     244            $check_url = new Jlog_Db_Query($sql); 
    233245 
    234246            if($check_url->error()) { 
     
    248260    } 
    249261} 
    250 ?> 
     262 
     263// eof 
  • branches/1.5/lib/Jlog/Comments.php

    r1748 r1753  
    11<?php 
    22 
    3  function com_form_output($com_form) { 
    4  $com_form = array_htmlspecialchars($com_form); 
    5  global $l, $plugins; 
    6  if(!isset($com_form['content'])) $com_form['content'] = ""; 
     3class Jlog_Comments 
     4{ 
     5    function com_form_output($com_form) { 
     6        global $l, $plugins; 
     7        $com_form = array_htmlspecialchars($com_form); 
     8        if(!isset($com_form['content'])) $com_form['content'] = ""; 
     9         
     10        $output = " 
     11        <form method='post' action='#entryform' id='entryform'> 
     12        <fieldset><legend>".$l['comments_entryform']."</legend> 
     13        <p class='xmp'> 
     14         <span>".$l['comments_bbcode']." 
     15          <a onclick=\"jlog_learnbb('".JLOG_PATH."'); return false;\" href='".JLOG_PATH."/learn_bb.php'>BBcode</a>? 
     16         </span> 
     17         <br id='bbcode' /> 
     18         <textarea rows='8' cols='30' name='content'>".$com_form['content']."</textarea> 
     19        </p> 
     20        <p> 
     21         <input class='userdata' type='text' name='name' value='".$com_form['name']."' 
     22          onfocus=\"if(this.value &amp;&amp; this.value=='".$l['comments_name']."')this.value=''\" 
     23          onblur=\"if(this.value=='') this.value='".$l['comments_name']."'\" /> 
     24         <input class='userdata' type='text' name='city' value='".$com_form['city']."' 
     25          onfocus=\"if(this.value &amp;&amp; this.value=='".$l['comments_city']."')this.value=''\" 
     26          onblur=\"if(this.value=='') this.value='".$l['comments_city']."'\" /><br /> 
     27         <input class='userdata' type='text' name='email' value='".$com_form['email']."' 
     28          onfocus=\"if(this.value &amp;&amp; this.value=='".$l['comments_email']."')this.value=''\" 
     29          onblur=\"if(this.value=='') this.value='".$l['comments_email']."'\" /> 
     30         <input class='userdata' type='text' name='homepage' value='".$com_form['homepage']."' /> 
     31        </p> 
     32        <p class='checkbox'> 
     33         <input type='checkbox' id='mail_by_comment' name='mail_by_comment' "; 
     34        if(isset($com_form['mail_by_comment']) AND $com_form['mail_by_comment'] == 1) $output .= "checked='checked'"; 
     35        $output .= " value='1' /> <label for='mail_by_comment'>".$l['comments_mail_by_comment']."</label>&nbsp;"; 
     36        if(defined('JLOG_ADMIN')) $output .= "\n     <input type='hidden' value='".$com_form['id']."' name='id' />\n"; 
     37        else { 
     38            $output .= "   <input type='checkbox' id='cookie' name='cookie' "; 
     39            if(isset($com_form['cookie']) AND $com_form['cookie'] == 1) $output .= "checked='checked'"; 
     40            $output .= " value='1' /> <label for='cookie'>".$l['comments_save_data']."</label>\n"; 
     41        } 
     42        $output .= "     <input type='hidden' value='".$com_form['sid']."' name='sid' /> 
     43        </p> 
     44        <p> 
     45         <input class='send' type='submit' name='form_submitted' value='".$l['comments_preview']."' onclick=\"this.form.action = '#preview'\" /> 
     46         <input class='send' type='submit' name='form_submitted' value='".$l['comments_send']."' />"; 
     47         
     48        if(defined("JLOG_ADMIN")) $output .= add_session_id_input_tag(); 
     49         
     50        $output .= " 
     51        </p> 
     52        </fieldset> 
     53        </form>\n 
     54        "; 
     55         
     56        ### Plugin Hook 
     57        $output = $plugins->callHook('commentForm', $output, $com_form); 
     58         
     59        return $output; 
     60    } 
     61     
     62    function com_javascript_variables() { 
     63        global $l; 
     64        return " 
     65        <script type='text/javascript'> 
     66        jlog_l_comments_show = '".$l['comments_show']."'; 
     67        jlog_l_comments_hide = '".$l['comments_hide']."'; 
     68        jlog_l_comments_bold = '".$l['comments_bold']."'; 
     69        jlog_l_comments_italic = '".$l['comments_italic']."'; 
     70        jlog_l_comments_quote = '".$l['comments_quote']."'; 
     71        jlog_l_comments_url = '".$l['comments_url']."'; 
     72        jlog_l_comments_plz_format_txt = '".$l['comments_plz_format_txt']."'; 
     73        jlog_l_comments_url_href = '".$l['comments_url_href']."'; 
     74        jlog_l_comments_url_node = '".$l['comments_url_node']."'; 
     75        </script> 
     76        ";  
     77    } 
     78     
     79    function com_check_errors($com_form) { 
     80        global $l; 
     81        if(empty($com_form['sid'])) $errors[] = $l['comments_no_sid']; 
     82        if(isset($com_form['email']) AND $com_form['email'] != "" AND !preg_match("/^[^@]+@.+\.\D{2,6}$/", $com_form['email']) AND $com_form['email'] != $l['comments_email']) $errors[] = $l['comments_false_mail']; 
     83        if(empty($com_form['content'])) $errors[] = $l['comments_notext']; 
     84        if(isset($errors)) return $errors; 
     85    } 
     86     
     87    function com_clean_data($data) { 
     88        global $l; 
     89        if(empty($data['name']) OR $data['name'] == $l['comments_name']) $data['name'] = ""; 
     90        if(empty($data['city']) OR $data['city'] == $l['comments_city']) $data['city'] = ""; 
     91        if(empty($data['email']) OR $data['email'] == $l['comments_email']) $data['email'] = ""; 
     92        if(empty($data['homepage']) OR $data['homepage'] == $l['comments_homepage']) $data['homepage'] = ""; 
     93         
     94        if(empty($data['date'])) $data['date'] = time(); 
     95         
     96        return $data; 
     97    } 
     98     
     99    function set_cookie($data) { 
     100        $userdaten = array( $data['name'], 
     101                                 $data['city'], 
     102                                 $data['email'], 
     103                                 $data['homepage'] ); 
     104        $cookielife = time() + 42 * 24 * 60 * 60; 
     105        $path = parse_url(JLOG_PATH); 
     106        if(!isset($path['path'])) $path['path'] = ""; 
     107        setcookie("jlog_userdata", urlencode(serialize($userdaten)), $cookielife, $path['path']."/"); 
     108    } 
     109     
     110    function trash_cookie() { 
     111        $cookielife = time() - 3600; 
     112        setcookie("jlog_userdata", '', $cookielife, "/"); 
     113    } 
     114     
     115    function new_sid() { 
     116        list($usec, $sec) = explode(' ', microtime()); 
     117        mt_srand((float) $sec + ((float) $usec * 100000)); 
     118        return $_SERVER["REMOTE_ADDR"]."-".time()."-".mt_rand(1000,9999); 
     119    } 
     120     
     121    function do_comment($data, $nr) { 
     122        global $JLOG; 
     123        $bbcomments = $JLOG['bbcode']->forComments(); 
     124         
     125        $meta = array_htmlspecialchars($data); 
     126        $comment = " 
     127        <li id='c".$data['id']."'> 
     128        <p class='meta'><a class='permalink' title='".$l['comments_permalink']."' href='#c".$data['id']."'>".$nr."</a> <cite>"; 
     129        if(!empty($meta['homepage'])) $comment .= "<a title='".$meta['homepage']."' href='".$meta['homepage']."'>"; 
     130        if(!empty($meta['name'])) $comment .= $meta['name']; 
     131        else $comment .= $l['comments_anonym']; 
     132        if(!empty($meta['homepage'])) $comment .= "</a>"; 
     133        $comment .= "</cite>"; 
     134        if(!empty($meta['city'])) $comment .= " ".$l['comments_from']." ".$meta['city']; 
     135        $comment .= " ".$l['comments_posted']." ".strftime(JLOG_DATE_COMMENT, $data['date']).":</p>\n".$bbcomments->parse($data['content'])."</li>"; 
     136         
     137        ### Plugin Hook 
     138        $comment = $plugins->callHook('showComment', $comment, $data, $nr); 
     139         
     140        return $comment; 
     141    } 
     142} 
    7143 
    8   $output = " 
    9    <form method='post' action='#entryform' id='entryform'> 
    10     <fieldset><legend>".$l['comments_entryform']."</legend> 
    11     <p class='xmp'> 
    12      <span>".$l['comments_bbcode']." 
    13       <a onclick=\"jlog_learnbb('".JLOG_PATH."'); return false;\" href='".JLOG_PATH."/learn_bb.php'>BBcode</a>? 
    14      </span> 
    15      <br id='bbcode' />