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

Last change on this file since 7330 was 7330, checked in by repie38, 14 years ago

New admin panel

File size: 3.5 KB
RevLine 
[5483]1<?php
[3684]2/*
3Plugin Name: Random Header
[7330]4Version: 2.2
[3684]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
[7134]6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=188
[3687]7Author: repie38
[7134]8Author URI:
[3684]9*/
10
11if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
[7330]12DEFINE('RH_VERSION','v2.2');
[3684]13define('RH_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
[5465]14
[3684]15class RandomHeader
16{
[7134]17         var $rh_config;
[5465]18        function load_config()
[3684]19    {
[7134]20        $x = file_get_contents( dirname(__FILE__).'/data.dat' );
[5465]21               
[3684]22        if ($x!==false)
23                $this->rh_config = unserialize($x);
[5465]24
[7134]25                foreach (get_pwg_themes() as $pwg_templateID => $pwg_template) {
26               
27                          if (empty($this->rh_config[$pwg_templateID]['selected_cat']))  {
[5465]28
[7134]29                                $this->rh_config[$pwg_templateID]['selected_cat'] = '0';
30                $this->rh_config[$pwg_templateID]['active_on_picture']='off';
31                                $this->rh_config[$pwg_templateID]['head_css']='';
32                                $this->rh_config[$pwg_templateID]['img_css']='';
33                                $this->rh_config[$pwg_templateID]['mode_background']='off';
34                                $this->rh_config[$pwg_templateID]['concat_before'] ='off' ;
35                                $this->rh_config[$pwg_templateID]['concat_after'] ='off' ;
[3684]36
37                $this->save_config();
38                }
39                }
[5465]40
[3684]41    }
[7134]42       
43       
44       
[3684]45    function save_config()
46    {
47        $file = fopen( dirname(__FILE__).'/data.dat', 'w' );
48        fwrite($file, serialize($this->rh_config) );
49        fclose( $file );
50    }
[7134]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       
[3684]60        function randombanner(){
61                global $page;
62                global $template;
63                global $conf;
64                global $user;
[7134]65               
66                $usertheme=$user['theme'] ;
67
[3684]68                if ( !defined('IN_ADMIN') && isset($page['body_id']) && ($page['body_id']!='thePicturePage' || $this->rh_config[$usertheme]['active_on_picture']=='on') ) {
[5465]69
[3684]70                        $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');
71                        if (mysql_num_rows($result) > 0) {
72                                $toto = mysql_fetch_row($result);
[5465]73
[3684]74                                if ($this->rh_config[$usertheme]['mode_background']=='on') {
[5465]75                                        $template->append('head_elements','<style>#theHeader{background: url('.$toto[0].') no-repeat;'. $this->rh_config[$usertheme]['head_css'] .'}</style>');
[3684]76                                }
77                                else {
[5465]78                                        if ($this->rh_config[$usertheme]['img_css']!='' || $this->rh_config[$usertheme]['head_css']!='')
79                                                $template->append('head_elements','<style>#theHeader{'. $this->rh_config[$usertheme]['head_css'] .'}#theHeader #RandomImage{'. $this->rh_config[$usertheme]['img_css'] .'}</style>');
80                                        $page['page_banner'] = ($this->rh_config[$usertheme]['concat_before']=='on') ? $conf['page_banner'] : '';
[3684]81                                        $page['page_banner'].= '<img id="RandomImage" src="'.$toto[0].'">';
[5465]82                                        $page['page_banner'].= ($this->rh_config[$usertheme]['concat_after']=='on') ? $conf['page_banner'] : '';
[3684]83                                }
84                        }
85                }
86        }
87
[7134]88}
[3684]89
90$obj = new RandomHeader();
91$obj->load_config();
92add_event_handler('loc_begin_page_header', array(&$obj, 'randombanner') );
93add_event_handler('get_admin_plugin_menu_links', array(&$obj, 'plugin_admin_menu') );
94set_plugin_data($plugin['id'], $obj)
95
96
97?>
Note: See TracBrowser for help on using the repository browser.