1 | <?php
|
---|
2 | /**
|
---|
3 | * Copyright 2006, 2007, 2008, 2009 Eric D. Hough (http://ehough.com)
|
---|
4 | *
|
---|
5 | * This file is part of TubePress (http://tubepress.org)
|
---|
6 | *
|
---|
7 | * TubePress is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * TubePress is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with TubePress. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | *
|
---|
20 | */
|
---|
21 |
|
---|
22 | function_exists('tubepress_load_classes')
|
---|
23 | || require(dirname(__FILE__) . '/../../../classes/tubepress_classloader.php');
|
---|
24 | tubepress_load_classes(array('org_tubepress_options_storage_WordPressStorageManager',
|
---|
25 | 'org_tubepress_options_category_Advanced',
|
---|
26 | 'org_tubepress_shortcode_SimpleShortcodeService',
|
---|
27 | 'org_tubepress_ioc_DefaultIocService',
|
---|
28 | 'org_tubepress_ioc_IocService',
|
---|
29 | 'org_tubepress_util_Debug',
|
---|
30 | 'org_tubepress_util_StringUtils'));
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * Main filter hook. Looks for a tubepress tag
|
---|
34 | * and, if found, replaces it with a gallery
|
---|
35 | */
|
---|
36 | function tubepress_content_filter($content = '')
|
---|
37 | {
|
---|
38 | try {
|
---|
39 | return _tubepress_content_filter($content);
|
---|
40 | } catch (Exception $e) {
|
---|
41 | return $e->getMessage() . $content;
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | function _tubepress_content_filter($content) {
|
---|
46 |
|
---|
47 | /* do as little work as possible here 'cause we might not even run */
|
---|
48 | $wpsm = new org_tubepress_options_storage_WordPressStorageManager();
|
---|
49 | $trigger = $wpsm->get(org_tubepress_options_category_Advanced::KEYWORD);
|
---|
50 | $shortcodeService = new org_tubepress_shortcode_SimpleShortcodeService();
|
---|
51 |
|
---|
52 | /* no shortcode? get out */
|
---|
53 | if (!$shortcodeService->somethingToParse($content, $trigger)) {
|
---|
54 | return $content;
|
---|
55 | }
|
---|
56 |
|
---|
57 | /* Whip up the IOC service */
|
---|
58 | $iocContainer = new org_tubepress_ioc_DefaultIocService();
|
---|
59 |
|
---|
60 | /* Get a handle to our options manager */
|
---|
61 | $tpom = $iocContainer->get(org_tubepress_ioc_IocService::OPTIONS_MGR);
|
---|
62 |
|
---|
63 | /* Get a copy of the content that we'll edit */
|
---|
64 | $newcontent = $content;
|
---|
65 |
|
---|
66 | /* And finally, the gallery itself */
|
---|
67 | $gallery = $iocContainer->get(org_tubepress_ioc_IocService::GALLERY);
|
---|
68 |
|
---|
69 | while ($shortcodeService->somethingToParse($newcontent, $trigger)) {
|
---|
70 |
|
---|
71 | $shortcodeService->parse($newcontent, $tpom);
|
---|
72 |
|
---|
73 | if (org_tubepress_util_Debug::areWeDebugging($tpom)) {
|
---|
74 | org_tubepress_util_Debug::execute($iocContainer);
|
---|
75 | }
|
---|
76 |
|
---|
77 | /* replace the tag with our new content */
|
---|
78 | $newcontent = org_tubepress_util_StringUtils::replaceFirst($tpom->getShortcode(),
|
---|
79 | $gallery->generate(mt_rand()), $newcontent);
|
---|
80 | }
|
---|
81 |
|
---|
82 | return $newcontent;
|
---|
83 | }
|
---|
84 |
|
---|
85 | /**
|
---|
86 | * Spits out the CSS and JS files that we always need for TubePress
|
---|
87 | */
|
---|
88 | function tubepress_head_filter()
|
---|
89 | {
|
---|
90 | try {
|
---|
91 | _tubepress_head_filter();
|
---|
92 | } catch (Exception $e) {
|
---|
93 | /* this is in the head, so just print an HTML comment and proceed */
|
---|
94 | print "<!-- " . $e->getMessage() . " -->";
|
---|
95 | }
|
---|
96 | }
|
---|
97 |
|
---|
98 | function _tubepress_head_filter() {
|
---|
99 | global $tubepress_base_url;
|
---|
100 |
|
---|
101 | print<<<GBS
|
---|
102 | <script type="text/javascript" src="$tubepress_base_url/ui/lib/tubepress.js"></script>
|
---|
103 | <link rel="stylesheet" href="$tubepress_base_url/ui/lib/tubepress.css" type="text/css" />
|
---|
104 | <script type="text/javascript">jQuery(document).ready(function() {tubepress_init("$tubepress_base_url");});</script>
|
---|
105 |
|
---|
106 | GBS;
|
---|
107 | }
|
---|
108 |
|
---|
109 |
|
---|
110 | /**
|
---|
111 | * Tells WordPress to load jQuery for us
|
---|
112 | *
|
---|
113 | * @return void
|
---|
114 | */
|
---|
115 | function tubepress_load_jquery()
|
---|
116 | {
|
---|
117 | wp_enqueue_script('jquery');
|
---|
118 | }
|
---|
119 | ?>
|
---|