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

Last change on this file since 44 was 44, checked in by luciano, 14 years ago
File size: 4.7 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',
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_options_form_CategoryPrinter'));
31
32/**
33 * Displays a generic options form for TubePress
34 *
35 */
36class org_tubepress_options_form_FormHandler
37{
38 private $_optionsReference;
39 private $_messageService;
40 private $_storageManager;
41 private $_categoryPrinter;
42
43 /**
44 * Displays all the TubePress options in HTML
45 *
46 * @param org_tubepress_options_storage_StorageManager $tpsm The TubePress storage manager
47 *
48 * @return void
49 */
50 public final function display()
51 {
52 /* load up the template */
53 $tpl = new net_php_pear_HTML_Template_IT(dirname(__FILE__) . "/../../../../../ui/options_page/html_templates");
54 if (!$tpl->loadTemplatefile("options_page.tpl.html", true, true)) {
55 throw new Exception("Could not load options page template");
56 }
57
58 /* set the surrounding text */
59 $tpl->setVariable("PAGETITLE", $this->_messageService->_("options-page-title"));
60 $tpl->setVariable("INTROTEXT", $this->_messageService->_("options-page-intro-text"));
61 $tpl->setVariable("DONATION", $this->_messageService->_("options-page-donation"));
62 $tpl->setVariable("SAVE", $this->_messageService->_("options-page-save-button"));
63
64 /* now parse each option category */
65 $optionCategoryNames = $this->_optionsReference->getOptionCategoryNames();
66
67 foreach ($optionCategoryNames as $optionCategoryName) {
68
69 /* don't display the widget options on this page */
70 if ($optionCategoryName == org_tubepress_options_Category::WIDGET) {
71 continue;
72 }
73
74 $categoryHtml = $this->_categoryPrinter->getHtml($optionCategoryName);
75
76 $tpl->setVariable("OPTION_CATEGORY", $categoryHtml);
77 $tpl->parse("optionCategory");
78 }
79
80 print $tpl->get();
81 }
82
83 /**
84 * Updates options from a keyed array
85 *
86 * @param org_tubepress_options_storage_StorageManager $tpsm The TubePress storage manager
87 * @param array $postVars The POST variables
88 *
89 * @return void
90 */
91 public final function collect($postVars)
92 {
93 /* this loop will collect everything except checkboxes */
94 foreach ($postVars as $name => $value) {
95 if ($this->_storageManager->exists($name)) {
96 $this->_storageManager->set($name, $value);
97 }
98 }
99
100 /* this loop will handle the checkboxes */
101 $names = $this->_optionsReference->getAllOptionNames();
102 foreach ($names as $name) {
103
104 /* ignore non-bools */
105 if ($this->_optionsReference->getType($name) != org_tubepress_options_Type::BOOL) {
106 continue;
107 }
108
109 /* if the user checked the box, the option name will appear in the POST vars */
110 $this->_storageManager->set($name, array_key_exists($name, $postVars));
111 }
112 }
113
114 public function setMessageService(org_tubepress_message_MessageService $messageService) { $this->_messageService = $messageService; }
115 public function setOptionsReference(org_tubepress_options_reference_OptionsReference $reference) { $this->_optionsReference = $reference; }
116 public function setStorageManager(org_tubepress_options_storage_StorageManager $storageManager) { $this->_storageManager = $storageManager; }
117 public function setCategoryPrinter(org_tubepress_options_form_CategoryPrinter $printer) { $this->_categoryPrinter = $printer; }
118}
Note: See TracBrowser for help on using the repository browser.