1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Random Header |
---|
4 | Version: 2.0.d |
---|
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.d'); |
---|
13 | define('RH_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/'); |
---|
14 | |
---|
15 | function get_file_contents($url, $totalTries = 5) |
---|
16 | { |
---|
17 | $Tries = 0; |
---|
18 | do |
---|
19 | { |
---|
20 | if ($Tries > 0) sleep(1); # Wait for a sec before retrieving again |
---|
21 | $contents = @file_get_contents($url); |
---|
22 | $Tries++; |
---|
23 | } while ($Tries <= $totalTries && $contents === FALSE); |
---|
24 | if ($contents == "") $contents = FALSE; |
---|
25 | return $contents; |
---|
26 | } |
---|
27 | |
---|
28 | class RandomHeader |
---|
29 | { |
---|
30 | var $rh_config; |
---|
31 | |
---|
32 | function load_config() |
---|
33 | { |
---|
34 | $x = get_file_contents( dirname(__FILE__).'/data.dat' ); |
---|
35 | |
---|
36 | if ($x!==false) |
---|
37 | $this->rh_config = unserialize($x); |
---|
38 | |
---|
39 | foreach (str_replace(" ", "_", get_pwg_themes()) as $pwg_template) { |
---|
40 | if (empty($this->rh_config[$pwg_template]['selected_cat'])) { |
---|
41 | |
---|
42 | $this->rh_config[$pwg_template]['selected_cat'] = '0'; |
---|
43 | $this->rh_config[$pwg_template]['active_on_picture']='off'; |
---|
44 | $this->rh_config[$pwg_template]['head_css']=''; |
---|
45 | $this->rh_config[$pwg_template]['img_css']=''; |
---|
46 | $this->rh_config[$pwg_template]['mode_background']='off'; |
---|
47 | $this->rh_config[$pwg_template]['concat_before'] ='off' ; |
---|
48 | $this->rh_config[$pwg_template]['concat_after'] ='off' ; |
---|
49 | |
---|
50 | $this->save_config(); |
---|
51 | } |
---|
52 | } |
---|
53 | |
---|
54 | } |
---|
55 | function save_config() |
---|
56 | { |
---|
57 | $file = fopen( dirname(__FILE__).'/data.dat', 'w' ); |
---|
58 | fwrite($file, serialize($this->rh_config) ); |
---|
59 | fclose( $file ); |
---|
60 | } |
---|
61 | function plugin_admin_menu($menu) |
---|
62 | { |
---|
63 | array_push($menu, |
---|
64 | array( |
---|
65 | 'NAME' => 'Random Header', |
---|
66 | 'URL' => get_admin_plugin_menu_link(dirname(__FILE__).'/admin/rh_admin.php') |
---|
67 | )); |
---|
68 | return $menu; |
---|
69 | } |
---|
70 | |
---|
71 | function randombanner(){ |
---|
72 | global $page; |
---|
73 | global $template; |
---|
74 | global $conf; |
---|
75 | global $user; |
---|
76 | $usertheme=str_replace(" ", "_", $user['template'].'/'.$user['theme'] ); |
---|
77 | if ( !defined('IN_ADMIN') && isset($page['body_id']) && ($page['body_id']!='thePicturePage' || $this->rh_config[$usertheme]['active_on_picture']=='on') ) { |
---|
78 | |
---|
79 | $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'); |
---|
80 | if (mysql_num_rows($result) > 0) { |
---|
81 | $toto = mysql_fetch_row($result); |
---|
82 | |
---|
83 | if ($this->rh_config[$usertheme]['mode_background']=='on') { |
---|
84 | $template->append('head_elements','<style>#theHeader{background: url('.$toto[0].') no-repeat;'. $this->rh_config[$usertheme]['head_css'] .'}</style>'); |
---|
85 | } |
---|
86 | else { |
---|
87 | if ($this->rh_config[$usertheme]['img_css']!='' || $this->rh_config[$usertheme]['head_css']!='') |
---|
88 | $template->append('head_elements','<style>#theHeader{'. $this->rh_config[$usertheme]['head_css'] .'}#theHeader #RandomImage{'. $this->rh_config[$usertheme]['img_css'] .'}</style>'); |
---|
89 | $page['page_banner'] = ($this->rh_config[$usertheme]['concat_before']=='on') ? $conf['page_banner'] : ''; |
---|
90 | $page['page_banner'].= '<img id="RandomImage" src="'.$toto[0].'">'; |
---|
91 | $page['page_banner'].= ($this->rh_config[$usertheme]['concat_after']=='on') ? $conf['page_banner'] : ''; |
---|
92 | } |
---|
93 | } |
---|
94 | } |
---|
95 | } |
---|
96 | |
---|
97 | |
---|
98 | } |
---|
99 | $obj = new RandomHeader(); |
---|
100 | $obj->load_config(); |
---|
101 | |
---|
102 | add_event_handler('loc_begin_page_header', array(&$obj, 'randombanner') ); |
---|
103 | add_event_handler('get_admin_plugin_menu_links', array(&$obj, 'plugin_admin_menu') ); |
---|
104 | set_plugin_data($plugin['id'], $obj) |
---|
105 | |
---|
106 | |
---|
107 | ?> |
---|