Deutschland United States United Kingdom
ContentLion - Open Source CMS

Compare Revisions

Ignore whitespace Rev 4 → Rev 5

/deactivate.php
File deleted
\ No newline at end of file
/info.php
File deleted
\ No newline at end of file
/activate.php
File deleted
\ No newline at end of file
/widget.php
File deleted
\ No newline at end of file
/trunk/deactivate.php
New file
0,0 → 1,3
<?PHP
WidgetController::unregister("updater/widget.php");
?>
/trunk/info.php
New file
0,0 → 1,12
<?PHP
$pluginInfo = new PluginInfo();
$pluginInfo->path = "updater";
$pluginInfo->name = "Updater";
$pluginInfo->authorName = "ContentLion";
$pluginInfo->authorLink = "http://contentlion.org";
$pluginInfo->version = "1.0.6";
$pluginInfo->license = "GPL 2";
$pluginInfo->licenseUrl = "http://www.gnu.org/licenses/gpl.html";
$pluginInfo->supportedLanguages = array("de","en");
$this->Add($pluginInfo);
?>
/trunk/interfaces/iupdatecommand.php
New file
0,0 → 1,7
<?PHP
interface IUpdateCommand {
public function runUpdate();
public function __toString();
public function load($commandString);
}
?>
/trunk/interfaces/iupdateimporter.php
New file
0,0 → 1,7
<?PHP
interface IUpdateImporter{
public function getUpdates();
public function importPath($path);
public function importCode($code);
}
?>
/trunk/activate.php
New file
0,0 → 1,5
<?PHP
WidgetController::register("Updater","Updater","updater/widget.php");
$row = DataBase::Current()->ReadField("SELECT IFNULL(MAX(row),0) + 1 FROM {'dbprefix'}dashboards WHERE col = 1");
DataBase::Current()->Execute("INSERT INTO `{'dbprefix'}dashboards` (alias,col,row,path) VALUES ('admin/home', 1, ".$row.", 'updater/widget.php');");
?>
/trunk/languages/en.php
New file
0,0 → 1,7
<?PHP
$tokens['plugin_description'] = 'Keeps ContentLion up to date';
$tokens['no_updates'] = 'No Updates available.';
$tokens['install'] = 'Install';
$tokens['install_it'] = 'Install';
$tokens['install_complete'] = 'Installation completed';
?>
/trunk/languages/de.php
New file
0,0 → 1,7
<?PHP
$tokens['plugin_description'] = 'Hält ContentLion auf dem aktuellen Stand';
$tokens['no_updates'] = 'Keine Updates vorhanden!';
$tokens['install'] = 'Installieren';
$tokens['install_it'] = 'Installiere';
$tokens['install_complete'] = 'Installation abgeschlossen';
?>
/trunk/widget.php
New file
0,0 → 1,43
<?PHP
class Updater extends WidgetBase{
public function load(){
$this->headline = "Updater";
include_once('interfaces/iupdateimporter.php');
include_once('interfaces/iupdatecommand.php');
if(Cache::contains("packages","all")){
$installedPackages = Cache::getData("packages","all");
}
else{
$installedPackages = Plugin_Updater_Package::readFromDB();
Cache::setData("packages","all",$installedPackages);
}
$path = "http://connect.contentlion.org/update.php?format=xml";
$i = 0;
if(is_array($installedPackages)){
foreach($installedPackages as $package){
$path .= "&".$package->getUpdateToken($i);
$i++;
}
}
$importer = new Plugin_Updater_UpdateXmlImporter();
$importer->importPath($path);
if($importer->areUpdatesAvailible()){
$host = Settings::getInstance()->get("host");
foreach($importer->getUpdates() as $update){
if(isset($_GET['update']) && $_GET['update'] == $update->getName()){
$this->content .= $update->getName()."..."."<br />";
$update->runUpdate();
Cache::clear();
$this->content .=htmlentities(Language::DirectTranslate("plugin_updater_install_complete"))."<br />";
}
else{
$this->content .= $update->getName()." - <a href='".UrlRewriting::GetUrlByAlias("admin/home","update=".$update->getName())."'>".Language::DirectTranslate("plugin_updater_install")."</a><br />";
}
}
}
else{
$this->content = Language::DirectTranslate("plugin_updater_no_updates");
}
}
}
?>
/trunk/classes/incrementversioncommand.php
New file
0,0 → 1,23
<?PHP
class Plugin_Updater_IncrementVersionCommand implements IUpdateCommand{
protected $package = "";
 
public function runUpdate(){
$name = $GLOBALS['db']->EscapeString($this->package);
$GLOBALS['db']->Execute("UPDATE {'dbprefix'}packages SET version = version + 1 WHERE name = '".$name."'");
}
 
public function setPackage($package){
$this->package = trim($package);
}
 
public function __toString(){
return "IncrementVersion:".$this->package;
}
 
public function load($commandString){
$this->setPackage(substr($commandString,17));
return $this;
}
}
?>
/trunk/classes/package.php
New file
0,0 → 1,45
<?PHP
class Plugin_Updater_Package {
protected $name;
protected $version;
 
public function setName($name){
$this->name = $name;
}
 
public function getName(){
return $this->name;
}
 
public function setVersion($version){
$this->version = $version;
}
 
public function getVersion(){
return $this->version;
}
 
public function getUpdateToken($id){
return "package".urlencode($id)."=".urlencode($this->name)."&version".urlencode($id)."=".$this->version;
}
 
public static function readFromDB(){
$res = array();
$i = 0;
 
$rows = $GLOBALS['db']->ReadRows("SELECT name, version FROM {'dbprefix'}packages");
if($rows){
foreach($rows as $row){
$package = new Plugin_Updater_Package();
$package->setName($row->name);
$package->setVersion($row->version);
$res[] = $package;
$i++;
}
}
 
return $res;
}
 
}
?>
/trunk/classes/removedircommand.php
New file
0,0 → 1,22
<?PHP
class Plugin_Updater_RemoveDirCommand implements IUpdateCommand{
protected $path = "";
 
public function runUpdate(){
@rmdir($this->path);
}
 
public function setPath($path){
$this->path = $path;
}
 
public function __toString(){
return "RemoveDir:".$this->path;
}
 
public function load($commandString){
$this->setPath(substr($commandString,10));
return $this;
}
}
?>
/trunk/classes/sqlcommand.php
New file
0,0 → 1,22
<?PHP
class Plugin_Updater_SqlCommand implements IUpdateCommand{
protected $text = "";
public function setText($text){
$this->text = $text;
}
 
public function runUpdate(){
$GLOBALS['db']->Execute($this->text);
}
 
public function __toString(){
return "Sql:".$this->text;
}
 
public function load($commandString){
$this->setText(substr($commandString,4));
return $this;
}
}
?>
/trunk/classes/updatepackage.php
New file
0,0 → 1,50
<?PHP
class Plugin_Updater_UpdatePackage{
public $commandText = "";
public $commands = array();
public $path = "";
public $name = "";
 
public static function get($path){
$res = new Plugin_Updater_UpdatePackage();
$source=fopen($path,"r");
while ($a=fread($source,1024)){
$res->commandText .= $a;
}
fclose($source);
$commands = preg_split( '/\r\n|\r|\n/', $string, $res->commandText);
foreach($commands as $line){
$command = Plugin_Updater_CommandFactory::getCommandByCommandText($line);
if($command != null){
$command->load($line);
$res->commands[] = $command;
}
}
$res->path = $path;
return $res;
}
 
public function getName(){
return $this->name;
}
 
public function setName($name){
$this->name = $name;
}
 
public function getPath(){
return $this->path;
}
 
public function setPath($path){
$this->path = $path;
}
 
public function runUpdate(){
foreach($this->commands as $command){
$command->runUpdate();
}
}
 
}
?>
/trunk/classes/unlinkcommand.php
New file
0,0 → 1,22
<?PHP
class Plugin_Updater_UnLinkCommand implements IUpdateCommand{
protected $path = "";
 
public function runUpdate(){
@unlink($this->path);
}
 
public function setPath($path){
$this->path = $path;
}
 
public function __toString(){
return "UnLink:".$this->path;
}
 
public function load($commandString){
$this->setPath(substr($commandString,7));
return $this;
}
}
?>
/trunk/classes/includecommand.php
New file
0,0 → 1,22
<?PHP
class Plugin_Updater_IncludeCommand implements IUpdateCommand{
protected $path = "";
 
public function runUpdate(){
include(Settings::getInstance()->get('root').$this->path);
}
 
public function setPath($path){
$this->path = $path;
}
 
public function __toString(){
return "Include:".$this->path;
}
 
public function load($commandString){
$this->setPath(substr($commandString,8));
return $this;
}
}
?>
/trunk/classes/filetransfercommand.php
New file
0,0 → 1,35
<?PHP
class Plugin_Updater_FileTransferCommand implements IUpdateCommand{
protected $fromPath = "";
protected $toPath = "";
 
public function runUpdate(){
$destination=fopen(Settings::getInstance()->get("root").$this->toPath,"w");
$source=fopen($this->fromPath,"r");
while ($a=fread($source,1024)){
fwrite($destination,$a);
}
fclose($source);
fclose($destination);
}
 
public function setFromPath($path){
$this->fromPath = $path;
}
 
public function setToPath($path){
$this->toPath = $path;
}
 
public function __toString(){
return "FileTransfer:".$this->fromPath.";".$this->toPath;
}
 
public function load($commandString){
$command = explode(';',substr($commandString,13));
$this->setFromPath($command[0]);
$this->setToPath($command[1]);
return $this;
}
}
?>
/trunk/classes/mkdircommand.php
New file
0,0 → 1,25
<?PHP
class Plugin_Updater_MkdirCommand implements IUpdateCommand{
protected $path = "";
 
public function runUpdate(){
$path = Settings::getInstance()->get('root')."/".$this->path;
if(!file_exists($path)){
mkdir($path);
}
}
 
public function setPath($path){
$this->path = $path;
}
 
public function __toString(){
return "Mkdir:".$this->path;
}
 
public function load($commandString){
$this->setPath(substr($commandString,6));
return $this;
}
}
?>
/trunk/classes/updatexmlimporter.php
New file
0,0 → 1,41
<?PHP
class Plugin_Updater_UpdateXmlImporter implements IUpdateImporter{
protected $updates = array();
 
public function getUpdates(){
return $this->updates;
}
 
public function importPath($path){
if($source=@fopen($path,"r")){
$text = "";
while ($a=fread($source,1024)){
$text .= $a;
}
fclose($source);
return $this->importCode($text);
}
}
 
public function importCode($code){
$xml = new SimpleXMLElement($code);
$updates = array();
foreach($xml->xpath('/contentlionupdates/update') as $update){
$package = Plugin_Updater_UpdatePackage::get($update->path);
$package->setName($update->name);
$updates[] = $package;
if(strtolower($package->getName()) == "plugin_updater"){
$this->updates[] = $package;
}
}
if(!$this->areUpdatesAvailible() && sizeof($updates) > 0){
$this->updates = $updates;
}
return $this;
}
 
public function areUpdatesAvailible(){
return sizeof($this->updates) > 0;
}
}
?>
/trunk/classes/commandfactory.php
New file
0,0 → 1,19
<?PHP
class Plugin_Updater_CommandFactory{
 
public static function getCommandByName($name){
$res = null;
$name = "Plugin_Updater_".$name."Command";
if(class_exists($name)){
$res = new $name();
}
return $res;
}
 
public static function getCommandByCommandText($text){
$parts = explode(':',$text);
return self::getCommandByName($parts[0]);
}
 
}
?>