/** * @param array $errors An associative array, which may be empty, of field IDs to error messages. * @param boolean $justSubmitted True if the form was just submitted, false otherwise. * * @return string The HTML for the options page. */ public function getHTML(array $errors = array(), $justSubmitted = false) { $templateBldr = tubepress_impl_patterns_sl_ServiceLocator::getTemplateBuilder(); $eventDispatcher = tubepress_impl_patterns_sl_ServiceLocator::getEventDispatcher(); $environmentDetector = tubepress_impl_patterns_sl_ServiceLocator::getEnvironmentDetector(); $template = $templateBldr->getNewTemplateInstance($this->_templatePath); $fields = $this->_buildFieldsArray(); $categories = $this->_buildCategoriesArray(); $categoryIdToParticipantIdToFieldsMap = $this->_buildCategoryIdToParticipantIdToFieldsMap($categories); $participants = $this->_buildParticipantsArray(); if (isset($fields[tubepress_addons_core_impl_options_ui_fields_ParticipantFilterField::FIELD_ID])) { /** * @var $filterField tubepress_addons_core_impl_options_ui_fields_ParticipantFilterField */ $filterField = $fields[tubepress_addons_core_impl_options_ui_fields_ParticipantFilterField::FIELD_ID]; $filterField->setOptionsPageParticipants($this->_optionsPageParticipants); } $templateVariables = array('categories' => $categories, 'categoryIdToParticipantIdToFieldsMap' => $categoryIdToParticipantIdToFieldsMap, 'errors' => $errors, 'fields' => $fields, 'isPro' => $environmentDetector->isPro(), 'justSubmitted' => $justSubmitted, 'participants' => $participants, "successMessage" => 'Settings updated.', 'tubePressBaseUrl' => $environmentDetector->getBaseUrl(), "saveText" => 'Save'); foreach ($templateVariables as $key => $val) { $template->setVariable($key, $val); } $templateEvent = new tubepress_spi_event_EventBase($template); $eventDispatcher->dispatch(tubepress_api_const_event_EventNames::OPTIONS_PAGE_TEMPLATE, $templateEvent); return $template->toString(); }
/** * Filter the content (which may be empty). */ public final function printControlHtml() { $wpsm = tubepress_impl_patterns_sl_ServiceLocator::getOptionStorageManager(); $msg = tubepress_impl_patterns_sl_ServiceLocator::getMessageService(); $tplBuilder = tubepress_impl_patterns_sl_ServiceLocator::getTemplateBuilder(); $hrps = tubepress_impl_patterns_sl_ServiceLocator::getHttpRequestParameterService(); /* are we saving? */ if ($hrps->hasParam(self::WIDGET_SUBMIT_TAG)) { self::_verifyNonce(); $wpsm->queueForSave(tubepress_addons_wordpress_api_const_options_names_WordPress::WIDGET_SHORTCODE, $hrps->getParamValue('tubepress-widget-tagstring')); $wpsm->queueForSave(tubepress_addons_wordpress_api_const_options_names_WordPress::WIDGET_TITLE, $hrps->getParamValue('tubepress-widget-title')); $wpsm->flushSaveQueue(); } /* load up the gallery template */ $templatePath = TUBEPRESS_ROOT . '/src/main/php/add-ons/wordpress/resources/templates/widget_controls.tpl.php'; $tpl = $tplBuilder->getNewTemplateInstance($templatePath); /* set up the template */ $tpl->setVariable(self::WIDGET_TITLE, $wpsm->fetch(tubepress_addons_wordpress_api_const_options_names_WordPress::WIDGET_TITLE)); $tpl->setVariable(self::WIDGET_CONTROL_TITLE, $msg->_('Title')); //>(translatable)< $tpl->setVariable(self::WIDGET_CONTROL_SHORTCODE, $msg->_('TubePress shortcode for the widget. See the <a href="http://tubepress.com/documentation" target="_blank">documentation</a>.')); //>(translatable)< $tpl->setVariable(self::WIDGET_SHORTCODE, $wpsm->fetch(tubepress_addons_wordpress_api_const_options_names_WordPress::WIDGET_SHORTCODE)); $tpl->setVariable(self::WIDGET_SUBMIT_TAG, self::WIDGET_SUBMIT_TAG); /* get the template's output */ echo $tpl->toString(); }
/** * @return string The widget HTML for this form element. */ public function getWidgetHTML() { $templateBuilder = tubepress_impl_patterns_sl_ServiceLocator::getTemplateBuilder(); $eventDispatcher = tubepress_impl_patterns_sl_ServiceLocator::getEventDispatcher(); $template = $templateBuilder->getNewTemplateInstance($this->getAbsolutePathToTemplate()); $templateEvent = new tubepress_spi_event_EventBase($template); $templateEvent->setArgument('field', $this); $templateVariables = $this->getTemplateVariables(); foreach ($templateVariables as $name => $value) { $template->setVariable($name, $value); } $eventDispatcher->dispatch(tubepress_api_const_event_EventNames::OPTIONS_PAGE_FIELDTEMPLATE, $templateEvent); return $template->toString(); }
/** * Gets an instance of a template appropriate for the current theme. * * @param string $pathToTemplate The relative path (from the root of the user's theme directory, * or the fallback directory) to the template. * @param string $fallBackDirectory The absolute path to a directory where this template (defined by the relative * path, can be found). You should make sure that the template will *always* exist * here. * * @throws RuntimeException If the template could not be found. * * @return ehough_contemplate_api_Template The template instance. */ function getTemplateInstance($pathToTemplate, $fallBackDirectory) { $debugEnabled = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG); if ($debugEnabled) { $this->_logger->debug("Attempting to load template instance from {$pathToTemplate} with fallback directory " . " at {$fallBackDirectory}"); } $currentTheme = $this->calculateCurrentThemeName(); if ($debugEnabled) { $this->_logger->debug("Requested theme is '{$currentTheme}'"); } $templateBuilder = tubepress_impl_patterns_sl_ServiceLocator::getTemplateBuilder(); $filePath = $this->_getFilePath($currentTheme, $pathToTemplate, $fallBackDirectory, $debugEnabled); $template = $templateBuilder->getNewTemplateInstance($filePath); if ($debugEnabled) { $this->_logger->debug("Successfully loaded template from {$filePath}"); } return $template; }