예제 #1
0
 /**
  * Parse the URL of video service
  *
  * <code>
  * $url = "http://youtube.com/...";
  *
  * $video = new Prism\Video\Embed($url);
  * $video->parse();
  *
  * </code>
  */
 public function parse()
 {
     $uri = new \JUri($this->url);
     $host = $uri->getHost();
     // Youtube
     if (false !== strpos($host, 'youtu') and preg_match($this->patternYouTube, $this->url, $matches)) {
         $this->code = $matches[0];
         $this->service = 'youtube';
         return;
     }
     // Vimeo
     if (false !== strpos($host, 'vimeo') and preg_match($this->patternVimeo, $this->url, $matches)) {
         $this->code = $matches[5];
         $this->service = 'vimeo';
         return;
     }
 }
예제 #2
0
 /**
  * Parse the URL of video service
  *
  * <code>
  * $url = "http://youtube.com/...";
  *
  * $video = new ITPrismVideoEmbed($url);
  * $video->parse();
  *
  * </code>
  */
 public function parse()
 {
     $uri = new JUri($this->url);
     $host = $uri->getHost();
     // Youtube
     if (false !== strpos($host, "youtu")) {
         if (preg_match($this->patternYouTube, $this->url, $matches)) {
             $this->code = $matches[0];
             $this->service = "youtube";
             return;
         }
     }
     // Vimeo
     if (false !== strpos($host, "vimeo")) {
         if (preg_match($this->patternVimeo, $this->url, $matches)) {
             $this->code = $matches[5];
             $this->service = "vimeo";
             return;
         }
     }
 }
예제 #3
0
파일: socket.php 프로젝트: grlf/eyedock
 /**
  * Method to connect to a server and get the resource.
  *
  * @param   JUri     $uri      The URI to connect with.
  * @param   integer  $timeout  Read timeout in seconds.
  *
  * @return  resource  Socket connection resource.
  *
  * @since   11.3
  * @throws  RuntimeException
  */
 protected function connect(JUri $uri, $timeout = null)
 {
     $errno = null;
     $err = null;
     // Get the host from the uri.
     $host = $uri->isSsl() ? 'ssl://' . $uri->getHost() : $uri->getHost();
     // If the port is not explicitly set in the URI detect it.
     if (!$uri->getPort()) {
         $port = $uri->getScheme() == 'https' ? 443 : 80;
     } else {
         $port = $uri->getPort();
     }
     // Build the connection key for resource memory caching.
     $key = md5($host . $port);
     // If the connection already exists, use it.
     if (!empty($this->connections[$key]) && is_resource($this->connections[$key])) {
         // Connection reached EOF, cannot be used anymore
         $meta = stream_get_meta_data($this->connections[$key]);
         if ($meta['eof']) {
             if (!fclose($this->connections[$key])) {
                 throw new RuntimeException('Cannot close connection');
             }
         } elseif (!$meta['timed_out']) {
             return $this->connections[$key];
         }
     }
     if (!is_numeric($timeout)) {
         $timeout = ini_get('default_socket_timeout');
     }
     // Capture PHP errors
     $php_errormsg = '';
     $track_errors = ini_get('track_errors');
     ini_set('track_errors', true);
     // PHP sends a warning if the uri does not exists; we silence it and throw an exception instead.
     // Attempt to connect to the server
     $connection = @fsockopen($host, $port, $errno, $err, $timeout);
     if (!$connection) {
         if (!$php_errormsg) {
             // Error but nothing from php? Create our own
             $php_errormsg = sprintf('Could not connect to resource: %s', $uri, $err, $errno);
         }
         // Restore error tracking to give control to the exception handler
         ini_set('track_errors', $track_errors);
         throw new RuntimeException($php_errormsg);
     }
     // Restore error tracking to what it was before.
     ini_set('track_errors', $track_errors);
     // Since the connection was successful let's store it in case we need to use it later.
     $this->connections[$key] = $connection;
     // If an explicit timeout is set, set it.
     if (isset($timeout)) {
         stream_set_timeout($this->connections[$key], (int) $timeout);
     }
     return $this->connections[$key];
 }
예제 #4
0
파일: http.php 프로젝트: carmerin/cesae-web
 /**
  * Method to connect to a server and get the resource.
  *
  * @param   JUri   $uri  The URI to connect with.
  *
  * @return  mixed  Connection resource on success or boolean false on failure.
  *
  * @since   11.1
  */
 protected function _connect(JUri $uri)
 {
     // Initialize variables.
     $errno = null;
     $err = null;
     // Get the host from the uri.
     $host = $uri->isSSL() ? 'ssl://' . $uri->getHost() : $uri->getHost();
     // If the port is not explicitly set in the URI detect it.
     if (!$uri->getPort()) {
         $port = $uri->getScheme() == 'https' ? 443 : 80;
     } else {
         $port = $uri->getPort();
     }
     // Build the connection key for resource memory caching.
     $key = md5($host . $port);
     // If the connection already exists, use it.
     if (!empty($this->_connections[$key]) && is_resource($this->_connections[$key])) {
         // Make sure the connection has not timed out.
         $meta = stream_get_meta_data($this->_connections[$key]);
         if (!$meta['timed_out']) {
             return $this->_connections[$key];
         }
     }
     // Attempt to connect to the server.
     if ($this->_connections[$key] = fsockopen($host, $port, $errno, $err, $this->_timeout)) {
         stream_set_timeout($this->_connections[$key], $this->_timeout);
     }
     return $this->_connections[$key];
 }
예제 #5
0
파일: socket.php 프로젝트: exntu/joomla-cms
 /**
  * Method to connect to a server and get the resource.
  *
  * @param   JUri     $uri      The URI to connect with.
  * @param   integer  $timeout  Read timeout in seconds.
  *
  * @return  resource  Socket connection resource.
  *
  * @since   11.3
  * @throws  RuntimeException
  */
 protected function connect(JUri $uri, $timeout = null)
 {
     // Initialize variables.
     $errno = null;
     $err = null;
     // Get the host from the uri.
     $host = $uri->isSSL() ? 'ssl://' . $uri->getHost() : $uri->getHost();
     // If the port is not explicitly set in the URI detect it.
     if (!$uri->getPort()) {
         $port = $uri->getScheme() == 'https' ? 443 : 80;
     } else {
         $port = $uri->getPort();
     }
     // Build the connection key for resource memory caching.
     $key = md5($host . $port);
     // If the connection already exists, use it.
     if (!empty($this->connections[$key]) && is_resource($this->connections[$key])) {
         // Connection reached EOF, cannot be used anymore
         $meta = stream_get_meta_data($this->connections[$key]);
         if ($meta['eof']) {
             if (!fclose($this->connections[$key])) {
                 throw new RuntimeException('Cannot close connection');
             }
         } elseif (!$meta['timed_out']) {
             return $this->connections[$key];
         }
     }
     if (!is_numeric($timeout)) {
         $timeout = ini_get("default_socket_timeout");
     }
     // Attempt to connect to the server.
     $connection = fsockopen($host, $port, $errno, $err, $timeout);
     if (!$connection) {
         throw new RuntimeException($err, $errno);
     }
     // Since the connection was successful let's store it in case we need to use it later.
     $this->connections[$key] = $connection;
     // If an explicit timeout is set, set it.
     if (isset($timeout)) {
         stream_set_timeout($this->connections[$key], (int) $timeout);
     }
     return $this->connections[$key];
 }
예제 #6
0
 /**
  * Get the origin image path, if is a remote image, will store in temp dir first.
  *
  * @param   string $url  The image URL.
  * @param   string $hash Not available now..
  *
  * @return  string  Image path.
  */
 public function getImagePath($url, $hash = null)
 {
     $self = \JUri::getInstance();
     $url = new \JUri($url);
     // Is same host?
     if ($self->getHost() == $url->getHost()) {
         $url = $url->toString();
         $path = str_replace(\JURI::root(), JPATH_ROOT . '/', $url);
         $path = \JPath::clean($path);
     } elseif (!$url->getHost()) {
         $url = $url->toString();
         $path = \JPath::clean(JPATH_ROOT . '/' . $url);
     } else {
         $handler = $this->hashHandler;
         $path = $this->config['path.temp'] . '/' . $handler(basename($url)) . '.jpg';
         if (!is_file($path)) {
             CurlHelper::download((string) $url, $path);
         }
     }
     return $path;
 }
 /**
  * Test the setHost method.
  *
  * @return  void
  *
  * @since   11.1
  * @covers  JUri::setHost
  */
 public function testSetHost()
 {
     $this->object->setHost('www.example.org');
     $this->assertThat($this->object->getHost(), $this->equalTo('www.example.org'));
 }
예제 #8
0
 function onAfterInitialise()
 {
     /** @var JSite $app */
     $app = JFactory::getApplication();
     if ($app->isAdmin()) {
         // don't use MobileJoomla in backend
         return;
     }
     $is_joomla15 = $this->isJoomla15();
     //load MobileJoomla class
     require_once JPATH_ADMINISTRATOR . '/components/com_mobilejoomla/classes/mobilejoomla.php';
     //load config
     $MobileJoomla_Settings =& MobileJoomla::getConfig();
     $MobileJoomla_Device =& MobileJoomla::getDevice();
     // check for legacy redirect
     if (@$_GET['option'] == 'com_mobilejoomla' && @$_GET['task'] == 'setmarkup' && isset($_GET['markup']) && isset($_GET['return'])) {
         $desktop_uri = new JUri($MobileJoomla_Settings['desktop_url']);
         $uri = new JUri(base64_decode($_GET['return']));
         if (!$uri->getScheme()) {
             $uri->setScheme('http');
         }
         $uri->setHost($desktop_uri->getHost());
         $uri->setPort($desktop_uri->getPort());
         $app->redirect($uri->toString());
     }
     JPluginHelper::importPlugin('mobile');
     $cached_data = $app->getUserState('mobilejoomla.cache');
     if ($cached_data !== null) {
         $cached_data = @gzinflate(@base64_decode($cached_data));
         if ($cached_data !== false) {
             $cached_data = @unserialize($cached_data);
         }
     }
     if (is_array($cached_data)) {
         $MobileJoomla_Device = $cached_data['device'];
     } else {
         $app->triggerEvent('onDeviceDetection', array(&$MobileJoomla_Settings, &$MobileJoomla_Device));
         $gzlevel = 5;
         $cached_data = array('device' => $MobileJoomla_Device);
         $cached_data = base64_encode(gzdeflate(serialize($cached_data), $gzlevel));
         $app->setUserState('mobilejoomla.cache', $cached_data);
     }
     $MobileJoomla_Device['markup'] = self::CheckMarkup($MobileJoomla_Device['markup']);
     $MobileJoomla_Device['real_markup'] = $MobileJoomla_Device['markup'];
     $app->triggerEvent('onAfterDeviceDetection', array(&$MobileJoomla_Settings, &$MobileJoomla_Device));
     $MobileJoomla_Device['markup'] = self::CheckMarkup($MobileJoomla_Device['markup']);
     $markup = $MobileJoomla_Device['markup'];
     $MobileJoomla_Device['default_markup'] = $markup;
     //get user choice
     $user_markup = $this->getUserMarkup();
     if ($user_markup !== false) {
         $markup = $user_markup;
     }
     // template preview
     $getTemplate = isset($_GET['template']) ? $_GET['template'] : null;
     if (version_compare(JVERSION, '1.7', '>=')) {
         if ($getTemplate === null && isset($_GET['templateStyle']) && is_int($_GET['templateStyle'])) {
             $db = JFactory::getDBO();
             $query = 'SELECT template FROM #__template_styles WHERE id = ' . intval($_GET['templateStyle']) . ' AND client_id = 0';
             $db->setQuery($query);
             $getTemplate = $db->loadResult();
         }
     } elseif (version_compare(JVERSION, '1.6', '>=')) {
         if (is_int($getTemplate)) {
             $db = JFactory::getDBO();
             $query = 'SELECT template FROM #__template_styles WHERE id = ' . intval($getTemplate) . ' AND client_id = 0';
             $db->setQuery($query);
             $getTemplate = $db->loadResult();
         }
     }
     if ($getTemplate) {
         switch ($getTemplate) {
             case $MobileJoomla_Settings['xhtml.template']:
                 $markup = 'xhtml';
                 break;
             case $MobileJoomla_Settings['iphone.template']:
                 $markup = 'iphone';
                 break;
             case $MobileJoomla_Settings['wml.template']:
                 $markup = 'wml';
                 break;
             case $MobileJoomla_Settings['chtml.template']:
                 $markup = 'chtml';
                 break;
         }
     }
     $MobileJoomla_Device['markup'] = $markup;
     if ($MobileJoomla_Device['screenwidth'] == 0 || $MobileJoomla_Device['screenheight'] == 0) {
         switch ($markup) {
             case 'wml':
                 $MobileJoomla_Device['screenwidth'] = 64;
                 $MobileJoomla_Device['screenheight'] = 96;
                 break;
             case 'chtml':
                 $MobileJoomla_Device['screenwidth'] = 120;
                 $MobileJoomla_Device['screenheight'] = 128;
                 break;
             case 'xhtml':
                 $MobileJoomla_Device['screenwidth'] = 320;
                 $MobileJoomla_Device['screenheight'] = 480;
                 break;
             case 'iphone':
                 $MobileJoomla_Device['screenwidth'] = 320;
                 $MobileJoomla_Device['screenheight'] = 480;
                 break;
         }
     }
     if ($MobileJoomla_Device['imageformats'] === null) {
         switch ($markup) {
             case 'wml':
                 $MobileJoomla_Device['imageformats'] = array('wbmp');
                 break;
             case 'chtml':
                 $MobileJoomla_Device['imageformats'] = array('gif');
                 break;
             case 'xhtml':
             case 'iphone':
                 $MobileJoomla_Device['imageformats'] = array('png', 'gif', 'jpg');
                 break;
         }
     }
     if (count($MobileJoomla_Device['imageformats']) == 0) {
         $MobileJoomla_Settings['wml.img'] = 1;
         $MobileJoomla_Settings['chtml.img'] = 1;
         $MobileJoomla_Settings['xhtml.img'] = 1;
         $MobileJoomla_Settings['iphone.img'] = 1;
     }
     $app->triggerEvent('onBeforeMobileMarkupInit', array(&$MobileJoomla_Settings, &$MobileJoomla_Device));
     $MobileJoomla_Device['markup'] = self::CheckMarkup($MobileJoomla_Device['markup']);
     $this->updateUserMarkup();
     $app->triggerEvent('onMobileMarkupInit', array(&$MobileJoomla_Settings, &$MobileJoomla_Device));
     $markup = $MobileJoomla_Device['markup'];
     if (empty($markup)) {
         $MobileJoomla_Device['markup'] = false;
         return;
     }
     $MobileJoomla = MobileJoomla::getInstance($markup);
     // set headers here to be compatible with System-Cache
     $MobileJoomla->setHeader();
     if ($MobileJoomla_Settings['mobile_sitename']) {
         $this->setConfig('sitename', $MobileJoomla_Settings['mobile_sitename']);
     }
     if (!$is_joomla15) {
         if (!$MobileJoomla_Settings['caching']) {
             $this->setConfig('caching', 0);
         }
         $cachekey = MobileJoomla::getCacheKey();
         $registeredurlparams = isset($app->registeredurlparams) ? $app->registeredurlparams : null;
         if (empty($registeredurlparams)) {
             $registeredurlparams = new stdClass();
         }
         $this->setRequestVar('mjcachekey', $cachekey);
         $registeredurlparams->mjcachekey = 'CMD';
         $this->setRequestVar('mjurlkey', JRequest::getURI());
         $registeredurlparams->mjurlkey = 'STRING';
         $app->registeredurlparams = $registeredurlparams;
         //fix System-Cache plugin in J!3.0
         if (JPluginHelper::isEnabled('system', 'cache') && version_compare(JVERSION, '3.0.0', '>=')) {
             $dispatcher = JEventDispatcher::getInstance();
             $refObj = new ReflectionObject($dispatcher);
             $refProp = $refObj->getProperty('_observers');
             $refProp->setAccessible(true);
             $observers = $refProp->getValue($dispatcher);
             foreach ($observers as $index => $object) {
                 if (is_a($object, 'plgSystemCache')) {
                     $object->_cache_key = '~' . $cachekey . '~' . $object->_cache_key;
                 }
             }
         }
     } else {
         if ($MobileJoomla_Settings['caching']) {
             /** @var JRegistry $config */
             $config = JFactory::getConfig();
             $handler = $config->getValue('config.cache_handler', 'file');
             $handler .= '_mj';
             $config->setValue('config.cache_handler', $handler);
             $class = 'JCacheStorage' . ucfirst($handler);
             $path = JPATH_ADMINISTRATOR . '/components/com_mobilejoomla/override/cachestorage/' . $handler . '.php';
             jimport('joomla.cache.storage');
             JLoader::register($class, $path);
         } else {
             $this->setConfig('caching', 0);
             //disable System-Cache plugin
             $dispatcher = JDispatcher::getInstance();
             foreach ($dispatcher->_observers as $index => $object) {
                 if (is_a($object, 'plgSystemCache')) {
                     $object->_cache = new _CacheStub();
                     unset($dispatcher->_observers[$index]);
                     break;
                 }
             }
         }
     }
     if (@$_SERVER['REQUEST_METHOD'] != 'POST') {
         $router = $app->getRouter();
         $router->attachBuildRule(array($this, 'buildRule'));
     }
     if (!defined('SHMOBILE_MOBILE_TEMPLATE_SWITCHED')) {
         define('SHMOBILE_MOBILE_TEMPLATE_SWITCHED', 1);
     }
 }
예제 #9
0
 /**
  * Method to connect to a server and get the resource.
  *
  * @param   JUri     $uri      The URI to connect with.
  * @param   integer  $timeout  Read timeout in seconds.
  *
  * @return  resource  Socket connection resource.
  *
  * @since   11.3
  * @throws  JMapExceptionRuntime
  */
 protected function connect(JUri $uri, $timeout = null)
 {
     // Initialize variables.
     $errno = null;
     $err = null;
     // Get the host from the uri.
     $host = $uri->isSSL() ? 'ssl://' . $uri->getHost() : $uri->getHost();
     // If the port is not explicitly set in the URI detect it.
     if (!$uri->getPort()) {
         $port = $uri->getScheme() == 'https' ? 443 : 80;
     } else {
         $port = $uri->getPort();
     }
     // Build the connection key for resource memory caching.
     $key = md5($host . $port);
     // If the connection already exists, use it.
     if (!empty($this->connections[$key]) && is_resource($this->connections[$key])) {
         // Make sure the connection has not timed out.
         $meta = stream_get_meta_data($this->connections[$key]);
         if (!$meta['timed_out']) {
             return $this->connections[$key];
         }
     }
     // Attempt to connect to the server.
     $connection = @fsockopen($host, $port, $errno, $err, $timeout);
     if (!$connection) {
         throw new JMapExceptionRuntime($err, 'error', $errno);
     }
     // Since the connection was successful let's store it in case we need to use it later.
     $this->connections[$key] = $connection;
     // If an explicit timeout is set, set it.
     if (isset($timeout)) {
         stream_set_timeout($this->connections[$key], (int) $timeout);
     }
     return $this->connections[$key];
 }
예제 #10
0
 /**
  * Give a relative path, return path with host.
  *
  * @param   string $path A system path.
  *
  * @return  string  Path with host added.
  */
 public static function pathAddHost($path)
 {
     if (!$path) {
         return '';
     }
     // Build path
     $uri = new \JUri($path);
     if ($uri->getHost()) {
         return $path;
     }
     $uri->parse(\JUri::root());
     $root_path = $uri->getPath();
     if (strpos($path, $root_path) === 0) {
         $num = Utf8String::strlen($root_path);
         $path = Utf8String::substr($path, $num);
     }
     $uri->setPath($uri->getPath() . $path);
     $uri->setScheme('http');
     $uri->setQuery(null);
     return $uri->toString();
 }
예제 #11
0
 static function getCanonicalURI()
 {
     jimport('joomla.environment.uri');
     $MobileJoomla_Device =& MobileJoomla::getDevice();
     $MobileJoomla_Settings =& MobileJoomla::getConfig();
     $desktop_uri = new JUri($MobileJoomla_Settings['desktop_url']);
     $uri = clone JUri::getInstance();
     $uri_host = preg_replace('#^www\\.#', '', $uri->getHost());
     $desktop_host = preg_replace('#^www\\.#', '', $desktop_uri->getHost());
     if ($uri_host == $desktop_host && $MobileJoomla_Device['markup'] == $MobileJoomla_Device['default_markup']) {
         return false;
     }
     $uri->delVar('device');
     $uri->delVar('format');
     $uri->setHost($desktop_uri->getHost());
     return htmlspecialchars($uri->toString());
 }