Ticket #962: podpress.php

File podpress.php, 29.0 KB (added by ntm, 3 years ago)

with the changed podPress_do_feed_torrent function

Line 
1<?php
2define('PODPRESS_VERSION', '8.8');
3/*
4 Info for WordPress:
5 ==============================================================================
6 Plugin Name: podPress
7 Version: 8.8.1
8 Plugin URI: http://www.mightyseek.com/podpress/
9 Description: The podPress pluggin gives you everything you need in one easy plugin to use WordPress for Podcasting. Set it up in <a href="admin.php?page=podpress/podpress_feed.php">'podPress'->Feed/iTunes Settings</a>. If you this plugin works for you, send us a comment.
10 Author: Dan Kuykendall (Seek3r)
11 Author URI: http://www.mightyseek.com/
12
13 podPress - Podcasting made easy for WordPress
14 ==============================================================================
15
16 This plugin makes it much easier and organized to use WordPress for Podcasting.
17
18 The plugin was created as a way for me to merge Garrick Van Buren's  WP-iPodCatter
19 and Martin Laine's Audio Player with some hacks I made to Word Press 2.0.
20 I had tweaked the player to have the [audio:filename.mp3] entry to drive the
21 whole podcasting need. In the rss2.php I had tweaked it to generate the
22 enclosure tag from it. So thats how the plugin took birth, and I have been adding
23 features to make the process cleaner over time.
24
25 Feel free to visit my website under www.mightyseek.com or contact me at
26 dan [at] kuykendall [dot] org
27
28 Have fun!
29
30 Installation:
31 ==============================================================================
32 1. Upload the full directory into your wp-content/plugins directory
33 2. Activate it in the Plugin options
34 3. Edit or publish a post or click on Rebuild Sitemap on the Sitemap Administration Interface
35
36
37 Contributors:
38 ==============================================================================
39 Developer              Dan Kuykendall      http://www.mightyseek.com/
40 Developer              David Maciejewski   http://www.macx.de/
41 Forum Support/BugBoy   Jeff Norris         http://www.iscifi.tv/
42
43 Audio player           Martin Laine        http://www.1pixelout.net
44 WP-iPodCatter          Garrick Van Buren   http://garrickvanburen.com/
45
46 Thanks to all contributors and bug reporters! :)
47
48 Release History:
49 ==============================================================================
50 Instead of maintaining the history in here, Im just going to maintain it at
51 http://www.mightyseek.com/podpress/changelog/
52
53 License:
54 ==============================================================================
55
56    Copyright 2006  Dan Kuykendall  (email : dan@kuykendall.org)
57
58    This program is free software; you can redistribute it and/or modify
59    it under the terms of the GNU General Public License as published by
60    the Free Software Foundation; either version 2 of the License, or
61    (at your option) any later version.
62
63    This program is distributed in the hope that it will be useful,
64    but WITHOUT ANY WARRANTY; without even the implied warranty of
65    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
66    GNU General Public License for more details.
67
68    You should have received a copy of the GNU General Public License
69    along with this program; if not, write to the Free Software
70    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-107  USA
71*/
72
73//ini_set('memory_limit', '1M');
74$podPress_memoryUsage = array();
75$podPress_memoryIncrease = 0;
76$podPress_feedHooksAdded = false;
77$GLOBALS['podPressPlayer'] = 0;  // Global counter of Players
78
79if (!defined('PLUGINDIR')) {
80        define('PLUGINDIR', 'wp-content/plugins');
81}
82
83if (!defined('PODPRESSPLUGINDIR')) {
84        define('PODPRESSPLUGINDIR', ABSPATH.PLUGINDIR);
85}
86
87if(!function_exists('memory_get_usage')) {
88        unset($_GET['podpress_showmem']);
89        function memory_get_usage() { return 0; }
90        if(!function_exists('podPress_bytes')) {
91                function podPress_bytes($i) { return $i;        }
92                function podPress_checkmem() { return;  }
93        }
94} elseif(!function_exists('podPress_bytes')) {
95        function podPress_bytes($input, $dec=0) {
96                $unim = array('B','KB','MB','GB','TB','PB');
97                $value = round($input, $dec);
98         $i=0;
99         while ($value>1024) { $value /= 1024; $i++; }
100                return round($value, $dec).$unim[$i];
101        }
102
103        function podPress_checkmem($txt, $start = false) {
104                GLOBAL $podPress_memoryUsage, $podPress_memoryIncrease;
105                if(isset($_GET['podpress_showmem'])) {
106                        $mem = memory_get_usage();
107                        if($start) {
108                                $podPress_memoryUsage[$txt] = array('start'=>$mem);
109                        } else {
110                                if(!is_array($podPress_memoryUsage[$txt])) {
111                                        if(count($podPress_memoryUsage) > 0) {
112                                                $prevval = end($podPress_memoryUsage);
113                                                $prevval = $prevval['finish'];
114                                        } else {
115                                                $prevval = $mem;
116                                        }
117                                        $podPress_memoryUsage[$txt] = array('start'=>$prevval, 'fromprev'=>'X');
118                                        unset($prevval);
119                                }
120                                $podPress_memoryUsage[$txt]['finish'] = $mem;
121                                $increase = $mem - $podPress_memoryUsage[$txt]['start'];
122                                $podPress_memoryUsage[$txt]['increase'] = $increase;
123                                $podPress_memoryIncrease = $podPress_memoryIncrease+$increase;
124                                if($_GET['podpress_showmem'] == 1) {
125                                        echo $txt.': Increased memory '.podPress_bytes($increase)." for a total of ".podPress_bytes($mem)."<br/>\n";
126                                }
127                        }
128                }
129        }
130}
131
132if($_GET['podpress_showmem'] == 1) {
133        echo 'PHP has a memory_limit set to: '.ini_get('memory_limit').'<br/>';
134}
135podPress_checkmem('podPress start');
136
137if(file_exists(ABSPATH.PLUGINDIR.'/podpress.php')) {
138        echo __('It appears you are upgrading podPress, but left the pre-4.x version of podpress.php file in the plugins directory. Please delete this file to continue.', 'podpress');
139        exit;
140}
141
142if(!class_exists ('podPress_class')) {
143        if(function_exists('load_plugin_textdomain')) {
144                load_plugin_textdomain('podpress',PLUGINDIR.'/podpress');
145        }
146        require_once(ABSPATH.PLUGINDIR.'/podpress/podpress_class.php');
147        podPress_checkmem('podPress base class included');
148        require_once(ABSPATH.PLUGINDIR.'/podpress/podpress_functions.php');
149        podPress_checkmem('podPress functions loaded');
150
151        if($podPress_x = @parse_url($_SERVER['REQUEST_URI'])) {
152                $podPress_x = $podPress_x['path'];
153                if (strpos($podPress_x, 'crossdomain.xml')) {
154                        podPress_crossdomain();
155                } elseif ($pos = strpos($podPress_x, 'podpress_trac')) {
156                        /* short circut the loading process for a simple redirect */
157                        podPress_checkmem('standard podPress class loaded', true);
158                        $podPress = new podPress_class;
159                        podPress_checkmem('standard podPress class loaded');
160                        podPress_statsDownloadRedirect($podPress_x);
161                        exit;
162                }
163                unset($podPress_x);
164        }
165
166        $customThemeFile = ABSPATH.'/wp-content/themes/'.get_option('template').'/podpress_theme.php';
167        if(file_exists($customThemeFile)) {
168                require_once($customThemeFile);
169        podPress_checkmem('podPress custom theme file loaded');
170        }
171        require_once(ABSPATH.PLUGINDIR.'/podpress/podpress_theme.php');
172        podPress_checkmem('podPress core theme file loaded');
173
174        /*************************************************************/
175        /* Simple wrapper functions, since I dont think I can        */
176        /* register object functions                                 */
177        /*************************************************************/
178
179        function podPress_init() {
180                GLOBAL $podPress;
181
182                if(function_exists('add_feed')) {
183                        add_feed('podcast', 'podPress_do_feed_podcast');
184                        add_feed('premium', 'podPress_do_feed_premium');
185                        add_feed('torrent', 'podPress_do_feed_torrent');
186                        add_feed('playlist.xspf', 'podPress_do_feed_xspf');
187                }
188                remove_action('do_feed_rss', 'do_feed_rss', 10, 1);
189                add_action('do_feed_rss', 'podPress_do_feed_rss2', 1, 1);
190                add_action('do_feed_rss2', 'podPress_do_feed_rss2', 1, 1);
191                remove_action('do_feed_atom', 'do_feed_atom', 10, 1);
192                add_action('do_feed_atom', 'podPress_do_feed_atom1', 1, 1);
193
194                if(is_feed()) {
195                        podPress_addFeedHooks();
196                        $podPress->feed_getCategory();
197                }
198        }
199
200        function podPress_add_menu_page() {
201                GLOBAL $podPress;
202                if(podPress_WPVersionCheck('2.0.0')) {
203                        $permission_needed = $podPress->requiredAdminRights;
204                } else {
205                        $permission_needed = 1;
206                }
207                if (function_exists('add_menu_page')) {
208                        if($podPress->settings['enableStats'] == true) {
209                                $starting_point = 'podpress_stats';
210                        } else {
211                                $starting_point = 'podpress_feed';
212                        }
213                        add_menu_page('podPress', 'podPress', $permission_needed, 'podpress/'.$starting_point.'.php');
214                }
215                if (function_exists('add_submenu_page')) {
216                        if($podPress->settings['enableStats'] == true) {
217                                $starting_point = 'podpress_stats';
218                        } else {
219                                $starting_point = 'podpress_feed';
220                        }
221
222                        if($podPress->settings['enableStats'] == true) {
223                                add_submenu_page('podpress/'.$starting_point.'.php', __('Stats'), __('Stats'), $permission_needed, 'podpress/podpress_stats.php');
224                        }
225                        add_submenu_page('podpress/'.$starting_point.'.php', __('Feed/iTunes Settings', 'podpress'), __('Feed/iTunes Settings', 'podpress'), $permission_needed, 'podpress/podpress_feed.php');
226                        add_submenu_page('podpress/'.$starting_point.'.php', __('General Settings', 'podpress'), __('General Settings', 'podpress'), $permission_needed, 'podpress/podpress_general.php');
227
228                        if($podPress->settings['contentPlayer'] != 'disabled') {
229                                add_submenu_page('podpress/'.$starting_point.'.php', __('Player Settings', 'podpress'), __('Player Settings', 'podpress'), $permission_needed, 'podpress/podpress_players.php');
230                        }
231
232                        if($podPress->settings['enablePodangoIntegration'] == true) {
233                                add_submenu_page('podpress/'.$starting_point.'.php', __('Podango Settings', 'podpress'), __('Podango Settings', 'podpress'), $permission_needed, 'podpress/podpress_podango.php');
234                        }
235                }
236        }
237
238        function podPress_switch_theme() {
239                GLOBAL $podPress;
240                $podPress->settings['compatibilityChecks']['themeTested'] = false;
241                $podPress->settings['compatibilityChecks']['wp_head'] = false;
242                $podPress->settings['compatibilityChecks']['wp_footer'] = false;
243                podPress_update_option('podPress_config', $podPress->settings);
244        }
245
246        function podPress_wp_head() {
247                GLOBAL $podPress, $podPress_inAdmin;
248                if(!$podPress_inAdmin) {
249                        if(!$podPress->settings['compatibilityChecks']['themeTested']) {
250                                $podPress->settings['compatibilityChecks']['themeTested'] = true;
251                                podPress_update_option('podPress_config', $podPress->settings);
252                        }
253                        if(!$podPress->settings['compatibilityChecks']['wp_head']) {
254                                $podPress->settings['compatibilityChecks']['wp_head'] = true;
255                                podPress_update_option('podPress_config', $podPress->settings);
256                        } else {
257                                $podPress->settings['compatibilityChecks']['wp_head'] = true;
258                        }
259                }
260                echo '<script type="text/javascript" src="'.podPress_url().'podpress.js"></script>'."\n";
261                echo '<script type="text/javascript"><!--'."\n";
262                echo 'var podPressBackendURL = location.protocol;'."\n";
263                echo 'if(location.port != "80" && location.port != "443") {podPressBackendURL = podPressBackendURL+location.port; } '."\n";
264                echo 'podPressBackendURL = podPressBackendURL+"//"+location.hostname+"'.podPress_url(true).'";'."\n";
265                echo 'var podPressDefaultPreviewImage = podPressBackendURL+"/images/vpreview_center.png";'."\n";
266
267                if($podPress->settings['enablePodangoIntegration'] || $podPress->settings['mp3Player'] != '1pixelout') {
268                        echo 'var podPressPlayerFile = "podango_player.swf";'."\n";
269                } else {
270                        echo 'var podPressPlayerFile = "1pixelout_player.swf";'."\n";
271                }
272
273                $playerOptions = '';
274                if(@!is_array($podPress->settings['player'])) {
275                        $podPress->resetPlayerSettings();
276                }
277                foreach($podPress->settings['player'] as $key => $val) {
278                        $val = str_replace('#', '0x', $val);
279                        $playerOptions .= '&amp;' . $key . '=' . rawurlencode($val);
280                }
281                echo 'var podPressMP3PlayerOptions = "'.$playerOptions.'&amp;";'."\n";
282
283                if($podPress->settings['player']['listenWrapper']) {
284                        echo 'var podPressMP3PlayerWrapper = true;'."\n";
285                } else {
286                        echo 'var podPressMP3PlayerWrapper = false;'."\n";
287                }
288
289                echo 'var podPressText_PlayNow = "'.__('Play Now', 'podpress').'";'."\n";
290                echo 'var podPressText_HidePlayer = "'.__('Hide Player', 'podpress').'";'."\n";
291                echo '--></script>'."\n";
292
293                if(file_exists(ABSPATH.'/wp-content/themes/'.get_option('template').'/podpress.css')) {
294                        echo '<link rel="stylesheet" href="'.podPress_siteurl().'/wp-content/themes/'.get_option('template').'/podpress.css" type="text/css" />'."\n";
295                } else {
296                        echo '<link rel="stylesheet" href="'.podPress_url().'podpress.css" type="text/css" />'."\n";
297                }
298        }
299
300        function podPress_admin_javascript() {
301                podPress_wp_head();
302                echo '<script type="text/javascript" src="'.podPress_url().'podpress_admin.js"></script>'."\n";
303                if(function_exists('wp_admin_tiger_css')) {
304                        $admincss = 'podpress_admin_tigercheck.css';
305                } else {
306                        $admincss = 'podpress_admin.css';
307                }
308                echo '<link rel="stylesheet" href="'.podPress_url().$admincss.'" type="text/css" />'."\n";
309        }
310
311        function podPress_activity_box() {
312                GLOBAL $podPress, $wpdb;
313                if($podPress->settings['enableStats']) {
314                        echo '<h3>podPress&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.mightyseek.com/podpress/#download" target="_new"><img src="http://www.mightyseek.com/podpress_downloads/versioncheck.php?current='.PODPRESS_VERSION.'" alt="'.__('Checking for updates... Failed', 'podpress').'" border="0" /></a></h3>'."\n";
315                        if($podPress->settings['enableStats']) {
316                                $sql = "SELECT SUM(total) as cnt_total,
317                                               SUM(feed) as cnt_feed ,
318                                               SUM(web) as cnt_web ,
319                                               SUM(play) as cnt_play
320                                               FROM ".$wpdb->prefix."podpress_statcounts";
321                                $stats = $wpdb->get_results($sql);
322                                if($stats) {
323                                        echo '                  <legend>'.__('Stats Summary', 'podpress').'</legend>'."\n";
324                                        echo '                  <table class="the-list-x" width="100%" cellpadding="1" cellspacing="1">'."\n";
325                                        echo '                          <tr><th>'.__('Feed', 'podpress').'</th><th>'.__('Web', 'podpress').'</th><th>'.__('Play', 'podpress').'</th><th>'.__('Total', 'podpress').'</th></tr>'."\n";
326                                        echo '                          <tr><td align="center">'.$stats[0]->cnt_feed.'</td><td align="center">'.$stats[0]->cnt_web.'</td><td align="center">'.$stats[0]->cnt_play.'</td><td align="center">'.$stats[0]->cnt_total.'</td></tr>'."\n";
327                                        echo '                  </table>'."\n";
328                                }
329                        }
330                }
331        }
332
333        function podPress_admin_head () {
334                GLOBAL $action;
335                podPress_wp_head(false);
336                echo '<script type="text/javascript" src="'.podPress_url().'podpress_admin.js"></script>'."\n";
337                if(function_exists('wp_admin_tiger_css')) {
338                        $admincss = 'podpress_admin_tigercheck.css';
339                } else {
340                        $admincss = 'podpress_admin.css';
341                }
342                echo '<link rel="stylesheet" href="'.podPress_url().$admincss.'" type="text/css" />'."\n";
343                if ((strpos($_SERVER['REQUEST_URI'], 'plugins.php') !== false) && (podPress_remote_version_check() == 1)) {
344                        $atmp = parse_url(podPress_url());
345                        $xyz = $atmp['path'];
346
347                        echo "<script type='text/javascript' src='" . $xyz . "/prototype-1.4.0.js'></script>\n";
348                        $alert = "\n";
349                        $alert .= "\n<script type='text/javascript'>";
350                        $alert .= "\n//<![CDATA[";
351                        $alert .= "\nfunction alertNewPodPressVersion() {";
352                        $alert .= "\n   pluginname = 'podPress';";
353                        $alert .= "\n   allNodes = document.getElementsByClassName('name');";
354                        $alert .= "\n   for(i = 0; i < allNodes.length; i++) {";
355                        $alert .= "\n                   var regExp=/<\S[^>]*>/g;";
356                        $alert .= "\n       temp = allNodes[i].innerHTML;";
357                        $alert .= "\n       if (temp.replace(regExp,'') == pluginname) {";
358                        $alert .= "\n               Element.setStyle(allNodes[i].getElementsByTagName('a')[0], {color: '#f00'});";
359                        $alert .= "\n               new Insertion.After(allNodes[i].getElementsByTagName('strong')[0],'<br/><small>" .  __('new version available', 'podpress') . "</small>');";
360                        $alert .= "\n           }";
361                        $alert .= "\n   }";
362                        $alert .= "\n}";
363
364                        $alert .= "\naddLoadEvent(alertNewPodPressVersion);";
365
366                        $alert .= "\n//]]>";
367                        $alert .= "\n</script>";
368                        $alert .= "\n";
369                        echo $alert;
370                }
371        }
372
373        function podPress_admin_footer () {
374                GLOBAL $action;
375                if ((strpos($_SERVER['REQUEST_URI'], 'categories.php') !== false) && $action == 'edit') {
376                        //echo "<script type=\"text/javascript\">var x=1; var y = document.getElementByName('editcat').innerHTML; alert('y: '+y);</script>";
377                }
378        }
379
380        function podPress_wp_footer() {
381                GLOBAL $podPress, $podPress_inAdmin;
382                if(!$podPress_inAdmin) {
383                        if(!$podPress->settings['compatibilityChecks']['themeTested']) {
384                                $podPress->settings['compatibilityChecks']['themeTested'] = true;
385                                podPress_update_option('podPress_config', $podPress->settings);
386                        }
387                }
388                if(!$podPress_inAdmin) {
389                        if(!$podPress->settings['compatibilityChecks']['wp_footer']) {
390                                $podPress->settings['compatibilityChecks']['wp_footer'] = true;
391                                podPress_update_option('podPress_config', $podPress->settings);
392                        } else {
393                                $podPress->settings['compatibilityChecks']['wp_footer'] = true;
394                        }
395                }
396
397                if($podPress->settings['enableFooter']) {
398                        $diplay = 'block';
399                } else {
400                        $diplay = 'none';
401                }
402                echo '<div id="podPress_footer" style="display: '.$diplay.'; text-align: center;"><cite>'.__('Podcast Powered by ', 'podpress').'<a href="http://www.mightyseek.com/podpress/" title="podPress, '.__('the dream plugin for podcasting with WordPress', 'podpress').'"><strong>podPress (v'.PODPRESS_VERSION.')</strong></a></cite></div>';
403        }
404
405        function podPress_get_the_guid($guid) {
406                GLOBAL $post, $wpdb;
407                if(empty($guid)) {
408                        $guid = rand();
409                        if(is_object($post) && !empty($post->ID)) {
410                                $wpdb->query("UPDATE ".$wpdb->posts." SET guid = '".$guid."' WHERE ID=".$post->ID);
411                        }
412                }
413                return $guid;
414        }
415
416        function podPress_get_attached_file($file, $id='') {
417                if(is_feed()) {
418                        return '';
419                }       else {
420                        return $file;
421                }
422        }
423       
424        function podPress_wp_get_attachment_metadata($data, $id='') {
425                if(is_feed()) {
426                        return '';
427                }       else {
428                        return $file;
429                }
430        }
431
432        function podPress_crossdomain() {
433                header("HTTP/1.0 200 OK");
434                header('Content-type: text/xml; charset=' . get_settings('blog_charset'), true);
435                echo '<?xml version="1.0"?>'."\n";
436                echo '<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">'."\n";
437                echo '<cross-domain-policy>'."\n";
438                echo '  <allow-access-from domain="*" />'."\n";
439                echo '</cross-domain-policy>'."\n";
440                exit;
441        }
442
443        function podPress_do_feed_rss2($withcomments) {
444                podPress_addFeedHooks();
445                if (!function_exists('do_feed_rss2')) {
446                        load_template(ABSPATH.'wp-rss2.php');
447                } else {
448                        do_feed_rss2($withcomments);
449                }
450        }
451
452        function podPress_do_feed_premium($withcomments) {
453                GLOBAL $cache_lastpostmodified;
454                unset($_SERVER['HTTP_IF_MODIFIED_SINCE']);
455                $cache_lastpostmodified = date('Y-m-d h:i:s', time()+36000);
456                podPress_addFeedHooks();
457                define('PREMIUMCAST', true);
458                podPress_validateLogin();
459                if(!function_exists('do_feed_rss2')) {
460                        load_template(ABSPATH.'wp-rss2.php');
461                } else {
462                        do_feed_rss2($withcomments);
463                }
464        }
465
466        function podPress_do_feed_podcast($withcomments) {
467                GLOBAL $wp_query;
468                podPress_addFeedHooks();
469                define('PODPRESS_PODCASTSONLY', true);
470                $wp_query->get_posts();
471                if (!function_exists('do_feed_rss2')) {
472                        load_template(ABSPATH.'wp-rss2.php');
473                } else {
474                        do_feed_rss2($withcomments);
475                }
476        }
477
478        function podPress_do_feed_atom1() {
479                podPress_addFeedHooks();
480                load_template(ABSPATH.PLUGINDIR.'/podpress/wp-atom1.php');
481        }
482
483        function podPress_do_feed_torrent() {
484                GLOBAL $podPress, $posts;
485                podPress_addFeedHooks();
486                define('PODPRESS_TORRENTCAST', true);
487                $posts = $podPress->the_posts($posts);
488                if (!function_exists('do_feed_rss2')) {
489                        load_template(ABSPATH.'wp-rss2.php');
490                } else {
491                        do_feed_rss2($withcomments);
492                }
493        }
494
495        function podPress_do_feed_xspf() {
496                GLOBAL $wp_query;
497                podPress_addFeedHooks();
498                define('PODPRESS_PODCASTSONLY', true);
499                $wp_query->get_posts();
500                podPress_xspf_playlist();
501        }
502
503        function podPress_addFeedHooks() {
504                GLOBAL $podPress, $podPress_feedHooksAdded, $wp_query;
505                $wp_query->is_feed = true;
506
507                if(!$podPress_feedHooksAdded) {
508                        require_once(ABSPATH.PLUGINDIR.'/podpress/podpress_feed_functions.php');
509                        podPress_checkmem('podPress feed functions loaded');
510                        add_filter('option_blogname', 'podPress_feedblogname');
511                        add_filter('option_blogdescription', 'podPress_feedblogdescription');
512                        add_filter('option_rss_language', 'podPress_feedblogrsslanguage');
513                        add_filter('option_rss_image', 'podPress_feedblogrssimage');
514
515                        /* stuff that goes in the rss feed */
516                        add_action('the_content_rss', array(&$podPress, 'insert_content'));
517                        add_action('rss2_ns', 'podPress_rss2_ns');
518                        add_action('rss2_head', 'podPress_rss2_head');
519                        add_action('rss2_item', 'podPress_rss2_item');
520
521                        /* stuff that goes in the atom feed */
522                        add_action('atom_head', 'podPress_atom_head');
523                        add_action('atom_entry', 'podPress_atom_entry');
524                        $podPress_feedHooksAdded = true;
525                }
526        }
527}
528
529        /*************************************************************/
530        /* !!! BEGINNING OF THE ACTION !!!                           */
531        /*************************************************************/
532
533        /*************************************************************/
534        /* Create the podPress object                                */
535        /*************************************************************/
536
537        if(!is_object ($podPress)) {
538                if(get_option('podPress_version') < PODPRESS_VERSION) {
539                        $podPress_inUpgrade = true;
540                } else {
541                        $podPress_inUpgrade = false;
542                }
543                $podPress_inAdmin = strpos($_SERVER['REQUEST_URI'], 'wp-admin');
544                if($podPress_inUpgrade) {
545                        podPress_checkmem('podpress admin class loaded', true);
546                        require_once(ABSPATH.PLUGINDIR.'/podpress/podpress_admin_functions.php');
547                        require_once(ABSPATH.PLUGINDIR.'/podpress/podpress_upgrade_class.php');
548                        podPress_checkmem('podpress upgrade class loaded');
549                        require_once(ABSPATH.PLUGINDIR.'/podpress/podpress_admin_class.php');
550                        podPress_checkmem('podpress admin class loaded');
551                        $podPress = new podPressUpgrade_class(get_option('podPress_version'));
552                        header('Location: '.$_SERVER['REQUEST_URI']);
553                        exit;
554                } elseif ($podPress_inAdmin) {
555                        podPress_checkmem('podpress admin functions loaded', true);
556                        require_once(ABSPATH.PLUGINDIR.'/podpress/podpress_admin_functions.php');
557                        podPress_checkmem('podpress admin functions loaded');
558                        if(isset($_GET['page'])) {
559                                $podPress_adminPage = $_GET['page'];
560                        } elseif(isset($_POST['podPress_submitted'])) {
561                                $podPress_adminPage = 'podpress/podpress_'.$_POST['podPress_submitted'].'.php';
562                        } else {
563                                $podPress_adminPage = 'usedefault';
564                        }
565                        switch($podPress_adminPage) {
566                                case 'podpress/podpress_general.php':
567                                        require_once(ABSPATH.PLUGINDIR.'/podpress/podpress_admin_general_class.php');
568                                        podPress_checkmem('admin general code loaded');
569                                        break;
570                                case 'podpress/podpress_feed.php':
571                                        require_once(ABSPATH.PLUGINDIR.'/podpress/podpress_admin_feed_class.php');
572                                        podPress_checkmem('admin feed code loaded');
573                                        break;
574                                case 'podpress/podpress_players.php':
575                                        require_once(ABSPATH.PLUGINDIR.'/podpress/podpress_admin_player_class.php');
576                                        podPress_checkmem('admin player code loaded');
577                                        break;
578                                case 'podpress/podpress_stats.php':
579                                        require_once(ABSPATH.PLUGINDIR.'/podpress/podpress_admin_stats_class.php');
580                                        podPress_checkmem('admin stats code loaded');
581                                        break;
582                                case 'podpress/podpress_podango.php':
583                                        require_once(ABSPATH.PLUGINDIR.'/podpress/podpress_admin_podango_class.php');
584                                        podPress_checkmem('admin podango code loaded');
585                                        break;
586                                default:
587                                        require_once(ABSPATH.PLUGINDIR.'/podpress/podpress_admin_class.php');
588                                        podPress_checkmem('admin code loaded');
589                        }
590
591                        $podPress = new podPressAdmin_class();
592                       
593                        if($podPress->settings['enablePodangoIntegration']) {
594                                podPress_checkmem('PodangoAPI code loaded', true);
595                                require_once(ABSPATH.PLUGINDIR.'/podpress/podango-api.php');
596                                $podPress->podangoAPI = new PodangoAPI ($podPress->settings['podangoUserKey'], $podPress->settings['podangoPassKey']);
597                                if(!empty($podPress->settings['podangoDefaultPodcast'])) {
598                                        $podPress->podangoAPI->defaultPodcast = $podPress->settings['podangoDefaultPodcast'];
599                                }
600                                if(!empty($podPress->settings['podangoDefaultTranscribe'])) {
601                                        $podPress->podangoAPI->defaultTranscribe = (int)$podPress->settings['podangoDefaultTranscribe'];
602                                }
603                                podPress_checkmem('PodangoAPI code loaded');
604                        }
605                } else {
606                        podPress_checkmem('standard podPress class loaded', true);
607                        $podPress = new podPress_class;
608                        podPress_checkmem('standard podPress class loaded');
609                }
610        }
611        /*************************************************************/
612        /* Register all the actions and filters                      */
613        /*************************************************************/
614        /* Add podpress data to each post */
615        if(!podPress_WPVersionCheck()) {
616                // WP 1.5 legacy vars support
617                if(isset($table_prefix) && !isset($wpdb->prefix)) {
618                        $wpdb->prefix = $table_prefix;
619                }
620                if(isset($tablecomments) && !isset($wpdb->comments)) {
621                        $wpdb->comments = $tablecomments;
622                }
623        }
624
625        add_action('init', 'podPress_init');
626
627        /* Add podpress data to each post */
628        if(podPress_WPVersionCheck()) {
629                add_action('the_posts', array(&$podPress, 'the_posts'));
630        } else {
631                add_filter('the_posts', array(&$podPress, 'the_posts'));
632        }
633
634        add_action('xmlrpc-mw_newPost', array(&$podPress, 'xmlrpc_post_addMedia'));
635        add_action('xmlrpc-mw_editPost', array(&$podPress, 'xmlrpc_post_addMedia'));
636
637        add_filter('posts_join', array(&$podPress, 'posts_join'));
638        add_filter('posts_where', array(&$podPress, 'posts_where'));
639
640        /* stuff that goes in the display of the Post */
641        add_action('the_content', array(&$podPress, 'insert_content'));
642        add_action('get_the_excerpt', array(&$podPress, 'insert_the_excerpt'), 1);
643        add_action('the_excerpt', array(&$podPress, 'insert_the_excerptplayer'));
644
645        add_filter('get_attached_file', 'podPress_get_attached_file');
646        add_filter('wp_get_attachment_metadata', 'podPress_wp_get_attachment_metadata');
647       
648        /* stuff that goes in the HTML header */
649        add_action('wp_head', 'podPress_wp_head');
650        add_action('wp_footer', 'podPress_wp_footer');
651        add_action('switch_theme', 'podPress_switch_theme');
652
653        /* misc stuff */
654        add_action('activity_box_end', 'podPress_activity_box');
655        if($podPress->settings['enableStats'] == true) {
656                add_action('template_redirect', 'podPress_statsDownloadRedirect');
657        }
658        add_filter('get_the_guid', 'podPress_get_the_guid');
659
660        /* stuff that goes into all feeds */
661
662        if(is_feed()) {
663                podPress_addFeedHooks();
664        }
665
666        /* Widgets */
667        add_action('widgets_init', 'podPress_loadWidgets');
668
669        /* stuff for premium podcasts */
670        if($podPress->settings['enablePremiumContent']) {
671                require_once(ABSPATH.PLUGINDIR.'/podpress/podpress_premium_functions.php');
672                podPress_checkmem('premium functions included');
673                add_action('wp_login', 'podpress_adddigestauth');
674        }
675
676        /* stuff that goes into setting up the site for podpress */
677        if($podPress_inAdmin) {
678                add_action('activate_podpress/podpress.php', array(&$podPress, 'activate'));
679                add_action('deactivate_podpress/podpress.php', array(&$podPress, 'deactivate'));
680
681                /* if this is an admin page, run the function to add podpress tab to options menu */
682                add_action('admin_menu', 'podPress_add_menu_page');
683                add_action('admin_head', 'podPress_admin_head');
684                add_action('admin_footer', 'podPress_admin_footer');
685
686                add_action('simple_edit_form', array(&$podPress, 'post_form'));
687                add_action('edit_form_advanced', array(&$podPress, 'post_form'));
688                add_action('edit_page_form', array(&$podPress, 'page_form'));
689                add_action('save_post', array(&$podPress, 'post_edit'));
690                add_action('edit_post', array(&$podPress, 'post_edit')); // seems to be a duplicate
691
692                /* stuff that goes in the category */
693                add_action('create_category', array(&$podPress, 'edit_category'));
694                add_action('edit_category_form', array(&$podPress, 'edit_category_form'));
695                add_action('edit_category', array(&$podPress, 'edit_category'));
696                add_action('delete_category', array(&$podPress, 'delete_category'));
697
698                /* stuff for editing settings */
699                if(isset($_POST['podPress_submitted']) && method_exists($podPress,'settings_'.$_POST['podPress_submitted'].'_save')) {
700                        $funcnametouse = 'settings_'.$_POST['podPress_submitted'].'_save';
701                        $podPress->$funcnametouse();
702                }
703
704                /* stuff for editing settings */
705                $wp_importers['podcast'] = array ('Podcast RSS2', 'podPress import of posts from a Podcast RSS2 feed.', array(&$podPress, 'import_dispatch'));
706                //if(function_exists('register_importer')) {
707                //      register_importer('podcast', __('Podcast RSS2'), __('Import posts from an RSS2 Podcast feed'), array (&$podPress, 'import_dispatch'));
708                //}
709
710        } else {
711        }
712
713        //podPress_checkmem('podPress end');
714        if(!function_exists('podPress_shutdown')) {
715                function podPress_shutdown() {
716                        GLOBAL $podPress_memoryUsage, $podPress_memoryIncrease;
717                        if($_GET['podpress_showmem'] == 1) {
718                                echo "Total podpress mem: ".podPress_bytes($podPress_memoryIncrease)." out of a total ".podPress_bytes(memory_get_usage())."<br/>\n";
719                        }
720
721                        if($_GET['podpress_showmem'] == 2) {
722                                html_print_r($podPress_memoryUsage);
723                        } elseif($_GET['podpress_showmem'] == 3) {
724                                comment_print_r($podPress_memoryUsage);
725                        }
726                }
727                add_action( 'shutdown', 'podPress_shutdown', 1);
728        }