/**
  * Fetch an http file from the URL
  *
  * @param  string  $url    URL from where to fetch
  * @return string          content, or NULL in case of error
  */
 private function _fetch_http_file($url)
 {
     cbimport('cb.snoopy');
     $s = new CBSnoopy();
     $s->read_timeout = 20;
     @$s->fetch($url);
     if ($s->error || $s->status != 200) {
         // echo '<font color="red">Connection to update server failed: ERROR: ' . $s->error . ($s->status == -100 ? 'Timeout' : $s->status).'</font>';
         $content = null;
     } else {
         $content = $s->results;
     }
     return $content;
 }
Exemplo n.º 2
0
 /**
  * returns plugins xml version
  *
  * @param  null|PluginTable|int  $plugin    The plugin id or object to check version for
  * @param  bool                  $raw       1/True: version only (no farm), 0/False: Formatted version (green/red/shortened), 2: array of version information ( $version, $latestVersion, $isLatest, $latestURL )
  * @param  int                   $duration  The duration to cache the plugin version xml file (null/0 for no limit)
  * @param  int                   $length    The maximum version length to display (null/0 for no limit)
  * @return null|string
  */
 public function getPluginVersion($plugin, $raw = false, $duration = 24, $length = 0)
 {
     global $_CB_framework, $ueConfig;
     cbimport('cb.snoopy');
     static $plgVersions = null;
     if ($plgVersions === null) {
         $cacheFile = $_CB_framework->getCfg('absolute_path') . '/cache/cbpluginsversions.xml';
         $plgVersionsXML = null;
         if (file_exists($cacheFile)) {
             if (!$duration || intval(($_CB_framework->now() - filemtime($cacheFile)) / 3600) > $duration) {
                 $request = true;
             } else {
                 $plgVersionsXML = new SimpleXMLElement(trim(file_get_contents($cacheFile)));
                 $request = false;
             }
         } else {
             $request = true;
         }
         if ($request) {
             $s = new CBSnoopy();
             $s->read_timeout = 30;
             $s->referer = $_CB_framework->getCfg('live_site');
             @$s->fetch('http://update.joomlapolis.net/cbpluginsversions20.xml');
             if ((int) $s->status == 200) {
                 try {
                     $plgVersionsXML = new SimpleXMLElement($s->results);
                     $plgVersionsXML->saveXML($cacheFile);
                 } catch (Exception $e) {
                 }
             }
         }
         if ($plgVersionsXML) {
             $plgVersions = $plgVersionsXML->getElementByPath('cb_plugins/' . (checkJversion() >= 2 ? 'j30' : 'j15'));
         } else {
             $plgVersions = false;
         }
     }
     $plugin = $this->getCachedPluginObject($plugin);
     if (!$plugin) {
         return $raw === 2 ? array(null, null, null, null) : null;
     }
     static $cache = array();
     $pluginId = (int) $plugin->id;
     if (!isset($cache[$pluginId][$raw])) {
         $xmlFile = $this->getPluginXmlPath($plugin);
         $version = null;
         $latestVersion = null;
         $isLatest = null;
         $latestURL = null;
         if (file_exists($xmlFile)) {
             try {
                 $xml = new SimpleXMLElement(trim(file_get_contents($xmlFile)));
             } catch (\Exception $e) {
                 $xml = null;
                 echo "{$xmlFile} not an XML file!!!";
             }
             if ($xml !== null) {
                 $ver = null;
                 if (isset($xml->release)) {
                     // New release XML variable used by incubator projects:
                     $ver = $xml->release;
                 } elseif (isset($xml->cbsubsversion)) {
                     // CBSubs plugin versions are same as the CBSubs version; lets grab them:
                     $cbsubsVer = $xml->cbsubsversion->attributes();
                     if (isset($cbsubsVer['version'])) {
                         $ver = $cbsubsVer['version'];
                     }
                 } elseif (isset($xml->description)) {
                     // Attempt to parse plugin description for a version using logical naming:
                     if (preg_match('/(?:plugin|field|fieldtype|ver|version|' . preg_quote($plugin->name) . ') ((?:[0-9]+(?:\\.)?(?:(?: )?RC)?(?:(?: )?B)?(?:(?: )?BETA)?)+)/i', $xml->description, $matches)) {
                         $ver = $matches[1];
                     }
                 }
                 // Check if version was found; if it was lets clean it up:
                 if ($ver) {
                     if (preg_match('/^\\d+(\\.\\d+)+(-[a-z]+\\.\\d+)?(\\+\\w)?$/', $ver)) {
                         $version = $ver;
                     } else {
                         $version = preg_replace('/\\.*([a-zA-Z]+)\\.*/i', '.$1.', preg_replace('/^[a-zA-Z]+/i', '', str_replace(array('-', '_', '+'), '.', str_replace(' ', '', strtoupper($ver)))));
                     }
                     if (is_integer($version)) {
                         $version = implode('.', str_split($version));
                     } elseif (preg_match('/^(\\d{2,})(\\.[a-zA-Z].+)/i', $version, $matches)) {
                         $version = implode('.', str_split($matches[1])) . $matches[2];
                     }
                     $version = trim(str_replace('..', '.', $version), '.');
                     // Encase the version is too long lets cut it short for readability and display full version as mouseover title:
                     if ($version && $length && cbIsoUtf_strlen($version) > $length) {
                         $versionName = rtrim(trim(cbIsoUtf_substr($version, 0, $length)), '.') . '&hellip;';
                         $versionShort = true;
                     } else {
                         $versionName = $version;
                         $versionShort = false;
                     }
                     // Lets try and parse out latest version and latest url from versions xml data:
                     if ($plgVersions) {
                         foreach ($plgVersions as $plgVersion) {
                             $plgName = (string) $plgVersion->name;
                             $plgFile = (string) $plgVersion->file;
                             if ($plgName == $plugin->name || strpos($plgName, $plugin->name) !== false || strpos($plgFile, $plugin->folder) !== false) {
                                 $latestVersion = (string) $plgVersion->version;
                                 $latestURL = (string) $plgVersion->url;
                             }
                         }
                     }
                     if ($latestVersion) {
                         if (version_compare($version, $latestVersion) >= 0) {
                             $isLatest = true;
                         } else {
                             $isLatest = false;
                         }
                     }
                     // Format version display:
                     if (!$raw) {
                         if ($latestVersion) {
                             if ($isLatest) {
                                 $version = '<span class="text-success"' . ($versionShort ? ' title="' . htmlspecialchars($version) . '"' : null) . '><strong>' . $versionName . '</strong></span>';
                             } else {
                                 $version = '<span class="text-danger" title="' . htmlspecialchars($latestVersion) . '"><strong>' . $versionName . '</strong></span>';
                                 if ($latestURL) {
                                     $version = '<a href="' . htmlspecialchars($latestURL) . '" target="_blank">' . $version . '</a>';
                                 }
                             }
                         } else {
                             if ($versionShort) {
                                 $version = '<span title="' . htmlspecialchars($version) . '">' . $versionName . '</span>';
                             } else {
                                 $version = $versionName;
                             }
                         }
                     }
                 }
             }
         }
         if (!$version && !$raw) {
             if ($plugin->iscore) {
                 // core plugins are same version as CB it self:
                 if ($length && cbIsoUtf_strlen($ueConfig['version']) > $length) {
                     $version = '<span title="' . htmlspecialchars($ueConfig['version']) . '">' . rtrim(trim(cbIsoUtf_substr($ueConfig['version'], 0, $length)), '.') . '&hellip;</span>';
                 } else {
                     $version = $ueConfig['version'];
                 }
             } else {
                 $version = '-';
             }
         }
         if ($raw === 2) {
             $version = array($version, $latestVersion, $isLatest, $latestURL);
         }
         $cache[$pluginId][$raw] = $version;
     }
     return $cache[$pluginId][$raw];
 }
Exemplo n.º 3
0
 /**
  * Uploads a file from a Url into a file on the filesystem
  *
  * @param  string  $userfileURL    Url
  * @param  string  $userfile_name  INPUT+OUTPUT: Destination filesname
  * @param  string  $msg            OUTPUT: Message for user
  * @return boolean                 Success
  */
 private function uploadFileURL($userfileURL, $userfile_name, &$msg)
 {
     global $_CB_framework;
     cbimport('cb.snoopy');
     cbimport('cb.adminfilesystem');
     $adminFS = cbAdminFileSystem::getInstance();
     if ($adminFS->isUsingStandardPHP()) {
         $baseDir = _cbPathName($_CB_framework->getCfg('tmp_path'));
     } else {
         $baseDir = $_CB_framework->getCfg('absolute_path') . '/tmp';
     }
     if (file_exists($baseDir)) {
         if ($adminFS->is_writable($baseDir) || !$adminFS->isUsingStandardPHP()) {
             $s = new CBSnoopy();
             $fetchResult = @$s->fetch($userfileURL);
             if ($fetchResult && !$s->error && $s->status == 200) {
                 cbimport('cb.adminfilesystem');
                 $adminFS = cbAdminFileSystem::getInstance();
                 if ($adminFS->file_put_contents($baseDir . $userfile_name, $s->results)) {
                     if ($this->_cbAdmin_chmod($baseDir . $userfile_name)) {
                         return true;
                     } else {
                         $msg = sprintf(CBTxt::T('Failed to change the permissions of the uploaded file %s'), $baseDir . $userfile_name);
                     }
                 } else {
                     $msg = sprintf(CBTxt::T('Failed to create and write uploaded file in %s'), $baseDir . $userfile_name);
                 }
             } else {
                 $msg = $s->error ? sprintf(CBTxt::T('Failed to download package file from <code>%s</code> to webserver due to following error: %s'), $userfileURL, $s->error) : sprintf(CBTxt::T('Failed to download package file from <code>%s</code> to webserver due to following status: %s'), $userfileURL, $s->status . ': ' . $s->response_code);
             }
         } else {
             $msg = sprintf(CBTxt::T('Upload failed as %s directory is not writable.'), '<code>' . htmlspecialchars($baseDir) . '</code>');
         }
     } else {
         $msg = sprintf(CBTxt::T('Upload failed as %s directory does not exist.'), '<code>' . htmlspecialchars($baseDir) . '</code>');
     }
     return false;
 }
Exemplo n.º 4
0
function latestVersion()
{
    global $_CB_framework, $ueConfig;
    cbimport('cb.snoopy');
    $s = new CBSnoopy();
    $s->read_timeout = 90;
    $s->referer = $_CB_framework->getCfg('live_site');
    @$s->fetch('http://www.joomlapolis.com/versions/comprofilerversion.php?currentversion=' . urlencode($ueConfig['version']));
    $version_info = $s->results;
    $version_info_pos = strpos($version_info, ":");
    if ($version_info_pos === false) {
        $version = $version_info;
        $info = null;
    } else {
        $version = substr($version_info, 0, $version_info_pos);
        $info = substr($version_info, $version_info_pos + 1);
    }
    if ($s->error || $s->status != 200) {
        echo '<span class="text-danger">' . CBTxt::T('Connection to update server failed') . ': ' . CBTxt::T('ERROR') . ': ' . $s->error . ($s->status == -100 ? CBTxt::T('Timeout') : $s->status) . '</span>';
    } else {
        if ($version == $ueConfig['version']) {
            echo '<span class="text-success">' . $version . '</span>' . $info;
        } else {
            echo '<span class="text-danger">' . $version . '</span>' . $info;
        }
    }
}
Exemplo n.º 5
0
 /**
  * @param string $url
  * @param string $file
  * @param int $duration
  * @return SimpleXMLElement|null
  */
 public static function getFeedXML($url, $file, $duration = 12)
 {
     global $_CB_framework;
     cbimport('cb.snoopy');
     $cache = $_CB_framework->getCfg('absolute_path') . '/cache/' . $file;
     $xml = null;
     if (file_exists($cache)) {
         if (!$duration || intval(($_CB_framework->now() - filemtime($cache)) / 3600) > $duration) {
             $request = true;
         } else {
             $xml = new SimpleXMLElement(trim(file_get_contents($cache)));
             $request = false;
         }
     } else {
         $request = true;
     }
     if ($request) {
         $s = new CBSnoopy();
         $s->read_timeout = 30;
         $s->referer = $_CB_framework->getCfg('live_site');
         @$s->fetch($url);
         if ((int) $s->status == 200) {
             try {
                 $xml = new SimpleXMLElement($s->results);
                 $xml->saveXML($cache);
             } catch (Exception $e) {
             }
         }
     }
     return $xml;
 }
Exemplo n.º 6
0
	/**
	 * Called at each change of user subscription state due to a plan activation or deactivation
	 *
	 * @param  UserTable        $user
	 * @param  string           $status
	 * @param  int              $planId
	 * @param  int              $replacedPlanId
	 * @param  ParamsInterface  $integrationParams
	 * @param  string           $cause              'PaidSubscription' (first activation only), 'SubscriptionActivated' (renewals, cancellation reversals), 'SubscriptionDeactivated', 'Denied'
	 * @param  string           $reason             'N' new subscription, 'R' renewal, 'U'=update
	 * @param  int              $now                Unix time
	 * @param cbpaidSomething   $subscription
	 */
	public function onCPayUserStateChange( &$user, $status, $planId, $replacedPlanId, &$integrationParams, $cause, $reason, /** @noinspection PhpUnusedParameterInspection */ $now, &$subscription ) {
		global $_CB_framework;
		
		if ( ! $user ) {
			return;
		}
		
		$event		=	null;
		
		if ( ( $status == 'A' ) && ( $cause == 'PaidSubscription' ) && ( $reason != 'R' ) ) {
			$event	=	'activation';
		} elseif ( ( $status == 'A' ) && ( $cause == 'PaidSubscription' ) && ( $reason == 'R' ) ) {
			$event	=	'renewal';
		} elseif ( ( $status == 'X' ) && ( $cause != 'Pending' ) ) {
			$event	=	'expiration';
		} elseif ( ( $status == 'C' ) && ( $cause != 'Pending' ) ) {
			$event	=	'deactivation';
		}
		
		if ( $event ) {
			$path									=	$integrationParams->get( 'url_path_' . $event, null );
			$method									=	$integrationParams->get( 'url_method_' . $event, 'GET' );
			$results								=	$integrationParams->get( 'url_results_' . $event, 0 );
			
			if ( $path ) {

				// add substitutions for: [plan_id], [replaced_plan_id], [subscription_id], [parent_plan_id], [parent_subscription_id]
				$extraStringsLocal					=	array(
													'plan_id'					=>	(int) $planId,
													'replaced_plan_id'			=>	(int) $replacedPlanId,
													'subscription_id'			=>	(int) $subscription->id,
													'parent_plan_id'			=>	(int) $subscription->parent_plan,
													'parent_subscription_id'	=>	(int) $subscription->parent_subscription
													);
				$extraStrings						=	array_merge( $subscription->substitutionStrings( false ), $extraStringsLocal );

				cbimport( 'cb.snoopy' );
				
				$cbUser								=&	CBuser::getInstance( $user->id );
				
				if ( ! $cbUser ) {
					return;
				}
				
				$path								=	trim( $cbUser->replaceUserVars( $path, array( $this, '_urlencode' ), false, $extraStrings, false ) );
				$snoopy								=	new CBSnoopy();
				$snoopy->read_timeout				=	30;
				
				switch ($method ) {
					case 'POST':
						$post						=	$integrationParams->get( 'url_post_' . $event, null );
						$formvar					=	array();

						if ( $post ) {
							$formvars				=	explode( "\n", $post );
							foreach ( $formvars as $vars ) {
								$var				=	explode( '=', trim( $vars ), 2 );
								if ( count( $var ) == 2 ) {
									$key			=	trim( $var[0] );
									$value			=	trim( $cbUser->replaceUserVars( $var[1], false, false, $extraStrings, false ) );
									$formvar[$key]	=	$value;
								}
							}
						}
						
						$snoopy->submit( $path, $formvar );
						break;

					case 'XML':
						$xmlText					=	$integrationParams->get( 'url_xml_' . $event, null );
						$xmlText					=	trim( $cbUser->replaceUserVars( $xmlText, array( $this, '_htmlspecialchars' ), false, $extraStrings, false ) );
						$formvar					=	array( 'xml' => $xmlText );
						$snoopy->set_submit_xml();
						$snoopy->submit( $path, $formvar );
						break;

					case 'GET':
					default:
						$snoopy->fetch( $path );
						break;
				}

				if ( $results && ( ! $snoopy->error ) && ( $snoopy->status == 200 ) && $snoopy->results && ( $_CB_framework->getUi() == 1 ) ) {
					// display only in frontend:
					echo '<div class="CBSubsURL_Results_' . (int) $planId . '">' . $snoopy->results . '</div>';
				}
			}
		}
	}