From: garvinhicking Date: Tue, 4 Oct 2005 10:46:24 +0000 (+0000) Subject: * Fix UTF-8 problems of Spartacus, X-Git-Tag: 0.9~96 X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=40e20c50f43f975e6b3b4dde0f3980978b42f44c;p=s9y.git * Fix UTF-8 problems of Spartacus, * Allow changing permission masks --- diff --git a/docs/NEWS b/docs/NEWS index c58b7f1..767bc37 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -3,6 +3,10 @@ Version 0.9-beta2 () ------------------------------------------------------------------------ + * Spartacus can be configured to set file owner/permissions of + downloaded files via chown/chmod. Also fix UTF-8 problems in + non-UTF-8 environments. (garvinhicking) + * Allow per-author XML feeds, added bundled sidebar plugin to show (multiple) authors. (jtate) diff --git a/plugins/serendipity_event_spartacus/serendipity_event_spartacus.php b/plugins/serendipity_event_spartacus/serendipity_event_spartacus.php index a0a2490..5c2c7c7 100644 --- a/plugins/serendipity_event_spartacus/serendipity_event_spartacus.php +++ b/plugins/serendipity_event_spartacus/serendipity_event_spartacus.php @@ -25,6 +25,10 @@ if (file_exists($probelang)) { @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 { @@ -44,7 +48,7 @@ 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', @@ -58,7 +62,7 @@ class serendipity_event_spartacus extends serendipity_event '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) { @@ -124,6 +128,20 @@ class serendipity_event_spartacus extends serendipity_event 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); @@ -196,8 +214,34 @@ class serendipity_event_spartacus extends serendipity_event 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; } @@ -244,11 +288,14 @@ class serendipity_event_spartacus extends serendipity_event if ($decode_utf8) { $data = str_replace('', '', $data); - $this->decode($data); + $this->decode($data, true); } fwrite($fp, $data); fclose($fp); + + $this->fileperm($target, false); + echo PLUGIN_EVENT_SPARTACUS_FETCHED_DONE; echo '
'; $this->purgeCache = true; @@ -258,9 +305,9 @@ class serendipity_event_spartacus extends serendipity_event 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; }