]> git.andy128k.dev Git - ipf.git/commitdiff
cleanup
authorAndrey Kutejko <andy128k@gmail.com>
Wed, 3 Sep 2014 05:54:27 +0000 (08:54 +0300)
committerAndrey Kutejko <andy128k@gmail.com>
Wed, 3 Sep 2014 05:54:27 +0000 (08:54 +0300)
ipf.php
ipf/exception/form.php [deleted file]
ipf/exception/image.php [deleted file]
ipf/exception/panic.php [deleted file]
ipf/exception/settings.php [deleted file]
ipf/form.php [deleted file]
ipf/form/exception.php [new file with mode: 0644]
ipf/form/form.php [new file with mode: 0644]
ipf/form/widget/htmlinput.php
ipf/legacy_orm/app.php

diff --git a/ipf.php b/ipf.php
index 96378fc8cb324c8ea2f0b5ffd414d81114ec0f9c..57d8f969995ee6a0c939665790c827b0f39eb454 100644 (file)
--- a/ipf.php
+++ b/ipf.php
@@ -17,6 +17,8 @@ final class IPF
         'dir_permission'    => 0777,
         'file_permission'   => 0666,
         'time_zone'         => 'America/Toronto',
+        'tmp'               => '/tmp',
+        'admin_title'       => 'IPF Administration',
     );
 
     private static function applySettings($settings)
@@ -30,46 +32,32 @@ final class IPF
         $settings_file = IPF::$settings['project_path'].DIRECTORY_SEPARATOR.'settings.php';
         IPF::$settings['settings_file'] = $settings_file;
 
-        if (file_exists($settings_file))
-            IPF::applySettings(require $settings_file);
-        else
-            throw new IPF_Exception_Settings('Configuration file does not exist: '.$settings_file);
+        if (!file_exists($settings_file))
+            die('Configuration file does not exist: '.$settings_file);
+
+        IPF::applySettings(require $settings_file);
 
         $settings_local_file = IPF::$settings['project_path'].DIRECTORY_SEPARATOR.'settings_local.php';
         if (file_exists($settings_local_file))
             IPF::applySettings(require $settings_local_file);
 
-        if (!isset(IPF::$settings['dsn']) && !isset(IPF::$settings['database']))
-            throw new IPF_Exception_Settings('Please specify database parameters or DSN in settings file');
-
-        if (isset(IPF::$settings['database']) && !is_array(IPF::$settings['database']))
-            throw new IPF_Exception_Settings('Database must be array with keys: driver, host, port (optional), database, username, password, options (optional)');
+        if (!isset(IPF::$settings['database']))
+            die('Please specify database parameters in settings file');
 
-        if (isset(IPF::$settings['dsn']) && !is_string(IPF::$settings['dsn']))
-            throw new IPF_Exception_Settings('DSN must be string');
+        if (!is_array(IPF::$settings['database']))
+            die('Database must be array with keys: driver, host, port (optional), database, username, password');
 
-        if (!isset(IPF::$settings['tmp']))
-            IPF::$settings['tmp'] = '/tmp';
-        else
-            if (!is_string(IPF::$settings['tmp']))
-                throw new IPF_Exception_Settings('TMP must be string');
+        if (!is_string(IPF::$settings['tmp']))
+            die('TMP must be string');
 
         if (!isset(IPF::$settings['applications']))
-            throw new IPF_Exception_Settings('Please specify application list');
-        if (!is_array(IPF::$settings['applications']))
-            throw new IPF_Exception_Settings('applications must be array of string');
-
-        if (!isset(IPF::$settings['admin_title'])){
-            IPF::$settings['admin_title'] = 'IPF Administration';
-        }
+            die('Please specify application list');
 
-        if (!isset(IPF::$settings['tiny_mce_url'])){
-            IPF::$settings['tiny_mce_url'] =  IPF::$settings['static_url'] . 'admin/tiny_mce/';
-        }
+        if (!is_array(IPF::$settings['applications']))
+            die('applications must be array of string');
 
-        if (!isset(IPF::$settings['urls'])){
-            throw new IPF_Exception_Settings('Specify site url routes');
-        }
+        if (!isset(IPF::$settings['urls']))
+            die('Specify site url routes');
     }
 
     private static function requestedFileExists()
@@ -88,12 +76,9 @@ final class IPF
         IPF::$settings['project_path'] = $project_path;
         IPF::$settings['document_root'] = $document_root;
 
-        try {
-            IPF::loadSettings();
-            date_default_timezone_set(IPF::$settings['time_zone']);
-        } catch (IPF_Exception_Settings $e) {
-            die('Setting Error: '.$e->getMessage()."\n");
-        }
+        IPF::loadSettings();
+        date_default_timezone_set(IPF::$settings['time_zone']);
+
         return true;
     }
 
diff --git a/ipf/exception/form.php b/ipf/exception/form.php
deleted file mode 100644 (file)
index ab8a8ec..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-<?php
-
-class IPF_Exception_Form extends IPF_Exception{}
diff --git a/ipf/exception/image.php b/ipf/exception/image.php
deleted file mode 100644 (file)
index 907545c..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-<?php
-
-class IPF_Exception_Image extends IPF_Exception{}
diff --git a/ipf/exception/panic.php b/ipf/exception/panic.php
deleted file mode 100644 (file)
index 9cd6178..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-<?php
-
-class IPF_Exception_Panic extends IPF_Exception{}
diff --git a/ipf/exception/settings.php b/ipf/exception/settings.php
deleted file mode 100644 (file)
index 50c4cbe..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-<?php
-
-class IPF_Exception_Settings extends IPF_Exception{}
diff --git a/ipf/form.php b/ipf/form.php
deleted file mode 100644 (file)
index 9fab7b8..0000000
+++ /dev/null
@@ -1,258 +0,0 @@
-<?php
-
-use \PFF\HtmlBuilder\Tag as Tag;
-
-abstract class IPF_Form implements Iterator
-{
-    public $fields = array();
-    public $field_groups = array();
-
-    public $prefix = '';
-    public $id_fields = 'id_%s';
-    public $initial = null;
-    public $data = array();
-    public $cleaned_data = array();
-    public $errors = array();
-    public $is_bound = false;
-    public $label_suffix = ':';
-
-    protected $is_valid = null;
-
-    function __construct($data=null, $extra=array())
-    {
-        if ($data !== null) {
-            $this->data = $data;
-            $this->is_bound = true;
-        }
-        $this->initial = \PFF\Arr::get($extra, 'initial', array());
-        $this->initFields($extra);
-    }
-
-    abstract protected function initFields($extra=array());
-
-    function addPrefix($field_name)
-    {
-        if ('' !== $this->prefix) {
-            return $this->prefix.$field_name;
-        }
-        return $field_name;
-    }
-
-    function isValid()
-    {
-        if (!$this->is_bound)
-            return false;
-
-        if ($this->is_valid !== null)
-            return $this->is_valid;
-
-        $this->cleaned_data = array();
-        $this->errors = array();
-        $form_methods = get_class_methods($this);
-
-        foreach ($this->fields as $name => $field) {
-            $value = $this->field($name)->value();
-            try {
-                $value = $field->clean($value);
-                $this->cleaned_data[$name] = $value;
-                if (in_array('clean_'.$name, $form_methods)) {
-                    $m = 'clean_'.$name;
-                    $value = $this->$m();
-                    $this->cleaned_data[$name] = $value;
-                }
-            } catch (IPF_Exception_Form $e) {
-                if (!isset($this->errors[$name]))
-                    $this->errors[$name] = array();
-                $this->errors[$name][] = $e->getMessage();
-
-                if (isset($this->cleaned_data[$name])) {
-                    unset($this->cleaned_data[$name]);
-                }
-            }
-        }
-
-        if (empty($this->errors)) {
-            try {
-                $this->cleaned_data = $this->clean();
-            } catch (IPF_Exception_Form $e) {
-                if (!isset($this->errors['__all__'])) $this->errors['__all__'] = array();
-                $this->errors['__all__'][] = $e->getMessage();
-            }
-        }
-
-        if (empty($this->errors)) {
-            $this->is_valid = true;
-            return true;
-        } else {
-            // as some errors, we do not have cleaned data available.
-            $this->cleaned_data = array();
-            $this->is_valid = false;
-            return false;
-        }
-    }
-
-    public function clean()
-    {
-        return $this->cleaned_data;
-    }
-
-    public function initial($name)
-    {
-        return \PFF\Arr::get($this->initial, $name, null);
-    }
-
-    public function hiddenFields()
-    {
-        $hidden = array();
-        foreach ($this->fields as $name => $field)
-            if ($field->widget->is_hidden)
-                $hidden[] = $name;
-        return $hidden;
-    }
-
-    public function render_top_errors($raw=false)
-    {
-        $errors = IPF_Form::renderErrorsAsHTML($this->get_top_errors());
-        if ($raw)
-            return $errors;
-        else
-            return $this->unescape($errors);
-    }
-
-    public function get_top_errors()
-    {
-        return \PFF\Arr::get($this->errors, '__all__', array());
-    }
-
-    public function renderLayout($layout, $raw=false)
-    {
-        foreach ($this->field_groups as $field_group) {
-            if (!$field_group['fields'])
-                throw new IPF_Exception('Empty field group.');
-            foreach ($field_group['fields'] as $field_name)
-                if (!array_key_exists($field_name, $this->fields))
-                    throw new IPF_Exception('Unknown field "' . $field_name . '".');
-        }
-
-        $groups = array();
-        foreach ($this->field_groups as $field_group) {
-            $_fields = array();
-            foreach ($field_group['fields'] as $field_name)
-                $_fields[$field_name] = $this->fields[$field_name];
-            $groups[] = array(
-                'fields' => $_fields,
-                'label' => @$field_group['label'],
-            );
-        }
-        
-        if (!count($groups)) {
-            $groups = array(array('fields' => $this->fields));
-        }
-
-        $output = $layout->startForm($this);
-        foreach ($groups as $group) {
-            $groupLabel = \PFF\Arr::get($group, 'label', '');
-            $output .= $layout->startGroup($groupLabel);
-
-            foreach ($group['fields'] as $name=>$field) {
-                if ($field->widget->is_hidden)
-                    continue;
-
-                $bf = $this->field($name);
-
-                $output .= $layout->field($bf);
-            }
-            $output .= $layout->endGroup($groupLabel);
-        }
-        $output .= $layout->endForm($this);
-
-        if (!$raw)
-            $output = $this->unescape($output);
-
-        return $output;
-    }
-
-    public function extra_js()
-    {
-        $extra_js = array();
-        foreach ($this->fields as $name => $field)
-            $extra_js = array_merge($extra_js, $field->widget->extra_js());
-        return array_unique($extra_js);
-    }
-
-    public function render_p($raw=false)
-    {
-        return $form->renderLayout(new IPF_Form_ParagraphLayout, $raw);
-    }
-
-    public function render_ul($raw=false)
-    {
-        return $form->renderLayout(new IPF_Form_ListLayout, $raw);
-    }
-
-    public function render_table($raw=false)
-    {
-        return $form->renderLayout(new IPF_Form_TableLayout, $raw);
-    }
-
-    public function render_admin($raw=false)
-    {
-        return $form->renderLayout(new IPF_Admin_Form_Layout, $raw);
-    }
-
-    function __get($prop)
-    {
-        if (!in_array($prop, array('render_p', 'render_ul', 'render_table', 'render_top_errors', 'get_top_errors'))) {
-            return $this->$prop;
-        }
-        return $this->$prop();
-    }
-
-    public function field($key)
-    {
-        return new IPF_Form_BoundField($this, $this->fields[$key], $key);
-    }
-
-    public function current()
-    {
-        $name = key($this->fields);
-        return $this->field($name);
-    }
-
-    public function key()
-    {
-        return key($this->fields);
-    }
-
-    public function next()
-    {
-        next($this->fields);
-    }
-
-    public function rewind()
-    {
-        reset($this->fields);
-    }
-
-    public function valid()
-    {
-        return (false !== current($this->fields));
-    }
-
-    public static function renderErrorsAsHTML($errors)
-    {
-        if (!count($errors))
-            return '';
-        $ul = Tag::ul(array('class' => 'errorlist'));
-        foreach ($errors as $err)
-            $ul->append(Tag::li(null, $err));
-        return $ul->html();
-    }
-
-    public function unescape($html)
-    {
-        // Do nothing
-        return $html;
-    }
-}
-
diff --git a/ipf/form/exception.php b/ipf/form/exception.php
new file mode 100644 (file)
index 0000000..ab8a8ec
--- /dev/null
@@ -0,0 +1,3 @@
+<?php
+
+class IPF_Exception_Form extends IPF_Exception{}
diff --git a/ipf/form/form.php b/ipf/form/form.php
new file mode 100644 (file)
index 0000000..9fab7b8
--- /dev/null
@@ -0,0 +1,258 @@
+<?php
+
+use \PFF\HtmlBuilder\Tag as Tag;
+
+abstract class IPF_Form implements Iterator
+{
+    public $fields = array();
+    public $field_groups = array();
+
+    public $prefix = '';
+    public $id_fields = 'id_%s';
+    public $initial = null;
+    public $data = array();
+    public $cleaned_data = array();
+    public $errors = array();
+    public $is_bound = false;
+    public $label_suffix = ':';
+
+    protected $is_valid = null;
+
+    function __construct($data=null, $extra=array())
+    {
+        if ($data !== null) {
+            $this->data = $data;
+            $this->is_bound = true;
+        }
+        $this->initial = \PFF\Arr::get($extra, 'initial', array());
+        $this->initFields($extra);
+    }
+
+    abstract protected function initFields($extra=array());
+
+    function addPrefix($field_name)
+    {
+        if ('' !== $this->prefix) {
+            return $this->prefix.$field_name;
+        }
+        return $field_name;
+    }
+
+    function isValid()
+    {
+        if (!$this->is_bound)
+            return false;
+
+        if ($this->is_valid !== null)
+            return $this->is_valid;
+
+        $this->cleaned_data = array();
+        $this->errors = array();
+        $form_methods = get_class_methods($this);
+
+        foreach ($this->fields as $name => $field) {
+            $value = $this->field($name)->value();
+            try {
+                $value = $field->clean($value);
+                $this->cleaned_data[$name] = $value;
+                if (in_array('clean_'.$name, $form_methods)) {
+                    $m = 'clean_'.$name;
+                    $value = $this->$m();
+                    $this->cleaned_data[$name] = $value;
+                }
+            } catch (IPF_Exception_Form $e) {
+                if (!isset($this->errors[$name]))
+                    $this->errors[$name] = array();
+                $this->errors[$name][] = $e->getMessage();
+
+                if (isset($this->cleaned_data[$name])) {
+                    unset($this->cleaned_data[$name]);
+                }
+            }
+        }
+
+        if (empty($this->errors)) {
+            try {
+                $this->cleaned_data = $this->clean();
+            } catch (IPF_Exception_Form $e) {
+                if (!isset($this->errors['__all__'])) $this->errors['__all__'] = array();
+                $this->errors['__all__'][] = $e->getMessage();
+            }
+        }
+
+        if (empty($this->errors)) {
+            $this->is_valid = true;
+            return true;
+        } else {
+            // as some errors, we do not have cleaned data available.
+            $this->cleaned_data = array();
+            $this->is_valid = false;
+            return false;
+        }
+    }
+
+    public function clean()
+    {
+        return $this->cleaned_data;
+    }
+
+    public function initial($name)
+    {
+        return \PFF\Arr::get($this->initial, $name, null);
+    }
+
+    public function hiddenFields()
+    {
+        $hidden = array();
+        foreach ($this->fields as $name => $field)
+            if ($field->widget->is_hidden)
+                $hidden[] = $name;
+        return $hidden;
+    }
+
+    public function render_top_errors($raw=false)
+    {
+        $errors = IPF_Form::renderErrorsAsHTML($this->get_top_errors());
+        if ($raw)
+            return $errors;
+        else
+            return $this->unescape($errors);
+    }
+
+    public function get_top_errors()
+    {
+        return \PFF\Arr::get($this->errors, '__all__', array());
+    }
+
+    public function renderLayout($layout, $raw=false)
+    {
+        foreach ($this->field_groups as $field_group) {
+            if (!$field_group['fields'])
+                throw new IPF_Exception('Empty field group.');
+            foreach ($field_group['fields'] as $field_name)
+                if (!array_key_exists($field_name, $this->fields))
+                    throw new IPF_Exception('Unknown field "' . $field_name . '".');
+        }
+
+        $groups = array();
+        foreach ($this->field_groups as $field_group) {
+            $_fields = array();
+            foreach ($field_group['fields'] as $field_name)
+                $_fields[$field_name] = $this->fields[$field_name];
+            $groups[] = array(
+                'fields' => $_fields,
+                'label' => @$field_group['label'],
+            );
+        }
+        
+        if (!count($groups)) {
+            $groups = array(array('fields' => $this->fields));
+        }
+
+        $output = $layout->startForm($this);
+        foreach ($groups as $group) {
+            $groupLabel = \PFF\Arr::get($group, 'label', '');
+            $output .= $layout->startGroup($groupLabel);
+
+            foreach ($group['fields'] as $name=>$field) {
+                if ($field->widget->is_hidden)
+                    continue;
+
+                $bf = $this->field($name);
+
+                $output .= $layout->field($bf);
+            }
+            $output .= $layout->endGroup($groupLabel);
+        }
+        $output .= $layout->endForm($this);
+
+        if (!$raw)
+            $output = $this->unescape($output);
+
+        return $output;
+    }
+
+    public function extra_js()
+    {
+        $extra_js = array();
+        foreach ($this->fields as $name => $field)
+            $extra_js = array_merge($extra_js, $field->widget->extra_js());
+        return array_unique($extra_js);
+    }
+
+    public function render_p($raw=false)
+    {
+        return $form->renderLayout(new IPF_Form_ParagraphLayout, $raw);
+    }
+
+    public function render_ul($raw=false)
+    {
+        return $form->renderLayout(new IPF_Form_ListLayout, $raw);
+    }
+
+    public function render_table($raw=false)
+    {
+        return $form->renderLayout(new IPF_Form_TableLayout, $raw);
+    }
+
+    public function render_admin($raw=false)
+    {
+        return $form->renderLayout(new IPF_Admin_Form_Layout, $raw);
+    }
+
+    function __get($prop)
+    {
+        if (!in_array($prop, array('render_p', 'render_ul', 'render_table', 'render_top_errors', 'get_top_errors'))) {
+            return $this->$prop;
+        }
+        return $this->$prop();
+    }
+
+    public function field($key)
+    {
+        return new IPF_Form_BoundField($this, $this->fields[$key], $key);
+    }
+
+    public function current()
+    {
+        $name = key($this->fields);
+        return $this->field($name);
+    }
+
+    public function key()
+    {
+        return key($this->fields);
+    }
+
+    public function next()
+    {
+        next($this->fields);
+    }
+
+    public function rewind()
+    {
+        reset($this->fields);
+    }
+
+    public function valid()
+    {
+        return (false !== current($this->fields));
+    }
+
+    public static function renderErrorsAsHTML($errors)
+    {
+        if (!count($errors))
+            return '';
+        $ul = Tag::ul(array('class' => 'errorlist'));
+        foreach ($errors as $err)
+            $ul->append(Tag::li(null, $err));
+        return $ul->html();
+    }
+
+    public function unescape($html)
+    {
+        // Do nothing
+        return $html;
+    }
+}
+
index b255a53629d1467724bcf689ebaf9605aa7a8164..197d99815a1cbf9a92262d6596cba1c52ede1583 100644 (file)
@@ -13,7 +13,10 @@ class IPF_Form_Widget_HTMLInput extends IPF_Form_Widget
 
     public function __construct($attrs=array())
     {
-        $this->tinymce_url          = \PFF\Arr::pop($attrs, 'tinymce_url');
+        $this->tinymce_url = \PFF\Arr::pop($attrs, 'tinymce_url',
+            IPF::get('tiny_mce_url',
+            IPF::get('static_url').'admin/tiny_mce/'));
+
         $this->mode                 = \PFF\Arr::pop($attrs, 'mode',                 'textareas');
         $this->theme                = \PFF\Arr::pop($attrs, 'theme',                'simple');
         $this->include_tinymce      = \PFF\Arr::pop($attrs, 'include_tinymce',      true);
@@ -51,7 +54,7 @@ class IPF_Form_Widget_HTMLInput extends IPF_Form_Widget
     public function extra_js()
     {
         return array(
-            '<script type="text/javascript" src="'.IPF::get('tiny_mce_url').'tiny_mce.js"></script>',
+            '<script type="text/javascript" src="'.$this->tiny_mce_url.'tiny_mce.js"></script>',
             '<script type="text/javascript">
 function ipf_filebrowser(field_name, url, type, win) {
   var cmsURL = "/admin/filebrowser/";
index 4cc34722a84aab8192c2f25cf82f9e09a5f2437a..8db81a04101b1e1c17569b56f2c30e54a1201393 100644 (file)
@@ -20,16 +20,6 @@ class IPF_Legacy_ORM_App extends IPF_Application
                 // nothing to do
             }
 
-            // reorder models according to a given option
-            if (method_exists($app, 'admin_models_order')) {
-                $ordered = $app->admin_models_order();
-                foreach ($ordered as $modelname) {
-                    if (!in_array($modelname, $models))
-                        throw new IPF_Exception_Panic("Model \"$modelname\" does not exist.");
-                }
-                $models = array_merge($ordered, array_diff($models, $ordered));
-            }
-
             self::$appModels[$app->getName()] = $models;
         }
         return self::$appModels[$app->getName()];