diff --git a/plugins/ktstandard/AdminVersionPlugin/AdminVersion.inc.php b/plugins/ktstandard/AdminVersionPlugin/AdminVersion.inc.php new file mode 100644 index 0000000..755fb29 --- /dev/null +++ b/plugins/ktstandard/AdminVersionPlugin/AdminVersion.inc.php @@ -0,0 +1,90 @@ + $v) + { + $aEncoded[] = sprintf("%s=%s", urlencode($k), urlencode($v)); + } + + if (empty($url)) + $sUrl = self::KT_VERSION_URL; + else + $sUrl = $url; + $sUrl .= '?' . implode('&', $aEncoded); + + $sIdentifier = KTUtil::getSystemIdentifier(); + $sUrl .= '&' . sprintf("system_identifier=%s", $sIdentifier); + + if (!function_exists('curl_init')) + { + $stuff = @file_get_contents($sUrl); + } + else + { + $ch = @curl_init($sUrl); + if (!$ch) + { + return false; + } + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_TIMEOUT, 10); + $stuff = curl_exec($ch); + curl_close($ch); + } + if ($stuff === false) + { + $stuff = ""; + } + else + { + $stuff = str_replace('\'','"', $stuff); + $decoded = json_decode($stuff); + if ($decoded === false) + { + return false; + } + KTUtil::setSystemSetting('ktadminversion_lastcheck', date('Y-m-d H:i:s')); + KTUtil::setSystemSetting('ktadminversion_lastvalue', serialize($decoded)); + } + } + + public static + function isNewVersionAvailable() + { + $aVersions = KTUtil::getKTVersions(); + + $name = array_keys($aVersions); + $name = $name[0]; + $version = array_values($aVersions); + $version = $version[0]; + + $aRemoteVersions = unserialize(KTUtil::getSystemSetting('ktadminversion_lastvalue')); + + $aVersions = get_object_vars($aRemoteVersions); + + if (!isset($aVersions[$name])) + { + return false; + } + + $newVersion = $aRemoteVersions->$name; + if (version_compare($version, $newVersion) == -1) + { + return array('name'=>$name,'version'=>$aRemoteVersions->$name); + } + + return false; + } +} + +?> \ No newline at end of file diff --git a/plugins/ktstandard/AdminVersionPlugin/AdminVersionDashlet.php b/plugins/ktstandard/AdminVersionPlugin/AdminVersionDashlet.php index 49e4558..4881e5d 100644 --- a/plugins/ktstandard/AdminVersionPlugin/AdminVersionDashlet.php +++ b/plugins/ktstandard/AdminVersionPlugin/AdminVersionDashlet.php @@ -6,71 +6,71 @@ * Document Management Made Simple * Copyright (C) 2008 KnowledgeTree Inc. * Portions copyright The Jam Warehouse Software (Pty) Limited - * + * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the * Free Software Foundation. - * + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, + * + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, * California 94120-7775, or email info@knowledgetree.com. - * + * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. - * + * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by - * KnowledgeTree" logo and retain the original copyright notice. If the display of the + * KnowledgeTree" logo and retain the original copyright notice. If the display of the * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices - * must display the words "Powered by KnowledgeTree" and retain the original + * must display the words "Powered by KnowledgeTree" and retain the original * copyright notice. * Contributor( s): ______________________________________ * */ +require_once('AdminVersion.inc.php'); + class AdminVersionDashlet extends KTBaseDashlet { - var $oUser; var $sClass = 'ktError'; - + function AdminVersionDashlet(){ $this->sTitle = _kt('New Version Available'); } - - /*function is_active($oUser) { - $this->oUser = $oUser; - return true; - } - */ - - function is_active($oUser) { - $this->oUser = $oUser; - return Permission::userIsSystemAdministrator($oUser); + + function is_active($oUser) + { + $this->version = AdminVersion::isNewVersionAvailable(); + return true; + if ($this->version === false) + { + return false; + } + return Permission::userIsSystemAdministrator(); } - + function render() { global $main; - $main->requireJSResource("plugins/ktstandard/AdminVersionPlugin/js/update.js"); - - $oPlugin =& $this->oPlugin; - + $oTemplating =& KTTemplating::getSingleton(); - $oTemplate = $oTemplating->loadTemplate('AdminVersionPlugin/dashlet'); - + $oTemplate = $oTemplating->loadTemplate('dashlet'); + + $name = $this->version['name']; + $version = $this->version['version']; + $aTemplateData = array( 'context' => $this, - 'url' => $oPlugin->getPagePath('versions'), - + 'name' => $name, + 'version' => $version ); - - + return $oTemplate->render($aTemplateData); } } diff --git a/plugins/ktstandard/AdminVersionPlugin/AdminVersionPage.php b/plugins/ktstandard/AdminVersionPlugin/AdminVersionPage.php deleted file mode 100644 index 1f0d4b4..0000000 --- a/plugins/ktstandard/AdminVersionPlugin/AdminVersionPage.php +++ /dev/null @@ -1,210 +0,0 @@ -. - * - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, - * California 94120-7775, or email info@knowledgetree.com. - * - * The interactive user interfaces in modified source and object code versions - * of this program must display Appropriate Legal Notices, as required under - * Section 5 of the GNU General Public License version 3. - * - * In accordance with Section 7(b) of the GNU General Public License version 3, - * these Appropriate Legal Notices must retain the display of the "Powered by - * KnowledgeTree" logo and retain the original copyright notice. If the display of the - * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices - * must display the words "Powered by KnowledgeTree" and retain the original - * copyright notice. - * Contributor( s): ______________________________________ - * - */ - - -require_once(KT_LIB_DIR . "/plugins/plugin.inc.php"); -require_once(KT_LIB_DIR . "/plugins/pluginregistry.inc.php"); -require_once(KT_LIB_DIR . "/dashboard/dashlet.inc.php"); - -define('KT_VERSION_URL', 'http://version.knowledgetree.com/kt_versions'); - -class AdminVersionPage extends KTStandardDispatcher { - - function _checkCache() { - global $default; - $iLastCheck = KTUtil::getSystemSetting('ktadminversion_lastcheck'); - if (empty($iLastCheck)) { - return; - } - $sLastValue = KTUtil::getSystemSetting('ktadminversion_lastvalue'); - if (empty($sLastValue)) { - $now = time(); - $diff = $now - $iLastCheck; - if ($diff > (24*60*60)) { - return; - } - } - $now = time(); - $diff = $now - $iLastCheck; - if ($diff > (24*60*60)) { - return; - } - return $sLastValue; - } - - function do_main() { - session_write_close(); - - $sCache = $this->_checkCache(); - if (!is_null($sCache)) { - $sCachedVersion = $sCache; - - $sVName = ""; - $sVNum = ""; - - $sTrimmer = str_replace('{', '', str_replace('}', '', str_replace('\'', '', $sCachedVersion))); - $aCachedVersionsTemp = explode(',',$sTrimmer); - - for($i=0;$i"; - print_r($aCachedVersions); - echo ""; - echo "
";
-        	print_r($aVersions);
-        	echo "
"; - exit; -*/ - - foreach ($aVersions as $k => $v) { - foreach($aCachedVersions as $j => $l) { - if (($k == $j) && (version_compare($aVersions[$k], $aCachedVersions[$j]) == -1)) - { - //save new name and version - $sVName = $j; - $sVNum = $l; - } - }//end foreach - - }//end foreach - - if ($sVName != "") - { - return "
"; - } - else - { - return ""; - } - } - - $sUrl = KT_VERSION_URL; - $aVersions = KTUtil::getKTVersions(); - - foreach ($aVersions as $k => $v) { - $sUrl .= '?' . sprintf("%s=%s", $k, $v); - } - $sIdentifier = KTUtil::getSystemIdentifier(); - $sUrl .= '&' . sprintf("system_identifier=%s", $sIdentifier); - - if (!function_exists('curl_init')) { - if (OS_WINDOWS) { - return ""; - } - - $stuff = @file_get_contents($sUrl); - if ($stuff === false) { - $stuff = ""; - } - } else { - - $ch = @curl_init($sUrl); - if (!$ch) { - return ""; - } - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_TIMEOUT, 10); - $stuff = curl_exec($ch); - curl_close($ch); - if (!$stuff) { - $stuff = ""; - } - } - KTUtil::setSystemSetting('ktadminversion_lastcheck', time()); - KTUtil::setSystemSetting('ktadminversion_lastvalue', (string)$stuff); - - $sVName = ""; - $sVNum = ""; - - $trim_stuff = str_replace('{', '', str_replace('}', '', str_replace('\'', '', $stuff))); - $aRemoteVersionstemp = explode(',',$trim_stuff); - - for($i=0;$i"; - print_r($aRemoteVersions); - echo ""; - echo "
";
-        	print_r($aVersions);
-        echo "
"; - exit; -*/ - foreach ($aVersions as $k => $v) { - foreach($aRemoteVersions as $j => $l) { - if (($k == $j) && (version_compare($aVersions[$k], $aRemoteVersions[$j]) == -1)) - { - //save new name and version - $sVName = $j; - $sVNum = $l; - } - } - } - - if ($sVName != "") - { - return "
"; - } - else - { - return ""; - } - } - - function handleOutput($sOutput) { - print $sOutput; - } -} - -?> \ No newline at end of file diff --git a/plugins/ktstandard/AdminVersionPlugin/AdminVersionPlugin.php b/plugins/ktstandard/AdminVersionPlugin/AdminVersionPlugin.php index 8a84ab5..c45f24d 100644 --- a/plugins/ktstandard/AdminVersionPlugin/AdminVersionPlugin.php +++ b/plugins/ktstandard/AdminVersionPlugin/AdminVersionPlugin.php @@ -6,63 +6,63 @@ * Document Management Made Simple * Copyright (C) 2008 KnowledgeTree Inc. * Portions copyright The Jam Warehouse Software (Pty) Limited - * + * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the * Free Software Foundation. - * + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, + * + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, * California 94120-7775, or email info@knowledgetree.com. - * + * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. - * + * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by - * KnowledgeTree" logo and retain the original copyright notice. If the display of the + * KnowledgeTree" logo and retain the original copyright notice. If the display of the * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices - * must display the words "Powered by KnowledgeTree" and retain the original + * must display the words "Powered by KnowledgeTree" and retain the original * copyright notice. * Contributor( s): ______________________________________ * */ - + require_once(KT_LIB_DIR . "/plugins/plugin.inc.php"); require_once(KT_LIB_DIR . "/plugins/pluginregistry.inc.php"); +require_once(KT_LIB_DIR . "/templating/templating.inc.php"); class AdminVersionPlugin extends KTPlugin { var $sNamespace = 'ktstandard.adminversion.plugin'; var $autoRegister = true; - + function AdminVersionPlugin($sFilename = null) { - + $res = parent::KTPlugin($sFilename); $this->sFriendlyName = _kt('Admin Version Notifier'); return $res; - + } - + function setup() { - + $this->registerDashlet('AdminVersionDashlet', 'ktstandard.adminversion.dashlet', 'AdminVersionDashlet.php'); - $this->registerPage('versions', 'AdminVersionPage', 'AdminVersionPage.php'); - - require_once(KT_LIB_DIR . "/templating/templating.inc.php"); + $oTemplating =& KTTemplating::getSingleton(); $oTemplating->addLocation('AdminVersionDashlet', '/plugins/ktstandard/AdminVersionPlugin/templates'); } } + $oPluginRegistry =& KTPluginRegistry::getSingleton(); $oPluginRegistry->registerPlugin('AdminVersionPlugin', 'ktstandard.adminversion.plugin', __FILE__); -?> +?> \ No newline at end of file diff --git a/plugins/ktstandard/AdminVersionPlugin/bin/UpdateNewVersion.php b/plugins/ktstandard/AdminVersionPlugin/bin/UpdateNewVersion.php new file mode 100644 index 0000000..ae01a20 --- /dev/null +++ b/plugins/ktstandard/AdminVersionPlugin/bin/UpdateNewVersion.php @@ -0,0 +1,45 @@ +. + * + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, + * California 94120-7775, or email info@knowledgetree.com. + * + * The interactive user interfaces in modified source and object code versions + * of this program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU General Public License version 3. + * + * In accordance with Section 7(b) of the GNU General Public License version 3, + * these Appropriate Legal Notices must retain the display of the "Powered by + * KnowledgeTree" logo and retain the original copyright notice. If the display of the + * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices + * must display the words "Powered by KnowledgeTree" and retain the original + * copyright notice. + * Contributor( s): ______________________________________ + * + */ + +chdir(dirname(__FILE__)); +require_once(realpath('../../../../config/dmsDefaults.php')); +require_once('../AdminVersion.inc.php'); + +AdminVersion::refresh(); + diff --git a/plugins/ktstandard/AdminVersionPlugin/js/update.js b/plugins/ktstandard/AdminVersionPlugin/js/update.js deleted file mode 100644 index d1daf0e..0000000 --- a/plugins/ktstandard/AdminVersionPlugin/js/update.js +++ /dev/null @@ -1,38 +0,0 @@ -var currloc = location.pathname.substring(0,location.pathname.lastIndexOf('/')+1); -var user = ''; - -function CheckVersion(){ - xmlHttpAdmin=GetXmlHttpAdminObject(); - if (xmlHttpAdmin===null){ - alert ("Browser does not support HTTP Request"); - return; - } - var url=VERSIONS_URL; - - xmlHttpAdmin.onreadystatechange=adminStateChanged; - xmlHttpAdmin.open("GET",url,true); - xmlHttpAdmin.send(null); - -} - -function adminStateChanged(){ - if (xmlHttpAdmin.readyState==4 || xmlHttpAdmin.readyState=="complete"){ - if(xmlHttpAdmin.responseText != ""){ - document.getElementById("AdminVersionDashlet").style.display = "block"; - document.getElementById("AdminVersionBlock").innerHTML=xmlHttpAdmin.responseText; - } - }else{ - //dashlet not shown until new version is returned so this print isn't needed - //document.getElementById("AdminVersionBlock").innerHTML="Checking Versions"; - } -} - -function GetXmlHttpAdminObject(){ - var objXMLHttpAdmin=null; - if (window.XMLHttpRequest){ - objXMLHttpAdmin=new XMLHttpRequest(); - }else if (window.ActiveXObject){ - objXMLHttpAdmin=new ActiveXObject("Microsoft.XMLHTTP"); - } - return objXMLHttpAdmin; -} \ No newline at end of file diff --git a/plugins/ktstandard/AdminVersionPlugin/templates/AdminVersionPlugin/computer_go.png b/plugins/ktstandard/AdminVersionPlugin/templates/computer_go.png index 0b26144..0b26144 100644 --- a/plugins/ktstandard/AdminVersionPlugin/templates/AdminVersionPlugin/computer_go.png +++ b/plugins/ktstandard/AdminVersionPlugin/templates/computer_go.png diff --git a/plugins/ktstandard/AdminVersionPlugin/templates/AdminVersionPlugin/dashlet.smarty b/plugins/ktstandard/AdminVersionPlugin/templates/dashlet.smarty index 6c71ea0..b2b3a5b 100644 --- a/plugins/ktstandard/AdminVersionPlugin/templates/AdminVersionPlugin/dashlet.smarty +++ b/plugins/ktstandard/AdminVersionPlugin/templates/dashlet.smarty @@ -1,37 +1,26 @@ -{literal} - - - -{/literal} - - - -
-
- The following upgrade is available: -
-
- -
- +{literal} + + + +{/literal} + +
+
+ The following upgrade is available: +
+
\ No newline at end of file diff --git a/plugins/ktstandard/AdminVersionPlugin/test/checkVersion.php b/plugins/ktstandard/AdminVersionPlugin/test/checkVersion.php new file mode 100644 index 0000000..74e224c --- /dev/null +++ b/plugins/ktstandard/AdminVersionPlugin/test/checkVersion.php @@ -0,0 +1,50 @@ +. + * + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, + * California 94120-7775, or email info@knowledgetree.com. + * + * The interactive user interfaces in modified source and object code versions + * of this program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU General Public License version 3. + * + * In accordance with Section 7(b) of the GNU General Public License version 3, + * these Appropriate Legal Notices must retain the display of the "Powered by + * KnowledgeTree" logo and retain the original copyright notice. If the display of the + * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices + * must display the words "Powered by KnowledgeTree" and retain the original + * copyright notice. + * Contributor( s): ______________________________________ + * + */ + +chdir(dirname(__FILE__)); +require_once(realpath('../../../../config/dmsDefaults.php')); +require_once('../AdminVersion.inc.php'); + +$version = AdminVersion::isNewVersionAvailable(); + +if ($version == false) +print 'No new version available.'; +else +print_r($version); + diff --git a/plugins/ktstandard/AdminVersionPlugin/test/latestVersion.php b/plugins/ktstandard/AdminVersionPlugin/test/latestVersion.php new file mode 100644 index 0000000..cbace13 --- /dev/null +++ b/plugins/ktstandard/AdminVersionPlugin/test/latestVersion.php @@ -0,0 +1,48 @@ +. + * + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, + * California 94120-7775, or email info@knowledgetree.com. + * + * The interactive user interfaces in modified source and object code versions + * of this program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU General Public License version 3. + * + * In accordance with Section 7(b) of the GNU General Public License version 3, + * these Appropriate Legal Notices must retain the display of the "Powered by + * KnowledgeTree" logo and retain the original copyright notice. If the display of the + * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices + * must display the words "Powered by KnowledgeTree" and retain the original + * copyright notice. + * Contributor( s): ______________________________________ + * + */ + +// NOTE: this is a test script. The values are for test purposes only. + +$versions = array( +'Development OSS'=> '3.5' +); + +print json_encode($versions); + +?> \ No newline at end of file diff --git a/sql/mysql/install/data.sql b/sql/mysql/install/data.sql index d7c3977..9d999c3 100644 --- a/sql/mysql/install/data.sql +++ b/sql/mysql/install/data.sql @@ -932,7 +932,8 @@ INSERT INTO `scheduler_tasks` VALUES (5,'Database Maintenance','bin/dbmaint.php','optimize',0,'monthly','2007-10-01',NULL,0,'disabled'), (6,'Open Office test','bin/checkopenoffice.php','',0,'1min','2007-10-01',NULL,0,'enabled'), (7,'Cleanup Temporary Directory','search2/bin/cronCleanup.php','',0,'1min','2007-10-01',NULL,0,'enabled'), -(8,'Disk Usage and Folder Utilisation Statistics','plugins/housekeeper/bin/UpdateStats.php','',0,'5mins','2007-10-01',NULL,0,'enabled'); +(8,'Disk Usage and Folder Utilisation Statistics','plugins/housekeeper/bin/UpdateStats.php','',0,'5mins','2007-10-01',NULL,0,'enabled'), +(9,'Check Latest Version','plugins/ktstandard/AdminVersionPlugin/bin/UpdateNewVersion.php','',0,'daily','2007-10-01',NULL,0,'enabled'); /*!40000 ALTER TABLE `scheduler_tasks` ENABLE KEYS */; UNLOCK TABLES; @@ -1846,7 +1847,7 @@ UNLOCK TABLES; LOCK TABLES `zseq_scheduler_tasks` WRITE; /*!40000 ALTER TABLE `zseq_scheduler_tasks` DISABLE KEYS */; -INSERT INTO `zseq_scheduler_tasks` VALUES (7); +INSERT INTO `zseq_scheduler_tasks` VALUES (9); /*!40000 ALTER TABLE `zseq_scheduler_tasks` ENABLE KEYS */; UNLOCK TABLES; diff --git a/sql/mysql/upgrade/3.5.2/zdashboard_tasks.sql b/sql/mysql/upgrade/3.5.2/zdashboard_tasks.sql index 0ce5c90..4351aec 100644 --- a/sql/mysql/upgrade/3.5.2/zdashboard_tasks.sql +++ b/sql/mysql/upgrade/3.5.2/zdashboard_tasks.sql @@ -1,4 +1,7 @@ select @id:=max(id)+1 from scheduler_tasks; INSERT INTO `scheduler_tasks` VALUES (@id,'Disk Usage and Folder Utilisation Statistics','plugins/housekeeper/bin/UpdateStats.php','',0,'5mins','2007-10-01',NULL,0,'enabled'); +select @id:=max(id)+1 from scheduler_tasks; +INSERT INTO `scheduler_tasks` VALUES (@id,'Check Latest Version','plugins/ktstandard/AdminVersionPlugin/bin/UpdateNewVersion.php','',0,'daily','2007-10-01',NULL,0,'enabled'); + UPDATE zseq_scheduler_tasks set id=@id; \ No newline at end of file