PageRenderTime 71ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/wordpress/wp-content/plugins/podpress/podpress_functions.php

https://github.com/bill742/verbalbrew
PHP | 2410 lines | 2126 code | 116 blank | 168 comment | 676 complexity | b73ad71bac4e0823eef4e97fe15551ce MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-3.0, AGPL-1.0, LGPL-2.1, GPL-2.0
  1. <?php
  2. /*
  3. License:
  4. ==============================================================================
  5. Copyright 2006 Dan Kuykendall (email : dan@kuykendall.org)
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  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. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-107 USA
  17. */
  18. if(!function_exists('getmicrotime')) {
  19. function getmicrotime() {
  20. list($usec, $sec) = explode(" ",microtime());
  21. return ((float)$usec + (float)$sec);
  22. }
  23. }
  24. function podPress_WPVersionCheck($input = '2.0.0') {
  25. GLOBAL $wp_version;
  26. if ( substr($wp_version, 0, 12) == 'wordpress-mu' ) {
  27. return true;
  28. }
  29. return ( (float) $input <= (float) $wp_version );
  30. }
  31. function podPress_iTunesLink() {
  32. GLOBAL $podPress;
  33. echo $podPress->iTunesLink();
  34. }
  35. function podPress_siteurl($noDomain = false) {
  36. if (!defined('PODPRESSSITEURL') || $noDomain) {
  37. $result = '';
  38. $urlparts = parse_url(get_option('siteurl'));
  39. if(!$noDomain) {
  40. if(empty($urlparts['scheme'])) {
  41. $urlparts['scheme'] = 'http';
  42. }
  43. $result .= $urlparts['scheme'].'://'.$_SERVER['HTTP_HOST'];
  44. if($urlparts['port'] != '' && $urlparts['port'] != '80') {
  45. $result .= ':'.$urlparts['port'];
  46. }
  47. }
  48. if(isset($urlparts['path'])) {
  49. $result .= $urlparts['path'];
  50. }
  51. if(substr($result, -1, 1) != '/') {
  52. $result .= '/';
  53. }
  54. if( TRUE == isset($urlparts['query']) AND '' != $urlparts['query'] ) {
  55. $result .= '?'.$urlparts['query'];
  56. }
  57. if( TRUE == isset($urlparts['fragment']) AND '' != $urlparts['fragment']) {
  58. $result .= '#'.$urlparts['fragment'];
  59. }
  60. if($noDomain) {
  61. return $result.'wp-content/plugins/';
  62. }
  63. define('PODPRESSSITEURL', $result.'wp-content/plugins/');
  64. }
  65. return PODPRESSSITEURL;
  66. }
  67. function podPress_url($noDomain = false) {
  68. if($noDomain) {
  69. if (!defined('PODPRESSURL')) {
  70. define('PODPRESSURL', podPress_siteurl($noDomain).'podpress/');
  71. }
  72. return PODPRESSURL;
  73. } else {
  74. //~ $result = get_option('siteurl');
  75. //~ if(substr($result, -1, 1) != '/') {
  76. //~ $result .= '/';
  77. //~ }
  78. //~ return $result.'wp-content/plugins/podpress/';
  79. return PODPRESS_URL.'/';
  80. }
  81. }
  82. function podPress_getFileExt($str)
  83. {
  84. $pos = strrpos($str, '.');
  85. $pos = $pos+1;
  86. return substr(strtolower($str), $pos);
  87. }
  88. function podPress_getFileName($str)
  89. {
  90. if(strrpos($str, '/')) {
  91. $pos = strrpos($str, '/');
  92. $pos = $pos+1;
  93. return substr($str, $pos);
  94. } elseif(strrpos($str, ':')) {
  95. $pos = strrpos($str, ':');
  96. $pos = $pos+1;
  97. return substr($str, $pos);
  98. } else {
  99. return $str;
  100. }
  101. }
  102. function podPress_wordspaceing($txt, $number = 5, $paddingchar = ' ') {
  103. $txt_array = array();
  104. $len = strlen($txt);
  105. $count=$len/$number;
  106. $i=0;
  107. while($i<=$count) {
  108. if($i==0) {$ib=0;} else {$ib=($i*$number)+1;}
  109. $txt_array[$i]=substr($txt, $ib, $number);
  110. $i++;
  111. }
  112. $i=0;
  113. $count_array=count($txt_array)-1;
  114. while ($i<=$count_array) {
  115. if ($i==0) {$txt=$txt_array[$i].$paddingchar;} else {$txt.=''.$txt_array[$i].' ';}
  116. $i++;
  117. }
  118. return $txt;
  119. }
  120. function podPress_stringLimiter($str, $len, $snipMiddle = false)
  121. {
  122. if (strlen($str) > $len) {
  123. if ( function_exists('mb_substr') ) {
  124. if($snipMiddle) {
  125. $startlen = $len / 3;
  126. $startlen = $startlen - 1;
  127. $endlen = $startlen * 2;
  128. $endlen = $endlen - $endlen - $endlen;
  129. return mb_substr($str, 0, $startlen).'...'.mb_substr($str, $endlen);
  130. } else {
  131. $len = $len - 3;
  132. return mb_substr($str, 0, $len).'...';
  133. }
  134. } else {
  135. if ($snipMiddle) {
  136. $startlen = $len / 3;
  137. $startlen = $startlen - 1;
  138. $endlen = $startlen * 2;
  139. $endlen = $endlen - $endlen - $endlen;
  140. return substr($str, 0, $startlen).'...'.substr($str, $endlen);
  141. } else {
  142. $len = $len - 3;
  143. return substr($str, 0, $len).'...';
  144. }
  145. }
  146. } else {
  147. return $str;
  148. }
  149. }
  150. /**
  151. * podPress_strlimiter2 - if the input phrase is longer then maxlength then cut out character from the middle of the phrase
  152. *
  153. * @package podPress
  154. * @since 8.8.5 beta 3
  155. *
  156. * @param str $phrase input string
  157. * @param int $maxlength [optional] - max. length of the output string
  158. * @param bool $abbrev [optional] - use the abbr-tag with the original string as the title element
  159. * @param str $paddingchar [optional] - character(s) which should symbolize the shortend string / placed in the middle of the shortend string
  160. * @param str $classname [optional] - name(s) of the CSS class(es) of the abbr-tag
  161. *
  162. * @return str phrase with max. length
  163. */
  164. function podPress_strlimiter2($phrase, $maxlength = 25, $abbrev = FALSE, $paddingchar = ' ... ', $classname = 'podpress_abbr') {
  165. $len = strlen($phrase);
  166. $maxlen = ($maxlength-strlen($paddingchar));
  167. if ( $len > $maxlen ) {
  168. $part1_len = floor($maxlen/2);
  169. $part1 = substr($phrase, 0, $part1_len);
  170. $part2_len = ceil($maxlen/2);
  171. $part2 = substr($phrase, -$part2_len, $len);
  172. if ($abbrev == TRUE) {
  173. if ( Trim($classname) != '' ) {
  174. return '<span class="'.$classname.'" title="'.attribute_escape(str_replace('"', '\'', $phrase)).'">' . $part1 . $paddingchar . $part2 . '</span>';
  175. } else {
  176. return '<span title="'.attribute_escape(str_replace('"', '\'', $phrase)).'">' . $part1 . $paddingchar . $part2 . '</span>';
  177. }
  178. } else {
  179. return $part1 . $paddingchar. $part2;
  180. }
  181. } else {
  182. return $phrase;
  183. }
  184. }
  185. /**
  186. * podPress_strlimiter_end - if the input phrase is longer then maxlength then cut characters from the end of the phrase
  187. *
  188. * @package podPress
  189. * @since 8.8.10.8
  190. *
  191. * @param str $phrase input string
  192. * @param int $maxlength [optional] - max. length of the output string
  193. * @param str $paddingchar [optional] - character(s) which should symbolize the shortend string / placed in the middle of the shortend string
  194. * @param bool $respecthtmlentities [optional] - if TRUE then the function will not cut htmlentities in half. It will cut before and after the entity.
  195. * @param bool $abbrev [optional] - use the abbr-tag with the original string as the title element
  196. * @param str $classname [optional] - name(s) of the CSS class(es) of the abbr-tag
  197. *
  198. * @return str phrase with max. length
  199. */
  200. function podPress_strlimiter_end($phrase, $maxlength = 25, $paddingchar = ' ... ', $respecthtmlentities = FALSE, $abbrev = FALSE, $classname = 'podpress_abbr', $charset = 'UTF-8') {
  201. $len = strlen($phrase);
  202. $maxlen = ($maxlength-strlen($paddingchar));
  203. if ( $len > $maxlen ) {
  204. if ( function_exists('mb_substr') AND function_exists('mb_strrpos') ) {
  205. $short_phrase = mb_substr($phrase, 0, $maxlen);
  206. if ( TRUE === $respecthtmlentities ) {
  207. $short_phrase_end = mb_substr($short_phrase, -10);
  208. $ampersandpos = mb_strrpos($short_phrase_end, '&');
  209. if ( FALSE !== $ampersandpos ) {
  210. // if there is an ampersand among the last characters then it might be an entity
  211. $semicolonpos = mb_strrpos($short_phrase_end, ';');
  212. if ( FALSE === $semicolonpos OR $semicolonpos < $ampersandpos ) {
  213. // if no semicolon is following the ampersand OR if the position of the semicolon is smaller than (before the) position of the ampersand then it is most likely an entity which was cut off
  214. // cut the string before the entity
  215. $short_phrase = mb_substr($phrase, 0, ($maxlen - 10 + $ampersandpos));
  216. }
  217. }
  218. }
  219. } else {
  220. $short_phrase = substr($phrase, 0, $maxlen);
  221. if ( TRUE === $respecthtmlentities ) {
  222. $short_phrase_end = substr($short_phrase, -10);
  223. $ampersandpos = strrpos($short_phrase_end, '&');
  224. if ( FALSE !== $ampersandpos ) {
  225. // if there is an ampersand among the last characters then it might be an entity
  226. $semicolonpos = strrpos($short_phrase_end, ';');
  227. if ( FALSE === $semicolonpos OR $semicolonpos < $ampersandpos ) {
  228. // if no semicolon is following the ampersand OR if the position of the semicolon is smaller than (before the) position of the ampersand then it is most likely an entity which was cut off
  229. // cut the string before the entity
  230. $short_phrase = substr($phrase, 0, ($maxlen - 10 + $ampersandpos));
  231. }
  232. }
  233. }
  234. }
  235. if ($abbrev == TRUE) {
  236. if ( Trim($classname) != '' ) {
  237. return '<span class="'.$classname.'" title="'.attribute_escape(str_replace('"', '\'', $phrase)).'">' . $short_phrase . $paddingchar . '</span>';
  238. } else {
  239. return '<span title="'.attribute_escape(str_replace('"', '\'', $phrase)).'">' . $short_phrase . $paddingchar . '</span>';
  240. }
  241. } else {
  242. return $short_phrase . $paddingchar;
  243. }
  244. } else {
  245. return $phrase;
  246. }
  247. }
  248. /**
  249. * podPress_strlimiter_middle - if the input phrase is longer then maxlength then cut characters from the center of the phrase
  250. *
  251. * @package podPress
  252. * @since 8.8.10.8
  253. *
  254. * @param str $phrase input string
  255. * @param int $maxlength [optional] - max. length of the output string
  256. * @param str $paddingchar [optional] - character(s) which should symbolize the shortend string / placed in the middle of the shortend string
  257. * @param bool $respecthtmlentities [optional] - if TRUE then the function will not cut htmlentities in half. It will cut before and after the entity.
  258. * @param bool $abbrev [optional] - use the abbr-tag with the original string as the title element
  259. * @param str $classname [optional] - name(s) of the CSS class(es) of the abbr-tag
  260. *
  261. * @return str phrase with max. length
  262. */
  263. function podPress_strlimiter_middle($phrase, $maxlength = 25, $paddingchar = ' ... ', $respecthtmlentities = FALSE, $abbrev = FALSE, $classname = 'podpress_abbr') {
  264. $len = strlen($phrase);
  265. $paddinglen = strlen($paddingchar);
  266. $maxlen = ($maxlength-$paddinglen);
  267. if ( $len > $maxlen ) {
  268. if ( function_exists('mb_substr') AND function_exists('mb_strrpos') AND function_exists('mb_strpos') ) {
  269. $part1_len = floor($maxlen/2);
  270. $part1 = mb_substr($phrase, 0, $part1_len);
  271. $part2_len = ceil($maxlen/2);
  272. $part2 = mb_substr($phrase, -$part2_len, $len);
  273. if ( TRUE === $respecthtmlentities ) {
  274. $part1_end = mb_substr($part1, -10);
  275. $ampersandpos_part1 = mb_strrpos($part1_end, '&');
  276. if ( FALSE !== $ampersandpos_part1 ) {
  277. // if there is an ampersand among the last characters of part1 then it might be an entity
  278. $semicolonpos_part1 = mb_strrpos($part1_end, ';');
  279. if ( FALSE === $semicolonpos_part1 OR $semicolonpos_part1 < $ampersandpos_part1 ) {
  280. // if no semicolon is following the ampersand then it is most likely an entity which was cut off
  281. // cut the 1. part phrase before the entity
  282. $part1 = mb_substr($part1, 0, ($part1_len - 10 + $ampersandpos_part1));
  283. }
  284. }
  285. $part2_start = mb_substr($part2, 0, 10);
  286. $semicolonpos_part2 = mb_strpos($part2_start, ';');
  287. if ( FALSE !== $semicolonpos_part2 ) {
  288. // if there is a semicolon among the first characters of part2 then check whether there is an ampersand before that semicolon
  289. $ampersandpos_part2 = mb_strrpos($part2_start, '&');
  290. if ( FALSE === $ampersandpos_part2 OR $ampersandpos_part2 > $semicolonpos_part2 ) {
  291. // if there is no ampersand among the first characters of part2 which comes before the semicolon then look for it in the 10 characters before the semicolon
  292. $part2_long_start = mb_substr($phrase, (-$part2_len+$semicolonpos_part2-10), 10); // a certain number of characters before the semicolon (this might include characters from part1 depending on the $paddinglen)
  293. $ampersandpos_part2_long = mb_strrpos($part2_long_start, '&');
  294. $semicolonpos_part2_long = mb_strrpos($part2_long_start, ';');
  295. if ( (FALSE !== $ampersandpos_part2_long AND FALSE === $semicolonpos_part2_long) OR (FALSE !== $ampersandpos_part2_long AND FALSE !== $semicolonpos_part2_long AND $semicolonpos_part2_long < $ampersandpos_part2_long) ) {
  296. // if there is an ampersand and no further semicolon OR if there is an ampersand and further semicolon which comes before the ampersand then this semicolon is most likely a semicolon of an entity
  297. // cut the 2. part phrase after the semicolon
  298. $part2 = mb_substr($part2, (-$part2_len+$semicolonpos_part2+1), $len);
  299. }
  300. }
  301. }
  302. }
  303. } else {
  304. $part1_len = floor($maxlen/2);
  305. $part1 = substr($phrase, 0, $part1_len);
  306. $part2_len = ceil($maxlen/2);
  307. $part2 = substr($phrase, -$part2_len, $len);
  308. if ( TRUE === $respecthtmlentities ) {
  309. $part1_end = substr($part1, -10);
  310. $ampersandpos_part1 = strrpos($part1_end, '&');
  311. if ( FALSE !== $ampersandpos_part1 ) {
  312. // if there is an ampersand among the last characters of part1 then it might be an entity
  313. $semicolonpos_part1 = strrpos($part1_end, ';');
  314. if ( FALSE === $semicolonpos_part1 OR $semicolonpos_part1 < $ampersandpos_part1 ) {
  315. // if no semicolon is following the ampersand then it is most likely an entity which was cut off
  316. // cut the 1. part phrase before the entity
  317. $part1 = substr($part1, 0, ($part1_len - 10 + $ampersandpos_part1));
  318. }
  319. }
  320. $part2_start = substr($part2, 0, 10);
  321. $semicolonpos_part2 = strpos($part2_start, ';');
  322. if ( FALSE !== $semicolonpos_part2 ) {
  323. // if there is a semicolon among the first characters of part2 then check whether there is an ampersand before that semicolon
  324. $ampersandpos_part2 = strrpos($part2_start, '&');
  325. if ( FALSE === $ampersandpos_part2 OR $ampersandpos_part2 > $semicolonpos_part2 ) {
  326. // if there is no ampersand among the first characters of part2 which comes before the semicolon then look for it in the 10 characters before the semicolon
  327. $part2_long_start = substr($phrase, (-$part2_len+$semicolonpos_part2-10), 10); // a certain number of characters before the semicolon (this might include characters from part1 depending on the $paddinglen)
  328. $ampersandpos_part2_long = strrpos($part2_long_start, '&');
  329. $semicolonpos_part2_long = strrpos($part2_long_start, ';');
  330. if ( (FALSE !== $ampersandpos_part2_long AND FALSE === $semicolonpos_part2_long) OR (FALSE !== $ampersandpos_part2_long AND FALSE !== $semicolonpos_part2_long AND $semicolonpos_part2_long < $ampersandpos_part2_long) ) {
  331. // if there is an ampersand and no further semicolon OR if there is an ampersand and further semicolon which comes before the ampersand then this semicolon is most likely a semicolon of an entity
  332. // cut the 2. part phrase after the semicolon
  333. $part2 = substr($part2, (-$part2_len+$semicolonpos_part2+1), $len);
  334. }
  335. }
  336. }
  337. }
  338. }
  339. if ($abbrev == TRUE) {
  340. if ( Trim($classname) != '' ) {
  341. return '<span class="'.$classname.'" title="'.attribute_escape(str_replace('"', '\'', $phrase)).'">' . $part1 . $paddingchar . $part2 . '</span>';
  342. } else {
  343. return '<span title="'.attribute_escape(str_replace('"', '\'', $phrase)).'">' . $part1 . $paddingchar . $part2 . '</span>';
  344. }
  345. } else {
  346. return $part1 . $paddingchar. $part2;
  347. }
  348. } else {
  349. return $phrase;
  350. }
  351. }
  352. if(!function_exists('html_print_r')) {
  353. function html_print_r($v, $n = '', $ret = false) {
  354. if($ret) {
  355. ob_start();
  356. }
  357. echo $n.'<pre>';
  358. print_r($v);
  359. echo '</pre>';
  360. if($ret) {
  361. $result = ob_get_contents();
  362. ob_end_clean();
  363. return $result;
  364. }
  365. }
  366. }
  367. if(!function_exists('comment_print_r')) {
  368. function comment_print_r($v, $n = '', $ret = false) {
  369. $result = "<!-- \n";
  370. $result .= html_print_r($v, $n, true);
  371. $result .= " -->\n";
  372. if($ret) {
  373. return $result;
  374. }
  375. echo $result;
  376. }
  377. }
  378. if(!function_exists('maybe_unserialize')) {
  379. function maybe_unserialize($original, $ss = false) {
  380. if($ss) {
  381. $original = stripslashes($original);
  382. }
  383. if ( false !== $gm = @ unserialize($original) ) {
  384. return $gm;
  385. } else {
  386. return $original;
  387. }
  388. }
  389. }
  390. if(!function_exists('isBase64')) {
  391. function isBase64($str)
  392. {
  393. $_tmp=preg_replace("/[^A-Z0-9\+\/\=]/i",'',$str);
  394. return (strlen($_tmp) % 4 == 0 ) ? true : false;
  395. }
  396. }
  397. function podPress_mimetypes($ext, $mp4_type = 'audio') {
  398. $ext = strtolower($ext);
  399. $ext_list = array (
  400. 'jpg' => 'image/jpeg',
  401. 'jpeg' => 'image/jpeg',
  402. 'jpe' => 'image/jpeg',
  403. 'gif' => 'image/gif',
  404. 'png' => 'image/png',
  405. 'bmp' => 'image/bmp',
  406. 'tif' => 'image/tiff',
  407. 'tiff' => 'image/tiff',
  408. 'ico' => 'image/x-icon',
  409. 'flv' => 'video/flv',
  410. 'asf' => 'video/asf',
  411. 'wmv' => 'video/wmv',
  412. 'asx' => 'video/asf',
  413. 'wax' => 'video/asf',
  414. 'wmx' => 'video/asf',
  415. 'avi' => 'video/avi',
  416. 'qt' => 'video/quicktime',
  417. 'mov' => 'video/quicktime',
  418. 'm4v' => 'video/x-m4v',
  419. 'mpeg' => 'video/mpeg',
  420. 'mpg' => 'video/mpeg',
  421. 'mpe' => 'video/mpeg',
  422. 'txt' => 'text/plain',
  423. 'c' => 'text/plain',
  424. 'cc' => 'text/plain',
  425. 'h' => 'text/plain',
  426. 'rtx' => 'text/richtext',
  427. 'css' => 'text/css',
  428. 'htm' => 'text/html',
  429. 'html' => 'text/html',
  430. 'mp3' => 'audio/mpeg',
  431. 'mp4' => $mp4_type.'/mpeg',
  432. 'm4a' => 'audio/x-m4a',
  433. 'aa' => 'audio/audible',
  434. 'ra' => 'audio/x-realaudio',
  435. 'ram' => 'audio/x-realaudio',
  436. 'wav' => 'audio/wav',
  437. 'ogg' => 'audio/ogg',
  438. 'ogv' => 'video/ogg',
  439. 'mid' => 'audio/midi',
  440. 'midi' => 'audio/midi',
  441. 'wma' => 'audio/wma',
  442. 'rtf' => 'application/rtf',
  443. 'js' => 'application/javascript',
  444. 'pdf' => 'application/pdf',
  445. 'epub' => 'document/x-epub',
  446. 'doc' => 'application/msword',
  447. 'pot' => 'application/vnd.ms-powerpoint',
  448. 'pps' => 'application/vnd.ms-powerpoint',
  449. 'ppt' => 'application/vnd.ms-powerpoint',
  450. 'wri' => 'application/vnd.ms-write',
  451. 'xla' => 'application/vnd.ms-excel',
  452. 'xls' => 'application/vnd.ms-excel',
  453. 'xlt' => 'application/vnd.ms-excel',
  454. 'xlw' => 'application/vnd.ms-excel',
  455. 'mdb' => 'application/vnd.ms-access',
  456. 'mpp' => 'application/vnd.ms-project',
  457. 'swf' => 'application/x-shockwave-flash',
  458. 'class' => 'application/java',
  459. 'tar' => 'application/x-tar',
  460. 'zip' => 'application/zip',
  461. 'gz' => 'application/x-gzip',
  462. 'gzip' => 'application/x-gzip',
  463. 'torrent' => 'application/x-bittorrent',
  464. 'exe' => 'application/x-msdownload'
  465. );
  466. if(!isset($ext_list[$ext])) {
  467. return 'application/unknown';
  468. }
  469. return $ext_list[$ext];
  470. }
  471. function podPress_maxMemory() {
  472. $max = ini_get('memory_limit');
  473. if (preg_match('/^([\d\.]+)([gmk])?$/i', $max, $m)) {
  474. $value = $m[1];
  475. if (isset($m[2])) {
  476. switch(strtolower($m[2])) {
  477. case 'g': $value *= 1024; # fallthrough
  478. case 'm': $value *= 1024; # fallthrough
  479. case 'k': $value *= 1024; break;
  480. default: $value = 2048000;
  481. }
  482. }
  483. $max = $value;
  484. } else {
  485. $max = 2048000;
  486. }
  487. return $max/2;
  488. }
  489. /**************************************************************/
  490. /* Functions for supporting the widgets */
  491. /**************************************************************/
  492. /* for WP < 2.8 only */
  493. function podPress_loadWidgets () {
  494. global $wp_version;
  495. if ( !function_exists('register_sidebar_widget') || !function_exists('register_widget_control') ) {
  496. return;
  497. }
  498. if (TRUE == version_compare($wp_version, '2.2', '>=')) {
  499. // Feed Buttons widget
  500. $widget_ops = array(
  501. 'classname' => 'podpress_feedbuttons',
  502. 'description' => __('Shows buttons for the podcast feeds in the sidebar', 'podpress')
  503. );
  504. $control_ops = array('width' => 400, 'height' => 700, 'id_base' => 'podpressfeedbuttons');
  505. $id = $control_ops['id_base'];
  506. wp_register_sidebar_widget($id, __('podPress - Feed Buttons','podpress'), 'podPress_feedButtons', $widget_ops);
  507. wp_register_widget_control($id, __('podPress - Feed Buttons','podpress'), 'podPress_feedButtons_control', $control_ops);
  508. // XSPF Player widget
  509. $widget_ops = array(
  510. 'classname' => 'podpress_xspfplayer',
  511. 'description' => __('Shows a XSPF Player in the sidebar which uses e.g. the XSPF playlist of your podcast episodes', 'podpress')
  512. );
  513. $control_ops = array('width' => 400, 'height' => 400, 'id_base' => 'podpressxspfplayer');
  514. $id = $control_ops['id_base'];
  515. wp_register_sidebar_widget($id, __('podPress - XSPF Player','podpress'), 'podPress_xspfPlayer', $widget_ops);
  516. wp_register_widget_control($id, __('podPress - XSPF Player','podpress'), 'podPress_xspfPlayer_control', $control_ops);
  517. } else {
  518. // Feed Buttons widget
  519. register_sidebar_widget(array('podPress - Feed Buttons', 'widgets'), 'podPress_feedButtons', $widget_ops);
  520. register_widget_control(array('podPress - Feed Buttons', 'widgets'), 'podPress_feedButtons_control', 400, 700);
  521. // XSPF Player widget
  522. register_sidebar_widget(array('podPress - XSPF Player', 'widgets'), 'podPress_xspfPlayer');
  523. register_widget_control(array('podPress - XSPF Player', 'widgets'), 'podPress_xspfPlayer_control', 400, 400);
  524. }
  525. }
  526. /* for WP < 2.8 only */
  527. function podPress_feedButtons_control() {
  528. GLOBAL $podPress, $wp_version, $wpdb;
  529. $options = get_option('widget_podPressFeedButtons');
  530. $newoptions = $options;
  531. if ( isset($_POST['podPressFeedButtons-submit']) ) {
  532. $newoptions['blog'] = isset($_POST['podPressFeedButtons-posts']);
  533. $newoptions['comments'] = isset($_POST['podPressFeedButtons-comments']);
  534. $newoptions['entries-atom'] = isset($_POST['podPressFeedButtons-entries-atom']);
  535. $newoptions['comments-atom'] = isset($_POST['podPressFeedButtons-comments-atom']);
  536. $newoptions['posts_buttonurl'] = clean_url($_POST['podPressFeedButtons-posts_buttonurl'], array('http', 'https'), 'db');
  537. $newoptions['comments_buttonurl'] = clean_url($_POST['podPressFeedButtons-comments_buttonurl'], array('http', 'https'), 'db');
  538. $newoptions['entries-atom_buttonurl'] = clean_url($_POST['podPressFeedButtons-entries-atom_buttonurl'], array('http', 'https'), 'db');
  539. $newoptions['comments-atom_buttonurl'] = clean_url($_POST['podPressFeedButtons-comments-atom_buttonurl'], array('http', 'https'), 'db');
  540. $newoptions['posts_altfeedurl'] = clean_url($_POST['podPressFeedButtons-posts_altfeedurl'], array('http', 'https'), 'db');
  541. $newoptions['comments_altfeedurl'] = clean_url($_POST['podPressFeedButtons-comments_altfeedurl'], array('http', 'https'), 'db');
  542. $newoptions['entries-atom_altfeedurl'] = clean_url($_POST['podPressFeedButtons-entries-atom_altfeedurl'], array('http', 'https'), 'db');
  543. $newoptions['comments-atom_altfeedurl'] = clean_url($_POST['podPressFeedButtons-comments-atom_altfeedurl'], array('http', 'https'), 'db');
  544. $newoptions['itunes'] = isset($_POST['podPressFeedButtons-itunes']);
  545. $newoptions['itunes_buttonurl'] = clean_url($_POST['podPressFeedButtons-itunes_buttonurl'], array('http', 'https'), 'db');
  546. // iscifi new option for itunes protocol
  547. $newoptions['iprot'] = isset($_POST['podPressItunesProtocol-iprot']);
  548. $blog_charset = get_bloginfo('charset');
  549. $newoptions['title'] = htmlspecialchars(strip_tags(trim($_POST['podPressFeedButtons-title'])), ENT_QUOTES, $blog_charset);
  550. $newoptions['buttons-or-text'] = $_POST['podPressFeedButtons-buttons-or-text'];
  551. // CategoryCasting Feeds:
  552. if ( is_array($_POST['podPressFeedButtons-catcast']) ) {
  553. foreach ( $_POST['podPressFeedButtons-catcast'] as $cat_id => $feed_options ) {
  554. if ( 'yes' === $feed_options['use'] ) {
  555. $newoptions['catcast'][$cat_id]['use'] = 'yes';
  556. } else {
  557. $newoptions['catcast'][$cat_id]['use'] = 'no';
  558. }
  559. $newoptions['catcast'][$cat_id]['buttonurl'] = clean_url($feed_options['buttonurl'], array('http', 'https'), 'db');
  560. $newoptions['catcast'][$cat_id]['altfeedurl'] = clean_url($feed_options['altfeedurl'], array('http', 'https'), 'db');
  561. }
  562. }
  563. // podPress Feeds:
  564. if ( is_array($_POST['podpressfeeds']) ) {
  565. foreach ( $_POST['podpressfeeds'] as $feed_slug => $feed_options ) {
  566. if ( 'yes' === $feed_options['use'] ) {
  567. $newoptions['podpressfeeds'][$feed_slug]['use'] = 'yes';
  568. } else {
  569. $newoptions['podpressfeeds'][$feed_slug]['use'] = 'no';
  570. }
  571. $newoptions['podpressfeeds'][$feed_slug]['button'] = $feed_options['button'];
  572. if ( 'custom' === $feed_options['button'] ) {
  573. $newoptions['podpressfeeds'][$feed_slug]['buttonurl'] = clean_url($feed_options['buttonurl'], array('http', 'https'), 'db');
  574. } else {
  575. $newoptions['podpressfeeds'][$feed_slug]['buttonurl'] = PODPRESS_URL.'/images/'.$feed_options['button'];
  576. }
  577. $newoptions['podpressfeeds'][$feed_slug]['altfeedurl'] = clean_url($feed_options['altfeedurl'], array('http', 'https'), 'db');
  578. }
  579. }
  580. }
  581. if ( $options != $newoptions ) {
  582. $options = $newoptions;
  583. update_option('widget_podPressFeedButtons', $options);
  584. }
  585. if(!isset($options['blog'])) {
  586. $options['blog'] = false;
  587. }
  588. if(!isset($options['comments'])) {
  589. $options['comments'] = false;
  590. }
  591. if(!isset($options['entries-atom'])) {
  592. $options['entries-atom'] = false;
  593. }
  594. if(!isset($options['comments-atom'])) {
  595. $options['comments-atom'] = false;
  596. }
  597. if(!isset($options['itunes'])) {
  598. $options['itunes'] = false;
  599. }
  600. if (!isset($options['iprot'])) {
  601. $options['iprot'] = false;
  602. }
  603. if (!isset($options['buttons-or-text'])) {
  604. $options['buttons-or-text'] = 'buttons';
  605. }
  606. if (!isset($options['itunes_buttonurl'])) {
  607. $options['itunes_buttonurl'] = PODPRESS_URL.'/images/itunes.png';
  608. }
  609. if (!isset($options['posts_buttonurl'])) {
  610. $options['posts_buttonurl'] = PODPRESS_URL.'/images/feed_button-rss-blog.png';
  611. }
  612. if (!isset($options['comments_buttonurl'])) {
  613. $options['comments_buttonurl'] = PODPRESS_URL.'/images/feed_button-rss-comments.png';
  614. }
  615. if (!isset($options['entries-atom_buttonurl'])) {
  616. $options['entries-atom_buttonurl'] = PODPRESS_URL.'/images/feed_button-atom-blog.png';
  617. }
  618. if (!isset($options['comments-atom_buttonurl'])) {
  619. $options['comments-atom_buttonurl'] = PODPRESS_URL.'/images/feed_button-atom-comments.png';
  620. }
  621. $blog = $options['blog'] ? 'checked="checked"' : '';
  622. $comments = $options['comments'] ? 'checked="checked"' : '';
  623. $entries_atom = $options['entries-atom'] ? 'checked="checked"' : '';
  624. $comments_atom = $options['comments-atom'] ? 'checked="checked"' : '';
  625. $itunes = $options['itunes'] ? 'checked="checked"' : '';
  626. $iprot = $options['iprot'] ? 'checked="checked"' :'';
  627. if ( 'text' == $options['buttons-or-text'] ) {
  628. $text = 'checked="checked"';
  629. $buttons = '';
  630. } else {
  631. $text = '';
  632. $buttons = 'checked="checked"';
  633. }
  634. if(!isset($options['title'])) {
  635. $options['title'] = __('Podcast Feeds', 'podpress');
  636. }
  637. $title = attribute_escape(stripslashes($options['title']));
  638. ?>
  639. <p><label for="podPressFeedButtons-title"><?php _e('Title:', 'podpress'); ?></label> <input class="podpress_widget_settings_title" id="podPressFeedButtons-title" name="podPressFeedButtons-title" type="text" value="<?php echo $title; ?>" /></p>
  640. <p><?php _e('Show the buttons for the following feeds:', 'podpress'); ?></p>
  641. <div class="podpress_widget_accordion"><!-- Begin: podPress Widget Accordion -->
  642. <h5><a href=""><?php _e('iTunes Button', 'podpress'); ?></a></h5>
  643. <div>
  644. <input class="checkbox" type="checkbox" <?php echo $itunes; ?> id="podPressFeedButtons-itunes" name="podPressFeedButtons-itunes" /> <label for="podPressFeedButtons-itunes"><?php _e('Show iTunes button', 'podpress'); ?></label><br />
  645. <input class="checkbox" type="checkbox" <?php echo $iprot; ?> id="podPressFeedButtons-iprot" name="podPressItunesProtocol-iprot" /> <label for="podPressFeedButtons-iprot"><?php _e('Use iTunes protocol for URL', 'podpress'); ?> <?php _e('(itpc://)', 'podpress'); ?></label><br />
  646. <span class="nonessential"><?php _e('The user subscribes immediatly with the click. Otherwise the iTunes Store page of the podcast will be displayed first and the user can subscribe manually.', 'podpress'); ?></span><br />
  647. <label for="podPressFeedButtons-itunes_buttonurl"><?php _e('Button URL:', 'podpress'); ?></label> <input type="text" id="podPressFeedButtons-itunes_buttonurl" name="podPressFeedButtons-itunes_buttonurl" class="widefat" value="<?php echo $options['itunes_buttonurl']; ?>" />
  648. </div>
  649. <?php
  650. if ( version_compare( $wp_version, '2.1', '>=' ) ) { // ntm: the add_feed() functions exists since WP 2.1 and widgets are probably possible in earlier WP versions with a plugin.
  651. $feedbuttons = podpress_get_feed_buttons();
  652. if ( is_array($podPress->settings['podpress_feeds']) AND FALSE == empty($podPress->settings['podpress_feeds']) ) {
  653. foreach ($podPress->settings['podpress_feeds'] as $feed) {
  654. if ( TRUE === $feed['use'] AND FALSE == empty($feed['slug']) ) {
  655. if ( FALSE == empty($feed['descr']) ) {
  656. $descr = '<br /><span class="nonessential">'.stripslashes($feed['descr']).'</span>';
  657. } else {
  658. $descr = '';
  659. }
  660. // take over the old widget settings
  661. if ( TRUE == is_array($old_widget_options) AND FALSE == empty($old_widget_options) ) {
  662. Switch ($feed['slug']) {
  663. case 'podcast' :
  664. case 'enhancedpodcast' :
  665. case 'torrent' :
  666. $options['podpressfeeds'][$feed['slug']]['use'] = $old_widget_options[$feed['slug']];
  667. if ( 'podcast' === $feed['slug'] ) {
  668. $options['podpressfeeds'][$feed['slug']]['button'] = 'feed_button-rss-'.$feed['slug'].'.png';
  669. } else {
  670. $options['podpressfeeds'][$feed['slug']]['button'] = 'feed_button-'.$feed['slug'].'.png';
  671. }
  672. break;
  673. }
  674. }
  675. if ( TRUE == isset($options['podpressfeeds'][$feed['slug']]['use']) AND 'yes' === $options['podpressfeeds'][$feed['slug']]['use'] ) {
  676. $podpressfeed_checked = ' checked="checked"';
  677. } else {
  678. $podpressfeed_checked = '';
  679. }
  680. $feedname = stripslashes($feed['name']);
  681. echo '<h5><a href="">'.$feedname.'</a></h5>'."\n";
  682. echo '<div class="podpress_widget_settings_row_div">'."\n";
  683. echo '<input type="checkbox"'.$podpressfeed_checked.' id="podPressFeedButtons-'.$feed['slug'].'_use" name="podpressfeeds['.$feed['slug'].'][use]" value="yes" /> <label for="podPressFeedButtons-'.$feed['slug'].'_use">'.sprintf(__('Show %1$s button', 'podpress'), $feedname).'</label>'."\n";
  684. echo $descr."\n";
  685. echo '<br />'.__('Select a feed button:', 'podpress').'<br />'."\n";
  686. echo '<span class="podpress_feedbuttonsselectbox">'."\n";
  687. $id_base = 'podPressFeedButtons-'.$feed['slug'].'_'.$feed['button'];
  688. $i=0;
  689. $feedbutton_checked_nr = 0;
  690. foreach ($feedbuttons as $feedbutton) {
  691. if ( TRUE == isset($options['podpressfeeds'][$feed['slug']]['button']) AND $feedbutton == $options['podpressfeeds'][$feed['slug']]['button'] ) {
  692. $feedbutton_checked_nr = $i;
  693. }
  694. $i++;
  695. }
  696. $i=0;
  697. foreach ($feedbuttons as $feedbutton) {
  698. if ( $i == $feedbutton_checked_nr ) {
  699. $feedbutton_checked = ' checked="checked"';
  700. } else {
  701. $feedbutton_checked = '';
  702. }
  703. echo '<input type="radio" name="podpressfeeds['.$feed['slug'].'][button]" id="'.$id_base.''.$i.'" value="'.$feedbutton.'"'.$feedbutton_checked.' /> <label for="'.$id_base.''.$i.'"><img src="'.PODPRESS_URL.'/images/'.$feedbutton.'" alt="" /></label><br />'."\n";
  704. $i++;
  705. }
  706. if ( TRUE == isset($options['podpressfeeds'][$feed['slug']]['button']) AND 'custom' == $options['podpressfeeds'][$feed['slug']]['button'] ) {
  707. echo '<input type="radio" name="podpressfeeds['.$feed['slug'].'][button]" id="'.$id_base.''.$i.'" value="custom" checked="checked" /> <input type="text" id="podPressFeedButtons-'.$feed['slug'].'_'.$feed['custombuttonurl'].'" name="podpressfeeds['.$feed['slug'].'][buttonurl]" class="widefat podpress_customfeedbuttonurl" value="'.$options['podpressfeeds'][$feed['slug']]['buttonurl'].'" />'."\n";
  708. } else {
  709. echo '<input type="radio" name="podpressfeeds['.$feed['slug'].'][button]" id="'.$id_base.''.$i.'" value="custom" /> <input type="text" id="podPressFeedButtons-'.$feed['slug'].'_'.$feed['custombuttonurl'].'" name="podpressfeeds['.$feed['slug'].'][buttonurl]" class="widefat podpress_customfeedbuttonurl" value="" />'."\n";
  710. }
  711. echo '</span>'."\n";
  712. echo '<label for="podPressFeedButtons-'.$feed['slug'].'_altfeedurl">'.__('Alternative Feed URL:', 'podpress').'</label> <input type="text" id="podPressFeedButtons-'.$feed['slug'].'_altfeedurl" name="podpressfeeds['.$feed['slug'].'][altfeedurl]" class="widefat" value="'.$options['podpressfeeds'][$feed['slug']]['altfeedurl'].'" />'."\n";
  713. echo '</div>'."\n";
  714. }
  715. }
  716. }
  717. }
  718. ?>
  719. <h5><a href=""><?php _e('Entries RSS Feed', 'podpress'); ?></a></h5>
  720. <div>
  721. <input class="checkbox" type="checkbox" <?php echo $blog; ?> id="podPressFeedButtons-posts" name="podPressFeedButtons-posts" /> <label for="podPressFeedButtons-posts"><?php _e('Entries RSS Feed', 'podpress'); ?></label><br />
  722. <label for="podPressFeedButtons-posts_buttonurl"><?php _e('Button URL:', 'podpress'); ?></label> <input type="text" id="podPressFeedButtons-posts_buttonurl" name="podPressFeedButtons-posts_buttonurl" class="widefat" value="<?php echo $options['posts_buttonurl']; ?>" /><br />
  723. <label for="podPressFeedButtons-posts_altfeedurl"><?php _e('Alternative Feed URL:', 'podpress'); ?></label> <input type="text" id="podPressFeedButtons-posts_altfeedurl" name="podPressFeedButtons-posts_altfeedurl" class="widefat" value="<?php echo $options['posts_altfeedurl']; ?>" />
  724. </div>
  725. <h5><a href=""><?php _e('Comments RSS Feed', 'podpress'); ?></a></h5>
  726. <div>
  727. <input class="checkbox" type="checkbox" <?php echo $comments; ?> id="podPressFeedButtons-comments" name="podPressFeedButtons-comments" /> <label for="podPressFeedButtons-comments"><?php _e('Comments RSS Feed', 'podpress'); ?></label><br />
  728. <label for="podPressFeedButtons-posts_buttonurl"><?php _e('Button URL:', 'podpress'); ?></label> <input type="text" id="podPressFeedButtons-comments_buttonurl" name="podPressFeedButtons-comments_buttonurl" class="widefat" value="<?php echo $options['comments_buttonurl']; ?>" /><br />
  729. <label for="podPressFeedButtons-posts_altfeedurl"><?php _e('Alternative Feed URL:', 'podpress'); ?></label> <input type="text" id="podPressFeedButtons-comments_altfeedurl" name="podPressFeedButtons-comments_altfeedurl" class="widefat" value="<?php echo $options['comments_altfeedurl']; ?>" />
  730. </div>
  731. <h5><a href=""><?php _e('Entries ATOM Feed', 'podpress'); ?></a></h5>
  732. <div>
  733. <input class="checkbox" type="checkbox" <?php echo $entries_atom; ?> id="podPressFeedButtons-entries-atom" name="podPressFeedButtons-entries-atom" /> <label for="podPressFeedButtons-entries-atom"><?php _e('Entries ATOM Feed', 'podpress'); ?></label><br />
  734. <label for="podPressFeedButtons-posts_buttonurl"><?php _e('Button URL:', 'podpress'); ?></label> <input type="text" id="podPressFeedButtons-entries-atom_buttonurl" name="podPressFeedButtons-entries-atom_buttonurl" class="widefat" value="<?php echo $options['entries-atom_buttonurl']; ?>" /><br />
  735. <label for="podPressFeedButtons-posts_altfeedurl"><?php _e('Alternative Feed URL:', 'podpress'); ?></label> <input type="text" id="podPressFeedButtons-entries-atom_altfeedurl" name="podPressFeedButtons-entries-atom_altfeedurl" class="widefat" value="<?php echo $options['entries-atom_altfeedurl']; ?>" />
  736. </div>
  737. <h5><a href=""><?php _e('Comments ATOM Feed', 'podpress'); ?></a></h5>
  738. <div>
  739. <input class="checkbox" type="checkbox" <?php echo $comments_atom; ?> id="podPressFeedButtons-comments-atom" name="podPressFeedButtons-comments-atom" /> <label for="podPressFeedButtons-comments-atom"><?php _e('Comments ATOM Feed', 'podpress'); ?></label><br />
  740. <label for="podPressFeedButtons-posts_buttonurl"><?php _e('Button URL:', 'podpress'); ?></label> <input type="text" id="podPressFeedButtons-comments-atom_buttonurl" name="podPressFeedButtons-comments-atom_buttonurl" class="widefat" value="<?php echo $options['comments-atom_buttonurl']; ?>" /><br />
  741. <label for="podPressFeedButtons-posts_altfeedurl"><?php _e('Alternative Feed URL:', 'podpress'); ?></label> <input type="text" id="podPressFeedButtons-comments-atom_altfeedurl" name="podPressFeedButtons-comments-atom_altfeedurl" class="widefat" value="<?php echo $options['comments-atom_altfeedurl']; ?>" />
  742. </div>
  743. <?php
  744. $query_string = 'SELECT option_name, option_value FROM '.$wpdb->prefix.'options WHERE INSTR(option_name, "podPress_category_")';
  745. $category_feeds = $wpdb->get_results($query_string);
  746. if ( isset($category_feeds) AND FALSE == empty($category_feeds) ) {
  747. foreach ($category_feeds as $feed_options) {
  748. $feed = maybe_unserialize($feed_options->option_value);
  749. if ( isset($feed['categoryCasting']) AND 'true' == $feed['categoryCasting'] ) {
  750. $cat_id = end(explode('_', $feed_options->option_name));
  751. $checked = $options['catcast'][$cat_id] ? 'checked="checked"' :'';
  752. echo '<h5><a href="">'.sprintf(__('Category "%1$s" RSS Feed', 'podpress'), get_cat_name($cat_id)).'</a></h5>'."\n";
  753. echo '<div>'."\n";
  754. echo '<input type="checkbox" '.$checked.' id="podPressFeedButtons-catcast_'.$cat_id.'_use" name="podPressFeedButtons-catcast['.$cat_id.'][use]" /> <label for="podPressFeedButtons-catcast_'.$cat_id.'_use">'.sprintf(__('Category "%1$s" RSS Feed', 'podpress'), get_cat_name($cat_id)).'</label><br />'."\n";
  755. echo '<label for="podPressFeedButtons-catcast_'.$cat_id.'_buttonurl">'.__('Button URL:', 'podpress').'</label> <input type="text" id="podPressFeedButtons-catcast_'.$cat_id.'_buttonurl" name="podPressFeedButtons-catcast['.$cat_id.'][buttonurl]" class="widefat" value="'.$options['podPressFeedButtons-catcast'][$cat_id]['buttonurl'].'" /><br />'."\n";
  756. echo '<label for="podPressFeedButtons-catcast_'.$cat_id.'_altfeedurl">'.__('Alternative Feed URL:', 'podpress').'</label> <input type="text" id="podPressFeedButtons-catcast_'.$cat_id.'_altfeedurl" name="podPressFeedButtons-catcast['.$cat_id.'][altfeedurl]" class="widefat" value="'.$options['podPressFeedButtons-catcast'][$cat_id]['altfeedurl'].'" />'."\n";
  757. echo '</div>'."\n";
  758. }
  759. }
  760. }
  761. ?>
  762. </div><!-- End: podPress Widget Accordion -->
  763. <p class="podpress_widget_settings_row"><?php _e('Show buttons or text?', 'podpress'); ?></p>
  764. <p><label for="podPressFeedButtons-buttons"><?php _e('Buttons', 'podpress'); ?></label> <input type="radio" <?php echo $buttons; ?> value="buttons" id="podPressFeedButtons-buttons" name="podPressFeedButtons-buttons-or-text" /> <input type="radio" <?php echo $text; ?> value="text" id="podPressFeedButtons-text" name="podPressFeedButtons-buttons-or-text" /> <label for="podPressFeedButtons-text"><?php _e('Text', 'podpress'); ?></label></p>
  765. <input type="hidden" id="podPressFeedButtons-submit" name="podPressFeedButtons-submit" value="1" />
  766. <?php
  767. }
  768. /* for WP < 2.8 only */
  769. function podPress_feedButtons ($args) {
  770. GLOBAL $podPress, $wp_version;
  771. extract($args);
  772. $options = get_option('widget_podPressFeedButtons');
  773. if ( version_compare( $wp_version, '2.2', '>=' ) ) { // the rss.png is in wp_includes since WP 2.2 (this is only necessary until the required WP version will be changed to e.g 2.3)
  774. $feed_icon = '<img src="'.get_option('siteurl') . '/' . WPINC . '/images/rss.png" class="podpress_feed_icon" alt="" />';
  775. } else {
  776. $feed_icon = apply_filters('podpress_legacy_support_feed_icon', '');
  777. }
  778. if(!isset($options['title'])) {
  779. $options['title'] = __('Podcast Feeds', 'podpress');
  780. } else {
  781. $options['title'] = stripslashes($options['title']);
  782. }
  783. if(!isset($options['blog'])) {
  784. $options['blog'] = false;
  785. }
  786. if(!isset($options['comments'])) {
  787. $options['comments'] = false;
  788. }
  789. if(!isset($options['entries-atom'])) {
  790. $options['entries-atom'] = false;
  791. }
  792. if(!isset($options['comments-atom'])) {
  793. $options['comments-atom'] = false;
  794. }
  795. if(!isset($options['itunes'])) {
  796. $options['itunes'] = true;
  797. }
  798. if (!isset($options['iprot'])) {
  799. $options['iprot'] = false;
  800. }
  801. if (!isset($options['buttons-or-text'])) {
  802. $options['buttons-or-text'] = 'buttons';
  803. }
  804. echo $before_widget;
  805. echo $before_title . $options['title'] . $after_title;
  806. echo '<ul class="podpress_feed_buttons_list">'."\n";
  807. switch ($options['buttons-or-text']) {
  808. default:
  809. case 'buttons' :
  810. if ($options['itunes']) {
  811. // for more info: http://www.apple.com/itunes/podcasts/specs.html#linking
  812. if ($options['iprot'] ) {
  813. echo ' <li><a href="itpc://'.preg_replace('/^https?:\/\//i', '', $podPress->settings['podcastFeedURL']).'"';
  814. } else {
  815. echo ' <li><a href="http://www.itunes.com/podcast?id='.$podPress->settings['iTunes']['FeedID'].'"';
  816. }
  817. if ( FALSE == empty($options['itunes_buttonurl']) ) {
  818. echo ' title="'.__('Subscribe to the Podcast Feed with iTunes', 'podpress').'"><img src="'.$options['itunes_buttonurl'].'" class="podpress_feed_buttons" alt="'.__('Subscribe with iTunes', 'podpress').'" /></a></li>'."\n";
  819. } else {
  820. echo ' title="'.__('Subscribe to the Podcast Feed with iTunes', 'podpress').'"><img src="'.podPress_url().'images/itunes.png" class="podpress_feed_buttons" alt="'.__('Subscribe with iTunes', 'podpress').'" /></a></li>'."\n";
  821. }
  822. }
  823. // podPress feeds:
  824. if ( is_array($options['podpressfeeds']) AND FALSE == empty($options['podpressfeeds']) ) {
  825. foreach ($options['podpressfeeds'] as $feed_slug => $feed_options) {
  826. if ( 'yes' === $feed_options['use'] AND is_array($podPress->settings['podpress_feeds']) ) {
  827. foreach ( $podPress->settings['podpress_feeds'] AS $feed ) {
  828. if ( $feed_slug === $feed['slug'] AND TRUE === $feed['use'] ) {
  829. if ( FALSE == empty($feed_options['altfeedurl']) ) {
  830. $feed_link = $feed_options['altfeedurl'];
  831. } else {
  832. $feed_link = get_feed_link($feed_slug);
  833. }
  834. if ( FALSE == empty($feed['slug']) ) {
  835. $descr = stripslashes($feed['descr']);
  836. } else {
  837. $descr = __('Subscribe to this Feed with any feed reader', 'podpress');
  838. }
  839. if ( FALSE == empty($feed_options['buttonurl']) ) {
  840. echo ' <li><a href="'.$feed_link.'" title="'.attribute_escape($descr).'"><img src="'.$feed_options['buttonurl'].'" class="podpress_feed_buttons" alt="'.attribute_escape(stripslashes($feed['name'])).'" /></a></li>'."\n";
  841. } else {
  842. echo ' <li><a href="'.$feed_link.'" title="'.attribute_escape($descr).'">'.$feed_icon.' '.stripslashes($feed['name']).'</a></li>'."\n";
  843. }
  844. }
  845. }
  846. }
  847. }
  848. }
  849. if($options['blog']) {
  850. if ( FALSE === empty($options['posts_altfeedurl']) ) {
  851. $feedlink = $options['posts_altfeedurl'];
  852. } else {
  853. $feedlink = get_bloginfo('rss2_url');
  854. }
  855. if ( FALSE == empty($options['posts_buttonurl']) ) {
  856. echo ' <li><a href="'.$feedlink.'" title="'.__('Subscribe to the main RSS Feed with any feed reader', 'podpress').'"><img src="'.$options['posts_buttonurl'].'" class="podpress_feed_buttons" alt="'.__('Subscribe to the RSS Feed', 'podpress').'" /></a></li>'."\n";
  857. } else {
  858. echo ' <li><a href="'.$feedlink.'" title="'.__('Subscribe to the main RSS Feed with any feed reader', 'podpress').'"><img src="'.podPress_url().'images/feed_button-rss-blog.png" class="podpress_feed_buttons" alt="'.__('Subscribe to the RSS Feed', 'podpress').'" /></a></li>'."\n";
  859. }
  860. }
  861. if($options['comments']) {
  862. if ( FALSE === empty($options['comments_altfeedurl']) ) {
  863. $feedlink = $options['comments_altfeedurl'];
  864. } else {
  865. $feedlink = get_bloginfo('comments_rss2_url');
  866. }
  867. if ( FALSE == empty($options['comments_buttonurl']) ) {
  868. echo ' <li><a href="'.$feedlink.'" title="'.__('Subscribe to the comments RSS Feed with any feed reader', 'podpress').'"><img src="'.$options['comments_buttonurl'].'" class="podpress_feed_buttons" alt="'.__('Subscribe to the comments RSS Feed', 'podpress').'" /></a></li>'."\n";
  869. } else {
  870. echo ' <li><a href="'.$feedlink.'" title="'.__('Subscribe to the comments RSS Feed with any feed reader', 'podpress').'"><img src="'.podPress_url().'images/feed_button-rss-comments.png" class="podpress_feed_buttons" alt="'.__('Subscribe to the comments RSS Feed', 'podpress').'" /></a></li>'."\n";
  871. }
  872. }
  873. if($options['entries-atom']) {
  874. if ( FALSE === empty($options['entries-atom_altfeedurl']) ) {
  875. $feedlink = $options['entries-atom_altfeedurl'];
  876. } else {
  877. $feedlink = get_bloginfo('atom_url');
  878. }
  879. if ( FALSE == empty($options['entries-atom_buttonurl']) ) {
  880. echo ' <li><a href="'.$feedlink.'" title="'.__('Subscribe to the main ATOM Feed with any feed reader', 'podpress').'"><img src="'.$options['entries-atom_buttonurl'].'" class="podpress_feed_buttons" alt="'.__('Subscribe to the ATOM Feed', 'podpress').'" /></a></li>'."\n";
  881. } else {
  882. echo ' <li><a href="'.$feedlink.'" title="'.__('Subscribe to the main ATOM Feed with any feed reader', 'podpress').'"><img src="'.podPress_url().'images/feed_button-atom-blog.png" class="podpress_feed_buttons" alt="'.__('Subscribe to the ATOM Feed', 'podpress').'" /></a></li>'."\n";
  883. }
  884. }
  885. if($options['comments-atom']) {
  886. if ( FALSE === empty($options['comments-atom_altfeedurl']) ) {
  887. $feedlink = $options['comments-atom_altfeedurl'];
  888. } else {
  889. $feedlink = get_bloginfo('comments_atom_url');
  890. }
  891. if ( FALSE == empty($options['comments-atom_buttonurl']) ) {
  892. echo ' <li><a href="'.$feedlink.'" title="'.__('Subscribe to the comments ATOM Feed with any feed reader', 'podpress').'"><img src="'.$options['comments-atom_buttonurl'].'" class="podpress_feed_buttons" alt="'.__('Subscribe to the comments ATOM Feed', 'podpress').'" /></a></li>'."\n";
  893. } else {
  894. echo ' <li><a href="'.$feedlink.'" title="'.__('Subscribe to the comments ATOM Feed with any feed reader', 'podpress').'"><img src="'.podPress_url().'images/feed_button-atom-comments.png" class="podpress_feed_buttons" alt="'.__('Subscribe to the comments ATOM Feed', 'podpress').'" /></a></li>'."\n";
  895. }
  896. }
  897. if ( is_array($options['catcast']) AND FALSE == empty($options['catcast']) ) {
  898. foreach ($options['catcast'] as $cat_id => $catcast_options) {
  899. if ( 'yes' === $catcast_options['use'] ) {
  900. if ( FALSE == empty($catcast_options['altfeedurl']) ) {
  901. $cat_feed_link = $catcast_options['altfeedurl'];
  902. } else {
  903. if (TRUE == version_compare($wp_version, '2.9.3','>') ) {
  904. $cat_feed_link = get_term_feed_link($cat_id);
  905. } elseif ( TRUE == version_compare($wp_version, '2.9.3','<=') AND TRUE == version_compare($wp_version, '2.4','>') ) {
  906. $cat_feed_link = get_category_feed_link($cat_id);
  907. } else {
  908. $cat_feed_link = get_option('siteurl').'/?feed=rss2&cat='.$cat_id;
  909. }
  910. }
  911. if ( FALSE == empty($catcast_options['buttonurl']) ) {
  912. echo ' <li><a href="'.$cat_feed_link.'" title="'.__('Subscribe to this Category RSS Feed with any feed reader', 'podpress').'"><img src="'.$catcast_options['buttonurl'].'" class="podpress_feed_buttons" alt="'.attributes_escape(sprintf(__('Category "%1$s" RSS Feed', 'podpress'), get_cat_name($cat_id))).'" /></a></li>'."\n";
  913. } else {
  914. echo ' <li><a href="'.$cat_feed_link.'" title="'.__('Subscribe to this Category RSS Feed with any feed reader', 'podpress').'">'.$feed_icon.' '.sprintf(__('Category "%1$s" RSS Feed', 'podpress'), get_cat_name($cat_id)).'</a></li>'."\n";
  915. }
  916. }
  917. }
  918. }
  919. break;
  920. case 'text' :
  921. if ($options['itunes']) {
  922. // for more info: http://www.apple.com/itunes/podcasts/specs.html#linking
  923. if ($options['iprot'] ) {
  924. echo ' <li><a href="itpc://'.preg_replace('/^https?:\/\//i', '', $podPress->settings['podcastFeedURL']).'"';
  925. } else {
  926. echo ' <li><a href="http://www.itunes.com/podcast?id='.$podPress->settings['iTunes']['FeedID'].'"';
  927. }
  928. echo ' title="'.__('Subscribe to the Podcast Feed with iTunes', 'podpress').'">'.$feed_icon.' '.__('Subscribe with iTunes', 'podpress').'</a></li>'."\n";
  929. }
  930. // podPress feeds:
  931. if ( is_array($options['podpressfeeds']) AND FALSE == empty($options['podpressfeeds']) ) {
  932. foreach ($options['podpressfeeds'] as $feed_slug => $feed_options) {
  933. if ( 'yes' === $feed_options['use'] AND is_array($podPress->settings['podpress_feeds']) ) {
  934. foreach ( $podPress->settings['podpress_feeds'] AS $feed ) {
  935. if ( $feed_slug === $feed['slug'] AND TRUE === $feed['use'] ) {
  936. if ( FALSE == empty($feed_options['altfeedurl']) ) {
  937. $feed_link = $feed_options['altfeedurl'];
  938. } else {
  939. $feed_link = get_feed_link($feed_slug);
  940. }
  941. if ( FALSE == empty($feed['slug']) ) {
  942. $descr = stripslashes($feed['descr']);
  943. } else {
  944. $descr = __('Subscribe to this Feed with any feed reader', 'podpress');
  945. }
  946. echo ' <li><a href="'.$feed_link.'" title="'.attribute_escape($descr).'">'.$feed_icon.' '.stripslashes($feed['name']).'</a></li>'."\n";
  947. }
  948. }
  949. }
  950. }
  951. }
  952. if($options['blog']) {
  953. if ( FALSE === empty($options['posts_altfeedurl']) ) {
  954. $feedlink = $options['posts_altfeedurl'];
  955. } else {
  956. $feedlink = get_bloginfo('rss2_url');
  957. }
  958. echo ' <li><a href="'.$feedlink.'" title="'.__('Subscribe to the main RSS Feed with any feed reader', 'podpress').'">'.$feed_icon.' '.__('Entries RSS Feed', 'podpress').'</a></li>'."\n";
  959. }
  960. if($options['comments']) {
  961. if ( FALSE === empty($options['comments_altfeedurl']) ) {
  962. $feedlink = $options['comments_altfeedurl'];
  963. } else {
  964. $feedlink = get_bloginfo('comments_rss2_url');
  965. }
  966. echo ' <li><a href="'.$feedlink.'" title="'.__('Subscribe to the comments RSS Feed with any feed reader', 'podpress').'">'.$feed_icon.' '.__('Comments RSS Feed', 'podpress').'</a></li>'."\n";
  967. }
  968. if($options['entries-atom']) {
  969. if ( FALSE === empty($options['entries-atom_altfeedurl']) ) {
  970. $feedlink = $options['entries-atom_altfeedurl'];
  971. } else {
  972. $feedlink = get_bloginfo('atom_url');
  973. }
  974. echo ' <li><a href="'.$feedlink.'" title="'.__('Subscribe to the main ATOM Feed with any feed reader', 'podpress').'">'.$feed_icon.' '.__('Entries ATOM Feed', 'podpress').'</a></li>'."\n";
  975. }
  976. if($options['comments-atom']) {
  977. if ( FALSE === empty($options['comments-atom_altfeedurl']) ) {
  978. $feedlink = $options['comments-atom_altfeedurl'];
  979. } else {
  980. $feedlink = get_bloginfo('comments_atom_url');
  981. }
  982. echo ' <li><a href="'.$feedlink.'" title="'.__('Subscribe to the comments ATOM Feed with any feed reader', 'podpress').'">'.$feed_icon.' '.__('Comments ATOM Feed', 'podpress').'</a></li>'."\n";
  983. }
  984. if ( is_array($options['catcast']) AND FALSE == empty($options['catcast']) ) {
  985. foreach ($options['catcast'] as $cat_id => $catcast_options) {
  986. if ( 'yes' === $catcast_options['use'] ) {
  987. if ( FALSE == empty($catcast_options['altfeedurl']) ) {
  988. $cat_feed_link = $catcast_options['altfeedurl'];
  989. } else {
  990. if (TRUE == version_compare($wp_version, '2.9.3','>') ) {
  991. $cat_feed_link = get_term_feed_link($cat_id);
  992. } elseif ( TRUE == version_compare($wp_version, '2.9.3','<=') AND TRUE == version_compare($wp_version, '2.4','>') ) {
  993. $cat_feed_link = get_category_feed_link($cat_id);
  994. } else {
  995. $cat_feed_link = get_option('siteurl').'/?feed=rss2&cat='.$cat_id;
  996. }
  997. }
  998. echo ' <li><a href="'.$cat_feed_link.'" title="'.__('Subscribe to this Category RSS Feed with any feed reader', 'podpress').'">'.$feed_icon.' '.sprintf(__('Category "%1$s" RSS Feed', 'podpress'), get_cat_name($cat_id)).'</a></li>'."\n";
  999. }
  1000. }
  1001. }
  1002. break;
  1003. }
  1004. echo "</ul>\n";
  1005. echo $after_widget;
  1006. }
  1007. /* for WP < 2.8 only */
  1008. function podPress_xspfPlayer_control() {
  1009. global $blog_id;
  1010. $xspf_width_const_msg = '';
  1011. $xspf_height_const_msg = '';
  1012. $xspf_heightslim_const_msg = '';
  1013. $xspf_width_readonly = '';
  1014. $xspf_height_readonly = '';
  1015. $xspf_heightslim_readonly = '';
  1016. $options = get_option('widget_podPressXspfPlayer');
  1017. $blog_charset = get_bloginfo('charset');
  1018. if ( isset($_POST['podPressXspfPlayer-submit']) ) {
  1019. $options['title'] = htmlspecialchars(strip_tags(trim($_POST['podPressXspfPlayer-title'])), ENT_QUOTES, $blog_charset);
  1020. $options['useSlimPlayer'] = isset($_POST['podPressXspfPlayer-useSlimPlayer']);
  1021. $options['PlayerWidth'] = intval(preg_replace('/[^0-9]/', '',$_POST['podPressXspfPlayer-width'])); // only numeric values are allowed
  1022. $options['PlayerHeight'] = intval(preg_replace('/[^0-9]/', '',$_POST['podPressXspfPlayer-height'])); // only numeric values are allowed
  1023. $options['useSlimPlayer'] = isset($_POST['podPressXspfPlayer-useSlimPlayer']);
  1024. $options['SlimPlayerHeight'] = intval(preg_replace('/[^0-9]/', '',$_POST['podPressXspfPlayer-heightslim'])); // only numeric values are allowed
  1025. $options['trackinfoformat'] = strip_tags($_POST['podPressXspfPlayer-trackinfoformat']);
  1026. }
  1027. if ( 150 > intval($options['PlayerWidth']) ) {
  1028. $options['PlayerWidth'] = 150; // min width
  1029. }
  1030. if ( 100 > intval($options['PlayerHeight']) ) {
  1031. $options['PlayerHeight'] = 100; // min height
  1032. }
  1033. if ( 100 < intval($options['SlimPlayerHeight']) ) {
  1034. $options['SlimPlayerHeight'] = 100; // max height slim
  1035. } elseif ( 30 > intval($options['SlimPlayerHeight']) ) {
  1036. $options['SlimPlayerHeight'] = 30; // min height slim
  1037. }
  1038. if ( isset($_POST['podPressXspfPlayer-submit']) ) {
  1039. if ( isset($_POST['podPressXspfPlayer-xspf_use_custom_playlist']) ) {
  1040. $options['xspf_use_custom_playlist'] = TRUE;
  1041. } else {
  1042. $options['xspf_use_custom_playlist'] = FALSE;
  1043. }
  1044. $options['xspf_custom_playlist_url'] = clean_url($_POST['podPressXspfPlayer-xspf_custom_playlist_url'], array('http', 'https'), 'db');
  1045. update_option('widget_podPressXspfPlayer', $options);
  1046. $updated = true; // So that we don't go through this more than once
  1047. }
  1048. if (!isset($options['title'])) {
  1049. $options['title'] = __('Podcast Player', 'podpress');
  1050. }
  1051. $title = attribute_escape(stripslashes($options['title']));
  1052. $useSlimPlayer = $options['useSlimPlayer'] ? ' checked="checked"' : '';
  1053. ?>
  1054. <p><label for="podPressXspfPlayer-title"><?php _e('Title:'); ?></label> <input type="text" id="podPressXspfPlayer-title" name="podPressXspfPlayer-title" value="<?php echo $title; ?>" class="podpress_widget_settings_title" /></p>
  1055. <p><label for="podPressXspfPlayer-width"><?php _e('Player Width:', 'podpress'); ?></label> <input type="text" id="podPressXspfPlayer-width" name="podPressXspfPlayer-width" maxlength="3" value="<?php echo $options['PlayerWidth']; ?>" class="podpress_widget_settings_3digits" /> <?php _e('px', 'podpress'); ?> <?php echo '<span class="nonessential">'.__('(150 <= w < 1000)', 'podpress').'</span>'; ?></p>
  1056. <p><label for="podPressXspfPlayer-height"><?php _e('Player Height:', 'podpress'); ?></label> <input type="text" id="podPressXspfPlayer-height" name="podPressXspfPlayer-height" maxlength="3" value="<?php echo $options['PlayerHeight']; ?>" class="podpress_widget_settings_3digits" /> <?php _e('px', 'podpress'); ?> <?php echo '<span class="nonessential">'.__('(100 <= h < 1000)', 'podpress').'</span>'; ?></p>
  1057. <p><label for="podPressXspfPlayer-useSlimPlayer"><?php _e('Use Slim Player', 'podpress'); ?></label> <input type="checkbox" id="podPressXspfPlayer-useSlimPlayer" name="podPressXspfPlayer-useSlimPlayer"<?php echo $useSlimPlayer; ?> class="checkbox" /></p>
  1058. <p><label for="podPressXspfPlayer-heightslim"><?php _e('Slim Player Height:', 'podpress'); ?></label> <input type="text" id="podPressXspfPlayer-heightslim" name="podPressXspfPlayer-heightslim" maxlength="3" value="<?php echo $options['SlimPlayerHeight']; ?>" class="podpress_widget_settings_3digits" /> <?php _e('px', 'podpress'); ?> <?php echo '<span class="nonessential">'.__('(30 <= h <= 100)', 'podpress').'</span>'; ?></p>
  1059. <p><label for="podPressXspfPlayer-trackinfoformat"><?php _e('Choose the format of the playlist entires:', 'podpress'); ?></label>
  1060. <select id="podPressXspfPlayer-trackinfoformat" name="podPressXspfPlayer-trackinfoformat">
  1061. <?php
  1062. $trackinfoformats = Array(
  1063. Array('val' => '-title - -creator', 'name'=>__('episode title', 'podpress').' - '.__('artist', 'podpress')),
  1064. Array('val' => '-title : -creator', 'name'=>__('episode title', 'podpress').' : '.__('artist', 'podpress')),
  1065. Array('val' => '-creator - -title', 'name'=>__('artist', 'podpress').' - '.__('episode title', 'podpress')),
  1066. Array('val' => '-creator : -title', 'name'=>__('artist', 'podpress').' : '.__('episode title', 'podpress')),
  1067. Array('val' => '-title', 'name'=>__('episode title', 'podpress'))
  1068. );
  1069. if ( FALSE == isset($options['trackinfoformat']) OR TRUE == empty($options['trackinfoformat']) ) {
  1070. $options['trackinfoformat'] = '-creator : -title';
  1071. }
  1072. foreach ($trackinfoformats as $format) {
  1073. if ($options['trackinfoformat'] == $format['val']) {
  1074. echo '<option value="'.$format['val'].'" selected="selected">'.$format['name'].'</option>';
  1075. } else {
  1076. echo '<option value="'.$format['val'].'">'.$format['name'].'</option>';
  1077. }
  1078. }
  1079. ?>
  1080. </select>
  1081. </p>
  1082. <?php
  1083. if ( defined('PODPRESS_CUSTOM_XSPF_URL_'.$blog_id) AND '' !== constant('PODPRESS_CUSTOM_XSPF_URL_'.$blog_id) ) {
  1084. $xspf_custom_playlist_url_readonly = ' readonly="readonly"';
  1085. $xspf_custom_playlist_url = attribute_escape(constant('PODPRESS_CUSTOM_XSPF_URL_'.$blog_id));
  1086. $xspf_use_custom_playlist_disabled = ' disabled="disabled"';
  1087. $xspf_use_custom_playlist_checked = ' checked="checked"';
  1088. $xspf_custom_playlist_msg = '<p class="podpress_notice">'.sprintf(__('<strong>Notice:</strong> The custom playlist URL is currently defined via the constant PODPRESS_CUSTOM_XSPF_URL_%1$s and this constant overwrites the custom XSPF playlist settings.', 'podpress'), $blog_id).'</p>';
  1089. } else {
  1090. $xspf_custom_playlist_url_readonly = '';
  1091. $xspf_custom_playlist_url = attribute_escape($options['xspf_custom_playlist_url']);
  1092. $xspf_use_custom_playlist_disabled = '';
  1093. if ( TRUE === $options['xspf_use_custom_playlist'] ) {
  1094. $xspf_use_custom_playlist_checked = ' checked="checked"';
  1095. } else {
  1096. $xspf_use_custom_playlist_checked = '';
  1097. }
  1098. $xspf_custom_playlist_msg = '';
  1099. }
  1100. echo '<p><label for="xspf_use_custom_playlist">'.__('use a custom XSPF playlist:', 'podpress').'</label> <input type="checkbox" name="podPressXspfPlayer-xspf_use_custom_playlist" id="xspf_use_custom_playlist"'.$xspf_use_custom_playlist_checked.$xspf_use_custom_playlist_disabled.' /></p>'."\n";
  1101. echo '<p><label for="xspf_custom_playlist_url">'.__('custom playlist URL:', 'podpress').'</label><br /><input type="text" name="podPressXspfPlayer-xspf_custom_playlist_url" id="xspf_custom_playlist_url" class="podpress_full_width_text_field" size="40" value="'.$xspf_custom_playlist_url.'"'.$xspf_custom_playlist_url_readonly.' /><span class="nonessential">'.__('The custom playlist URL has to be an URL to a playlist which is on the same domain/server as your blog. The files in the playlist can be located some where else.', 'podpress').'</span></p>'.$xspf_custom_playlist_msg."\n";
  1102. if ( TRUE == defined('PODPRESS_XSPF_PLAYER_USE_CUSTOM_SKINFILE_'.$blog_id) AND TRUE === constant('PODPRESS_XSPF_PLAYER_USE_CUSTOM_SKINFILE_'.$blog_id) ) {
  1103. echo '<p class="podpress_notice podpress_msg">'.sprintf(__('<strong>Notice:</strong> PODPRESS_XSPF_PLAYER_USE_CUSTOM_SKINFILE_%1$s is defined. This widget uses custom skin files. Make sure that there is a custom skin file for these dimensions (see podpress_xspf_config.php).', 'podpress'), $blog_id).'</p>';
  1104. }
  1105. ?>
  1106. <input type="hidden" id="podPressXspfPlayer-submit" name="podPressXspfPlayer-submit" value="1" />
  1107. <?php
  1108. }
  1109. /* for WP < 2.8 only */
  1110. function podPress_xspfPlayer($args) {
  1111. GLOBAL $podPress, $blog_id;
  1112. extract($args);
  1113. $options = get_option('widget_podPressXspfPlayer');
  1114. if ( !isset($options['title']) ) {
  1115. $options['title'] = __('Podcast Player', 'podpress');
  1116. } else {
  1117. $options['title'] = stripslashes($options['title']);
  1118. }
  1119. if ( !isset($options['useSlimPlayer']) ) {
  1120. $options['useSlimPlayer'] = false;
  1121. }
  1122. if ( 150 > intval($options['PlayerWidth']) ) {
  1123. $options['PlayerWidth'] = 150; // min width
  1124. }
  1125. $skin_variables_url = PODPRESS_OPTIONS_URL.'/xspf_options/variables';
  1126. $skin_variables_dir = PODPRESS_OPTIONS_DIR.'/xspf_options/variables';
  1127. $skin_file = PODPRESS_URL.'/podpress_xspfskinfile.php';
  1128. echo $before_widget."\n";
  1129. echo $before_title . $options['title'] . $after_title."\n";
  1130. if ( TRUE === $options['useSlimPlayer'] ) {
  1131. if ( 30 > intval($options['SlimPlayerHeight']) ) {
  1132. $options['SlimPlayerHeight'] = 30; // min height slim
  1133. }
  1134. if ( TRUE == defined('PODPRESS_XSPF_PLAYER_USE_CUSTOM_SKINFILE_'.$blog_id) AND TRUE == defined('PODPRESS_XSPF_SLIM_SKIN_URL_'.$blog_id) AND TRUE == defined('PODPRESS_XSPF_SLIM_SKIN_DIR_'.$blog_id) AND TRUE == is_readable(constant('PODPRESS_XSPF_SLIM_SKIN_DIR_'.$blog_id).'/skin_'.$blog_id.'_'.$options['PlayerWidth'].'x'.$options['SlimPlayerHeight'].'.xml') ) {
  1135. $skin_file = constant('PODPRESS_XSPF_SLIM_SKIN_URL_'.$blog_id).'/skin_'.$blog_id.'_'.$options['PlayerWidth'].'x'.$options['SlimPlayerHeight'].'.xml';
  1136. }
  1137. $skin_variables_url .= '_slim';
  1138. $skin_variables_dir .= '_slim';
  1139. if ( TRUE === defined('PODPRESS_XSPF_SLIM_USE_CUSTOM_VARIABLES_'.$blog_id) AND TRUE === constant('PODPRESS_XSPF_SLIM_USE_CUSTOM_VARIABLES_'.$blog_id) AND TRUE == is_readable($skin_variables_dir.'/variables_'.$blog_id.'.txt')) {
  1140. $variables = '&skin_url='.$skin_file.'&loadurl='.$skin_variables_url.'/variables_'.$blog_id.'.txt';
  1141. } else {
  1142. if ( FALSE == isset($options['trackinfoformat']) OR (TRUE == isset($options['trackinfoformat']) AND '-creator : -title' == $options['trackinfoformat']) ) {
  1143. $variables = '&skin_url='.$skin_file.'&autoload=true&autoplay=false&loaded=true';
  1144. } else {
  1145. $variables = '&skin_url='.$skin_file.'&autoload=true&autoplay=false&loaded=true&format='.$options['trackinfoformat'];
  1146. }
  1147. }
  1148. $data_string = PODPRESS_URL.'/players/xspf_jukebox/xspf_jukebox.swf?playlist_url='.(PODPRESS_URL.'/podpress_xspfplaylist.php').$variables;
  1149. $data_string = htmlspecialchars($data_string);
  1150. echo '<object type="application/x-shockwave-flash" classid="CLSID:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'.$options['PlayerWidth'].'" height="'.$options['PlayerHeight'].'" id="podpress_xspf_player_slim">'."\n";
  1151. $height = $options['SlimPlayerHeight'];
  1152. } else {
  1153. if ( 100 > intval($options['PlayerHeight']) ) {
  1154. $options['PlayerHeight'] = 100; // min height
  1155. }
  1156. if ( TRUE == defined('PODPRESS_XSPF_PLAYER_USE_CUSTOM_SKINFILE_'.$blog_id) AND TRUE == defined('PODPRESS_XSPF_SKIN_URL_'.$blog_id) AND TRUE == defined('PODPRESS_XSPF_SKIN_DIR_'.$blog_id) AND TRUE == is_readable(constant('PODPRESS_XSPF_SKIN_DIR_'.$blog_id).'/skin_'.$blog_id.'_'.$options['PlayerWidth'].'x'.$options['PlayerHeight'].'.xml') ) {
  1157. $skin_file = constant('PODPRESS_XSPF_SKIN_URL_'.$blog_id).'/skin_'.$blog_id.'_'.$options['PlayerWidth'].'x'.$options['PlayerHeight'].'.xml';
  1158. }
  1159. if ( TRUE === defined('PODPRESS_XSPF_USE_CUSTOM_VARIABLES_'.$blog_id) AND TRUE === constant('PODPRESS_XSPF_USE_CUSTOM_VARIABLES_'.$blog_id) AND TRUE == is_readable($skin_variables_dir.'/variables_'.$blog_id.'.txt')) {
  1160. $variables = '&skin_url='.$skin_file.'&loadurl='.$skin_variables_url.'/variables_'.$blog_id.'.txt';
  1161. } else {
  1162. if ( FALSE == isset($options['trackinfoformat']) OR (TRUE == isset($options['trackinfoformat']) AND '-creator : -title' == $options['trackinfoformat']) ) {
  1163. $variables = '&skin_url='.$skin_file.'&autoload=true&autoplay=false&loaded=true';
  1164. } else {
  1165. $variables = '&skin_url='.$skin_file.'&autoload=true&autoplay=false&loaded=true&format='.$options['trackinfoformat'];
  1166. }
  1167. }
  1168. $data_string = PODPRESS_URL.'/players/xspf_jukebox/xspf_jukebox.swf?playlist_url='.(PODPRESS_URL.'/podpress_xspfplaylist.php').$variables;
  1169. $data_string = htmlspecialchars($data_string);
  1170. echo '<object type="application/x-shockwave-flash" classid="CLSID:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'.$options['PlayerWidth'].'" height="'.$options['PlayerHeight'].'" id="podpress_xspf_player">'."\n";
  1171. $height = $options['PlayerHeight'];
  1172. }
  1173. echo ' <param name="movie" value="'.$data_string.'" />'."\n";
  1174. if ( defined('PODPRESS_XSPF_BACKGROUND_COLOR_'.$blog_id) AND '' !== constant('PODPRESS_XSPF_BACKGROUND_COLOR_'.$blog_id) ) {
  1175. echo ' <param name="bgcolor" value="#'.constant('PODPRESS_XSPF_BACKGROUND_COLOR_'.$blog_id).'" />'."\n";
  1176. } else {
  1177. echo ' <param name="bgcolor" value="#FFFFFF" />'."\n";
  1178. }
  1179. echo ' <param name="menu" value="true" />';
  1180. echo ' <param name="wmode" value="transparent" />';
  1181. echo ' <param name="quality" value="high" />';
  1182. echo ' <embed src="'.$data_string.'" type="application/x-shockwave-flash" width="'.$options['PlayerWidth'].'" height="'.$height.'" wmode="transparent" quality="high" />';
  1183. echo '</object>'."\n";
  1184. echo $after_widget;
  1185. }
  1186. /**
  1187. * podPress Feed Buttons Widget Class
  1188. * since podPress v8.8.7 beta 2
  1189. * for WP > = 2.8
  1190. */
  1191. if ( TRUE == version_compare($wp_version, '2.8', '>=') ) {
  1192. class podpress_feedbuttons extends WP_Widget {
  1193. /** constructor */
  1194. function podpress_feedbuttons() {
  1195. $widget_ops = array(
  1196. 'classname' => 'podpress_feedbuttons',
  1197. 'description' => __('Shows buttons for the podcast feeds in the sidebar', 'podpress')
  1198. );
  1199. $control_ops = array('width' => 400, 'height' => 300);
  1200. parent::WP_Widget(false, $name = __('podPress - Feed Buttons','podpress'), $widget_ops, $control_ops);
  1201. }
  1202. /** @see WP_Widget::widget */
  1203. function widget($args, $instance) {
  1204. GLOBAL $podPress, $wp_version;
  1205. extract( $args );
  1206. $title = apply_filters('widget_title', $instance['title']);
  1207. $feed_icon = '<img src="'.get_option('siteurl') . '/' . WPINC . '/images/rss.png" class="podpress_feed_icon" alt="" />';
  1208. echo $before_widget;
  1209. echo $before_title . $title . $after_title;
  1210. echo '<ul class="podpress_feed_buttons_list">'."\n";
  1211. switch ($instance['buttons-or-text']) {
  1212. default:
  1213. case 'buttons' :
  1214. if ($instance['itunes']) {
  1215. // for more info: http://www.apple.com/itunes/podcasts/specs.html#linking
  1216. if ($instance['iprot'] ) {
  1217. echo ' <li><a href="itpc://'.preg_replace('/^https?:\/\//i', '', $podPress->settings['podcastFeedURL']).'"';
  1218. } else {
  1219. echo ' <li><a href="http://www.itunes.com/podcast?id='.$podPress->settings['iTunes']['FeedID'].'"';
  1220. }
  1221. if ( FALSE == empty($instance['itunes_buttonurl']) ) {
  1222. echo ' title="'.__('Subscribe to the Podcast Feed with iTunes', 'podpress').'"><img src="'.$instance['itunes_buttonurl'].'" class="podpress_feed_buttons" alt="'.__('Subscribe with iTunes', 'podpress').'" /></a></li>'."\n";
  1223. } else {
  1224. echo ' title="'.__('Subscribe to the Podcast Feed with iTunes', 'podpress').'"><img src="'.podPress_url().'images/itunes.png" class="podpress_feed_buttons" alt="'.__('Subscribe with iTunes', 'podpress').'" /></a></li>'."\n";
  1225. }
  1226. }
  1227. // podPress feeds:
  1228. if ( is_array($instance['podpressfeeds']) AND FALSE == empty($instance['podpressfeeds']) ) {
  1229. foreach ($instance['podpressfeeds'] as $feed_slug => $feed_options) {
  1230. if ( 'yes' === $feed_options['use'] AND is_array($podPress->settings['podpress_feeds']) ) {
  1231. foreach ( $podPress->settings['podpress_feeds'] AS $feed ) {
  1232. if ( $feed_slug === $feed['slug'] AND TRUE === $feed['use'] ) {
  1233. if ( FALSE == empty($feed_options['altfeedurl']) ) {
  1234. $feed_link = $feed_options['altfeedurl'];
  1235. } else {
  1236. $feed_link = get_feed_link($feed_slug);
  1237. }
  1238. if ( FALSE == empty($feed['slug']) ) {
  1239. $descr = stripslashes($feed['descr']);
  1240. } else {
  1241. $descr = __('Subscribe to this Feed with any feed reader', 'podpress');
  1242. }
  1243. if ( FALSE == empty($feed_options['buttonurl']) ) {
  1244. echo ' <li><a href="'.$feed_link.'" title="'.esc_attr($descr).'"><img src="'.$feed_options['buttonurl'].'" class="podpress_feed_buttons" alt="'.esc_attr(stripslashes($feed['name'])).'" /></a></li>'."\n";
  1245. } else {
  1246. echo ' <li><a href="'.$feed_link.'" title="'.esc_attr($descr).'">'.$feed_icon.' '.stripslashes($feed['name']).'</a></li>'."\n";
  1247. }
  1248. }
  1249. }
  1250. }
  1251. }
  1252. }
  1253. if($instance['posts']) {
  1254. if ( FALSE == empty($instance['posts_altfeedurl']) ) {
  1255. $feedlink = $instance['posts_altfeedurl'];
  1256. } else {
  1257. $feedlink = get_bloginfo('rss2_url');
  1258. }
  1259. if ( FALSE == empty($instance['posts_buttonurl']) ) {
  1260. echo ' <li><a href="'.$feedlink.'" title="'.__('Subscribe to the main RSS Feed with any feed reader', 'podpress').'"><img src="'.$instance['posts_buttonurl'].'" class="podpress_feed_buttons" alt="'.__('Subscribe to the RSS Feed', 'podpress').'" /></a></li>'."\n";
  1261. } else {
  1262. echo ' <li><a href="'.$feedlink.'" title="'.__('Subscribe to the main RSS Feed with any feed reader', 'podpress').'"><img src="'.podPress_url().'images/feed_button-rss-blog.png" class="podpress_feed_buttons" alt="'.__('Subscribe to the RSS Feed', 'podpress').'" /></a></li>'."\n";
  1263. }
  1264. }
  1265. if($instance['comments']) {
  1266. if ( FALSE == empty($instance['comments_altfeedurl']) ) {
  1267. $feedlink = $instance['comments_altfeedurl'];
  1268. } else {
  1269. $feedlink = get_bloginfo('comments_rss2_url');
  1270. }
  1271. if ( FALSE == empty($instance['comments_buttonurl']) ) {
  1272. echo ' <li><a href="'.$feedlink.'" title="'.__('Subscribe to the comments RSS Feed with any feed reader', 'podpress').'"><img src="'.$instance['comments_buttonurl'].'" class="podpress_feed_buttons" alt="'.__('Subscribe to the comments RSS Feed', 'podpress').'" /></a></li>'."\n";
  1273. } else {
  1274. echo ' <li><a href="'.$feedlink.'" title="'.__('Subscribe to the comments RSS Feed with any feed reader', 'podpress').'"><img src="'.podPress_url().'images/feed_button-rss-comments.png" class="podpress_feed_buttons" alt="'.__('Subscribe to the comments RSS Feed', 'podpress').'" /></a></li>'."\n";
  1275. }
  1276. }
  1277. if($instance['entries-atom']) {
  1278. if ( FALSE == empty($instance['entries-atom_altfeedurl']) ) {
  1279. $feedlink = $instance['entries-atom_altfeedurl'];
  1280. } else {
  1281. $feedlink = get_bloginfo('atom_url');
  1282. }
  1283. if ( FALSE == empty($instance['entries-atom_buttonurl']) ) {
  1284. echo ' <li><a href="'.$feedlink.'" title="'.__('Subscribe to the main ATOM Feed with any feed reader', 'podpress').'"><img src="'.$instance['entries-atom_buttonurl'].'" class="podpress_feed_buttons" alt="'.__('Subscribe to the ATOM Feed', 'podpress').'" /></a></li>'."\n";
  1285. } else {
  1286. echo ' <li><a href="'.$feedlink.'" title="'.__('Subscribe to the main ATOM Feed with any feed reader', 'podpress').'"><img src="'.podPress_url().'images/feed_button-atom-blog.png" class="podpress_feed_buttons" alt="'.__('Subscribe to the ATOM Feed', 'podpress').'" /></a></li>'."\n";
  1287. }
  1288. }
  1289. if($instance['comments-atom']) {
  1290. if ( FALSE === empty($instance['comments-atom_altfeedurl']) ) {
  1291. $feedlink = $instance['comments-atom_altfeedurl'];
  1292. } else {
  1293. $feedlink = get_bloginfo('comments_atom_url');
  1294. }
  1295. if ( FALSE == empty($instance['comments-atom_buttonurl']) ) {
  1296. echo ' <li><a href="'.$feedlink.'" title="'.__('Subscribe to the comments ATOM Feed with any feed reader', 'podpress').'"><img src="'.$instance['comments-atom_buttonurl'].'" class="podpress_feed_buttons" alt="'.__('Subscribe to the comments ATOM Feed', 'podpress').'" /></a></li>'."\n";
  1297. } else {
  1298. echo ' <li><a href="'.$feedlink.'" title="'.__('Subscribe to the comments ATOM Feed with any feed reader', 'podpress').'"><img src="'.podPress_url().'images/feed_button-atom-comments.png" class="podpress_feed_buttons" alt="'.__('Subscribe to the comments ATOM Feed', 'podpress').'" /></a></li>'."\n";
  1299. }
  1300. }
  1301. if ( is_array($instance['catcast']) AND FALSE == empty($instance['catcast']) ) {
  1302. foreach ($instance['catcast'] as $cat_id => $catcast_options) {
  1303. if ( 'yes' === $catcast_options['use'] ) {
  1304. if ( FALSE == empty($catcast_options['altfeedurl']) ) {
  1305. $cat_feed_link = $catcast_options['altfeedurl'];
  1306. } else {
  1307. if (TRUE == version_compare($wp_version, '2.9.3','>') ) {
  1308. $cat_feed_link = get_term_feed_link($cat_id);
  1309. } else {
  1310. $cat_feed_link = get_category_feed_link($cat_id);
  1311. }
  1312. }
  1313. if ( FALSE == empty($catcast_options['buttonurl']) ) {
  1314. echo ' <li><a href="'.$cat_feed_link.'" title="'.__('Subscribe to this Category RSS Feed with any feed reader', 'podpress').'"><img src="'.$catcast_options['buttonurl'].'" class="podpress_feed_buttons" alt="'.esc_attr(sprintf(__('Category "%1$s" RSS Feed', 'podpress'), get_cat_name($cat_id))).'" /></a></li>'."\n";
  1315. } else {
  1316. echo ' <li><a href="'.$cat_feed_link.'" title="'.__('Subscribe to this Category RSS Feed with any feed reader', 'podpress').'">'.$feed_icon.' '.sprintf(__('Category "%1$s" RSS Feed', 'podpress'), get_cat_name($cat_id)).'</a></li>'."\n";
  1317. }
  1318. }
  1319. }
  1320. }
  1321. break;
  1322. case 'text' :
  1323. if ($instance['itunes']) {
  1324. // for more info: http://www.apple.com/itunes/podcasts/specs.html#linking
  1325. if ($instance['iprot'] ) {
  1326. echo ' <li><a href="itpc://'.preg_replace('/^https?:\/\//i', '', $podPress->settings['podcastFeedURL']).'"';
  1327. } else {
  1328. echo ' <li><a href="http://www.itunes.com/podcast?id='.$podPress->settings['iTunes']['FeedID'].'"';
  1329. }
  1330. echo ' title="'.__('Subscribe to the Podcast Feed with iTunes', 'podpress').'">'.$feed_icon.' '.__('Subscribe with iTunes', 'podpress').'</a></li>'."\n";
  1331. }
  1332. // podPress feeds:
  1333. if ( is_array($instance['podpressfeeds']) AND FALSE == empty($instance['podpressfeeds']) ) {
  1334. foreach ($instance['podpressfeeds'] as $feed_slug => $feed_options) {
  1335. if ( 'yes' === $feed_options['use'] AND is_array($podPress->settings['podpress_feeds']) ) {
  1336. foreach ( $podPress->settings['podpress_feeds'] AS $feed ) {
  1337. if ( $feed_slug === $feed['slug'] AND TRUE === $feed['use'] ) {
  1338. if ( FALSE == empty($feed_options['altfeedurl']) ) {
  1339. $feed_link = $feed_options['altfeedurl'];
  1340. } else {
  1341. $feed_link = get_feed_link($feed_slug);
  1342. }
  1343. if ( FALSE == empty($feed['slug']) ) {
  1344. $descr = stripslashes($feed['descr']);
  1345. } else {
  1346. $descr = __('Subscribe to this Feed with any feed reader', 'podpress');
  1347. }
  1348. echo ' <li><a href="'.$feed_link.'" title="'.esc_attr($descr).'">'.$feed_icon.' '.stripslashes($feed['name']).'</a></li>'."\n";
  1349. }
  1350. }
  1351. }
  1352. }
  1353. }
  1354. if($instance['posts']) {
  1355. if ( FALSE == empty($instance['posts_altfeedurl']) ) {
  1356. $feedlink = $instance['posts_altfeedurl'];
  1357. } else {
  1358. $feedlink = get_bloginfo('rss2_url');
  1359. }
  1360. echo ' <li><a href="'.$feedlink.'" title="'.__('Subscribe to the main RSS Feed with any feed reader', 'podpress').'">'.$feed_icon.' '.__('Entries RSS Feed', 'podpress').'</a></li>'."\n";
  1361. }
  1362. if($instance['comments']) {
  1363. if ( FALSE == empty($instance['comments_altfeedurl']) ) {
  1364. $feedlink = $instance['comments_altfeedurl'];
  1365. } else {
  1366. $feedlink = get_bloginfo('comments_rss2_url');
  1367. }
  1368. echo ' <li><a href="'.$feedlink.'" title="'.__('Subscribe to the comments RSS Feed with any feed reader', 'podpress').'">'.$feed_icon.' '.__('Comments RSS Feed', 'podpress').'</a></li>'."\n";
  1369. }
  1370. if($instance['entries-atom']) {
  1371. if ( FALSE == empty($instance['entries-atom_altfeedurl']) ) {
  1372. $feedlink = $instance['entries-atom_altfeedurl'];
  1373. } else {
  1374. $feedlink = get_bloginfo('atom_url');
  1375. }
  1376. echo ' <li><a href="'.$feedlink.'" title="'.__('Subscribe to the main ATOM Feed with any feed reader', 'podpress').'">'.$feed_icon.' '.__('Entries ATOM Feed', 'podpress').'</a></li>'."\n";
  1377. }
  1378. if($instance['comments-atom']) {
  1379. if ( FALSE === empty($instance['comments-atom_altfeedurl']) ) {
  1380. $feedlink = $instance['comments-atom_altfeedurl'];
  1381. } else {
  1382. $feedlink = get_bloginfo('comments_atom_url');
  1383. }
  1384. echo ' <li><a href="'.$feedlink.'" title="'.__('Subscribe to the comments ATOM Feed with any feed reader', 'podpress').'">'.$feed_icon.' '.__('Comments ATOM Feed', 'podpress').'</a></li>'."\n";
  1385. }
  1386. if ( is_array($instance['catcast']) AND FALSE == empty($instance['catcast']) ) {
  1387. foreach ($instance['catcast'] as $cat_id => $catcast_options) {
  1388. if ( 'yes' === $catcast_options['use'] ) {
  1389. if ( FALSE == empty($catcast_options['altfeedurl']) ) {
  1390. $cat_feed_link = $catcast_options['altfeedurl'];
  1391. } else {
  1392. if (TRUE == version_compare($wp_version, '2.9.3','>') ) {
  1393. $cat_feed_link = get_term_feed_link($cat_id);
  1394. } else {
  1395. $cat_feed_link = get_category_feed_link($cat_id);
  1396. }
  1397. }
  1398. echo ' <li><a href="'.$cat_feed_link.'" title="'.__('Subscribe to this Category RSS Feed with any feed reader', 'podpress').'">'.$feed_icon.' '.sprintf(__('Category "%1$s" RSS Feed', 'podpress'), get_cat_name($cat_id)).'</a></li>'."\n";
  1399. }
  1400. }
  1401. }
  1402. break;
  1403. }
  1404. echo "</ul>\n";
  1405. echo $after_widget;
  1406. }
  1407. /** @see WP_Widget::update */
  1408. function update($new_instance, $old_instance) {
  1409. $blog_charset = get_bloginfo('charset');
  1410. $instance = $old_instance;
  1411. $instance['title'] = htmlspecialchars(strip_tags(trim($new_instance['title'])), ENT_QUOTES, $blog_charset);
  1412. $instance['posts'] = $new_instance['posts'];
  1413. $instance['comments'] = $new_instance['comments'];
  1414. $instance['entries-atom'] = $new_instance['entries-atom'];
  1415. $instance['comments-atom'] = $new_instance['comments-atom'];
  1416. $instance['posts_buttonurl'] = clean_url($new_instance['posts_buttonurl'], array('http', 'https'), 'db');
  1417. $instance['comments_buttonurl'] = clean_url($new_instance['comments_buttonurl'], array('http', 'https'), 'db');
  1418. $instance['entries-atom_buttonurl'] = clean_url($new_instance['entries-atom_buttonurl'], array('http', 'https'), 'db');
  1419. $instance['comments-atom_buttonurl'] = clean_url($new_instance['comments-atom_buttonurl'], array('http', 'https'), 'db');
  1420. $instance['posts_altfeedurl'] = clean_url($new_instance['posts_altfeedurl'], array('http', 'https'), 'db');
  1421. $instance['comments_altfeedurl'] = clean_url($new_instance['comments_altfeedurl'], array('http', 'https'), 'db');
  1422. $instance['entries-atom_altfeedurl'] = clean_url($new_instance['entries-atom_altfeedurl'], array('http', 'https'), 'db');
  1423. $instance['comments-atom_altfeedurl'] = clean_url($new_instance['comments-atom_altfeedurl'], array('http', 'https'), 'db');
  1424. $instance['itunes'] = $new_instance['itunes'];
  1425. $instance['itunes_buttonurl'] = clean_url($new_instance['itunes_buttonurl'], array('http', 'https'), 'db');
  1426. $instance['iprot'] = $new_instance['iprot'];
  1427. $instance['buttons-or-text'] = $new_instance['buttons-or-text'];
  1428. // CategoryCasting Feeds:
  1429. if ( is_array($new_instance['catcast']) ) {
  1430. foreach ( $new_instance['catcast'] as $cat_id => $feed_options ) {
  1431. if ( 'yes' === $feed_options['use'] ) {
  1432. $instance['catcast'][$cat_id]['use'] = 'yes';
  1433. } else {
  1434. $instance['catcast'][$cat_id]['use'] = 'no';
  1435. }
  1436. $instance['catcast'][$cat_id]['buttonurl'] = clean_url($feed_options['buttonurl'], array('http', 'https'), 'db');
  1437. $instance['catcast'][$cat_id]['altfeedurl'] = clean_url($feed_options['altfeedurl'], array('http', 'https'), 'db');
  1438. }
  1439. }
  1440. // podPress Feeds:
  1441. if ( is_array($new_instance['podpressfeeds']) ) {
  1442. foreach ( $new_instance['podpressfeeds'] as $feed_slug => $feed_options ) {
  1443. if ( 'yes' === $feed_options['use'] ) {
  1444. $instance['podpressfeeds'][$feed_slug]['use'] = 'yes';
  1445. } else {
  1446. $instance['podpressfeeds'][$feed_slug]['use'] = 'no';
  1447. }
  1448. $instance['podpressfeeds'][$feed_slug]['button'] = $feed_options['button'];
  1449. if ( 'custom' === $feed_options['button'] ) {
  1450. $instance['podpressfeeds'][$feed_slug]['buttonurl'] = clean_url($feed_options['buttonurl'], array('http', 'https'), 'db');
  1451. } else {
  1452. $instance['podpressfeeds'][$feed_slug]['buttonurl'] = PODPRESS_URL.'/images/'.$feed_options['button'];
  1453. }
  1454. $instance['podpressfeeds'][$feed_slug]['altfeedurl'] = clean_url($feed_options['altfeedurl'], array('http', 'https'), 'db');
  1455. }
  1456. }
  1457. // delete the old widget settings
  1458. $old_widget_options = get_option('widget_podPressFeedButtons');
  1459. if ( FALSE !== $old_widget_options ) {
  1460. delete_option('widget_podPressFeedButtons');
  1461. }
  1462. return $instance;
  1463. }
  1464. /** @see WP_Widget::form */
  1465. function form($instance) {
  1466. GLOBAL $podPress, $wpdb;
  1467. // take over the old widget settings (of podPress 8.8.5.x widgets)
  1468. $old_widget_options = get_option('widget_podPressFeedButtons');
  1469. if ( TRUE == is_array($old_widget_options) AND FALSE == empty($old_widget_options) ) {
  1470. $instance['title'] = $old_widget_options['title'];
  1471. $instance['posts'] = $old_widget_options['blog'];
  1472. $instance['comments'] = $old_widget_options['comments'];
  1473. $instance['entries-atom'] = $old_widget_options['entries-atom'];
  1474. $instance['comments-atom'] = $old_widget_options['comments-atom'];
  1475. $instance['itunes'] = $old_widget_options['itunes'];
  1476. $instance['iprot'] = $old_widget_options['iprot'];
  1477. $instance['buttons-or-text'] = $old_widget_options['buttons-or-text'];
  1478. }
  1479. // first time use - default settings
  1480. if (!isset($instance['posts'])) {
  1481. $instance['posts'] = false;
  1482. }
  1483. if (!isset($instance['comments'])) {
  1484. $instance['comments'] = false;
  1485. }
  1486. if (!isset($instance['entries-atom'])) {
  1487. $instance['entries-atom'] = false;
  1488. }
  1489. if (!isset($instance['comments-atom'])) {
  1490. $instance['comments-atom'] = false;
  1491. }
  1492. if (!isset($instance['itunes'])) {
  1493. $instance['itunes'] = false;
  1494. }
  1495. if (!isset($instance['iprot'])) {
  1496. $instance['iprot'] = false;
  1497. }
  1498. if (!isset($instance['buttons-or-text'])) {
  1499. $instance['buttons-or-text'] = 'buttons';
  1500. }
  1501. if (!isset($instance['itunes_buttonurl'])) {
  1502. $instance['itunes_buttonurl'] = PODPRESS_URL.'/images/itunes.png';
  1503. }
  1504. if (!isset($instance['posts_buttonurl'])) {
  1505. $instance['posts_buttonurl'] = PODPRESS_URL.'/images/feed_button-rss-blog.png';
  1506. }
  1507. if (!isset($instance['comments_buttonurl'])) {
  1508. $instance['comments_buttonurl'] = PODPRESS_URL.'/images/feed_button-rss-comments.png';
  1509. }
  1510. if (!isset($instance['entries-atom_buttonurl'])) {
  1511. $instance['entries-atom_buttonurl'] = PODPRESS_URL.'/images/feed_button-atom-blog.png';
  1512. }
  1513. if (!isset($instance['comments-atom_buttonurl'])) {
  1514. $instance['comments-atom_buttonurl'] = PODPRESS_URL.'/images/feed_button-atom-comments.png';
  1515. }
  1516. $blog = $instance['posts'] ? 'checked="checked"' : '';
  1517. $comments = $instance['comments'] ? 'checked="checked"' : '';
  1518. $entries_atom = $instance['entries-atom'] ? 'checked="checked"' : '';
  1519. $comments_atom = $instance['comments-atom'] ? 'checked="checked"' : '';
  1520. $itunes = $instance['itunes'] ? 'checked="checked"' : '';
  1521. $iprot = $instance['iprot'] ? 'checked="checked"' :'';
  1522. if ( 'text' == $instance['buttons-or-text'] ) {
  1523. $text = 'checked="checked"';
  1524. $buttons = '';
  1525. } else {
  1526. $text = '';
  1527. $buttons = 'checked="checked"';
  1528. }
  1529. if(!isset($instance['title'])) {
  1530. $instance['title'] = __('Podcast Feeds', 'podpress');
  1531. }
  1532. $title = esc_attr(stripslashes($instance['title']));
  1533. ?>
  1534. <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'podpress'); ?></label> <input class="podpress_widget_settings_title" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p>
  1535. <p><?php _e('Show the buttons for the following feeds:', 'podpress'); ?></p>
  1536. <div id="<?php echo $this->get_field_id('podpress_widget_accordion'); ?>" class="podpress_widget_accordion"><!-- Begin: podPress Widget Accordion -->
  1537. <h5><a href=""><?php _e('iTunes Button', 'podpress'); ?></a></h5>
  1538. <div>
  1539. <input type="checkbox" <?php echo $itunes; ?> id="<?php echo $this->get_field_id('itunes'); ?>" name="<?php echo $this->get_field_name('itunes'); ?>" /> <label for="<?php echo $this->get_field_id('itunes'); ?>"><?php printf(__('Show %1$s button', 'podpress'), __('iTunes', 'podpress')); ?></label><br />
  1540. <input type="checkbox" <?php echo $iprot; ?> id="<?php echo $this->get_field_id('iprot'); ?>" name="<?php echo $this->get_field_name('iprot'); ?>" /> <label for="<?php echo $this->get_field_id('iprot'); ?>"><?php _e('Use iTunes protocol for URL', 'podpress'); ?> <?php _e('(itpc://)', 'podpress'); ?></label><br />
  1541. <span class="nonessential"><?php _e('The user subscribes immediatly with the click. Otherwise the iTunes Store page of the podcast will be displayed first and the user can subscribe manually.', 'podpress'); ?></span><br />
  1542. <label for="<?php echo $this->get_field_id('itunes_buttonurl'); ?>"><?php _e('Button URL:', 'podpress'); ?></label> <input type="text" id="<?php echo $this->get_field_id('itunes_buttonurl'); ?>" name="<?php echo $this->get_field_name('itunes_buttonurl'); ?>" class="widefat" value="<?php echo $instance['itunes_buttonurl']; ?>" />
  1543. </div>
  1544. <?php
  1545. $feedbuttons = podpress_get_feed_buttons();
  1546. if ( is_array($podPress->settings['podpress_feeds']) AND FALSE == empty($podPress->settings['podpress_feeds']) ) {
  1547. foreach ($podPress->settings['podpress_feeds'] as $feed) {
  1548. if ( TRUE === $feed['use'] AND FALSE == empty($feed['slug']) ) {
  1549. if ( FALSE == empty($feed['descr']) ) {
  1550. $descr = '<br /><span class="nonessential">'.stripslashes($feed['descr']).'</span>';
  1551. } else {
  1552. $descr = '';
  1553. }
  1554. // take over the old widget settings (of podPress 8.8.5.x widgets)
  1555. if ( TRUE == is_array($old_widget_options) AND FALSE == empty($old_widget_options) ) {
  1556. Switch ($feed['slug']) {
  1557. case 'podcast' :
  1558. case 'enhancedpodcast' :
  1559. case 'torrent' :
  1560. $instance['podpressfeeds'][$feed['slug']]['use'] = $old_widget_options[$feed['slug']];
  1561. if ( 'podcast' === $feed['slug'] ) {
  1562. $instance['podpressfeeds'][$feed['slug']]['button'] = 'feed_button-rss-'.$feed['slug'].'.png';
  1563. } else {
  1564. $instance['podpressfeeds'][$feed['slug']]['button'] = 'feed_button-'.$feed['slug'].'.png';
  1565. }
  1566. break;
  1567. }
  1568. }
  1569. if ( TRUE == isset($instance['podpressfeeds'][$feed['slug']]['use']) AND 'yes' == $instance['podpressfeeds'][$feed['slug']]['use'] ) {
  1570. $podpressfeed_checked = ' checked="checked"';
  1571. } else {
  1572. $podpressfeed_checked = '';
  1573. }
  1574. echo '<h5><a href="">'.stripslashes($feed['name']).'</a></h5>'."\n";
  1575. echo '<div class="podpress_widget_settings_row_div">'."\n";
  1576. echo '<input type="checkbox"'.$podpressfeed_checked.' id="'.$this->get_field_id($feed['slug'].'_use').'" name="'.$this->get_field_name('podpressfeeds').'['.$feed['slug'].'][use]" value="yes" /> <label for="'.$this->get_field_id($feed['slug'].'_use').'">'.sprintf(__('Show %1$s button', 'podpress'), stripslashes($feed['name'])).'</label>'."\n";
  1577. echo $descr."\n";
  1578. echo '<br />'.__('Select a feed button:', 'podpress').'<br />'."\n";
  1579. echo '<span class="podpress_feedbuttonsselectbox">'."\n";
  1580. $id_base = $this->get_field_id($feed['slug'].'_'.$feed['button']);
  1581. $i=0;
  1582. $feedbutton_checked_nr = 0;
  1583. foreach ($feedbuttons as $feedbutton) {
  1584. if ( TRUE == isset($instance['podpressfeeds'][$feed['slug']]['button']) AND $feedbutton == $instance['podpressfeeds'][$feed['slug']]['button'] ) {
  1585. $feedbutton_checked_nr = $i;
  1586. }
  1587. $i++;
  1588. }
  1589. $i=0;
  1590. foreach ($feedbuttons as $feedbutton) {
  1591. if ( $i == $feedbutton_checked_nr ) {
  1592. $feedbutton_checked = ' checked="checked"';
  1593. } else {
  1594. $feedbutton_checked = '';
  1595. }
  1596. echo '<input type="radio" name="'.$this->get_field_name('podpressfeeds').'['.$feed['slug'].'][button]" id="'.$id_base.''.$i.'" value="'.$feedbutton.'"'.$feedbutton_checked.' /> <label for="'.$id_base.''.$i.'"><img src="'.PODPRESS_URL.'/images/'.$feedbutton.'" alt="'.$feedbutton.'" title="'.$feedbutton.'" /></label><br />'."\n";
  1597. $i++;
  1598. }
  1599. if ( TRUE == isset($instance['podpressfeeds'][$feed['slug']]['button']) AND 'custom' == $instance['podpressfeeds'][$feed['slug']]['button'] ) {
  1600. echo '<input type="radio" name="'.$this->get_field_name('podpressfeeds').'['.$feed['slug'].'][button]" id="'.$id_base.''.$i.'" value="custom" checked="checked" /> <input type="text" id="'.$this->get_field_id($feed['slug'].'_'.$feed['custombuttonurl']).'" name="'.$this->get_field_name('podpressfeeds').'['.$feed['slug'].'][buttonurl]" class="widefat podpress_customfeedbuttonurl" value="'.$instance['podpressfeeds'][$feed['slug']]['buttonurl'].'" />'."\n";
  1601. } else {
  1602. echo '<label for="'.$this->get_field_id($feed['slug'].'_'.$feed['custombuttonurl']).'"><input type="radio" name="'.$this->get_field_name('podpressfeeds').'['.$feed['slug'].'][button]" id="'.$id_base.''.$i.'" value="custom" /></label> <input type="text" id="'.$this->get_field_id($feed['slug'].'_'.$feed['custombuttonurl']).'" name="'.$this->get_field_name('podpressfeeds').'['.$feed['slug'].'][buttonurl]" class="widefat podpress_customfeedbuttonurl" value="" />'."\n";
  1603. }
  1604. echo '</span>'."\n";
  1605. echo '<label for="'.$this->get_field_id($feed['slug'].'_altfeedurl').'">'.__('Alternative Feed URL:', 'podpress').'</label> <input type="text" id="'.$this->get_field_id($feed['slug'].'_altfeedurl').'" name="'.$this->get_field_name('podpressfeeds').'['.$feed['slug'].'][altfeedurl]" class="widefat" value="'.$instance['podpressfeeds'][$feed['slug']]['altfeedurl'].'" />'."\n";
  1606. echo '</div>'."\n";
  1607. }
  1608. }
  1609. }
  1610. ?>
  1611. <h5><a href=""><?php _e('Entries RSS Feed', 'podpress'); ?></a></h5>
  1612. <div>
  1613. <input type="checkbox" <?php echo $blog; ?> id="<?php echo $this->get_field_id('posts'); ?>" name="<?php echo $this->get_field_name('posts'); ?>" /> <label for="<?php echo $this->get_field_id('posts'); ?>"><?php printf(__('Show %1$s button', 'podpress'), __('Entries RSS Feed', 'podpress')); ?></label><br />
  1614. <label for="<?php echo $this->get_field_id('posts_buttonurl'); ?>"><?php _e('Button URL:', 'podpress'); ?></label> <input type="text" id="<?php echo $this->get_field_id('posts_buttonurl'); ?>" name="<?php echo $this->get_field_name('posts_buttonurl'); ?>" class="widefat" value="<?php echo $instance['posts_buttonurl']; ?>" /><br />
  1615. <label for="<?php echo $this->get_field_id('posts_altfeedurl'); ?>"><?php _e('Alternative Feed URL:', 'podpress'); ?></label> <input type="text" id="<?php echo $this->get_field_id('posts_altfeedurl'); ?>" name="<?php echo $this->get_field_name('posts_altfeedurl'); ?>" class="widefat" value="<?php echo $instance['posts_altfeedurl']; ?>" />
  1616. </div>
  1617. <h5><a href=""><?php _e('Comments RSS Feed', 'podpress'); ?></a></h5>
  1618. <div>
  1619. <input type="checkbox" <?php echo $comments; ?> id="<?php echo $this->get_field_id('comments'); ?>" name="<?php echo $this->get_field_name('comments'); ?>" /> <label for="<?php echo $this->get_field_id('comments'); ?>"><?php printf(__('Show %1$s button', 'podpress'), __('Comments RSS Feed', 'podpress')); ?></label><br />
  1620. <label for="<?php echo $this->get_field_id('comments_buttonurl'); ?>"><?php _e('Button URL:', 'podpress'); ?></label> <input type="text" id="<?php echo $this->get_field_id('comments_buttonurl'); ?>" name="<?php echo $this->get_field_name('comments_buttonurl'); ?>" class="widefat" value="<?php echo $instance['comments_buttonurl']; ?>" /><br />
  1621. <label for="<?php echo $this->get_field_id('comments_altfeedurl'); ?>"><?php _e('Alternative Feed URL:', 'podpress'); ?></label> <input type="text" id="<?php echo $this->get_field_id('comments_altfeedurl'); ?>" name="<?php echo $this->get_field_name('comments_altfeedurl'); ?>" class="widefat" value="<?php echo $instance['comments_altfeedurl']; ?>" />
  1622. </div>
  1623. <h5><a href=""><?php _e('Entries ATOM Feed', 'podpress'); ?></a></h5>
  1624. <div>
  1625. <input type="checkbox" <?php echo $entries_atom; ?> id="<?php echo $this->get_field_id('entries-atom'); ?>" name="<?php echo $this->get_field_name('entries-atom'); ?>" /> <label for="<?php echo $this->get_field_id('entries-atom'); ?>"><?php printf(__('Show %1$s button', 'podpress'), __('Entries ATOM Feed', 'podpress')); ?></label><br />
  1626. <label for="<?php echo $this->get_field_id('entries-atom_buttonurl'); ?>"><?php _e('Button URL:', 'podpress'); ?></label> <input type="text" id="<?php echo $this->get_field_id('entries-atom_buttonurl'); ?>" name="<?php echo $this->get_field_name('entries-atom_buttonurl'); ?>" class="widefat" value="<?php echo $instance['entries-atom_buttonurl']; ?>" /><br />
  1627. <label for="<?php echo $this->get_field_id('entries-atom_altfeedurl'); ?>"><?php _e('Alternative Feed URL:', 'podpress'); ?></label> <input type="text" id="<?php echo $this->get_field_id('entries-atom_altfeedurl'); ?>" name="<?php echo $this->get_field_name('entries-atom_altfeedurl'); ?>" class="widefat" value="<?php echo $instance['entries-atom_altfeedurl']; ?>" />
  1628. </div>
  1629. <h5><a href=""><?php _e('Comments ATOM Feed', 'podpress'); ?></a></h5>
  1630. <div>
  1631. <input type="checkbox" <?php echo $comments_atom; ?> id="<?php echo $this->get_field_id('comments-atom'); ?>" name="<?php echo $this->get_field_name('comments-atom'); ?>" /> <label for="<?php echo $this->get_field_id('comments-atom'); ?>"><?php printf(__('Show %1$s button', 'podpress'), __('Comments ATOM Feed', 'podpress')); ?></label><br />
  1632. <label for="<?php echo $this->get_field_id('comments-atom_buttonurl'); ?>"><?php _e('Button URL:', 'podpress'); ?></label> <input type="text" id="<?php echo $this->get_field_id('comments-atom_buttonurl'); ?>" name="<?php echo $this->get_field_name('comments-atom_buttonurl'); ?>" class="widefat" value="<?php echo $instance['comments-atom_buttonurl']; ?>" /><br />
  1633. <label for="<?php echo $this->get_field_id('comments-atom_altfeedurl'); ?>"><?php _e('Alternative Feed URL:', 'podpress'); ?></label> <input type="text" id="<?php echo $this->get_field_id('comments-atom_altfeedurl'); ?>" name="<?php echo $this->get_field_name('comments-atom_altfeedurl'); ?>" class="widefat" value="<?php echo $instance['comments-atom_altfeedurl']; ?>" />
  1634. </div>
  1635. <?php
  1636. $query_string = 'SELECT option_name, option_value FROM '.$wpdb->prefix.'options WHERE INSTR(option_name, "podPress_category_")';
  1637. $category_feeds = $wpdb->get_results($query_string);
  1638. if ( isset($category_feeds) AND FALSE == empty($category_feeds) ) {
  1639. foreach ($category_feeds as $feed_options) {
  1640. $feed = maybe_unserialize($feed_options->option_value);
  1641. if ( isset($feed['categoryCasting']) AND 'true' == $feed['categoryCasting'] ) {
  1642. $cat_id = end(explode('_', $feed_options->option_name));
  1643. $checked = $instance['catcast'][$cat_id]['use'] == 'yes' ? 'checked="checked"' :'';
  1644. echo '<h5><a href="">'.sprintf(__('Category "%1$s" RSS Feed', 'podpress'), get_cat_name($cat_id)).'</a></h5>'."\n";
  1645. echo '<div>'."\n";
  1646. echo '<input type="checkbox" '.$checked.' id="'.$this->get_field_id('catcast_'.$cat_id.'_use').'" name="'.$this->get_field_name('catcast').'['.$cat_id.'][use]" value="yes" /> <label for="'.$this->get_field_id('catcast_'.$cat_id.'_use').'">'.sprintf( __('Show %1$s button', 'podpress'), sprintf(__('Category "%1$s" RSS Feed', 'podpress'), get_cat_name($cat_id)) ).'</label><br />'."\n";
  1647. echo '<label for="'.$this->get_field_id('catcast_'.$cat_id.'_buttonurl').'">'.__('Button URL:', 'podpress').'</label> <input type="text" id="'.$this->get_field_id('catcast_'.$cat_id.'_buttonurl').'" name="'.$this->get_field_name('catcast').'['.$cat_id.'][buttonurl]" class="widefat" value="'.$instance['catcast'][$cat_id]['buttonurl'].'" /><br />'."\n";
  1648. echo '<label for="'.$this->get_field_id('catcast_'.$cat_id.'_altfeedurl').'">'.__('Alternative Feed URL:', 'podpress').'</label> <input type="text" id="'.$this->get_field_id('catcast_'.$cat_id.'_altfeedurl').'" name="'.$this->get_field_name('catcast').'['.$cat_id.'][altfeedurl]" class="widefat" value="'.$instance['catcast'][$cat_id]['altfeedurl'].'" />'."\n";
  1649. echo '</div>'."\n";
  1650. }
  1651. }
  1652. }
  1653. ?>
  1654. </div><!-- End: podPress Widget Accordion -->
  1655. <p class="podpress_widget_settings_row">
  1656. <?php _e('Show buttons or text?', 'podpress'); ?><br />
  1657. <label for="<?php echo $this->get_field_id('buttons'); ?>"><?php _e('Buttons', 'podpress'); ?></label> <input type="radio" <?php echo $buttons; ?> value="buttons" id="<?php echo $this->get_field_id('buttons'); ?>" name="<?php echo $this->get_field_name('buttons-or-text'); ?>" /> <input type="radio" <?php echo $text; ?> value="text" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('buttons-or-text'); ?>" /> <label for="<?php echo $this->get_field_id('text'); ?>"><?php _e('Text', 'podpress'); ?></label>
  1658. </p>
  1659. <?php
  1660. }
  1661. } // class podPress Feed Buttons Widget
  1662. }
  1663. /**
  1664. * podpress_get_feed_buttons - retrieves a list of all feed button files from a certian directory
  1665. *
  1666. * @package podPress
  1667. * @since 8.8.8
  1668. *
  1669. * @param str $dir (optional) - the full directory name of the directory which inludes the feed buttons
  1670. * @param str $exceptions (optional) - an Array of names of files which should not be in the result list / if it is empty then it means no exceptions
  1671. * @param str $needle (optional) - a string which should be a part of the file names
  1672. *
  1673. * @return Array all file which inlude "feed_button" in their names or an empty array
  1674. */
  1675. function podpress_get_feed_buttons($dir = '', $exceptions = Array('feed_button-atom-blog.png', 'feed_button-atom-comments.png', 'feed_button-rss-blog.png', 'feed_button-rss-comments.png'), $needle = '') {
  1676. if ( FALSE != empty($dir) OR FALSE == is_dir($dir) ) {
  1677. $dir = PODPRESS_DIR.'/images/';
  1678. }
  1679. if ( FALSE == is_dir($dir) OR FALSE == is_readable($dir) ) {
  1680. return Array();
  1681. }
  1682. if ( FALSE != empty($exceptions) ) {
  1683. $use_exceptions = FALSE;
  1684. } else {
  1685. $use_exceptions = TRUE;
  1686. }
  1687. if ( FALSE != empty($needle) ) {
  1688. $needle = 'feed_button';
  1689. }
  1690. $feed_buttons= Array();
  1691. if ( $handle = opendir($dir) ) {
  1692. while ( false !== ($file = readdir($handle)) ) {
  1693. if ( $file != "." AND $file != ".." AND FALSE !== stripos($file, $needle) ) {
  1694. if ( TRUE === $use_exceptions ) {
  1695. if ( FALSE == in_array($file, $exceptions) ) {
  1696. $feed_buttons[] = $file;
  1697. }
  1698. } else {
  1699. $feed_buttons[] = $file;
  1700. }
  1701. }
  1702. }
  1703. closedir($handle);
  1704. }
  1705. sort($feed_buttons);
  1706. return $feed_buttons;
  1707. }
  1708. /**
  1709. * podPress XSPF Player Widget Class
  1710. * since podPress v8.8.7 beta 2
  1711. * for WP >= 2.8
  1712. */
  1713. if ( TRUE == version_compare($wp_version, '2.8', '>=') ) {
  1714. class podpress_xspfplayer extends WP_Widget {
  1715. /** constructor */
  1716. function podpress_xspfplayer() {
  1717. $widget_ops = array(
  1718. 'classname' => 'podpress_xspfplayer',
  1719. 'description' => __('Shows a XSPF Player in the sidebar which uses e.g. the XSPF playlist of your podcast episodes', 'podpress')
  1720. );
  1721. $control_ops = array('width' => 400, 'height' => 300);
  1722. parent::WP_Widget(false, $name = __('podPress - XSPF Player','podpress'), $widget_ops, $control_ops);
  1723. }
  1724. /** @see WP_Widget::widget */
  1725. function widget($args, $instance) {
  1726. GLOBAL $podPress, $blog_id;
  1727. extract($args);
  1728. if (!isset($instance['title'])) {
  1729. $instance['title'] = __('Podcast Player', 'podpress');
  1730. } else {
  1731. $instance['title'] = stripslashes($instance['title']);
  1732. }
  1733. $title = apply_filters('widget_title', $instance['title']);
  1734. if (!isset($instance['useSlimPlayer'])) {
  1735. $instance['useSlimPlayer'] = false;
  1736. }
  1737. if ( 150 > intval($instance['PlayerWidth']) ) {
  1738. $instance['PlayerWidth'] = 150; // min width
  1739. }
  1740. // save the current (the first) XSPF player widget ID (of a page) in the db
  1741. $isset_podpress_xspf_widget_temp = get_option('podpress_xspf_widget_temp');
  1742. if (FALSE === $isset_podpress_xspf_widget_temp) {
  1743. update_option('podpress_xspf_widget_temp', $widget_id);
  1744. }
  1745. // podpress_xspf_widget_temp is going to be deleted from the db after the playlist has been loaded. (The XSPF loads the skin file before the playlist.)
  1746. $skin_variables_url = PODPRESS_OPTIONS_URL.'/xspf_options/variables';
  1747. $skin_variables_dir = PODPRESS_OPTIONS_DIR.'/xspf_options/variables';
  1748. $skin_file = PODPRESS_URL.'/podpress_xspfskinfile.php';
  1749. echo $before_widget."\n";
  1750. echo $before_title . $title . $after_title."\n";
  1751. if (defined('PODPRESS_ONE_XSPF_IS_ACTIVE')) {
  1752. echo '<div class="podpress_error"><p>'.__('Please use this widget only once per page.', 'podpress').'</p></div>';
  1753. } else {
  1754. define('PODPRESS_ONE_XSPF_IS_ACTIVE', TRUE);
  1755. if ( TRUE === $instance['useSlimPlayer'] ) {
  1756. if ( 30 > intval($instance['SlimPlayerHeight']) ) {
  1757. $instance['SlimPlayerHeight'] = 30; // min height slim
  1758. }
  1759. if ( TRUE == defined('PODPRESS_XSPF_PLAYER_USE_CUSTOM_SKINFILE_'.$blog_id) AND TRUE == defined('PODPRESS_XSPF_SLIM_SKIN_URL_'.$blog_id) AND TRUE == defined('PODPRESS_XSPF_SLIM_SKIN_DIR_'.$blog_id) AND TRUE == is_readable(constant('PODPRESS_XSPF_SLIM_SKIN_DIR_'.$blog_id).'/skin_'.$blog_id.'_'.$instance['PlayerWidth'].'x'.$instance['SlimPlayerHeight'].'.xml') ) {
  1760. $skin_file = constant('PODPRESS_XSPF_SLIM_SKIN_URL_'.$blog_id).'/skin_'.$blog_id.'_'.$instance['PlayerWidth'].'x'.$instance['SlimPlayerHeight'].'.xml';
  1761. }
  1762. $skin_variables_url .= '_slim';
  1763. $skin_variables_dir .= '_slim';
  1764. if ( TRUE === defined('PODPRESS_XSPF_SLIM_USE_CUSTOM_VARIABLES_'.$blog_id) AND TRUE === constant('PODPRESS_XSPF_SLIM_USE_CUSTOM_VARIABLES_'.$blog_id) AND TRUE == is_readable($skin_variables_dir.'/variables_'.$blog_id.'.txt')) {
  1765. $variables = '&skin_url='.$skin_file.'&loadurl='.$skin_variables_url.'/variables_'.$blog_id.'.txt';
  1766. } else {
  1767. if ( FALSE == isset($instance['trackinfoformat']) OR (TRUE == isset($instance['trackinfoformat']) AND '-creator : -title' == $instance['trackinfoformat']) ) {
  1768. $variables = '&skin_url='.$skin_file.'&autoload=true&autoplay=false&loaded=true';
  1769. } else {
  1770. $variables = '&skin_url='.$skin_file.'&autoload=true&autoplay=false&loaded=true&format='.$instance['trackinfoformat'];
  1771. }
  1772. }
  1773. $data_string = PODPRESS_URL.'/players/xspf_jukebox/xspf_jukebox.swf?playlist_url='.(PODPRESS_URL.'/podpress_xspfplaylist.php').$variables;
  1774. $data_string = htmlspecialchars($data_string);
  1775. echo '<object type="application/x-shockwave-flash" classid="CLSID:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'.$instance['PlayerWidth'].'" height="'.$instance['SlimPlayerHeight'].'" id="podpress_xspf_player_slim">'."\n";
  1776. $height = $instance['SlimPlayerHeight'];
  1777. } else {
  1778. if ( 100 > intval($instance['PlayerHeight']) ) {
  1779. $instance['PlayerHeight'] = 100; // min height
  1780. }
  1781. if ( TRUE == defined('PODPRESS_XSPF_PLAYER_USE_CUSTOM_SKINFILE_'.$blog_id) AND TRUE == defined('PODPRESS_XSPF_SKIN_URL_'.$blog_id) AND TRUE == defined('PODPRESS_XSPF_SKIN_DIR_'.$blog_id) AND TRUE == is_readable(constant('PODPRESS_XSPF_SKIN_DIR_'.$blog_id).'/skin_'.$blog_id.'_'.$instance['PlayerWidth'].'x'.$instance['PlayerHeight'].'.xml') ) {
  1782. $skin_file = constant('PODPRESS_XSPF_SKIN_URL_'.$blog_id).'/skin_'.$blog_id.'_'.$instance['PlayerWidth'].'x'.$instance['PlayerHeight'].'.xml';
  1783. }
  1784. if ( TRUE === defined('PODPRESS_XSPF_USE_CUSTOM_VARIABLES_'.$blog_id) AND TRUE === constant('PODPRESS_XSPF_USE_CUSTOM_VARIABLES_'.$blog_id) AND TRUE == is_readable($skin_variables_dir.'/variables_'.$blog_id.'.txt')) {
  1785. $variables = '&skin_url='.$skin_file.'&loadurl='.$skin_variables_url.'/variables_'.$blog_id.'.txt';
  1786. } else {
  1787. if ( FALSE == isset($instance['trackinfoformat']) OR (TRUE == isset($instance['trackinfoformat']) AND '-creator : -title' == $instance['trackinfoformat']) ) {
  1788. $variables = '&skin_url='.$skin_file.'&autoload=true&autoplay=false&loaded=true';
  1789. } else {
  1790. $variables = '&skin_url='.$skin_file.'&autoload=true&autoplay=false&loaded=true&format='.$instance['trackinfoformat'];
  1791. }
  1792. }
  1793. $data_string = PODPRESS_URL.'/players/xspf_jukebox/xspf_jukebox.swf?playlist_url='.(PODPRESS_URL.'/podpress_xspfplaylist.php').$variables;
  1794. $data_string = htmlspecialchars($data_string);
  1795. echo '<object type="application/x-shockwave-flash" classid="CLSID:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'.$instance['PlayerWidth'].'" height="'.$instance['PlayerHeight'].'" id="podpress_xspf_player">'."\n";
  1796. $height = $instance['PlayerHeight'];
  1797. }
  1798. echo ' <param name="movie" value="'.$data_string.'" />'."\n";
  1799. if ( defined('PODPRESS_XSPF_BACKGROUND_COLOR_'.$blog_id) AND '' !== constant('PODPRESS_XSPF_BACKGROUND_COLOR_'.$blog_id) ) {
  1800. echo ' <param name="bgcolor" value="#'.constant('PODPRESS_XSPF_BACKGROUND_COLOR_'.$blog_id).'" />'."\n";
  1801. } else {
  1802. echo ' <param name="bgcolor" value="#FFFFFF" />'."\n";
  1803. }
  1804. echo ' <param name="menu" value="true" />'."\n";
  1805. echo ' <param name="wmode" value="transparent" />'."\n";
  1806. echo ' <param name="quality" value="high" />'."\n";
  1807. echo ' <embed src="'.$data_string.'" type="application/x-shockwave-flash" width="'.$instance['PlayerWidth'].'" height="'.$height.'" wmode="transparent" quality="high" />'."\n";
  1808. echo '</object>'."\n";
  1809. }
  1810. echo $after_widget;
  1811. }
  1812. /** @see WP_Widget::update */
  1813. function update($new_instance, $old_instance) {
  1814. GLOBAL $blog_id;
  1815. $blog_charset = get_bloginfo('charset');
  1816. $instance = $old_instance;
  1817. $instance['title'] = htmlspecialchars(strip_tags(trim($new_instance['title'])), ENT_QUOTES, $blog_charset);
  1818. $instance['PlayerWidth'] = intval(preg_replace('/[^0-9]/', '',$new_instance['width'])); // only numeric values are allowed
  1819. $instance['PlayerHeight'] = intval(preg_replace('/[^0-9]/', '',$new_instance['height'])); // only numeric values are allowed
  1820. $instance['useSlimPlayer'] = isset($new_instance['useSlimPlayer']);
  1821. $instance['SlimPlayerHeight'] = intval(preg_replace('/[^0-9]/', '',$new_instance['heightslim'])); // only numeric values are allowed
  1822. if ( 150 > intval($instance['PlayerWidth']) ) {
  1823. $instance['PlayerWidth'] = 150; // min width
  1824. }
  1825. if ( 100 > intval($instance['PlayerHeight']) ) {
  1826. $instance['PlayerHeight'] = 100; // min height
  1827. }
  1828. if ( 100 < intval($instance['SlimPlayerHeight']) ) {
  1829. $instance['SlimPlayerHeight'] = 100; // max height slim
  1830. } elseif ( 30 > intval($instance['SlimPlayerHeight']) ) {
  1831. $instance['SlimPlayerHeight'] = 30; // min height slim
  1832. }
  1833. if ( isset($new_instance['xspf_use_custom_playlist']) ) {
  1834. $instance['xspf_use_custom_playlist'] = TRUE;
  1835. } else {
  1836. $instance['xspf_use_custom_playlist'] = FALSE;
  1837. }
  1838. $instance['trackinfoformat'] = $new_instance['trackinfoformat'];
  1839. $instance['xspf_custom_playlist_url'] = clean_url($new_instance['xspf_custom_playlist_url'], array('http', 'https'), 'db');
  1840. // delete the old widget settings
  1841. $old_widget_options = get_option('widget_podPressXspfPlayer');
  1842. if ( FALSE !== $old_widget_options ) {
  1843. delete_option('widget_podPressXspfPlayer');
  1844. }
  1845. return $instance;
  1846. }
  1847. /** @see WP_Widget::form */
  1848. function form($instance) {
  1849. GLOBAL $blog_id;
  1850. // take over the old widget settings (of podPress 8.8.5.x widgets)
  1851. $old_widget_options = get_option('widget_podPressXspfPlayer');
  1852. if ( TRUE == is_array($old_widget_options) AND FALSE == empty($old_widget_options) ) {
  1853. $instance['title'] = $old_widget_options['title'];
  1854. $instance['PlayerWidth'] = $old_widget_options['PlayerWidth'];
  1855. $instance['PlayerHeight'] = $old_widget_options['PlayerHeight'];
  1856. $instance['useSlimPlayer'] = $old_widget_options['useSlimPlayer'];
  1857. $instance['SlimPlayerHeight'] = $old_widget_options['SlimPlayerHeight'];
  1858. $instance['trackinfoformat'] = $old_widget_options['trackinfoformat'];
  1859. }
  1860. if(!isset($instance['title'])) {
  1861. $instance['title'] = __('Podcast Player', 'podpress');
  1862. }
  1863. $title = esc_attr(stripslashes($instance['title']));
  1864. if ( 150 > intval($instance['PlayerWidth']) ) {
  1865. $instance['PlayerWidth'] = 150; // min width
  1866. }
  1867. if ( 100 > intval($instance['PlayerHeight']) ) {
  1868. $instance['PlayerHeight'] = 100; // min height
  1869. }
  1870. $useSlimPlayer = $instance['useSlimPlayer'] ? ' checked="checked"' : '';
  1871. if ( 100 < intval($instance['SlimPlayerHeight']) ) {
  1872. $instance['SlimPlayerHeight'] = 100; // max height slim
  1873. } elseif ( 30 > intval($instance['SlimPlayerHeight']) ) {
  1874. $instance['SlimPlayerHeight'] = 30; // min height slim
  1875. }
  1876. ?>
  1877. <p><?php _e('<strong>Notice:</strong> This widget works only one time per blog page.', 'podpress'); ?></p>
  1878. <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> <input type="text" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $title; ?>" class="podpress_widget_settings_title" /></p>
  1879. <p><label for="<?php echo $this->get_field_id('width'); ?>"><?php _e('Player Width:', 'podpress'); ?></label> <input type="text" id="<?php echo $this->get_field_id('width'); ?>" name="<?php echo $this->get_field_name('width'); ?>" maxlength="3" value="<?php echo $instance['PlayerWidth']; ?>" class="podpress_widget_settings_3digits" /> <?php _e('px', 'podpress'); ?> <?php echo '<span class="nonessential">'.__('(150 <= w < 1000)', 'podpress').'</span>'; ?></p>
  1880. <p><label for="<?php echo $this->get_field_id('height'); ?>"><?php _e('Player Height:', 'podpress'); ?></label> <input type="text" id="<?php echo $this->get_field_id('height'); ?>" name="<?php echo $this->get_field_name('height'); ?>" maxlength="3" value="<?php echo $instance['PlayerHeight']; ?>" class="podpress_widget_settings_3digits" /> <?php _e('px', 'podpress'); ?> <?php echo '<span class="nonessential">'.__('(100 <= h < 1000)', 'podpress').'</span>'; ?></p>
  1881. <p><label for="<?php echo $this->get_field_id('useSlimPlayer'); ?>"><?php _e('Use Slim Player:', 'podpress'); ?></label> <input type="checkbox" id="<?php echo $this->get_field_id('useSlimPlayer'); ?>" name="<?php echo $this->get_field_name('useSlimPlayer'); ?>"<?php echo $useSlimPlayer; ?> /></p>
  1882. <p><label for="<?php echo $this->get_field_id('heightslim'); ?>"><?php _e('Slim Player Height:', 'podpress'); ?></label> <input type="text" id="<?php echo $this->get_field_id('heightslim'); ?>" name="<?php echo $this->get_field_name('heightslim'); ?>" maxlength="3" value="<?php echo $instance['SlimPlayerHeight']; ?>" class="podpress_widget_settings_3digits" /> <?php _e('px', 'podpress'); ?> <?php echo '<span class="nonessential">'.__('(30 <= h <= 100)', 'podpress').'</span>'; ?></p>
  1883. <p><label for="<?php echo $this->get_field_id('trackinfoformat'); ?>"><?php _e('Choose the format of the playlist entires:', 'podpress'); ?></label>
  1884. <select id="<?php echo $this->get_field_id('trackinfoformat'); ?>" name="<?php echo $this->get_field_name('trackinfoformat'); ?>">
  1885. <?php
  1886. $trackinfoformats = Array(
  1887. Array('val' => '-title - -creator', 'name'=>__('episode title', 'podpress').' - '.__('artist', 'podpress')),
  1888. Array('val' => '-title : -creator', 'name'=>__('episode title', 'podpress').' : '.__('artist', 'podpress')),
  1889. Array('val' => '-creator - -title', 'name'=>__('artist', 'podpress').' - '.__('episode title', 'podpress')),
  1890. Array('val' => '-creator : -title', 'name'=>__('artist', 'podpress').' : '.__('episode title', 'podpress')),
  1891. Array('val' => '-title', 'name'=>__('episode title', 'podpress'))
  1892. );
  1893. if ( FALSE == isset($instance['trackinfoformat']) OR TRUE == empty($instance['trackinfoformat']) ) {
  1894. $instance['trackinfoformat'] = '-creator : -title';
  1895. }
  1896. foreach ($trackinfoformats as $format) {
  1897. if ($instance['trackinfoformat'] == $format['val']) {
  1898. echo '<option value="'.$format['val'].'" selected="selected">'.$format['name'].'</option>';
  1899. } else {
  1900. echo '<option value="'.$format['val'].'">'.$format['name'].'</option>';
  1901. }
  1902. }
  1903. ?>
  1904. </select>
  1905. </p>
  1906. <?php
  1907. if ( defined('PODPRESS_CUSTOM_XSPF_URL_'.$blog_id) AND '' !== constant('PODPRESS_CUSTOM_XSPF_URL_'.$blog_id) ) {
  1908. $xspf_custom_playlist_url_readonly = ' readonly="readonly"';
  1909. $xspf_custom_playlist_url = esc_attr(constant('PODPRESS_CUSTOM_XSPF_URL_'.$blog_id));
  1910. $xspf_use_custom_playlist_disabled = ' disabled="disabled"';
  1911. $xspf_use_custom_playlist_checked = ' checked="checked"';
  1912. $xspf_custom_playlist_msg = '<p class="podpress_notice">'.sprintf(__('<strong>Notice:</strong> The custom playlist URL is currently defined via the constant PODPRESS_CUSTOM_XSPF_URL_%1$s and this constant overwrites the custom XSPF playlist settings.', 'podpress'), $blog_id).'</p>';
  1913. } else {
  1914. $xspf_custom_playlist_url_readonly = '';
  1915. $xspf_custom_playlist_url = esc_attr($instance['xspf_custom_playlist_url']);
  1916. $xspf_use_custom_playlist_disabled = '';
  1917. if ( TRUE === $instance['xspf_use_custom_playlist'] ) {
  1918. $xspf_use_custom_playlist_checked = ' checked="checked"';
  1919. } else {
  1920. $xspf_use_custom_playlist_checked = '';
  1921. }
  1922. $xspf_custom_playlist_msg = '';
  1923. }
  1924. echo '<p><label for="'.$this->get_field_id('xspf_use_custom_playlist').'">'.__('use a custom XSPF playlist:', 'podpress').'</label> <input type="checkbox" name="'.$this->get_field_name('xspf_use_custom_playlist').'" id="'.$this->get_field_id('xspf_use_custom_playlist').'"'.$xspf_use_custom_playlist_checked.$xspf_use_custom_playlist_disabled.' /></p>'."\n";
  1925. echo '<p><label for="'.$this->get_field_id('xspf_custom_playlist_url').'">'.__('custom playlist URL:', 'podpress').'</label><br /><input type="text" name="'.$this->get_field_name('xspf_custom_playlist_url').'" id="'.$this->get_field_id('xspf_custom_playlist_url').'" class="podpress_full_width_text_field" size="40" value="'.$xspf_custom_playlist_url.'"'.$xspf_custom_playlist_url_readonly.' /><span class="nonessential">'.__('The custom playlist URL has to be an URL to a playlist which is on the same domain/server as your blog. The files in the playlist can be located some where else.', 'podpress').'</span></p>'.$xspf_custom_playlist_msg."\n";
  1926. if ( TRUE == defined('PODPRESS_XSPF_PLAYER_USE_CUSTOM_SKINFILE_'.$blog_id) AND TRUE === constant('PODPRESS_XSPF_PLAYER_USE_CUSTOM_SKINFILE_'.$blog_id) ) {
  1927. echo '<p class="podpress_notice podpress_msg">'.sprintf(__('<strong>Notice:</strong> PODPRESS_XSPF_PLAYER_USE_CUSTOM_SKINFILE_%1$s is defined. This widget uses custom skin files. Make sure that there is a custom skin file for these dimensions (see podpress_xspf_config.php).', 'podpress'), $blog_id).'</p>';
  1928. }
  1929. }
  1930. } // class podPress XSPF Player Widget
  1931. }
  1932. /**************************************************************/
  1933. /* Functions for supporting the downloader */
  1934. /**************************************************************/
  1935. function podPress_StatCounter($postID, $media, $method) {
  1936. global $wpdb;
  1937. switch($method) {
  1938. case 'feed':
  1939. case 'web':
  1940. case 'play':
  1941. $sqlIoU = "INSERT INTO ".$wpdb->prefix."podpress_statcounts (postID, media, $method) VALUES ($postID, '$media', 1) ON DUPLICATE KEY UPDATE $method = $method+1, total = total+1";
  1942. $result = $wpdb->query($sqlIoU);
  1943. break;
  1944. default:
  1945. return;
  1946. }
  1947. }
  1948. function podPress_StatCollector($postID, $media, $method) {
  1949. global $wpdb;
  1950. $media = addslashes($media);
  1951. $method = addslashes($method);
  1952. $ip = addslashes($_SERVER['REMOTE_ADDR']);
  1953. //$cntry = addslashes(podPress_determineCountry($ip));
  1954. $cntry = addslashes('');
  1955. $lang = addslashes(podPress_determineLanguage());
  1956. $ref = addslashes($_SERVER['HTTP_REFERER']);
  1957. $url = parse_url($ref);
  1958. $domain = addslashes(eregi_replace('^www.','',$url['host']));
  1959. //$res = $_SERVER['REQUEST_URI'];
  1960. $ua = addslashes($_SERVER['HTTP_USER_AGENT']);
  1961. $br = podPress_parseUserAgent($_SERVER['HTTP_USER_AGENT']);
  1962. $dt = time();
  1963. $query = "INSERT INTO ".$wpdb->prefix."podpress_stats (postID, media, method, remote_ip, country, language, domain, referer, user_agent, platform, browser, version, dt) VALUES ('$postID', '$media', '$method', '".$ip."', '$cntry', '$lang', '$domain', '$ref', '$ua', '".addslashes($br['platform'])."', '".addslashes($br['browser'])."', '".addslashes($br['version'])."', $dt)";
  1964. $result = $wpdb->query($query);
  1965. return $wpdb->insert_id;
  1966. }
  1967. function podPress_determineCountry($ip) {
  1968. $coinfo = @file('http://www.hostip.info/api/get.html?ip=' . $ip);
  1969. $country_string = explode(':',$coinfo[0]);
  1970. $country = trim($country_string[1]);
  1971. if($country == '(Private Address) (XX)'
  1972. || $country == '(Unknown Country?) (XX)'
  1973. || $country == ''
  1974. || !$country
  1975. )return 'Indeterminable';
  1976. return $country;
  1977. }
  1978. function podPress_parseUserAgent($ua) {
  1979. $browser['platform'] = "Indeterminable";
  1980. $browser['browser'] = "Indeterminable";
  1981. $browser['version'] = "Indeterminable";
  1982. $browser['majorver'] = "Indeterminable";
  1983. $browser['minorver'] = "Indeterminable";
  1984. // Test for platform
  1985. if (FALSE !== stripos($ua, 'Win95')) {
  1986. $browser['platform'] = "Windows 95";
  1987. }
  1988. else if (FALSE !== stripos($ua, 'Win98')) {
  1989. $browser['platform'] = "Windows 98";
  1990. }
  1991. else if (FALSE !== stripos($ua, 'Win 9x 4.90')) {
  1992. $browser['platform'] = "Windows ME";
  1993. }
  1994. else if (FALSE !== stripos($ua, 'Windows NT 5.0')) {
  1995. $browser['platform'] = "Windows 2000";
  1996. }
  1997. else if (FALSE !== stripos($ua, 'Windows NT 5.1')) {
  1998. $browser['platform'] = "Windows XP";
  1999. }
  2000. else if (FALSE !== stripos($ua, 'Windows NT 5.2')) {
  2001. $browser['platform'] = "Windows 2003";
  2002. }
  2003. else if (FALSE !== stripos($ua, 'Windows NT 6.0')) {
  2004. $browser['platform'] = "Windows Vista";
  2005. }
  2006. else if (FALSE !== stripos($ua, 'Windows NT 6.1')) {
  2007. $browser['platform'] = "Windows 7";
  2008. }
  2009. else if (FALSE !== stripos($ua, 'Windows')) {
  2010. $browser['platform'] = "Windows";
  2011. }
  2012. else if (FALSE !== stripos($ua, 'Mac OS X')) {
  2013. $browser['platform'] = "Mac OS X";
  2014. }
  2015. else if (FALSE !== stripos($ua, 'iphone') || FALSE !== stripos($ua, 'ios')) {
  2016. $browser['platform'] = "iPhone OS / iOS";
  2017. }
  2018. else if (FALSE !== stripos($ua, 'Mac OS X')) {
  2019. $browser['platform'] = "Mac OS X";
  2020. }
  2021. else if (FALSE !== stripos($ua, 'Macintosh')) {
  2022. $browser['platform'] = "Mac OS Classic";
  2023. }
  2024. else if (FALSE !== stripos($ua, 'Linux')) {
  2025. $browser['platform'] = "Linux";
  2026. }
  2027. else if (FALSE !== stripos($ua, 'BSD') || FALSE !== stripos($ua, 'FreeBSD') || FALSE !== stripos($ua, 'NetBSD')) {
  2028. $browser['platform'] = "BSD";
  2029. }
  2030. else if (FALSE !== stripos($ua, 'SunOS')) {
  2031. $browser['platform'] = "Solaris";
  2032. }
  2033. $browsernames = Array(
  2034. 'Firefox' => 'Firefox',
  2035. 'Opera' => 'Opera',
  2036. 'Safari' => 'Safari',
  2037. 'MSIE' => 'Internet Explorer',
  2038. 'Chrome' => 'Chrome',
  2039. 'iCab' => 'iCab',
  2040. 'Camino' => 'Camino',
  2041. 'Konqueror' => 'Konqueror',
  2042. 'Iceweasel' => 'Iceweasel',
  2043. 'Midori' => 'Midori',
  2044. 'K-Meleon' => 'K-Meleon',
  2045. 'Chimera' => 'Chimera',
  2046. 'Firebird' => 'Firebird',
  2047. 'Netscape' => 'Netscape',
  2048. 'MSN Explorer' => 'MSN Explorer',
  2049. 'K-Meleon' => 'K-Meleon',
  2050. 'AOL' => 'America Online Browser',
  2051. 'America Online Browser' => 'America Online Browser',
  2052. 'Beonex' => 'Beonex',
  2053. 'OmniWeb' => 'OmniWeb',
  2054. 'Galeon' => 'Galeon',
  2055. 'Kazehakase' => 'Kazehakase',
  2056. 'Amaya' => 'Amaya',
  2057. 'Lynx' => 'Lynx',
  2058. 'Links' => 'Links',
  2059. 'ELinks' => 'ELinks',
  2060. 'Crawl' => 'Crawler/Search Engine',
  2061. 'bot' => 'Crawler/Search Engine',
  2062. 'slurp' => 'Crawler/Search Engine',
  2063. 'spider' => 'Crawler/Search Engine'
  2064. );
  2065. $foundbrowser = FALSE;
  2066. foreach ($browsernames as $browserid => $browsername) {
  2067. $result = preg_match('/'.$browserid.'\/[0-9]+\.[0-9]+/i', $ua, $b);
  2068. if (0 < $result) {
  2069. $b_parts = explode('/', $b[0]);
  2070. $browser['browser'] = $browsername;
  2071. $browser['version'] = $b_parts[1];
  2072. $foundbrowser = TRUE;
  2073. break;
  2074. }
  2075. }
  2076. if ( FALSE == $foundbrowser ) {
  2077. foreach ($browsernames as $browserid => $browsername) {
  2078. $result = preg_match('/'.$browserid.' [0-9]+\.[0-9]+/i', $ua, $b);
  2079. if (0 < $result) {
  2080. $b_parts = explode(' ', $b[0]);
  2081. $browser['browser'] = $browsername;
  2082. $browser['version'] = $b_parts[1];
  2083. break;
  2084. }
  2085. }
  2086. }
  2087. if (empty($browser['version']) || $browser['version']=='.0') {
  2088. $browser['version'] = "Indeterminable";
  2089. $browser['majorver'] = "Indeterminable";
  2090. $browser['minorver'] = "Indeterminable";
  2091. }
  2092. return $browser;
  2093. }
  2094. function podPress_determineLanguage() {
  2095. $lang_choice = "empty";
  2096. if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) {
  2097. // Capture up to the first delimiter (, found in Safari)
  2098. preg_match("/([^,;]*)/",$_SERVER["HTTP_ACCEPT_LANGUAGE"],$langs);
  2099. $lang_choice = $langs[0];
  2100. }
  2101. return $lang_choice;
  2102. }
  2103. function podPress_statsDownloadRedirect($requested = '##NOTSET##') {
  2104. GLOBAL $podPress;
  2105. //~ printphpnotices_var_dump('requested a:');
  2106. //~ printphpnotices_var_dump($requested);
  2107. if($requested == '##NOTSET##') {
  2108. $requested = parse_url($_SERVER['REQUEST_URI']);
  2109. $requested = $requested['path'];
  2110. }
  2111. //~ printphpnotices_var_dump('requested b:');
  2112. //~ printphpnotices_var_dump($requested);
  2113. $pos = 0;
  2114. if (is_404() || $pos = strpos($requested, 'podpress_trac')) {
  2115. if($pos == 0) {
  2116. $pos = strpos($requested, 'podpress_trac');
  2117. }
  2118. $pos = $pos+14;
  2119. if(substr($requested, $pos, 1) == '/') {
  2120. $pos = $pos+1;
  2121. }
  2122. $requested = substr($requested, $pos);
  2123. $parts = explode('/', $requested);
  2124. //~ printphpnotices_var_dump($parts);
  2125. if(count($parts) == 4) {
  2126. podPress_processDownloadRedirect($parts[1], $parts[2], $parts[3], $parts[0]);
  2127. }
  2128. }
  2129. }
  2130. function podPress_processDownloadRedirect($postID, $mediaNum, $filename, $method = '') {
  2131. GLOBAL $podPress, $wpdb;
  2132. $allowedMethods = array('feed', 'play', 'web');
  2133. $realURL = false;
  2134. $realSysPath = false;
  2135. $statID = false;
  2136. if(substr($filename, -20, 20) == 'podPressStatTest.txt') {
  2137. status_header('200');
  2138. echo 'Worked'; // Don't translate this!
  2139. exit;
  2140. }
  2141. if (in_array($method, $allowedMethods) && is_numeric($postID) && is_numeric($mediaNum)) {
  2142. $mediaFiles = podPress_get_post_meta($postID, '_podPressMedia', true);
  2143. if(isset($mediaFiles[$mediaNum])) {
  2144. if($mediaFiles[$mediaNum]['URI'] == urldecode($filename)) {
  2145. $realURL = $filename;
  2146. } elseif(podPress_getFileName($mediaFiles[$mediaNum]['URI']) == urldecode($filename)) {
  2147. $realURL = $mediaFiles[$mediaNum]['URI'];
  2148. } elseif(podPress_getFileName($mediaFiles[$mediaNum]['URI_torrent']) == urldecode($filename)) {
  2149. $realURL = $mediaFiles[$mediaNum]['URI_torrent'];
  2150. }
  2151. }
  2152. }
  2153. if(!$realURL) {
  2154. header('X-PodPress-Location: '.get_option('siteurl'));
  2155. header('Location: '.get_option('siteurl'));
  2156. exit;
  2157. }
  2158. $badextensions = array('.smi', '.jpg', '.png', '.gif');
  2159. if($filename && !in_array(strtolower(substr($filename, -4)), $badextensions)) {
  2160. podPress_StatCounter($postID, $filename, $method);
  2161. if($podPress->settings['statLogging'] == 'Full' || $podPress->settings['statLogging'] == 'FullPlus') {
  2162. $statID = podPress_StatCollector($postID, $filename, $method);
  2163. }
  2164. }
  2165. $realSysPath = $podPress->convertPodcastFileNameToSystemPath(str_replace('%20', ' ', $realURL));
  2166. if (FALSE === $realSysPath) {
  2167. $realSysPath = $podPress->TryToFindAbsFileName(str_replace('%20', ' ', $realURL));
  2168. }
  2169. $realURL = $podPress->convertPodcastFileNameToValidWebPath($realURL);
  2170. if ($podPress->settings['enable3rdPartyStats'] == 'PodTrac') {
  2171. $realURL = str_replace(array('ftp://', 'http://', 'https://'), '', $realURL);
  2172. $realURL = $podPress->podtrac_url.$realURL;
  2173. } elseif ( strtolower($podPress->settings['enable3rdPartyStats']) == 'blubrry' && !empty($podPress->settings['statBluBrryProgramKeyword'])) {
  2174. $realURL = str_replace('http://', '', $realURL);
  2175. $realURL = $podPress->blubrry_url.$podPress->settings['statBluBrryProgramKeyword'].'/'.$realURL;
  2176. } elseif ($podPress->settings['statLogging'] == 'FullPlus' && $realSysPath !== false) {
  2177. status_header('200');
  2178. $content_type = podPress_mimetypes(podPress_getFileExt($realSysPath));
  2179. if($method == 'web') {
  2180. header("Pragma: ");
  2181. header("Cache-Control: ");
  2182. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  2183. header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  2184. header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
  2185. header("Cache-Control: post-check=0, pre-check=0", false);
  2186. header('Content-Disposition: attachment; filename="'.$filename.'"');
  2187. header("Content-Description: ".trim(htmlentities($filename)));
  2188. header("Connection: close");
  2189. if(substr($content_type, 0, 4) != 'text') {
  2190. header("Content-Transfer-Encoding: binary");
  2191. }
  2192. } else {
  2193. header("Connection: Keep-Alive");
  2194. }
  2195. header("X-ForcedBy: podPress");
  2196. header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
  2197. header('Content-type: '.$content_type);
  2198. header('Content-Length: '.filesize($realSysPath));
  2199. set_time_limit(0);
  2200. $chunksize = 1*(1024*1024); // how many bytes per chunk
  2201. if ($handle = fopen($realSysPath, 'rb')) {
  2202. while (!feof($handle) && connection_status()==0) {
  2203. echo fread($handle, $chunksize);
  2204. ob_flush();
  2205. flush();
  2206. }
  2207. fclose($handle);
  2208. }
  2209. if($statID !== false && connection_status() == 0 && !connection_aborted()) {
  2210. $sqlU = "UPDATE ".$wpdb->prefix."podpress_stats SET completed=1 WHERE id=".$statID;
  2211. $wpdb->hide_errors();
  2212. $result = $wpdb->query($sqlI);
  2213. if(!$result) {
  2214. $wpdb->query($sqlU);
  2215. }
  2216. }
  2217. exit;
  2218. }
  2219. $realURL = str_replace(' ', '%20', $realURL);
  2220. status_header('302');
  2221. header('X-PodPress-Location: '.$realURL, true, 302);
  2222. header('Location: '.$realURL, true, 302);
  2223. header('Content-Length: 0');
  2224. exit;
  2225. }
  2226. function podPress_remote_version_check() {
  2227. $current = PODPRESS_VERSION;
  2228. $latestVersionCache = podPress_get_option('podPress_versionCheck');
  2229. if(($latestVersionCache['cached']+86400) < time() ) {
  2230. $current = $latestVersionCache['version'];
  2231. } elseif (class_exists(snoopy)) {
  2232. $client = new Snoopy();
  2233. $client->_fp_timeout = 10;
  2234. if (@$client->fetch('http://www.mightyseek.com/podpress_downloads/versioncheck.php?url='.get_option('siteurl').'&current='.PODPRESS_VERSION) === false) {
  2235. return -1;
  2236. } else {
  2237. $remote = $client->results;
  2238. if (!$remote || strlen($remote) > 8 ) {
  2239. return -1;
  2240. }
  2241. $current = $remote;
  2242. }
  2243. delete_option('podPress_versionCheck');
  2244. podPress_add_option('podPress_versionCheck', array('version'=>$current, 'cached'=> time()), 'Latest version available', 'yes');
  2245. }
  2246. if ($current > PODPRESS_VERSION) {
  2247. return 1;
  2248. } else {
  2249. return 0;
  2250. }
  2251. }
  2252. /**************************************************************/
  2253. /* Functions for supporting version of WordPress before 2.0.0 */
  2254. /**************************************************************/
  2255. function podPress_add_post_meta($post_id, $key, $value, $unique = false) {
  2256. GLOBAL $wpdb;
  2257. if(!podPress_WPVersionCheck('2.0.0')) {
  2258. if ( is_array($value) || is_object($value) ) {
  2259. $value = $wpdb->escape(serialize($value));
  2260. }
  2261. }
  2262. return add_post_meta($post_id, $key, $value, $unique);
  2263. }
  2264. function podPress_get_post_meta($post_id, $key, $single = false) {
  2265. if(podPress_WPVersionCheck('2.0.0') === false) {
  2266. return maybe_unserialize(get_post_meta($post_id, $key, $single));
  2267. }
  2268. return get_post_meta($post_id, $key, $single);
  2269. }
  2270. function podPress_add_option($name, $value = '', $description = '', $autoload = 'yes') {
  2271. if(!podPress_WPVersionCheck('2.0.0')) {
  2272. if ( is_array($value) || is_object($value) ) {
  2273. $value = serialize($value);
  2274. }
  2275. }
  2276. $result = add_option($name, $value, $description, $autoload);
  2277. return $result;
  2278. }
  2279. function podPress_get_option($option) {
  2280. if(!podPress_WPVersionCheck('2.0.0')) {
  2281. return maybe_unserialize(get_option($option));
  2282. }
  2283. return get_option($option);
  2284. }
  2285. function podPress_update_option($option_name, $option_value) {
  2286. delete_option($option_name);
  2287. $result = podPress_add_option($option_name, $option_value);
  2288. return $result;
  2289. }
  2290. ?>