/** * Applied to a single option name/value pair before it is applied to TubePress's execution context * or persistence storage. This filter is invoked *before* the option name or value is validated! * * @param string $value The option value being set. * @param string $name The name of the option being set. * * @return unknown_type The (possibly modified) option value. May be null. * * function alter_preValidationOptionSet($value, $name); */ public function alter_preValidationOptionSet($value, $name) { /** We only care about playlistValue. */ if ($name !== org_tubepress_api_const_options_names_GallerySource::YOUTUBE_PLAYLIST_VALUE) { return $value; } if (org_tubepress_impl_util_StringUtils::startsWith($value, 'PL')) { org_tubepress_impl_log_Log::log(self::$_logPrefix, 'Removing \'PL\' prefix from playlist value of %s', $value); return org_tubepress_impl_util_StringUtils::replaceFirst('PL', '', $value); } org_tubepress_impl_log_Log::log(self::$_logPrefix, 'Playlist value %s does not beging with \'PL\'', $value); return $value; }
/** * Does the heavy lifting of generating videos/galleries from content. * * @param string $content The WordPress content. * @param string $trigger The shortcode keyword * * @return string The modified content. */ private static function _getHtml($content, $trigger, $parser, $ioc) { $ms = $ioc->get(org_tubepress_api_message_MessageService::_); $context = $ioc->get(org_tubepress_api_exec_ExecutionContext::_); $gallery = $ioc->get(org_tubepress_api_shortcode_ShortcodeHtmlGenerator::_); /* Parse each shortcode one at a time */ while ($parser->somethingToParse($content, $trigger)) { /* Get the HTML for this particular shortcode. Could be a single video or a gallery. */ try { $generatedHtml = $gallery->getHtmlForShortcode($content); } catch (Exception $e) { $generatedHtml = $e->getMessage(); } /* remove any leading/trailing <p> tags from the content */ $pattern = '/(<[P|p]>\\s*)(' . preg_quote($context->getActualShortcodeUsed(), '/') . ')(\\s*<\\/[P|p]>)/'; $content = preg_replace($pattern, '${2}', $content); /* replace the shortcode with our new content */ $currentShortcode = $context->getActualShortcodeUsed(); $content = org_tubepress_impl_util_StringUtils::replaceFirst($currentShortcode, $generatedHtml, $content); /* reset the context for the next shortcode */ $context->reset(); } return $content; }
function testCanReplaceFirstOnlyFirstOccurence() { $this->assertEquals("zxx", org_tubepress_impl_util_StringUtils::replaceFirst("x", "z", "xxx")); }