public function run(tubepress_api_event_EventInterface $event)
 {
     $errors = array();
     $justSubmitted = false;
     /* are we updating? */
     if ($_SERVER['REQUEST_METHOD'] === 'POST' && $this->_httpRequestParams->hasParam('tubepress_save')) {
         $justSubmitted = true;
         $errors = $this->_form->onSubmit();
     }
     echo $this->_form->getHtml($errors, $justSubmitted);
 }
 private function _ensureRequiredParamsPresent()
 {
     $required = array_merge($this->getRequiredParamNames(), array('csrf_token', 'provider'));
     foreach ($required as $key) {
         if (!$this->_requestParams->hasParam($key)) {
             $this->bail(sprintf('Missing %s parameter.', $key));
         }
     }
 }
Esempio n. 3
0
 public function __construct(tubepress_api_options_ContextInterface $context, tubepress_api_http_RequestParametersInterface $requestParams)
 {
     $loggingRequested = $requestParams->hasParam('tubepress_debug') && $requestParams->getParamValue('tubepress_debug') === true;
     $loggingEnabled = $context->get(tubepress_api_options_Names::DEBUG_ON);
     $this->_enabled = $loggingRequested && $loggingEnabled;
     $this->_bootMessageBuffer = array();
     $this->_shouldBuffer = true;
     $this->_timezone = new DateTimeZone(@date_default_timezone_get() ? @date_default_timezone_get() : 'UTC');
 }
Esempio n. 4
0
 /**
  * Filter the content (which may be empty).
  */
 public function printControlHtml()
 {
     /* are we saving? */
     if ($this->_httpRequestParams->hasParam(self::WIDGET_SUBMIT_TAG)) {
         $this->_wpFunctions->check_admin_referer('tubepress-widget-nonce-save', 'tubepress-widget-nonce');
         $this->_persistence->queueForSave(tubepress_wordpress_api_Constants::OPTION_WIDGET_SHORTCODE, $this->_httpRequestParams->getParamValue('tubepress-widget-tagstring'));
         $this->_persistence->queueForSave(tubepress_wordpress_api_Constants::OPTION_WIDGET_TITLE, $this->_httpRequestParams->getParamValue('tubepress-widget-title'));
         $this->_persistence->flushSaveQueue();
     }
     $templateVars = array(self::WIDGET_TITLE => $this->_persistence->fetch(tubepress_wordpress_api_Constants::OPTION_WIDGET_TITLE), self::WIDGET_CONTROL_TITLE => $this->_translator->trans('Title'), self::WIDGET_CONTROL_SHORTCODE => $this->_translator->trans(sprintf('TubePress shortcode for the widget. See the <a href="%s" target="_blank">documentation</a>.', "http://docs.tubepress.com/")), self::WIDGET_SHORTCODE => $this->_persistence->fetch(tubepress_wordpress_api_Constants::OPTION_WIDGET_SHORTCODE), self::WIDGET_SUBMIT_TAG => self::WIDGET_SUBMIT_TAG, self::WIDGET_NONCE_FIELD => $this->_wpFunctions->wp_nonce_field('tubepress-widget-nonce-save', 'tubepress-widget-nonce', true, false));
     echo $this->_templating->renderTemplate('wordpress/single-widget-controls', $templateVars);
 }
Esempio n. 5
0
 /**
  * {@inheritdoc}
  */
 public function handle()
 {
     if ($this->_isDebugEnabled) {
         $this->_logger->debug('Handling incoming request');
     }
     if (!$this->_requestParameters->hasParam('tubepress_action')) {
         $this->_errorOut(new RuntimeException('Missing "tubepress_action" parameter'), 400);
         return;
     }
     $actionName = $this->_requestParameters->getParamValue('tubepress_action');
     $ajaxEvent = $this->_eventDispatcher->newEventInstance();
     try {
         $this->_eventDispatcher->dispatch(tubepress_api_event_Events::HTTP_AJAX . ".{$actionName}", $ajaxEvent);
     } catch (Exception $e) {
         $this->_errorOut($e, 500);
         return;
     }
     $resultingArgs = $ajaxEvent->getArguments();
     if (!array_key_exists('handled', $resultingArgs) || !$resultingArgs['handled']) {
         $this->_errorOut(new RuntimeException('Action not handled'), 400);
     }
 }