/** * 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; } }
/** * 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; }
/** * 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; }