[9407] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: Title |
---|
| 4 | Version: auto |
---|
[9423] | 5 | Description: Allows you to customize tag < title > of different Piwigo page |
---|
[9422] | 6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=507 |
---|
[9407] | 7 | Author: ddtddt |
---|
[31456] | 8 | Author URI: http://temmii.com/piwigo/ |
---|
[9407] | 9 | */ |
---|
| 10 | |
---|
[31456] | 11 | // +-----------------------------------------------------------------------+ |
---|
| 12 | // | Title plugin for piwigo | |
---|
| 13 | // +-----------------------------------------------------------------------+ |
---|
| 14 | // | Copyright(C) 2011 - 2016 ddtddt http://temmii.com/piwigo/ | |
---|
| 15 | // +-----------------------------------------------------------------------+ |
---|
| 16 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 17 | // | it under the terms of the GNU General Public License as published by | |
---|
| 18 | // | the Free Software Foundation | |
---|
| 19 | // | | |
---|
| 20 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 21 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 22 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 23 | // | General Public License for more details. | |
---|
| 24 | // | | |
---|
| 25 | // | You should have received a copy of the GNU General Public License | |
---|
| 26 | // | along with this program; if not, write to the Free Software | |
---|
| 27 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 28 | // | USA. | |
---|
| 29 | // +-----------------------------------------------------------------------+ |
---|
| 30 | |
---|
[9407] | 31 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 32 | |
---|
| 33 | global $prefixeTable, $template; |
---|
| 34 | |
---|
| 35 | define('TITLE_DIR' , basename(dirname(__FILE__))); |
---|
| 36 | define('TITLE_PATH' , PHPWG_PLUGINS_PATH . TITLE_DIR . '/'); |
---|
| 37 | define('TITLE_TABLE' , $prefixeTable . 'title'); |
---|
| 38 | define('TITLE_PHOTO_TABLE' , $prefixeTable . 'title_photo'); |
---|
| 39 | define('TITLE_ALBUM_TABLE' , $prefixeTable . 'title_album'); |
---|
[31456] | 40 | define('TITLE_ADMIN',get_root_url().'admin.php?page=plugin-'.TITLE_DIR); |
---|
[9407] | 41 | |
---|
[31456] | 42 | add_event_handler('loading_lang', 'title_loading_lang'); |
---|
| 43 | function title_loading_lang(){ |
---|
| 44 | load_language('plugin.lang', TITLE_PATH); |
---|
| 45 | } |
---|
| 46 | |
---|
[9407] | 47 | //prefiltre for change <title> |
---|
| 48 | add_event_handler('loc_begin_page_header', 'plug_Title', 56 ); |
---|
| 49 | |
---|
| 50 | function plug_Title() |
---|
| 51 | { |
---|
| 52 | global $template; |
---|
| 53 | $template->set_prefilter('header', 'plug_TitleP'); |
---|
| 54 | |
---|
| 55 | $PAED = pwg_db_fetch_assoc(pwg_query("SELECT state FROM " . PLUGINS_TABLE . " WHERE id = 'ExtendedDescription';")); |
---|
| 56 | if($PAED['state'] == 'active') add_event_handler('AP_render_content', 'get_user_language_desc'); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | function plug_TitleP($content, &$smarty) |
---|
| 60 | { |
---|
| 61 | $search = '#<title>.*?</title>#'; |
---|
| 62 | |
---|
| 63 | $replacement = '<title>{$PERSO_TITLE}</title> |
---|
| 64 | '; |
---|
| 65 | |
---|
| 66 | return preg_replace($search, $replacement, $content); |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | // Plugin for admin |
---|
| 70 | if (script_basename() == 'admin') |
---|
| 71 | { |
---|
| 72 | include_once(dirname(__FILE__).'/initadmin.php'); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | // no empty ! |
---|
| 76 | add_event_handler('loc_begin_page_header', 'plugTitle', 61 ); |
---|
| 77 | function plugTitle() |
---|
| 78 | { |
---|
| 79 | global $template, $conf; |
---|
| 80 | |
---|
| 81 | $titlegen = & $conf['gallery_title']; |
---|
| 82 | if (!empty($titlegen)) |
---|
| 83 | { |
---|
| 84 | $template->assign('PERSO_TITLE', $titlegen); |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | //use title on photo page |
---|
| 91 | add_event_handler('loc_begin_page_header', 'TitlePhoto', 76 ); |
---|
| 92 | function TitlePhoto() |
---|
| 93 | { |
---|
| 94 | global $template, $page; |
---|
| 95 | |
---|
| 96 | if ( !empty($page['image_id']) ) |
---|
| 97 | { |
---|
| 98 | $query = ' |
---|
| 99 | select id,title |
---|
| 100 | FROM ' . TITLE_PHOTO_TABLE . ' |
---|
| 101 | WHERE id = \''.$page['image_id'].'\' |
---|
| 102 | ;'; |
---|
| 103 | $result = pwg_query($query); |
---|
[21163] | 104 | $row = pwg_db_fetch_assoc($result); |
---|
[9407] | 105 | $titleP=$row['title']; |
---|
| 106 | |
---|
[29793] | 107 | $titlePED=trigger_change('AP_render_content', $titleP); |
---|
[9407] | 108 | |
---|
| 109 | if (!empty($titlePED)) |
---|
| 110 | { |
---|
| 111 | $template->assign('PERSO_TITLE', $titlePED); |
---|
| 112 | } |
---|
| 113 | } |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | // use title on album page |
---|
| 117 | add_event_handler('loc_begin_page_header', 'Titlealbum', 71 ); |
---|
| 118 | function Titlealbum() |
---|
| 119 | { |
---|
| 120 | global $template, $page; |
---|
| 121 | if (!empty($page['category']['id']) ) |
---|
| 122 | { |
---|
| 123 | $query = ' |
---|
| 124 | select id,title |
---|
| 125 | FROM ' . TITLE_ALBUM_TABLE . ' |
---|
| 126 | WHERE id = \''.$page['category']['id'].'\' |
---|
| 127 | ;'; |
---|
| 128 | $result = pwg_query($query); |
---|
[21163] | 129 | $row = pwg_db_fetch_assoc($result); |
---|
[9407] | 130 | $titleA=$row['title']; |
---|
| 131 | |
---|
[29793] | 132 | $titleAED=trigger_change('AP_render_content', $titleA); |
---|
[9407] | 133 | |
---|
| 134 | if (!empty($titleAED)) |
---|
| 135 | { |
---|
| 136 | $template->assign('PERSO_TITLE', $titleAED); |
---|
| 137 | } |
---|
| 138 | } |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | //other pages |
---|
| 142 | add_event_handler('loc_begin_page_header', 'Titleother', 66 ); |
---|
| 143 | function Titleother() |
---|
| 144 | { |
---|
[22676] | 145 | global $template, $page, $conf; |
---|
[9407] | 146 | |
---|
| 147 | $query = ' |
---|
| 148 | select id,page,title |
---|
| 149 | FROM ' . TITLE_TABLE . ' |
---|
| 150 | WHERE page IN (\'home\', \'best_rated\', \'most_visited\', \'recent_pics\', \'recent_cats\', \'favorites\', \'tags\', \'comments\', \'about\', \'search\', \'random\', \'notification\') |
---|
| 151 | |
---|
| 152 | ;'; |
---|
| 153 | $result = pwg_query($query); |
---|
| 154 | $titlespecial = array(); |
---|
[21163] | 155 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[9407] | 156 | { |
---|
| 157 | $titlespecial[$row['page']] = $row['title']; |
---|
[29793] | 158 | $titlespecialED[$row['page']]=trigger_change('AP_render_content', $titlespecial[$row['page']]); |
---|
[9407] | 159 | } |
---|
| 160 | |
---|
| 161 | if (isset($page['section']) and $page['section'] == 'categories' and empty($page['category']['id']) and !empty($titlespecialED['home'])) |
---|
| 162 | { |
---|
| 163 | $template->assign('PERSO_TITLE', $titlespecialED['home']); |
---|
| 164 | } |
---|
| 165 | if (isset($page['section']) and $page['section'] == 'best_rated' and !empty($titlespecialED['best_rated'])) |
---|
| 166 | { |
---|
| 167 | $template->assign('PERSO_TITLE', $titlespecialED['best_rated']); |
---|
| 168 | } |
---|
| 169 | if (isset($page['section']) and $page['section'] == 'most_visited' and !empty($titlespecialED['most_visited'])) |
---|
| 170 | { |
---|
| 171 | $template->assign('PERSO_TITLE', $titlespecialED['most_visited']); |
---|
| 172 | } |
---|
| 173 | if (isset($page['section']) and $page['section'] == 'recent_pics' and !empty($titlespecialED['recent_pics'])) |
---|
| 174 | { |
---|
| 175 | $template->assign('PERSO_TITLE', $titlespecialED['recent_pics']); |
---|
| 176 | } |
---|
| 177 | if (isset($page['section']) and $page['section'] == 'recent_cats' and !empty($titlespecialED['recent_cats'])) |
---|
| 178 | { |
---|
| 179 | $template->assign('PERSO_TITLE', $titlespecialED['recent_cats']); |
---|
| 180 | } |
---|
| 181 | if (isset($page['section']) and $page['section'] == 'favorites' and !empty($titlespecialED['favorites'])) |
---|
| 182 | { |
---|
| 183 | $template->assign('PERSO_TITLE', $titlespecialED['favorites']); |
---|
| 184 | } |
---|
| 185 | if (script_basename() == 'tags' and !empty($titlespecialED['tags'])) |
---|
| 186 | { |
---|
| 187 | $template->assign('PERSO_TITLE', $titlespecialED['tags']); |
---|
| 188 | } |
---|
| 189 | if (script_basename() == 'comments' and !empty($titlespecialED['comments'])) |
---|
| 190 | { |
---|
| 191 | $template->assign('PERSO_TITLE', $titlespecialED['comments']); |
---|
| 192 | } |
---|
| 193 | if (script_basename() == 'about' and !empty($titlespecialED['about'])) |
---|
| 194 | { |
---|
| 195 | $template->assign('PERSO_TITLE', $titlespecialED['about']); |
---|
| 196 | } |
---|
| 197 | if (script_basename() == 'search' and !empty($titlespecialED['search'])) |
---|
| 198 | { |
---|
| 199 | $template->assign('PERSO_TITLE', $titlespecialED['search']); |
---|
| 200 | } |
---|
| 201 | if (isset($page['section']) and $page['section'] == 'list' and !empty($titlespecialED['random'])) |
---|
| 202 | { |
---|
| 203 | $template->assign('PERSO_TITLE', $titlespecialED['random']); |
---|
| 204 | } |
---|
| 205 | if (script_basename() == 'notification' and !empty($titlespecialED['notification'])) |
---|
| 206 | { |
---|
| 207 | $template->assign('PERSO_TITLE', $titlespecialED['notification']); |
---|
[22676] | 208 | } |
---|
| 209 | |
---|
| 210 | $PAC = pwg_db_fetch_assoc(pwg_query("SELECT state FROM " . PLUGINS_TABLE . " WHERE id = 'ContactForm';")); |
---|
| 211 | if($PAC['state'] == 'active') |
---|
| 212 | { |
---|
[29793] | 213 | $titlespecialED['contact']=trigger_change('AP_render_content', $conf['contacttitle']); |
---|
[22676] | 214 | if (isset($page['section']) and $page['section'] == 'contact' and !empty($titlespecialED['contact'])) |
---|
| 215 | { |
---|
| 216 | $template->assign('PERSO_TITLE', $titlespecialED['contact']); |
---|
| 217 | } |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | $PAAP = pwg_db_fetch_assoc(pwg_query("SELECT state FROM " . PLUGINS_TABLE . " WHERE id = 'AdditionalPages';")); |
---|
| 221 | if($PAAP['state'] == 'active') |
---|
| 222 | { |
---|
| 223 | |
---|
| 224 | global $prefixeTable; |
---|
| 225 | if ( !empty($page['additional_page']['id']) ) |
---|
| 226 | { |
---|
| 227 | if (!defined('TITLE_AP_TABLE')) define('TITLE_AP_TABLE', $prefixeTable.'title_ap'); |
---|
| 228 | $lire=$page['additional_page']['id']; |
---|
| 229 | $query = ' |
---|
| 230 | select id,title |
---|
| 231 | FROM ' . TITLE_AP_TABLE . ' |
---|
| 232 | WHERE id = \''.$lire.'\' |
---|
| 233 | ;'; |
---|
| 234 | $result = pwg_query($query); |
---|
| 235 | $row = pwg_db_fetch_assoc($result); |
---|
| 236 | $titleap=$row['title']; |
---|
[29793] | 237 | $titlespecialED['AdditionalPages']=trigger_change('AP_render_content', $titleap); |
---|
[22676] | 238 | } |
---|
| 239 | if (isset($page['section']) and $page['section'] == 'additional_page' and !empty($titlespecialED['AdditionalPages'])) |
---|
| 240 | { |
---|
| 241 | $template->assign('PERSO_TITLE', $titlespecialED['AdditionalPages']); |
---|
| 242 | } |
---|
| 243 | } |
---|
[9407] | 244 | } |
---|
| 245 | |
---|
| 246 | ?> |
---|