web/wp-content/plugins/event-calendar/options.php
changeset 136 bde1974c263b
equal deleted inserted replaced
135:53cff4b4a802 136:bde1974c263b
       
     1 <?php
       
     2 /*
       
     3 Copyright (c) 2005-2008, Alex Tingle.  $Revision: 281 $
       
     4 
       
     5 This program is free software; you can redistribute it and/or
       
     6 modify it under the terms of the GNU General Public License
       
     7 as published by the Free Software Foundation; either version 2
       
     8 of the License, or (at your option) any later version.
       
     9 
       
    10 This program is distributed in the hope that it will be useful,
       
    11 but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    13 GNU General Public License for more details.
       
    14 
       
    15 You should have received a copy of the GNU General Public License
       
    16 along with this program; if not, write to the Free Software
       
    17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
       
    18 */
       
    19 
       
    20 /** Singleton class. Manages EC3 options. Global options that are guaranteed to
       
    21  *  exist (start of week, siteurl, home) are not managed by this class. */
       
    22 class ec3_Options
       
    23 {
       
    24   // Some global variables.
       
    25   var $version='3.1.4';
       
    26   var $myfiles='';
       
    27   var $call_count=0;
       
    28   var $schedule='ec3_schedule'; // table name
       
    29 
       
    30   // Code differences required by different versions of WordPress.
       
    31   // Defaults represent the latest version of WP.
       
    32 
       
    33   /** The name of the column wp_posts.user_nicename. */
       
    34   var $wp_user_nicename='user_nicename';
       
    35   /** The root of the XHTML id of the category checkboxes (edit page). */
       
    36   var $wp_in_category='in-category-';
       
    37   /** Is DBX available? */
       
    38   var $wp_have_dbx=true;
       
    39   /** Do we have categories? (WP<2.3) */
       
    40   var $wp_have_categories=false;
       
    41 
       
    42   // Settings used to flags activity between posts_where and other filters:
       
    43   var $is_listing=false;
       
    44   var $is_date_range=false;
       
    45   var $is_today=false;
       
    46   var $days=false;
       
    47   var $range_from=false;
       
    48   var $range_before=false;
       
    49   var $join_ec3_sch=false;
       
    50   var $join_only_active_events=false;
       
    51   var $order_by_start=false;
       
    52   
       
    53   /** May be set TRUE by a template before the call to wp_head().
       
    54     * Turns off CSS in header. */
       
    55   var $nocss=false;
       
    56 
       
    57   /** Which category is used for events? DEFAULT=0 */
       
    58   var $event_category;
       
    59   /** Show only events in calendar. DEFAULT=false */
       
    60   var $show_only_events;
       
    61   /** Number to months displayed by get_calendar(). DEFAULT=1 */
       
    62   var $num_months;
       
    63   /** Should day names be abbreviated to 1 or 3 letters? DEFAULT=1 */
       
    64   var $day_length;
       
    65   /** Hide the 'EC' logo on calendar displays? DEFAULT=0 */
       
    66   var $hide_logo;
       
    67   /** Display event box within post. DEFAULT=0 */
       
    68   var $hide_event_box;
       
    69   /** Use advanced post behaviour? DEFAULT=0 */
       
    70   var $advanced;
       
    71   /** Position navigation links or hide them. DEFAULT=0 */
       
    72   var $navigation;
       
    73   /** Disable popups? DEFAULT=0 */
       
    74   var $disable_popups;
       
    75   /** Local timezone. */
       
    76   var $tz;
       
    77 
       
    78   function ec3_Options()
       
    79   {
       
    80     global $table_prefix,$wp_version;
       
    81 
       
    82     $mydir=
       
    83       preg_replace('%^.*[/\\\\]([^/\\\\]+)[/\\\\]options.php$%','$1',__FILE__);
       
    84     load_plugin_textdomain('ec3','wp-content/plugins/'.$mydir.'/gettext');
       
    85 
       
    86     $this->myfiles=get_option('siteurl').'/wp-content/plugins/'.$mydir;
       
    87     $this->schedule=$table_prefix.$this->schedule; // table name
       
    88 
       
    89     // wp_version < 2.0
       
    90     if(ereg('^1[.]',$wp_version))
       
    91     {
       
    92       $this->wp_user_nicename='user_nickname';
       
    93       $this->wp_have_dbx=false;
       
    94     }
       
    95     // wp_version < 2.1
       
    96     if(ereg('^(1[.]|2[.]0)',$wp_version))
       
    97     {
       
    98       $this->wp_in_category='category-';
       
    99     }
       
   100     // wp_version < 2.3
       
   101     if(ereg('^(1[.]|2[.][012])',$wp_version))
       
   102     {
       
   103       $this->wp_have_categories=true;
       
   104     }
       
   105 
       
   106     $this->read_event_category();
       
   107     $this->read_show_only_events();
       
   108     $this->read_num_months();
       
   109     $this->read_day_length();
       
   110     $this->read_hide_logo();
       
   111     $this->read_hide_event_box();
       
   112     $this->read_advanced();
       
   113     $this->read_navigation();
       
   114     $this->read_disable_popups();
       
   115     $this->read_tz();
       
   116   }
       
   117   
       
   118   function reset_query()
       
   119   {
       
   120     $this->is_listing=false;
       
   121     $this->is_date_range=false;
       
   122     $this->is_today=false;
       
   123     $this->days=false;
       
   124     $this->range_from=false;
       
   125     $this->range_before=false;
       
   126     $this->join_ec3_sch=false;
       
   127     $this->join_only_active_events=false;
       
   128     $this->order_by_start=false;
       
   129   }
       
   130 
       
   131   // READ functions
       
   132   function read_event_category()
       
   133   {
       
   134     $this->event_category=intval( get_option('ec3_event_category') );
       
   135   }
       
   136   function read_show_only_events()
       
   137   {
       
   138     $this->show_only_events=intval(get_option('ec3_show_only_events'));
       
   139   }
       
   140   function read_num_months()
       
   141   {
       
   142     $this->num_months =abs(intval(get_option('ec3_num_months')));
       
   143     if(!$this->num_months)
       
   144         $this->num_months=1;
       
   145   }
       
   146   function read_day_length()
       
   147   {
       
   148     $this->day_length=intval(get_option('ec3_day_length'));
       
   149     if($this->day_length==0)
       
   150         $this->day_length=1;
       
   151   }
       
   152   function read_hide_logo()
       
   153   {
       
   154     $this->hide_logo=intval(get_option('ec3_hide_logo'));
       
   155   }
       
   156   function read_hide_event_box()
       
   157   {
       
   158     $this->hide_event_box=intval(get_option('ec3_hide_event_box'));
       
   159   }
       
   160   function read_advanced()
       
   161   {
       
   162     $this->advanced=intval(get_option('ec3_advanced'));
       
   163     // Sometimes we want to play around with the value of advanced.
       
   164     // 'advanced_setting' ALWAYS holds the REAL value.
       
   165     $this->advanced_setting=$this->advanced;
       
   166   }
       
   167   function read_navigation()
       
   168   {
       
   169     $this->navigation=intval(get_option('ec3_navigation'));
       
   170   }
       
   171   function read_disable_popups()
       
   172   {
       
   173     $this->disable_popups=intval(get_option('ec3_disable_popups'));
       
   174   }
       
   175   function read_tz()
       
   176   {
       
   177     $this->tz = get_option('ec3_tz');
       
   178     if(empty($this->tz) || $this->tz=='wordpress')
       
   179     {
       
   180       // Use WordPress default (doesn't understand daylight saving time).
       
   181       $gmt_offset=-intval(get_option('gmt_offset'));
       
   182       $this->tz='UTC';
       
   183       if($gmt_offset>0)
       
   184         $this->tz.='+'.$gmt_offset;
       
   185       elseif($gmt_offset<0)
       
   186         $this->tz.=$gmt_offset;
       
   187     }
       
   188   }
       
   189   
       
   190   // SET functions
       
   191   function set_event_category($val)
       
   192   {
       
   193     if($this->event_category!=$val)
       
   194     {
       
   195       update_option('ec3_event_category',$val);
       
   196       $this->read_event_category();
       
   197     }
       
   198   }
       
   199   function set_show_only_events($val)
       
   200   {
       
   201     if($this->show_only_events!=$val)
       
   202     {
       
   203       update_option('ec3_show_only_events',$val);
       
   204       $this->read_show_only_events();
       
   205     }
       
   206   }
       
   207   function set_num_months($val)
       
   208   {
       
   209     if($this->num_months!=$val)
       
   210     {
       
   211       update_option('ec3_num_months',$val);
       
   212       $this->read_num_months();
       
   213     }
       
   214   }
       
   215   function set_day_length($val)
       
   216   {
       
   217     if($this->day_length!=$val)
       
   218     {
       
   219       update_option('ec3_day_length',$val);
       
   220       $this->read_day_length();
       
   221     }
       
   222   }
       
   223   function set_hide_logo($val)
       
   224   {
       
   225     if($this->hide_logo!=$val)
       
   226     {
       
   227       update_option('ec3_hide_logo',$val);
       
   228       $this->read_hide_logo();
       
   229     }
       
   230   }
       
   231   function set_hide_event_box($val)
       
   232   {
       
   233     if($this->hide_event_box!=$val)
       
   234     {
       
   235       update_option('ec3_hide_event_box',$val);
       
   236       $this->read_hide_event_box();
       
   237     }
       
   238   }
       
   239   function set_advanced($val)
       
   240   {
       
   241     if($this->advanced_setting!=$val)
       
   242     {
       
   243       update_option('ec3_advanced',$val);
       
   244     }
       
   245     // read_advanced() does some special magic, so we always call it.
       
   246     $this->read_advanced();
       
   247   }
       
   248   function set_navigation($val)
       
   249   {
       
   250     if($this->navigation!=$val)
       
   251     {
       
   252       update_option('ec3_navigation',$val);
       
   253       $this->read_navigation();
       
   254     }
       
   255   }
       
   256   function set_disable_popups($val)
       
   257   {
       
   258     if($this->disable_popups!=$val)
       
   259     {
       
   260       update_option('ec3_disable_popups',$val);
       
   261       $this->read_disable_popups();
       
   262     }
       
   263   }
       
   264   function set_tz($val)
       
   265   {
       
   266     if(!preg_match('/(WordPress|[_a-zA-Z\/]+)/',$val))
       
   267       return;
       
   268     if($this->tz!=$val)
       
   269     {
       
   270       update_option('ec3_tz',$val);
       
   271       $this->read_tz();
       
   272     }
       
   273   }
       
   274 } // end class ec3_Options
       
   275 
       
   276 
       
   277 /** Singleton instance of ec3_Options. */
       
   278 $ec3=new ec3_Options();
       
   279 
       
   280 
       
   281 ?>