Ignore:
Timestamp:
Jun 26, 2009, 11:52:25 AM (15 years ago)
Author:
Criss
Message:

Display edit block on picture page if request comes from this page
Add simple administration configuration management
Add and remove default configuration from databaseon plugin install / uninstall

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/CommentEditor/classes/ce_plugin.class.php

    r3443 r3462  
    11<?php
    2 /* $Id: ce_plugin.class.php,v 1.8 2009/06/22 22:18:14 Criss Exp $ */
     2/* $Id: ce_plugin.class.php,v 1.11 2009/06/26 09:17:01 Criss Exp $ */
    33if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    4 
    5 ce_require_class("CE_Comment");
    64
    75/**
     
    108class CE_Plugin {
    119
    12     var $comments_ids;
    13 
    14     /* ************************ */
    15     /* ** Trigger management ** */
    16     /* ************************ */
    17 
    18     /**
    19      * Update comment ID array
    20      */
    21     function render_comment_content($content) {
    22         $author = null;
    23         $id = null;
    24         switch (script_basename()) {
    25             case "comments":
    26                 global $comment;
    27                 $author = $comment['author'];
    28                 $id = $comment['comment_id'];
    29                 break;
    30             case "picture":
    31                 global $row;
    32                 $author = $row['author'];
    33                 $id = $row['id'];
    34                 break;
    35             default:
    36                 // Not in right script
    37                 return $content;
    38         }
    39         global $template, $user;
    40         if ((!is_a_guest() and ($user['username'] == $author))
    41             or is_admin()) {
    42             $key = count($template->get_template_vars('comments'));
    43             $this->comments_ids[$key] = $id;
    44         }
     10  var $comments_ids;
     11  var $config;
     12  var $plugin_id;
     13
     14  /* ************************ */
     15  /* ** Constructor        ** */
     16  /* ************************ */
     17
     18  function CE_Plugin($plugin_id, $config = null) {
     19    $this->plugin_id = $plugin_id;
     20    $this->config = $config;
     21    if (null != $this->config) {
     22      $this->config->loadConfig();
     23    }
     24  }
     25
     26  function getConfig() {
     27    return $this->config;
     28  }
     29
     30  /* ************************ */
     31  /* ** Trigger management ** */
     32  /* ************************ */
     33
     34  function get_admin_plugin_menu_links($menu) {
     35    array_push(
     36        $menu,
     37        array(
     38            'NAME' => $this->plugin_id,
     39            'URL' => $this->get_plugin_admin_url()
     40        )
     41    );
     42    return $menu;
     43  }
     44
     45  /**
     46   * Update comment ID array
     47   */
     48  function render_comment_content($content) {
     49    $author = null;
     50    $id = null;
     51    switch (script_basename()) {
     52      case "comments":
     53        global $comment;
     54        $author = $comment['author'];
     55        $id = $comment['comment_id'];
     56        break;
     57      case "picture":
     58        global $row;
     59        $author = $row['author'];
     60        $id = $row['id'];
     61        break;
     62      default:
     63        // Not in right script
    4564        return $content;
    4665    }
    47 
    48     /**
    49      * Check whether the page contains comments.
    50      * Add an edit link if user is allowed to edit comment
    51      */
    52     function loc_begin_page_header() {
    53         global $template;
    54         $comments = $template->get_template_vars('comments');
    55         if (!isset($comments) or (null == $comments)) {
    56             // No comment...
    57             return;
    58         }
    59         foreach ($comments as $key => $value) {
    60             if (isset($this->comments_ids[$key])) {
    61                 // User allowed to have edit link
    62                 $current_id = $this->comments_ids[$key];
    63                 $comments[$key]['U_ID'] =  $current_id;
    64                 $comments[$key]['DATE'] .= ' - <a href="';
    65                 $comments[$key]['DATE'] .= $this->getEditUrl($current_id);
    66                 $comments[$key]['DATE'] .= '">';
    67                 $comments[$key]['DATE'] .= 'Edit';
    68                 $comments[$key]['DATE'] .= '</a>';
    69             }
    70         }
    71         $template->assign('comments', $comments);
    72     }
    73 
    74     /**
    75      * Check whether a comment edit or update is requested.
    76      */
    77     function loc_begin_index() {
    78         $comment_id = "";
    79         $action = $this->isCommentEdit($_SERVER['QUERY_STRING'], $comment_id);
    80         switch ($action) {
     66    global $template, $conf, $user;
     67    if ((!is_a_guest() and ($user[$conf['user_fields']['username']] == $author))
     68        or is_admin()) {
     69      $key = count($template->get_template_vars('comments'));
     70      $this->comments_ids[$key] = $id;
     71    }
     72    return $content;
     73  }
     74
     75  /**
     76   * Check whether the page contains comments.
     77   * Add an edit link if user is allowed to edit comment
     78   */
     79  function loc_begin_page_header() {
     80    global $template;
     81    $comments = $template->get_template_vars('comments');
     82    if (!isset($comments) or (null == $comments)) {
     83      // No comment...
     84      return;
     85    }
     86    // Include language advices
     87    load_language('plugin.lang', CE_PATH);
     88    foreach ($comments as $key => $value) {
     89      if (isset($this->comments_ids[$key])) {
     90        // User allowed to have edit link
     91        $current_id = $this->comments_ids[$key];
     92        $comments[$key]['U_ID'] =  $current_id;
     93        $comments[$key]['DATE'] .= ' - <a href="';
     94        $comments[$key]['DATE'] .= $this->getEditUrl($current_id);
     95        $comments[$key]['DATE'] .= '">';
     96        $comments[$key]['DATE'] .= l10n('comment_edit_tool');
     97        $comments[$key]['DATE'] .= '</a>';
     98      }
     99    }
     100    $template->assign('comments', $comments);
     101  }
     102
     103  /**
     104   * Check whether a comment edit or update is requested.
     105   */
     106  function loc_begin_index() {
     107    $this->doAction();
     108  }
     109
     110  function loc_begin_picture() {
     111    $this->doAction();
     112  }
     113
     114  /* ************************ */
     115  /* ** Private functions  ** */
     116  /* ************************ */
     117
     118  function doAction() {
     119    $comment_id = "";
     120    $action = $this->isCommentEdit($_SERVER['QUERY_STRING'], $comment_id);
     121    switch ($action) {
     122      case CE_ACTION_EDIT:
     123        // Edit
     124        $this->editComment($comment_id);
     125        break;
     126      case CE_ACTION_UPDATE:
     127        $this->updateComment();
     128        break;
     129      case CE_ACTION_ERROR:
     130        $infos = array('comment_edit_forbidden');
     131        $this->displayError($infos);
     132        break;
     133      case CE_ACTION_NONE:
     134        // Not an edit mode
     135        break;
     136    }
     137  }
     138
     139  function getTemplate($p_template = 'edit.tpl') {
     140    return realpath(CE_TEMPLATE . $p_template);
     141  }
     142
     143  function isCommentEdit($p_query_string, &$p_comment_id) {
     144    $params = split('\&', $p_query_string);
     145    $action = CE_ACTION_NONE;
     146    $comment_id = "";
     147    foreach ($params as $current_param) {
     148      $key_value = split('=', $current_param);
     149      if (isset($key_value[1])) {
     150        if (CE_ACTION == $key_value[0] && CE_ACTION_NONE == $action) {
     151          switch ($key_value[1]) {
    81152            case CE_ACTION_EDIT:
    82                 // Edit
    83                 $this->editComment($comment_id);
    84                 break;
    85153            case CE_ACTION_UPDATE:
    86                 $this->updateComment();
    87                 break;
    88             case CE_ACTION_ERROR:
    89                 $infos = array('comment_edit_forbidden');
    90                 $this->displayError($infos);
    91                 break;
    92             case CE_ACTION_NONE:
    93                 // Not an edit mode
    94                 break;
    95         }
    96     }
    97 
    98     /* ************************ */
    99     /* ** Private functions  ** */
    100     /* ************************ */
    101 
    102     function getTemplate($p_template = 'edit.tpl') {
    103         return realpath(CE_TEMPLATE . $p_template);
    104     }
    105 
    106     function isCommentEdit($p_query_string, &$p_comment_id) {
    107         $params = split('\&', $p_query_string);
    108         $action = CE_ACTION_NONE;
    109         $comment_id = "";
    110         foreach ($params as $current_param) {
    111             $key_value = split('=', $current_param);
    112             if (isset($key_value[1])) {
    113                 if (CE_ACTION == $key_value[0] && CE_ACTION_NONE == $action) {
    114                     //CE_ACTION_EDIT == $lKeyVal[1]
    115                     switch ($key_value[1]) {
    116                         case CE_ACTION_EDIT:
    117                         case CE_ACTION_UPDATE:
    118                             $action = $key_value[1];
    119                             break;
    120                     }
    121                 }
    122                 if (CE_ID == $key_value[0]) {
    123                     $comment_id = $key_value[1];
    124                 }
    125             }
    126         }
    127         if (CE_ACTION_EDIT == $action) {
    128             if (is_numeric($comment_id)) {
    129                 $p_comment_id = intval($comment_id);
    130             } else {
    131                 $action = CE_ACTION_ERROR;
    132             }
    133         }
    134         return $action;
    135     }
    136 
    137     function isEditAllowed($p_comment) {
    138         if ((FALSE == $p_comment->getInfo()) or
    139              is_a_guest()) {
    140             return false;
    141         }
    142         if (is_admin() and !is_adviser()) {
    143             return true;
    144         }
    145         global $user;
    146         return $p_comment->isAuthor($user['username']);
    147     }
    148 
    149     function editComment($p_comment_id) {
    150         //  Include language advices
    151         load_language('plugin.lang', CE_PATH);
    152 
    153         $comment = new CE_Comment($p_comment_id);
    154         $infos = array();
    155         if (!$this->isEditAllowed($comment)) {
    156             // Not allowed
    157             array_push($infos, 'comment_edit_forbidden');
    158             $this->displayError($infos);
    159             return;
    160         }
    161         $this->displayComment($comment);
    162     }
    163 
    164     function updateComment() {
    165         //  Include language advices
    166         load_language('plugin.lang', CE_PATH);
    167 
    168         $infos = array();
    169         if ((!isset($_POST['commentid'])) or
    170             (!isset($_POST['imageid']))) {
    171             array_push($infos, 'comment_access_invalid');
    172             $this->displayError($infos);
    173             return;
    174         }
    175         if (!is_numeric($_POST['imageid'])) {
    176             array_push($infos, 'comment_access_invalid');
    177             $this->displayError($infos);
    178             return;
    179         }
    180         $comment = new CE_Comment($_POST['commentid']);
    181 
    182         if (!$this->isEditAllowed($comment)) {
    183             array_push($infos, 'comment_edit_forbidden');
    184             $this->displayError($infos);
    185             return;
    186         }
    187         $image_id = $comment->getInfo('image_id');
    188         if (intval($_POST['imageid']) != intval($image_id)) {
    189             array_push($infos, 'comment_access_invalid');
    190             $this->displayError($infos);
    191             return;
    192         }
    193         if (isset($_POST['author'])) {
    194             $comment->setInfo('author', $_POST['author']);
    195         } else if ((isset($_POST['freeauthorck'])) and
    196                    (isset($_POST['freeauthor']))) {
    197             // Free author
    198             $new_author = trim(stripslashes($_POST['freeauthor']));
    199             $new_author = $comment->validateAuthor($new_author);
    200             $comment->setInfo('author', $new_author);
    201         }
    202 
    203         $comment_array = array(
    204             'author'        => trim( stripslashes($comment->getInfo('author')) ),
    205             'content'       => trim( stripslashes($_POST['content']) ),
    206             'image_id'      => $image_id,
    207             'comment_id'    => $comment->getInfo('comment_id'),
    208         );
    209 
    210         // Deactivate anti-flood system
    211         global $conf;
    212         $old_anti_flood = $conf['anti-flood_time'];
    213         $conf['anti-flood_time'] = 0;
    214 
    215         $comment_action = update_user_comment($comment_array, @$_POST['key'], $infos );
    216 
    217         // Reactivate anti-flood system
    218         $conf['anti-flood_time'] = $old_anti_flood;
    219 
    220         switch ($comment_action) {
    221             case 'moderate':
    222               array_push( $infos, 'comment_to_validate' );
    223             case 'validate':
    224               array_push( $infos, 'comment_added');
    225               break;
    226             case 'reject':
    227               set_status_header(403);
    228               array_push($infos, 'comment_not_added' );
     154              $action = $key_value[1];
    229155              break;
    230156            default:
    231               trigger_error('Invalid comment action '.$comment_action, E_USER_WARNING);
     157          }
    232158        }
    233         // allow plugins to notify what's going on
    234         trigger_action( 'user_comment_insertion',
    235                         array_merge($comment_array, array('action'=>$comment_action)));
    236         if ($comment_action=='reject') {
    237             $this->displayError($infos);
    238         } else {
    239             $this->displayInfo($infos);
     159        if (CE_ID == $key_value[0]) {
     160          $comment_id = $key_value[1];
    240161        }
    241     }
    242 
    243     function getCommentId($p_string_delete) {
    244         $comment_id = "";
    245         $elements = split('\?', $p_string_delete);
    246         if (count($elements) > 1) {
    247             $elem_var = split('\&amp;', $elements[1]);
    248             foreach ($elem_var as $var) {
    249                 $key_value = split('=', $var);
    250                 if (count($key_value) > 1) {
    251                     switch ($key_value[0]) {
    252                         case 'comment_to_delete':
    253                         case 'delete':
    254                             $comment_id = $key_value[1];
    255                             break;
    256                         default:
    257                             // No ID
    258                     }
    259                 }
    260             }
     162      }
     163    }
     164    if (CE_ACTION_EDIT == $action) {
     165      if (is_numeric($comment_id)) {
     166        $p_comment_id = intval($comment_id);
     167      } else {
     168        $action = CE_ACTION_ERROR;
     169      }
     170    }
     171    return $action;
     172  }
     173
     174  function isEditAllowed($p_comment) {
     175    if ((FALSE == $p_comment->getInfo()) or
     176        is_a_guest()) {
     177      return false;
     178    }
     179    if (is_admin() and !is_adviser()) {
     180      return true;
     181    }
     182    global $conf, $user;
     183    return $p_comment->isAuthor($user[$conf['user_fields']['username']]);
     184  }
     185
     186  function editComment($p_comment_id) {
     187    $comment = new CE_Comment($p_comment_id);
     188    $infos = array();
     189    if (!$this->isEditAllowed($comment)) {
     190      // Not allowed
     191      array_push($infos, 'comment_edit_forbidden');
     192      $this->displayError($infos);
     193      return;
     194    }
     195    $this->displayComment($comment);
     196  }
     197
     198  function updateComment() {
     199    $infos = array();
     200    if ((!isset($_POST['ce_commentid'])) or
     201        (!isset($_POST['ce_imageid']))) {
     202      array_push($infos, 'comment_access_invalid');
     203      $this->displayError($infos);
     204      return;
     205    }
     206    if (!is_numeric($_POST['ce_imageid'])) {
     207      array_push($infos, 'comment_access_invalid');
     208      $this->displayError($infos);
     209      return;
     210    }
     211    $comment = new CE_Comment($_POST['ce_commentid']);
     212
     213    if (!$this->isEditAllowed($comment)) {
     214      array_push($infos, 'comment_edit_forbidden');
     215      $this->displayError($infos);
     216      return;
     217    }
     218    $image_id = $comment->getInfo('image_id');
     219    if (intval($_POST['ce_imageid']) != intval($image_id)) {
     220      array_push($infos, 'comment_access_invalid');
     221      $this->displayError($infos);
     222      return;
     223    }
     224    if (isset($_POST['ce_author'])) {
     225      $comment->setInfo('author', $_POST['ce_author']);
     226    } else if ((isset($_POST['ce_freeauthorck'])) and
     227               (isset($_POST['ce_freeauthor']))) {
     228      // Free author
     229      $new_author = trim(stripslashes($_POST['ce_freeauthor']));
     230      $new_author = $comment->validateAuthor($new_author);
     231      $comment->setInfo('author', $new_author);
     232    }
     233
     234    $comment_array = array(
     235      'author'      => trim( stripslashes($comment->getInfo('author')) ),
     236      'content'     => trim( stripslashes($_POST['ce_content']) ),
     237      'image_id'    => $image_id,
     238      'comment_id'  => $comment->getInfo('comment_id'),
     239    );
     240
     241    // Deactivate anti-flood system
     242    global $conf;
     243    $old_anti_flood = $conf['anti-flood_time'];
     244    $conf['anti-flood_time'] = 0;
     245
     246    $comment_action = update_user_comment($comment_array, @$_POST['key'], $infos );
     247
     248    // Reactivate anti-flood system
     249    $conf['anti-flood_time'] = $old_anti_flood;
     250
     251    switch ($comment_action) {
     252      case 'moderate':
     253        array_push( $infos, 'comment_to_validate' );
     254      case 'validate':
     255        array_push( $infos, 'comment_added');
     256        break;
     257      case 'reject':
     258        set_status_header(403);
     259        array_push($infos, 'comment_not_added' );
     260        break;
     261      default:
     262        trigger_error('Invalid comment action '.$comment_action, E_USER_WARNING);
     263    }
     264
     265    // allow plugins to notify what's going on
     266    trigger_action( 'user_comment_insertion',
     267                    array_merge($comment_array, array('action'=>$comment_action)));
     268    if ($comment_action=='reject') {
     269      $this->displayError($infos);
     270    } else {
     271      $this->displayInfo($infos);
     272    }
     273  }
     274
     275  function getCommentId($p_string_delete) {
     276    $comment_id = "";
     277    $elements = split('\?', $p_string_delete);
     278    if (count($elements) > 1) {
     279      $elem_var = split('\&amp;', $elements[1]);
     280      foreach ($elem_var as $var) {
     281        $key_value = split('=', $var);
     282        if (count($key_value) > 1) {
     283          switch ($key_value[0]) {
     284            case 'comment_to_delete':
     285            case 'delete':
     286              $comment_id = $key_value[1];
     287              break;
     288            default:
     289              // No ID
     290          }
    261291        }
    262         return $comment_id;
    263     }
    264 
    265     function displayError($p_error) {
     292      }
     293    }
     294    return $comment_id;
     295  }
     296
     297  function displayError($p_error) {
     298    if ($this->config->getValue(CE_CFG_DISPLAY_ERROR)) {
    266299        $this->displayMessage($p_error, CE_TYPE_ERROR, CE_ERRORS);
    267300    }
    268 
    269     function displayInfo($p_info) {
    270         $this->displayMessage($p_info, CE_TYPE_INFO, CE_INFOS);
    271     }
    272 
    273     function displayMessage($p_message, $p_type, $p_image) {
    274         //  Include language advices
    275         load_language('plugin.lang', CE_PATH);
    276 
    277         $messages = array();
    278         foreach ($p_message as $message) {
    279             array_push($messages, l10n($message));
    280         }
    281         $message_array = array(
    282             'TYPE'  => $p_type,
    283             'IMG'   => $p_image,
    284             'TITLE' => l10n($p_type),
    285             'MSG'   => $messages
    286         );
    287 
    288         global $template;
    289         if ("" == $template->get_template_vars('U_HOME')) {
    290             $template->assign('U_HOME', make_index_url());
    291         }
    292         $template->set_filenames(array('ce_message'=>$this->getTemplate('message.tpl')));
    293         $template->block_html_head( '',
    294                                     '<link rel="stylesheet" type="text/css" href="'.CE_STYLE.'">',
    295                                     $smarty, $repeat);
    296         $begin = 'PLUGIN_INDEX_CONTENT_BEFORE';
    297         $template->assign('message', $message_array);
    298         $old_begin = $template->get_template_vars($begin);
    299         $template->assign($begin, $template->parse('ce_message', true));
    300         $template->concat($begin, $old_begin);
    301     }
    302 
    303     function displayComment($p_comment) {
    304         global $template;
    305         $template->set_filenames(array('ce_edit'=>$this->getTemplate()));
    306         $template->block_html_head( '',
    307                                     '<link rel="stylesheet" type="text/css" href="'.CE_STYLE.'">',
    308                                     $smarty, $repeat);
     301  }
     302
     303  function displayInfo($p_info) {
     304    if ($this->config->getValue(CE_CFG_DISPLAY_INFO)) {
     305      $this->displayMessage($p_info, CE_TYPE_INFO, CE_INFOS);
     306    }
     307  }
     308
     309  function displayMessage($p_message, $p_type, $p_image) {
     310    // Include language advices
     311    load_language('plugin.lang', CE_PATH);
     312
     313    $messages = array();
     314    foreach ($p_message as $message) {
     315      array_push($messages, l10n($message));
     316    }
     317    $message_array = array(
     318      'TYPE'  => $p_type,
     319      'IMG'   => $p_image,
     320      'TITLE' => l10n($p_type),
     321      'MSG'   => $messages
     322    );
     323
     324    global $template;
     325    if ("" == $template->get_template_vars('U_HOME')) {
     326      $template->assign('U_HOME', make_index_url());
     327    }
     328    $template->set_filenames(array('ce_message'=>$this->getTemplate('message.tpl')));
     329    $template->block_html_head( '',
     330                  '<link rel="stylesheet" type="text/css" href="'
     331                  .CE_INCLUDE . $this->getScriptName() . '.css'
     332                  .'">',
     333    $smarty, $repeat);
     334    if (!$this->setBeginEndFields($begin, $end)) {
     335      return;
     336    }
     337
     338    $template->assign('message', $message_array);
     339    $old_begin = $template->get_template_vars($begin);
     340    $template->assign($begin, $template->parse('ce_message', true));
     341    $template->concat($begin, $old_begin);
     342  }
     343
     344  function displayComment($p_comment) {
     345    // Include language advices
     346    load_language('plugin.lang', CE_PATH);
     347
     348    global $template;
     349    $template->set_filenames(array('ce_edit'=>$this->getTemplate()));
     350    $template->block_html_head( '',
     351                  '<link rel="stylesheet" type="text/css" href="'
     352                  .CE_INCLUDE . $this->getScriptName() . '.css'
     353                  .'">',
     354    $smarty, $repeat);
     355
     356    if (!$this->setBeginEndFields($begin, $end)) {
     357      return;
     358    }
     359
     360    $tpl_comment = array(
     361      'CONTENT'   => $p_comment->getInfo('content'),
     362      'KEY'       => $p_comment->getInfo('comment_id'),
     363      'AUTHOR'    => $p_comment->getInfo('author'),
     364      'IMAGE'     => $p_comment->getInfo('image_id'),
     365      'DISABLED'  => !is_admin(),
     366      'USERS'     => CE_Comment::getUsers(),
     367      'F_ACTION'  => $this->getUpdateUrl(),
     368      'FREEAUTHOR'=> ($p_comment->isKnownAuthor())?'':'checked="checked"'
     369      );
     370      if ("" == $template->get_template_vars('U_HOME')) {
     371        $template->assign('U_HOME', make_index_url());
     372      }
     373      $template->assign('comment', $tpl_comment);
     374      $old_begin = $template->get_template_vars($begin);
     375      $template->assign($begin, $template->parse('ce_edit', true));
     376      $template->concat($begin, $old_begin);
     377  }
     378
     379  function setBeginEndFields(&$begin, &$end) {
     380    switch (script_basename()) {
     381      case 'index':
    309382        $begin = 'PLUGIN_INDEX_CONTENT_BEFORE';
    310383        $end = 'PLUGIN_INDEX_CONTENT_AFTER';
    311         $template->assign($begin, null);
    312         $template->assign($end, null);
    313         $tpl_comment = array(
    314             'CONTENT'   => $p_comment->getInfo('content'),
    315             'KEY'       => $p_comment->getInfo('comment_id'),
    316             'AUTHOR'    => $p_comment->getInfo('author'),
    317             'IMAGE'     => $p_comment->getInfo('image_id'),
    318             'DISABLED'  => !is_admin(),
    319             'USERS'     => CE_Comment::getUsers(),
    320             'F_ACTION'  => $this->getUpdateUrl(),
    321             'FREEAUTHOR'=> ($p_comment->isKnownAuthor())?'':'checked="checked"'
    322         );
    323         if ("" == $template->get_template_vars('U_HOME')) {
    324             $template->assign('U_HOME', make_index_url());
    325         }
    326         $template->assign('comment', $tpl_comment);
    327         $template->concat($begin, $template->parse('ce_edit', true));
    328 
    329     }
    330 
    331     function getScriptName() {
    332         // By now, still in index page
    333         // return script_basename();
     384        break;
     385      case 'picture':
     386        $begin = 'PLUGIN_PICTURE_BEFORE';
     387        $end = 'PLUGIN_PICTURE_AFTER';
     388        break;
     389      default:
     390        return FALSE;
     391    }
     392    return TRUE;
     393  }
     394
     395  function getScriptName() {
     396    switch (script_basename()) {
     397      case 'index':
     398      case 'picture':
     399        return script_basename();
     400      default:
    334401        return 'index';
    335402    }
    336 
    337     function getEditUrl($comment_id) {
    338         $url  = get_root_url() . $this->getScriptName() . '.php';
    339         // By now, still in index pages without params
    340         // $url .= get_query_string_diff(array(CE_ACTION, CE_ID));
    341         $url = add_url_params(  $url,
    342                                 array(
    343                                     CE_ACTION => CE_ACTION_EDIT,
    344                                     CE_ID=>$comment_id
    345                                 )
    346         );
    347         return $url;
    348     }
    349 
    350     function getUpdateUrl() {
    351         $url  = get_root_url() . script_basename() .'.php';
    352         // By now, still in index pages without params
    353         // $url .= get_query_string_diff(array(CE_ACTION, CE_ID));
    354         $url = add_url_params(  $url,
    355                                 array(
    356                                     CE_ACTION => CE_ACTION_UPDATE
    357                                 )
    358         );
    359         return $url;
    360     }
     403  }
     404
     405  function getEditUrl($comment_id) {
     406    $url  = get_root_url() . $this->getScriptName() . '.php';
     407    $url .= get_query_string_diff(array(CE_ACTION, CE_ID));
     408    $url = add_url_params($url,
     409                          array(
     410                            CE_ACTION => CE_ACTION_EDIT,
     411                            CE_ID=>$comment_id
     412                          )
     413            );
     414    return $url;
     415  }
     416
     417  function getUpdateUrl() {
     418    $url  = get_root_url() . $this->getScriptName() .'.php';
     419    $url .= get_query_string_diff(array(CE_ACTION, CE_ID));
     420    $url = add_url_params($url,
     421                          array(
     422                            CE_ACTION => CE_ACTION_UPDATE
     423                          )
     424            );
     425    return $url;
     426  }
     427
     428  function get_plugin_admin_url() {
     429    return get_admin_plugin_menu_link(CE_PATH . 'administration.php');
     430  }
    361431
    362432}
Note: See TracChangeset for help on using the changeset viewer.