Store hidden themes in the private dir.
authorJonas Häggqvist <rasher@rasher.dk>
Tue, 17 Mar 2009 23:23:28 +0000 (18 00:23 +0100)
committerJonas Häggqvist <rasher@rasher.dk>
Tue, 17 Mar 2009 23:23:28 +0000 (18 00:23 +0100)
private/templates/TODO
private/themesite.class.php

index a16128d..0853270 100644 (file)
@@ -1,6 +1,4 @@
 SHORT TERM (needed before going live)
- - Store hidden/unverified .zip files in the private dir, with an option for
-   admins to download them.
  - Make the templates less awful (help needed!)
 MID TERM (add as soon as possible)
  - Validate .cfg files
index ca6bd34..86b88b4 100644 (file)
@@ -31,7 +31,6 @@ class themesite {
         $this->db = new db($dbfile);
         $this->themedir_public = sprintf("%s/%s/%s", $_SERVER['DOCUMENT_ROOT'], config::path, config::datadir);
         $this->themedir_private = sprintf("%s/%s", preconfig::privpath, config::datadir);
-        printf("%s<br />\n%s<br />\n", $this->themedir_public, $this->themedir_private);
     }
 
     /*
@@ -179,7 +178,7 @@ class themesite {
             $status_text[$newstatus],
             $reason
         ));
-        $sql = sprintf("SELECT shortname, mainlcd, email, name, author FROM themes WHERE RowID='%d'", db::quote($themeid));
+        $sql = sprintf("SELECT shortname, mainlcd, email, name, author, zipfile FROM themes WHERE RowID='%d'", db::quote($themeid));
         $theme = $this->db->query($sql)->next();
 
         if ($newstatus == -1) {
@@ -188,16 +187,18 @@ class themesite {
             );
 
             /* Delete the files */
-            $dir = sprintf("%s/%s/%s",
-                config::datadir,
-                $theme['mainlcd'],
-                $theme['shortname']
-            );
-            if (file_exists($dir)) {
-                foreach(glob(sprintf("%s/*", $dir)) as $file) {
-                    unlink($file);
+            foreach(array($this->themedir_public, $this->themedir_private) as $root) {
+                $dir = sprintf("%s/%s/%s",
+                    $root,
+                    $theme['mainlcd'],
+                    $theme['shortname']
+                );
+                if (file_exists($dir)) {
+                    foreach(glob(sprintf("%s/*", $dir)) as $file) {
+                        unlink($file);
+                    }
+                    rmdir($dir);
                 }
-                rmdir($dir);
             }
         }
         else {
@@ -206,6 +207,14 @@ class themesite {
                 db::quote($reason),
                 db::quote($themeid)
             );
+            $from = sprintf("%s/%s/%s/%s", $this->themedir_public, $theme['mainlcd'], $theme['shortname'], $theme['zipfile']);
+            $to = sprintf("%s/%s/%s/%s", $this->themedir_private, $theme['mainlcd'], $theme['shortname'], $theme['zipfile']);
+            if ($newstatus == 1) {
+                $temp = $to;
+                $to = $from;
+                $from = $temp;
+            }
+            rename($from, $to);
         }
         if ($oldstatus == 1 && $newstatus < 1) {
             // Send a mail to notify the user that his theme has been
@@ -244,9 +253,12 @@ END;
             $remotelcd === false ? 'NULL' : sprintf("'%s'", db::quote($remotelcd))
         );
         $this->db->query($sql);
-        $themedir = sprintf("%s/%s", $this->themedir_public, $mainlcd);
-        if (!file_exists($themedir)) {
-            mkdir($themedir);
+        /* Create the target's dir in both the private and public theme dir */
+        foreach(array($this->themedir_public, $this->themedir_private) as $root) {
+            $themedir = sprintf("%s/%s", $root, $mainlcd);
+            if (!file_exists($themedir)) {
+                mkdir($themedir);
+            }
         }
     }
 
@@ -299,16 +311,21 @@ END;
         $err = array();
         /* return array("Skipping upload"); */
 
-        /* Create the destination dir */
+        /* Create the destination dir in both private and public area */
+        foreach(array($this->themedir_public, $this->themedir_private) as $root) {
+            mkdir(sprintf("%s/%s/%s",
+                $root,
+                $mainlcd,
+                $shortname
+            ));
+        }
+
+        /* This is the actual destination dir */
         $destdir = sprintf("%s/%s/%s",
-            $this->themedir_public,
+            config::defaultstatus == 1 ? $this->themedir_public : $this->themedir_private,
             $mainlcd,
             $shortname
         );
-        if (!file_exists($destdir) && !mkdir($destdir)) {
-            $err[] = sprintf("Couldn't create themedir %s", $destdir);
-            return $err;
-        }
         
         /* Prepend wps- and menu- to screenshots */
         $sshot_wps['name']  = empty($sshot_wps['name'])  ? '' : 'wps-'.$sshot_wps['name'];