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