]> git.mjollnir.org Git - s9y.git/commitdiff
Add pivot importer
authorgarvinhicking <garvinhicking>
Tue, 11 Apr 2006 09:56:41 +0000 (09:56 +0000)
committergarvinhicking <garvinhicking>
Tue, 11 Apr 2006 09:56:41 +0000 (09:56 +0000)
docs/NEWS
include/admin/importers/pivot.inc.php [new file with mode: 0644]
include/functions_smarty.inc.php

index 6a96623e971c26eab85281e11cbf47c066947408..426df1d5f2046b0e0dee0c9345a27da5cbed7101 100644 (file)
--- a/docs/NEWS
+++ b/docs/NEWS
@@ -10,15 +10,15 @@ Version 1.1-alpha1()
 
    * Make media manager able to store media properties (garvinhicking)
      TODO:
+        - Also delete properties when deleting an image
+        - Enforce permissions on readable files via ACL queries on the given directory/path
+        - Make JS emit the image ID somewhere in the <img> tag
+        - Make media selector smartyfied
         - Show more existing properties in edit interface [see TODO in file]
         - Read/Parse EXIF metadata, ask which to import [config option?]
         - Search/Filter for specific properties/keywords
-        - Enforce permissions on readable files
-        - Make JS emit the image ID somewhere in the <img> tag
-        - Move images/directories
-        - Also delete properties when deleting an image
-        - Create Smarty functions to access media properties by ID/filename
-        - Make media selector smartyfied
+        - Move/rename images/directories (browse serendipity_entries to fix up image paths [using <img src="..." />]. Also move ALL images of a directory, like when moving s9y installations. Put this into "Sync Thumbs" or "Manage Directories" panel.
+        ? Create Smarty functions to access media properties by ID/filename
 
    * Added directory tree view widget (JS) to the Media Selector
      (garvinhicking)
@@ -75,6 +75,8 @@ Version 1.1-alpha1()
 Version 1.0 ()
 ------------------------------------------------------------------------
 
+   * Added Pivot importer (garvinhicking)
+
    * The spamblock plugin now continues to check any comment/trackback
      set to MODERATE if maybe other rules override the status to
      REJECTED. This should reduce the amount of moderation mails that
diff --git a/include/admin/importers/pivot.inc.php b/include/admin/importers/pivot.inc.php
new file mode 100644 (file)
index 0000000..11edf7f
--- /dev/null
@@ -0,0 +1,202 @@
+<?php # $Id: generic.inc.php 717 2005-11-21 09:56:25Z garvinhicking $
+# Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity Developer Team)
+# All rights reserved.  See LICENSE file for licensing details
+
+# Loosely based on the Importer by Stefan Koopmanschap for TXP:
+# http://www.leftontheweb.com/pivot_to_textpattern.phps
+
+class Serendipity_Import_Pivot extends Serendipity_Import {
+    var $info        = array('software' => 'Pivot');
+    var $data        = array();
+    var $inputFields = array();
+
+    function Serendipity_Import_Pivot($data) {
+        $this->data = $data;
+        $this->inputFields = array(array('text'    => PARENT_DIRECTORY,
+                                         'type'    => 'input',
+                                         'name'    => 'pivot_path',
+                                         'default' => '/path/to/pivot/db/'),
+        );
+    }
+
+    function validateData() {
+        return sizeof($this->data);
+    }
+
+    function getInputFields() {
+        return $this->inputFields;
+    }
+
+    function _getCategoryList() {
+        $res = serendipity_fetchCategories('all');
+        $ret = array(0 => NO_CATEGORY);
+        if (is_array($res)) {
+            foreach ($res as $v) {
+                $ret[$v['categoryid']] = $v['category_name'];
+            }
+        }
+        return $ret;
+    }
+
+    function toTimestamp($string) {
+        if (empty($string)) {
+            return time();
+        }
+
+        $parts = explode('-', $string);
+        return mktime($parts[3], $parts[4], 0, $parts[1], $parts[2], $parts[0]);
+    }
+
+    function &unserialize($file) {
+        $c = file_get_contents($file);
+        $entrydata = str_replace(array('<?php /* pivot */ die(); ?>', "\r"), array('', ''), $c);
+        $entrydata = unserialize($entrydata);
+
+        if (empty($entrydata) || !is_array($entrydata)) {
+            $entrydata = str_replace(array('<?php /* pivot */ die(); ?>'), array(''), $c);
+            $entrydata = unserialize($entrydata);
+        }
+
+        return $entrydata;
+    }
+
+    function import() {
+        global $serendipity;
+
+        $max_import = 9999;
+
+        $serendipity['noautodiscovery'] = true;
+        if (!is_dir($this->data['pivot_path']) || !is_readable($this->data['pivot_path'])) {
+            $check_dir = $serendipity['serendipityPath'] . $this->data['pivot_path'];
+            if (!is_dir($check_dir) || !is_readable($check_dir)) {
+                return sprintf(ERROR_NO_DIRECTORY, $this->data['pivot_path']);
+            }
+            $this->data['pivot_path'] = $check_dir;
+        }
+
+        printf('<br />' . CHECKING_DIRECTORY . '<br /><br />', $this->data['pivot_path']);
+        if ($root = opendir($this->data['pivot_path'])) {
+            // Fetch category data:
+            $s9y_categories = serendipity_fetchCategories('all');
+            $categories     = $this->unserialize($this->data['pivot_path'] . '/ser-cats.php');
+            $pivot_to_s9y   = array(
+                'categories' => array()
+            );
+
+            foreach($categories AS $pivot_category_id => $category) {
+                $found = false;
+                $pivot_category = trim(stripslashes($category[0]));
+                foreach($s9y_categories AS $idx => $item) {
+                    if ($pivot_category == $item['category_name']) {
+                        $found = $item['categoryid'];
+                        break;
+                    }
+                }
+
+                if ($found) {
+                    echo '&middot; Pivot Category "' . htmlspecialchars($pivot_category) . '" mapped to Serendipity ID ' . $found . '<br />';
+                    $pivot_to_s9y['categories'][$pivot_category] = $found;
+                } else {
+                    echo '&middot; Created Pivot Category "' . htmlspecialchars($pivot_category) . '".<br />';
+                    $cat = array('category_name'        => $pivot_category,
+                                 'category_description' => '',
+                                 'parentid'             => 0,
+                                 'category_left'        => 0,
+                                 'category_right'       => 0);
+
+
+                    serendipity_db_insert('category', $cat);
+                    $pivot_to_s9y['categories'][$pivot_category] = serendipity_db_insert_id('category', 'categoryid');
+                }
+            }
+
+            $i = 0;
+            while (false !== ($dir = readdir($root))) {
+                if ($dir{0} == '.') continue;
+                if (substr($dir, 0, 8) == 'standard') {
+                    printf('&nbsp;&nbsp;&middot; ' . CHECKING_DIRECTORY . '...<br />', $dir);
+                    $data = $this->unserialize($this->data['pivot_path'] . '/' . $dir . '/index-' . $dir . '.php');
+
+                    if (empty($data) || !is_array($data) || count($data) < 1) {
+                        echo '&nbsp;&nbsp;&nbsp;&nbsp;&middot; <strong style="color: red">FATAL: File <em>' . $dir . '/index-' . $dir . '.php</em> has no data!</strong><br />';
+                        flush();
+                        ob_flush();
+                        continue;
+                    }
+
+                    foreach($data as $entry) {
+                        $entryid = str_pad($entry['code'], 5, '0', STR_PAD_LEFT);
+
+                        if ($i >= $max_import) {
+                            echo '&nbsp;&nbsp;&nbsp;&nbsp;&middot; Skipping entry data for #' . $entryid . '<br />';
+                            continue;
+                        }
+
+                        echo '&nbsp;&nbsp;&nbsp;&nbsp;&middot; Fetching entry data for #' . $entryid . '<br />';
+                        $entrydata = $this->unserialize($this->data['pivot_path'] . '/' . $dir . '/' . $entryid . '.php');
+                        if (empty($entrydata) || !is_array($entrydata) || count($entrydata) < 1) {
+                            echo '&nbsp;&nbsp;&nbsp;&nbsp;&middot; <strong style="color: red">FATAL: File <em>' . $dir . '/' . $entryid . '.php</em> has no data!</strong><br />';
+                            flush();
+                            ob_flush();
+                            continue;
+                        }
+
+                        $entry = array();
+                        $entry['title'] = trim(stripslashes($entrydata['title']));
+                        $entry['categories'] = array();
+                        if (is_array($entrydata['category'])) {
+                            foreach($entrydata['category'] AS $pivot_category) {
+                                $entry['categories'][] = $pivot_to_s9y['categories'][$pivot_category];
+                            }
+                        }
+                        $entry['timestamp']         = $this->toTimestamp($entrydata['date']);
+                        $entry['last_modified']     = (!empty($entrydata['edit_date']) ? $this->toTimestamp($entrydata['edit_date']) : $entry['timestamp']);
+                        $entry['isdraft']           = ($entrydata['status'] == 'publish' ? 'false' : 'true');
+                        $entry['body']              = stripslashes($entrydata['introduction']);
+                        $entry['extended']          = stripslashes($entrydata['body']);
+                        $entry['title']             = stripslashes($entrydata['title']);
+                        $entry['authorid']          = $serendipity['authorid'];
+                        $entry['author']            = $serendipity['serendipityUser'];
+                        $entry['allow_comments']    = ($entrydata['allow_comments'] ? 'true' : 'false');
+                        $entry['moderate_comments'] = 'false';
+                        $entry['exflag']            = (!empty($entry['extended']) ? 1 : 0);
+                        $entry['trackbacks']        = 0;
+                        $entry['comments']          = (isset($entrydata['comments']) ? count($entrydata['comments']) : 0);
+                        serendipity_updertEntry($entry);
+                        $i++;
+
+                        if (isset($entrydata['comments']) && count($entrydata['comments']) > 0) {
+                            foreach($entrydata['comments'] as $comment) {
+                                $comment = array('entry_id ' => $entry['id'],
+                                                 'parent_id' => 0,
+                                                 'timestamp' => $this->toTimestamp($comment['date']),
+                                                 'author'    => stripslashes($comment['name']),
+                                                 'email'     => stripslashes($comment['email']),
+                                                 'url'       => stripslashes($comment['url']),
+                                                 'ip'        => stripslashes($comment['ip']),
+                                                 'status'    => 'approved',
+                                                 'body'      => stripslashes($comment['comment']),
+                                                 'subscribed'=> ($comment['notify'] ? 'true' : 'false'),
+                                                 'type'      => 'NORMAL');
+
+                                serendipity_db_insert('comments', $comment);
+                            }
+                        }
+                        echo '&nbsp;&nbsp;&nbsp;&nbsp;&middot; <strong style="color: green">Entry #' . $entryid . ' imported</strong><br />';
+                        flush();
+                        ob_flush();
+                    }
+                }
+            }
+        } else {
+            return sprintf(ERROR_NO_DIRECTORY, $this->data['pivot_path']);
+        }
+
+        return true;
+    }
+}
+
+return 'Serendipity_Import_Pivot';
+
+/* vim: set sts=4 ts=4 expandtab : */
+?>
index af2d35d0f6ef0b192b3f19fb393d0e4df0e73329..c7e096a5d58aaf98699b6219cde03e6d01c187e0 100644 (file)
@@ -580,7 +580,7 @@ function serendipity_smarty_init($vars = array()) {
 
         $serendipity['smarty']->config_dir    = &$serendipity['smarty']->template_dir[0];
         $serendipity['smarty']->secure_dir    = array($serendipity['serendipityPath'] . $serendipity['templatePath']);
-        $serendipity['smarty']->security_settings['MODIFIER_FUNCS']  = array('sprintf', 'sizeof', 'count', 'rand');
+        $serendipity['smarty']->security_settings['MODIFIER_FUNCS']  = array('sprintf', 'sizeof', 'count', 'rand', 'print_r');
         $serendipity['smarty']->security_settings['ALLOW_CONSTANTS'] = true;
         $serendipity['smarty']->security      = true;
         $serendipity['smarty']->use_sub_dirs  = false;