Thread: [Phpcms-plugins-cvs] download4phpCMS download4phpcms.php,NONE,1.1 .cvsignore,NONE,1.1
Brought to you by:
mjahn
From: Martin J. <mj...@us...> - 2005-02-23 23:54:33
|
Update of /cvsroot/phpcms-plugins/download4phpCMS In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12679 Added Files: download4phpcms.php .cvsignore Log Message: initial import --- NEW FILE: .cvsignore --- smarty* .project --- NEW FILE: download4phpcms.php --- <?php /** * download4phpCMS * * <b>License</b> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * @author Martin Jahn <mj...@us...> * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @copyright Copyright (c) 2005, Martin Jahn * @version $Id: download4phpcms.php,v 1.1 2005/02/23 23:54:23 mjahn Exp $ * @package downlod4phpCMS */ /* * $Log: download4phpcms.php,v $ * Revision 1.1 2005/02/23 23:54:23 mjahn * initial import * */ global $DEFAULTS; define ('SMARTYDIR', $_SERVER ['DOCUMENT_ROOT'].'/cms/admin/modules/layout/smarty/'); $databasedir = $_SERVER ['DOCUMENT_ROOT'].'/cms/data/download/'; $datadirs = array ('plugins'=>'plugins', 'screenshots'=>'screenshots', 'other'=>'other'); $templatedir = dirname (__FILE__).'/templates'; $cachedir = $_SERVER ['DOCUMENT_ROOT'].'/cms/parser/temp/'; $template = 'default.tpl'; $data = array (); $_datadir = ''; if (isset ($_GET ['datadir']) && isset ($datadirs [$_GET ['datadir']]) && is_dir ($databasedir.'/'.$datadirs [$_GET ['datadir']])) { $datadir = $databasedir.$datadirs [$_GET ['datadir']]; $_datadir = $_GET ['datadir']; } else { $datadir = $databasedir; } if (isset ($_GET ['package']) && trim ($_GET ['package']) != '') { list ($_package,) = explode ('/', strip_tags ($_GET ['package'], 2)); if (file_exists ($datadir.'/'.$_package)) { $package = $_package; } } if (isset ($_GET ['version']) && trim ($_GET ['version']) != '') { list ($version,) = explode ('/', strip_tags ($_GET ['version'], 2)); } if (isset ($_GET ['template']) && trim ($_GET ['template']) != '') { list ($_template,) = explode ('/', strip_tags ($_GET ['template'], 2)); if (file_exists ($templatedir.'/'.$_template.'.tpl')) { $template = $_template.'.tpl'; } } if (isset ($_GET ['dl']) && isset ($version) && isset ($package)) { $data = readPackage ($datadir.'/'.$package); if (!isset ($data ['versions'] [$version])) { return true; } $data ['versions'] [$version] ['counter'] = $data ['versions'] [$version] ['counter'] + 1; writePackage ($datadir.'/'.$package, $data); header ('Location: '.$data ['versions'] [$version] ['link']); return true; } function readPackage ($filename) { $data = array ('versions'=>array ()); $_data = parse_ini_file ($filename, true); foreach ($_data as $key=>$value) { if (!is_array ($value)) { $data [$key] = $value; continue; } if ($key == '__common') { foreach ($value as $id=>$value1) { $data [$id] = $value1; } continue; } $data ['versions'] [$key] = $value; } return $data; } function write_ini_file($path, $assoc_array) { foreach($assoc_array as $key => $item) { if(is_array($item)) { $content .= "\n[{$key}]\n"; foreach ($item as $key2 => $item2) { if(is_numeric($item2) || is_bool($item2)) $content .= "{$key2} = {$item2}\n"; else $content .= "{$key2} = \"{$item2}\"\n"; } } else { if(is_numeric($item) || is_bool($item)) $content .= "{$key} = {$item}\n"; else $content .= "{$key} = \"{$item}\"\n"; } } if(!$handle = fopen($path, 'w')) { return false; } if(!fwrite($handle, $content)) { return false; } fclose($handle); return true; } function writePackage ($filename, $data) { $_data = array (); $_versions = array (); foreach ($data as $id => $value) { if ($id == 'versions') { foreach ($value as $version=>$versiondata) { $_versions [$version] = $versiondata; } continue; } $_data [$id] = $value; } $_data = array_merge ($_versions, array ('__common'=>$_data)); return write_ini_file ($filename, $_data); } $dir = opendir ($datadir); while (false !== ($file = readdir ($dir))) { if ($file {0} == '.' || !is_readable ($datadir.'/'.$file) || !is_file ($datadir.'/'.$file)) { continue; } if (isset ($package) && $package != $file) { continue; } $data [$file] = readPackage ($datadir.'/'.$file); } closedir ($dir); //asort ($data); include_once (SMARTYDIR.'/Smarty.class.php'); $smarty =& new Smarty; $smarty->template_dir = $templatedir; $smarty->compile_dir = $cachedir; $smarty->cache_dir = $cachedir; $smarty->caching = false; $smarty->cache_lifetime = 300; $smarty->assign ('lang', $_GET ['lang']); $smarty->assign ('data', $data); $smarty->assign ('datadir', $_datadir); $smarty->display ($template); ?> |