function smarty_function_admin_relations($params = array(), &$smarty)
{
    require_once $smarty->_get_plugin_filepath('function', 'admin_link');
    $relations = array('parent' => 'edit ', 'children' => 'add/edit ');
    $object = null;
    $wrap = false;
    $links = array();
    $output = '';
    foreach ($params as $_key => $_value) {
        ${$_key} = $_value;
    }
    if (empty($object)) {
        $smarty->trigger_error("admin_relations: missing 'object' parameter", E_USER_NOTICE);
        return;
    }
    // cycle relations
    foreach ($relations as $relation_name => $relation_prefix) {
        // cycle object's 'get_' variables
        $i = 0;
        foreach ($object->{'get_' . $relation_name} as $model_name => $model_params) {
            AppModel::RelationNameParams($model_name, $model_params);
            // get controller
            $controller = Globe::Init($model_name, 'controller');
            // TODO replace by ::singleton, find others
            // action & text
            switch ($relation_name) {
                case 'parent':
                    $action = ($model = object_get($object, $model_name)) ? 'edit' . DS . $model->id : null;
                    $text = ucwords(AppInflector::titleize($model_name));
                    $image = 'page_white_edit';
                    break;
                case 'children':
                    $prefix = $i == 0 ? '' : AppInflector::tableize(get_class($object)) . '_id=';
                    $action = '?filter=' . $prefix . $object->id;
                    $text = ucwords(AppInflector::pluralize(AppInflector::titleize($model_name)));
                    $image = 'magnifier';
                    break;
                default:
                    $action = '';
                    $text = AppInflector::titleize($model_name);
                    $image = 'magnifier';
                    break;
            }
            // build link
            $links[] = smarty_function_admin_link(array('controller' => AppInflector::fileize(get_class($controller), 'controller'), 'action' => $action, 'text' => "<span>{$relation_prefix}{$text}</span>" . ' <img src="/assets/images/admin/silk/' . $image . '.png" width="16" height="16">'), $smarty);
            $i++;
        }
    }
    foreach ($links as $link) {
        $output .= "<li>{$link}</li>\n";
    }
    if ($wrap) {
        $output = '<ul class="relations">' . $output . '</ul>';
    }
    return $output;
}
 static function fileize($name = '', $type = 'class')
 {
     $type = strtolower($type);
     $name = AppInflector::underscore($name);
     switch ($type) {
         case 'controller':
             $name = AppInflector::pluralize(AppInflector::singularize(preg_replace('/_?Controller$/i', '', $name)));
             break;
     }
     return $name;
 }
Example #3
0
 /**
  * Loads files in bulk.
  *
  * @param mixed $names name or array of names
  * @param string $type class/include/file/package/controller/model
  * @return bool success?
  * @author Philip Blyth
  */
 static function Load($names, $type = 'class', $show_errors = true)
 {
     if (!is_array($names)) {
         $names = array($names);
     }
     $type = strtolower($type);
     $constant_name = strtoupper(AppInflector::pluralize($type)) . '_DIR';
     list($dir, $prefix, $suffix) = array(defined($constant_name) ? constant($constant_name) : '', $type . '.', '.php');
     switch ($type) {
         case 'include':
             $prefix = '';
             break;
         case 'file':
             $dir = $prefix = $suffix = '';
             break;
         case 'package':
             $prefix = '';
             break;
             // case 'class':
             // case 'model':
             // case 'controller':
             //   $file = strtolower($file);
             //   break;
     }
     $success = true;
     foreach ($names as $file) {
         if ($type == 'class' || $type == 'model' || $type == 'controller' && ($file != 'app' && $file != 'endo')) {
             $file = AppInflector::fileize($file, $type);
         }
         $filename = $prefix . $file . $suffix;
         if ($filepath = self::Find($filename, array(APP_ROOT . $dir, ENDO_ROOT . $dir, APP_PACKAGES_ROOT . $dir, ENDO_PACKAGES_ROOT . $dir))) {
             require_once $filepath;
         } else {
             if ($show_errors) {
                 Error::Set(ucfirst($type) . " not found in '" . self::CleanDir($filepath) . "'!", 'fatal');
             }
             $success = false;
         }
     }
     return $success;
 }
Example #4
0
 private function _handle_file_upload($field = null, $params = array())
 {
     require_once ENDO_PACKAGES_ROOT . 'VerotUpload' . DS . 'class.upload.php';
     // TODO add 'delete-checkbox' functionality
     if (!empty($_FILES)) {
         // defaults
         $path = array_get($params, 'path', 'assets');
         $allowed = array_get($params, 'allowed', 'image');
         $options = array_get($params, 'options', array());
         $file = new Upload($_FILES[$field]);
         if ($file->uploaded) {
             // path
             $path = 'uploads' . DS . AppInflector::pluralize(get_class($this)) . DS . $path . DS . $this->id . DS;
             $folder = WEB_ROOT . $path;
             // settings
             if ($allowed == 'image') {
                 $file->allowed = array('image/gif', 'image/jpg', 'image/jpeg', 'image/png', 'image/bmp');
                 // defaults
                 if (!array_get($options, 'width') && !array_get($options, 'height')) {
                     $options = array_merge(array('width' => 100), $options);
                 }
                 // resize
                 $file->image_max_pixels = 1000000;
                 $file->image_resize = true;
                 $file->image_convert = 'jpg';
                 // determine method
                 if (array_get($options, 'width') && !array_get($options, 'height')) {
                     // width only
                     $file->image_x = $options['width'];
                     $file->image_ratio_y = true;
                 } elseif (!array_get($options, 'width') && array_get($options, 'height')) {
                     // height only
                     $file->image_y = $options['height'];
                     $file->image_ratio_x = true;
                 } else {
                     // width and height
                     $file->image_x = $options['width'];
                     $file->image_y = $options['height'];
                     // crop?
                     if (array_get($options, 'crop')) {
                         $file->image_ratio_crop = true;
                     } else {
                         $file->image_ratio = true;
                     }
                 }
             } elseif (is_array($allowed)) {
                 $file->allowed = $allowed;
             }
             // process!
             $file->Process($folder);
             // success?
             if ($file->processed) {
                 // remove old file?
                 @unlink($folder . str_replace(DS . $path, '', $this->{$field . '_old'}));
                 $file->Clean();
                 $this->{$field} = DS . $path . $file->file_dst_name;
                 return parent::save();
             } else {
                 // TODO add endo form error message
                 echo 'ERROR: ' . $file->error;
                 return false;
             }
         }
     }
     return true;
 }