source: extensions/Random_Header/main.inc.php @ 7362

Last change on this file since 7362 was 7362, checked in by repie38, 13 years ago

change version from 2.2 to 2.1.2

File size: 3.5 KB
Line 
1<?php
2/*
3Plugin Name: Random Header
4Version: 2.1.2
5Description: Random Header allow you to show in the header a random picture from the choosen categorie, as a normal image, or as a background
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=188
7Author: repie38
8Author URI:
9*/
10
11if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
12DEFINE('RH_VERSION','v2.1.2');
13define('RH_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
14
15class RandomHeader
16{
17        var $rh_config;
18       
19        function load_config()
20    { 
21                global $conf;
22                $this->rh_config = unserialize($conf['Random_Header']);
23                foreach (get_pwg_themes() as $pwg_templateID => $pwg_template) {
24               
25                          if (empty($this->rh_config[$pwg_templateID]['selected_cat']))  {
26
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' ;
34
35                $this->save_config();
36                }
37                }
38        }
39       
40    function save_config()
41        {
42                $query = '
43                                        UPDATE '.CONFIG_TABLE.'
44                                        SET value = "'.addslashes(serialize($this->rh_config)).'"
45                                        WHERE param = "Random_Header"
46                                        ;';
47                pwg_query($query);
48               
49                load_conf_from_db();
50        }
51       
52        function plugin_admin_menu($menu)
53        {
54                array_push($menu,array(
55                                'NAME' => 'Random Header',
56                                'URL'  => get_admin_plugin_menu_link(dirname(__FILE__).'/admin/rh_admin.php')));
57                return $menu;
58        }
59       
60        function randombanner(){
61                global $page;
62                global $template;
63                global $conf;
64                global $user;
65               
66                $usertheme=$user['theme'] ;
67               
68                if (isset($this->rh_config[$usertheme])){
69                if ( !defined('IN_ADMIN') && isset($page['body_id']) && ($page['body_id']!='thePicturePage' || $this->rh_config[$usertheme]['active_on_picture']=='on') ) {
70
71                        $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');
72                        if (mysql_num_rows($result) > 0) {
73                                $toto = mysql_fetch_row($result);
74
75                                if ($this->rh_config[$usertheme]['mode_background']=='on') {
76                                        $template->append('head_elements','<style>#theHeader{background: url('.$toto[0].') no-repeat;'. $this->rh_config[$usertheme]['head_css'] .'}</style>');
77                                }
78                                else {
79                                        if ($this->rh_config[$usertheme]['img_css']!='' || $this->rh_config[$usertheme]['head_css']!='')
80                                                $template->append('head_elements','<style>#theHeader{'. $this->rh_config[$usertheme]['head_css'] .'}#theHeader #RandomImage{'. $this->rh_config[$usertheme]['img_css'] .'}</style>');
81                                        $page['page_banner'] = ($this->rh_config[$usertheme]['concat_before']=='on') ? $conf['page_banner'] : '';
82                                        $page['page_banner'].= '<img id="RandomImage" src="'.$toto[0].'">';
83                                        $page['page_banner'].= ($this->rh_config[$usertheme]['concat_after']=='on') ? $conf['page_banner'] : '';
84                                }
85                        }
86                }}
87        }
88
89}
90
91$obj = new RandomHeader();
92$obj->load_config();
93add_event_handler('loc_begin_page_header', array(&$obj, 'randombanner') );
94add_event_handler('get_admin_plugin_menu_links', array(&$obj, 'plugin_admin_menu') );
95set_plugin_data($plugin['id'], $obj)
96
97
98?>
Note: See TracBrowser for help on using the repository browser.