]> git.mjollnir.org Git - s9y.git/commitdiff
* Fix UTF-8 problems of Spartacus,
authorgarvinhicking <garvinhicking>
Tue, 4 Oct 2005 10:46:24 +0000 (10:46 +0000)
committergarvinhicking <garvinhicking>
Tue, 4 Oct 2005 10:46:24 +0000 (10:46 +0000)
* Allow changing permission masks

docs/NEWS
plugins/serendipity_event_spartacus/serendipity_event_spartacus.php

index c58b7f1c3d34b9770a2dc4ad88534ac5bcfb335f..767bc37716dd9aacb0231c8a6afd1b3372880991 100644 (file)
--- 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)
 
index a0a2490048c0257605a8c8e0692518015ce6cb06..5c2c7c75acd25367c43e1c92c27a195ade40a449 100644 (file)
@@ -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('<?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;
@@ -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;
         }