Пример #1
0
 public function alter_galleryTemplate(org_tubepress_api_template_Template $template, org_tubepress_api_provider_ProviderResult $providerResult, $page, $providerName)
 {
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $context = $ioc->get('org_tubepress_api_exec_ExecutionContext');
     $messageService = $ioc->get('org_tubepress_api_message_MessageService');
     $metaNames = org_tubepress_impl_options_OptionsReference::getOptionNamesForCategory(org_tubepress_api_const_options_CategoryName::META);
     $shouldShow = array();
     $labels = array();
     foreach ($metaNames as $metaName) {
         $shouldShow[$metaName] = $context->get($metaName);
         $labels[$metaName] = $messageService->_('video-' . $metaName);
     }
     $template->setVariable(org_tubepress_api_const_template_Variable::META_SHOULD_SHOW, $shouldShow);
     $template->setVariable(org_tubepress_api_const_template_Variable::META_LABELS, $labels);
     return $template;
 }
 /**
  * Checks if the option value has the right type
  *
  * @param string  $optionName The name of the option to validate
  * @param unknown $candidate  The value of the option to validate
  *
  * @return void
  */
 private static function _checkType($optionName, $candidate, org_tubepress_api_message_MessageService $messageService)
 {
     $type = org_tubepress_impl_options_OptionsReference::getType($optionName);
     switch ($type) {
         case org_tubepress_api_const_options_Type::TEXT:
         case org_tubepress_api_const_options_Type::YT_USER:
         case org_tubepress_api_const_options_Type::PLAYLIST:
             if (!is_string($candidate)) {
                 throw new Exception(sprintf($messageService->_('validation-text'), $optionName, $candidate));
             }
             break;
         case org_tubepress_api_const_options_Type::BOOL:
             if (strcasecmp((string) $candidate, '1') !== 0 && strcasecmp((string) $candidate, '') !== 0) {
                 throw new Exception(sprintf($messageService->_('validation-bool'), $optionName, $candidate));
             }
             break;
         case org_tubepress_api_const_options_Type::INTEGRAL:
             if (intval($candidate) == 0 && $optionName != org_tubepress_api_const_options_names_Display::DESC_LIMIT && $optionName !== org_tubepress_api_const_options_names_Feed::RESULT_COUNT_CAP) {
                 throw new Exception(sprintf($messageService->_('validation-int-type'), $optionName, $candidate));
             }
             break;
         case org_tubepress_api_const_options_Type::ORDER:
         case org_tubepress_api_const_options_Type::PLAYER:
         case org_tubepress_api_const_options_Type::PLAYER_IMPL:
         case org_tubepress_api_const_options_Type::SAFE_SEARCH:
         case org_tubepress_api_const_options_Type::TIME_FRAME:
             $validValues = org_tubepress_impl_options_OptionsReference::getValidEnumValues($type);
             if (in_array((string) $candidate, $validValues) !== true) {
                 throw new Exception(sprintf($messageService->_('validation-enum'), $optionName, implode(', ', $validValues), $candidate));
             }
             break;
         case org_tubepress_api_const_options_Type::COLOR:
             //implement me please
             break;
     }
 }
 /**
  * Sets an option value
  *
  * @param string       $optionName  The option name
  * @param unknown_type $optionValue The option value
  * 
  * @return void
  */
 public function set($optionName, $optionValue)
 {
     if (!org_tubepress_impl_options_OptionsReference::shouldBePersisted($optionName)) {
         return;
     }
     $ioc = org_tubepress_impl_ioc_IocContainer::getInstance();
     $validationService = $ioc->get('org_tubepress_api_options_OptionValidator');
     $validationService->validate($optionName, $optionValue);
     $this->setOption($optionName, $optionValue);
 }