Changeset 24889


Ignore:
Timestamp:
10/14/13 18:35:28 (6 years ago)
Author:
mistic100
Message:

use my plugin architecture, add options to hide the page for guests, fix admin links in mails

Location:
extensions/GuestBook
Files:
2 added
12 edited

Legend:

Unmodified
Added
Removed
  • extensions/GuestBook/admin.php

    r16347 r24889  
    2424 
    2525$template->assign_var_from_handle('ADMIN_CONTENT', 'guestbook'); 
    26  
    27  
    28 ?> 
  • extensions/GuestBook/admin/config.php

    r15948 r24889  
    11<?php 
    2 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); 
     2if (!defined('GUESTBOOK_PATH')) die('Hacking attempt!'); 
    33 
    44if (isset($_POST['submit'])) 
     
    1010    'nb_comment_page' => $_POST['nb_comment_page'], 
    1111    'activate_rating' => isset($_POST['activate_rating']), 
     12    'guest_can_view' => isset($_POST['guest_can_view']), 
     13    'guest_can_add' => isset($_POST['guest_can_add']), 
    1214    ); 
    1315     
     
    1820$template->assign($conf['guestbook']); 
    1921 
    20 $template->set_filename('guestbook', dirname(__FILE__).'/template/config.tpl'); 
    21  
    22 ?> 
     22$template->set_filename('guestbook', realpath(GUESTBOOK_PATH . 'admin/template/config.tpl')); 
  • extensions/GuestBook/admin/pending.php

    r15940 r24889  
    11<?php 
    2 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); 
     2if (!defined('GUESTBOOK_PATH')) die('Hacking attempt!'); 
    33 
    44include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); 
     
    109109 
    110110 
    111 $template->set_filename('guestbook', dirname(__FILE__).'/template/pending.tpl'); 
     111$template->set_filename('guestbook', realpath(GUESTBOOK_PATH . 'admin/template/pending.tpl')); 
    112112 
    113113?> 
  • extensions/GuestBook/admin/template/config.tpl

    r15948 r24889  
    11{combine_css path=$GUESTBOOK_PATH|@cat:'template/style.css'} 
     2 
     3{footer_script}{literal} 
     4$('input[name="comments_validation"]').on('change', function() { 
     5    $('#email_admin_on_comment_validation').toggle($(this).is(':checked')); 
     6}) 
     7.trigger('change'); 
     8 
     9$('input[name="guest_can_view"]').on('change', function() { 
     10    $('#guest_can_add').toggle($(this).is(':checked')); 
     11}) 
     12.trigger('change'); 
     13{/literal}{/footer_script} 
    214 
    315<div class="titrePage"> 
     
    3042    </li> 
    3143 
    32     <li id="notifyAdmin"> 
     44    <li> 
    3345      <strong>{'Notify administrators when a comment is'|@translate}</strong> 
     46 
     47      <label> 
     48        <input type="checkbox" name="email_admin_on_comment" {if ($email_admin_on_comment)}checked="checked"{/if}> {'added'|@translate} 
     49      </label> 
    3450 
    3551      <label id="email_admin_on_comment_validation"> 
    3652        <input type="checkbox" name="email_admin_on_comment_validation" {if ($email_admin_on_comment_validation)}checked="checked"{/if}> {'pending validation'|@translate} 
    3753      </label> 
     54    </li> 
     55     
     56    <li> 
     57      <strong>{'Guests (not registered) permissions :'|@translate}</strong> 
    3858 
    3959      <label> 
    40         <input type="checkbox" name="email_admin_on_comment" {if ($email_admin_on_comment)}checked="checked"{/if}> {'added'|@translate} 
     60        <input type="checkbox" name="guest_can_view" {if ($guest_can_view)}checked="checked"{/if}> {'view comments'|@translate} 
     61      </label> 
     62 
     63      <label id="guest_can_add"> 
     64        <input type="checkbox" name="guest_can_add" {if ($guest_can_add)}checked="checked"{/if}> {'add comment'|@translate} 
    4165      </label> 
    4266    </li> 
  • extensions/GuestBook/include/functions.inc.php

    r21542 r24889  
    3939  return $html; 
    4040} 
    41  
    42 ?> 
  • extensions/GuestBook/include/functions_comment.inc.php

    r21542 r24889  
    168168      include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); 
    169169 
    170       $comment_url = get_absolute_root_url().add_url_params(GUESTBOOK_URL, array('comment_id'=>$comm['id'])); 
     170      $comment_url = add_url_params(GUESTBOOK_URL, array('comment_id'=>$comm['id'])); 
    171171 
    172172      $keyargs_content = array 
     
    237237      include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); 
    238238       
    239       $comment_url = get_absolute_root_url().add_url_params(GUESTBOOK_URL, array('comment_id'=>$comm['id'])); 
     239      $comment_url = add_url_params(GUESTBOOK_URL, array('comment_id'=>$comm['id'])); 
    240240 
    241241      $keyargs_content = array 
     
    322322  pwg_query($query); 
    323323} 
    324  
    325 ?> 
  • extensions/GuestBook/include/guestbook.inc.php

    r20181 r24889  
    106106// |                                add comment                            | 
    107107// +-----------------------------------------------------------------------+ 
    108 if ( isset( $_POST['content'] ) ) 
     108if ( isset( $_POST['content'] ) && (!is_a_guest() || $conf['guestbook']['guest_can_add'])) 
    109109{ 
    110110  $comm = array( 
     
    289289} 
    290290 
    291 $show_add_comment_form = true; 
     291$show_add_comment_form = !is_a_guest() || $conf['guestbook']['guest_can_add']; 
    292292if (isset($edit_comment)) 
    293293{ 
     
    329329} 
    330330 
    331 $template->assign('ABS_GUESTBOOK_PATH', dirname(__FILE__).'/../'); 
     331$template->assign('ABS_GUESTBOOK_PATH', realpath(GUESTBOOK_PATH) . '/'); 
    332332$template->assign('GUESTBOOK_PATH', GUESTBOOK_PATH); 
    333333 
    334 $template->set_filename('index', dirname(__FILE__).'/../template/guestbook.tpl'); 
    335  
    336 ?> 
     334$template->set_filename('index', realpath(GUESTBOOK_PATH . 'template/guestbook.tpl')); 
  • extensions/GuestBook/include/import_tool.php

    r16347 r24889  
    11<?php 
    22define('PHPWG_ROOT_PATH','../../../'); 
    3 include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); 
     3include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); 
    44 
    55if (!is_admin()) die('Access denied'); 
    66?> 
    7 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 
    8    "http://www.w3.org/TR/html4/strict.dtd"> 
    9 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" dir="ltr"> 
     7<!DOCTYPE html> 
     8<html lang="en" dir="ltr"> 
    109<head> 
    1110  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
     
    5857{ 
    5958?> 
    60 Just enter the id of your old guestbook picture (the Id can be found a the picture edition page, near the thumbnail) and click the <b>import</b> button. 
     59Just enter the ID of your old guestbook picture (the ID can be found a the picture edition page, near the thumbnail) and click the <b>import</b> button. 
    6160<form action="" method="post"> 
    62 <label>Image id. <input type="text" size="5" name="image_id"></label><br> 
     61<label>Image ID : <input type="text" size="5" name="image_id"></label><br> 
    6362<input type="submit" value="import"> 
    6463</form> 
  • extensions/GuestBook/language/en_UK/plugin.lang.php

    r20181 r24889  
    1313$lang['Activate rating'] = 'Activate rating'; 
    1414$lang['%s says on %s :'] = '%s says on %s :'; 
     15$lang['Guests (not registered) permissions :'] = 'Guests (not registered) permissions :'; 
     16$lang['view comments'] = 'view comments'; 
     17$lang['add comment'] = 'add comment'; 
    1518 
    1619?> 
  • extensions/GuestBook/language/fr_FR/plugin.lang.php

    r20504 r24889  
    1313$lang['Activate rating'] = 'Activer la notation'; 
    1414$lang['%s says on %s :'] = '%s a dit le %s :'; 
     15$lang['Guests (not registered) permissions :'] = 'Droits des visiteurs (non enregistrés) :'; 
     16$lang['view comments'] = 'voir les commentaires'; 
     17$lang['add comment'] = 'ajouter un commentaire'; 
    1518 
    1619?> 
  • extensions/GuestBook/main.inc.php

    r21292 r24889  
    44Version: auto 
    55Description: Add a guestbook to the gallery 
    6 Plugin URI: http://piwigo.org/ext/extension_view.php?eid=609 
     6Plugin URI: auto 
    77Author: Mistic 
    88Author URI: http://www.strangeplanet.fr 
     
    1414 
    1515 
    16 define('GUESTBOOK_PATH' ,  PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/'); 
    17 define('GUESTBOOK_TABLE' , $prefixeTable . 'guestbook'); 
    18 define('GUESTBOOK_ADMIN',  get_root_url().'admin.php?page=plugin-' . basename(dirname(__FILE__))); 
    19 define('GUESTBOOK_URL',    get_absolute_root_url() . make_index_url(array('section' => 'guestbook'))); 
     16defined('GUESTBOOK_ID') or define('GUESTBOOK_ID', basename(dirname(__FILE__))); 
     17define('GUESTBOOK_PATH' ,   PHPWG_PLUGINS_PATH . GUESTBOOK_ID . '/'); 
     18define('GUESTBOOK_TABLE' ,  $prefixeTable . 'guestbook'); 
     19define('GUESTBOOK_ADMIN',   get_root_url().'admin.php?page=plugin-' . GUESTBOOK_ID); 
     20define('GUESTBOOK_URL',     get_absolute_root_url() . make_index_url(array('section' => 'guestbook'))); 
     21define('GUESTBOOK_VERSION', 'auto'); 
    2022 
    21 add_event_handler('init', 'gb_init'); 
    2223 
    23 function gb_init() 
     24include_once(GUESTBOOK_PATH . 'include/events.inc.php'); 
     25 
     26add_event_handler('init', 'guestbook_init'); 
     27 
     28// admin page 
     29if (defined('IN_ADMIN')) 
    2430{ 
    25   global $conf; 
     31  add_event_handler('get_admin_plugin_menu_links', 'gb_admin_menu'); 
     32} 
     33 
     34// menu entry 
     35add_event_handler('blockmanager_apply', 'gb_menubar_apply', EVENT_HANDLER_PRIORITY_NEUTRAL+10); 
     36 
     37// guestbook section 
     38add_event_handler('loc_end_section_init', 'gb_section_init'); 
     39add_event_handler('loc_end_index', 'gb_index'); 
     40 
     41// stuff 
     42// add_event_handler('get_stuffs_modules', 'gb_register_stuffs_module') 
     43 
     44 
     45function guestbook_init() 
     46{ 
     47  global $conf, $pwg_loaded_plugins; 
    2648   
    27   load_language('plugin.lang', GUESTBOOK_PATH); 
    28   $conf['guestbook'] = unserialize($conf['guestbook']); 
    29    
    30   // menubar 
    31   if (script_basename() != 'admin') 
     49  // apply upgrade if needed 
     50  if ( 
     51    GUESTBOOK_VERSION == 'auto' or 
     52    $pwg_loaded_plugins[GUESTBOOK_ID]['version'] == 'auto' or 
     53    version_compare($pwg_loaded_plugins[GUESTBOOK_ID]['version'], GUESTBOOK_VERSION, '<') 
     54  ) 
    3255  { 
    33     add_event_handler('blockmanager_apply', 'gb_menubar_apply', EVENT_HANDLER_PRIORITY_NEUTRAL+10); 
    34   } 
    35   else 
    36   { 
    37     add_event_handler('get_admin_plugin_menu_links', 'gb_admin_menu'); 
     56    // call install function 
     57    include_once(GUESTBOOK_PATH . 'include/install.inc.php'); 
     58    guestbook_install(); 
     59     
     60    // update plugin version in database 
     61    if ( $pwg_loaded_plugins[GUESTBOOK_ID]['version'] != 'auto' and GUESTBOOK_VERSION != 'auto' ) 
     62    { 
     63      $query = ' 
     64UPDATE '. PLUGINS_TABLE .' 
     65SET version = "'. GUESTBOOK_VERSION .'" 
     66WHERE id = "'. GUESTBOOK_ID .'"'; 
     67      pwg_query($query); 
     68       
     69      $pwg_loaded_plugins[GUESTBOOK_ID]['version'] = GUESTBOOK_VERSION; 
     70       
     71      if (defined('IN_ADMIN')) 
     72      { 
     73        $_SESSION['page_infos'][] = 'GuestBook updated to version '. GUESTBOOK_VERSION; 
     74      } 
     75    } 
    3876  } 
    3977   
    40   // guestbook section 
    41   add_event_handler('loc_end_section_init', 'gb_section_init'); 
    42   add_event_handler('loc_end_index', 'gb_index'); 
     78  // load plugin language file 
     79  load_language('plugin.lang', GUESTBOOK_PATH); 
    4380   
    44   // stuff 
    45   // add_event_handler('get_stuffs_modules', 'gb_register_stuffs_module') 
     81  // prepare plugin configuration 
     82  $conf['guestbook'] = unserialize($conf['guestbook']); 
    4683} 
    47  
    48 function gb_menubar_apply($menu_ref_arr) 
    49 { 
    50   $menu = &$menu_ref_arr[0]; 
    51    
    52   if ( ($block = $menu->get_block('mbMenu')) != null ) 
    53   { 
    54     array_push($block->data, array( 
    55       'URL' => GUESTBOOK_URL, 
    56       'TITLE' => l10n('GuestBook'), 
    57       'NAME' => l10n('GuestBook') 
    58     )); 
    59   } 
    60 } 
    61  
    62 function gb_section_init() 
    63 { 
    64   global $tokens, $page, $conf; 
    65  
    66   if ($tokens[0] == 'guestbook') 
    67   { 
    68     add_event_handler('loc_begin_page_header', 'gb_page_header'); 
    69      
    70     $page['section'] = 'guestbook'; 
    71     $page['title'] = l10n('GuestBook'); 
    72     $page['section_title'] = '<a href="'.get_gallery_home_url().'">'.l10n('Home').'</a>'.$conf['level_separator'].l10n('GuestBook'); 
    73   } 
    74 } 
    75  
    76 function gb_page_header() 
    77 { 
    78   global $page; 
    79   $page['body_id'] = 'theGuestBook'; 
    80 } 
    81  
    82 function gb_index()  
    83 { 
    84   global $template, $page, $conf; 
    85  
    86   if (isset($page['section']) and $page['section'] == 'guestbook') 
    87   { 
    88     include(GUESTBOOK_PATH . '/include/guestbook.inc.php'); 
    89   } 
    90 } 
    91  
    92 /*function gb_register_stuffs_module($modules) 
    93 { 
    94   array_push($modules, array( 
    95     'path' => GUESTBOOK_PATH . '/stuffs_module', 
    96     'name' => GB_NAME, 
    97     'description' => l10n('gb_stuffs_desc'), 
    98   )); 
    99  
    100   return $modules; 
    101 }*/ 
    102  
    103 function gb_admin_menu($menu)  
    104 { 
    105   array_push($menu, array( 
    106     'NAME' => 'GuestBook', 
    107     'URL' => GUESTBOOK_ADMIN, 
    108   )); 
    109   return $menu; 
    110 } 
    111  
    112 ?> 
  • extensions/GuestBook/maintain.inc.php

    r15948 r24889  
    22if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); 
    33 
    4 // Default config 
    5 define('default_guestbook_config', serialize(array( 
    6   'comments_validation' => false, 
    7   'email_admin_on_comment' => false, 
    8   'email_admin_on_comment_validation' => false, 
    9   'nb_comment_page' => 15, 
    10   'activate_rating' => true, 
    11 ))); 
     4defined('GUESTBOOK_ID') or define('GUESTBOOK_ID', basename(dirname(__FILE__))); 
     5include_once(PHPWG_PLUGINS_PATH . GUESTBOOK_ID . '/include/install.inc.php'); 
    126 
    137// Installation 
    148function plugin_install() 
    159{ 
    16   global $prefixeTable; 
    17  
    18   pwg_query(" 
    19 CREATE TABLE `" . $prefixeTable . "guestbook` ( 
    20   `id` int(11) unsigned NOT NULL AUTO_INCREMENT, 
    21   `date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', 
    22   `author` varchar(255) NOT NULL, 
    23   `author_id` smallint(5) DEFAULT NULL, 
    24   `anonymous_id` varchar(45) NOT NULL, 
    25   `email` varchar(255) DEFAULT NULL, 
    26   `website` varchar(255) DEFAULT NULL, 
    27   `content` longtext NOT NULL, 
    28   `rate` float(5,2) unsigned DEFAULT NULL, 
    29   `validated` enum('true','false') NOT NULL DEFAULT 'false', 
    30   `validation_date` datetime DEFAULT NULL, 
    31   PRIMARY KEY (`id`) 
    32 ) DEFAULT CHARSET=utf8 
    33 ;"); 
    34    
    35   conf_update_param('guestbook', default_guestbook_config); 
     10  guestbook_install(); 
     11  define('guestbook_installed', true 
    3612} 
    3713 
     
    3915function plugin_activate() 
    4016{ 
    41   global $conf; 
    42    
    43   if (!isset($conf['guestbook'])) 
     17  if (!defined('guestbook_installed')) 
    4418  { 
    45     conf_update_param('guestbook', default_guestbook_config); 
     19    guestbook_install(); 
    4620  } 
    4721} 
     
    5024function plugin_uninstall() 
    5125{ 
    52   global $prefixeTable; 
    53  
    54   pwg_query("DROP TABLE `" . $prefixeTable . "guestbook`;"); 
    55   pwg_query("DELETE FROM " . CONFIG_TABLE . " WHERE `param` = 'guestbook';"); 
     26  guestbook_uninstall(); 
    5627} 
    57 ?> 
Note: See TracChangeset for help on using the changeset viewer.