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_message_WordPressMessageService'));
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Registers TubePress as a widget
|
---|
28 | *
|
---|
29 | */
|
---|
30 | function tubepress_init_widget()
|
---|
31 | {
|
---|
32 | $msg = new org_tubepress_message_WordPressMessageService();
|
---|
33 | $widget_ops = array('classname' => 'widget_tubepress',
|
---|
34 | 'description' => $msg->_("widget-description"));
|
---|
35 | wp_register_sidebar_widget('tubepress', "TubePress",
|
---|
36 | 'tubepress_widget', $widget_ops);
|
---|
37 | wp_register_widget_control('tubepress', "TubePress",
|
---|
38 | 'tubepress_widget_control');
|
---|
39 | }
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Executes the main widget functionality
|
---|
43 | *
|
---|
44 | * @param unknown_type $opts
|
---|
45 | */
|
---|
46 | function tubepress_widget($opts)
|
---|
47 | {
|
---|
48 | extract($opts);
|
---|
49 |
|
---|
50 | $iocContainer = new org_tubepress_ioc_DefaultIocService();
|
---|
51 | $tpom = $iocContainer->get(org_tubepress_ioc_IocService::OPTIONS_MGR);
|
---|
52 |
|
---|
53 | $tpom->setCustomOptions(
|
---|
54 | array(org_tubepress_options_category_Display::RESULTS_PER_PAGE => 3,
|
---|
55 | org_tubepress_options_category_Meta::VIEWS => false,
|
---|
56 | org_tubepress_options_category_Meta::DESCRIPTION => true,
|
---|
57 | org_tubepress_options_category_Display::DESC_LIMIT => 50,
|
---|
58 | org_tubepress_options_category_Display::CURRENT_PLAYER_NAME => org_tubepress_player_Player::POPUP,
|
---|
59 | org_tubepress_options_category_Display::THUMB_HEIGHT => 105,
|
---|
60 | org_tubepress_options_category_Display::THUMB_WIDTH => 135
|
---|
61 | )
|
---|
62 | );
|
---|
63 |
|
---|
64 | $shortcodeService = $iocContainer->get(org_tubepress_ioc_IocService::SHORTCODE);
|
---|
65 | $wpsm = $iocContainer->get(org_tubepress_ioc_IocService::STORAGE);
|
---|
66 |
|
---|
67 | /* now apply the user's shortcode */
|
---|
68 | $shortcodeService->parse($wpsm->get(org_tubepress_options_category_Widget::TAGSTRING), $tpom, true);
|
---|
69 |
|
---|
70 | $gallery = $iocContainer->get(org_tubepress_ioc_IocService::WIDGET_GALL);
|
---|
71 |
|
---|
72 | /* get the output */
|
---|
73 | $out = $gallery->generate(mt_rand());
|
---|
74 |
|
---|
75 | /* do the standard WordPress widget dance */
|
---|
76 | echo $before_widget . $before_title .
|
---|
77 | $wpsm->get(org_tubepress_options_category_Widget::TITLE) .
|
---|
78 | $after_title . $out . $after_widget;
|
---|
79 | }
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * Handles the widget configuration panel
|
---|
83 | *
|
---|
84 | */
|
---|
85 | function tubepress_widget_control()
|
---|
86 | {
|
---|
87 | $iocContainer = new org_tubepress_ioc_DefaultIocService();
|
---|
88 | $wpsm = $iocContainer->get(org_tubepress_ioc_IocService::STORAGE);
|
---|
89 | $msg = $iocContainer->get(org_tubepress_ioc_IocService::MESSAGE);
|
---|
90 |
|
---|
91 | if ( $_POST["tubepress-widget-submit"] ) {
|
---|
92 | $wpsm->set(org_tubepress_options_category_Widget::TAGSTRING,
|
---|
93 | strip_tags(stripslashes($_POST["tubepress-widget-tagstring"])));
|
---|
94 | $wpsm->set(org_tubepress_options_category_Widget::TITLE,
|
---|
95 | strip_tags(stripslashes($_POST["tubepress-widget-title"])));
|
---|
96 | }
|
---|
97 |
|
---|
98 | /* load up the gallery template */
|
---|
99 | $tpl = new net_php_pear_HTML_Template_IT(dirname(__FILE__) . "/../../../ui/widget/html_templates");
|
---|
100 | if (!$tpl->loadTemplatefile("controls.tpl.html", true, true)) {
|
---|
101 | throw new Exception("Couldn't load widget control template");
|
---|
102 | }
|
---|
103 |
|
---|
104 | $tpl->setVariable("WIDGET-TITLE",
|
---|
105 | $msg->_("options-meta-title-title"));
|
---|
106 | $tpl->setVariable("WIDGET-TITLE-VALUE",
|
---|
107 | $wpsm->get(org_tubepress_options_category_Widget::TITLE));
|
---|
108 | $tpl->setVariable("WIDGET-TAGSTRING",
|
---|
109 | $msg->_("widget-tagstring-description"));
|
---|
110 | $tpl->setVariable("WIDGET-TAGSTRING-VALUE",
|
---|
111 | $wpsm->get(org_tubepress_options_category_Widget::TAGSTRING));
|
---|
112 | echo $tpl->get();
|
---|
113 | }
|
---|
114 |
|
---|
115 | ?>
|
---|