Ignore:
Timestamp:
Jun 30, 2009, 9:05:35 PM (15 years ago)
Author:
Criss
Message:

Add toolbar trigger for edit template

File:
1 edited

Legend:

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

    r3473 r3475  
    11<?php
    2 /* $Id: ce_plugin.class.php,v 1.12 2009/06/29 11:43:18 Criss Exp $ */
     2/* $Id: ce_plugin.class.php,v 1.13 2009/06/30 19:01:50 Criss Exp $ */
    33if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    44
     
    6565    }
    6666    global $template, $conf, $user;
    67     if ((!is_a_guest() and ($user[$conf['user_fields']['username']] == $author))
     67    if ((!is_a_guest()
     68          and ($user[$conf['user_fields']['username']] == $author))
    6869        or is_admin()) {
    6970      $key = count($template->get_template_vars('comments'));
     
    9495        $comments[$key]['DATE'] .= $this->getEditUrl($current_id);
    9596        $comments[$key]['DATE'] .= '">';
    96         $comments[$key]['DATE'] .= l10n('comment_edit_tool');
     97        $comments[$key]['DATE'] .= l10n('ce_edit_tool');
    9798        $comments[$key]['DATE'] .= '</a>';
    9899      }
     
    129130  function doAction() {
    130131    $comment_id = "";
    131     $action = $this->isCommentEdit($_SERVER['QUERY_STRING'], $comment_id);
     132    $action = $this->isCommentEdit($comment_id);
    132133    switch ($action) {
    133134      case CE_ACTION_EDIT:
     
    139140        break;
    140141      case CE_ACTION_ERROR:
    141         $infos = array('comment_edit_forbidden');
     142        $infos = array('ce_edit_forbidden');
    142143        $this->displayError($infos);
    143144        break;
     
    152153  }
    153154
    154   function isCommentEdit($p_query_string, &$p_comment_id) {
    155     $params = split('\&', $p_query_string);
     155  function isCommentEdit(&$p_comment_id) {
    156156    $action = CE_ACTION_NONE;
    157157    $comment_id = "";
    158     foreach ($params as $current_param) {
    159       $key_value = split('=', $current_param);
    160       if (isset($key_value[1])) {
    161         if (CE_ACTION == $key_value[0] && CE_ACTION_NONE == $action) {
    162           switch ($key_value[1]) {
    163             case CE_ACTION_EDIT:
    164             case CE_ACTION_UPDATE:
    165               $action = $key_value[1];
    166               break;
    167             default:
    168           }
    169         }
    170         if (CE_ID == $key_value[0]) {
    171           $comment_id = $key_value[1];
    172         }
     158    if (isset($_GET[CE_ACTION])) {
     159      switch ($_GET[CE_ACTION]) {
     160        case CE_ACTION_EDIT:
     161        case CE_ACTION_UPDATE:
     162          $action = $_GET[CE_ACTION];
     163          break;
     164        default:
    173165      }
     166    }
     167    if (isset($_GET[CE_ID])) {
     168        $comment_id = $_GET[CE_ID];
    174169    }
    175170    if (CE_ACTION_EDIT == $action) {
     
    200195    if (!$this->isEditAllowed($comment)) {
    201196      // Not allowed
    202       array_push($infos, 'comment_edit_forbidden');
     197      array_push($infos, 'ce_edit_forbidden');
    203198      $this->displayError($infos);
    204199      return;
     
    211206    if ((!isset($_POST['ce_commentid'])) or
    212207        (!isset($_POST['ce_imageid']))) {
    213       array_push($infos, 'comment_access_invalid');
     208      array_push($infos, 'ce_access_invalid');
    214209      $this->displayError($infos);
    215210      return;
    216211    }
    217212    if (!is_numeric($_POST['ce_imageid'])) {
    218       array_push($infos, 'comment_access_invalid');
     213      array_push($infos, 'ce_access_invalid');
    219214      $this->displayError($infos);
    220215      return;
     
    223218
    224219    if (!$this->isEditAllowed($comment)) {
    225       array_push($infos, 'comment_edit_forbidden');
     220      array_push($infos, 'ce_edit_forbidden');
    226221      $this->displayError($infos);
    227222      return;
     
    229224    $image_id = $comment->getInfo('image_id');
    230225    if (intval($_POST['ce_imageid']) != intval($image_id)) {
    231       array_push($infos, 'comment_access_invalid');
     226      array_push($infos, 'ce_access_invalid');
    232227      $this->displayError($infos);
    233228      return;
     
    255250    $conf['anti-flood_time'] = 0;
    256251
    257     $comment_action = update_user_comment($comment_array, @$_POST['key'], $infos );
     252    $comment_action = update_user_comment($comment_array,
     253                                          @$_POST['key'],
     254                                          $infos );
    258255
    259256    // Reactivate anti-flood system
     
    271268        break;
    272269      default:
    273         trigger_error('Invalid comment action '.$comment_action, E_USER_WARNING);
     270        trigger_error('Invalid comment action '.$comment_action,
     271                      E_USER_WARNING);
    274272    }
    275273
    276274    // allow plugins to notify what's going on
    277275    trigger_action( 'user_comment_insertion',
    278                     array_merge($comment_array, array('action'=>$comment_action)));
     276                    array_merge($comment_array, array('action'=>
     277                                                      $comment_action)));
    279278    if ($comment_action=='reject') {
    280279      $this->displayError($infos);
     
    329328      'TYPE'  => $p_type,
    330329      'IMG'   => $p_image,
    331       'TITLE' => l10n($p_type),
     330      'TITLE' => l10n('ce_'.$p_type),
    332331      'MSG'   => $messages
    333332    );
    334333
    335334    global $template;
    336     if ("" == $template->get_template_vars('U_HOME')) {
    337       $template->assign('U_HOME', make_index_url());
    338     }
    339     $template->set_filenames(array('ce_message'=>$this->getTemplate('message.tpl')));
     335
     336    $ce_exit = array(
     337      'URL'   => $this->getBaseUrl(),
     338      'TITLE' => 'ce_close_message_title',
     339      'ALT'   => 'ce_close_message_alt',
     340      'IMG'   => CE_CLOSE_IMG
     341    );
     342    $template->assign('ce_exit', $ce_exit);
     343    $template->set_filenames( array('ce_message'=>
     344                                    $this->getTemplate('message.tpl')));
    340345    $template->block_html_head( '',
    341346                  '<link rel="stylesheet" type="text/css" href="'
     
    347352    }
    348353
    349     $template->assign('message', $message_array);
     354    $template->assign('ce_message', $message_array);
    350355    $old_begin = $template->get_template_vars($begin);
    351356    $template->assign($begin, $template->parse('ce_message', true));
     
    374379      'AUTHOR'    => $p_comment->getInfo('author'),
    375380      'IMAGE'     => $p_comment->getInfo('image_id'),
    376       'DISABLED'  => !is_admin(),
    377       'USERS'     => CE_Comment::getUsers(),
    378       'F_ACTION'  => $this->getUpdateUrl(),
    379       'FREEAUTHOR'=> ($p_comment->isKnownAuthor())?'':'checked="checked"'
     381      'F_ACTION'  => $this->getUpdateUrl()
    380382      );
    381       if ("" == $template->get_template_vars('U_HOME')) {
    382         $template->assign('U_HOME', make_index_url());
    383       }
    384       $template->assign('comment', $tpl_comment);
    385       $old_begin = $template->get_template_vars($begin);
    386       $template->assign($begin, $template->parse('ce_edit', true));
    387       $template->concat($begin, $old_begin);
     383
     384    if (is_admin()) {
     385      $tpl_comment['USERS'] = CE_Comment::getUsers();
     386      $tpl_comment['FREEAUTHOR'] = ($p_comment->isKnownAuthor())?
     387                                        '':CE_CHECKED;
     388    }
     389
     390    $additional_toolbar = "";
     391    $additional_toolbar = trigger_event('comment_editor_toolbar',
     392                                        $additional_toolbar);
     393    if ("" != $additional_toolbar) {
     394        $tpl_comment['TOOLBAR'] = $additional_toolbar;
     395    }
     396
     397    $ce_exit = array(
     398      'URL'   => $this->getBaseUrl(),
     399      'TITLE' => 'ce_close_editor_title',
     400      'ALT'   => 'ce_close_editor_alt',
     401      'IMG'   => CE_CLOSE_IMG
     402    );
     403    $template->assign('ce_exit', $ce_exit);
     404
     405    $template->assign('comment_editor', $tpl_comment);
     406    $old_begin = $template->get_template_vars($begin);
     407    $template->assign($begin, $template->parse('ce_edit', true));
     408    $template->concat($begin, $old_begin);
    388409  }
    389410
     
    414435  }
    415436
    416   function getEditUrl($comment_id) {
     437  function getBaseUrl() {
    417438    $url  = get_root_url() . $this->getScriptName() . '.php';
    418439    $url .= get_query_string_diff(array(CE_ACTION, CE_ID));
     440    return $url;
     441  }
     442
     443  function getEditUrl($comment_id) {
     444    $url = $this->getBaseUrl();
    419445    $url = add_url_params($url,
    420446                          array(
     
    427453
    428454  function getUpdateUrl() {
    429     $url  = get_root_url() . $this->getScriptName() .'.php';
    430     $url .= get_query_string_diff(array(CE_ACTION, CE_ID));
     455    $url = $this->getBaseUrl();
    431456    $url = add_url_params($url,
    432457                          array(
Note: See TracChangeset for help on using the changeset viewer.