[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 |
---|
| 8 | Author URI: http://piwigo.org/ |
---|
| 9 | */ |
---|
| 10 | |
---|
| 11 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 12 | |
---|
| 13 | global $prefixeTable, $template; |
---|
| 14 | |
---|
| 15 | define('TITLE_DIR' , basename(dirname(__FILE__))); |
---|
| 16 | define('TITLE_PATH' , PHPWG_PLUGINS_PATH . TITLE_DIR . '/'); |
---|
| 17 | define('TITLE_TABLE' , $prefixeTable . 'title'); |
---|
| 18 | define('TITLE_PHOTO_TABLE' , $prefixeTable . 'title_photo'); |
---|
| 19 | define('TITLE_ALBUM_TABLE' , $prefixeTable . 'title_album'); |
---|
| 20 | |
---|
| 21 | //prefiltre for change <title> |
---|
| 22 | add_event_handler('loc_begin_page_header', 'plug_Title', 56 ); |
---|
| 23 | |
---|
| 24 | function 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 | |
---|
| 33 | function 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 |
---|
| 44 | if (script_basename() == 'admin') |
---|
| 45 | { |
---|
| 46 | include_once(dirname(__FILE__).'/initadmin.php'); |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | // no empty ! |
---|
| 50 | add_event_handler('loc_begin_page_header', 'plugTitle', 61 ); |
---|
| 51 | function 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 |
---|
| 65 | add_event_handler('loc_begin_page_header', 'TitlePhoto', 76 ); |
---|
| 66 | function TitlePhoto() |
---|
| 67 | { |
---|
| 68 | global $template, $page; |
---|
| 69 | |
---|
| 70 | if ( !empty($page['image_id']) ) |
---|
| 71 | { |
---|
| 72 | $query = ' |
---|
| 73 | select id,title |
---|
| 74 | FROM ' . TITLE_PHOTO_TABLE . ' |
---|
| 75 | WHERE id = \''.$page['image_id'].'\' |
---|
| 76 | ;'; |
---|
| 77 | $result = pwg_query($query); |
---|
[21163] | 78 | $row = pwg_db_fetch_assoc($result); |
---|
[9407] | 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 |
---|
| 91 | add_event_handler('loc_begin_page_header', 'Titlealbum', 71 ); |
---|
| 92 | function Titlealbum() |
---|
| 93 | { |
---|
| 94 | global $template, $page; |
---|
| 95 | if (!empty($page['category']['id']) ) |
---|
| 96 | { |
---|
| 97 | $query = ' |
---|
| 98 | select id,title |
---|
| 99 | FROM ' . TITLE_ALBUM_TABLE . ' |
---|
| 100 | WHERE id = \''.$page['category']['id'].'\' |
---|
| 101 | ;'; |
---|
| 102 | $result = pwg_query($query); |
---|
[21163] | 103 | $row = pwg_db_fetch_assoc($result); |
---|
[9407] | 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 = ' |
---|
| 122 | select 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(); |
---|
[21163] | 129 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[9407] | 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 | ?> |
---|