source: trunk/www.guidonia.net/wp/wp-content/plugins/tubepress/classes/org/tubepress/options/form/WidgetPrinter.class.php@ 44

Last change on this file since 44 was 44, checked in by luciano, 14 years ago
File size: 6.8 KB
Line 
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
22function_exists('tubepress_load_classes')
23 || require(dirname(__FILE__) . '/../../../../tubepress_classloader.php');
24tubepress_load_classes(array('net_php_pear_HTML_Template_IT',
25 'org_tubepress_options_category_Gallery',
26 'org_tubepress_options_Type',
27 'org_tubepress_message_MessageService',
28 'org_tubepress_options_reference_OptionsReference',
29 'org_tubepress_options_storage_StorageManager',
30 'org_tubepress_util_StringUtils'));
31
32/**
33 * Prints widgets for the options form
34 *
35 */
36class org_tubepress_options_form_WidgetPrinter
37{
38 private $_optionsReference;
39 private $_messageService;
40 private $_tpl;
41 private $_tpsm;
42
43 public function getHtml($optionName)
44 {
45 $this->_tpl = new net_php_pear_HTML_Template_IT(dirname(__FILE__) . "/../../../../../ui/options_page/html_templates");
46 if (!$this->_tpl->loadTemplatefile("options_widgets.tpl.html", true, true)) {
47 throw new Exception("Could not load template for $optionName option");
48 }
49
50 $this->_processSingleWidget($optionName);
51
52 return org_tubepress_util_StringUtils::removeEmptyLines($this->_tpl->get());
53 }
54
55 public function getHtmlForRadio($optionName)
56 {
57 $this->_tpl = new net_php_pear_HTML_Template_IT(dirname(__FILE__) . "/../../../../../ui/options_page/html_templates");
58 if (!$this->_tpl->loadTemplatefile("options_widgets.tpl.html", true, true)) {
59 throw new Exception("Could not load template for $optionName option");
60 }
61
62 $this->_displayGalleryInput($optionName, $this->_tpsm->get(org_tubepress_options_category_Gallery::MODE));
63
64 return org_tubepress_util_StringUtils::removeEmptyLines($this->_tpl->get());
65 }
66
67 private function _processSingleWidget($optionName)
68 {
69 $type = $this->_optionsReference->getType($optionName);
70 switch ($type) {
71 case org_tubepress_options_Type::BOOL:
72 $this->_displayBooleanInput($optionName);
73 break;
74 case org_tubepress_options_Type::TEXT:
75 case org_tubepress_options_Type::INTEGRAL:
76 $this->_displayTextInput($optionName);
77 break;
78 case org_tubepress_options_Type::COLOR:
79 $this->_displayColorInput($optionName);
80 break;
81 case org_tubepress_options_Type::ORDER:
82 case org_tubepress_options_Type::PLAYER:
83 case org_tubepress_options_Type::QUALITY:
84 case org_tubepress_options_Type::TIME_FRAME:
85 case org_tubepress_options_Type::SAFE_SEARCH:
86 case org_tubepress_options_Type::PLAYER_IMPL:
87 $this->_displayMenuInput($optionName, $this->_createMenuItemsArray($type));
88 }
89 }
90
91 private function _createMenuItemsArray($optionType)
92 {
93 $resuls = array();
94 foreach ($this->_optionsReference->getValidEnumValues($optionType) as $value) {
95 $results[$this->_messageService->_("$optionType-$value")] = $value;
96 }
97 return $results;
98 }
99
100 /**
101 * Displays a drop-down menu
102 *
103 * @param string $name The name of the select input
104 * @param array $values The possible values for the drop-down
105 *
106 * @return void
107 */
108 private function _displayMenuInput($name, $values)
109 {
110 $value = $this->_tpsm->get($name);
111 $this->_tpl->setVariable("OPTION_NAME", $name);
112 foreach ($values as $validValueTitle => $validValue) {
113
114 if ($validValue === $value) {
115 $this->_tpl->setVariable("OPTION_SELECTED", "SELECTED");
116 }
117 $this->_tpl->setVariable("MENU_ITEM_TITLE", $validValueTitle);
118 $this->_tpl->setVariable("MENU_ITEM_VALUE", $validValue);
119 $this->_tpl->parse("menuItem");
120 }
121 $this->_tpl->parse("menu");
122 }
123
124 /**
125 * Displays a text input
126 *
127 * @param string $name The name of the input
128 *
129 * @return void
130 */
131 private function _displayTextInput($name)
132 {
133 $value = $this->_tpsm->get($name);
134 $this->_tpl->setVariable("OPTION_VALUE", $value);
135 $this->_tpl->setVariable("OPTION_NAME", $name);
136 $this->_tpl->parse("text");
137 }
138
139 /**
140 * Displays a text input
141 *
142 * @param string $name The name of the input
143 *
144 * @return void
145 */
146 private function _displayColorInput($name)
147 {
148 $value = $this->_tpsm->get($name);
149 $this->_tpl->setVariable("OPTION_VALUE", $value);
150 $this->_tpl->setVariable("OPTION_NAME", $name);
151 $this->_tpl->parse("color");
152 }
153
154 /**
155 * Displays a checkbox input
156 *
157 * @param string $name The name of the checkbox input
158 *
159 * @return void
160 */
161 private function _displayBooleanInput($name)
162 {
163 $value = $this->_tpsm->get($name);
164 $this->_tpl->setVariable("OPTION_NAME", $name);
165
166 if ($value) {
167 $this->_tpl->setVariable("OPTION_SELECTED", "CHECKED");
168 }
169 $this->_tpl->parse("checkbox");
170 }
171
172 /**
173 * Displays a radio button and then an optional additional input
174 *
175 * @param string $name The name of the input
176 * @param string $value The current value
177 *
178 * @return void
179 */
180 private function _displayGalleryInput($name, $value)
181 {
182 $this->_tpl->setVariable("OPTION_NAME", $name);
183 if ($name === $value) {
184 $this->_tpl->setVariable("OPTION_SELECTED", "CHECKED");
185 }
186 $this->_tpl->parse("galleryType");
187 }
188
189 public function setMessageService(org_tubepress_message_MessageService $messageService) { $this->_messageService = $messageService; }
190 public function setOptionsReference(org_tubepress_options_reference_OptionsReference $reference) { $this->_optionsReference = $reference; }
191 public function setStorageManager(org_tubepress_options_storage_StorageManager $storageManager) { $this->_tpsm = $storageManager; }
192
193}
Note: See TracBrowser for help on using the repository browser.