[5483] | 1 | <?php |
---|
[3684] | 2 | /* |
---|
| 3 | Plugin Name: Random Header |
---|
[10938] | 4 | Version: 2.2 |
---|
[3684] | 5 | Description: Random Header allow you to show in the header a random picture from the choosen categorie, as a normal image, or as a background |
---|
[7134] | 6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=188 |
---|
[3687] | 7 | Author: repie38 |
---|
[7134] | 8 | Author URI: |
---|
[3684] | 9 | */ |
---|
| 10 | |
---|
| 11 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
[10938] | 12 | DEFINE('RH_VERSION','v2.2'); |
---|
[3684] | 13 | define('RH_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/'); |
---|
[5465] | 14 | |
---|
[3684] | 15 | class RandomHeader |
---|
| 16 | { |
---|
[7358] | 17 | var $rh_config; |
---|
| 18 | |
---|
[5465] | 19 | function load_config() |
---|
[7358] | 20 | { |
---|
| 21 | global $conf; |
---|
| 22 | $this->rh_config = unserialize($conf['Random_Header']); |
---|
| 23 | foreach (get_pwg_themes() as $pwg_templateID => $pwg_template) { |
---|
[7134] | 24 | |
---|
[7414] | 25 | if (empty($this->rh_config[$pwg_templateID]['selected_cat'])) { |
---|
[5465] | 26 | |
---|
[7134] | 27 | $this->rh_config[$pwg_templateID]['selected_cat'] = '0'; |
---|
| 28 | $this->rh_config[$pwg_templateID]['active_on_picture']='off'; |
---|
| 29 | $this->rh_config[$pwg_templateID]['head_css']=''; |
---|
| 30 | $this->rh_config[$pwg_templateID]['img_css']=''; |
---|
| 31 | $this->rh_config[$pwg_templateID]['mode_background']='off'; |
---|
| 32 | $this->rh_config[$pwg_templateID]['concat_before'] ='off' ; |
---|
| 33 | $this->rh_config[$pwg_templateID]['concat_after'] ='off' ; |
---|
[7412] | 34 | $this->rh_config[$pwg_templateID]['root_link'] ='off' ; |
---|
[3684] | 35 | |
---|
| 36 | $this->save_config(); |
---|
| 37 | } |
---|
[7414] | 38 | if (!isset($this->rh_config[$pwg_templateID]['root_link'])) $this->rh_config[$pwg_templateID]['root_link']='off'; |
---|
| 39 | |
---|
[3684] | 40 | } |
---|
[7358] | 41 | } |
---|
[7134] | 42 | |
---|
[3684] | 43 | function save_config() |
---|
[7358] | 44 | { |
---|
| 45 | $query = ' |
---|
| 46 | UPDATE '.CONFIG_TABLE.' |
---|
| 47 | SET value = "'.addslashes(serialize($this->rh_config)).'" |
---|
| 48 | WHERE param = "Random_Header" |
---|
| 49 | ;'; |
---|
| 50 | pwg_query($query); |
---|
| 51 | |
---|
| 52 | load_conf_from_db(); |
---|
| 53 | } |
---|
[7134] | 54 | |
---|
| 55 | function plugin_admin_menu($menu) |
---|
| 56 | { |
---|
| 57 | array_push($menu,array( |
---|
| 58 | 'NAME' => 'Random Header', |
---|
[10938] | 59 | 'URL' => get_root_url().'admin.php?page=plugin-'.basename(dirname(__FILE__)))); |
---|
[7134] | 60 | return $menu; |
---|
| 61 | } |
---|
| 62 | |
---|
[3684] | 63 | function randombanner(){ |
---|
| 64 | global $page; |
---|
| 65 | global $template; |
---|
| 66 | global $conf; |
---|
| 67 | global $user; |
---|
[7134] | 68 | |
---|
| 69 | $usertheme=$user['theme'] ; |
---|
[7358] | 70 | |
---|
| 71 | if (isset($this->rh_config[$usertheme])){ |
---|
[3684] | 72 | if ( !defined('IN_ADMIN') && isset($page['body_id']) && ($page['body_id']!='thePicturePage' || $this->rh_config[$usertheme]['active_on_picture']=='on') ) { |
---|
[5465] | 73 | |
---|
[3684] | 74 | $result = pwg_query('SELECT '.IMAGES_TABLE.'.path FROM '.IMAGES_TABLE.' , '.IMAGE_CATEGORY_TABLE.' WHERE '.IMAGES_TABLE.'.`id` = '.IMAGE_CATEGORY_TABLE.'.`image_id` AND '.IMAGE_CATEGORY_TABLE.'.category_id = ' . $this->rh_config[$usertheme]['selected_cat'] . ' ORDER BY RAND() LIMIT 0,1'); |
---|
| 75 | if (mysql_num_rows($result) > 0) { |
---|
| 76 | $toto = mysql_fetch_row($result); |
---|
[5465] | 77 | |
---|
[3684] | 78 | if ($this->rh_config[$usertheme]['mode_background']=='on') { |
---|
[10938] | 79 | $template->append('head_elements','<style type="text/css">#theHeader{background: url('.$toto[0].') no-repeat;'. $this->rh_config[$usertheme]['head_css'] .'}</style>'); |
---|
[3684] | 80 | } |
---|
| 81 | else { |
---|
[5465] | 82 | if ($this->rh_config[$usertheme]['img_css']!='' || $this->rh_config[$usertheme]['head_css']!='') |
---|
[10938] | 83 | $template->append('head_elements','<style type="text/css">#theHeader{'. $this->rh_config[$usertheme]['head_css'] .'}#theHeader #RandomImage{'. $this->rh_config[$usertheme]['img_css'] .'}</style>'); |
---|
[5465] | 84 | $page['page_banner'] = ($this->rh_config[$usertheme]['concat_before']=='on') ? $conf['page_banner'] : ''; |
---|
[7412] | 85 | $page['page_banner'].= ($this->rh_config[$usertheme]['root_link']=='on') ? '<a href="'.PHPWG_ROOT_PATH.'" title="'.l10n('Home').'">' : ''; |
---|
[3684] | 86 | $page['page_banner'].= '<img id="RandomImage" src="'.$toto[0].'">'; |
---|
[7412] | 87 | $page['page_banner'].= ($this->rh_config[$usertheme]['root_link']=='on') ? '</a>' : ''; |
---|
[5465] | 88 | $page['page_banner'].= ($this->rh_config[$usertheme]['concat_after']=='on') ? $conf['page_banner'] : ''; |
---|
[3684] | 89 | } |
---|
| 90 | } |
---|
[7358] | 91 | }} |
---|
[3684] | 92 | } |
---|
| 93 | |
---|
[7134] | 94 | } |
---|
[3684] | 95 | |
---|
| 96 | $obj = new RandomHeader(); |
---|
| 97 | $obj->load_config(); |
---|
| 98 | add_event_handler('loc_begin_page_header', array(&$obj, 'randombanner') ); |
---|
| 99 | add_event_handler('get_admin_plugin_menu_links', array(&$obj, 'plugin_admin_menu') ); |
---|
| 100 | set_plugin_data($plugin['id'], $obj) |
---|
| 101 | |
---|
| 102 | |
---|
| 103 | ?> |
---|