/**
  * This function checks for an update for a particular module at the lotuscms website.
  */
 protected function checkForTemplateUpdate($req, $page = null)
 {
     if (isset($_SESSION['TEM_LCMS_ORG_RESPONSE'])) {
         return $_SESSION['TEM_LCMS_ORG_RESPONSE'];
     } else {
         include_once "core/lib/RemoteFiles.php";
         include_once "core/lib/ModuleInfo.php";
         //Get information on update status of each plugin.
         //Setup remote file requestor
         $rf = new RemoteFiles();
         //Get site version
         $version = file_get_contents("data/config/site_version.dat");
         $data = "";
         if (isset($_SESSION['TEM_LCMS_ORG_RESPONSE_URL'])) {
             if (!empty($_SESSION['TEM_LCMS_ORG_RESPONSE_URL'])) {
                 $data = $_SESSION['TEM_LCMS_ORG_RESPONSE_URL'];
             }
         }
         if (empty($data)) {
             //Collect information on module updates.
             $data = $rf->getURL("http://styles.lotuscms.org/lcms-3-styles/checkTempString.php?t={$req}&v={$version}", $page);
         }
         $_SESSION['TEM_LCMS_ORG_RESPONSE_URL'] = $data;
         //Output
         $out = "";
         $modArray = array();
         //Get list of plugins
         $m = explode("|", $data);
         //Loop through each update response.
         for ($i = 0; $i < count($m); $i++) {
             //Split name & version number
             $getFull = explode(":", $m[$i]);
             //Get full number of plugin
             $nv = (double) $getFull[1];
             //Get current version number
             $cv = $this->getTemplateVersionNumber($getFull[0]);
             //If new version is actually newer than installed.
             if ($cv < $nv) {
                 $modArray[$getFull[0]] = true;
             } else {
                 $modArray[$getFull[0]] = false;
             }
         }
         //Response
         $_SESSION['TEM_LCMS_ORG_RESPONSE'] = $modArray;
         return $modArray;
     }
 }
 /**
  * Gets html formatted news from LotusCMS.org
  */
 private function getNews()
 {
     $data = "";
     if (file_exists("data/lcmscache/news.dat")) {
         $data = $this->openFile("data/lcmscache/news.dat");
     }
     if (empty($data)) {
         if (!isset($_SESSION['newsCheck'])) {
             include "core/lib/RemoteFiles.php";
             $rf = new RemoteFiles();
             //Get version of CMS
             $v = $this->con->getVersion();
             $data = $rf->getURL("http://news.lotuscms.org/lcms-3-series/getDashboardNews.php?v=" . $v);
             $_SESSION['newsCheck'] = $data;
         } else {
             $data = $_SESSION['newsCheck'];
         }
     }
     print $data;
 }
 /**
  * Allows download and install
  */
 public function downloadInstall()
 {
     $this->setState('DOWNLOADING_PLUGIN');
     //Get plugin name
     $plugin = $this->getActiveRequest();
     //Should never occur.
     if (empty($plugin)) {
         exit("Plugin Undefined.");
     }
     //Get remote files collector
     include_once "core/lib/RemoteFiles.php";
     //Create new remote file connector.
     $rf = new RemoteFiles();
     //Save this zip
     $rf->downloadRemoteFile("http://cdn.modules.lotuscms.org/lcms-3-series/zips/" . $plugin . ".zip", "data", $plugin . ".zip");
     include_once 'core/lib/pclzip.lib.php';
     //Setup Archive
     $archive = new PclZip("data/" . $plugin . ".zip");
     //Destroy existing plugin files if they exist.
     $this->destroyDir("modules/" . $plugin, true);
     //Extract Archive
     $list = $archive->extract(PCLZIP_OPT_PATH, "modules");
     if ($archive->extract() == 0) {
         $this->setState('DOWNLOADING_PLUGIN_FAILED');
         unlink("data/" . $plugin . ".zip");
         //Display Error Message
         exit("<p><strong>Error</strong> : " . $archive->errorInfo(true) . "</p><p>It may help to chmod (change write permissions) the 'modules' cms directory to 777.</p>");
     } else {
         $this->setState('DOWNLOADING_PLUGIN_SUCCESS');
         //If the original plugin folder is also there remove it
         if (is_dir($plugin)) {
             //Destroys the secondary folder before copy.
             $this->destroyDir($plugin, true);
             //Destroys the secondary folder before copy.
             $this->destroyDir("__MACOSX", true);
         }
         //Delete the temporary plugin zip file.
         unlink("data/" . $plugin . ".zip");
         return $plugin;
     }
 }
 /**
  * Gets featured templates from lotuscms.org
  */
 public function getFeaturedTemplates()
 {
     include_once "core/lib/RemoteFiles.php";
     //Create new remote file connector.
     $rf = new RemoteFiles();
     $id = $this->getInputString("id", "1", "G");
     $version = $this->openFile("data/config/site_version.dat");
     $out = $rf->getURL("http://styles.lotuscms.org/lcms-3-styles/infoloader.php?id=" . $id . "&lang=" . $this->getController()->getView()->getLocale() . "&t=" . $this->getAllTemplatesAsString() . "&v={$version}");
     if (empty($out)) {
         exit("<br /><br /><strong>Data retrieval failed</strong> - LotusCMS.org probably unavailable, please try again later.");
     }
     return $out1;
 }
 /**
  * This function checks for an update for a particular module at the lotuscms website.
  */
 public function checkForModuleUpdate($req)
 {
     if (isset($_SESSION['MODUPDATE'])) {
         print $_SESSION['MODUPDATE'];
         exit;
     } else {
         include_once "core/lib/RemoteFiles.php";
         include_once "core/lib/ModuleInfo.php";
         //Get information on update status of each plugin.
         //Setup remote file requestor
         $rf = new RemoteFiles();
         //Get site version
         $version = file_get_contents("data/config/site_version.dat");
         $data = "";
         if (isset($_SESSION['MOD_LCMS_ORG_RESPONSE_URL'])) {
             $data = $_SESSION['MOD_LCMS_ORG_RESPONSE_URL'];
         }
         if (file_exists("data/lcmscache/mod_update.dat") && empty($data)) {
             include_once "core/lib/io.php";
             $io = new InputOutput();
             $data = $io->openFile("data/lcmscache/mod_update.dat");
             $_SESSION['MOD_LCMS_ORG_RESPONSE_URL'] = $data;
             //Finally delete the cache
             unlink("data/lcmscache/mod_update.dat");
         } else {
             //Collect information on module updates.
             $data = $rf->getURL("http://cdn.modules.lotuscms.org/lcms-3-series/versioncontrol/allversioncheck.php?m={$req}&v={$version}");
         }
         //Save response in session in case it is required later
         $_SESSION['MOD_LCMS_ORG_RESPONSE_URL'] = $data;
         //Output
         $out = "";
         if (empty($data)) {
             print "<p class='msg error'><strong>Error:</strong> cannot connect to lotuscms.org</p>";
             exit;
         }
         //Get list of plugins
         $m = explode("|", $data);
         $l = new Locale();
         //Loop through each update response.
         for ($i = 0; $i < count($m); $i++) {
             //Split name & version number
             $getFull = explode(":", $m[$i]);
             //Get full number of plugin
             $nv = (double) $getFull[1];
             //Get current version
             include_once "modules/" . $getFull[0] . "/" . $getFull[0] . "ModuleInfo.php";
             $name = $getFull[0] . "ModuleInfo";
             //Load info class
             $info = new $name();
             //Load info
             $info->ModuleInfo();
             //Get current version number
             $cv = (double) $info->getVersion();
             //If new version is actually newer than installed.
             if ($cv < $nv) {
                 $out .= '<p class="msg error">' . $l->localize("Module") . ': ' . $getFull[0] . ' ' . $l->localize("is out of date") . ' [' . $l->localize("version") . ': ' . $getFull[1] . ']. <a href="index.php?system=Modules&page=updateCheck&req=' . $getFull[0] . '">' . $l->localize("Update") . '</a></p>';
             }
         }
         print $out;
         $_SESSION['MODUPDATE'] = $out;
         exit;
     }
 }
 /**
  * Create a form for the page.
  */
 protected function singleForm($version, $title)
 {
     $this->setState('CREATING_SINGLE_FORM');
     $listLocale = $this->getController()->getModel()->getListOfLocale();
     $activeLocale = $this->getLocale();
     //Get the form
     $out = $this->openFile("core/fragments/settings/GeneralSettingsForm.phtml");
     //Replace Title in File
     $out = str_replace("%TITLE%", $title, $out);
     //Replace current version in File
     $out = str_replace("%CURRENTVERSION%", $version, $out);
     //Put in update notice
     $out = str_replace("%UPDATE_NOTICE%", "<p class='msg error'>" . $this->getInputString('versionCheck', "", "S") . "</p>", $out);
     $localeOptions = "";
     $fID = 0;
     //Find the ID of the active locale
     for ($i = 0; $i < count($listLocale[0]); $i++) {
         if ($activeLocale == str_replace(".txt", "", $listLocale[0][$i])) {
             $fID = $i;
             break;
         }
     }
     $localeOptions .= "<option>";
     $localeOptions .= $listLocale[1][$fID] . " [" . str_replace(".txt", "", $listLocale[0][$fID]) . "]";
     $localeOptions .= "</option>";
     //Create the list
     for ($i = 0; $i < count($listLocale[0]); $i++) {
         if ($i != $fID) {
             $localeOptions .= "<option>";
             $localeOptions .= $listLocale[1][$i] . " [" . str_replace(".txt", "", $listLocale[0][$i]) . "]";
             $localeOptions .= "</option>";
         }
     }
     //Enter Locale List
     $out = str_replace("%LOCALE_LIST%", $localeOptions, $out);
     //Locale
     $out = str_replace("%WEBSITE_TITLE_LOCALE%", $this->localize("Website Title"), $out);
     $out = str_replace("%WEBSITE_VERSION_LOCALE%", $this->localize("Website Version"), $out);
     $out = str_replace("%CLEAR_CACHE_MESSAGE_LOCALE%", $this->localize("You may wish to clear the CMS cache after this, as cached pages will contain old title."), $out);
     $out = str_replace("%WEBSITE_DISABLE_LOCALE%", $this->localize("Disable Website"), $out);
     $out = str_replace("%UNDER_CONSTRUCTION_LOCALE%", $this->localize("This feature is yet to be implemented"), $out);
     $out = str_replace("%YOUR_VERSION_LOCALE%", $this->localize("Your Version"), $out);
     $out = str_replace("%LATEST_VERSION_LOCALE%", $this->localize("Latest Version"), $out);
     $out = str_replace("%SAVE_LOCALE%", $this->localize("Save"), $out);
     $out = str_replace("%WEBSITE_LOCALE_LOCALE%", $this->localize("Change Website Locale"), $out);
     $data = $this->getController()->getModel()->getInputString("vnumber", "", "S");
     //Include and load the latest version
     if (empty($data)) {
         include "core/lib/RemoteFiles.php";
         $rf = new RemoteFiles();
         $data = $rf->getURL("http://update.lotuscms.org/lcms-3-series/latestVersion.dat");
     }
     //Reduce load by dumping the retrieval system.
     unset($rf);
     //Replace Unix in File
     $out = str_replace("%LATESTVERSION%", $data, $out);
     //Return the out data
     return $out;
 }
 /**
  * Allows download and install
  */
 public function downloadInstall()
 {
     $this->setState('DOWNLOADING_PLUGIN');
     //Get plugin name
     $plugin = $this->getActiveRequest();
     //Should never occur.
     if (empty($plugin)) {
         exit("Plugin Undefined.");
     }
     //Get remote files collector
     include_once "core/lib/RemoteFiles.php";
     //Create new remote file connector.
     $rf = new RemoteFiles();
     //Get LCMS Version to select repository
     $version = $this->openFile("data/config/site_version.dat");
     //Explode the version number
     $v = explode(".", $version);
     //Create subversion number
     $version = $v[0] . "." . $v[1];
     //Save this zip
     $rf->downloadRemoteFile("http://cdn.modules.lotuscms.org/lcms-3-series/zips/{$version}/{$plugin}.zip", "data", "{$plugin}.zip");
     include_once 'modules/Backup/pclzip.lib.php';
     //Setup Archive
     $archive = new PclZip("data/" . $plugin . ".zip");
     //Extract Archive
     $list = $archive->extract(PCLZIP_OPT_PATH, "modules");
     if ($archive->extract() == 0) {
         $this->setState('DOWNLOADING_PLUGIN_FAILED');
         unlink("data/" . $plugin . ".zip");
         //Display Error Message
         exit("<p><strong>Error</strong> : " . $archive->errorInfo(true) . "</p><p>It may help to chmod (change write permissions) the 'modules' cms directory to 777.</p>");
     } else {
         $this->setState('DOWNLOADING_PLUGIN_SUCCESS');
         //Delete session varaibles detailing the info
         unset($_SESSION['MOD_LCMS_ORG_RESPONSE']);
         unset($_SESSION['MOD_LCMS_ORG_RESPONSE_URL']);
         //If the original plugin folder is also there remove it
         if (is_dir($plugin)) {
             //Destroys the secondary folder before copy.
             $this->destroyDir($plugin, true);
             //Destroys the secondary folder before copy.
             $this->destroyDir("__MACOSX", true);
         }
         //Delete the temporary plugin zip file.
         unlink("data/" . $plugin . ".zip");
         return $plugin;
     }
 }
 /**
  * This function checks for an update for a particular module at the lotuscms website.
  */
 protected function checkForModuleUpdate($req, $saveInfo)
 {
     if (isset($_SESSION['MOD_LCMS_ORG_RESPONSE'])) {
         return $_SESSION['MOD_LCMS_ORG_RESPONSE'];
     } else {
         include_once "core/lib/RemoteFiles.php";
         include_once "core/lib/ModuleInfo.php";
         //Get information on update status of each plugin.
         //Setup remote file requestor
         $rf = new RemoteFiles();
         //Get site version
         $version = file_get_contents("data/config/site_version.dat");
         $data = "";
         if (isset($_SESSION['MOD_LCMS_ORG_RESPONSE_URL']) && !$saveInfo) {
             if (!empty($_SESSION['MOD_LCMS_ORG_RESPONSE_URL'])) {
                 $data = $_SESSION['MOD_LCMS_ORG_RESPONSE_URL'];
             }
         } else {
             if (file_exists("data/lcmscache/mod_update.dat")) {
                 include_once "core/lib/io.php";
                 $io = new InputOutput();
                 $data = $io->openFile("data/lcmscache/mod_update.dat");
                 $_SESSION['MOD_LCMS_ORG_RESPONSE_URL'] = $data;
                 //Finally delete the cache
                 unlink("data/lcmscache/mod_update.dat");
             } else {
                 //Collect information on module updates.
                 $data = $rf->getURL("http://cdn.modules.lotuscms.org/lcms-3-series/versioncontrol/allversioncheck.php?m={$req}&v={$version}");
                 //If preloader is getting info, save it to file
                 if ($saveInfo && !empty($data)) {
                     include_once "core/lib/io.php";
                     $io = new InputOutput();
                     $io->saveFile("data/lcmscache/mod_update.dat", $data);
                     return null;
                 }
             }
         }
         //Output
         $out = "";
         if (empty($data)) {
             if (file_exists("data/lcmscache/mod_update.dat")) {
                 unlink("data/lcmscache/mod_update.dat");
             }
             return false;
         }
         $modArray = array();
         //Get list of plugins
         $m = explode("|", $data);
         //Loop through each update response.
         for ($i = 0; $i < count($m); $i++) {
             //Split name & version number
             $getFull = explode(":", $m[$i]);
             //Get full number of plugin
             $nv = (double) $getFull[1];
             //Get current version
             include_once "modules/" . $getFull[0] . "/" . $getFull[0] . "ModuleInfo.php";
             $name = $getFull[0] . "ModuleInfo";
             //Load info class
             $info = new $name();
             //Load info
             $info->ModuleInfo();
             //Get current version number
             $cv = (double) $info->getVersion();
             //If new version is actually newer than installed.
             if ($cv < $nv) {
                 $modArray[$getFull[0]] = true;
             } else {
                 $modArray[$getFull[0]] = false;
             }
         }
         //Response
         $_SESSION['MOD_LCMS_ORG_RESPONSE'] = $modArray;
         return $modArray;
     }
 }
 /**
  * This function checks for an update for a particular module at the lotuscms website.
  */
 public function checkForUpdate()
 {
     $this->setState('STARTING_UPDATE_CHECK');
     //Gets the module in question
     $req = $this->getInputString("req", "", "G");
     include "core/lib/RemoteFiles.php";
     include_once "core/lib/ModuleInfo.php";
     include "modules/" . $req . "/" . $req . "ModuleInfo.php";
     $classname = $req . "ModuleInfo";
     $mod = new $classname();
     $rf = new RemoteFiles();
     $version = file_get_contents("data/config/site_version.dat");
     //Get version of Module
     $v = $mod->getVersion();
     $data = $rf->getURL("http://cdn.modules.lotuscms.org/lcms-3-series/versioncontrol/versioncheck.php?module={$req}&v={$version}");
     if (!empty($data)) {
         if ($data != $v) {
             return true;
         }
     } else {
         return false;
     }
 }
 /**
  *
  */
 private function checkForUpdate()
 {
     $data = "";
     if (file_exists("data/lcmscache/vnumber.dat")) {
         $_SESSION['vnumber'] = $this->getView()->getController()->getModel()->openFile("data/lcmscache/vnumber.dat");
         unlink("data/lcmscache/vnumber.dat");
     }
     if (file_exists("data/lcmscache/vmessage.dat")) {
         $data = $this->getView()->getController()->getModel()->openFile("data/lcmscache/vmessage.dat");
         $_SESSION['versionCheck'] = $data;
         unlink("data/lcmscache/vmessage.dat");
         return $data;
     }
     if (empty($data)) {
         if (!isset($_SESSION['versionCheck'])) {
             include "core/lib/RemoteFiles.php";
             $rf = new RemoteFiles();
             //Get version of CMS
             $v = $this->getView()->getController()->getVersion();
             $data = $rf->getURL("http://update.lotuscms.org/lcms-3-series/updateCheck.php?v=" . $v . "&lang=" . $this->getView()->getLocale());
             $data = explode("%%", $data);
             $_SESSION['versionCheck'] = $data[1];
             $_SESSION['vnumber'] = $data[0];
         } else {
             $data = array("", $_SESSION['versionCheck']);
         }
         return $data[1];
     } else {
         return $data;
     }
 }