private function _enqueueThemeResources(tubepress_wordpress_impl_wp_WpFunctions $wpFunctions, tubepress_api_version_Version $version) { $callback = array($this, '__callbackConvertToWpUrlString'); $stylesUrls = $this->_htmlGenerator->getUrlsCSS(); $scriptsUrls = $this->_htmlGenerator->getUrlsJS(); $stylesStrings = array_map($callback, $stylesUrls); $scriptsStrings = array_map($callback, $scriptsUrls); $styleCount = count($stylesStrings); $scriptCount = count($scriptsStrings); for ($x = 0; $x < $styleCount; $x++) { $handle = 'tubepress-theme-' . $x; $wpFunctions->wp_register_style($handle, $stylesStrings[$x], array(), "{$version}"); $wpFunctions->wp_enqueue_style($handle); } for ($x = 0; $x < $scriptCount; $x++) { if ($this->_stringUtils->endsWith($scriptsStrings[$x], '/web/js/tubepress.js')) { $handle = 'tubepress'; $deps = array(); } else { $handle = 'tubepress-theme-' . $x; $deps = array('tubepress'); } $wpFunctions->wp_register_script($handle, $scriptsStrings[$x], $deps, "{$version}"); $wpFunctions->wp_enqueue_script($handle, false, array(), false, false); } }
/** * {@inheritdoc} */ public function rfc3339toUnixTime($rfcTime) { $tmp = str_replace('T', ' ', $rfcTime); $tmp = preg_replace('/(\\.[0-9]{1,})?/', '', $tmp); $datetime = substr($tmp, 0, 19); if ($this->_stringUtils->endsWith($tmp, 'Z')) { $reset = date_default_timezone_get(); date_default_timezone_set('UTC'); $toReturn = strtotime($datetime); date_default_timezone_set($reset); return $toReturn; } $timezone = str_replace(':', '', substr($tmp, 19, 6)); return strtotime($datetime . ' ' . $timezone); }
public function onFilter_jetpack_photon_skip_for_url(tubepress_api_event_EventInterface $event) { $args = $event->getArgument('args'); $imageUrl = $args[0]; try { $imageUrl = $this->_urlFactory->fromString($imageUrl); } catch (\InvalidArgumentException $e) { return; } $imageHost = $imageUrl->getHost(); foreach ($this->_domainsToSearch as $domain) { if ($imageHost === "{$domain}" || $this->_stringUtils->endsWith($imageHost, ".{$domain}")) { $event->setSubject(true); return; } } }
public function transform($incoming) { if ($this->_looksLikeDailymotionUser($incoming)) { //looks like a valid user idn return $incoming; } $incoming = trim($incoming, '/'); /* * Might be * * 1. http://www.dailymotion.com/user/foobar/1 * 2. http://www.dailymotion.com/user/foobar * 3. http://www.dailymotion.com/foobar */ try { $url = $this->_urlFactory->fromString($incoming); $host = $url->getHost(); if (!$this->_stringUtils->endsWith($host, 'dailymotion.com')) { return null; } $pathSegments = $url->getPathSegments(); $pathCount = count($pathSegments); if ($pathCount < 2) { return null; } if ($pathCount > 2 && $pathSegments[1] !== 'user') { return null; } if ($pathCount > 2) { $user = $pathSegments[2]; } else { $user = $pathSegments[1]; } $error = $user === 'user' || !$this->_looksLikeDailymotionUser($user); if ($error) { return null; } return $user; } catch (InvalidArgumentException $e) { //invalid URL return null; } }
public function transform($incoming) { if ($this->_looksLikeDailymotionVideoId($incoming)) { //looks like a valid video ID return $incoming; } // x2xv8yy_description if (preg_match_all('~^[a-z0-9]+_.+$~', $incoming, $matches) === 1) { $exploded = explode('_', $incoming); return $exploded[0]; } $incoming = trim($incoming, '/'); /* * Might be * * 1. http://www.dailymotion.com/video/videoid * 2. http://www.dailymotion.com/video/videoid_description */ try { $url = $this->_urlFactory->fromString($incoming); $host = $url->getHost(); $path = $url->getPath(); if (!$this->_stringUtils->endsWith($host, 'dailymotion.com')) { return null; } if (!$this->_stringUtils->startsWith($path, '/video/') && !$this->_stringUtils->startsWith($path, '/hub/')) { return null; } $one = 1; $path = str_replace(array('/video/', '/hub/'), '', $path, $one); $exploded = explode('_', $path); $videoId = $exploded[0]; $error = !$this->_looksLikeDailymotionVideoId($videoId); if ($error) { return null; } return $videoId; } catch (InvalidArgumentException $e) { //invalid URL return null; } }
private function _toRealScreenshotUrl($candidate) { $realUrl = $this->toUrl($candidate); if (!$realUrl) { return $realUrl; } $path = $realUrl->getPath(); if (!$this->_stringUtils->endsWith($path, '.png') && !$this->_stringUtils->endsWith($path, '.jpg')) { return null; } return $realUrl; }
private function _maybeConvertUrl($originalValue, $pathSegment) { $url = null; try { $url = $this->_urlFactory->fromString($originalValue); } catch (Exception $e) { return $originalValue; } $host = $url->getHost(); if (!$this->_stringUtils->endsWith($host, 'vimeo.com')) { return $originalValue; } $path = $url->getPath(); $pathStartsWithSegment = $this->_stringUtils->startsWith($path, '/' . $pathSegment); if (!$pathStartsWithSegment) { return $originalValue; } $explodedPath = preg_split('~/~', $path); if (count($explodedPath) < 3) { return $originalValue; } return $explodedPath[2]; }
private function _maybeGetPlaylistValueFromUrl($originalValue) { $url = null; try { $url = $this->_urlFactory->fromString($originalValue); } catch (Exception $e) { return $originalValue; } $host = $url->getHost(); if (!$this->_stringUtils->endsWith($host, 'youtube.com')) { return $originalValue; } $params = $url->getQuery(); if (!$params->hasKey('list') && !$params->hasKey('p')) { return $originalValue; } if ($params->hasKey('list')) { return $params->get('list'); } return $params->get('p'); }