PageRenderTime 29ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/bill742/verbalbrew
PHP | 1712 lines | 1379 code | 123 blank | 210 comment | 432 complexity | 12984c8d59d3c7aff9f5236de6b85b2a 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. class podPress_class {
  19. var $settings = array();
  20. // Global hardcoded settings
  21. var $podcasttag_regexp = "/\[podcast:([^]]+)]/";
  22. var $podcasttag = '[display_podcast]';
  23. var $podtrac_url = 'http://www.podtrac.com/pts/redirect.mp3?';
  24. var $blubrry_url = 'http://media.blubrry.com/';
  25. var $requiredadminrights = 'manage_categories';//'level_7';
  26. var $realm = 'Premium Subscribers Content';
  27. var $justposted = false;
  28. var $uploadurl = '';
  29. var $uploadpath = '';
  30. var $tempfilesystempath = '';
  31. var $tempfileurlpath = '';
  32. var $tempcontentaddedto = array();
  33. var $podangoapi;
  34. var $isexcerpt = FALSE;
  35. /*************************************************************/
  36. /* Load up the plugin values and get ready to action */
  37. /*************************************************************/
  38. function podPress_class() {
  39. //$this->feed_getCategory();
  40. // this is not workin in WP 3.0: //$this->uploadpath = get_option('upload_path');
  41. $wp_upload_dir = wp_upload_dir(); // since WP 2.0.0 but the return values were different back than
  42. if (FALSE == isset($wp_upload_dir['basedir']) OR FALSE == isset($wp_upload_dir['baseurl'])) {
  43. $wp_upload_dir = $this->upload_dir();
  44. }
  45. $this->uploadpath = $wp_upload_dir['basedir'];
  46. $this->uploadurl = $wp_upload_dir['baseurl'];
  47. $this->tempfilesystempath = $this->uploadpath.'/podpress_temp';
  48. $this->tempfileurlpath = $wp_upload_dir['baseurl'].'/podpress_temp';
  49. // load up podPress general config
  50. $this->settings = podPress_get_option('podPress_config');
  51. // make sure things look current, if not run the settings checker
  52. if(!is_array($this->settings) OR TRUE == version_compare(PODPRESS_VERSION, $this->settings['lastChecked'], '>') ) {
  53. $this->checkSettings();
  54. }
  55. if(is_object($GLOBALS['wp_rewrite'])
  56. && is_array($GLOBALS['wp_object_cache'])
  57. && is_array($GLOBALS['wp_object_cache']['cache'])
  58. && is_array($GLOBALS['wp_object_cache']['cache']['options'])
  59. && is_array($GLOBALS['wp_object_cache']['cache']['options']['alloptions'])
  60. && is_array($GLOBALS['wp_object_cache']['cache']['options']['alloptions']['rewrite_rules'])
  61. && !strpos($GLOBALS['wp_object_cache']['cache']['options']['alloptions']['rewrite_rules'], 'playlist.xspf')
  62. ) {
  63. $GLOBALS['wp_rewrite']->flush_rules();
  64. }
  65. }
  66. // taken from wp_upload_dir() of WP 2.8.4 to keep up the compatibility of this podPress version with older WP version
  67. // new in podPress since 8.8.5 beta 9
  68. function upload_dir() {
  69. $siteurl = get_option( 'siteurl' );
  70. $upload_path = get_option( 'upload_path' );
  71. $upload_path = trim($upload_path);
  72. if ( empty($upload_path) ) {
  73. $dir = WP_CONTENT_DIR . '/uploads';
  74. } else {
  75. $dir = $upload_path;
  76. }
  77. // $dir is absolute, $path is (maybe) relative to ABSPATH
  78. $dir = $this->path_join( ABSPATH, $dir );
  79. if ( !$url = get_option( 'upload_url_path' ) ) {
  80. if ( empty($upload_path) or ( $upload_path == $dir ) ) {
  81. $url = WP_CONTENT_URL . '/uploads';
  82. } else {
  83. $url = trailingslashit( $siteurl ) . $upload_path;
  84. }
  85. }
  86. if ( defined('UPLOADS') ) {
  87. $dir = ABSPATH . UPLOADS;
  88. $url = trailingslashit( $siteurl ) . UPLOADS;
  89. }
  90. return array( 'basedir' => $dir, 'baseurl' => $url);
  91. }
  92. // taken from WP 2.8.4 to keep up the compatibility of this podPress version with older WP version (new in WP since 2.5)
  93. // new in podPress since 8.8.5 beta 9
  94. function path_join( $base, $path ) {
  95. if ( $this->path_is_absolute($path) ) { return $path; }
  96. return rtrim($base, '/') . '/' . ltrim($path, '/');
  97. }
  98. // taken from WP 2.8.4 to keep up the compatibility of this podPress version with older WP version (new in WP since 2.5)
  99. // new in podPress since 8.8.5 beta 9
  100. function path_is_absolute( $path ) {
  101. // this is definitive if true but fails if $path does not exist or contains a symbolic link
  102. if ( realpath($path) == $path ) { return true;}
  103. if ( strlen($path) == 0 || $path{0} == '.' ) { return false; }
  104. // windows allows absolute paths like this
  105. if ( preg_match('#^[a-zA-Z]:\\\\#', $path) ) { return true; }
  106. // a path starting with / or \ is absolute; anything else is relative
  107. return (bool) preg_match('#^[/\\\\]#', $path);
  108. }
  109. /*************************************************************/
  110. // Handles all the default values for a new installation of the plugin
  111. // activate() is called only from podpress_upgrade_class.php during
  112. // the version check and upgrade routine which runs also after the plugin activation
  113. /*************************************************************/
  114. function activate() {
  115. GLOBAL $wpdb;
  116. if (function_exists('get_role') AND function_exists('is_role')) {
  117. if (FALSE === is_role('premium_subscriber')) {
  118. add_role('premium_subscriber', 'Premium Subscriber', $caps);
  119. }
  120. if (TRUE === is_role('premium_subscriber')) {
  121. $ps_role = get_role('premium_subscriber');
  122. if (Null !== $ps_role AND !$ps_role->has_cap('premium_content')) {
  123. $ps_role->add_cap('premium_content');
  124. }
  125. if(Null !== $ps_role AND !$ps_role->has_cap('read')) {
  126. $ps_role->add_cap('read');
  127. }
  128. }
  129. if (TRUE === is_role('administrator')) {
  130. $role = get_role('administrator');
  131. if (Null !== $role AND !$role->has_cap('premium_content')) {
  132. $role->add_cap('premium_content');
  133. }
  134. }
  135. }
  136. $this->createstatistictables();
  137. if(function_exists('wp_cache_flush')) {
  138. wp_cache_flush();
  139. }
  140. $current = get_option('podPress_version');
  141. if ( FALSE === $current ) {
  142. $current = constant('PODPRESS_VERSION');
  143. update_option('podPress_version', $current);
  144. }
  145. //$this->checkSettings();
  146. }
  147. /**
  148. * createstatistictables - creates the db tables for the statistics
  149. *
  150. * @package podPress
  151. * @since 8.8.10.3 beta 5
  152. *
  153. */
  154. function createstatistictables() {
  155. GLOBAL $wpdb;
  156. // ntm: create the table with the collation or db_charset (since 8.8.5 beta 4)
  157. if ( TRUE == defined('DB_COLLATE') AND '' !== DB_COLLATE ) {
  158. $db_charset = ' COLLATE ' . DB_COLLATE;
  159. } elseif ( (FALSE == defined('DB_COLLATE') OR '' == DB_COLLATE) AND TRUE == defined('DB_CHARSET') AND '' !== DB_CHARSET ) {
  160. $db_charset = ' DEFAULT CHARACTER SET ' . DB_CHARSET;
  161. } else {
  162. $db_charset = '';
  163. }
  164. // Create stats table
  165. $create_table = "CREATE TABLE ".$wpdb->prefix."podpress_statcounts (".
  166. "postID int(11) NOT NULL default '0',".
  167. "media varchar(255) NOT NULL,".
  168. "total int(11) default '1',".
  169. "feed int(11) default '0',".
  170. "web int(11) default '0',".
  171. "play int(11) default '0',".
  172. "PRIMARY KEY (media)) " . $db_charset;
  173. podPress_maybe_create_table($wpdb->prefix."podpress_statcounts", $create_table);
  174. // Create stats table
  175. $create_table = "CREATE TABLE ".$wpdb->prefix."podpress_stats (".
  176. "id int(11) unsigned NOT NULL auto_increment,".
  177. "postID int(11) NOT NULL default '0',".
  178. "media varchar(255) NOT NULL default '',".
  179. "method varchar(50) NOT NULL default '',".
  180. "remote_ip varchar(15) NOT NULL default '',".
  181. "country varchar(50) NOT NULL default '',".
  182. "language VARCHAR(5) NOT NULL default '',".
  183. "domain varchar(255) NOT NULL default '',".
  184. "referer varchar(255) NOT NULL default '',".
  185. "resource varchar(255) NOT NULL default '',".
  186. "user_agent varchar(255) NOT NULL default '',".
  187. "platform varchar(50) NOT NULL default '',".
  188. "browser varchar(50) NOT NULL default '',".
  189. "version varchar(15) NOT NULL default '',".
  190. "dt int(10) unsigned NOT NULL default '0',".
  191. "completed TINYINT(1) UNSIGNED DEFAULT '0',".
  192. "UNIQUE KEY id (id)) " . $db_charset;
  193. podPress_maybe_create_table($wpdb->prefix."podpress_stats", $create_table);
  194. }
  195. /**
  196. * checkLocalPathToMediaFiles - checks whether the "Local path to media files directory" exists or not. (This procedure is simply taken from the checkSettings() function earlier versions.)
  197. *
  198. * @package podPress
  199. * @since 8.8.5 beta 4
  200. *
  201. */
  202. function checkLocalPathToMediaFiles() {
  203. unset($this->settings['autoDetectedMediaFilePath']);
  204. $mediaFilePath = stripslashes($this->settings['mediaFilePath']);
  205. if ( FALSE == isset($this->settings['mediaFilePath']) OR FALSE == file_exists( $mediaFilePath ) ) {
  206. $this->settings['autoDetectedMediaFilePath'] = $this->uploadpath;
  207. if (!file_exists($this->settings['autoDetectedMediaFilePath'])) {
  208. $this->settings['autoDetectedMediaFilePath'] .= ' ('.__('Auto Detection Failed.', 'podpress').') '.strval($this->uploadpath);
  209. }
  210. }
  211. }
  212. function checkSettings() {
  213. GLOBAL $wp_object_cache, $wp_rewrite, $wp_version;
  214. if ( !is_array($this->settings) ) {
  215. $this->settings = podPress_get_option('podPress_config');
  216. if(!is_array($this->settings)) {
  217. $this->settings = array();
  218. }
  219. }
  220. $this->settings['lastChecked'] = PODPRESS_VERSION;
  221. // Make sure some standard values are set.
  222. $x = get_option('rss_language');
  223. if(!$x || empty($x))
  224. {
  225. add_option('rss_language', 'en');
  226. }
  227. $x = get_option('rss_image');
  228. if(!$x || empty($x))
  229. {
  230. podPress_update_option('rss_image', podPress_url().'images/powered_by_podpress.jpg');
  231. }
  232. // ntm: these settings are for the theme compatibility check resp. message. It seems to me that this checker was not in place at least since 8.8.
  233. // I could not find the routine which searches through the theme files for the wp_head and get_header etc. calls. Until there is such a test, I will set these values to TRUE.
  234. //~ if($this->settings['compatibilityChecks']['themeTested'] !== true) {
  235. //~ $this->settings['compatibilityChecks']['themeTested'] = false;
  236. //~ }
  237. //~ if($this->settings['compatibilityChecks']['wp_head'] !== true) {
  238. //~ $this->settings['compatibilityChecks']['wp_head'] = false;
  239. //~ }
  240. //~ if($this->settings['compatibilityChecks']['wp_footer'] !== true) {
  241. //~ $this->settings['compatibilityChecks']['wp_footer'] = false;
  242. //~ }
  243. $this->settings['compatibilityChecks']['themeTested'] = TRUE;
  244. $this->settings['compatibilityChecks']['wp_head'] = TRUE;
  245. $this->settings['compatibilityChecks']['wp_footer'] = TRUE;
  246. if(!is_bool($this->settings['enableStats'])) {
  247. if($this->settings['enableStats']== 'true') {
  248. $this->settings['enableStats'] = true;
  249. } else {
  250. $this->settings['enableStats'] = false;
  251. }
  252. }
  253. // no dashboardwidget support for WP 2.5.x and WP 2.6.x
  254. if ( TRUE == isset($this->settings['disabledashboardwidget']) AND TRUE === $this->settings['disabledashboardwidget'] OR (TRUE == version_compare($wp_version, '2.5', '>=') AND TRUE == version_compare($wp_version, '2.7', '<')) ) {
  255. $this->settings['disabledashboardwidget'] = TRUE;
  256. } else {
  257. $this->settings['disabledashboardwidget'] = FALSE;
  258. }
  259. if(!$this->settings['statMethod'] || empty($this->settings['statMethod']) || $this->settings['statMethod'] == 'htaccess')
  260. {
  261. $this->settings['statMethod'] = 'permalinks';
  262. }
  263. if(!$this->settings['statLogging'] || empty($this->settings['statLogging']))
  264. {
  265. $this->settings['statLogging'] = 'Counts';
  266. }
  267. if(empty($this->settings['enable3rdPartyStats'])) {
  268. $this->settings['enable3rdPartyStats'] = 'No';
  269. }
  270. if(!is_bool($this->settings['enableBlubrryStats'])) {
  271. if($this->settings['enableBlubrryStats']== 'true') {
  272. $this->settings['enableBlubrryStats'] = true;
  273. } else {
  274. $this->settings['enableBlubrryStats'] = false;
  275. }
  276. }
  277. if(!$this->settings['rss_copyright'] || empty($this->settings['rss_copyright']))
  278. {
  279. $this->settings['rss_copyright'] = __('Copyright', 'podpress').' &#xA9; '.get_bloginfo('blogname').' '. date('Y',time());
  280. }
  281. if(podPress_WPVersionCheck('2.0.0')) {
  282. if(!is_bool($this->settings['enablePremiumContent'])) {
  283. if($this->settings['enablePremiumContent']== 'true') {
  284. $this->settings['enablePremiumContent'] = true;
  285. } else {
  286. $this->settings['enablePremiumContent'] = false;
  287. }
  288. }
  289. } else {
  290. $this->settings['enablePremiumContent'] = false;
  291. }
  292. if(empty($this->settings['premiumMethod'])) {
  293. $this->settings['premiumMethod'] = 'Digest';
  294. }
  295. if(!defined('PODPRESS_PREMIUM_METHOD')) {
  296. define('PODPRESS_PREMIUM_METHOD', $this->settings['premiumMethod']);
  297. }
  298. if(!is_bool($this->settings['enableTorrentCasting'])) {
  299. if($this->settings['enableTorrentCasting']== 'true') {
  300. $this->settings['enableTorrentCasting'] = true;
  301. } else {
  302. $this->settings['enableTorrentCasting'] = false;
  303. }
  304. }
  305. if(empty($this->settings['podcastFeedURL'])) {
  306. if(podPress_WPVersionCheck('2.1')) {
  307. //~ $this->settings['podcastFeedURL'] = get_option('siteurl').'/?feed=podcast';
  308. $this->settings['podcastFeedURL'] = get_feed_link('podcast');
  309. } else {
  310. $this->settings['podcastFeedURL'] = get_option('siteurl').'/?feed=rss2';
  311. }
  312. }
  313. if ( FALSE == isset($this->settings['mediaWebPath']) OR TRUE == empty($this->settings['mediaWebPath']) ) {
  314. $this->settings['mediaWebPath'] = $this->uploadurl;
  315. }
  316. $this->checkLocalPathToMediaFiles();
  317. if(empty($this->settings['maxMediaFiles']) || $this->settings['maxMediaFiles'] < 1) {
  318. $this->settings['maxMediaFiles'] = 10;
  319. }
  320. if(!$this->settings['contentBeforeMore'] || empty($this->settings['contentBeforeMore']))
  321. {
  322. $this->settings['contentBeforeMore'] = 'yes';
  323. }
  324. if(!$this->settings['contentLocation'] || empty($this->settings['contentLocation']))
  325. {
  326. $this->settings['contentLocation'] = 'end';
  327. }
  328. if(!$this->settings['contentImage'] || empty($this->settings['contentImage']))
  329. {
  330. $this->settings['contentImage'] = 'button';
  331. }
  332. if(!$this->settings['contentPlayer'] || empty($this->settings['contentPlayer']))
  333. {
  334. $this->settings['contentPlayer'] = 'both';
  335. }
  336. if(!$this->settings['contentHidePlayerPlayNow'] || empty($this->settings['contentHidePlayerPlayNow']))
  337. {
  338. $this->settings['contentHidePlayerPlayNow'] = 'enabled';
  339. }
  340. if(FALSE == isset($this->settings['videoPreviewImage']) OR empty($this->settings['videoPreviewImage'])) {
  341. $this->settings['videoPreviewImage'] = PODPRESS_URL.'/images/vpreview_center.png';
  342. }
  343. if(!is_bool($this->settings['disableVideoPreview'])) {
  344. if($this->settings['disableVideoPreview']== 'true') {
  345. $this->settings['disableVideoPreview'] = true;
  346. } else {
  347. $this->settings['disableVideoPreview'] = false;
  348. }
  349. }
  350. if(!$this->settings['contentDownload'] || empty($this->settings['contentDownload']))
  351. {
  352. $this->settings['contentDownload'] = 'enabled';
  353. }
  354. if(!$this->settings['contentDownloadText'] || empty($this->settings['contentDownloadText']))
  355. {
  356. $this->settings['contentDownloadText'] = 'enabled';
  357. }
  358. if(!$this->settings['contentDownloadStats'] || empty($this->settings['contentDownloadStats']))
  359. {
  360. $this->settings['contentDownloadStats'] = 'enabled';
  361. }
  362. if(!$this->settings['contentDuration'] || empty($this->settings['contentDuration']))
  363. {
  364. $this->settings['contentDuration'] = 'enabled';
  365. }
  366. if ( FALSE == isset($this->settings['contentfilesize']) OR TRUE == empty($this->settings['contentfilesize'])) {
  367. $this->settings['contentfilesize'] = 'disabled';
  368. }
  369. if ( FALSE == isset($this->settings['incontentandexcerpt']) ) {
  370. $this->settings['incontentandexcerpt'] = 'in_content_and_excerpt';
  371. }
  372. if(!is_bool($this->settings['contentAutoDisplayPlayer'])) {
  373. if($this->settings['contentAutoDisplayPlayer'] == 'false') {
  374. $this->settings['contentAutoDisplayPlayer'] = false;
  375. } else {
  376. $this->settings['contentAutoDisplayPlayer'] = true;
  377. }
  378. }
  379. if ( FALSE == is_bool($this->settings['enableFooter']) ) {
  380. $this->settings['enableFooter'] = false;
  381. }
  382. if ( FALSE == isset($this->settings['mp3Player']) ) {
  383. $this->settings['mp3Player'] = '1pixelout';
  384. }
  385. if($this->settings['player']['bg'] == '') {
  386. $this->resetPlayerSettings();
  387. }
  388. if(empty($this->settings['iTunes']['summary'])) {
  389. $this->settings['iTunes']['summary'] = stripslashes(get_option('blogdescription'));
  390. } else {
  391. $this->settings['iTunes']['summary'] = stripslashes($this->settings['iTunes']['summary']);
  392. }
  393. $this->settings['iTunes']['keywords'] = stripslashes($this->settings['iTunes']['keywords']);
  394. $this->settings['iTunes']['subtitle'] = stripslashes($this->settings['iTunes']['subtitle']);
  395. $this->settings['iTunes']['author'] = stripslashes($this->settings['iTunes']['author']);
  396. $this->settings['iTunes']['FeedID'] = stripslashes($this->settings['iTunes']['FeedID']);
  397. $this->settings['iTunes']['FeedID'] = str_replace(' ', '', $this->settings['iTunes']['FeedID']);
  398. if(!empty($this->settings['iTunes']['FeedID']) && !is_numeric($this->settings['iTunes']['FeedID'])) {
  399. $this->settings['iTunes']['FeedID'] = settype($this->settings['iTunes']['FeedID'], 'double');
  400. }
  401. if(empty($this->settings['iTunes']['explicit'])) {
  402. $this->settings['iTunes']['explicit'] = 'No';
  403. }
  404. if(empty($this->settings['iTunes']['image'])) {
  405. $x = get_option('rss_image');
  406. if ( FALSE !== $x && $x != podPress_url().'images/powered_by_podpress.jpg') {
  407. $this->settings['iTunes']['image'] = $x;
  408. } else {
  409. $this->settings['iTunes']['image'] = podPress_url().'images/powered_by_podpress_large.jpg';
  410. }
  411. }
  412. if ( FALSE == isset($this->settings['iTunes']['new-feed-url']) OR ('Enable' != $this->settings['iTunes']['new-feed-url'] AND 'Disable' != $this->settings['iTunes']['new-feed-url']) ) {
  413. $this->settings['iTunes']['new-feed-url'] = 'Disable';
  414. }
  415. if ( FALSE == isset($this->settings['iTunes']['block']) OR ('Yes' != $this->settings['iTunes']['block'] AND 'No' != $this->settings['iTunes']['block']) ) {
  416. $this->settings['iTunes']['block'] = 'No';
  417. }
  418. if ( FALSE == isset($this->settings['rss_license_url']) ) {
  419. $this->settings['rss_license_url'] = '';
  420. }
  421. // since 8.8.8: default settings for the fully customizable feeds
  422. if ( FALSE == is_array($this->settings['podpress_feeds']) OR empty($this->settings['podpress_feeds']) ) {
  423. $email = get_option('admin_email');
  424. if ( FALSE === $email ) {
  425. $email = '';
  426. }
  427. $tagline = $this->settings['iTunes']['subtitle'];
  428. if ( FALSE === $tagline ) {
  429. $tagline = '';
  430. }
  431. $blog_charset = get_bloginfo('charset');
  432. $rss_language = get_option('rss_language');
  433. if ( FALSE === $rss_language ) { $rss_language = 'en'; }
  434. $rss_image = get_option('rss_image');
  435. if ( FALSE === $rss_image OR TRUE == empty($rss_image) ) {
  436. $rss_image = PODPRESS_URL.'/images/powered_by_podpress.jpg';
  437. }
  438. $ttl = get_option('rss_ttl');
  439. if ( FALSE === $ttl OR (!empty($ttl) && $ttl < 1440) ) {
  440. $ttl = 1440;
  441. }
  442. //~ if ( defined('PODPRESS_TAKEOVER_OLD_SETTINGS') AND TRUE === constant('PODPRESS_TAKEOVER_OLD_SETTINGS') ) {
  443. if ( FALSE == is_array($this->settings['iTunes']['category']) ) {
  444. $itunescategory = Array();
  445. }
  446. $this->settings['podpress_feeds'][0] = array(
  447. 'use' => TRUE,
  448. 'premium' => FALSE,
  449. 'name' => __('Podcast Feed', 'podpress'),
  450. 'slug' => 'podcast',
  451. 'feedtitle' => 'append',
  452. 'subtitle' => $tagline,
  453. 'itunes-newfeedurl' => 'Disable',
  454. 'descr' => $this->settings['iTunes']['summary'],
  455. 'itunes-category' => $itunescategory,
  456. 'rss_category' => $this->settings['rss_category'],
  457. 'itunes-keywords' => $this->settings['iTunes']['keywords'],
  458. 'itunes-author' => $this->settings['iTunes']['author'],
  459. 'email' => $email,
  460. 'itunes-image' => $this->settings['iTunes']['image'],
  461. 'rss_image' => $rss_image,
  462. 'copyright' => $this->settings['rss_copyright'],
  463. 'license_url' => $this->settings['rss_license_url'],
  464. 'language' => $rss_language,
  465. 'charset' => $blog_charset,
  466. 'FileTypes' => Array(),
  467. 'inclCategories' => Array(),
  468. 'show_only_podPress_podcasts' => TRUE,
  469. 'bypass_incl_selection' => FALSE,
  470. 'itunes-explicit' => $this->settings['iTunes']['explicit'],
  471. 'feedtype' => 'rss',
  472. 'ttl' => $ttl,
  473. 'itunes-feedid' => $this->settings['iTunes']['FeedID'],
  474. 'itunes-block' => $this->settings['iTunes']['block'],
  475. 'use_headerlink' => FALSE
  476. );
  477. $this->settings['podpress_feeds'][1] = array(
  478. 'use' => FALSE,
  479. 'premium' => FALSE,
  480. 'name' => __('Enhanced Podcast Feed', 'podpress'),
  481. 'slug' => 'enhancedpodcast',
  482. 'feedtitle' => 'append',
  483. 'subtitle' => $tagline,
  484. 'itunes-newfeedurl' => 'Disable',
  485. 'descr' => $this->settings['iTunes']['summary'],
  486. 'itunes-category' => $itunescategory,
  487. 'rss_category' => $this->settings['rss_category'],
  488. 'itunes-keywords' => $this->settings['iTunes']['keywords'],
  489. 'itunes-author' => $this->settings['iTunes']['author'],
  490. 'email' => $email,
  491. 'itunes-image' => $this->settings['iTunes']['image'],
  492. 'rss_image' => $rss_image,
  493. 'copyright' => $this->settings['rss_copyright'],
  494. 'license_url' => $this->settings['rss_license_url'],
  495. 'language' => $rss_language,
  496. 'charset' => $blog_charset,
  497. 'FileTypes' => Array('audio_m4a', 'video_m4v'),
  498. 'inclCategories' => Array(),
  499. 'show_only_podPress_podcasts' => TRUE,
  500. 'bypass_incl_selection' => FALSE,
  501. 'itunes-explicit' => $this->settings['iTunes']['explicit'],
  502. 'feedtype' => 'atom',
  503. 'ttl' => $ttl,
  504. 'itunes-feedid' => $this->settings['iTunes']['FeedID'],
  505. 'itunes-block' => $this->settings['iTunes']['block'],
  506. 'use_headerlink' => FALSE
  507. );
  508. $this->settings['podpress_feeds'][2] = array(
  509. 'use' => FALSE,
  510. 'premium' => FALSE,
  511. 'name' => __('Torrent Feed', 'podpress'),
  512. 'slug' => 'torrent',
  513. 'feedtitle' => 'append',
  514. 'subtitle' => $tagline,
  515. 'itunes-newfeedurl' => 'Disable',
  516. 'descr' => $this->settings['iTunes']['summary'],
  517. 'itunes-category' => $itunescategory,
  518. 'rss_category' => $this->settings['rss_category'],
  519. 'itunes-keywords' => $this->settings['iTunes']['keywords'],
  520. 'itunes-author' => $this->settings['iTunes']['author'],
  521. 'email' => $email,
  522. 'itunes-image' => $this->settings['iTunes']['image'],
  523. 'rss_image' => $rss_image,
  524. 'copyright' => $this->settings['rss_copyright'],
  525. 'license_url' => $this->settings['rss_license_url'],
  526. 'language' => $rss_language,
  527. 'charset' => $blog_charset,
  528. 'FileTypes' => Array('torrent'),
  529. 'inclCategories' => Array(),
  530. 'show_only_podPress_podcasts' => TRUE,
  531. 'bypass_incl_selection' => FALSE,
  532. 'itunes-explicit' => $this->settings['iTunes']['explicit'],
  533. 'feedtype' => 'atom',
  534. 'ttl' => $ttl,
  535. 'itunes-feedid' => $this->settings['iTunes']['FeedID'],
  536. 'itunes-block' => $this->settings['iTunes']['block'],
  537. 'use_headerlink' => FALSE
  538. );
  539. if ( FALSE == defined('PODPRESS_DEACTIVATE_PREMIUM') OR FALSE === constant('PODPRESS_DEACTIVATE_PREMIUM') ) {
  540. $this->settings['podpress_feeds'][3] = array(
  541. 'use' => FALSE,
  542. 'premium' => TRUE,
  543. 'name' => __('Premium Feed', 'podpress'),
  544. 'slug' => 'premium',
  545. 'feedtitle' => 'append',
  546. 'subtitle' => $tagline,
  547. 'itunes-newfeedurl' => 'Disable',
  548. 'descr' => $this->settings['iTunes']['summary'],
  549. 'itunes-category' => $itunescategory,
  550. 'rss_category' => $this->settings['rss_category'],
  551. 'itunes-keywords' => $this->settings['iTunes']['keywords'],
  552. 'itunes-author' => $this->settings['iTunes']['author'],
  553. 'email' => $email,
  554. 'itunes-image' => $this->settings['iTunes']['image'],
  555. 'rss_image' => $rss_image,
  556. 'copyright' => $this->settings['rss_copyright'],
  557. 'license_url' => $this->settings['rss_license_url'],
  558. 'language' => $rss_language,
  559. 'charset' => $blog_charset,
  560. 'FileTypes' => Array(),
  561. 'inclCategories' => Array(),
  562. 'show_only_podPress_podcasts' => TRUE,
  563. 'bypass_incl_selection' => FALSE,
  564. 'itunes-explicit' => $this->settings['iTunes']['explicit'],
  565. 'feedtype' => 'rss',
  566. 'ttl' => $ttl,
  567. 'itunes-feedid' => $this->settings['iTunes']['FeedID'],
  568. 'itunes-block' => $this->settings['iTunes']['block'],
  569. 'use_headerlink' => FALSE
  570. );
  571. }
  572. //~ } else {
  573. //~ // in case it is a first time installation
  574. //~ $this->settings['podpress_feeds'][0] = array(
  575. //~ 'use' => TRUE,
  576. //~ 'premium' => FALSE,
  577. //~ 'name' => __('Podcast Feed', 'podpress'),
  578. //~ 'slug' => 'podcast',
  579. //~ 'feedtitle' => 'append',
  580. //~ 'subtitle' => '',
  581. //~ 'itunes-newfeedurl' => 'Disable',
  582. //~ 'descr' => '',
  583. //~ 'itunes-category' => Array(),
  584. //~ 'rss_category' => '',
  585. //~ 'itunes-keywords' => '',
  586. //~ 'itunes-author' => '',
  587. //~ 'email' => '',
  588. //~ 'itunes-image' => $this->settings['iTunes']['image'],
  589. //~ 'rss_image' => $rss_image,
  590. //~ 'copyright' => $this->settings['rss_copyright'],
  591. //~ 'license_url' => '',
  592. //~ 'language' => $rss_langauge,
  593. //~ 'charset' => $blog_charset,
  594. //~ 'FileTypes' => Array(),
  595. //~ 'itunes-explicit' => 'No',
  596. //~ 'feedtype' => 'rss',
  597. //~ 'ttl' => $ttl,
  598. //~ 'itunes-feedid' => '',
  599. //~ 'itunes-block' => 'No'
  600. //~ );
  601. //~ }
  602. }
  603. podPress_update_option('podPress_config', $this->settings);
  604. if (
  605. is_object($wp_rewrite)
  606. && is_array($wp_object_cache)
  607. && is_array($wp_object_cache['cache'])
  608. && is_array($wp_object_cache['cache']['options'])
  609. && is_array($wp_object_cache['cache']['options']['alloptions'])
  610. && is_array($wp_object_cache['cache']['options']['alloptions']['rewrite_rules'])
  611. && !strpos($wp_object_cache['cache']['options']['alloptions']['rewrite_rules'], 'playlist.xspf')
  612. ) {
  613. $wp_rewrite->flush_rules();
  614. }
  615. }
  616. function deactivate() {
  617. // at the moment I have nothing I would want to clean up
  618. }
  619. /**
  620. * make_upgrade - helps to update the current settings
  621. *
  622. * @package podPress
  623. * @since 8.8.8 beta 5
  624. *
  625. */
  626. function update_podpress_class($podpress_version_from_db = '0') {
  627. if (class_exists('podPressUpgrade_class')) {
  628. $u = new podPressUpgrade_class($podpress_version_from_db);
  629. $this->settings = $u->settings;
  630. }
  631. return $this;
  632. }
  633. function iTunesLink() {
  634. return '<a href="http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewPodcast?id='.$this->settings['iTunes']['FeedID'].'"><img src="'.podPress_url().'images/itunes.png" border="0" alt="View in iTunes"/></a>';
  635. }
  636. function PlayerDefaultSettings() {
  637. // ntm: these colors are from the recent audio-player plugin
  638. // The new colors should make it clear that the 1PixelOut player was also updated in 8.8.5
  639. $result['bg'] = '#E5E5E5';
  640. $result['text'] = '#333333';
  641. $result['leftbg'] = '#CCCCCC';
  642. $result['lefticon'] = '#333333';
  643. $result['volslider'] = '#666666';
  644. $result['voltrack'] = '#FFFFFF';
  645. $result['rightbg'] = '#B4B4B4';
  646. $result['rightbghover'] = '#999999';
  647. $result['righticon'] = '#333333';
  648. $result['righticonhover'] = '#FFFFFF';
  649. $result['loader'] = '#009900';
  650. $result['track'] = '#FFFFFF';
  651. $result['border'] = '#CCCCCC';
  652. $result['tracker'] = '#DDDDDD';
  653. $result['skip'] = '#666666';
  654. $result['slider'] = '#666666'; // this is only for the Podango player
  655. $result['initialvolume'] = 70; // for 1Pixelout player (since podPress 8.8.5.2)
  656. $result['buffer'] = 5; // for 1Pixelout player (since podPress 8.8.5.2)
  657. $result['checkpolicy'] = 'no'; // for 1Pixelout player (since podPress 8.8.5.2)
  658. // player settings which are no direct resp. JS parameters of the players
  659. $result['overwriteTitleandArtist'] = 'no'; // for 1Pixelout player (since podPress 8.8.5.2)
  660. $result['listenWrapper'] = false;
  661. return $result;
  662. }
  663. function resetPlayerSettings() {
  664. $result = $this->PlayerDefaultSettings();
  665. $this->settings['player'] = $result;
  666. return $result;
  667. }
  668. function convertPodcastFileNameToValidWebPath($filename) {
  669. if ( strpos(substr($filename, 0, 10), '://') ) {
  670. $url = $filename;
  671. } else {
  672. if ( substr($filename, 0,1) == '/' ) {
  673. $baseurl = strtolower(strtok($_SERVER['SERVER_PROTOCOL'], '/')).'://'.$_SERVER['HTTP_HOST'].$this->settings['mediaWebPath'];
  674. } elseif ( strpos(substr($this->settings['mediaWebPath'], 0, 10), '://') ) {
  675. $baseurl = $this->settings['mediaWebPath'];
  676. } else {
  677. $baseurl = get_option('siteurl').$this->settings['mediaWebPath'];
  678. }
  679. if ( substr($filename, -1, 1) != '/' ) {
  680. $baseurl .= '/';
  681. }
  682. $url = $baseurl.$filename;
  683. }
  684. return $url;
  685. }
  686. function convertPodcastFileNameToWebPath($postID, $mediaNum, $filename = '', $method = false){
  687. $url = $this->convertPodcastFileNameToValidWebPath($filename);
  688. if($method != false) {
  689. if($this->settings['enableStats']) {
  690. $filename_part = podPress_getFileName($url);
  691. if($this->settings['statMethod'] == 'download.mp3') {
  692. $url = podPress_url().'download.mp3?'.$method.'='.$postID.'/'.$mediaNum.'/'.$filename_part;
  693. } else {
  694. $url = get_bloginfo('home').'/podpress_trac/'.$method.'/'.$postID.'/'.$mediaNum.'/'.$filename_part;
  695. }
  696. } elseif($this->settings['enable3rdPartyStats'] == 'Podtrac') {
  697. $url = str_replace(array('ftp://', 'http://', 'https://'), '', $url);
  698. $url = $this->podtrac_url.$url;
  699. } elseif($this->settings['enable3rdPartyStats'] == 'BluBrry' && !empty($this->settings['statBluBrryProgramKeyword'])) {
  700. $url = $this->blubrry_url.$this->settings['statBluBrryProgramKeyword'].'/'.$url;
  701. }
  702. }
  703. $url = str_replace(' ', '%20', $url);
  704. return $url;
  705. }
  706. function convertPodcastFileNameToSystemPath($filename = ''){
  707. if( FALSE === strpos(substr($filename, 0, 10), '://') ) {
  708. //if ( FALSE === empty($this->settings['mediaFilePath']) ) {
  709. $filename = $this->settings['mediaFilePath'].'/'.$filename;
  710. if(file_exists($filename))
  711. {
  712. return $filename;
  713. }
  714. //}
  715. }
  716. return false;
  717. }
  718. /**
  719. * TryToFindAbsFileName - tries to build a absolute path for the given URL and checks whether the build path exists and is local or not. This inetended deal with the (real) URLs of the media files
  720. *
  721. * @package podPress
  722. * @since 8.8.6 beta 1
  723. *
  724. * @param str $url - The (real) URL of a media file. (real URL means the URL of a media file and not the URLs masked for statistics)
  725. *
  726. * @return mixed the abspath to the file or FALSE
  727. */
  728. function TryToFindAbsFileName($url = '') {
  729. if (FALSE == empty($url)) {
  730. $uploadpath = $this->uploadpath;
  731. // remove drive letter
  732. $uploadpath_WL = end(explode(':', $uploadpath));
  733. // remove doubled backslashes
  734. $uploadpath_san1 = str_replace("\\\\", "\\", $uploadpath_WL);
  735. // replace backslash with slashes
  736. $uploadpath_san2 = str_replace("\\", "/", $uploadpath_san1);
  737. $uploadpath_parts = explode('/', $uploadpath_san2);
  738. //$result= parse_url($url);
  739. $home= get_bloginfo('home');
  740. $result['path'] = str_replace($home, '', $url);
  741. $urlpath_parts = explode('/', $result['path']);
  742. $diff = array_diff($urlpath_parts, $uploadpath_parts);
  743. $filename = $uploadpath.'/'.implode('/', $diff);
  744. if (TRUE === file_exists($filename)) {
  745. return $filename;
  746. } else {
  747. return false;
  748. }
  749. } else {
  750. return false;
  751. }
  752. }
  753. /**
  754. * checkWritableTempFileDir - (return values different since 8.8.6) controls whether the podPress temp/-folder is exists, or can be created and is writeable. This folder is e.g. uploads/podpress_temp/
  755. *
  756. * @package podPress
  757. * @since 8.8.6 beta 5
  758. *
  759. * @param bool $returnMessages - If it is true then the function returns in case of an error instead of false a string.
  760. *
  761. * @return mixed - TRUE if the folder exists and is writeable / FALSE or a string if there is a problem
  762. */
  763. function checkWritableTempFileDir($returnMessages = FALSE) {
  764. $siteurl = get_option('siteurl');
  765. if (file_exists($this->tempfilesystempath)) {
  766. if(is_writable($this->tempfilesystempath)) {
  767. if ($returnMessages) {
  768. return __('(The folder is writeable.)', 'podpress');
  769. } else {
  770. return true;
  771. }
  772. } else {
  773. if ($returnMessages) {
  774. return '<p class="message error">'.sprintf(__('Your uploads/podpress_temp directory is not writable. Please set permissions as needed, and make sure <a href="%1$s/wp-admin/options-misc.php">configuration</a> is correct.', 'podpress'), $siteurl).'<br />'.__('Currently set to:', 'podpress').'<code>'.$this->tempfilesystempath."</code></p>\n";
  775. } else {
  776. return false;
  777. }
  778. }
  779. } elseif (!file_exists($this->uploadpath)) {
  780. if ($returnMessages) {
  781. return '<p class="message error">'.sprintf(__('Your WordPress upload directory does not exist. Please create it and make sure <a href="%1$s/wp-admin/options-misc.php">configuration</a> is correct.', 'podpress'), $siteurl).'<br />'.__('Currently set to:', 'podpress').'<code>'.$this->uploadpath."</code></p>\n";
  782. } else {
  783. return false;
  784. }
  785. } elseif (!is_writable($this->uploadpath)) {
  786. if ($returnMessages) {
  787. return '<p class="message error">'.sprintf(__('Your WordPress upload directory is not writable. Please set permissions as needed, and make sure <a href="%1$s/wp-admin/options-misc.php">configuration</a> is correct.', 'podpress'), $siteurl).'<br />'.__('Currently set to:', 'podpress').'<code>'.$this->uploadpath."</code></p>\n";
  788. } else {
  789. return false;
  790. }
  791. } else {
  792. $mkdir = @mkdir($this->tempfilesystempath);
  793. if (!$mkdir) {
  794. if ($returnMessages) {
  795. return '<p class="message error">'.__('Could not create uploads/podpress_temp directory. Please set permission of the following directory to 755 or 777:', 'podpress').'<br /><code>'.$this->tempfilesystempath."</code></p>\n";
  796. } else {
  797. return false;
  798. }
  799. } else {
  800. if ($returnMessages) {
  801. return __('(The folder is writeable.)', 'podpress');
  802. } else {
  803. return true;
  804. }
  805. }
  806. }
  807. }
  808. /*************************************************************/
  809. /* Load up the plugin values and get ready to action */
  810. /*************************************************************/
  811. function addPostData($input, $forEdit = false) {
  812. $input->podPressMedia = podPress_get_post_meta($input->ID, '_podPressMedia', true);
  813. if(!is_array($input->podPressMedia)) {
  814. $x = maybe_unserialize($input->podPressMedia);
  815. if(is_array($x)) {
  816. $input->podPressMedia = $x;
  817. }
  818. if(!is_array($input->podPressMedia)) {
  819. $x = maybe_unserialize($input->podPressMedia, true);
  820. if(is_array($x)) {
  821. $input->podPressMedia = $x;
  822. }
  823. }
  824. }
  825. if(is_array($input->podPressMedia)) {
  826. reset($input->podPressMedia);
  827. while (list($key) = each($input->podPressMedia)) {
  828. if( !empty($input->podPressMedia[$key]['URI']) ) {
  829. if ( TRUE == isset($input->podPressMedia[$key]['premium_only']) AND ($input->podPressMedia[$key]['premium_only'] == 'on' || $input->podPressMedia[$key]['premium_only'] == true) ) {
  830. $input->podPressMedia[$key]['content_level'] = 'premium_content';
  831. } elseif ( !isset($input->podPressMedia[$key]['content_level']) ) {
  832. $input->podPressMedia[$key]['content_level'] = 'free';
  833. }
  834. if(!isset($input->podPressMedia[$key]['type'])) {
  835. $input->podPressMedia[$key]['type'] = '';
  836. }
  837. settype($input->podPressMedia[$key]['size'], 'int');
  838. if(0 >= $input->podPressMedia[$key]['size']) {
  839. $filepath = $this->convertPodcastFileNameToSystemPath($input->podPressMedia[$key]['URI']);
  840. if($filepath) {
  841. $input->podPressMedia[$key]['size'] = filesize ($filepath);
  842. } else {
  843. $input->podPressMedia[$key]['size'] = 1;
  844. }
  845. }
  846. $input->podPressMedia[$key]['ext'] = podPress_getFileExt($input->podPressMedia[$key]['URI']);
  847. $input->podPressMedia[$key]['mimetype'] = podPress_mimetypes($input->podPressMedia[$key]['ext']);
  848. if(!$forEdit && $this->settings['enablePremiumContent'] && $input->podPressMedia[$key]['content_level'] != 'free' && @$GLOBALS['current_user']->allcaps[$input->podPressMedia[$key]['content_level']] != 1) {
  849. $input->podPressMedia[$key]['authorized'] = false;
  850. $input->podPressMedia[$key]['URI'] = '';
  851. $input->podPressMedia[$key]['URI_torrent'] = '';
  852. } else {
  853. $input->podPressMedia[$key]['authorized'] = true;
  854. }
  855. }
  856. }
  857. }
  858. $input->podPressPostSpecific = podPress_get_post_meta($input->ID, '_podPressPostSpecific', true);
  859. if(!is_array($input->podPressPostSpecific)) {
  860. $input->podPressPostSpecific = array();
  861. }
  862. if(empty($input->podPressPostSpecific['itunes:subtitle'])) {
  863. $input->podPressPostSpecific['itunes:subtitle'] = '##PostExcerpt##';
  864. }
  865. if(empty($input->podPressPostSpecific['itunes:summary'])) {
  866. $input->podPressPostSpecific['itunes:summary'] = '##PostExcerpt##';
  867. }
  868. if(empty($input->podPressPostSpecific['itunes:keywords'])) {
  869. $input->podPressPostSpecific['itunes:keywords'] = '##WordPressCats##';
  870. }
  871. if(empty($input->podPressPostSpecific['itunes:author'])) {
  872. $input->podPressPostSpecific['itunes:author'] = '##Global##';
  873. }
  874. if(empty($input->podPressPostSpecific['itunes:explicit'])) {
  875. $input->podPressPostSpecific['itunes:explicit'] = 'Default';
  876. }
  877. if(empty($input->podPressPostSpecific['itunes:block'])) {
  878. $input->podPressPostSpecific['itunes:block'] = 'Default';
  879. }
  880. return $input;
  881. }
  882. function the_posts($input) {
  883. if ( FALSE === is_admin() && !$this->settings['compatibilityChecks']['themeTested'] ) {
  884. $this->settings['compatibilityChecks']['themeTested'] = true;
  885. podPress_update_option('podPress_config', $this->settings);
  886. }
  887. if(!is_array($input)) {
  888. return $input;
  889. }
  890. foreach($input as $key=>$value) {
  891. $input[$key] = $this->addPostData($value);
  892. }
  893. return $input;
  894. }
  895. /**
  896. * posts_distinct - filter function which return 'DISTINCT' while it is a search query. because joining the postmeta data leads to duplicate posts in the result list.
  897. *
  898. * @package podPress
  899. * @since 8.8.10 beta 2
  900. *
  901. * @param str $input
  902. *
  903. * @return str $input - is 'DISTINCT' or an empty string
  904. */
  905. function posts_distinct($input) {
  906. if ( is_search() AND isset($this->settings['activate_podpressmedia_search']) AND TRUE === $this->settings['activate_podpressmedia_search'] ) {
  907. $input = "DISTINCT";
  908. }
  909. return apply_filters('podpress_posts_distinct', $input);
  910. }
  911. function posts_join($input) {
  912. GLOBAL $wpdb;
  913. if ( is_search() AND isset($this->settings['activate_podpressmedia_search']) AND TRUE === $this->settings['activate_podpressmedia_search'] ) {
  914. $input .= " JOIN ".$wpdb->prefix."postmeta ON ".$wpdb->prefix."posts.ID=".$wpdb->prefix."postmeta.post_id ";
  915. } else {
  916. if ( defined('PODPRESS_PODCASTSONLY') AND FALSE !== constant('PODPRESS_PODCASTSONLY') ) {
  917. $input .= " JOIN ".$wpdb->prefix."postmeta ON ".$wpdb->prefix."posts.ID=".$wpdb->prefix."postmeta.post_id ";
  918. }
  919. }
  920. return apply_filters('podpress_posts_join', $input);
  921. }
  922. function posts_where($input) {
  923. GLOBAL $wpdb, $wp;
  924. if ( is_search() AND isset($this->settings['activate_podpressmedia_search']) AND TRUE === $this->settings['activate_podpressmedia_search'] ) {
  925. // search in the URI and title for the term
  926. $input .= " OR (".$wpdb->prefix."postmeta.meta_key='_podPressMedia' AND ( 1 = (".$wpdb->prefix."postmeta.meta_value REGEXP 's:5:\"title\";s:[0-9]+:\".*".$wpdb->escape($wp->query_vars['s'])."') OR 1 = (".$wpdb->prefix."postmeta.meta_value REGEXP 's:3:\"URI\";s:[0-9]+:\".*".$wp->query_vars['s']."')) )";
  927. } else {
  928. if ( defined('PODPRESS_PODCASTSONLY') AND FALSE !== constant('PODPRESS_PODCASTSONLY') ) {
  929. $input .= " AND ".$wpdb->prefix."postmeta.meta_key='_podPressMedia' ";
  930. }
  931. }
  932. return apply_filters('podpress_posts_where', $input);
  933. }
  934. function insert_the_excerpt($content = '') {
  935. GLOBAL $post;
  936. if ( FALSE == !empty($post->post_excerpt) ) {
  937. $this->tempcontentaddedto[$post->ID] = true;
  938. }
  939. $this->isexcerpt = true;
  940. return $content;
  941. }
  942. function insert_the_excerptplayer($content = '') {
  943. GLOBAL $post;
  944. $this->isexcerpt = true;
  945. $content = $this->insert_content($content, TRUE);
  946. return $content;
  947. }
  948. function insert_content($content = '', $is_the_excerpt = FALSE) {
  949. GLOBAL $post, $podPressTemplateData, $podPressTemplateUnauthorizedData, $wpdb;
  950. if ( !empty($post->post_password) ) { // if there's a password
  951. if ( stripslashes($_COOKIE['wp-postpass_'.COOKIEHASH]) != $post->post_password ) { // and it doesn't match the cookie
  952. return $content;
  953. }
  954. }
  955. if ( $this->isexcerpt === $is_the_excerpt ) {
  956. unset($this->tempcontentaddedto[$post->ID]);
  957. }
  958. $this->isexcerpt = FALSE;
  959. if ( isset($this->tempcontentaddedto[$post->ID]) ) {
  960. if ( is_feed() ) {
  961. return str_replace($this->podcasttag,'',$content);
  962. } else {
  963. return $content;
  964. }
  965. } else {
  966. $this->tempcontentaddedto[$post->ID] = true;
  967. }
  968. if ( is_feed() ) {
  969. return str_replace($this->podcasttag, '', $content);
  970. }
  971. if(!is_array($post->podPressMedia)) {
  972. return str_replace($this->podcasttag,'',$content);
  973. }
  974. if ( FALSE === stristr($content, $this->podcasttag) ) {
  975. if($this->settings['contentBeforeMore'] == 'no') {
  976. if (is_home() or is_archive()) {
  977. if ( FALSE !== strpos($post->post_content, '<!--more-->') ) {
  978. return $content;
  979. }
  980. }
  981. }
  982. if($this->settings['contentLocation'] == 'start') {
  983. $content = $this->podcasttag.$content;
  984. } else {
  985. $content .= $this->podcasttag;
  986. }
  987. }
  988. $podpressTag_in_the_content = '<p>'.$this->podcasttag.'</p>';
  989. // add the player and the other elements not if the related setting has been set
  990. if ( TRUE == isset($this->settings['incontentandexcerpt']) ) {
  991. if ( $is_the_excerpt === TRUE ) {
  992. switch ( $this->settings['incontentandexcerpt'] ) {
  993. default :
  994. case 'in_content_and_excerpt' :
  995. case 'in_excerpt_only' :
  996. break;
  997. case 'in_content_only' :
  998. if ( FALSE !== stripos($content, $podpressTag_in_the_content) ) {
  999. return str_replace($podpressTag_in_the_content, '', $content);
  1000. } else {
  1001. return str_replace($this->podcasttag,'',$content);
  1002. }
  1003. break;
  1004. }
  1005. } else {
  1006. switch ( $this->settings['incontentandexcerpt'] ) {
  1007. default :
  1008. case 'in_content_and_excerpt' :
  1009. case 'in_content_only' :
  1010. break;
  1011. case 'in_excerpt_only' :
  1012. if ( FALSE !== stripos($content, $podpressTag_in_the_content) ) {
  1013. return str_replace($podpressTag_in_the_content, '', $content);
  1014. } else {
  1015. return str_replace($this->podcasttag,'',$content);
  1016. }
  1017. break;
  1018. }
  1019. }
  1020. }
  1021. //~ $podPressRSSContent = '';
  1022. $showmp3player = false;
  1023. $showvideopreview = false;
  1024. $showvideoplayer = false;
  1025. $podPressTemplateData = array();
  1026. $podPressTemplateData['showDownloadText'] = $this->settings['contentDownloadText'];
  1027. $podPressTemplateData['showDownloadStats'] = $this->settings['contentDownloadStats'];
  1028. $podPressTemplateData['showDuration'] = $this->settings['contentDuration'];
  1029. $podPressTemplateData['showfilesize'] = $this->settings['contentfilesize'];
  1030. $this->playerCount++;
  1031. $podPressTemplateData['files'] = array();
  1032. $podPressTemplateData['player'] = array();
  1033. reset($post->podPressMedia);
  1034. while (list($key) = each($post->podPressMedia)) {
  1035. if(empty($post->podPressMedia[$key]['previewImage'])) {
  1036. $post->podPressMedia[$key]['previewImage'] = $this->settings['videoPreviewImage'];
  1037. }
  1038. $supportedVideoTypes = array('video_mp4', 'video_m4v', 'video_mov', 'video_qt', 'video_avi', 'video_mpg', 'video_asf', 'video_wmv', 'video_flv', 'video_swf', 'video_ogv');
  1039. if (TRUE == $this->settings['disableVideoPreview'] AND TRUE == in_array($post->podPressMedia[$key]['type'], $supportedVideoTypes)) {
  1040. $post->podPressMedia[$key]['disablePreview'] = true;
  1041. }
  1042. if ( TRUE == isset($post->podPressMedia[$key]['feedonly']) AND 'on' == $post->podPressMedia[$key]['feedonly'] ) {
  1043. continue;
  1044. }
  1045. $post->podPressMedia[$key]['title'] = htmlentities(stripslashes($post->podPressMedia[$key]['title']), ENT_QUOTES, get_option('blog_charset'));
  1046. $post->podPressMedia[$key]['stats'] = false;
  1047. if($this->settings['enableStats']) {
  1048. $pos = strrpos($post->podPressMedia[$key]['URI'], '/');
  1049. //$len = strlen($post->podPressMedia[$key]['URI']);
  1050. while(substr($post->podPressMedia[$key]['URI'], $pos, 1) == '/') {
  1051. $pos++;
  1052. }
  1053. $filename = substr($post->podPressMedia[$key]['URI'], $pos);
  1054. if($this->settings['statLogging'] == 'Full' || $this->settings['statLogging'] == 'FullPlus') {
  1055. $where = $this->wherestr_to_exclude_bots('', 'AND');
  1056. $query_string="SELECT method, COUNT(DISTINCT id) as downloads FROM ".$wpdb->prefix."podpress_stats WHERE postID='".$post->ID."' AND media='".rawurlencode($filename)."' ".$where."GROUP BY method ORDER BY method ASC";
  1057. $stats = $wpdb->get_results($query_string);
  1058. if (0 < count($stats)) {
  1059. $feed = intval($stats[0]->downloads);
  1060. $play = intval($stats[1]->downloads);
  1061. $web = intval($stats[2]->downloads);
  1062. $post->podPressMedia[$key]['stats'] = array('feed'=>$feed, 'web'=>$web, 'play'=>$play, 'total'=>($feed+$play+$web));
  1063. }
  1064. } else {
  1065. $sql = "SELECT * FROM ".$wpdb->prefix."podpress_statcounts WHERE media = '".rawurlencode($filename)."'";
  1066. $stats = $wpdb->get_results($sql);
  1067. if($stats) {
  1068. $post->podPressMedia[$key]['stats'] = array('feed'=>intval($stats[0]->feed), 'web'=>intval($stats[0]->web), 'play'=>intval($stats[0]->play), 'total'=>intval($stats[0]->total));
  1069. }
  1070. }
  1071. }
  1072. $supportedMediaTypes = array('audio_mp3', 'audio_ogg', 'audio_m4a', 'audio_mp4', 'audio_m3u', 'video_mp4', 'video_m4v', 'video_mov', 'video_qt', 'video_avi', 'video_mpg', 'video_asf', 'video_wmv', 'audio_wma', 'video_flv', 'video_swf', 'video_ogv', 'ebook_pdf', 'ebook_epub', 'embed_youtube', 'misc_torrent');
  1073. if(!in_array($post->podPressMedia[$key]['type'], $supportedMediaTypes)) {
  1074. $post->podPressMedia[$key]['type'] = 'misc_other';
  1075. }
  1076. // this loop is for the basics. After this the unauthorized content will stop
  1077. if(empty($post->podPressMedia[$key]['title'])) {
  1078. $post->podPressMedia[$key]['title'] = podPress_defaultTitles($post->podPressMedia[$key]['type']);
  1079. }
  1080. if ( '##Global##' == $post->podPressPostSpecific['itunes:author'] ) {
  1081. Global $podPress;
  1082. if (empty($podPress->settings['iTunes']['author'])) {
  1083. $post->podPressMedia[$key]['artist'] = get_bloginfo('blogname');
  1084. } else {
  1085. $post->podPressMedia[$key]['artist'] = $podPress->settings['iTunes']['author'];
  1086. }
  1087. } else {
  1088. $post->podPressMedia[$key]['artist'] = $post->podPressPostSpecific['itunes:author'];
  1089. }
  1090. if($this->settings['contentImage'] != 'none') {
  1091. $post->podPressMedia[$key]['image'] = $post->podPressMedia[$key]['type'].'_'.$this->settings['contentImage'].'.png';
  1092. }
  1093. if($post->podPressMedia[$key]['authorized']) {
  1094. $post->podPressMedia[$key]['URI_orig'] = $post->podPressMedia[$key]['URI'];
  1095. $post->podPressMedia[$key]['URI'] = $this->convertPodcastFileNameToWebPath($post->ID, $key, $post->podPressMedia[$key]['URI'], 'web');
  1096. $post->podPressMedia[$key]['URI_Player'] = $this->convertPodcastFileNameToWebPath($post->ID, $key, $post->podPressMedia[$key]['URI_orig'], 'play');
  1097. if(!empty($post->podPressMedia[$key]['URI_torrent'])) {
  1098. $post->podPressMedia[$key]['URI_torrent'] = $this->convertPodcastFileNameToWebPath($post->ID, $key, $post->podPressMedia[$key]['URI_torrent'], 'web');
  1099. }
  1100. if($this->settings['contentDownload'] == 'disabled') {
  1101. $post->podPressMedia[$key]['enableDownload'] = false;
  1102. $post->podPressMedia[$key]['enableTorrentDownload'] = false;
  1103. } else {
  1104. $post->podPressMedia[$key]['enableDownload'] = true;
  1105. //~ $podPressRSSContent .= '<a href="'.$post->podPressMedia[$key]['URI'].'">'.__('Download', 'podpress').' '.__($post->podPressMedia[$key]['title'], 'podpress').'</a><br/>';
  1106. if($this->settings['enableTorrentCasting'] && !empty($post->podPressMedia[$key]['URI_torrent'])) {
  1107. $post->podPressMedia[$key]['enableTorrentDownload'] = true;
  1108. }
  1109. }
  1110. switch($this->settings['contentPlayer']) {
  1111. case 'disabled':
  1112. $post->podPressMedia[$key]['enablePlayer'] = false;
  1113. $post->podPressMedia[$key]['enablePopup'] = false;
  1114. break;
  1115. case 'inline':
  1116. $post->podPressMedia[$key]['enablePlayer'] = true;
  1117. $post->podPressMedia[$key]['enablePopup'] = false;
  1118. break;
  1119. case 'popup':
  1120. $post->podPressMedia[$key]['enablePlayer'] = false;
  1121. $post->podPressMedia[$key]['enablePopup'] = true;
  1122. break;
  1123. case 'both':
  1124. $post->podPressMedia[$key]['enablePlayer'] = true;
  1125. $post->podPressMedia[$key]['enablePopup'] = true;
  1126. default:
  1127. }
  1128. if($this->settings['contentHidePlayerPlayNow'] == 'disabled') {
  1129. $post->podPressMedia[$key]['enablePlaylink'] = FALSE;
  1130. } else {
  1131. $post->podPressMedia[$key]['enablePlaylink'] = TRUE;
  1132. }
  1133. if($post->podPressMedia[$key]['enablePlayer']) {
  1134. // This loop is to put together the player data.
  1135. switch($post->podPressMedia[$key]['type']) {
  1136. case 'audio_mp3':
  1137. $post->podPressMedia[$key]['dimensionW'] = 290;
  1138. $post->podPressMedia[$key]['dimensionH'] = 24;
  1139. //~ $post->podPressMedia[$key]['dimensionW'] = 300;
  1140. //~ $post->podPressMedia[$key]['dimensionH'] = 30;
  1141. break;
  1142. case 'audio_ogg':
  1143. case 'audio_m4a':
  1144. case 'audio_mp4':
  1145. case 'audio_wma':
  1146. case 'video_ogv':
  1147. case 'video_m4v':
  1148. case 'video_mp4':
  1149. case 'video_mov':
  1150. case 'video_qt':
  1151. case 'video_avi':
  1152. case 'video_mpg':
  1153. case 'video_asf':
  1154. case 'video_wmv':
  1155. case 'video_flv':
  1156. case 'video_swf':
  1157. break;
  1158. case 'embed_youtube':
  1159. $x = parse_url($post->podPressMedia[$key]['URI_orig']);
  1160. $x = explode('&', $x['query']);
  1161. foreach($x as $v) {
  1162. if(substr($v, 0, 2) == 'v=') {
  1163. if(str_replace('/', '', $post->podPressMedia[$key]['previewImage']) == str_replace('/', '', $this->settings['videoPreviewImage'])) {
  1164. $post->podPressMedia[$key]['previewImage'] = 'http://img.youtube.com/vi/'. substr($v, 2).'/default.jpg';
  1165. }
  1166. $post->podPressMedia[$key]['URI_Player'] = substr($v, 2).'.youtube';
  1167. break;
  1168. }
  1169. }
  1170. $post->podPressMedia[$key]['URI'] = $post->podPressMedia[$key]['URI_orig'];
  1171. break;
  1172. case 'audio_m3u':
  1173. $post->podPressMedia[$key]['enableDownload'] = true;
  1174. case 'ebook_pdf':
  1175. case 'ebook_epub':
  1176. default:
  1177. $post->podPressMedia[$key]['enablePlayer'] = false;
  1178. $post->podPressMedia[$key]['enablePopup'] = false;
  1179. }
  1180. }
  1181. }
  1182. if ( TRUE == isset($post->podPressMedia[$key]['disablePlayer']) AND (TRUE === $post->podPressMedia[$key]['disablePlayer'] OR 'on' == $post->podPressMedia[$key]['disablePlayer'])) {
  1183. $post->podPressMedia[$key]['enablePlayer'] = false;
  1184. $post->podPressMedia[$key]['enablePopup'] = false;
  1185. }
  1186. $podPressTemplateData['files'][] = $post->podPressMedia[$key];
  1187. $post->podPressMedia[$key]['URI'] = $post->podPressMedia[$key]['URI_orig'];
  1188. unset($post->podPressMedia[$key]['URI_orig']);
  1189. }
  1190. if(!$this->settings['compatibilityChecks']['wp_head']) {
  1191. $podPressContent = '<code>'.__('podPress theme compatibility problem. Please check podPress->General Settings for more information.', 'podpress').'</code><br/>';
  1192. $this->settings['compatibilityChecks']['wp_head'] = false;
  1193. $this->settings['compatibilityChecks']['wp_footer'] = false;
  1194. podPress_update_option('podPress_config', $this->settings);
  1195. } else {
  1196. /* The theme file needs to populate these */
  1197. $podPressContent = podPress_webContent($podPressTemplateData);
  1198. }
  1199. if ( FALSE !== stripos($content, $podpressTag_in_the_content) ) {
  1200. return str_replace($podpressTag_in_the_content, $podPressContent, $content);
  1201. } else {
  1202. return str_replace($this->podcasttag, $podPressContent, $content);
  1203. }
  1204. }
  1205. /**
  1206. * feed_excerpt_filter - a function to filter the excerpt content (mainly to remove the podPress shortcode which is not desired in feed elements)
  1207. *
  1208. * @package podPress
  1209. * @since 8.8.10.7
  1210. *
  1211. * @param str $content - text which may contain the podPress shortcode to determine the position of the player at the blog page
  1212. *
  1213. * @return str the content without the podPress shortcode
  1214. */
  1215. function feed_excerpt_filter($content) {
  1216. return str_replace($this->podcasttag, '', $content);
  1217. }
  1218. function xmlrpc_post_addMedia($input) {
  1219. $postdata = $input['postdata'];
  1220. $content_struct = $input['content_struct'];
  1221. if(isset($content_struct['enclosure']) && !empty($content_struct['enclosure']['url'])) {
  1222. $media[0]['URI'] = $content_struct['enclosure']['url'];
  1223. $media[0]['authorized'] = true;
  1224. if(!empty($content_struct['enclosure']['type'])) {
  1225. $media[0]['type'] = $content_struct['enclosure']['type'];
  1226. } else {
  1227. $media[0]['type'] = podPress_mimetypes(podPress_getFileExt($content_struct['enclosure']['url']));
  1228. }
  1229. if($media[0]['type'] == 'video/x-ms-wmv') {
  1230. $media[0]['type'] = 'video/wmv';
  1231. } elseif($media[0]['type'] == 'video/x-flv') {
  1232. $media[0]['type'] = 'video/flv';
  1233. }
  1234. $media[0]['type'] = str_replace('/', '_', $media[0]['type']);
  1235. if(!empty($content_struct['enclosure']['duration'])) {
  1236. $media[0]['duration'] =$content_struct['enclosure']['duration'];
  1237. } else {
  1238. $media[0]['duration'] = 0;
  1239. }
  1240. if(!empty($content_struct['enclosure']['size'])) {
  1241. $media[0]['size'] = $content_struct['enclosure']['size'];
  1242. } else {
  1243. $media[0]['size'] = 0;
  1244. }
  1245. if(!empty($content_struct['enclosure']['title'])) {
  1246. $media[0]['title'] = $content_struct['enclosure']['title'];
  1247. }
  1248. if(!empty($content_struct['enclosure']['previewImage'])) {
  1249. $media[0]['previewImage'] = $content_struct['enclosure']['previewImage'];
  1250. }
  1251. if(!empty($content_struct['enclosure']['rss'])) {
  1252. $media[0]['rss'] = $content_struct['enclosure']['rss'];
  1253. } else {
  1254. $media[0]['rss'] = true;
  1255. }
  1256. delete_post_meta($postdata['ID'], '_podPressMedia');
  1257. podPress_add_post_meta($postdata['ID'], '_podPressMedia', $media, true) ;
  1258. }
  1259. return true;
  1260. }
  1261. /**
  1262. * wherestr_to_exclude_bots - builds a WHERE string to exclude bot IP addresses and user agents from the statistic output
  1263. *
  1264. * @package podPress
  1265. * @since 8.8.5 beta 3
  1266. *
  1267. * @param str $tablename [optional] - If you want to add the WHERE string to a query with data from two or more db tables then you should use this parameter to add the name of stats table.
  1268. * @param str $begin_phrase [optional] - If you have already a WHERE condition and you want to add this WHERE string to a query then you can use e.g. AND or OR instead of WHERE which is the default
  1269. *
  1270. * @return str WHERE string with one space at the end or an empty string
  1271. */
  1272. function wherestr_to_exclude_bots($tablename = '', $begin_phrase='WHERE') {
  1273. $botdb = get_option('podpress_botdb');
  1274. if (FALSE == empty($tablename)) {
  1275. $tablename = rtrim($tablename, '.');
  1276. $tablename .= '.';
  1277. }
  1278. $begin_phrase = trim($begin_phrase);
  1279. if (is_array($botdb) AND 0 < count($botdb)) {
  1280. if (is_array($botdb['fullbotnames']) AND 1 < count($botdb['fullbotnames'])) {
  1281. $where = $begin_phrase." ".$tablename."user_agent NOT IN ('". implode("', '", $botdb['fullbotnames'])."') ";
  1282. } elseif ( is_array($botdb['fullbotnames']) AND 1 == count($botdb['fullbotnames']) ) {
  1283. $where = $begin_phrase." ".$tablename."user_agent NOT IN ('". $botdb['fullbotnames'][0]."') ";
  1284. } else {
  1285. $where = '';
  1286. }
  1287. if ($where != '') {
  1288. $and_or_where = 'AND';
  1289. } else {
  1290. $and_or_where = $begin_phrase;
  1291. }
  1292. if (is_array($botdb['IP']) AND 1 < count($botdb['IP'])) {
  1293. $where .= $and_or_where." ".$tablename."remote_ip NOT IN ('". implode("', '", $botdb['IP'])."') ";
  1294. } elseif ( is_array($botdb['IP']) AND 1 == count($botdb['IP']) ) {
  1295. $where .= $and_or_where." ".$tablename."remote_ip NOT IN ('". $botdb['IP'][0]."') ";
  1296. } else {
  1297. $where .= '';
  1298. }
  1299. } else {
  1300. $where = '';
  1301. }
  1302. return $where;
  1303. }
  1304. /**
  1305. * cleanup_itunes_keywords - cleans the iTunes:Keywords up and gives a string back which contains max. 8 comma separated words. This string is escaped with strip_tags and htmlspecialchars and ready for storing it in a DB.
  1306. *
  1307. * @package podPress
  1308. * @since 8.8.5 beta 3
  1309. *
  1310. * @param str $rawstring - The raw input string.
  1311. * @param str $blog_charset [optional] - should be a PHP conform charset string like UTF-8
  1312. * @param bool $do_htmlspecialchars [optional] - do htmlspecialchars or not (since 8.8.10.7)
  1313. *
  1314. * @return str clean keyword string
  1315. */
  1316. function cleanup_itunes_keywords($rawstring='', $blog_charset='', $do_htmlspecialchars = TRUE) {
  1317. if ( FALSE === empty($rawstring) ) {
  1318. $tmpstring = strip_tags(trim($rawstring));
  1319. $tmpstring_parts = preg_split("/(\,)|(\s+)/", $tmpstring, -1, PREG_SPLIT_NO_EMPTY);
  1320. $i=0;
  1321. foreach ($tmpstring_parts as $tmpstring_part) {
  1322. $string_parts[] = $tmpstring_part;
  1323. if ( 11 == $i ) { // max 12 keywords
  1324. break;
  1325. }
  1326. $i++;
  1327. }
  1328. if ( TRUE === $do_htmlspecialchars ) {
  1329. if ( FALSE === empty($blog_charset) ) {
  1330. return htmlspecialchars(implode(', ', $string_parts), ENT_QUOTES, $blog_charset);
  1331. } else {
  1332. return htmlspecialchars(implode(', ', $string_parts), ENT_QUOTES);
  1333. }
  1334. } else {
  1335. return implode(', ', $string_parts);
  1336. }
  1337. } else {
  1338. return '';
  1339. }
  1340. }
  1341. // This function converts duration strings of the format minutes:seconds, hours:minutes:seconds and hours:minutes:seconds:milliseconds into milliseconds.
  1342. // Better ideas are welcome! Write a post here: http://wordpress.org/tags/podpress and use the tag "podpress".
  1343. function strtomilliseconds($durationstr) {
  1344. $dstr_parts=explode(':', $durationstr);
  1345. $nr_dstr_parts=count($dstr_parts);
  1346. if (1 < $nr_dstr_parts AND 5 > $nr_dstr_parts) {
  1347. switch ($nr_dstr_parts) {
  1348. case 2 :
  1349. // this method is only good if the input data which consist of two parts is most likely in the format m:s because
  1350. // m:s
  1351. $duration = $this->strtomilliseconds_core(1, 2, $dstr_parts);
  1352. break;
  1353. case 3 :
  1354. // h:m:s
  1355. $duration = $this->strtomilliseconds_core(0, 3, $dstr_parts);
  1356. break;
  1357. case 4 :
  1358. // h:m:s:ms
  1359. $duration = $this->strtomilliseconds_core(0, 4, $dstr_parts);
  1360. break;
  1361. }
  1362. }
  1363. if (!isset($duration) OR $duration < 0) {
  1364. $duration = 0;
  1365. }
  1366. return $duration;
  1367. }
  1368. function strtomilliseconds_core($startindex=0, $max_nr_parts=4, $dstr_parts=array()){
  1369. $duration = $j = 0;
  1370. if (!empty($dstr_parts)) {
  1371. for ($i=$startindex; $i < ($max_nr_parts+$startindex); $i++) {
  1372. switch ($i) {
  1373. case 0 : // hours
  1374. $duration += 3600000 * intval($dstr_parts[$j]);
  1375. $j++;
  1376. break;
  1377. case 1 : // minutes
  1378. $duration += 60000 * intval($dstr_parts[$j]);
  1379. $j++;
  1380. break;
  1381. case 2 : // seconds
  1382. $duration += 1000 * intval($dstr_parts[$j]);
  1383. $j++;
  1384. break;
  1385. case 3 : // milliseconds
  1386. $duration += intval($dstr_parts[$j]);
  1387. $j++;
  1388. break;
  1389. }
  1390. }
  1391. }
  1392. return $duration;
  1393. }
  1394. // This function gives the milliseconds value back in the format h:m:s or in a given format.
  1395. function millisecondstostring($duration, $format = 'h:m:s', $dimensionchr = ':', $decimals = 3, $dec_point = '.') {
  1396. if ( FALSE == is_string($format) OR empty($format) ) {
  1397. $format = 'h:m:s';
  1398. $parts = 3;
  1399. } else {
  1400. $format = strtolower($format);
  1401. $possible_formats = Array('h:m:s', 'm:s', 'h:m:s:ms', 'm:s:ms', 's:ms', 'h', 'm', 's', 'ms');
  1402. if ( FALSE == in_array($format, $possible_formats) ) {
  1403. $format = 'h:m:s';
  1404. $parts = 3;
  1405. } else {
  1406. $parts = substr_count( $format, ':' ) + 1;
  1407. }
  1408. }
  1409. // control the dimension character (/ divider)
  1410. if ( is_array($dimensionchr) AND (empty($dimensionchr) OR $parts > count($dimensionchr)) ) {
  1411. $dimensionchr = Array('h' => __('h', 'podpress'), 'm' => __('min', 'podpress'), 's' => __('s', 'podpress'), 'ms' => __('ms', 'podpress'));
  1412. }
  1413. Switch ($format) {
  1414. default :
  1415. case 'h:m:s' :
  1416. $dur['h'] = intval($duration / 3600000);
  1417. $dur['m'] = intval($duration / (60000) % 60);
  1418. $dur['s'] = intval($duration / (1000) % 60);
  1419. return $this->millisecondstostring_print($dur, $duration, $this->podpress_build_dimchr($dur, $dimensionchr));
  1420. break;
  1421. case 'm:s' :
  1422. $dur['m'] = intval($duration / 60000);
  1423. $dur['s'] = intval($duration / (1000) % 60);
  1424. return $this->millisecondstostring_print($dur, $duration, $this->podpress_build_dimchr($dur, $dimensionchr));
  1425. break;
  1426. case 'h:m:s:ms' :
  1427. $dur['h'] = intval($duration / 3600000);
  1428. $dur['m'] = intval($duration / (60000) % 60);
  1429. $dur['s'] = intval($duration / (1000) % 60);
  1430. $dur['ms'] = intval($duration % 1000);
  1431. return $this->millisecondstostring_print($dur, $duration, $this->podpress_build_dimchr($dur, $dimensionchr));
  1432. break;
  1433. case 'm:s:ms' :
  1434. $dur['m'] = intval($duration / 60000);
  1435. $dur['s'] = intval($duration / (1000) % 60);
  1436. $dur['ms'] = intval($duration % 1000);
  1437. return $this->millisecondstostring_print($dur, $duration, $this->podpress_build_dimchr($dur, $dimensionchr));
  1438. break;
  1439. case 's:ms' :
  1440. $dur['s'] = intval($duration / 1000);
  1441. $dur['ms'] = intval($duration % 1000);
  1442. return $this->millisecondstostring_print($dur, $duration, $this->podpress_build_dimchr($dur, $dimensionchr));
  1443. break;
  1444. case 'h' :
  1445. $hours = ($duration / 3600000);
  1446. if ( '.' == $dec_point OR ',' == $dec_point ) {
  1447. $duration_str = number_format($hours, intval($decimals), $dec_point, '');
  1448. } else {
  1449. $duration_str = number_format($hours);
  1450. }
  1451. $dimensionchr = $this->podpress_build_dimchr($dur, $dimensionchr);
  1452. if ( is_array($dimensionchr) AND isset($dimensionchr['h']) ) {
  1453. return $duration_str.' '.$dimensionchr['h'];
  1454. } else {
  1455. return $duration_str;
  1456. }
  1457. break;
  1458. case 'm' :
  1459. $minutes = ($duration / 60000);
  1460. if ( '.' == $dec_point OR ',' == $dec_point ) {
  1461. $duration_str = number_format($minutes, intval($decimals), $dec_point, '');
  1462. } else {
  1463. $duration_str = number_format($minutes);
  1464. }
  1465. $dimensionchr = $this->podpress_build_dimchr($dur, $dimensionchr);
  1466. if ( is_array($dimensionchr) AND isset($dimensionchr['m']) ) {
  1467. return $duration_str.' '.$dimensionchr['m'];
  1468. } else {
  1469. return $duration_str;
  1470. }
  1471. break;
  1472. case 's' :
  1473. $seconds = ($duration / 1000);
  1474. if ( '.' == $dec_point OR ',' == $dec_point ) {
  1475. $duration_str = number_format($seconds, intval($decimals), $dec_point, '');
  1476. } else {
  1477. $duration_str = number_format($seconds);
  1478. }
  1479. $dimensionchr = $this->podpress_build_dimchr($dur, $dimensionchr);
  1480. if ( is_array($dimensionchr) AND isset($dimensionchr['s']) ) {
  1481. return $duration_str.' '.$dimensionchr['s'];
  1482. } else {
  1483. return $duration_str;
  1484. }
  1485. break;
  1486. case 'ms' :
  1487. $dimensionchr = $this->podpress_build_dimchr($dur, $dimensionchr);
  1488. if ( is_array($dimensionchr) AND isset($dimensionchr['ms']) ) {
  1489. return $duration.' '.$dimensionchr['ms'];
  1490. } else {
  1491. return $duration;
  1492. }
  1493. break;
  1494. }
  1495. }
  1496. function millisecondstostring_print($dur, $duration_ms, $dimensionchr = ':') {
  1497. if ($duration_ms < 1000) { // the minimum return value should be 00:01 seconds (this is important for the <itunes:duration> string)
  1498. $dur = Array('m' => 0, 's'=> 1);
  1499. }
  1500. if ( is_array($dimensionchr) ) {
  1501. $use_non_default_dim = TRUE;
  1502. foreach ($dur as $key => $val) {
  1503. if ( FALSE == array_key_exists($key, $dimensionchr) ) {
  1504. $use_non_default_dim = FALSE;
  1505. }
  1506. }
  1507. } else {
  1508. $use_non_default_dim = FALSE;
  1509. }
  1510. $prev_empty = TRUE;
  1511. $dur_parts = count($dur);
  1512. if ( TRUE === $use_non_default_dim ) {
  1513. foreach ($dur as $dur_key => $dur_val) {
  1514. // don't print leading or trailing elements if they are zero and the numaber of elements is greater than 2 (2 elements minimum because the duration string should be atleast of the format m:ss)
  1515. if ( ($dur_parts > 2) AND (TRUE === $prev_empty AND 0 == $dur_val) OR ($dur_key == 'ms' AND $dur_val == 0) ) {
  1516. $prev_empty = TRUE;
  1517. } else {
  1518. // If it is not the leading element but a numerical digit then add a zero and make the string two digits wide.
  1519. if (TRUE !== $prev_empty AND 0 <= $dur_val AND 9 >= $dur_val) {
  1520. $dur_str_ar[] = '0'.$dur_val.' '.$dimensionchr[$dur_key];
  1521. } else {
  1522. $dur_str_ar[] = $dur_val.' '.$dimensionchr[$dur_key];
  1523. }
  1524. $prev_empty = FALSE;
  1525. }
  1526. $dur_parts--;
  1527. }
  1528. return implode(' ', $dur_str_ar);
  1529. } else {
  1530. foreach ($dur as $dur_key => $dur_val) {
  1531. if ( ($dur_parts > 3) AND (TRUE === $prev_empty AND 0 == $dur_val) OR ($dur_key == 'ms' AND $dur_val == 0) ) {
  1532. $prev_empty = TRUE;
  1533. } else {
  1534. if (TRUE !== $prev_empty AND 0 <= $dur_val AND 9 >= $dur_val) {
  1535. $dur_str_ar[] = '0'.$dur_val;
  1536. } else {
  1537. $dur_str_ar[] = $dur_val;
  1538. }
  1539. $prev_empty = FALSE;
  1540. }
  1541. $dur_parts--;
  1542. }
  1543. return implode(':', $dur_str_ar);
  1544. }
  1545. }
  1546. function podpress_build_dimchr($dur, $dimensionchr) {
  1547. global $wp_version;
  1548. if ( TRUE == is_array($dimensionchr) ) {
  1549. return $dimensionchr;
  1550. } else {
  1551. if ( FALSE == isset($dur['h']) ) {
  1552. $dur['h'] = 0;
  1553. }
  1554. if ( FALSE == isset($dur['m']) ) {
  1555. $dur['m'] = 0;
  1556. }
  1557. if ( FALSE == isset($dur['s']) ) {
  1558. $dur['s'] = 0;
  1559. }
  1560. if ( FALSE == isset($dur['ms']) ) {
  1561. $dur['ms'] = 0;
  1562. }
  1563. switch ( $dimensionchr ) {
  1564. case 'hminsms' :
  1565. return Array('h' => __('h', 'podpress'), 'm' => __('min', 'podpress'), 's' => __('s', 'podpress'), 'ms' => __('ms', 'podpress'));
  1566. break;
  1567. case 'hrminsecmsec' :
  1568. return Array('h' => __('hr.', 'podpress'), 'm' => __('min.', 'podpress'), 's' => __('sec.', 'podpress'), 'ms' => __('msec.', 'podpress'));
  1569. break;
  1570. case 'hoursminutessecondsmilliseconds' :
  1571. if (version_compare($wp_version, '2.8', '<')) {
  1572. return Array('h' => __ngettext('hour', 'hours', $dur['h'], 'podpress'), 'm' => __ngettext('minute', 'minutes', $dur['m'], 'podpress'), 's' => __ngettext('second', 'seconds', $dur['s'], 'podpress'), 'ms' => __ngettext('millisecond', 'milliseconds', $dur['ms'], 'podpress') );
  1573. } else {
  1574. return Array('h' => _n('hour', 'hours', $dur['h'], 'podpress'), 'm' => _n('minute', 'minutes', $dur['m'], 'podpress'), 's' => _n('second', 'seconds', $dur['s'], 'podpress'), 'ms' => _n('millisecond', 'milliseconds', $dur['ms'], 'podpress') );
  1575. }
  1576. break;
  1577. case 'colon' :
  1578. default :
  1579. return ':';
  1580. break;
  1581. }
  1582. }
  1583. }
  1584. }
  1585. ?>