source: extensions/title/main.inc.php

Last change on this file was 32302, checked in by ddtddt, 4 weeks ago

[title] php7.4 Notice

File size: 7.8 KB
Line 
1<?php
2/*
3Plugin Name: Title
4Version: auto
5Description: Allows you to customize tag < title > of different Piwigo page
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=507
7Author: ddtddt
8Author URI: http://temmii.com/piwigo/
9*/
10
11// +-----------------------------------------------------------------------+
12// | Title plugin for piwigo by TEMMII                                     |
13// +-----------------------------------------------------------------------+
14// | Copyright(C) 2011 - 2020 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
31if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
32
33global $prefixeTable, $template;
34
35define('TITLE_DIR' , basename(dirname(__FILE__)));
36define('TITLE_PATH' , PHPWG_PLUGINS_PATH . TITLE_DIR . '/');
37define('TITLE_TABLE' , $prefixeTable . 'title');
38define('TITLE_PHOTO_TABLE' , $prefixeTable . 'title_photo');
39define('TITLE_ALBUM_TABLE' , $prefixeTable . 'title_album');
40define('TITLE_ADMIN',get_root_url().'admin.php?page=plugin-'.TITLE_DIR);
41
42add_event_handler('loading_lang', 'title_loading_lang');         
43function title_loading_lang(){
44  load_language('plugin.lang', TITLE_PATH);
45}
46
47//prefiltre for change <title>
48add_event_handler('loc_begin_page_header', 'plug_Title', 56 );
49
50function plug_Title(){
51  global $template, $pwg_loaded_plugins;
52  $template->set_prefilter('header', 'plug_TitleP');
53  if (isset($pwg_loaded_plugins['ExtendedDescription'])){
54        add_event_handler('AP_render_content', 'get_user_language_desc');
55  } 
56}
57
58function plug_TitleP($content, &$smarty){
59  $search = '#<title>.*?</title>#';
60  $replacement = '<title>{$PERSO_TITLE}</title>
61  ';
62  return preg_replace($search, $replacement, $content);
63}
64
65// Plugin for admin
66if (script_basename() == 'admin'){
67  include_once(dirname(__FILE__).'/initadmin.php');
68}
69
70// no empty !
71add_event_handler('loc_begin_page_header', 'plugTitle', 61 );
72function plugTitle(){
73  global $template, $conf;
74  $titlegen = & $conf['gallery_title'];
75  if (!empty($titlegen)){                               
76        $template->assign('PERSO_TITLE', $titlegen);
77  }
78} 
79
80//use title on photo page
81add_event_handler('loc_begin_page_header', 'TitlePhoto', 76 );
82function TitlePhoto(){
83  global $template, $page;
84  if ( !empty($page['image_id']) ){
85    $query = '
86select id,title
87  FROM ' . TITLE_PHOTO_TABLE . '
88  WHERE id = \''.$page['image_id'].'\'
89  ;';
90$result = pwg_query($query);
91$row = pwg_db_fetch_assoc($result);
92$titleP=$row['title'];
93$titlePED=trigger_change('AP_render_content', $titleP);
94        if (!empty($titlePED)){
95          $template->assign('PERSO_TITLE', $titlePED);
96        }
97  }
98}
99
100// use title on album page
101add_event_handler('loc_begin_page_header', 'Titlealbum', 71 );
102function Titlealbum(){
103  global $template, $page;
104  if (!empty($page['category']['id']) ){
105    $query = '
106select id,title
107  FROM ' . TITLE_ALBUM_TABLE . '
108  WHERE id = \''.$page['category']['id'].'\'
109  ;';
110$result = pwg_query($query);
111$row = pwg_db_fetch_assoc($result);
112$titleA=$row['title'];
113$titleAED=trigger_change('AP_render_content', $titleA);
114        if (!empty($titleAED)){
115                                $template->assign('PERSO_TITLE', $titleAED);
116        }
117  }
118}
119
120//other pages
121add_event_handler('loc_begin_page_header', 'Titleother', 66 );
122function Titleother(){
123  global $template, $page, $conf, $pwg_loaded_plugins;
124  $query = '
125select id,page,title
126  FROM ' . TITLE_TABLE . '
127  WHERE page IN (\'home\', \'best_rated\', \'most_visited\', \'recent_pics\', \'recent_cats\', \'favorites\', \'tags\', \'comments\', \'about\', \'search\', \'random\', \'notification\')
128 
129  ;';
130  $result = pwg_query($query);
131  $titlespecial = array();
132  while ($row = pwg_db_fetch_assoc($result)){
133        $titlespecial[$row['page']] = $row['title'];
134        $titlespecialED[$row['page']]=trigger_change('AP_render_content', $titlespecial[$row['page']]);
135  }
136  if (isset($page['section']) and $page['section'] == 'categories' and empty($page['category']['id']) and !empty($titlespecialED['home'])){
137        $template->assign('PERSO_TITLE', $titlespecialED['home']);
138  }
139  if (isset($page['section']) and $page['section'] == 'best_rated' and !empty($titlespecialED['best_rated'])){
140        $template->assign('PERSO_TITLE', $titlespecialED['best_rated']);
141  }
142  if (isset($page['section']) and $page['section'] == 'most_visited' and !empty($titlespecialED['most_visited'])){
143        $template->assign('PERSO_TITLE', $titlespecialED['most_visited']);
144  }
145  if (isset($page['section']) and $page['section'] == 'recent_pics' and !empty($titlespecialED['recent_pics'])){
146        $template->assign('PERSO_TITLE', $titlespecialED['recent_pics']);
147  }
148  if (isset($page['section']) and $page['section'] == 'recent_cats' and !empty($titlespecialED['recent_cats'])){
149        $template->assign('PERSO_TITLE', $titlespecialED['recent_cats']);
150  }
151  if (isset($page['section']) and $page['section'] == 'favorites' and !empty($titlespecialED['favorites'])){
152        $template->assign('PERSO_TITLE', $titlespecialED['favorites']);
153  }
154  if (script_basename() == 'tags' and !empty($titlespecialED['tags'])){
155        $template->assign('PERSO_TITLE', $titlespecialED['tags']);
156  }
157  if (script_basename() == 'comments' and !empty($titlespecialED['comments'])){
158        $template->assign('PERSO_TITLE', $titlespecialED['comments']);
159  }
160  if (script_basename() == 'about' and !empty($titlespecialED['about'])){
161        $template->assign('PERSO_TITLE', $titlespecialED['about']);
162  }
163  if (script_basename() == 'search' and !empty($titlespecialED['search'])){
164        $template->assign('PERSO_TITLE', $titlespecialED['search']);
165  }
166  if (isset($page['section']) and $page['section'] == 'list' and !empty($titlespecialED['random'])){
167        $template->assign('PERSO_TITLE', $titlespecialED['random']);
168  }
169  if (script_basename() == 'notification' and !empty($titlespecialED['notification'])){
170        $template->assign('PERSO_TITLE', $titlespecialED['notification']);
171  }
172  if (isset($pwg_loaded_plugins['ContactForm'])){
173        $titlespecialED['contact']=trigger_change('AP_render_content', $conf['contacttitle']);
174        if (isset($page['section']) and $page['section'] == 'contact' and !empty($titlespecialED['contact'])){
175          $template->assign('PERSO_TITLE', $titlespecialED['contact']);
176        }
177  }
178  if (isset($pwg_loaded_plugins['AdditionalPages'])){   
179        global $prefixeTable;
180        if ( !empty($page['additional_page']['id']) ){
181                if (!defined('TITLE_AP_TABLE')) define('TITLE_AP_TABLE', $prefixeTable.'title_ap');     
182        $lire=$page['additional_page']['id'];
183        $query = '
184  select id,title
185  FROM ' . TITLE_AP_TABLE . '
186  WHERE id = \''.$lire.'\'
187  ;';
188        $result = pwg_query($query);
189        $row = pwg_db_fetch_assoc($result);
190        $titleap=$row['title'];
191        $titlespecialED['AdditionalPages']=trigger_change('AP_render_content', $titleap);       
192        }
193        if (isset($page['section']) and $page['section'] == 'additional_page' and !empty($titlespecialED['AdditionalPages'])){
194          $template->assign('PERSO_TITLE', $titlespecialED['AdditionalPages']);
195        }
196  }
197}
198 
199?>
Note: See TracBrowser for help on using the repository browser.