예제 #1
0
 /**
  * Method to get the field label.
  *
  * @return  string  A message containing the installed version and,
  *                  if necessary, information on a new version.
  *
  * @since   2.1
  */
 protected function getLabel()
 {
     // Get the module's XML
     $xmlfile = dirname(__DIR__) . '/mod_tweetdisplayback.xml';
     $data = JApplicationHelper::parseXMLInstallFile($xmlfile);
     $cacheFile = JPATH_CACHE . '/tweetdisplayback_update.json';
     // The module's version
     $version = $data['version'];
     // The target to check against
     $target = 'https://www.babdev.com/updates/TDB_version_new';
     // Get the module params
     $params = static::getModuleParams($this->form->getValue('id', null, 0));
     // Get the stability level we want to show data for
     $stability = $params->get('stability', 'stable');
     // Check if we have cached data and use it if unexpired
     if (!file_exists($cacheFile) || time() - @filemtime($cacheFile) > 86400) {
         // Get the data from remote
         $helper = new ModTweetDisplayBackHelper(new JRegistry());
         $data = $helper->getJSON($target);
         $update = $data->{$stability};
         // Write the cache if data exists
         if (isset($update->notice)) {
             $cache = json_encode($data);
             file_put_contents($cacheFile, $cache);
         }
     } else {
         // Render from the cached data
         $data = json_decode(file_get_contents($cacheFile));
         $update = $data->{$stability};
     }
     // Message containing the version
     if (version_compare(JVERSION, '3.0', 'ge')) {
         $message = '<div class="alert alert-info">';
         $close = '</div>';
     } else {
         $message = '<label style="max-width:100%">';
         $close = '</label>';
     }
     $message .= JText::sprintf('MOD_TWEETDISPLAYBACK_VERSION_INSTALLED', $version);
     // Make sure that the $update object actually has data
     if (!isset($update->notice)) {
         $message .= '  ' . JText::_('MOD_TWEETDISPLAYBACK_VERSION_FAILED') . $close;
     } elseif (version_compare($update->version, $version, 'gt') && version_compare(JVERSION, $update->jversion, 'ge')) {
         $message .= '  <a href="' . $update->notice . '" target="_blank">' . JText::sprintf('MOD_TWEETDISPLAYBACK_VERSION_UPDATE', $update->version) . '</a></label>';
     } else {
         $message .= '  ' . JText::_('MOD_TWEETDISPLAYBACK_VERSION_CURRENT') . $close;
     }
     return $message;
 }
예제 #2
0
파일: version.php 프로젝트: bizanto/Hooked
 /**
  * Method to get the element.
  *
  * @return  string  A message containing the installed version and,
  *                  if necessary, information on a new version.
  *
  * @since   2.1
  */
 function fetchElement($name, $value, &$node, $control_name)
 {
     // Check if cURL is loaded; if not, proceed no further
     if (!extension_loaded('curl')) {
         return JText::_('MOD_TWEETDISPLAYBACK_ERROR_NOCURL');
     } else {
         // Get the module's XML
         $xmlfile = JPATH_SITE . '/modules/mod_tweetdisplayback/mod_tweetdisplayback.xml';
         $data = JApplicationHelper::parseXMLInstallFile($xmlfile);
         // The module's version
         $version = $data['version'];
         // The target to check against
         $target = 'http://www.flbab.com/updates/TDB_version';
         // Get the JSON data
         $update = ModTweetDisplayBackHelper::getJSON($target);
         // Message containing the version
         $message = '<label style="max-width:100%">' . JText::sprintf('MOD_TWEETDISPLAYBACK_VERSION_INSTALLED', $version);
         // If an update is available, notify the user
         if (version_compare($update['version'], $version, 'gt')) {
             $message .= '  <a href="' . $update['notice'] . '" target="_blank">' . JText::sprintf('MOD_TWEETDISPLAYBACK_VERSION_UPDATE', $update['version']) . '</a></label>';
         } else {
             $message .= '  ' . JText::_('MOD_TWEETDISPLAYBACK_VERSION_CURRENT') . '</label>';
         }
         return $message;
     }
 }
예제 #3
0
 /**
  * Method to get the field label.
  *
  * @return  string  A message containing the installed version and,
  *                  if necessary, information on a new version.
  *
  * @since   2.1
  */
 protected function getLabel()
 {
     // Get the module's XML
     $xmlfile = dirname(__DIR__) . '/mod_tweetdisplayback.xml';
     $data = JApplicationHelper::parseXMLInstallFile($xmlfile);
     // The module's version
     $version = $data['version'];
     // The target to check against
     $target = 'http://www.babdev.com/updates/TDB_version_new';
     // Get the module params
     $params = static::getModuleParams($this->form->getValue('id', null, 0));
     // Get the stability level we want to show data for
     $stability = $params->get('stability', 'stable');
     // Get the JSON data
     $helper = new ModTweetDisplayBackHelper(new JRegistry());
     $data = $helper->getJSON($target);
     $update = $data->{$stability};
     // Message containing the version
     if (version_compare(JVERSION, '3.0', 'ge')) {
         $message = '<div class="alert alert-info">';
         $close = '</div>';
     } else {
         $message = '<label style="max-width:100%">';
         $close = '</label>';
     }
     $message .= JText::sprintf('MOD_TWEETDISPLAYBACK_VERSION_INSTALLED', $version);
     // Make sure that the $update object actually has data
     if (!isset($update->notice)) {
         $message .= '  ' . JText::_('MOD_TWEETDISPLAYBACK_VERSION_FAILED') . $close;
     } elseif (version_compare($update->version, $version, 'gt') && version_compare(JVERSION, $update->jversion, 'ge')) {
         $message .= '  <a href="' . $update->notice . '" target="_blank">' . JText::sprintf('MOD_TWEETDISPLAYBACK_VERSION_UPDATE', $update->version) . '</a></label>';
     } else {
         $message .= '  ' . JText::_('MOD_TWEETDISPLAYBACK_VERSION_CURRENT') . $close;
     }
     return $message;
 }
defined('_JEXEC') or die;
// Include the helper
JLoader::register('ModTweetDisplayBackHelper', __DIR__ . '/helper.php');
/* @type JRegistry $params */
// Set the template variables
$imgpath = JUri::root() . 'modules/mod_tweetdisplayback/media/images';
$headerAlign = $params->get('headerAvatarAlignment');
$tweetAlign = $params->get('tweetAlignment');
$headerClassSfx = htmlspecialchars($params->get('headerclasssfx'));
$tweetClassSfx = htmlspecialchars($params->get('tweetclasssfx'));
$template = $params->get('templateLayout', 'default');
$flist = ModTweetDisplayBackHelper::toAscii($params->get('twitterList', ''));
$count = $params->get('twitterCount', '3') - 1;
// Load module CSS
JHtml::stylesheet('mod_tweetdisplayback/' . $template . '.css', false, true, false);
$helper = new ModTweetDisplayBackHelper($params);
// The files that the data is cached to
$cacheTweets = JPATH_CACHE . '/tweetdisplayback_tweets.json';
$cacheUser = JPATH_CACHE . '/tweetdisplayback_user.json';
// Check if caching is enabled
if ($params->get('cache') == 1) {
    // Fetch cache time from module parameters and convert to seconds
    $cacheTime = $params->get('cache_time', 15);
    $cacheTime = $cacheTime * 60;
    // Cache files expired?
    if (!file_exists($cacheTweets) && !file_exists($cacheUser) || time() - @filemtime($cacheTweets) > $cacheTime && time() - @filemtime($cacheUser) > $cacheTime) {
        // Do a request to the Twitter API for new data
        $twitter = $helper->compileData();
    } else {
        // Render from the cached data
        $helper->isCached = true;
예제 #5
0
    if ($params->get('cache') == 1) {
        // Set the cache parameters
        $options = array('defaultgroup' => 'mod_tweetdisplayback');
        $cache = JCache::getInstance('callback', $options);
        $cacheTime = $params->get('cache_time');
        // J! 1.5 and 1.6 cache is set in seconds, 1.7 caches in minutes
        if (version_compare(JVERSION, '1.7.0', 'ge')) {
            $cacheTime = round($cacheTime / 60);
        }
        $cache->setLifeTime($cacheTime);
        $cache->setCaching(true);
        // Call the cache; if expired, pull new data
        $twitter = $cache->call(array('ModTweetDisplayBackHelper', 'compileData'), $params);
    } else {
        // Pull new data
        $twitter = ModTweetDisplayBackHelper::compileData($params);
    }
    // No hits remaining
    if (isset($twitter->hits)) {
        echo '<div class="TDB-tweet' . $tweetClassSfx . $tweetAvatar . '"><div class="TDB-tweet-container TDB-tweet-align-' . $tweetAlign . ' TDB-error"><div class="TDB-tweet-text">' . JText::_('MOD_TWEETDISPLAYBACK_ERROR_NOHITS') . '</div></div></div>';
        return;
    } else {
        if (!$twitter || isset($twitter->error)) {
            echo '<div class="TDB-tweet' . $tweetClassSfx . $tweetAvatar . '"><div class="TDB-tweet-container TDB-tweet-align-' . $tweetAlign . ' TDB-error"><div class="TDB-tweet-text">' . JText::_('MOD_TWEETDISPLAYBACK_ERROR_UNABLETOLOAD') . '</div></div></div>';
            return;
        }
    }
}
// Add the Twitter Web Intents script if something else already hasn't
$document = JFactory::getDocument();
if (!in_array('<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>', $document->_custom)) {