Changeset 5465


Ignore:
Timestamp:
Mar 30, 2010, 12:19:14 AM (14 years ago)
Author:
repie38
Message:

2.0.c adding of get_file_contents function to avoid @file_get_contents errors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/Random_Header/main.inc.php

    r4538 r5465  
    1 <?php
     1<?php
    22/*
    33Plugin Name: Random Header
    4 Version: 2.0.b
     4Version: 2.0.c
    55Description: Random Header allow you to show in the header a random picture from the choosen categorie, as a normal image, or as a background
    66Plugin URI: http://phpwebgallery.net/ext/extension_view.php?eid=188
     
    1212DEFINE('RH_VERSION','v2.0.b');
    1313define('RH_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
     14
     15function 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
    1428class RandomHeader
    1529{
    1630    var $rh_config;
    17     function load_config()
     31       
     32        function load_config()
    1833    {
    19         $x = @file_get_contents( dirname(__FILE__).'/data.dat' );
     34        $x = get_file_contents( dirname(__FILE__).'/data.dat' );
     35               
    2036        if ($x!==false)
    2137                $this->rh_config = unserialize($x);
    22        
     38
    2339                foreach (str_replace(" ", "_", get_pwg_themes()) as $pwg_template) {
    2440                          if (empty($this->rh_config[$pwg_template]['selected_cat']))  {
    25                        
     41
    2642                                $this->rh_config[$pwg_template]['selected_cat'] = '0';
    2743                $this->rh_config[$pwg_template]['active_on_picture']='off';
     
    2945                                $this->rh_config[$pwg_template]['img_css']='';
    3046                                $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' ; 
     47                                $this->rh_config[$pwg_template]['concat_before'] ='off' ;
     48                                $this->rh_config[$pwg_template]['concat_after'] ='off' ;
    3349
    3450                $this->save_config();
    3551                }
    3652                }
    37            
     53
    3854    }
    3955    function save_config()
     
    6076                $usertheme=str_replace(" ", "_", $user['template'].'/'.$user['theme'] );
    6177                if ( !defined('IN_ADMIN') && isset($page['body_id']) && ($page['body_id']!='thePicturePage' || $this->rh_config[$usertheme]['active_on_picture']=='on') ) {
    62                        
     78
    6379                        $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');
    6480                        if (mysql_num_rows($result) > 0) {
    6581                                $toto = mysql_fetch_row($result);
    66                                                        
     82
    6783                                if ($this->rh_config[$usertheme]['mode_background']=='on') {
    68                                         $template->append('head_elements','<style type="text/css">#theHeader{background: url('.$toto[0].') no-repeat;'. $this->rh_config[$usertheme]['head_css'] .'}</style>');
     84                                        $template->append('head_elements','<style>#theHeader{background: url('.$toto[0].') no-repeat;'. $this->rh_config[$usertheme]['head_css'] .'}</style>');
    6985                                }
    7086                                else {
    71                                         if ($this->rh_config[$usertheme]['img_css']!='' || $this->rh_config[$usertheme]['head_css']!='') 
    72                                                 $template->append('head_elements','<style type="text/css">#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'] : ''; 
     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'] : '';
    7490                                        $page['page_banner'].= '<img id="RandomImage" src="'.$toto[0].'">';
    75                                         $page['page_banner'].= ($this->rh_config[$usertheme]['concat_after']=='on') ? $conf['page_banner'] : ''; 
     91                                        $page['page_banner'].= ($this->rh_config[$usertheme]['concat_after']=='on') ? $conf['page_banner'] : '';
    7692                                }
    7793                        }
Note: See TracChangeset for help on using the changeset viewer.