Esempio n. 1
0
 public function getSource($name)
 {
     $source = file_get_contents($this->findTemplate($name));
     if ($this->_shouldLog) {
         $this->_logger->debug(sprintf('Template source for <code>%s</code> was found on the filesystem at <code>%s</code>', $name, $this->findTemplate($name)));
     }
     return $source;
 }
Esempio n. 2
0
 public function __construct(tubepress_api_log_LoggerInterface $logger, tubepress_api_options_ContextInterface $context, tubepress_api_event_EventDispatcherInterface $eventDispatcher, tubepress_api_environment_EnvironmentInterface $environment)
 {
     $this->_context = $context;
     $this->_eventDispatcher = $eventDispatcher;
     $this->_logger = $logger;
     $this->_shouldLog = $logger->isEnabled();
     $this->_environment = $environment;
 }
Esempio n. 3
0
 public function __construct(tubepress_api_log_LoggerInterface $logger, tubepress_api_options_ContextInterface $context, tubepress_api_http_RequestParametersInterface $requestParams, tubepress_api_media_CollectorInterface $collector)
 {
     $this->_logger = $logger;
     $this->_context = $context;
     $this->_requestParams = $requestParams;
     $this->_collector = $collector;
     $this->_shouldLog = $logger->isEnabled();
 }
Esempio n. 4
0
 public function __construct(tubepress_api_log_LoggerInterface $logger, tubepress_api_http_RequestParametersInterface $requestParams, tubepress_api_http_ResponseCodeInterface $responseCode, tubepress_api_event_EventDispatcherInterface $eventDispatcher, tubepress_api_template_TemplatingInterface $templating)
 {
     $this->_logger = $logger;
     $this->_isDebugEnabled = $logger->isEnabled();
     $this->_requestParameters = $requestParams;
     $this->_responseCode = $responseCode;
     $this->_eventDispatcher = $eventDispatcher;
     $this->_templating = $templating;
 }
Esempio n. 5
0
 public function onFatalError(tubepress_api_log_LoggerInterface $logger, array $error)
 {
     try {
         if (!$this->_isErrorFatal($error)) {
             return;
         }
         $logger->error(sprintf('Fatal error (type <code>%s</code>) detected on line <code>%s</code> of <code>%s</code>: <code>%s</code>', $error['type'], $error['line'], htmlspecialchars($error['file']), htmlspecialchars($error['message'])));
     } catch (\Exception $e) {
         //we tried
     }
 }
Esempio n. 6
0
 public function onOptionSet(tubepress_api_event_EventInterface $event)
 {
     if (!$this->_logger->isEnabled()) {
         return;
     }
     $errors = $event->getSubject();
     $optionName = $event->getArgument('optionName');
     $optionValue = $event->getArgument('optionValue');
     if (count($errors) === 0) {
         $this->_logger->debug(sprintf('(Option Logger) Accepted valid value: <code>%s</code> = <code>%s</code>', $optionName, $this->_stringUtils->redactSecrets($optionValue)));
     } else {
         $this->_logger->error(sprintf('(Option Logger) Rejecting invalid value: <code>%s</code> = <code>%s</code> (%s)', $optionName, $this->_stringUtils->redactSecrets($optionValue), $errors[0]));
     }
 }
Esempio n. 7
0
 private function _handle(tubepress_api_event_EventInterface $event)
 {
     $itemId = $this->_requestParams->getParamValue('tubepress_item');
     $shouldLog = $this->_logger->isEnabled();
     if ($shouldLog) {
         $this->_logger->debug(sprintf('Building single video with ID %s', $itemId));
     }
     $result = $this->_context->setEphemeralOption(tubepress_api_options_Names::SINGLE_MEDIA_ITEM_ID, $itemId);
     if ($result !== null) {
         if ($shouldLog) {
             $this->_logger->debug('Could not verify video ID.');
         }
     }
 }
Esempio n. 8
0
 /**
  * Handles the detection of a custom options.
  *
  * @param array $match The array shortcode matches
  *
  * @return array The name value pair array.
  */
 private function _buildNameValuePairArray($match)
 {
     $toReturn = array();
     $value = null;
     foreach ($match as $m) {
         if (!empty($m[1])) {
             $name = $m[1];
             $value = $m[2];
         } elseif (!empty($m[3])) {
             $name = $m[3];
             $value = $m[4];
         } elseif (!empty($m[5])) {
             $name = $m[5];
             $value = $m[6];
         }
         if (!isset($name) || !isset($value)) {
             continue;
         }
         if ($this->_shouldLog) {
             $this->_logger->debug(sprintf('Name-value pair detected: %s = "%s" (unfiltered)', $name, $this->_stringUtils->redactSecrets($value)));
         }
         $event = $this->_eventDispatcher->newEventInstance($value, array('optionName' => $name));
         $this->_eventDispatcher->dispatch(tubepress_api_event_Events::NVP_FROM_EXTERNAL_INPUT, $event);
         $filtered = $event->getSubject();
         $event = $this->_eventDispatcher->newEventInstance($filtered, array('optionName' => $name));
         $this->_eventDispatcher->dispatch(tubepress_api_event_Events::NVP_FROM_EXTERNAL_INPUT . ".{$name}", $event);
         $filtered = $event->getSubject();
         if ($this->_shouldLog) {
             $this->_logger->debug(sprintf('Name-value pair detected: %s = "%s" (filtered)', $name, $this->_stringUtils->redactSecrets($filtered)));
         }
         $toReturn[$name] = $filtered;
     }
     return $toReturn;
 }
Esempio n. 9
0
 public function onException(tubepress_api_event_EventInterface $event)
 {
     if (!$this->_logger->isEnabled()) {
         return;
     }
     /*
      * @var Exception
      */
     $exception = $event->getSubject();
     $traceData = $exception->getTraceAsString();
     $traceData = explode("\n", $traceData);
     foreach ($traceData as $line) {
         $line = htmlspecialchars($line);
         $this->_logger->error("<code>{$line}</code><br />");
     }
 }
Esempio n. 10
0
 public function onHtmlGeneration(tubepress_api_event_EventInterface $event)
 {
     $mediaItemId = $this->_context->get(tubepress_api_options_Names::SINGLE_MEDIA_ITEM_ID);
     if ($mediaItemId == '') {
         return;
     }
     /* grab the media item from the provider */
     if ($this->_logger->isEnabled()) {
         $this->_logger->debug(sprintf('Asking provider for video with ID %s', $mediaItemId));
     }
     $mediaItem = $this->_collector->collectSingle($mediaItemId);
     $eventArgs = array('itemId' => $mediaItemId);
     if ($mediaItem !== null) {
         $eventArgs['mediaItem'] = $mediaItem;
     }
     $singleHtml = $this->_templating->renderTemplate('single/main', $eventArgs);
     $event->setSubject($singleHtml);
     $event->stopPropagation();
 }
Esempio n. 11
0
 /**
  * @param string $manifestPath
  * @param array  $manifestData
  *
  * @return tubepress_internal_contrib_AbstractContributable
  */
 public function fromManifestData($manifestPath, array $manifestData)
 {
     $errors = $this->_normalizeAndReturnErrors($manifestPath, $manifestData);
     if (count($errors) !== 0) {
         if ($this->_logger->isEnabled()) {
             $this->_logger->error(sprintf('The following errors were detected when processing %s', $manifestPath));
             foreach ($errors as $error) {
                 $this->_logger->error($error);
             }
         }
         return $errors;
     }
     $contributable = $this->buildWithValidNormalizedData($manifestPath, $manifestData);
     $this->_setDescription($manifestData, $contributable);
     $this->_setKeywords($manifestData, $contributable);
     $this->_setScreenshots($manifestData, $contributable);
     $this->_setSupport($manifestData, $contributable);
     return $contributable;
 }
Esempio n. 12
0
 public function onAjax(tubepress_api_event_EventInterface $ajaxEvent)
 {
     $isDebugEnabled = $this->_logger->isEnabled();
     if ($isDebugEnabled) {
         $this->_logger->debug('Handling incoming request. First parsing shortcode.');
     }
     $nvpMap = $this->_requestParams->getParamValue('tubepress_options');
     $itemId = $this->_requestParams->getParamValue('tubepress_item');
     if ($isDebugEnabled) {
         $this->_logger->debug('Requested item ID is ' . $itemId);
     }
     $this->_context->setEphemeralOptions($nvpMap);
     if ($this->_context->get(tubepress_api_options_Names::EMBEDDED_LAZYPLAY)) {
         $this->_context->setEphemeralOption(tubepress_api_options_Names::EMBEDDED_AUTOPLAY, true);
     }
     if ($isDebugEnabled) {
         $this->_logger->debug('Now asking collector for item with ID ' . $itemId);
     }
     /* grab the item! */
     $mediaItem = $this->_collector->collectSingle($itemId);
     if ($mediaItem === null) {
         $this->_responseCode->setResponseCode(404);
         $ajaxEvent->setArgument('handled', true);
         return;
     }
     if ($isDebugEnabled) {
         $this->_logger->debug('Collector found item with ID ' . $itemId . '. Sending it to browser');
     }
     $playerHtml = $this->_templating->renderTemplate('gallery/player/ajax', array(tubepress_api_template_VariableNames::MEDIA_ITEM => $mediaItem));
     $toReturn = array('mediaItem' => $mediaItem->toHtmlSafeArray(), 'html' => $playerHtml);
     $this->_responseCode->setResponseCode(200);
     echo json_encode($toReturn);
     $ajaxEvent->setArgument('handled', true);
 }
Esempio n. 13
0
 /**
  * @param tubepress_api_url_UrlInterface $url
  * @param array                          $requestOpts
  *
  * @return array
  */
 public function getDecodedApiResponse(tubepress_api_url_UrlInterface $url, $requestOpts = array())
 {
     $httpRequest = $this->_httpClient->createRequest('GET', $url, $requestOpts);
     $finalConfig = array_merge($httpRequest->getConfig(), array('tubepress-remote-api-call' => true));
     $httpRequest->setConfig($finalConfig);
     $urlAsString = $url->toString();
     if (!isset($this->_memoryCache[$urlAsString])) {
         $httpResponse = $this->_httpClient->send($httpRequest);
         $rawFeed = $httpResponse->getBody()->toString();
         $decoded = json_decode($rawFeed, true);
         if ($decoded === null) {
             throw new RuntimeException('Unable to decode JSON from Dailymotion');
         }
         $this->checkForApiResponseError($decoded);
         $this->_memoryCache[$urlAsString] = $decoded;
     } else {
         if ($this->_shouldLog) {
             $this->_logger->debug(sprintf('Response for <code>%s</code> found in the in-memory cache.', $urlAsString));
         }
     }
     return $this->_memoryCache[$urlAsString];
 }
Esempio n. 14
0
 public function onPreValidationSet(tubepress_api_event_EventInterface $event)
 {
     $themeValue = $event->getArgument('optionValue');
     $shouldLog = $this->_logger->isEnabled();
     if (in_array($themeValue, self::$_LEGACY_THEME_VALUES)) {
         if ($shouldLog) {
             $this->_logger->debug(sprintf('Renaming theme value from %s to tubepress/legacy-%s', $themeValue, $themeValue));
         }
         $event->setArgument('optionValue', "tubepress/legacy-{$themeValue}");
         return;
     }
     $allThemes = $this->_themeRegistry->getAll();
     foreach ($allThemes as $theme) {
         if ($theme->getName() !== "unknown/legacy-{$themeValue}") {
             continue;
         }
         if ($shouldLog) {
             $this->_logger->debug(sprintf('Renaming theme value from %s to unknown/legacy-%s', $themeValue, $themeValue));
         }
         $event->setArgument('optionValue', "unknown/legacy-{$themeValue}");
     }
 }
Esempio n. 15
0
 private function _collectGroupIdsFromSubmission()
 {
     $allParams = $this->_httpRequestParams->getAllParams();
     $this->_cachedGroupIds = array();
     foreach ($allParams as $key => $value) {
         if (preg_match_all('/^tubepress-multisource-([0-9]+)-.+$/', $key, $matches) !== 1) {
             continue;
         }
         if (!is_array($matches) || count($matches) !== 2 || !is_array($matches[1]) || count($matches[1]) !== 1) {
             continue;
         }
         $this->_cachedGroupIds[] = $matches[1][0];
     }
     $this->_cachedGroupIds = array_values(array_unique($this->_cachedGroupIds));
     if ($this->_shouldLog) {
         $this->_logger->debug(sprintf('Found %d multisource group(s): %s', count($this->_cachedGroupIds), json_encode($this->_cachedGroupIds)));
     }
 }
Esempio n. 16
0
 private function _logDebug($msg)
 {
     $this->_logger->debug(sprintf('(Manifest Finder) %s', $msg));
 }
Esempio n. 17
0
 private function _logDebug($msg)
 {
     $this->_logger->debug(sprintf('(WordPress Entry Point) %s', $msg));
 }
 private function _logDebug($msg)
 {
     $this->_logger->debug(sprintf('(API Cache Driver - Filesystem) %s', $msg));
 }
Esempio n. 19
0
 private function _logDebug($msg)
 {
     $this->_logger->debug(sprintf('(Gallery Listener) %s', $msg));
 }
Esempio n. 20
0
 private function _log($msg)
 {
     $this->_logger->debug(sprintf('(Boot Settings) %s', $msg));
 }
Esempio n. 21
0
 private function _logDebug($msg)
 {
     $this->_logger->debug(sprintf('(YouTube Feed Handler) %s', $msg));
 }
Esempio n. 22
0
 private function _logDebug($msg)
 {
     $this->_logger->debug(sprintf('(Compiler) %s', $msg));
 }
Esempio n. 23
0
 private function _logDebug($msg)
 {
     $this->_logger->debug(sprintf('(Theme Template Locator) %s', $msg));
 }
Esempio n. 24
0
 private function _logDebug($msg)
 {
     $this->_logger->debug(sprintf('(HTTP Client) %s', $msg));
 }
Esempio n. 25
0
 private function _logDebug($msg)
 {
     $this->_logger->debug(sprintf('(Shortcode Listener) %s', $msg));
 }
Esempio n. 26
0
 private function _logDebug($msg)
 {
     $this->_logger->debug(sprintf('(Dailymotion Feed Handler) %s', $msg));
 }
Esempio n. 27
0
 private function _logDebug($msg)
 {
     $this->_logger->debug(sprintf('(API Cache Listener) %s', $msg));
 }
Esempio n. 28
0
 public function flushTo(tubepress_api_log_LoggerInterface $logger)
 {
     foreach ($this->_buffer as $message => $context) {
         $error = false;
         if (isset($context['__level'])) {
             $error = $context['__level'] === 'error';
             unset($context['__level']);
         }
         if ($error) {
             $logger->error($message, $context);
         } else {
             $logger->debug($message, $context);
         }
     }
 }
Esempio n. 29
0
 private function _logDebug($msg)
 {
     $this->_logger->debug(sprintf('(Container Supplier) %s', $msg));
 }
Esempio n. 30
0
 private function _logDebug($msg)
 {
     $this->_logger->debug(sprintf('(Delegating Template Engine) %s', $msg));
 }