[44] | 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__) . '/../../../../tubepress_classloader.php');
|
---|
| 24 | tubepress_load_classes(array('org_tubepress_options_category_Gallery',
|
---|
| 25 | 'org_tubepress_options_Category',
|
---|
| 26 | 'org_tubepress_options_form_WidgetPrinter',
|
---|
| 27 | 'org_tubepress_message_MessageService',
|
---|
| 28 | 'org_tubepress_options_reference_OptionsReference',
|
---|
| 29 | 'org_tubepress_options_storage_StorageManager',
|
---|
| 30 | 'net_php_pear_HTML_Template_IT'));
|
---|
| 31 |
|
---|
| 32 | /**
|
---|
| 33 | * Gets the HTML for an option category
|
---|
| 34 | *
|
---|
| 35 | */
|
---|
| 36 | class org_tubepress_options_form_CategoryPrinter
|
---|
| 37 | {
|
---|
| 38 | private $_tpl;
|
---|
| 39 | private $_optionsReference;
|
---|
| 40 | private $_messageService;
|
---|
| 41 | private $_tpsm;
|
---|
| 42 | private $_wp;
|
---|
| 43 |
|
---|
| 44 | public function getHtml($optionCategoryName) {
|
---|
| 45 |
|
---|
| 46 | $this->_loadTemplateFile($optionCategoryName);
|
---|
| 47 |
|
---|
| 48 | $this->_tpl->setVariable("OPTION_CATEGORY_TITLE",
|
---|
| 49 | $this->_messageService->_("options-category-title-$optionCategoryName"));
|
---|
| 50 |
|
---|
| 51 | $this->_parseOptionCategory($optionCategoryName);
|
---|
| 52 |
|
---|
| 53 | return $this->_tpl->get();
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | private function _parseOptionCategory($optionCategoryName)
|
---|
| 57 | {
|
---|
| 58 | switch ($optionCategoryName) {
|
---|
| 59 | case org_tubepress_options_Category::META:
|
---|
| 60 | $this->_parseMetaOptionsCategory();
|
---|
| 61 | break;
|
---|
| 62 | case org_tubepress_options_Category::GALLERY:
|
---|
| 63 | $this->_parseGalleryOptionsCategory();
|
---|
| 64 | break;
|
---|
| 65 | default:
|
---|
| 66 | $this->_parseRegularOptionsCategory($optionCategoryName);
|
---|
| 67 | }
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | private function _parseGalleryOptionsCategory()
|
---|
| 71 | {
|
---|
| 72 | $modeNames = $this->_optionsReference->getValidEnumValues(org_tubepress_options_category_Gallery::MODE);
|
---|
| 73 | foreach ($modeNames as $modeName) {
|
---|
| 74 |
|
---|
| 75 | $this->_tpl->setVariable("OPTION_TITLE",
|
---|
| 76 | $this->_messageService->_("options-title-$modeName"));
|
---|
| 77 | $this->_tpl->setVariable("OPTION_DESC",
|
---|
| 78 | $this->_messageService->_("options-desc-$modeName"));
|
---|
| 79 |
|
---|
| 80 | $html = $this->_wp->getHtmlForRadio($modeName);
|
---|
| 81 |
|
---|
| 82 | if ($this->_optionsReference->isOptionName($modeName . "Value")) {
|
---|
| 83 | $newName = $modeName . "Value";
|
---|
| 84 | $html .= $this->_wp->getHtml($newName);
|
---|
| 85 | }
|
---|
| 86 | $this->_tpl->setVariable("OPTION_WIDGET", $html);
|
---|
| 87 | $this->_tpl->parse('optionRow');
|
---|
| 88 | }
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | private function _parseMetaOptionsCategory()
|
---|
| 92 | {
|
---|
| 93 | $optionNames = $this->_optionsReference->getOptionNamesForCategory(org_tubepress_options_Category::META);
|
---|
| 94 |
|
---|
| 95 | $index = 1;
|
---|
| 96 | foreach ($optionNames as $optionName) {
|
---|
| 97 |
|
---|
| 98 | $this->_parseCommonOptionInfo($optionName);
|
---|
| 99 |
|
---|
| 100 | if ($index % 4 == 0) {
|
---|
| 101 | $this->_tpl->parse('optionRow');
|
---|
| 102 | } else {
|
---|
| 103 | $this->_tpl->parse('option');
|
---|
| 104 | }
|
---|
| 105 | $index++;
|
---|
| 106 | }
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | private function _parseRegularOptionsCategory($optionCategoryName)
|
---|
| 110 | {
|
---|
| 111 | $optionNames = $this->_optionsReference->getOptionNamesForCategory($optionCategoryName);
|
---|
| 112 |
|
---|
| 113 | foreach ($optionNames as $optionName) {
|
---|
| 114 |
|
---|
| 115 | $this->_parseCommonOptionInfo($optionName);
|
---|
| 116 | $this->_tpl->parse('optionRow');
|
---|
| 117 | }
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | private function _parseCommonOptionInfo($optionName)
|
---|
| 121 | {
|
---|
| 122 | $this->_tpl->setVariable("OPTION_TITLE",
|
---|
| 123 | $this->_messageService->_("options-title-$optionName"));
|
---|
| 124 | $this->_tpl->setVariable("OPTION_DESC",
|
---|
| 125 | $this->_messageService->_("options-desc-$optionName"));
|
---|
| 126 | $this->_tpl->setVariable("OPTION_WIDGET",
|
---|
| 127 | $this->_wp->getHtml($optionName));
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | private function _loadTemplateFile($optionCategoryName)
|
---|
| 131 | {
|
---|
| 132 | $this->_tpl = new net_php_pear_HTML_Template_IT(dirname(__FILE__) . "/../../../../../ui/options_page/html_templates");
|
---|
| 133 |
|
---|
| 134 | $name = $optionCategoryName == org_tubepress_options_Category::META ? "options_group_meta" : "options_group_regular";
|
---|
| 135 |
|
---|
| 136 | if (!$this->_tpl->loadTemplatefile("$name.tpl.html", true, true)) {
|
---|
| 137 | throw new Exception("Could not load template for $optionCategoryName category");
|
---|
| 138 | }
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | public function setMessageService(org_tubepress_message_MessageService $messageService) { $this->_messageService = $messageService; }
|
---|
| 142 | public function setOptionsReference(org_tubepress_options_reference_OptionsReference $reference) { $this->_optionsReference = $reference; }
|
---|
| 143 | public function setStorageManager(org_tubepress_options_storage_StorageManager $storageManager) { $this->_tpsm = $storageManager; }
|
---|
| 144 | public function setWidgetPrinter(org_tubepress_options_form_WidgetPrinter $widgetPrinter) { $this->_wp = $widgetPrinter; }
|
---|
| 145 | }
|
---|