public function onResponse(tubepress_api_event_EventInterface $event) { /* * @var tubepress_api_http_message_RequestInterface */ $httpRequest = $event->getArgument('request'); if (!$this->_shouldExecute($httpRequest)) { return; } /** * @var $httpResponse tubepress_api_http_message_ResponseInterface */ $httpResponse = $event->getSubject(); if ($httpResponse->hasHeader(self::HTTP_HEADER_CACHE_HIT)) { return; } $url = $httpRequest->getUrl(); $body = $httpResponse->getBody(); $result = $this->_getItem($url); $this->_possiblyClearCache(); $toStore = $body ? $body->toString() : ''; $storedSuccessfully = $result->set($toStore, intval($this->_context->get(tubepress_api_options_Names::CACHE_LIFETIME_SECONDS))); if (!$storedSuccessfully) { if ($this->_logger->isEnabled()) { $this->_logger->error('Unable to store data to cache'); } } }
/** * {@inheritdoc} */ public function parse($content) { try { $this->_wrappedParse($content); } catch (Exception $e) { if ($this->_shouldLog) { $this->_logger->error('Caught exception when parsing shortcode: ' . $e->getMessage()); } } }
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])); } }
private function _registerLegacyExtension(tubepress_internal_ioc_ContainerBuilder $container, $extensionClassName, $index, $count, tubepress_api_contrib_AddonInterface $addon) { if ($this->_shouldLog) { $this->_logDebug(sprintf('Converting <code>%s</code>', $extensionClassName)); } try { $ref = new ReflectionClass($extensionClassName); $path = realpath($ref->getFileName()); $fileContents = file_get_contents($path); if ($fileContents === false) { if ($this->_shouldLog) { $this->_logger->error(sprintf('Failed to read <code>%s</code> for <code>%s</code>', $path, $extensionClassName)); } return; } $search = array('tubepress_platform_api_ioc_ContainerBuilderInterface', 'tubepress_platform_api_ioc_ContainerExtensionInterface', 'tubepress_platform_api_ioc_DefinitionInterface', 'tubepress_platform_api_ioc_Reference', 'tubepress_app_api_options_ReferenceInterface', 'tubepress_app_api_options_ui_FieldInterface', 'tubepress_app_api_options_ui_FieldProviderInterface', 'tubepress_lib_api_ioc_ServiceTags', 'tubepress_app_api_listeners_options_RegexValidatingListener', 'tubepress_app_api_options_ui_FieldBuilderInterface', 'tubepress_app_api_event_Events', 'tubepress_app_api_embedded_EmbeddedProviderInterface', 'tubepress_lib_api_template_TemplatingInterface', 'tubepress_app_api_options_ContextInterface', 'tubepress_platform_api_url_UrlFactoryInterface', 'tubepress_platform_api_util_StringUtilsInterface'); $replace = array('tubepress_api_ioc_ContainerBuilderInterface', 'tubepress_spi_ioc_ContainerExtensionInterface', 'tubepress_api_ioc_DefinitionInterface', 'tubepress_api_ioc_Reference', 'tubepress_api_options_ReferenceInterface', 'tubepress_api_options_ui_FieldInterface', 'tubepress_spi_options_ui_FieldProviderInterface', 'tubepress_api_ioc_ServiceTags', 'tubepress_api_options_listeners_RegexValidatingListener', 'tubepress_api_options_ui_FieldBuilderInterface', 'tubepress_api_event_Events', 'tubepress_spi_embedded_EmbeddedProviderInterface', 'tubepress_api_template_TemplatingInterface', 'tubepress_api_options_ContextInterface', 'tubepress_api_url_UrlFactoryInterface', 'tubepress_api_util_StringUtilsInterface'); if ($this->_shouldLog) { $this->_logDebug(sprintf('Successfully read <code>%s</code> for <code>%s</code>. Now converting.', $path, $extensionClassName)); } $fileContents = str_replace('<?php', '', $fileContents); $fileContents = preg_replace('/class\\s+([^\\s]+)\\s+implements\\s+tubepress_platform_api_ioc_ContainerExtensionInterface\\s+/', 'class ${1}__converted implements tubepress_platform_api_ioc_ContainerExtensionInterface ', $fileContents); $newContents = str_replace($search, $replace, $fileContents); $evalResult = @eval($newContents); if ($this->_shouldLog) { $this->_logDebug(sprintf('Successfully loaded converted class? <code>%s</code>', $evalResult === null ? 'yes' : 'no')); } $this->_registerModernExtension($container, $extensionClassName . '__converted', $index, $count, $addon); } catch (Exception $e) { if ($this->_shouldLog) { $this->_logger->error(sprintf('Failed to convert <code>%s</code>: <code>%s</code>', $extensionClassName, $e->getMessage())); } return false; } }
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 />"); } }
private function _feedToMediaItemArray(tubepress_spi_media_HttpFeedHandlerInterface $feedHandler) { $toReturn = array(); $total = $feedHandler->getCurrentResultCount(); if ($this->_shouldLog) { $this->_logDebug(sprintf('Now attempting to build %d item(s) from raw feed', $total)); } for ($index = 0; $index < $total; ++$index) { $failureMessage = $feedHandler->getReasonUnableToUseItemAtIndex($index); if ($failureMessage !== null) { if ($this->_shouldLog) { $this->_logDebug(sprintf('Skipping item at index %d: %s', $index, $failureMessage)); } continue; } $mediaItemId = $feedHandler->getIdForItemAtIndex($index); if (!$mediaItemId) { if ($this->_logger->isEnabled()) { $this->_logger->error(sprintf('Unable to determine ID for item at index %d. Skipping it.', $index)); } continue; } $mediaItem = new tubepress_api_media_MediaItem($mediaItemId); $initialEventArgs = $feedHandler->getNewItemEventArguments($mediaItem, $index); $finalItem = $this->_dispatchAndReturnSubject($feedHandler, tubepress_api_event_Events::MEDIA_ITEM_HTTP_NEW, $mediaItem, $initialEventArgs); array_push($toReturn, $finalItem); } $feedHandler->onAnalysisComplete(); if ($this->_shouldLog) { $this->_logDebug(sprintf('Built %d items(s) from raw feed', sizeof($toReturn))); } return $toReturn; }
public function callback_onActivation() { try { $this->_dispatch(tubepress_wordpress_api_Constants::EVENT_PLUGIN_ACTIVATION, func_get_args()); } catch (\Exception $e) { $this->_logger->error($e->getMessage()); } }
/** * An associative array. The keys are the absolute paths to the manifests, and the values * are associative arrays containing the decoded manifest data. * * @return array */ public function find() { $toReturn = array(); $manifestPaths = $this->_findManifestPaths(); foreach ($manifestPaths as $manifestPath) { $decoded = null; try { $decoded = $this->_decodeManifestToAssociativeArray($manifestPath); $toReturn[$manifestPath] = $decoded; } catch (InvalidArgumentException $e) { if ($this->_shouldLog) { $this->_logger->error($e->getMessage()); continue; } } } return $toReturn; }
/** * @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; }
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 } }
/** * @param tubepress_internal_ioc_ContainerBuilder $containerBuilder * * @return \Symfony\Component\DependencyInjection\ContainerInterface */ private function _convertToSymfonyContainer(tubepress_internal_ioc_ContainerBuilder $containerBuilder) { if ($this->_shouldLog) { $this->_logDebug('Preparing to store boot to cache.'); } $dumpedContainerText = $this->_getDumpedSymfonyContainerAsString($containerBuilder->getDelegateContainerBuilder()); if ($this->_bootSettings->isSystemCacheEnabled()) { $cachePath = $this->_bootSettings->getPathToSystemCacheDirectory(); $storagePath = sprintf('%s%sTubePressServiceContainer.php', $cachePath, DIRECTORY_SEPARATOR); } else { $storagePath = tempnam(sys_get_temp_dir(), 'TubePressServiceContainer'); } if (!is_dir(dirname($storagePath))) { if ($this->_shouldLog) { $this->_logDebug(sprintf('Attempting to create all the parent directories of <code>%s</code>', $storagePath)); } $success = @mkdir(dirname($storagePath), 0755, true); if ($this->_shouldLog) { if ($success === true) { $this->_logDebug(sprintf('Created all the parent directories of <code>%s</code>', $storagePath)); } else { $this->_logger->error(sprintf('Failed to create all the parent directories of <code>%s</code>', $storagePath)); } } if ($success !== true) { return $containerBuilder->getDelegateContainerBuilder(); } } if ($this->_shouldLog) { $this->_logDebug(sprintf('Now writing dumped container to <code>%s</code>', $storagePath)); } $success = @file_put_contents($storagePath, $dumpedContainerText) !== false; if ($success) { if ($this->_shouldLog) { $this->_logDebug(sprintf('Saved service container to <code>%s</code>. Now including it.', $storagePath)); } if (!class_exists('TubePressServiceContainer', false)) { /** @noinspection PhpIncludeInspection */ require $storagePath; } } else { if ($this->_shouldLog) { $this->_logger->error(sprintf('Could not write service container to <code>%s</code>.', $storagePath)); } return $containerBuilder->getDelegateContainerBuilder(); } /** @noinspection PhpUndefinedClassInspection */ return new TubePressServiceContainer(); }
private function _getUrl(array $config, $key) { if (!$this->_isAllSet($config, self::$_TOP_LEVEL_KEY_USER, self::$_2ND_LEVEL_KEY_URLS, $key)) { return null; } $candidate = $config[self::$_TOP_LEVEL_KEY_USER][self::$_2ND_LEVEL_KEY_URLS][$key]; try { $toReturn = $this->_urlFactory->fromString($candidate); $toReturn->freeze(); return $toReturn; } catch (InvalidArgumentException $e) { if ($this->_shouldLog) { $this->_logger->error("Unable to parse {$key} URL from settings.php"); } return null; } }
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); } } }
/** * @param $templateName * * @return null|tubepress_api_theme_ThemeInterface */ private function _findThemeForTemplate($templateName) { $activeTheme = $this->_currentThemeService->getCurrentTheme(); $activeThemeName = $activeTheme->getName(); if (strpos($templateName, '::') !== false) { $exploded = explode('::', $templateName); if (count($exploded) === 2 && $this->_themeRegistry->getInstanceByName($exploded[0]) !== null) { $activeTheme = $this->_themeRegistry->getInstanceByName($exploded[0]); $activeThemeName = $activeTheme->getName(); $templateName = $exploded[1]; } } if ($this->_shouldLog) { $this->_logDebug(sprintf('Seeing if we can find <code>%s</code> in the theme hierarchy. %s.', $templateName, $this->_loggerPostfix($activeTheme))); } if (isset($this->_currentThemeNameToTemplateNameToThemeInstanceCache[$activeThemeName]) && isset($this->_currentThemeNameToTemplateNameToThemeInstanceCache[$activeThemeName][$templateName])) { $cachedValue = $this->_currentThemeNameToTemplateNameToThemeInstanceCache[$activeThemeName][$templateName]; if ($this->_shouldLog) { if ($cachedValue) { $this->_logDebug(sprintf('Theme for template <code>%s</code> was found in the cache to be contained in theme <code>%s</code> version <code>%s</code>. %s.', $templateName, $cachedValue->getName(), $cachedValue->getVersion(), $this->_loggerPostfix($activeTheme))); } else { $this->_logDebug(sprintf('We already tried to find a theme that contains <code>%s</code> in the theme hierarchy but didn\'t find it anywhere. %s.', $templateName, $this->_loggerPostfix($activeTheme))); } } return $cachedValue ? $cachedValue : null; } else { if ($this->_shouldLog) { $this->_logDebug(sprintf('Looks like this is the first time searching for a theme that contains <code>%s</code>. %s.', $templateName, $this->_loggerPostfix($activeTheme))); } } do { $activeThemeName = $activeTheme->getName(); if ($activeTheme->hasTemplateSource($templateName)) { if (!isset($this->_currentThemeNameToTemplateNameToThemeInstanceCache[$activeThemeName])) { $this->_currentThemeNameToTemplateNameToThemeInstanceCache[$activeThemeName] = array(); } $this->_currentThemeNameToTemplateNameToThemeInstanceCache[$activeThemeName][$templateName] = $activeTheme; if ($this->_shouldLog) { $this->_logDebug(sprintf('Template source for <code>%s</code> was found in theme <code>%s</code> version <code>%s</code>. %s.', $templateName, $activeThemeName, $activeTheme->getVersion(), $this->_loggerPostfix($activeTheme))); } return $activeTheme; } $nextThemeNameToCheck = $activeTheme->getParentThemeName(); if ($nextThemeNameToCheck === null) { break; } if ($this->_shouldLog) { $this->_logDebug(sprintf('Template source for <code>%s</code> was not found in theme <code>%s</code>. Now trying its parent theme: <code>%s</code>.', $templateName, $activeTheme->getName(), $nextThemeNameToCheck)); } try { $activeTheme = $this->_themeRegistry->getInstanceByName($nextThemeNameToCheck); } catch (InvalidArgumentException $e) { if ($this->_shouldLog) { $this->_logger->error(sprintf('Unable to get the theme instance for <code>%s</code>. This should never happen!', $nextThemeNameToCheck)); } break; } } while ($activeTheme !== null); if (!isset($this->_currentThemeNameToTemplateNameToThemeInstanceCache[$activeThemeName])) { $this->_currentThemeNameToTemplateNameToThemeInstanceCache[$activeThemeName] = array(); } $this->_currentThemeNameToTemplateNameToThemeInstanceCache[$activeThemeName][$templateName] = false; if ($this->_shouldLog) { $this->_logDebug(sprintf('Unable to find source of template <code>%s</code> from theme hierarchy.', $templateName)); } return null; }