Update of /cvsroot/php-blog/additional_plugins
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14334
Added Files:
emerge_spartacus.php
Log Message:
Initial groundwork for
[S]erendipity
[P]lugin
[A]ccess
[R]epository
[T]ool
[A]nd
[C]ustomization/
[U]nification
[S]ystem
(see mailinglist)
--- NEW FILE: emerge_spartacus.php ---
<?php # $Id: emerge_spartacus.php,v 1.1 2004/12/29 14:05:06 garvinhicking Exp $
/* This file creates a package XML file for all additional_plugins CVS files
*
* It can only be run by authorized users on special machines. The file
* emerge_spartacus.dat contains the username:password information to mirror servers
*/
header('Content-Type: text/plain');
class emerge_spartacus {
var $helper;
var $pluginpath;
var $plugins = array();
var $xmlData = array();
function emerge_spartacus() {
// Load Serendipity Framework
$serendipity = array();
$serendipity['serendipityPath'] = '/home/garvin/cvs/serendipity/serendipity_MERGE/';
$serendipity['dbType'] = 'mysql';
define('IN_serendipity', true);
define('S9Y_INCLUDE_PATH', $serendipity['serendipityPath']);
include_once S9Y_INCLUDE_PATH . 'include/plugin_api.inc.php';
}
function init() {
$this->pluginpath = dirname(__FILE__);
}
function load_plugin(&$plugins) {
foreach($plugins AS $plugin_name => $plugin_data) {
$path = $this->pluginpath . '/' . $plugin_data['pluginPath'] . '/';
include_once $path . $plugin_data['name'] . '.php';
$plugins[$plugin_name]['plugin'] =& new $plugin_data['name']($plugin_name);
$plugin =&$plugins[$plugin_name]['plugin'];
if (is_object($plugin)) {
$bag = new serendipity_property_bag;
$plugin->introspect($bag);
$plugins[$plugin_name]['properties'] = $bag->properties;
$plugins[$plugin_name]['files'] = $this->get_files($plugin_data['pluginPath']);
echo 'Successfully loaded plugin ' . $plugin_name . "\n";
} else {
echo 'Error loading plugin ' . $plugin_name . ' (' . $plugin_data['pluginPath'] . ')' . "\n";
}
}
}
function get_files($path, $init = true) {
if ($init) {
$this->helper = array('full' => array(), 'xml' => '');
}
if (is_dir($path)) {
if ($d = opendir($path)) {
$this->helper['xml'] .= '<dir name="' . basename($path) . '">' . "\n";
while (($f = readdir($d)) !== false) {
if ($f{0} != '.' && $f != 'CVS') {
if (is_dir($path . '/' . $f)) {
$this->get_files($path . '/' . $f, false);
} else {
$this->helper['full'][] = $path . '/' . $f;
$this->helper['xml'] .= '<file>' . $f . '</file>' . "\n";
}
}
}
$this->helper['xml'] .= '</dir>' . "\n";
}
}
if ($init) {
return $this->helper;
}
}
function get_plugins() {
serendipity_plugin_api::traverse_plugin_dir($this->pluginpath, $this->plugins['event'], true);
serendipity_plugin_api::traverse_plugin_dir($this->pluginpath, $this->plugins['sidebar'], false);
$this->load_plugin($this->plugins['event']);
$this->load_plugin($this->plugins['sidebar']);
}
function emerge($key) {
$this->xmlData[$key] = array();
$x = &$this->xmlData[$key];
$x[] = '<?xml version="1.0" encoding="ISO-8859-1" ?>';
$x[] = '<!-- $Revision: 1.1 $ -->' . "\n";
$x[] = '<packages>';
foreach($this->plugins[$key] AS $plugin_name => $plugin_data) {
$version = isset($plugin_data['properties']['version']) ? $plugin_data['properties']['version'] : '1.0';
$license = isset($plugin_data['properties']['license']) ? $plugin_data['properties']['license'] : 'GPL';
$author = isset($plugin_data['properties']['author']) ? $plugin_data['properties']['author'] : 'Serendipity Team';
$x[] = '<package version="1.0">';
$x[] = '<name>' . $plugin_name . '</name>';
$x[] = '<license>' . $license . '</license>';
$x[] = '<summary>' . $plugin_data['properties']['name'] . '</summary>';
$x[] = '<description>' . $plugin_data['properties']['description'] . '</description>';
$x[] = '<maintainers><maintainer><name>' . $author . '</name><role>lead</role></maintainer></maintainers>';
$x[] = '<release>';
$x[] = ' <version>' . $version . '</version>';
$x[] = ' <date>' . date('Y-m-d', filemtime($plugin_data['pluginPath'] . '/' . $plugin_data['name'] . '.php')) . '</date>';
$x[] = ' <filelist>';
$x[] = $plugin_data['files']['xml'];
$x[] = ' </filelist>';
$x[] = ' <serendipityFilelist>';
foreach($plugin_data['files']['full'] AS $file) {
$x[] = ' <file>' . $file . '</file>';
}
$x[] = ' </serendipityFilelist>';
$x[] = '</release>';
$x[] = '</package>';
}
$x[] = '</packages>';
}
function output($key) {
$remotefile = 'package_' . $key . '.xml';
$file = dirname(__FILE__) . '/' . $remotefile;
$fp = fopen($file, 'w');
if ($fp) {
fwrite($fp, implode("\n", $this->xmlData[$key]));
fclose($fp);
}
if (function_exists('ftp_connect')) {
$c = ftp_connect('netmirror.org');
$data = explode(':', file_get_contents('emerge_spartacus.dat'));
$login = ftp_login($c, $data[0], $data[1]);
if ($c && $login) {
echo 'Uploading ' . $file . ' to ' . $remotefile . "\n";
ftp_put($c, $remotefile, $file, FTP_BINARY);
}
}
}
}
$spartacus = new emerge_spartacus;
$spartacus->init();
$spartacus->get_plugins();
$spartacus->emerge('event');
$spartacus->emerge('sidebar');
$spartacus->output('event');
$spartacus->output('sidebar');
|