source: extensions/title/main.inc.php

Last change on this file was 33082, checked in by ddtddt, 2 months ago

[title] size photo id

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