function load_controller($name) { $args = func_get_args(); $name = array_shift($args); if (!class_exists(ucfirst($name))) { $content_path = View_Loader::get_instance()->get_path(); if (file_exists($content_path . '/' . $name . '.php')) { include $content_path . '/' . $name . '.php'; } else { return false; } } if (!class_exists(ucfirst($name))) { return false; } $classObj = new ReflectionClass(ucfirst($name)); return $classObj->newInstanceArgs($args); }
public function function_call($field, $object, $data) { $classname = ucfirst($object['contentname']); $function_name = strval($field['name']); if (class_exists($classname) && method_exists($classname, $function_name)) { View_Loader::get_instance()->set_path(CONTENTPATH . $object['contentname']); $result = call_user_func_array($classname . '::' . $function_name, array($object, $data)); if ($result) { echo view("head", array("pages" => FW4_Admin::get_pages(), "title" => strval($field), "user" => FW4_User::get_user(), "site" => current_site())); echo '<h2>' . strval($field) . '</h2>'; echo '<div class="input">' . $result . '</div>'; echo '<div class="controls">'; echo '<a class="button save" href="' . preg_replace('/[^\\/]+\\/[^\\/]+\\/?$/', '', $_SERVER['REQUEST_URI']) . '">' . l(array('nl' => 'Terug', 'fr' => 'Retour', 'en' => 'Back')) . '</a>'; if (isset($field['allow_print'])) { echo '<a class="button right" href="#" onclick="window.print();return false;">' . l(array('nl' => 'Afdrukken', 'fr' => 'Imprimer', 'en' => 'Print', 'de' => 'Drucken')) . '</a>'; } echo '</div>'; echo view("foot", array('scripts' => array())); exit; } } redirect($_SERVER['HTTP_REFERER']); }
private static function route($priority) { $uri = implode('/', segments()); foreach (self::$slugs as $key => $routes) { $key = str_replace('%s', '([a-z0-9\\-]+)', str_replace('%d', '([0-9]+)', str_replace('/', '\\/', $key))); if (preg_match('/^' . $key . '(\\/|$)/is', $uri, $matches)) { array_pop($matches); array_shift($matches); foreach ($routes as &$route) { if ($route->get_priority() == $priority) { $arguments = preg_replace('/^' . $key . '(\\/|$)/is', '', $uri); $arguments = explode("?", $arguments); $arguments = array_filter(explode("/", array_shift($arguments))); $arguments = array_merge($matches, $arguments); // Check if the class that will handle the content actually contains the requested function. if (!method_exists($route->get_classname(), $route->get_function())) { continue; } // Check if we're not calling said function with too few parameters. $reflector = new ReflectionClass($route->get_classname()); if (count($arguments) < $reflector->getMethod($route->get_function())->getNumberOfRequiredParameters()) { continue; } // Check if this function might want variable number of parameters. $collapse_parameters = false; $parameters = $reflector->getMethod($route->get_function())->getParameters(); if (count($parameters) && end($parameters)->name == 'parameters') { $collapse_parameters = true; } if (count($arguments) > count($parameters) && $collapse_parameters && $priority == ROUTE_DEFAULT) { $route->set_priority(ROUTE_LATE); continue; } // Check if we're not calling said function with too many parameters. if (count($arguments) > count($parameters) && !$collapse_parameters) { continue; } // Check if we're not calling a static function. if ($reflector->getMethod($route->get_function())->isStatic()) { continue; } // Save old segments should we need it again later self::$urlsegments = self::$segments; // Set the segments to those that matched our content self::$segments = array(); self::$segments[0] = strtolower($route->get_contentname()); self::$segments[1] = strtolower($route->get_function()); self::$segments = array_merge(self::$segments, $arguments); // Set the current route self::$current_route = $route; // Check database if needed (only do this when there's no admin panel) if (!Config::admin_enabled()) { $site = current_site(); if (self::is_fw4() && !$site->live) { FW4_Structure::check_structure(); } } // Fire the controller View_Loader::get_instance()->set_path(CONTENTPATH . self::$content_prefix . self::$segments[0]); $page = self::$content_pages[strtolower($route->get_classname())]; if ($collapse_parameters) { $non_optional = array_splice($arguments, 0, count($parameters) - 1); $arguments = array_merge($non_optional, array(array_diff($arguments, array('index')))); } try { $result = call_user_func_array(array($page, $route->get_function()), $arguments); } catch (RowNotFoundException $e) { $result = false; } // If the controller returns false, reset the segments and continue matching if ($result === false) { self::$segments = self::$urlsegments; continue; } return true; } } } } return false; }
private static function print_field($field, $data, $structure) { if (in_array($field->getName(), array('div', 'span', 'img'))) { echo '<div class="usernote">' . strval($field->asXML()) . '</div>'; return false; } $user = FW4_User::get_user(); if (isset($field['require']) && $user->id !== 0) { $require_fields = explode('.', $field['require']); $require_field = $user; foreach ($require_fields as $current_field) { if (isset($require_field[$current_field]) && $require_field[$current_field]) { $require_field = $require_field[$current_field]; } else { $require_field = false; break; } } if (!$require_field && !isset($structure['is_version'])) { return false; } } if (isset($field['hide_on_recursive']) && self::$recursive_levels > 0) { return false; } $types = FW4_Type_Manager::get_instance(); $fieldname = strval($field['name']); switch ($field->getName()) { case 'object': if (isset($data->id) && !isset($structure['is_version'])) { $objectquery = where((isset($structure['orig_name']) ? $structure['orig_name'] : $structure['name']) . '_id = %d', $data->id); foreach ($field->children() as $type => $subfield) { if ($type == 'object') { $objectquery->including(strval($subfield['name'])); } if ($type == 'summary' && isset($subfield['needs'])) { foreach (explode(',', strval($subfield['needs'])) as $needs) { $objectquery->including(trim($needs)); } } if ($type == 'recursive') { $objectquery->where('parent_id IS NULL'); } } $objectamount = $objectquery->get($structure['stack'] . '>' . $field['name'])->rowCount(); $objectdata = $objectquery->limit(50)->get($structure['stack'] . '>' . $field['name']); $field['stack'] = $structure['stack'] . '>' . $field['name']; self::print_object_list($field, $objectdata, $objectamount, $data->id); } return false; case 'recursive': if (isset($structure['editing_disabled'])) { return false; } if (isset($field['levels']) && $field['levels'] <= self::$recursive_levels) { return false; } if (isset($data->id)) { $recursive_structure = clone $structure; if (isset($field['title'])) { $recursive_structure['title'] = $field['title']; } if (isset($field['label'])) { $recursive_structure['label'] = $field['label']; } if (isset($field['name'])) { $recursive_structure['orig_name'] = $recursive_structure['name']; $recursive_structure['name'] = $field['name']; } $objectquery = where('parent_id = %d', $data->id)->limit(50); $objectdata = $objectquery->get($structure['stack']); $objectamount = $objectquery->count_rows($structure['stack']); self::print_object_list($recursive_structure, $objectdata, $objectamount, $data->id, true, true, true); } return false; case 'list': if (isset($field['datasource'])) { if (function_exists('datasource_' . $field['datasource'])) { $listdata = call_user_func('datasource_' . $field['datasource'], false); if (is_array($listdata)) { echo View_Loader::get_instance()->load("data_list", array('data' => $listdata, 'export' => isset($field['exportable']), 'datasource' => isset($field['datasource']) ? strval($field['datasource']) : false, 'object' => isset($field['object']) ? strval($field['object']) : false)); } } } if (isset($data->id)) { $object = FW4_Structure::get_object_structure(strval($field['object'])); if (!$object) { return false; } foreach ($field->attributes() as $key => $val) { $object->addAttribute($key, $val); } $query = new Query(); if (isset($field['order_field'])) { $query->order_by(strval($field['order_field'])); } if (isset($field['where'])) { foreach (explode(',', strval($field['where'])) as $item) { $item = explode(':', $item); $query->where($item[0] . ' = %s', $item[1]); } } $allow_edit = true; if (isset($field['allow_edit']) && ($field['allow_edit'] == 'false' || !$field['allow_edit'])) { $allow_edit = false; } $rows = $query->load_children(true)->get(strval($field['object'])); self::print_object_list($object, $rows, count($rows), $data->id, true, $allow_edit); } return false; case 'string': case 'email': if (isset($field['readonly']) && isset($data->id) || isset($structure['editing_disabled'])) { echo '<div class="input"><label for="' . $field['name'] . '" class="for-input">' . $field['label'] . '</label><div class="value">' . (isset($data->{$fieldname}) && $data->{$fieldname} ? self::placeholder_decode($data->{$fieldname}, $field) : '-') . '</div></div>'; } else { if (isset($field['translatable']) && $field['translatable']) { echo '<div class="' . (FW4_Admin::$in_fieldset ? 'field' : 'input') . '"><label' . (isset($field['invalid']) && $field['invalid'] ? ' class="invalid"' : '') . '>' . $field['label'] . '</label> '; foreach (languages() as $key => $lang) { $fieldlang = $fieldname . '_' . $key; echo '<div class="language"><input type="text" class="' . (count(languages()) > 1 ? 'with_lang_label lowmargin' : '') . (isset($field['required']) && $field['required'] ? ' required' : '') . '' . (isset($field['wide']) ? ' wide' : '') . '" name="' . $field['name'] . '_' . $key . '" value="' . htmlentities_all(isset($data->{$fieldlang}) ? $data->{$fieldlang} : '') . '" maxlength="' . (isset($field['length']) ? $field['length'] : 150) . '"' . (isset($field['visible_condition']) ? ' data-visible-condition="' . $field['visible_condition'] . '"' : '') . ' />' . (count(languages()) > 1 ? '<span class="lang_label">' . strtoupper($key) . '</span>' : '') . '</div>'; } echo '<br/></div>'; } else { echo '<div class="' . (FW4_Admin::$in_fieldset ? 'field' : 'input') . '"><label for="' . $field['name'] . '" class="for-input">' . $field['label'] . '</label> <input class="' . (isset($field['required']) && $field['required'] ? 'required' : '') . '' . (isset($field['wide']) ? ' wide' : '') . '" type="text" id="input-' . $field['name'] . '" name="' . $field['name'] . '" value="' . htmlspecialchars(isset($data->{$fieldname}) ? $data->{$fieldname} : '') . '" maxlength="' . (isset($field['length']) ? $field['length'] : 150) . '"' . (isset($field['visible_condition']) ? ' data-visible-condition="' . $field['visible_condition'] . '"' : '') . ' /></div>'; } } return true; case 'number': if (isset($field['readonly']) && $field['readonly'] || isset($structure['editing_disabled'])) { if (isset($data->id)) { echo '<div class="input"><label for="' . $field['name'] . '"' . (isset($field['invalid']) && $field['invalid'] ? ' class="invalid"' : '') . '>' . $field['label'] . '</label> <div class="value">' . (isset($data->{$fieldname}) ? $data->{$fieldname} : '') . '</div></div>'; } } else { echo '<div class="input"><label for="' . $field['name'] . '"' . (isset($field['invalid']) && $field['invalid'] ? ' class="invalid"' : '') . '>' . $field['label'] . '</label> <input class="number' . (isset($field['required']) && $field['required'] ? ' required' : '') . '" type="text" name="' . $field['name'] . '" value="' . (isset($data->{$fieldname}) ? $data->{$fieldname} : '') . '" maxlength="' . (isset($field['length']) ? $field['length'] : 20) . '" /></div>'; } return true; case 'float': if (isset($field['readonly']) && $field['readonly'] || isset($structure['editing_disabled'])) { if (isset($data->id)) { echo '<div class="input"><label for="' . $field['name'] . '"' . (isset($field['invalid']) && $field['invalid'] ? ' class="invalid"' : '') . '>' . $field['label'] . '</label> <div class="value">' . (isset($data->{$fieldname}) ? trim(trim(number_format($data->{$fieldname}, 2, ',', '.'), '0'), ',') : '') . '</div></div>'; } } else { echo '<div class="input"><label for="' . $field['name'] . '"' . (isset($field['invalid']) && $field['invalid'] ? ' class="invalid"' : '') . '>' . $field['label'] . '</label> <input class="float' . (isset($field['required']) && $field['required'] ? ' required' : '') . '" type="text" name="' . $field['name'] . '" value="' . (isset($data->{$fieldname}) ? trim(trim(number_format($data->{$fieldname}, 2, ',', '.'), '0'), ',') : '') . '" maxlength="' . (isset($field['length']) ? $field['length'] : 20) . '" /></div>'; } return true; case 'password': if (isset($field['readonly']) && isset($data->id) || isset($structure['editing_disabled'])) { return false; } else { echo '<div class="input"><label for="' . $field['name'] . '"' . (isset($field['invalid']) && $field['invalid'] ? ' class="invalid"' : '') . '>' . $field['label'] . '</label> <input type="password"' . (isset($field['required']) && $field['required'] && !isset($data->id) ? ' class="required"' : '') . ' name="' . $field['name'] . '" maxlength="' . (isset($field['length']) ? $field['length'] : 150) . '" /></div>'; } return true; case 'bool': if (self::$in_fieldset) { echo '<div class="field">'; } else { echo '<fieldset>'; } if (isset($field['readonly']) && isset($data->id) || isset($structure['editing_disabled'])) { echo $field['label'] . ': <strong>' . (isset($data->{$fieldname}) && $data->{$fieldname} == 1 || !$data->id && isset($field['default']) ? l(array('nl' => 'Ja', 'fr' => 'Oui', 'en' => 'Yes')) : l(array('nl' => 'Nee', 'fr' => 'Non', 'en' => 'No'))) . '</strong>'; } else { echo '<input id="input-' . $field['name'] . '"' . (isset($field['enabled_condition']) ? ' data-enabled-condition="' . $field['enabled_condition'] . '"' : '') . '' . (isset($field['visible_condition']) ? ' data-visible-condition="' . $field['visible_condition'] . '"' : '') . ' type="checkbox" name="' . $field['name'] . '" value="1" ' . (isset($data->{$fieldname}) && $data->{$fieldname} == 1 || (!isset($data->id) || !$data->id) && isset($field['default']) ? 'checked="checked"' : '') . ' /><label for="input-' . $field['name'] . '">' . $field['label'] . '</label>'; } if (self::$in_fieldset) { echo '</div>'; } else { echo '</fieldset>'; } return true; case 'date': if (isset($field['default_today']) && $field['default_today'] && !isset($data->id)) { $data->{$fieldname} = time(); } else { if (!isset($data->{$fieldname})) { $data->{$fieldname} = ''; } } echo '<div class="' . (FW4_Admin::$in_fieldset ? 'field' : 'input') . '"><label class="for-input">' . $field['label'] . '</label>'; if (isset($field['readonly']) && $field['readonly'] || isset($structure['editing_disabled'])) { echo '<div class="value">' . (isset($data->{$fieldname}) && is_numeric($data->{$fieldname}) && $data->{$fieldname} ? date('d/m/Y', $data->{$fieldname}) : ($data->{$fieldname} ? $data->{$fieldname} : 'Nooit')) . '</div>'; } else { echo '<input type="text" name="' . $field['name'] . '" style="width:100px" class="date' . (isset($field['required']) && $field['required'] ? ' required' : '') . '" size="20" id="input-' . $field['name'] . '" value="' . (isset($data->{$fieldname}) && is_numeric($data->{$fieldname}) ? date('d/m/Y', $data->{$fieldname}) : $data->{$fieldname}) . '"' . (isset($field['visible_condition']) ? ' data-visible-condition="' . $field['visible_condition'] . '"' : '') . '' . (isset($field['limit']) ? ' data-limit="' . $field['limit'] . '"' : '') . '/>'; } echo '</div>'; return true; case 'timedate': $date = new DateTime(null, new DateTimeZone('Etc/GMT+2')); if (isset($field['default_today']) && $field['default_today'] && !isset($data->{$fieldname})) { $data->{$fieldname} = $date->getTimestamp(); } else { if (!isset($data->{$fieldname})) { $data->{$fieldname} = ''; } } if (isset($data->{$fieldname}) && is_numeric($data->{$fieldname}) && $data->{$fieldname} > 0) { if (strftime('%H:%M', $data->{$fieldname}) == '00:00') { $value = strftime('%d/%m/%Y', $data->{$fieldname}); } else { $value = strftime('%d/%m/%Y %H:%M', $data->{$fieldname}); } } else { $value = ''; } echo '<div class="input"><label for="' . $field['name'] . '"' . (isset($field['invalid']) && $field['invalid'] ? ' class="invalid"' : '') . '>' . $field['label'] . '</label>'; if (isset($field['readonly']) && $field['readonly'] || isset($structure['editing_disabled'])) { echo '<div class="value">' . ($value ? $value : 'Nooit') . '</div>'; } else { echo '<input type="text" name="' . $field['name'] . '" style="width:150px" class="timedate' . (isset($field['required']) && $field['required'] ? ' required' : '') . '" size="20" value="' . $value . '" data-limit="' . (isset($field['limit']) ? $field['limit'] . '"' : '') . '/>'; } echo '</div>'; return true; case 'text': $placeholdernames = array(); $placeholderlabels = array(); $placeholdericons = array(); foreach ($field->xpath('//placeholder') as $child) { $placeholdernames[] = strval($child['name']); $placeholderlabels[] = isset($child['label']) ? $child['label'] : ucfirst($child['name']); $placeholdericons[] = isset($child['icon']) ? $child['icon'] : url(ADMINRESOURCES . 'images/icon-placeholder.png'); } if (isset($field['readonly']) && $field['readonly'] || isset($structure['editing_disabled'])) { echo '<div class="input"><label for="' . $field['name'] . '"' . (isset($field['invalid']) && $field['invalid'] ? ' class="invalid"' : '') . '>' . $field['label'] . '</label><div class="value">' . (isset($data->{$fieldname}) && $data->{$fieldname} ? self::placeholder_decode($data->{$fieldname}, $field) : '-') . '</div></div>'; } else { if (isset($field['translatable']) && $field['translatable']) { echo '<div class="input langswitch"><label' . (isset($field['invalid']) && $field['invalid'] ? ' class="invalid"' : '') . '>' . $field['label'] . '</label><div class="translate-container">'; if (count(languages()) > 1) { echo '<select class="langswitch">'; foreach (languages() as $key => $lang) { echo '<option value="' . $key . '">' . $lang . '</option> '; } echo '</select>'; } foreach (languages() as $key => $lang) { $fieldlang = $fieldname . '_' . $key; echo '<div class="translatable editor lang_' . $key . ($key == language() ? '' : ' hidden') . '"><textarea class="' . (isset($field['required']) && $field['required'] ? ' required' : '') . (isset($field['controls']) && $field['controls'] ? ' ' . $field['controls'] : '') . (isset($field['size']) && $field['size'] ? ' ' . $field['size'] : '') . '" name="' . $field['name'] . '_' . $key . '" rows="5"' . (isset($field['toolbar']) && $field['toolbar'] ? ' data-controls="' . $field['toolbar'] . '"' : ''); if (count($placeholdernames)) { echo ' data-placeholder-names="' . e(implode(',', $placeholdernames)) . '"'; } if (count($placeholderlabels)) { echo ' data-placeholder-labels="' . e(implode(',', $placeholderlabels)) . '"'; } if (count($placeholdericons)) { echo ' data-placeholder-icons="' . e(implode(',', $placeholdericons)) . '"'; } echo '>' . (isset($data->{$fieldlang}) ? self::placeholder_decode($data->{$fieldlang}, $field) : '') . '</textarea></div>'; } echo '<div class="textarea-loader"></div></div></div>'; } else { echo '<div class="input"><label for="' . $field['name'] . '"' . (isset($field['invalid']) && $field['invalid'] ? ' class="invalid"' : '') . '>' . $field['label'] . '</label> <textarea name="' . $field['name'] . '" rows="5" class="' . (isset($field['required']) && $field['required'] ? ' required' : '') . (isset($field['controls']) && $field['controls'] ? ' ' . $field['controls'] : '') . (isset($field['size']) && $field['size'] ? ' ' . $field['size'] : '') . '"' . (isset($field['toolbar']) && $field['toolbar'] ? ' data-controls="' . $field['toolbar'] . '"' : ''); if (count($placeholdernames)) { echo ' data-placeholder-names="' . e(implode(',', $placeholdernames)) . '"'; } if (count($placeholderlabels)) { echo ' data-placeholder-labels="' . e(implode(',', $placeholderlabels)) . '"'; } if (count($placeholdericons)) { echo ' data-placeholder-icons="' . e(implode(',', $placeholdericons)) . '"'; } echo '>' . (isset($data->{$fieldname}) ? self::placeholder_decode($data->{$fieldname}, $field) : '') . '</textarea><div class="textarea-loader"></div></div>'; } } return true; case 'fieldset': $iseditable = false; self::$in_fieldset = true; echo '<fieldset>'; foreach ($field->children() as $type => $subfield) { $user = FW4_User::get_user(); if (isset($field['hidden'])) { continue; } if (isset($subfield['superadmin_only']) && $user['id'] != 0) { continue; } if (self::print_field($subfield, $data, $structure)) { $iseditable = true; } else { if ($type_obj = $types->get_type($type)) { $type_obj->print_field($subfield, $data, $field); if ($type != 'header') { $iseditable = true; } } } } echo '</fieldset>'; self::$in_fieldset = false; return $iseditable; } return false; }
function view($viewname, $vars = array()) { return View_Loader::get_instance()->load($viewname, $vars); }