/** * @return array An associative array of template variables for this field. */ protected function getTemplateVariables() { $storage = tubepress_impl_patterns_sl_ServiceLocator::getOptionStorageManager(); $id = $this->getId(); $value = $this->convertStorageFormatToStringValueForHTML($storage->fetch($id)); return array_merge(array('id' => $id, 'value' => $value), $this->getAdditionalTemplateVariables()); }
/** * 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(); }
/** * Gets the value of an option * * @param string $optionName The name of the option * * @return mixed The option value */ public final function get($optionName) { /* get the value, either from the shortcode or the db */ if (array_key_exists($optionName, $this->_customOptions)) { return $this->_customOptions[$optionName]; } $optionStorageManagerService = tubepress_impl_patterns_sl_ServiceLocator::getOptionStorageManager(); return $optionStorageManagerService->fetch($optionName); }
/** * Filter the content (which may be empty). */ public final function filterContent($content = '') { /* do as little work as possible here 'cause we might not even run */ $wpsm = tubepress_impl_patterns_sl_ServiceLocator::getOptionStorageManager(); $trigger = $wpsm->fetch(tubepress_api_const_options_names_Advanced::KEYWORD); $parser = tubepress_impl_patterns_sl_ServiceLocator::getShortcodeParser(); /* no shortcode? get out */ if (!$parser->somethingToParse($content, $trigger)) { return $content; } return $this->_getHtml($content, $trigger, $parser); }
public function onBoot(tubepress_api_event_EventInterface $event) { $storageManager = tubepress_impl_patterns_sl_ServiceLocator::getOptionStorageManager(); $odr = tubepress_impl_patterns_sl_ServiceLocator::getOptionDescriptorReference(); $allOptions = $odr->findAll(); $toPersist = array(); /** * @var $optionDescriptor tubepress_spi_options_OptionDescriptor */ foreach ($allOptions as $optionDescriptor) { if ($optionDescriptor->isMeantToBePersisted()) { $toPersist[$optionDescriptor->getName()] = $optionDescriptor->getDefaultValue(); } } $storageManager->createEachIfNotExists($toPersist); }
/** * Invoked when the page is submitted by the user. * * @return array An associative array, which may be empty, of field IDs to error messages. */ public function onSubmit() { /** * @var tubepress_spi_options_ui_OptionsPageFieldInterface[] $fields */ $fields = $this->_buildFieldsArray(); $errors = array(); foreach ($fields as $field) { $fieldError = $field->onSubmit(); if ($fieldError) { $errors[$field->getId()] = $fieldError; } } /** * Let's save! */ $optionStorage = tubepress_impl_patterns_sl_ServiceLocator::getOptionStorageManager(); $optionStorage->flushSaveQueue(); return $errors; }
/** * @param array $values The incoming values for this field. * * @return string|null A string error message to be displayed to the user, or null if no problem. */ protected function onSubmitMixed(array $values) { $storageManager = tubepress_impl_patterns_sl_ServiceLocator::getOptionStorageManager(); $optionName = $this->_disabledParticipantsOptionDescriptor->getName(); $allParticipantNames = array_keys($this->_getParticipantNamesToFriendlyNamesMap()); $toHide = array(); foreach ($allParticipantNames as $participantName) { /* * They checked the box, which means they want to show it. */ if (in_array($participantName, $values)) { continue; } /** * They don't want to show this provider, so hide it. */ $toHide[] = $participantName; } return $storageManager->queueForSave($optionName, implode(';', $toHide)); }
/** * @param string $name The option name. * @param string $value The option value. * * @return string|null Null if stored successfully, otherwise a string error message. */ protected function sendToStorage($name, $value) { $storageManager = tubepress_impl_patterns_sl_ServiceLocator::getOptionStorageManager(); return $storageManager->queueForSave($name, $value); }
/** * @param array $values The incoming values for this field. * * @return string|null A string error message to be displayed to the user, or null if no problem. */ protected function onSubmitMixed(array $values) { $storage = tubepress_impl_patterns_sl_ServiceLocator::getOptionStorageManager(); $optionNames = array_keys($this->_getOptionDescriptors()); foreach ($optionNames as $optionName) { $message = $storage->queueForSave($optionName, in_array($optionName, $values)); if ($message !== null) { return $message; } } return null; }