'dir_permission' => 0777,
'file_permission' => 0666,
'time_zone' => 'America/Toronto',
+ 'tmp' => '/tmp',
+ 'admin_title' => 'IPF Administration',
);
private static function applySettings($settings)
$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()
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;
}
+++ /dev/null
-<?php
-
-class IPF_Exception_Form extends IPF_Exception{}
+++ /dev/null
-<?php
-
-class IPF_Exception_Image extends IPF_Exception{}
+++ /dev/null
-<?php
-
-class IPF_Exception_Panic extends IPF_Exception{}
+++ /dev/null
-<?php
-
-class IPF_Exception_Settings extends IPF_Exception{}
+++ /dev/null
-<?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;
- }
-}
-
--- /dev/null
+<?php
+
+class IPF_Exception_Form extends IPF_Exception{}
--- /dev/null
+<?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;
+ }
+}
+
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);
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/";
// 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()];