Changeset 1381583
- Timestamp:
- 03/30/2016 01:16:47 AM (10 years ago)
- Location:
- omt-on-air/trunk
- Files:
-
- 3 edited
-
. (modified) (1 prop)
-
readme.txt (modified) (2 diffs)
-
wp.widget_lrhomtonair.php (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
omt-on-air/trunk
-
Property
svn:ignore
set to
__history
-
Property
svn:ignore
set to
-
omt-on-air/trunk/readme.txt
r1285800 r1381583 63 63 == Changelog == 64 64 65 = 1.4.0 = 66 * Maintenance. 67 * Changed ajax update interval default to 20 seconds 68 * Changed ajax call to use internal object, fewer parameters 69 70 = 1.3.0 = 71 * Maintenance. 72 * Addition of option to not show album data 73 * Addition of option to show a number of recently played cuts 74 * Addition of option to limit cuts displayed to a category 75 65 76 = 1.2.3 = 66 67 77 * Maintenance. 68 78 * Addition of footer line. 69 79 70 80 = 1.2.0 = 71 72 81 * Maintenance update. 73 82 … … 81 90 * This is the initial version. You'll like it. 82 91 83 = 1.2.3 =84 * Maintenance.85 * Addition of footer line.86 87 = 1.3.0 =88 * Maintenance.89 * Addition of option to not show album data90 * Addition of option to show a number of recently played cuts91 * Addition of option to limit cuts displayed to a category92 93 92 == Upgrade Notice == 94 93 95 = 1. 3.0 =94 = 1.4.0 = 96 95 * Maintenance. 97 * Addition of option to not show album data 98 * Addition of option to show a number of recently played cuts 99 * Addition of option to limit cuts displayed to a category 96 * Changed ajax update interval default to 20 seconds 97 * Changed ajax call to use internal object, fewer parameters -
omt-on-air/trunk/wp.widget_lrhomtonair.php
r1285796 r1381583 5 5 Description: Retrieves the OMT/iMediaTouch OnAir xml file and displays the active cut. 6 6 Author: Larry Houbre, Jr. 7 Version: 1. 3.07 Version: 1.4.0 8 8 */ 9 9 … … 23 23 define('cwidgetoption_lrhomtonair_useajax','lrhomtonair_ua'); 24 24 define('cwidgetoption_lrhomtonair_useintervalsecs','lrhomtonair_is'); 25 define('cwidgetoption_lrhomtonair_useintervalsecs_value','2 .5');25 define('cwidgetoption_lrhomtonair_useintervalsecs_value','20'); 26 26 define('cwidgetoption_lrhomtonair_ajaxload','lrhomtonair_al'); 27 27 define('cwidgetoption_lrhomtonair_ajaxload_value',__('Loading...',cwidgetbaseid_lrhomtonair)); … … 32 32 33 33 define('cwidgetajax_lrhomtonair_request','lrhomtonair_ar'); 34 define('cwidgetajax_lrhomtonair_request_update','update');35 define('cwidgetajax_lrhomtonair_url','lrhomtonair_au');36 define('cwidgetajax_lrhomtonair_defpgm','lrhomtonair_ad');37 define('cwidgetajax_lrhomtonair_usediv','lrhomtonair_ud');38 define('cwidgetajax_lrhomtonair_showalbum','lrhomtonair_salb');39 define('cwidgetajax_lrhomtonair_cats','lrhomtonair_cats');40 define('cwidgetajax_lrhomtonair_prevcount','lrhomtonair_pcnt');41 34 define('cwidgetajax_lrhomtonair_nonce','lrhomtonair_an'); 42 35 … … 44 37 class lrh_widget_omtonair extends LRH_WPWidget { 45 38 46 function __construct()47 {48 $n=__(cwidgetname_lrhomtonair,cwidgetbaseid_lrhomtonair);49 $d=__('Retrieves the OMT/iMediaTouch OnAir xml file and displays the active cut.',cwidgetbaseid_lrhomtonair);50 parent::__construct('bi_'.cwidgetbaseid_lrhomtonair,cwidgetbaseid_lrhomtonair,$n,$d);51 52 //Register option fields53 $this->RegisterOptionField('title'54 ,__('Title:',cwidgetbaseid_lrhomtonair)55 ,'','text');56 $this->RegisterOptionField(cwidgetoption_lrhomtonair_defaultprogram57 ,__('Default Program:',cwidgetbaseid_lrhomtonair)58 ,'','text');59 $this->RegisterOptionField(cwidgetoption_lrhomtonair_xmlurl60 ,__('Location of OMT XML file: (required)',cwidgetbaseid_lrhomtonair)61 ,'','text');62 $this->RegisterOptionField(cwidgetoption_lrhomtonair_useajax63 ,__('Use Ajax:',cwidgetbaseid_lrhomtonair)64 ,'0','yesnoselect');65 $this->RegisterOptionField(cwidgetoption_lrhomtonair_useintervalsecs66 ,__('Ajax update interval, seconds:',cwidgetbaseid_lrhomtonair)67 ,cwidgetoption_lrhomtonair_useintervalsecs_value,'text');68 $this->RegisterOptionField(cwidgetoption_lrhomtonair_ajaxload69 ,__('"Loading" notice:',cwidgetbaseid_lrhomtonair)70 ,'','text');71 $this->RegisterOptionField(cwidgetoption_lrhomtonair_usediv72 ,__('Output as non-list:',cwidgetbaseid_lrhomtonair)73 ,'0','yesnoselect');74 $this->RegisterOptionField(cwidgetoption_lrhomtonair_foot75 ,__('Footer text:',cwidgetbaseid_lrhomtonair)76 ,'','text');77 $this->RegisterOptionField(cwidgetoption_lrhomtonair_showalbum78 ,__('Show album:',cwidgetbaseid_lrhomtonair)79 ,'1','yesnoselect');80 $this->RegisterOptionField(cwidgetoption_lrhomtonair_cats81 ,__('Categorys:',cwidgetbaseid_lrhomtonair)82 ,'','text');83 $this->RegisterOptionField(cwidgetoption_lrhomtonair_prevcount84 ,__('Show recently played:',cwidgetbaseid_lrhomtonair)85 ,'0','text');86 87 $this->RegisterFieldHelp(cwidgetoption_lrhomtonair_defaultprogram88 ,__('Used when there is no cut playing, or no data available. Default is ',cwidgetbaseid_lrhomtonair)39 function __construct() 40 { 41 $n=__(cwidgetname_lrhomtonair,cwidgetbaseid_lrhomtonair); 42 $d=__('Retrieves the OMT/iMediaTouch OnAir xml file and displays the active cut.',cwidgetbaseid_lrhomtonair); 43 parent::__construct('bi_'.cwidgetbaseid_lrhomtonair,cwidgetbaseid_lrhomtonair,$n,$d); 44 45 //Register option fields 46 $this->RegisterOptionField('title' 47 ,__('Title:',cwidgetbaseid_lrhomtonair) 48 ,'','text'); 49 $this->RegisterOptionField(cwidgetoption_lrhomtonair_defaultprogram 50 ,__('Default Program:',cwidgetbaseid_lrhomtonair) 51 ,'','text'); 52 $this->RegisterOptionField(cwidgetoption_lrhomtonair_xmlurl 53 ,__('Location of OMT XML file: (required)',cwidgetbaseid_lrhomtonair) 54 ,'','text'); 55 $this->RegisterOptionField(cwidgetoption_lrhomtonair_useajax 56 ,__('Use Ajax:',cwidgetbaseid_lrhomtonair) 57 ,'0','yesnoselect'); 58 $this->RegisterOptionField(cwidgetoption_lrhomtonair_useintervalsecs 59 ,__('Ajax update interval, seconds:',cwidgetbaseid_lrhomtonair) 60 ,cwidgetoption_lrhomtonair_useintervalsecs_value,'text'); 61 $this->RegisterOptionField(cwidgetoption_lrhomtonair_ajaxload 62 ,__('"Loading" notice:',cwidgetbaseid_lrhomtonair) 63 ,'','text'); 64 $this->RegisterOptionField(cwidgetoption_lrhomtonair_usediv 65 ,__('Output as non-list:',cwidgetbaseid_lrhomtonair) 66 ,'0','yesnoselect'); 67 $this->RegisterOptionField(cwidgetoption_lrhomtonair_foot 68 ,__('Footer text:',cwidgetbaseid_lrhomtonair) 69 ,'','text'); 70 $this->RegisterOptionField(cwidgetoption_lrhomtonair_showalbum 71 ,__('Show album:',cwidgetbaseid_lrhomtonair) 72 ,'1','yesnoselect'); 73 $this->RegisterOptionField(cwidgetoption_lrhomtonair_cats 74 ,__('Categorys:',cwidgetbaseid_lrhomtonair) 75 ,'','text'); 76 $this->RegisterOptionField(cwidgetoption_lrhomtonair_prevcount 77 ,__('Show recently played:',cwidgetbaseid_lrhomtonair) 78 ,'0','text'); 79 80 $this->RegisterFieldHelp(cwidgetoption_lrhomtonair_defaultprogram 81 ,__('Used when there is no cut playing, or no data available. Default is ',cwidgetbaseid_lrhomtonair) 89 82 .cwidgetoption_lrhomtonair_defaultprogram_value); 90 $this->RegisterFieldHelp(cwidgetoption_lrhomtonair_xmlurl91 ,__('Use file:://path if the file resides on the host system.',cwidgetbaseid_lrhomtonair));92 $this->RegisterFieldHelp(cwidgetoption_lrhomtonair_useajax93 ,__('Keeps status updated, every interval seconds.',cwidgetbaseid_lrhomtonair));94 $this->RegisterFieldHelp(cwidgetoption_lrhomtonair_useintervalsecs95 ,__('When using ajax, update this often, in seconds. Default is ',cwidgetbaseid_lrhomtonair)83 $this->RegisterFieldHelp(cwidgetoption_lrhomtonair_xmlurl 84 ,__('Use file:://path if the file resides on the host system.',cwidgetbaseid_lrhomtonair)); 85 $this->RegisterFieldHelp(cwidgetoption_lrhomtonair_useajax 86 ,__('Keeps status updated, every interval seconds.',cwidgetbaseid_lrhomtonair)); 87 $this->RegisterFieldHelp(cwidgetoption_lrhomtonair_useintervalsecs 88 ,__('When using ajax, update this often, in seconds. Default is ',cwidgetbaseid_lrhomtonair) 96 89 .cwidgetoption_lrhomtonair_useintervalsecs_value); 97 $this->RegisterFieldHelp(cwidgetoption_lrhomtonair_ajaxload 98 ,__('Text shown while waiting for initial ajax response.',cwidgetbaseid_lrhomtonair)); 99 $this->RegisterFieldHelp(cwidgetoption_lrhomtonair_usediv 100 ,__('Do not use an unnumbered list in display text, use div instead.',cwidgetbaseid_lrhomtonair)); 101 $this->RegisterFieldHelp(cwidgetoption_lrhomtonair_cats 102 ,__('[optional] List categorys to show, comma separated.' 103 .' (Or, start list with a minus "-" to NOT show these categorys.)' 104 ,cwidgetbaseid_lrhomtonair) 105 ); 106 $this->RegisterFieldHelp(cwidgetoption_lrhomtonair_prevcount 107 ,__('Number of recently played cuts to show, normally none. ' 108 .' (Set to -1 to show one if nothing playing can be displayed)' 109 ,cwidgetbaseid_lrhomtonair) 110 ); 111 112 // Make sure jQuery is available 113 // already always included in WP 2.x ?? 114 wp_enqueue_script('jquery'); 115 } 116 117 function widget( $args, $instance ) { 118 // If no URL, don't bother 119 $URL=$instance[cwidgetoption_lrhomtonair_xmlurl]; 120 if (empty($URL)) return; 121 122 extract($args); 123 $title = apply_filters('widget_title' 124 ,empty($instance['title']) ? $this->name : $instance['title'] 125 ,$instance 126 ,$this->id_base 90 $this->RegisterFieldHelp(cwidgetoption_lrhomtonair_ajaxload 91 ,__('Text shown while waiting for initial ajax response.',cwidgetbaseid_lrhomtonair)); 92 $this->RegisterFieldHelp(cwidgetoption_lrhomtonair_usediv 93 ,__('Do not use an unnumbered list in display text, use div instead.',cwidgetbaseid_lrhomtonair)); 94 $this->RegisterFieldHelp(cwidgetoption_lrhomtonair_cats 95 ,__('[optional] List categorys to show, comma separated.' 96 .' (Or, start list with a minus "-" to NOT show these categorys.)' 97 ,cwidgetbaseid_lrhomtonair) 127 98 ); 99 $this->RegisterFieldHelp(cwidgetoption_lrhomtonair_prevcount 100 ,__('Number of recently played cuts to show, normally none. ' 101 .' (Set to -1 to show one if nothing playing can be displayed)' 102 ,cwidgetbaseid_lrhomtonair) 103 ); 104 105 // Make sure jQuery is available 106 // already always included in WP 2.x ?? 107 wp_enqueue_script('jquery'); 108 109 // add in ajax handler in case we need it 110 add_action('wp_ajax_'.cwidgetajax_lrhomtonair_request,array($this,'ajaxhandler')); 111 add_action('wp_ajax_nopriv_'.cwidgetajax_lrhomtonair_request,array($this,'ajaxhandler')); 112 } 113 114 function widget( $args, $instance ) { 115 // If no URL, don't bother 116 $URL=$instance[cwidgetoption_lrhomtonair_xmlurl]; 117 if (empty($URL)) return; 118 119 extract($args); 120 $title = apply_filters('widget_title' 121 ,empty($instance['title']) ? $this->name : $instance['title'] 122 ,$instance 123 ,$this->id_base 124 ); 128 125 129 126 $useajax=('1'==$instance[cwidgetoption_lrhomtonair_useajax]); 130 $defpgm=$instance[cwidgetoption_lrhomtonair_defaultprogram];131 127 $footer=$instance[cwidgetoption_lrhomtonair_foot]; 132 128 $usediv=('1'==$instance[cwidgetoption_lrhomtonair_usediv]); 133 $showalbum=('1'==$instance[cwidgetoption_lrhomtonair_showalbum]);134 $cats=trim($instance[cwidgetoption_lrhomtonair_cats]);135 $prevcnt=intval($instance[cwidgetoption_lrhomtonair_prevcount]);136 129 137 130 if ($useajax) { … … 150 143 . ' url:"'.$jurl.'",'."\r\n" 151 144 . ' data:{action:"'.cwidgetajax_lrhomtonair_request.'"'."\r\n" 152 . ' ,'.cwidgetajax_lrhomtonair_request.':"'.cwidgetajax_lrhomtonair_request_update.'"'."\r\n"153 . ' ,'.cwidgetajax_lrhomtonair_url.':"'.$URL.'"'."\r\n"154 . ' ,'.cwidgetajax_lrhomtonair_defpgm.':"'.$defpgm.'"'."\r\n"155 . ' ,'.cwidgetoption_lrhomtonair_usediv.':"'.$usediv.'"'."\r\n"156 . ' ,'.cwidgetajax_lrhomtonair_showalbum.':"'.$showalbum.'"'."\r\n"157 . ' ,'.cwidgetajax_lrhomtonair_cats.':"'.$cats.'"'."\r\n"158 . ' ,'.cwidgetajax_lrhomtonair_prevcount.':"'.$prevcnt.'"'."\r\n"159 145 . ' ,'.cwidgetajax_lrhomtonair_nonce.':"'.$nonce.'"'."\r\n" 160 146 . ' },'."\r\n" … … 178 164 . '</script>'; 179 165 } else { 180 $show= lrhomtonair_GetDisplayText($URL,$defpgm,$showalbum,$cats,$prevcnt,$usediv);166 $show=$this->GetDisplayText(); 181 167 $script=''; 182 168 } 183 169 184 echo '<!-- '.cwidgetbaseid_lrhomtonair.' '.$this->GetPluginVersion(__FILE__).' -->';185 echo $before_widget;186 if ( $title )187 echo $before_title.$title.$after_title;188 if ($usediv) echo '<div';189 else echo '<ul';190 echo " id='{$widget_id}_onair' class='".cwidgetbaseid_lrhomtonair."_content'>$show</";191 if ($usediv) echo 'div>';192 else echo 'ul>';193 if ($footer) {194 echo (($usediv)?"<div":"<p")195 ." class='".cwidgetbaseid_lrhomtonair."_footer'>"196 .$footer.(($usediv)?'</div>':'</p>');197 }198 echo $after_widget;199 print $script;200 }201 202 function FormBeforeFields($aInstance)203 {204 parent::FormBeforeFields($aInstance);205 echo $this->form_info(206 __('Version',cwidgetbaseid_lrhomtonair)170 echo '<!-- '.cwidgetbaseid_lrhomtonair.' '.$this->GetPluginVersion(__FILE__).' -->'; 171 echo $before_widget; 172 if ( $title ) 173 echo $before_title.$title.$after_title; 174 if ($usediv) echo '<div'; 175 else echo '<ul'; 176 echo " id='{$widget_id}_onair' class='".cwidgetbaseid_lrhomtonair."_content'>$show</"; 177 if ($usediv) echo 'div>'; 178 else echo 'ul>'; 179 if ($footer) { 180 echo (($usediv)?"<div":"<p") 181 ." class='".cwidgetbaseid_lrhomtonair."_footer'>" 182 .$footer.(($usediv)?'</div>':'</p>'); 183 } 184 echo $after_widget; 185 print $script; 186 } 187 188 function FormBeforeFields($aInstance) 189 { 190 parent::FormBeforeFields($aInstance); 191 echo $this->form_info 192 (__('Version',cwidgetbaseid_lrhomtonair) 207 193 .': '.$this->GetPluginVersion(__FILE__) 208 ); 209 } 210 211 }//class 212 213 214 // To support the AJAX calls, these need to be OUTSIDE of the widget class 215 function lrhomtonair_GetOnAirData($aUrl,$aCats) { 194 ); 195 } 196 197 function ajaxhandler() 198 { 199 check_ajax_referer(cwidgetbaseid_lrhomtonair,cwidgetajax_lrhomtonair_nonce); 200 echo $this->GetDisplayText(); 201 die(); 202 } 203 204 function GetOnAirData($aUrl,$aCats) 205 { 216 206 //echo "|$aUrl|<br>|$aCats|<br>"; 217 207 if ('file://'==substr($aUrl,0,7)) { … … 219 209 if (file_exists($aUrl)) { 220 210 $content=file_get_contents($aUrl); 221 if ($content=='') return lrhomtonair_DataError('File:no content'); //nothing211 if ($content=='') return $this->DataError('File:no content'); //nothing 222 212 } else { 223 return lrhomtonair_DataError('File:not found'); //nothing213 return $this->DataError('File:not found'); //nothing 224 214 } 225 215 } else { … … 227 217 if ('http://'!=substr($aUrl,0,7)) $aUrl='http://'.$aUrl; 228 218 $content=wp_remote_retrieve_body(wp_remote_get($aUrl)); 229 if ($content=='') return lrhomtonair_DataError('Http:no content'); //nothing219 if ($content=='') return $this->DataError('Http:no content'); //nothing 230 220 } 231 221 //convert xml to data array … … 233 223 @$x=new SimpleXMLElement($content); 234 224 } catch (Exception $e) { 235 return lrhomtonair_DataError('XML error:'.$e->getMessage(),$content); //trouble225 return $this->DataError('XML error:'.$e->getMessage(),$content); //trouble 236 226 } 237 227 … … 288 278 } 289 279 290 function lrhomtonair_DataError($aMsg,$aMsg2='') { 280 function DataError($aMsg,$aMsg2='') 281 { 291 282 if (WP_DEBUG) { 292 283 //for debugging … … 300 291 } 301 292 302 function lrhomtonair_FormatItem(array $aItem,$aShowAlbum,$aUseDiv)293 function FormatItem(array $aItem,$aShowAlbum,$aUseDiv) 303 294 { 304 295 $show=''; … … 310 301 } 311 302 312 function lrhomtonair_GetDisplayText($aUrl,$aDefaultProgram,$aShowAlbum,$aCats,$aPrevCnt,$aUseDiv) { 313 $ONAIR=lrhomtonair_GetOnAirData($aUrl,$aCats); 303 function GetDisplayText() 304 { 305 $a=$this->get_settings(); 306 $s=$a[$this->number]; 307 $aUrl =$s[cwidgetoption_lrhomtonair_xmlurl]; 308 $aDefaultProgram =$s[cwidgetoption_lrhwumdonair_defaultprogram]; 309 $aShowAlbum =('1'==$s[cwidgetoption_lrhomtonair_showalbum]); 310 $aCats =trim($s[cwidgetoption_lrhomtonair_cats]); 311 $aPrevCnt =intval($s[cwidgetoption_lrhomtonair_prevcount]); 312 $aUseDiv =('1'==$s[cwidgetoption_lrhomtonair_usediv]); 313 314 $ONAIR=$this->GetOnAirData($aUrl,$aCats); 314 315 $pc=count($ONAIR['prev']); 315 316 //echo "<pre>|$aUrl|$aDefaultProgram|$aShowAlbum|$aPrevCnt|$aUseDiv|$aCats|$pc|\r\n</pre>"; 316 317 //echo "<pre>ONAIR DATA:\r\n"; print_r($ONAIR); echo "</pre>"; 317 318 if (isset($ONAIR['now'][0])) { 318 $show= lrhomtonair_FormatItem($ONAIR['now'][0],$aShowAlbum,$aUseDiv);319 $show=$this->FormatItem($ONAIR['now'][0],$aShowAlbum,$aUseDiv); 319 320 } else { 320 321 if ( (0==$aPrevCnt) || (0==$pc) ) { 321 322 $show=$aDefaultProgram; 322 323 if (empty($show)) $show=cwidgetoption_lrhomtonair_defaultprogram_value; 323 $show= lrhomtonair_FormatItem(array('Title'=>$show),$aShowAlbum,$aUseDiv);324 $show=$this->FormatItem(array('Title'=>$show),$aShowAlbum,$aUseDiv); 324 325 } else if (-1==$pc) { 325 326 reset($ONAIR['prev']); 326 $show= lrhomtonair_FormatItem(current($ONAIR['prev']),$aShowAlbum,$aUseDiv);327 $show=$this->FormatItem(current($ONAIR['prev']),$aShowAlbum,$aUseDiv); 327 328 } 328 329 } … … 330 331 $cnt=$aPrevCnt; 331 332 foreach($ONAIR['prev'] as $item) { 332 $show.= lrhomtonair_FormatItem($item,$aShowAlbum,$aUseDiv);333 $show.=$this->FormatItem($item,$aShowAlbum,$aUseDiv); 333 334 if (0==--$cnt) break; 334 335 } … … 338 339 } 339 340 340 function lrhomtonair_ajaxhandler() { 341 if (WP_DEBUG) error_log('loo handler'); 342 if (!empty($_POST[cwidgetajax_lrhomtonair_request])) { 343 //check_ajax_referer does not return if check fails 344 check_ajax_referer(cwidgetbaseid_lrhomtonair,cwidgetajax_lrhomtonair_nonce); 345 $REQ=strip_tags($_POST[cwidgetajax_lrhomtonair_request]); 346 if ($REQ==cwidgetajax_lrhomtonair_request_update) { 347 $URL=strip_tags($_POST[cwidgetajax_lrhomtonair_url]); 348 $DEFPGM=strip_tags($_POST[cwidgetajax_lrhomtonair_defpgm]); 349 $USEDIV='1'==strip_tags($_POST[cwidgetajax_lrhomtonair_usediv]); 350 $SHOWALBUM='1'==strip_tags($_POST[cwidgetajax_lrhomtonair_showalbum]); 351 $CATS=strip_tags($_POST[cwidgetajax_lrhomtonair_cats]); 352 $PRVCNT=intval(strip_tags($_POST[cwidgetajax_lrhomtonair_prevcount])); 353 echo lrhomtonair_GetDisplayText($URL,$DEFPGM,$SHOWALBUM,$CATS,$PRVCNT,$USEDIV); 354 die(); 355 } 356 } 357 echo "Trouble in<br>AJAX<br>land."; 358 } 341 }//class 342 359 343 360 344 add_action('widgets_init' 361 345 ,create_function('','return register_widget("lrh_widget_omtonair");') 362 346 ); 363 add_action('wp_ajax_'.cwidgetajax_lrhomtonair_request,'lrhomtonair_ajaxhandler');364 add_action('wp_ajax_nopriv_'.cwidgetajax_lrhomtonair_request,'lrhomtonair_ajaxhandler');365 347 366 348 ?>
Note: See TracChangeset
for help on using the changeset viewer.