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; }
/** * 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; }
function smarty_function_link($params = array(), &$smarty) { require_once $smarty->_get_plugin_filepath('shared', 'escape_special_chars'); $output = ''; $text = ''; $controller = ''; $action = ''; $set_gets = false; $extra = ''; $prefix = DS; foreach ($params as $_key => $_value) { switch ($_key) { case 'text': case 'controller': case 'action': case 'parameters': case 'href': case 'set_gets': case 'prefix': ${$_key} = $_value; break; case 'confirm': $extra .= ' onclick="return confirm(\'' . str_replace_js($_value) . '\');"'; break; default: if (!is_array($_value)) { $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_value) . '"'; } else { $smarty->trigger_error("link: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE); } break; } } if (empty($text)) { $smarty->trigger_error("link: missing 'text' parameter", E_USER_NOTICE); return; } if (empty($href)) { if (empty($controller)) { $smarty->trigger_error("link: missing 'controller' parameter", E_USER_NOTICE); return; } else { if (!is_string($controller)) { if (is_subclass_of($controller, 'AppModel') || is_subclass_of($controller, 'AppController')) { $controller = AppInflector::fileize(get_class($controller), 'controller'); } else { // no link possible... return $text; } } } $output .= '<a href="' . $prefix . $controller; if (!empty($action)) { $output .= DS . $action; } if (!empty($parameters)) { $output .= DS . $parameters; } } else { $output .= '<a href="'; if (preg_match('/.*@.*\\..{2,5}/', $href)) { $output .= 'mailto:'; } $output .= $href; } if ($set_gets != false) { require_once $smarty->_get_plugin_filepath('function', 'set_gets'); $output .= smarty_function_set_gets(is_bool($set_gets) ? array() : array('vars' => $set_gets), $smarty); } $output .= '"' . $extra . '>' . $text . '</a>'; return $output; }