/** * Method to get video info from Youtube * * @param string $file_url * * @return type */ public static function getVimeoVideoInfo($file_url) { if (empty($file_url)) { return NULL; } $api_url = 'http://vimeo.com/api/oembed.json?url=' . $file_url; $html = @JSNUtilsHttp::get($api_url); if ($html) { return $html['body']; } return false; }
public function DownloadToString() { if ($this->_url == '') { return false; } try { $content = JSNUtilsHttp::get($this->_url); return $content['body']; } catch (Exception $e) { echo 'Message:' . $e->getMessage(); return false; } }
/** * DEFINE shortcode content * * @param array $attributes * @param mixed $content * * @return string */ public function element_shortcode($attributes = null, $content = null) { extract(JSNPagebuilderHelpersShortcode::shortcodeAtts($this->config['params'], $attributes)); $queryString = "http://query.yahooapis.com/v1/public/yql?env=store://datatables.org/alltableswithkeys&format=json&q=select * from yahoo.finance.quotes where symbol in ('" . $attributes['market_item_symbol_code'] . "')"; try { $result = JSNUtilsHttp::get($queryString); $dataRaw = json_decode($result['body'], true); if (isset($dataRaw['error'])) { return "<!--separate-->"; } else { $dataItem['time_stamp'] = $dataRaw['query']['created']; $dataItem['data'] = $dataRaw['query']['results']['quote']; $dataItem['data']['name'] = $attributes['market_item_text']; } return json_encode($dataItem) . '<!--separate-->'; } catch (Exception $e) { $dataItem['error'] = $e->getMessage(); return json_encode($dataItem) . "<!--separate-->"; } }
/** * This task will be send list of editions to the client in JSON format. * * @return void */ public function editions() { // Initialize variables $input = JFactory::getApplication()->input; $jVer = new JVersion(); $info = JSNUtilsXml::loadManifestCache(); // Get product edition and identified name $edition = strtolower(JSNUtilsText::getConstant('EDITION')); $identified = ($identified = JSNUtilsText::getConstant('IDENTIFIED_NAME')) ? $identified : strtolower($info->name); // Build query string $query[] = 'joomla_version=' . urlencode($jVer->RELEASE); $query[] = 'username='******'customer_username')); $query[] = 'password='******'customer_password')); $query[] = 'identified_name=' . ($input->getCmd('id') ? urlencode($input->getCmd('id')) : urlencode($identified)); // Finalize link $url = str_replace('upgrade=yes', 'upgrade=no', JSN_EXT_DOWNLOAD_UPDATE_URL) . '&' . implode('&', $query); // Get results try { $result = JSNUtilsHttp::get($url); if (substr($result['body'], 0, 3) == 'ERR') { jexit(json_encode(array('message' => JText::_('JSN_EXTFW_LIGHTCART_ERROR_' . $result['body']), 'type' => 'error'))); } // JSON-decode the result $result = json_decode($result['body']); if (is_null($result)) { jexit(json_encode(array('message' => JText::_('JSN_EXTFW_VERSION_CHECK_FAIL'), 'type' => 'error'))); } if ($edition != 'free') { if (!in_array('PRO UNLIMITED', $result->editions)) { jexit(json_encode(array('message' => JText::sprintf('JSN_EXTFW_UPGRADE_YOUR_ACCOUNT_IS_NOT_PROVIDED_WITH_UNLIMITED_EDITION', JText::_($info->name) . ' PRO Unlimited'), 'type' => 'error'))); } $result->editions = array('PRO UNLIMITED'); } jexit(json_encode($result->editions)); } catch (Exception $e) { jexit(json_encode(array('message' => JText::_('JSN_EXTFW_VERSION_CHECK_FAIL'), 'type' => 'error'))); } }
public function download($options) { $this->setOptions($options); $url = $this->_downloadURL . $this->_getFields; try { $content = JSNUtilsHttp::get($url); if ($content) { if (!$this->_jarchiveZip->checkZipData($content['body'])) { $this->_msgError = (string) $content['body']; if (JFile::exists($this->_tmpPackagePath)) { JFile::delete($this->_tmpPackagePath); return false; } } else { JFile::write($this->_tmpPackagePath, $content['body']); return basename($this->_tmpPackagePath); } } return false; } catch (Exception $e) { return false; } }
/** * Communicate with JoomlaShine server for latest product version. * * If a product does not have sub-product, the <b>$products</b> parameter * does not required when calling this method: * * <pre>JSNUpdateHelper::check();</pre> * * Result will be returned in the following format: * * <pre>If product update is available: * <code>array( * 'identified_name' => object( * 'name' => 'The product name', * 'identified_name' => 'The product identification', * 'description' => 'The product description', * 'version' => 'The latest product version', * 'authentication' => 'Indicates whether authentication is required when updating product' * ) * )</code> * If the product does not have update: * <code>array( * 'identified_name' => false * )</code></pre> * * If a product has sub-product, this method need to be called as below to * check all sub-product for latest version: * * <pre>JSNUpdateHelper::check( * array( * // Core component * 'imageshow' => '4.2.0', * * // Themes * 'themeclassic' => '1.1.5', * 'themeslider' => '1.0.4', * 'themegrid' => '1.0.0', * * // Sources * 'picasa' => '1.1.2', * 'flickr' => '1.1.2', * 'phoca' => '1.0.1', * 'joomgallery' => '1.0.1', * 'rsgallery2' => '1.0.1', * 'facebook' => '1.0.1' * ) * );</pre> * * In this case, the returned result might look like below: * * <pre>array( * // Core component * 'imageshow' => object( * 'name' => 'JSN ImageShow', * 'identified_name' => 'imageshow', * 'description' => 'Something about JSN ImageShow', * 'version' => '4.3.0', * 'editions' => array( * 0 => object( * 'edition' => 'PRO STANDARD', * 'authentication' => 1 * ), * 1 => object( * 'edition' => 'PRO UNLIMITED', * 'authentication' => 1 * ), * 2 => object( * 'edition' => 'FREE', * 'authentication' => 0 * ) * ) * ), * * // Themes * 'themeclassic' => false, // Product update not available * 'themeslider' => false, // Product update not available * 'themegrid' => object( * 'name' => 'Theme Grid', * 'identified_name' => 'themegrid', * 'description' => 'JSN ImageShow Theme Grid plugin', * 'version' => '1.0.1', * 'edition' => 'FREE', * 'authentication' => 0 * ), * * // Sources * 'picasa' => false, // Product update not available * 'flickr' => false, // Product update not available * 'phoca' => false, // Product update not available * 'joomgallery' => false, // Product update not available * 'rsgallery2' => false, // Product update not available * 'facebook' => object( * 'name' => 'FaceBook', * 'identified_name' => 'facebook', * 'description' => 'JSN ImageShow Image Source Facebook plugin', * 'version' => '1.0.2', * 'edition' => 'FREE', * 'authentication' => 0 * ) * )</pre> * * @param array $products Array of identified name for checking latest version. * @param string $requiredJoomlaVersion Joomla version required by extension, e.g. 2.5, 3.0, etc. * @param array $latestUpdates Latest update response (for use in self recursive call only). * @param array $results Check update results (for use in self recursive call only). * * @return mixed */ public static function check($products = array(), $requiredJoomlaVersion = JSN_FRAMEWORK_REQUIRED_JOOMLA_VER, $latestUpdates = '', $results = '') { // Only communicate with server if check update URLs is not load before if (empty($latestUpdates)) { if (!isset(self::$versions)) { try { // Get Joomla config and input object $config = JFactory::getConfig(); $input = JFactory::getApplication()->input; // Generate cache file path $cache = $config->get('tmp_path') . '/JoomlaShineUpdates.json'; // Get current option and view $option = $input->getCmd('option'); $view = $input->getCmd('view'); // Get latest version from local file if not in about page or cache is not timed out if ((!in_array($option, JSNVersion::$products) or $view != 'about') and is_readable($cache) and time() - filemtime($cache) < CHECK_UPDATE_PERIOD) { // Decode JSON encoded update details self::$versions = json_decode(JFile::read($cache)); } else { // Always update cache file modification time is_writable($cache) and touch($cache, time()); // Communicate with JoomlaShine server via latest version checking URL try { self::$versions = JSNUtilsHttp::get(JSN_EXT_VERSION_CHECK_URL); self::$versions = isset(self::$versions['body']) ? self::$versions['body'] : '{"items":[]}'; // Cache latest version to local file system JFile::write($cache, self::$versions); // Decode JSON encoded update details self::$versions = json_decode(self::$versions); } catch (Exception $e) { throw $e; } } } catch (Exception $e) { throw new Exception(JText::_('JSN_EXTFW_VERSION_CHECK_FAIL')); } } $latestUpdates = self::$versions; } // Prepare product identification if (!is_array($products) or !count($products)) { is_array($products) or $products = array(); // Get the product info $version = JSNUtilsText::getConstant('VERSION'); // Is identified name defined? if ($const = JSNUtilsText::getConstant('IDENTIFIED_NAME')) { $products[$const] = $version; } else { $component = substr(JFactory::getApplication()->input->getCmd('option'), 4); $products[$component] = $version; $products['ext_' . $component] = $version; } } // Get Joomla version $joomlaVersion = new JVersion(); // Preset return results is_array($results) or $results = array(); // Get the latest product version foreach ($products as $product => $current) { if (!isset($results[$product])) { foreach ($latestUpdates->items as $item) { if (isset($item->items)) { $results = self::check(array($product => $current), $requiredJoomlaVersion, $item, $results); continue; } if (isset($item->identified_name) and $item->identified_name == $product) { $results[$product] = $item; break; } } // Does latest product info found? if (isset($results[$product]) and is_object($results[$product])) { // Does product support installed Joomla version? $tags = explode(';', $results[$product]->tags); if (!in_array($joomlaVersion->RELEASE, $tags)) { $results[$product] = false; } // Does product upgradable? if ($results[$product] and !empty($requiredJoomlaVersion) and !JSNVersion::isJoomlaCompatible($requiredJoomlaVersion) and !version_compare($results[$product]->version, $current, '>=')) { $results[$product] = false; } // Does product have newer version? if ($results[$product] and (empty($requiredJoomlaVersion) or JSNVersion::isJoomlaCompatible($requiredJoomlaVersion)) and !version_compare($results[$product]->version, $current, '>')) { $results[$product] = false; } } } } return $results; }
/** * Install sample data (step 1). * * @return boolean */ protected function installSampleStep1() { // Get Joomla config $config = JFactory::getConfig(); // Get URL to download sample data package $url = JFactory::getApplication()->input->getVar('sampleDownloadUrl'); // Set maximum execution time ini_set('max_execution_time', 300); // Try to download the sample data package try { $path = $config->get('tmp_path') . '/' . basename($url); if (!JSNUtilsHttp::get($url, $path, true)) { jexit('DOWNLOAD FAIL'); } } catch (Exception $e) { jexit('DOWNLOAD FAIL'); } // Complete AJAX based download task jexit('DONE: ' . trim(str_replace(JPATH_ROOT, '', $path), '/\\')); }
* * Websites: http://www.joomlashine.com * Technical Support: Feedback - http://www.joomlashine.com/contact-us/get-support.html */ // No direct access to this file defined('_JEXEC') or die('Restricted access'); // Initialize product info $name = preg_replace('/JSN\\s*/i', '', JText::_($info->name)); $edition = strtolower(JSNUtilsText::getConstant('EDITION')); $buyNow = JSNUtilsText::getConstant('BUY_LINK'); // Get input object $input = JFactory::getApplication()->input; // Get upgrade details from JoomlaShine server $response = null; try { $response = JSNUtilsHttp::get(JSN_EXT_UPGRADE_DETAILS_URL); $response = json_decode($response['body'], true); } catch (Exception $e) { // Do nothing } if ($response != null) { // Get response belonging to current extension if (isset($response[JSNUtilsText::getConstant('IDENTIFIED_NAME')])) { $response = $response[JSNUtilsText::getConstant('IDENTIFIED_NAME')]; } elseif (isset($response['extension'])) { $response = $response['extension']; } else { $response = $response['default']; } // Get current template edition $currentEdition = strcasecmp(JSNUtilsText::getConstant('EDITION'), 'free') == 0 ? 'free' : 'pro';
/** * Download update package for current product. * * @return void */ protected function downloadPackage() { // Get Joomla config $config = JFactory::getConfig(); // Initialize variable $input = JFactory::getApplication()->input; $JVersion = new JVersion(); // Get the product info $info = JSNUtilsXml::loadManifestCache(); $edition = $input->getVar('edition', JSNUtilsText::getConstant('EDITION')); $identified = ($identified = JSNUtilsText::getConstant('IDENTIFIED_NAME')) ? $identified : strtolower($info->name); // Build query string $query[] = 'joomla_version=' . $JVersion->RELEASE; $query[] = 'username='******'customer_username')); $query[] = 'password='******'customer_password')); $query[] = 'identified_name=' . ($input->getCmd('id') ? $input->getCmd('id') : $identified); $query[] = 'edition=' . strtolower(urlencode($edition)); // Build final URL for downloading update $url = JSN_EXT_DOWNLOAD_UPDATE_URL . '&' . implode('&', $query); // Generate file name for update package $name[] = 'jsn'; $name[] = $input->getCmd('id') ? $input->getCmd('id') : $identified; if ($edition) { $name[] = $input->getCmd('view') == 'upgrade' ? 'pro_' . (strtolower($edition) == 'free' ? 'standard' : 'unlimited') : strtolower(str_replace(' ', '_', $input->getVar('edition') ? $input->getVar('edition') : $edition)); } $name[] = 'j' . $JVersion->RELEASE; $name[] = 'install.zip'; $name = implode('_', $name); // Set maximum execution time ini_set('max_execution_time', 300); // Try to download the update package try { $path = $config->get('tmp_path') . '/' . $name; if (!JSNUtilsHttp::get($url, $path, true)) { throw new Exception(JText::_('JSN_EXTFW_UPDATE_DOWNLOAD_PACKAGE_FAIL')); } } catch (Exception $e) { throw new Exception(JText::_('JSN_EXTFW_UPDATE_DOWNLOAD_PACKAGE_FAIL')); } // Validate downloaded update package if (filesize($path) < 10) { // Get LightCart error code $errorCode = JFile::read($path); if ($edition) { $edition = $input->getCmd('view') == 'upgrade' ? 'pro ' . (strtolower($edition) == 'free' ? 'standard' : 'unlimited') : $input->getVar('edition') ? $input->getVar('edition') : $edition; } throw new Exception(JText::sprintf('JSN_EXTFW_LIGHTCART_ERROR_' . $errorCode, JText::_($info->name) . ' ' . strtoupper($edition))); } return $path; }
/** * Down load the sample data package * * @return string */ public function downloadSampleDataPackage() { ini_set('max_execution_time', 300); $sampleDownloadUrl = JFactory::getApplication()->input->getVar('sample_download_url'); $perm = true; $foldername = 'tmp'; $folderpath = JPATH_ROOT . DS . $foldername; $link = 'index.php?option=com_imageshow&view=maintenance&s=maintenance&g=data#data-sample-installation'; if (is_writable($folderpath)) { try { $objJSNDownloadPackage = JSNUtilsHttp::get($sampleDownloadUrl, $folderpath . DS . basename($sampleDownloadUrl)); if ($objJSNDownloadPackage) { echo json_encode(array('download' => true, 'file_name' => (string) basename($sampleDownloadUrl))); } else { $msg = JText::_('MAINTENANCE_SAMPLE_DATA_CANNOT_DOWNLOAD_INSTALLATION_FILE', true); echo json_encode(array('download' => false, 'message' => $msg, 'redirect_link' => $link)); } } catch (Exception $e) { $msg = JText::_('MAINTENANCE_SAMPLE_DATA_CANNOT_DOWNLOAD_INSTALLATION_FILE', true); echo json_encode(array('download' => false, 'message' => $msg, 'redirect_link' => $link)); } } else { $msg = JText::sprintf('MAINTENANCE_SAMPLE_DATA_FOLDER_MUST_HAVE_WRITABLE_PERMISSION', DS . 'tmp'); echo json_encode(array('download' => false, 'message' => $msg, 'redirect_link' => $link)); } exit; }
/** * @param bool $isForecast * @return bool|mixed|string */ public function fetchDataFromSource($isForecast = false) { $pathCache = JPATH_ROOT . "/tmp/"; if (!is_writable($pathCache)) { $dataArray['response']['error']['description'] = "tmp folder must be writable"; return json_encode($dataArray); } $cacheFile = $pathCache . "jsn_pb_" . md5($this->attributes['weather_location_code']); $cacheFile .= $isForecast ? "_forecast.json" : ".json"; if (!file_exists($cacheFile) || strtotime(date("Y-m-d", filemtime($cacheFile))) < strtotime(date("Y-m-d"))) { // Fetch new data $result = JSNUtilsHttp::get($this->getApiUrl($isForecast)); $resultContent = $result['body']; // Write cache JFile::write($cacheFile, $resultContent); } else { // Read cache $resultContent = file_get_contents($cacheFile); } // Return result return $resultContent; }
/** * Function to validate audio file * * @return string */ public function validateFile($url = null, $isAjax = true) { if (isset($url) && !empty($url)) { $file_url = $url; } else { $file_url = isset($_POST['file_url']) ? $_POST['file_url'] : ''; } // Default : weather $config = JSNConfigHelper::get('com_pagebuilder'); $soundCloudKey = $config->get('soundcloud_client_id'); if ($soundCloudKey == "") { if ($isAjax) { return false; } else { return array("valid" => false, "message" => "JSN_PAGEBUILDER_SOUNDCLOUD_CLIENT_ID_DOES_NOT_EXIST"); } } // $soundCloudKey = "0b237e55b145e6967548c14f1ec7d494"; $api_url = 'http://api.soundcloud.com/resolve.json?url=' . $file_url . '&client_id=' . $soundCloudKey; $get_contents = JSNUtilsHttp::get($api_url); $html = $get_contents['body']; if ($html && strpos($html, 'error') === false) { $data = array(); $data['type'] = ''; $content = ''; $res = @simplexml_load_string($html); if ((string) @$res->kind === 'user') { $content .= 'Username' . ': <b>' . (string) $res->username . '</b><br>'; $content .= 'Country' . ': <b>' . (string) $res->country . '</b><br>'; $content .= 'Full Name' . ' : <b>' . (string) $res->{'full-name'} . '</b><br>'; $content .= 'Description' . ' : <b>' . (string) $res->description . '</b><br>'; $data['type'] = 'list'; } else { if ((string) @$res->kind === 'track') { // Render Duration displaying $_duration = $res->duration; $_seconds = round($_duration / 1000); $_minutes = round($_seconds / 60); $_hours = round($_seconds / 3600); $_odd_sec = $_seconds - $_minutes * 60; $_duration_str = ''; if ($_hours >= 1 && $_hours < 10) { $_duration_str .= '0' . $_hours . ':'; } else { if ($_hours >= 10) { $_duration_str .= $_hours . ':'; } } if ($_minutes >= 1 && $_minutes < 10) { $_duration_str .= '0' . $_minutes . ':'; } else { if ($_minutes >= 10) { $_duration_str .= $_minutes . ':'; } else { $_duration_str .= '00:'; } } if ($_odd_sec >= 1 && $_odd_sec < 10) { $_duration_str .= '0' . $_odd_sec; } else { if ($_minutes >= 10) { $_duration_str .= $_odd_sec; } else { $_duration_str .= '00'; } } $content .= 'Title' . ': <b>' . (string) $res->title . '</b><br>'; $content .= 'Genre' . ': <b>' . (string) $res->genre . '</b><br>'; $content .= 'User' . ' : <b>' . (string) $res->user->username . '</b><br>'; $content .= 'Format' . ' : <b>' . (string) $res->{'original-format'} . '</b><br>'; $content .= 'Duration' . ' : <b>' . (string) $_duration_str . '</b><br>'; } else { if ((string) @$res->kind === 'playlist') { $_duration = $res->duration; $_seconds = round($_duration / 1000); $_minutes = round($_seconds / 60); $_hours = round($_seconds / 3600); $_odd_sec = $_seconds - $_minutes * 60; $_duration_str = ''; if ($_hours >= 1 && $_hours < 10) { $_duration_str .= '0' . $_hours . ':'; } else { if ($_hours >= 10) { $_duration_str .= $_hours . ':'; } } if ($_minutes >= 1 && $_minutes < 10) { $_duration_str .= '0' . $_minutes . ':'; } else { if ($_minutes >= 10) { $_duration_str .= $_minutes . ':'; } else { $_duration_str .= '00:'; } } if ($_odd_sec >= 1 && $_odd_sec < 10) { $_duration_str .= '0' . $_odd_sec; } else { if ($_minutes >= 10) { $_duration_str .= $_odd_sec; } else { $_duration_str .= '00'; } } $content .= 'Title' . ': <b>' . (string) $res->title . '</b><br>'; $content .= 'Username' . ' : <b>' . (string) $res->user->username . '</b><br>'; $content .= 'Duration' . ' : <b>' . (string) $_duration_str . '</b><br>'; $res->description = JSNPagebuilderHelpersShortcode::pbTrimWords((string) $res->description, 20); $content .= 'Description' . ' : <b>' . $res->description . '</b><br>'; $data['type'] = 'list'; } } } $data['content'] = $content; if ($isAjax) { exit(json_encode($data)); } else { return array("valid" => true, "message" => "Success"); } } if ($isAjax) { exit('false'); } else { return array("valid" => true, "message" => "Invalid URL"); } }