@define('PLUGIN_EVENT_SPARTACUS_MIRROR_XML', 'File/Mirror location (XML metadata)');
@define('PLUGIN_EVENT_SPARTACUS_MIRROR_FILES', 'File/Mirror location (files)');
@define('PLUGIN_EVENT_SPARTACUS_MIRROR_DESC', 'Choose a download location. Do NOT change this value unless you know what you are doing and if servers get oudated. This option is available mainly for forward compatibility.');
+@define('PLUGIN_EVENT_SPARTACUS_CHOWN', 'Owner of downloaded files');
+@define('PLUGIN_EVENT_SPARTACUS_CHOWN_DESC', 'Here you can enter the (FTP/Shell) owner (like "nobody") of files downloaded by Spartacus. If empty, no changes are made to the ownership.');
+@define('PLUGIN_EVENT_SPARTACUS_CHMOD', 'Permissions downloaded files');
+@define('PLUGIN_EVENT_SPARTACUS_CHMOD_DESC', 'Here you can enter the octal mode (like "0777") of the file permissions for Spartacus files.(FTP/Shell) owner of files downloaded by Spartacus. If empty, the default permission mask of the system are used. Note that not all servers allow changing/setting permissions. Pay attention that the applied permissions allow reading and writing for the webserver user. Else spartacus/Serendipity cannot overwrite existing files.');
class serendipity_event_spartacus extends serendipity_event
{
$propbag->add('description', PLUGIN_EVENT_SPARTACUS_DESC);
$propbag->add('stackable', false);
$propbag->add('author', 'Garvin Hicking');
- $propbag->add('version', '2.2');
+ $propbag->add('version', '2.3');
$propbag->add('requirements', array(
'serendipity' => '0.9',
'smarty' => '2.6.7',
'backend_templates_fetchtemplate' => true
));
$propbag->add('groups', array('BACKEND_FEATURES'));
- $propbag->add('configuration', array('mirror_xml', 'mirror_files'));
+ $propbag->add('configuration', array('mirror_xml', 'mirror_files', 'chown', 'chmod'));
}
function generate_content(&$title) {
global $serendipity;
switch($name) {
+ case 'chmod':
+ $propbag->add('type', 'string');
+ $propbag->add('name', PLUGIN_EVENT_SPARTACUS_CHMOD);
+ $propbag->add('description', PLUGIN_EVENT_SPARTACUS_CHMOD_DESC);
+ $propbag->add('default', '');
+ break;
+
+ case 'chown':
+ $propbag->add('type', 'string');
+ $propbag->add('name', PLUGIN_EVENT_SPARTACUS_CHOWN);
+ $propbag->add('description', PLUGIN_EVENT_SPARTACUS_CHOWN_DESC);
+ $propbag->add('default', '');
+ break;
+
case 'mirror_xml':
$propbag->add('type', 'select');
$propbag->add('name', PLUGIN_EVENT_SPARTACUS_MIRROR_XML);
if (!is_dir($stack) && !mkdir($stack)) {
return false;
+ } else {
+ $this->fileperm($stack, true);
+ }
+ }
+
+ return true;
+ }
+
+ // Apply file permission settings.
+ function fileperm($stack, $is_dir) {
+ $chmod = octdec($this->get_config('chmod'));
+ $chown = $this->get_config('chown');
+
+ if (!empty($chmod) && function_exists('chmod')) {
+ @chmod($stack, $chmod);
+ if ($is_dir) {
+ @chmod($stack, 'ug+x'); // Always ensure directory traversal.
}
}
+
+ if (!empty($chown) && function_exists('chown')) {
+ $own = explode('.', $chown);
+ if (isset($own[1])) {
+ @chgrp($stack, $own[1]);
+ }
+ @chown($stack, $own[0]);
+ }
+
return true;
}
if ($decode_utf8) {
$data = str_replace('<?xml version="1.0" encoding="UTF-8" ?>', '<?xml version="1.0" encoding="' . LANG_CHARSET . '" ?>', $data);
- $this->decode($data);
+ $this->decode($data, true);
}
fwrite($fp, $data);
fclose($fp);
+
+ $this->fileperm($target, false);
+
echo PLUGIN_EVENT_SPARTACUS_FETCHED_DONE;
echo '<br />';
$this->purgeCache = true;
return $data;
}
- function decode(&$data) {
+ function decode(&$data, $force = false) {
// xml_parser_* functions to recoding from ISO-8859-1/UTF-8
- if (LANG_CHARSET == 'ISO-8859-1' || LANG_CHARSET == 'UTF-8') {
+ if ($force === false && (LANG_CHARSET == 'ISO-8859-1' || LANG_CHARSET == 'UTF-8')) {
return true;
}