source: extensions/title/main.inc.php @ 11661

Last change on this file since 11661 was 9423, checked in by ddtddt, 13 years ago

[extensions] - title - update description

File size: 5.3 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://piwigo.org/
9*/
10
11if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
12
13global $prefixeTable, $template;
14
15define('TITLE_DIR' , basename(dirname(__FILE__)));
16define('TITLE_PATH' , PHPWG_PLUGINS_PATH . TITLE_DIR . '/');
17define('TITLE_TABLE' , $prefixeTable . 'title');
18define('TITLE_PHOTO_TABLE' , $prefixeTable . 'title_photo');
19define('TITLE_ALBUM_TABLE' , $prefixeTable . 'title_album');
20
21//prefiltre for change <title>
22add_event_handler('loc_begin_page_header', 'plug_Title', 56 );
23
24function plug_Title()
25 {
26        global $template;
27        $template->set_prefilter('header', 'plug_TitleP');
28       
29        $PAED = pwg_db_fetch_assoc(pwg_query("SELECT state FROM " . PLUGINS_TABLE . " WHERE id = 'ExtendedDescription';"));
30        if($PAED['state'] == 'active') add_event_handler('AP_render_content', 'get_user_language_desc');
31 }
32
33function plug_TitleP($content, &$smarty)
34 {
35  $search = '#<title>.*?</title>#';
36 
37  $replacement = '<title>{$PERSO_TITLE}</title>
38  ';
39
40  return preg_replace($search, $replacement, $content);
41 }
42
43// Plugin for admin
44if (script_basename() == 'admin')   
45{
46  include_once(dirname(__FILE__).'/initadmin.php');
47}
48
49// no empty !
50add_event_handler('loc_begin_page_header', 'plugTitle', 61 );
51function plugTitle()
52 {
53        global $template, $conf;
54
55                                $titlegen = & $conf['gallery_title'];
56                 if (!empty($titlegen))
57                        {                               
58                                $template->assign('PERSO_TITLE', $titlegen);
59                        }
60
61 } 
62
63
64//use title on photo page
65add_event_handler('loc_begin_page_header', 'TitlePhoto', 76 );
66function TitlePhoto()
67 {
68                global $template, $page;
69
70                          if ( !empty($page['image_id']) )   
71                                {
72    $query = '
73select id,title
74  FROM ' . TITLE_PHOTO_TABLE . '
75  WHERE id = \''.$page['image_id'].'\'
76  ;';
77$result = pwg_query($query);
78$row = mysql_fetch_array($result);
79$titleP=$row['title'];
80
81$titlePED=trigger_event('AP_render_content', $titleP);
82       
83                if (!empty($titlePED))
84                        {
85                                $template->assign('PERSO_TITLE', $titlePED);
86                        }
87                                }
88 }
89
90// use title on album page
91add_event_handler('loc_begin_page_header', 'Titlealbum', 71 );
92function Titlealbum()
93 {
94        global $template, $page;
95                 if (!empty($page['category']['id']) )   
96                                {
97    $query = '
98select id,title
99  FROM ' . TITLE_ALBUM_TABLE . '
100  WHERE id = \''.$page['category']['id'].'\'
101  ;';
102$result = pwg_query($query);
103$row = mysql_fetch_array($result);
104$titleA=$row['title'];
105
106$titleAED=trigger_event('AP_render_content', $titleA);
107
108                if (!empty($titleAED))
109                        {
110                                $template->assign('PERSO_TITLE', $titleAED);
111                        }
112                                }
113 }
114
115 //other pages
116 add_event_handler('loc_begin_page_header', 'Titleother', 66 );
117 function Titleother()
118 {
119        global $template, $page;
120       
121                $query = '
122select id,page,title
123  FROM ' . TITLE_TABLE . '
124  WHERE page IN (\'home\', \'best_rated\', \'most_visited\', \'recent_pics\', \'recent_cats\', \'favorites\', \'tags\', \'comments\', \'about\', \'search\', \'random\', \'notification\')
125 
126  ;';
127$result = pwg_query($query);
128$titlespecial = array();
129                while ($row = mysql_fetch_assoc($result))
130                        {
131                        $titlespecial[$row['page']] = $row['title'];
132                        $titlespecialED[$row['page']]=trigger_event('AP_render_content', $titlespecial[$row['page']]);
133                        }
134       
135          if (isset($page['section']) and $page['section'] == 'categories' and empty($page['category']['id']) and !empty($titlespecialED['home']))
136                {
137                        $template->assign('PERSO_TITLE', $titlespecialED['home']);
138                }
139          if (isset($page['section']) and $page['section'] == 'best_rated' and !empty($titlespecialED['best_rated']))
140                {
141                        $template->assign('PERSO_TITLE', $titlespecialED['best_rated']);
142                }
143          if (isset($page['section']) and $page['section'] == 'most_visited' and !empty($titlespecialED['most_visited']))
144                {
145                        $template->assign('PERSO_TITLE', $titlespecialED['most_visited']);
146                }
147          if (isset($page['section']) and $page['section'] == 'recent_pics' and !empty($titlespecialED['recent_pics']))
148                {
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                {
153                        $template->assign('PERSO_TITLE', $titlespecialED['recent_cats']);
154                }
155          if (isset($page['section']) and $page['section'] == 'favorites' and !empty($titlespecialED['favorites']))
156                {
157                        $template->assign('PERSO_TITLE', $titlespecialED['favorites']);
158                }
159          if (script_basename() == 'tags' and !empty($titlespecialED['tags']))   
160                {
161                        $template->assign('PERSO_TITLE', $titlespecialED['tags']);
162                }
163          if (script_basename() == 'comments' and !empty($titlespecialED['comments']))   
164                {
165                        $template->assign('PERSO_TITLE', $titlespecialED['comments']);
166                }
167          if (script_basename() == 'about' and !empty($titlespecialED['about']))   
168                {
169                        $template->assign('PERSO_TITLE', $titlespecialED['about']);
170                }
171          if (script_basename() == 'search' and !empty($titlespecialED['search']))   
172                {
173                        $template->assign('PERSO_TITLE', $titlespecialED['search']);
174                }
175          if (isset($page['section']) and $page['section'] == 'list' and !empty($titlespecialED['random']))
176                {
177                        $template->assign('PERSO_TITLE', $titlespecialED['random']);
178                }
179          if (script_basename() == 'notification' and !empty($titlespecialED['notification']))   
180                {
181                        $template->assign('PERSO_TITLE', $titlespecialED['notification']);
182                }               
183 }
184 
185?>
Note: See TracBrowser for help on using the repository browser.