1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Random Header |
---|
4 | Version: 2.0.b |
---|
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 |
---|
6 | Plugin URI: http://phpwebgallery.net/ext/extension_view.php?eid=188 |
---|
7 | Author: repie38 |
---|
8 | Author URI: http://www.pierre-b.com |
---|
9 | */ |
---|
10 | |
---|
11 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
12 | DEFINE('RH_VERSION','v2.0.b'); |
---|
13 | define('RH_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/'); |
---|
14 | class RandomHeader |
---|
15 | { |
---|
16 | var $rh_config; |
---|
17 | function load_config() |
---|
18 | { |
---|
19 | $x = @file_get_contents( dirname(__FILE__).'/data.dat' ); |
---|
20 | if ($x!==false) |
---|
21 | $this->rh_config = unserialize($x); |
---|
22 | |
---|
23 | foreach (str_replace(" ", "_", get_pwg_themes()) as $pwg_template) { |
---|
24 | if (empty($this->rh_config[$pwg_template]['selected_cat'])) { |
---|
25 | |
---|
26 | $this->rh_config[$pwg_template]['selected_cat'] = '0'; |
---|
27 | $this->rh_config[$pwg_template]['active_on_picture']='off'; |
---|
28 | $this->rh_config[$pwg_template]['head_css']=''; |
---|
29 | $this->rh_config[$pwg_template]['img_css']=''; |
---|
30 | $this->rh_config[$pwg_template]['mode_background']='off'; |
---|
31 | $this->rh_config[$pwg_template]['concat_before'] ='off' ; |
---|
32 | $this->rh_config[$pwg_template]['concat_after'] ='off' ; |
---|
33 | |
---|
34 | $this->save_config(); |
---|
35 | } |
---|
36 | } |
---|
37 | |
---|
38 | } |
---|
39 | function save_config() |
---|
40 | { |
---|
41 | $file = fopen( dirname(__FILE__).'/data.dat', 'w' ); |
---|
42 | fwrite($file, serialize($this->rh_config) ); |
---|
43 | fclose( $file ); |
---|
44 | } |
---|
45 | function plugin_admin_menu($menu) |
---|
46 | { |
---|
47 | array_push($menu, |
---|
48 | array( |
---|
49 | 'NAME' => 'Random Header', |
---|
50 | 'URL' => get_admin_plugin_menu_link(dirname(__FILE__).'/admin/rh_admin.php') |
---|
51 | )); |
---|
52 | return $menu; |
---|
53 | } |
---|
54 | |
---|
55 | function randombanner(){ |
---|
56 | global $page; |
---|
57 | global $template; |
---|
58 | global $conf; |
---|
59 | global $user; |
---|
60 | $usertheme=str_replace(" ", "_", $user['template'].'/'.$user['theme'] ); |
---|
61 | if ( !defined('IN_ADMIN') && isset($page['body_id']) && ($page['body_id']!='thePicturePage' || $this->rh_config[$usertheme]['active_on_picture']=='on') ) { |
---|
62 | |
---|
63 | $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'); |
---|
64 | if (mysql_num_rows($result) > 0) { |
---|
65 | $toto = mysql_fetch_row($result); |
---|
66 | |
---|
67 | if ($this->rh_config[$usertheme]['mode_background']=='on') { |
---|
68 | $template->append('head_elements','<style>#theHeader{background: url('.$toto[0].') no-repeat;'. $this->rh_config[$usertheme]['head_css'] .'}</style>'); |
---|
69 | } |
---|
70 | else { |
---|
71 | if ($this->rh_config[$usertheme]['img_css']!='' || $this->rh_config[$usertheme]['head_css']!='') |
---|
72 | $template->append('head_elements','<style>#theHeader{'. $this->rh_config[$usertheme]['head_css'] .'}#theHeader #RandomImage{'. $this->rh_config[$usertheme]['img_css'] .'}</style>'); |
---|
73 | $page['page_banner'] = ($this->rh_config[$usertheme]['concat_before']=='on') ? $conf['page_banner'] : ''; |
---|
74 | $page['page_banner'].= '<img id="RandomImage" src="'.$toto[0].'">'; |
---|
75 | $page['page_banner'].= ($this->rh_config[$usertheme]['concat_after']=='on') ? $conf['page_banner'] : ''; |
---|
76 | } |
---|
77 | } |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | |
---|
82 | } |
---|
83 | $obj = new RandomHeader(); |
---|
84 | $obj->load_config(); |
---|
85 | |
---|
86 | add_event_handler('loc_begin_page_header', array(&$obj, 'randombanner') ); |
---|
87 | add_event_handler('get_admin_plugin_menu_links', array(&$obj, 'plugin_admin_menu') ); |
---|
88 | set_plugin_data($plugin['id'], $obj) |
---|
89 | |
---|
90 | |
---|
91 | ?> |
---|