source: extensions/Comments_on_Albums/trunk/main.inc.php @ 21347

Last change on this file since 21347 was 21347, checked in by mistic100, 11 years ago

update PWG Stuffs module, use UNIX eol

File size: 3.8 KB
Line 
1<?php
2/*
3Plugin Name: Comments on Albums
4Version: auto
5Description: Activate comments on albums pages
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=512
7Author: Mistic
8Author URI: http://www.strangeplanet.fr
9*/
10
11if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
12
13if (mobile_theme())
14{
15  return;
16}
17
18global $prefixeTable;
19
20// +-----------------------------------------------------------------------+
21//          Global variables
22// +-----------------------------------------------------------------------+
23defined('COA_ID') or define('COA_ID', basename(dirname(__FILE__)));
24define('COA_PATH' ,   PHPWG_PLUGINS_PATH . COA_ID . '/');
25define('COA_TABLE' ,  $prefixeTable . 'comments_categories');
26define('COA_ADMIN',   get_root_url().'admin.php?page=plugin-' . COA_ID);
27define('COA_VERSION', 'auto');
28
29
30// +-----------------------------------------------------------------------+
31//          Triggers
32// +-----------------------------------------------------------------------+
33add_event_handler('init', 'coa_init');
34function coa_init()
35{
36  global $user, $conf, $pwg_loaded_plugins;
37 
38  // luciano doesn't use comments
39  // incompatible with dynamic display of Stripped & Collumns
40  if ($user['theme'] == 'luciano' or $user['theme'] == 'stripped_black_bloc') return;
41 
42  // apply upgrade if needed
43  if (
44    COA_VERSION == 'auto' or
45    $pwg_loaded_plugins[COA_ID]['version'] == 'auto' or
46    version_compare($pwg_loaded_plugins[COA_ID]['version'], COA_VERSION, '<')
47  )
48  {
49    // call install function
50    include_once(COA_PATH . 'include/install.inc.php');
51    coa_install();
52   
53    // update plugin version in database
54    if ( $pwg_loaded_plugins[COA_ID]['version'] != 'auto' and COA_VERSION != 'auto' )
55    {
56      $query = '
57UPDATE '. PLUGINS_TABLE .'
58SET version = "'. COA_VERSION .'"
59WHERE id = "'. COA_ID .'"';
60      pwg_query($query);
61     
62      $pwg_loaded_plugins[COA_ID]['version'] = COA_VERSION;
63     
64      if (defined('IN_ADMIN'))
65      {
66        $_SESSION['page_infos'][] = 'Comments on Albums updated to version '. COA_VERSION;
67      }
68    }
69  }
70 
71  // add events handlers
72  if (defined('IN_ADMIN'))
73  {
74    add_event_handler('loc_begin_admin_page', 'coa_admin_intro');
75    add_event_handler('loc_end_admin', 'coa_admin_comments');
76  }
77  else
78  {
79    add_event_handler('loc_after_page_header', 'coa_albums');
80    add_event_handler('loc_after_page_header', 'coa_comments_page');
81  } 
82  add_event_handler('get_stuffs_modules', 'coa_register_stuffs_module');
83}
84
85
86// +-----------------------------------------------------------------------+
87//          Functions
88// +-----------------------------------------------------------------------+
89
90function coa_albums() 
91{
92  global $template, $page, $conf, $pwg_loaded_plugins;
93 
94  if ( !empty($page['section']) AND $page['section'] == 'categories' AND isset($page['category']) AND $page['body_id'] == 'theCategoryPage' )
95  {   
96    trigger_action('loc_begin_coa');
97    include(COA_PATH . 'include/coa_albums.php');
98  }
99}
100
101function coa_comments_page() 
102{
103  global $template, $page, $conf, $user;
104 
105  if (isset($page['body_id']) AND $page['body_id'] == 'theCommentsPage') 
106  {
107    include(COA_PATH . 'include/coa_comments_page.php');
108  }
109}
110
111function coa_admin_intro() 
112{
113  global $page;
114 
115  if ($page['page'] == 'intro') 
116  { 
117    include(COA_PATH . 'include/coa_admin_intro.php');
118  } 
119}
120
121function coa_admin_comments() 
122{
123  global $page;
124 
125  if ($page['page'] == 'comments') 
126  { 
127    include(COA_PATH . 'include/coa_admin_comments.php');
128  }
129}
130
131function coa_register_stuffs_module($modules) 
132{
133  load_language('plugin.lang', COA_PATH);
134 
135  array_push($modules, array(
136    'path' => COA_PATH . '/stuffs_module',
137    'name' => l10n('Last comments on albums'),
138    'description' => l10n('Display last posted comments on albums'),
139  ));
140
141  return $modules;
142}
143
144?>
Note: See TracBrowser for help on using the repository browser.