Changeset 3439


Ignore:
Timestamp:
Jun 22, 2009, 2:30:31 PM (12 years ago)
Author:
Criss
Message:

Add coment edit link for author even if he's not an admin
Code cleanup

Location:
extensions/CommentEditor
Files:
3 edited

Legend:

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

    r3434 r3439  
    11<?php
    2 /* $Id: ce_plugin.class.php,v 1.6 2009/06/18 21:02:12 Criss Exp $ */
     2/* $Id: ce_plugin.class.php,v 1.7 2009/06/22 12:25:04 Criss Exp $ */
    33if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    44
     
    1010class CE_Plugin {
    1111
     12    var $comments_ids;
    1213    private static $url_prefix = null;
    1314
     
    2223    /* ** Trigger management ** */
    2324    /* ************************ */
     25
     26    /**
     27     * Update comment ID array
     28     */
     29    function render_comment_content($content) {
     30        $author = null;
     31        $id = null;
     32        switch (script_basename()) {
     33            case "comments":
     34                global $comment;
     35                $author = $comment['author'];
     36                $id = $comment['comment_id'];
     37                break;
     38            case "picture":
     39                global $row;
     40                $author = $row['author'];
     41                $id = $row['id'];
     42                break;
     43            default:
     44                // Not in right script
     45                return $content;
     46        }
     47        global $template, $user;
     48        if ((!is_a_guest() and ($user['username'] == $author))
     49            or is_admin()) {
     50            $key = count($template->get_template_vars('comments'));
     51            $this->comments_ids[$key] = $id;
     52        }
     53        return $content;
     54    }
    2455
    2556    /**
     
    2960    function loc_begin_page_header() {
    3061        global $template;
    31         $all_comments = &$template->get_template_vars('comments');
    32         for ($i=0; $i < count($all_comments) ; $i++) {
    33             if (isset($all_comments[$i]) and is_array($all_comments[$i])) {
    34                 $comment = &$all_comments[$i];
    35                 if (isset($comment['U_DELETE'])) {
    36                     $comment['U_ID'] =  $this->getCommentId($comment['U_DELETE']);
    37                     $comment['DATE'] .= ' - <a href="' . $this->getEditUrlPrefix();
    38                     $comment['DATE'] .= $comment['U_ID'] . '">';
    39                     $comment['DATE'] .= 'Edit';
    40                     $comment['DATE'] .= '</a>';
    41                 }
     62        $comments = $template->get_template_vars('comments');
     63        if (!isset($comments) or (null == $comments)) {
     64            // No comment...
     65            return;
     66        }
     67        foreach ($comments as $key => $value) {
     68            if (isset($this->comments_ids[$key])) {
     69                // User allowed to have edit link
     70                $comments[$key]['U_ID'] =  $this->comments_ids[$key];
     71                $comments[$key]['DATE'] .= ' - <a href="' . $this->getEditUrlPrefix();
     72                $comments[$key]['DATE'] .= $comments[$key]['U_ID'] . '">';
     73                $comments[$key]['DATE'] .= 'Edit';
     74                $comments[$key]['DATE'] .= '</a>';
    4275            }
    4376        }
     77        $template->assign('comments', $comments);
    4478    }
    4579
     
    108142
    109143    function isEditAllowed($p_comment) {
    110         if (FALSE == $p_comment->getInfo()) {
     144        if ((FALSE == $p_comment->getInfo()) or
     145             is_a_guest()) {
    111146            return false;
    112147        }
  • extensions/CommentEditor/include/ce_common.inc.php

    r3436 r3439  
    33if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    44
    5 define('CE_VERSION',       '1.0.e');
     5define('CE_VERSION',       '1.0.f');
    66define('CE_INCLUDE_DIR',   'include/');
    77define('CE_CLASSES_DIR',   'classes/');
  • extensions/CommentEditor/main.inc.php

    r3436 r3439  
    11<?php
    2 /* $Id: main.inc.php,v 1.6 2009/06/18 21:02:12 Criss Exp $ */
     2/* $Id: main.inc.php,v 1.8 2009/06/22 12:25:04 Criss Exp $ */
    33/*
    44 Plugin Name: Comment Editor
    5  Version: 1.0.e
     5 Version: 1.0.f
    66 Description: Allow to edit comment
    77 Plugin URI: http://piwigo.org/ext/extension_view.php?eid=296
     
    1111
    1212/** History **
     13
     14    2009-06-22 1.0.f
     15                        Add edit link for author even if he's not an admin
     16                        Code cleanup
    1317
    1418    2009-06-18 1.0.e
     
    3640
    3741$ce_plugin = new CE_Plugin();
     42add_event_handler(  'render_comment_content',
     43                    array(&$ce_plugin, 'render_comment_content'));
    3844add_event_handler(  'loc_begin_page_header',
    3945                    array(&$ce_plugin, 'loc_begin_page_header'));
Note: See TracChangeset for help on using the changeset viewer.