Source for file class.acBlockType_date.php

Documentation is available at class.acBlockType_date.php

  1. <?php
  2. {
  3.     function __construct(&$content_obj$params array())
  4.     {
  5.         $params['block_type''date';
  6.         parent::__construct($content_obj$params);
  7.         
  8.         $showClock !(isset($params['show_clock']&& ac_utils::IsFalse($params['show_clock']));
  9.         
  10.         $mode 'calendar';
  11.         if(isset($params['mode']&& strtolower($params['mode']== 'dropdown')
  12.             $mode 'dropdown';
  13.         
  14.         $show24h    !(isset($params['show24h']&& ac_utils::IsFalse($params['show24h']));
  15.         $dateFormat = isset($params['date_format']$params['date_format''%x %X';
  16.         
  17.         $startHour 0;
  18.         $endHour   23;
  19.         if(isset($params['start_hour']))
  20.         {
  21.             if(endswith($params['start_hour'],'pm'))
  22.                 $params['start_hour'trim(str_ireplace('pm','',$params['start_hour'])) 12;
  23.             else
  24.                 $params['start_hour'trim(str_ireplace(array('am','pm'),'',$params['start_hour']));
  25.             
  26.             if($params['start_hour'&& $params['start_hour'<= $endHour)
  27.                 $startHour trim($params['start_hour']);
  28.         }
  29.         
  30.         if(isset($params['end_hour']))
  31.         {
  32.             if(endswith($params['end_hour'],'pm'))
  33.                 $params['end_hour'trim(str_ireplace('pm','',$params['end_hour'])) 12;
  34.             else
  35.                 $params['end_hour'trim(str_ireplace(array('am','pm'),'',$params['end_hour']));
  36.             
  37.             if($params['end_hour'>= && $params['end_hour'$endHour)
  38.                 $endHour trim($params['end_hour']);
  39.         }
  40.         
  41.         if($endHour $startHour)
  42.             $endHour $startHour;
  43.         
  44.         $startMinute 0;
  45.         if(isset($params['start_minute']&& $params['start_minute'&& $params['start_minute'<= 59)
  46.             $startMinute trim($params['start_minute']);
  47.         
  48.         $endMinute 59;
  49.         if(isset($params['end_minute']&& $params['end_minute'>= && $params['end_minute'59)
  50.             $endMinute trim($params['end_minute']);
  51.         
  52.         if($endMinute $startMinute)
  53.             $endMinute $startMinute;
  54.         
  55.         $startSecond 0;
  56.         if(isset($params['start_second']&& $params['start_second'&& $params['start_second'<= 59)
  57.             $startSecond trim($params['start_second']);
  58.         
  59.         $endSecond 59;
  60.         if(isset($params['end_second']&& $params['end_second'>= && $params['end_second'59)
  61.             $endSecond trim($params['end_second']);
  62.         
  63.         if($endSecond $startSecond)
  64.             $endSecond $startSecond;
  65.         
  66.         $stepHours 1;
  67.         if(isset($params['step_hours']&& $params['step_hours'&& $params['step_hours'<= ($endHour-$startHour))
  68.             $stepHours trim($params['step_hours']);
  69.         else if(isset($params['step_hours']&& $params['step_hours'&& $params['step_hours'>= ($endHour-$startHour))
  70.             $stepHours $endHour-$startHour;
  71.         
  72.         $stepMinutes 30;
  73.         if(isset($params['step_minutes']&& $params['step_minutes'&& $params['step_minutes'<= ($endMinute-$startMinute))
  74.             $stepMinutes trim($params['step_minutes']);
  75.         else if(isset($params['step_minutes']&& $params['step_minutes'&& $params['step_minutes'>= ($endMinute-$startMinute))
  76.             $stepMinutes $endMinute-$startMinute;
  77.         
  78.         $stepSeconds 1;
  79.         if(isset($params['step_seconds']&& $params['step_seconds'&& $params['step_seconds'<= ($endSecond-$startSeconds))
  80.             $stepSeconds trim($params['step_seconds']);
  81.         else if(isset($params['step_seconds']&& $params['step_seconds'&& $params['step_seconds'>= ($endSecond-$startSeconds))
  82.             $stepSeconds $endSecond-$startSeconds;
  83.         
  84.         $this->SetProperty('show24h',$show24h);
  85.         $this->SetProperty('mode',$mode);
  86.         $this->SetProperty('start_hour',$startHour);
  87.         $this->SetProperty('end_hour',$endHour);
  88.         $this->SetProperty('start_minute',$startMinute);
  89.         $this->SetProperty('end_minute',$endMinute);
  90.         $this->SetProperty('start_second',$startSecond);
  91.         $this->SetProperty('end_second',$endSecond);
  92.         $this->SetProperty('step_hours',$stepHours);
  93.         $this->SetProperty('step_minutes',$stepMinutes);
  94.         $this->SetProperty('step_seconds',$stepSeconds);
  95.         $this->SetProperty('show_clock',$showClock);
  96.         $this->SetProperty('date_format',$dateFormat);
  97.     }
  98.     
  99.     public function GetInput()
  100.     {
  101.         if(!$this->GetContent())
  102.             $this->SetContent(time());
  103.         
  104.         setlocale(LC_ALLget_preference(get_userid()'default_cms_language'));
  105.         
  106.         $date strftime('%x'intval($this->GetContent()));
  107.         $time '0:0';
  108.         if($this->GetProperty('show_clock'))
  109.             $time strftime('%H:%M'intval($this->GetContent()));
  110.         
  111.         $_tmp        ac_utils::CleanArray(explode(':',$time));
  112.         $timeSeconds (($_tmp[03600($_tmp[160));
  113.         $dateSeconds $this->GetContent($timeSeconds;
  114.         
  115.         $dateInput '<input id="'.$this->GetProperty('id').'_AdvancedContentDatePickerDisplay" type="text" value="' $date '" />
  116.             <input id="'.$this->GetProperty('id').'_AdvancedContentDate" type="hidden" name="'.$this->GetProperty('id').'[date]" value="'($dateSeconds  1000'" />';
  117.             
  118.         $suffix    '';
  119.         $timeInput '';
  120.         if($this->GetProperty('show_clock'))
  121.         {
  122.             $timeInput '&nbsp;&nbsp;-&nbsp;&nbsp;<select name="'.$this->GetProperty('id').'[time]">';
  123.             $_i        0;
  124.             for($i=$this->GetProperty('start_hour')$i<=$this->GetProperty('end_hour')$i += $this->GetProperty('step_hours'))
  125.             {
  126.                 if($i<12 && !$this->GetProperty('show24h'))
  127.                     $suffix ' am';
  128.                 else if(!$this->GetProperty('show24h'))
  129.                     $suffix ' pm';
  130.                 
  131.                 for($j=$this->GetProperty('start_minute')$j<=$this->GetProperty('end_minute')$j += $this->GetProperty('step_minutes'))
  132.                 {
  133.                     $value ($i*3600($j*60);
  134.                     if(($this->GetProperty('end_hour'23 && $value <= ($this->GetProperty('end_hour'3600)) || $this->GetProperty('end_hour'== 23)
  135.                         $timeInput .= '<option value="'$value .'"'($value == $timeSeconds ' selected="selected"':''.'>'($i<10?'0'.$i:(!$this->GetProperty('show24h'&& $i>12?$i-12:$i)) .':'($j<10?'0'.$j:$j$suffix '</option>';
  136.                 }
  137.                 $j $this->GetProperty('start_minute');
  138.             }
  139.             $timeInput .= '</select>';
  140.         }
  141.         return $dateInput.$timeInput;
  142.     }
  143.     
  144.     public function GetHeaderHTML()
  145.     {
  146.         if($this->_header_html_called)
  147.             return;
  148.         
  149.         $this->_header_html_called true;
  150.         
  151.         $ret '
  152. <script language="javascript" type="text/javascript">
  153. /* <![CDATA[ */
  154. ac_onload.push(function(){
  155.     (function($){';
  156.         foreach(acContentBlockManager::GetBlocksByType('date'as $block_id)
  157.         {
  158.             $contentBlock &$this->content_obj->GetContentBlock($block_id);
  159.             if($contentBlock->GetProperty('mode'== 'calendar')
  160.             {
  161.                 $ret .= '
  162.         $("#'$block_id .'_AdvancedContentDatePickerDisplay").datepicker({
  163.             numberOfMonths: 3,
  164.             showButtonPanel: true,
  165.             showOn: "button",
  166.             buttonImage: "../modules/AdvancedContent/images/calendar.png",
  167.             altField: "#'$block_id .'_AdvancedContentDate",
  168.             altFormat: "@",
  169.             buttonImageOnly: true
  170.         });';
  171.             }
  172.         }
  173.         return $ret '
  174.     })(jQuery);
  175. });
  176. /* ]]> */
  177. </script>';
  178.     }
  179.     
  180.     public function FillParams(&$params$editing false)
  181.     {
  182.         $blockId $this->GetProperty('id');
  183.         if(!isset($params[$blockId]|| $this->GetProperty('mode'!= 'calendar')
  184.             return;
  185.         
  186.         $value (isset($params[$blockId]['time']$params[$blockId]['time'0($params[$blockId]['date']  1000);
  187.         return $value;
  188.     }
  189.     
  190.     public function Show()
  191.     {
  192.         if($this->GetProperty('date_format'!= '')
  193.             return strftime($this->GetProperty('date_format')intval($this->GetContent()));
  194.         
  195.         return $this->GetContent();
  196.     }
  197. }
  198. ?>

Documentation generated on Tue, 09 Oct 2012 16:57:03 +0200 by phpDocumentor 1.4.1