/** * Renders the field's form element for editing in the admin site * @see \Admin::getFieldSettings() * @param mixed $value The current value of the property, if there is one * @param array $settings Field settings, created through \Admin::getFieldSettings() * @param object $model The model, if it is being edited. * @return string The form control */ public static function displayForm($value, &$settings, $model) { $class = get_called_class(); $settings = static::settings($settings); $include_label = isset($settings['label']) ? $settings['label'] : true; $required = isset($settings['required']) ? $settings['required'] : false; $errors = $model->getErrorsForField($settings['mapping']['fieldName']); $has_errors = count($errors) > 0; $input_attributes = isset($settings['input_attributes']) ? $settings['input_attributes'] : array('class' => 'input-xxlarge'); if (!isset($input_attributes['id'])) { $input_attributes['id'] = 'form_' . $settings['mapping']['fieldName']; } $attributes = array('class' => 'controls control-group' . ($has_errors ? ' error' : '') . ' field-type-' . $class::type($settings)); $label_text = $settings['title'] . ($required ? ' *' : ''); // Translation? if (\CMF::$lang_enabled && !\CMF::langIsDefault() && isset($settings['mapping']['columnName']) && $model->isTranslatable($settings['mapping']['columnName'])) { // If there is no translation if (!$model->hasTranslation($settings['mapping']['columnName'])) { $attributes['class'] .= ' no-translation'; $input_attributes['class'] .= ' no-translation'; $label_text = '<img class="lang-flag" src="' . \Uri::create('/admin/assets/img/lang/' . \CMF::defaultLang() . '.png') . '" /> ' . $label_text; } else { $label_text = '<img class="lang-flag" src="' . \Uri::create('/admin/assets/img/lang/' . \CMF::lang() . '.png') . '" /> ' . $label_text; } } // Description? $description = isset($settings['description']) ? '<span class="help-block">' . $settings['description'] . '</span>' : ''; // Build the input $input = '<input type="text" name="' . $settings['mapping']['fieldName'] . '" ' . array_to_attr($input_attributes) . ' value="' . \Security::htmlentities(strval($value), ENT_QUOTES) . '" />'; // Build the label $label = !$include_label ? '' : html_tag('label', array('class' => 'item-label', 'for' => $settings['mapping']['fieldName']), $label_text . ($has_errors ? ' - ' . $errors[0] : '')); // Prepend or append things... if (isset($settings['prepend'])) { $input = html_tag('div', array('class' => 'input-prepend'), html_tag('span', array('class' => 'add-on'), $settings['prepend']) . $input); } if (isset($settings['append'])) { $input = html_tag('div', array('class' => 'input-append'), $input . html_tag('span', array('class' => 'add-on'), $settings['append'])); } // Don't wrap the input if wrap is set to false if (isset($settings['wrap']) && $settings['wrap'] === false) { return $label . $input; } // Add the 'keep updated' control if the field has a template if (isset($settings['template']) && !empty($settings['template'])) { $attributes['class'] .= ' field-with-controls field-with-template'; $auto_update_setting = 'settings[' . $settings['mapping']['fieldName'] . '][auto_update]'; $auto_update_content = \Form::hidden($auto_update_setting, '0', array()) . html_tag('label', array('class' => 'checkbox auto-update-label'), \Form::checkbox($auto_update_setting, '1', \Arr::get($settings, 'auto_update', true), array('class' => 'auto-update')) . strtolower(\Lang::get('admin.common.auto_update'))); $auto_update = html_tag('div', array('class' => 'controls-top'), $auto_update_content); $label .= $auto_update; return array('content' => html_tag('div', $attributes, $label . $description . $input) . '<div class="clear"><!-- --></div>', 'widget' => false, 'assets' => array('js' => array('/admin/assets/js/twig.min.js', '/admin/assets/js/fields/template.js')), 'js_data' => $settings); } return html_tag('div', $attributes, $label . $description . $input); }
/** * An editor view for the fuel lang entries */ public function get_terms() { $this->template = 'admin/lang/terms.twig'; // Determine what's in the left and right cols $this->lang_lft = \Arr::get(\Lang::$fallback, '0', 'en'); $this->lang_rgt = \CMF::lang(); // Get the common group $result_lft = \Lang::load("common.db", 'common', $this->lang_lft, true, true); $result_rgt = \Lang::load("common.db", 'common', $this->lang_rgt, true, true); $this->result_lft = $result_lft; $this->result_rgt = $result_rgt; $this->lines = \Arr::get(\Lang::$lines, \Lang::$fallback[0], array()); }
/** inheritdoc */ public static function displayForm($value, &$settings, $model) { $settings = static::settings($settings); $include_label = isset($settings['label']) ? $settings['label'] : true; $required = isset($settings['required']) ? $settings['required'] : false; $errors = $model->getErrorsForField($settings['mapping']['fieldName']); $has_errors = count($errors) > 0; $attributes = array('class' => 'controls control-group ' . ($has_errors ? ' error' : '')); $input_attributes = isset($settings['input_attributes']) ? $settings['input_attributes'] : array('class' => 'input-xxlarge'); //add redactor to the class for the field $input_attributes['class'] = $input_attributes['class'] . " redactor"; $label_text = $settings['title'] . ($required ? ' *' : ''); $input = \Form::textarea($settings['mapping']['fieldName'], strval($value), $input_attributes); // Translation? if (\CMF::$lang_enabled && !\CMF::langIsDefault() && $model->isTranslatable($settings['mapping']['columnName'])) { // If there is no translation if (!$model->hasTranslation($settings['mapping']['columnName'])) { $attributes['class'] .= ' no-translation'; $label_text = '<span class="no-translation"><img class="lang-flag" src="' . \Uri::create('/admin/assets/img/lang/' . \CMF::defaultLang() . '.png') . '" /> ' . $label_text . '</span>'; } else { $label_text = '<img class="lang-flag" src="' . \Uri::create('/admin/assets/img/lang/' . \CMF::lang() . '.png') . '" /> ' . $label_text; } } // Build the label $label = !$include_label ? '' : \Form::label($label_text . ($has_errors ? ' - ' . $errors[0] : ''), $settings['mapping']['fieldName'], array('class' => 'item-label')); // Set up required information for any links specified if (isset($settings['links']) && is_array($settings['links'])) { $links = array(); foreach ($settings['links'] as $link_type => $link) { if (!class_exists($link_type)) { continue; } $link['table_name'] = \CMF\Admin::getTableForClass($link_type); $link['singular'] = $link_type::singular(); $link['plural'] = $link_type::plural(); $link['icon'] = $link_type::icon(); $links[$link_type] = $link; } $settings['links'] = $links; } // Return only the field and label if no wrap is required if (isset($settings['wrap']) && $settings['wrap'] === false) { return $label . $input; } // Return the widget if (isset($settings['widget']) && $settings['widget'] === true) { return array('assets' => array(), 'content' => $input, 'widget' => true, 'widget_title' => $label_text, 'widget_icon' => 'align-left', 'js_data' => $settings); } // Return the normal field return array('assets' => array(), 'content' => html_tag('div', $attributes, $label . $input), 'widget' => false, 'js_data' => $settings); }
/** inheritdoc */ public static function displayForm($value, &$settings, $model) { $required = isset($settings['required']) ? $settings['required'] : false; $errors = $model->getErrorsForField($settings['mapping']['fieldName']); $has_errors = count($errors) > 0; $input_attributes = array('class' => 'input input-xxlarge'); $attributes = array('class' => 'field-type-link controls control-group' . ($has_errors ? ' error' : '')); $href_name = $settings['mapping']['fieldName'] . '[href]'; $value['href'] = isset($value['href']) ? $value['href'] : null; $label_text = $settings['title'] . ($required ? ' *' : ''); // Translation? if (\CMF::$lang_enabled && !\CMF::langIsDefault() && isset($settings['mapping']['columnName']) && $model->isTranslatable($settings['mapping']['columnName'])) { // If there is no translation if (!$model->hasTranslation($settings['mapping']['columnName'])) { $attributes['class'] .= ' no-translation'; $input_attributes['class'] .= ' no-translation'; $label_text = '<img class="lang-flag" src="' . \Uri::create('/admin/assets/img/lang/' . \CMF::defaultLang() . '.png') . '" /> ' . $label_text; } else { $label_text = '<img class="lang-flag" src="' . \Uri::create('/admin/assets/img/lang/' . \CMF::lang() . '.png') . '" /> ' . $label_text; } } // EXTERNAL CHECKBOX $external_name = $settings['mapping']['fieldName'] . '[external]'; $external_value = \Arr::get($value, 'external', false); $external = \Form::hidden($external_name, '0') . html_tag('label', array('class' => 'checkbox external-checkbox'), \Form::checkbox($external_name, '1', $external_value, array()) . ' custom'); $label = \Form::label($label_text . ($has_errors ? ' - ' . $errors[0] : ''), $href_name, array('class' => 'item-label')) . $external . html_tag('div', array('class' => 'clear'), ' '); if ($external_value) { $attributes['class'] .= ' external'; } // EXTERNAL INPUT CONTENT $href_value_ext = $external_value ? $value['href'] : ''; $ext_input = \Form::input($href_name, $href_value_ext, $input_attributes); $ext_content = html_tag('div', array('class' => 'external-link'), $ext_input); // INTERNAL DROPDOWN CONTENT $options = static::getOptions($settings, $model); $href_value_int = $external_value ? '' : $value['href']; // Check if the value is actually an alias if (!empty($href_value_int)) { $url_value = \CMF\Model\URL::find($href_value_int); if ($url_value && ($alias = $url_value->alias)) { $href_value_int = $alias->id; } } $input = \Form::select($href_name, $href_value_int, $options, $input_attributes); $int_content = html_tag('div', array('class' => 'internal-link'), $input); return html_tag('div', $attributes, $label . $int_content . $ext_content) . html_tag('div', array(), ''); }
/** inheritdoc */ public static function displayForm($value, &$settings, $model) { $include_label = isset($settings['label']) ? $settings['label'] : true; $target_class = $settings['mapping']['targetEntity']; if (is_null($value) || !$value instanceof $target_class) { $value = new $target_class(); } // Show a simple alias form if the input var is set if (\Input::param('alias', false) !== false) { $linkValue = array(); if (!empty($value)) { $linkValue['href'] = $value->isExternal() ? $value->url : strval($value->id); $linkValue['external'] = $value->isExternal(); } return \CMF\Field\Object\Link::displayForm($linkValue, $settings, $model); } $model_class = get_class($model); $errors = $model->getErrorsForField($settings['mapping']['fieldName']); $has_errors = count($errors) > 0; $attributes = array('class' => 'field-type-url controls control-group' . ($has_errors ? ' error' : '')); $slug_name = $settings['mapping']['fieldName'] . '[slug]'; $label_text = $settings['title'] . ($has_errors ? ' - ' . $errors[0] : ''); if (\CMF::$lang_enabled && !\CMF::langIsDefault()) { if (!$value->hasTranslation('slug')) { $attributes['class'] .= ' no-translation'; $label_text = '<img class="lang-flag" src="' . \Uri::create('/admin/assets/img/lang/' . \CMF::defaultLang() . '.png') . '" /> ' . $label_text; } else { $label_text = '<img class="lang-flag" src="' . \Uri::create('/admin/assets/img/lang/' . \CMF::lang() . '.png') . '" /> ' . $label_text; } } $keep_updated_setting = 'settings[' . $settings['mapping']['fieldName'] . '][keep_updated]'; $keep_updated = \Form::hidden($keep_updated_setting, '0', array()) . html_tag('label', array('class' => 'checkbox keep-updated'), \Form::checkbox($keep_updated_setting, '1', \Arr::get($settings, 'keep_updated', true), array()) . strtolower(\Lang::get('admin.common.auto_update'))); $input = \Form::input($slug_name, $value->slug, array('class' => 'input-xlarge', 'data-copy-from' => implode(',', $model_class::slugFields()))); $label = !$include_label ? '' : html_tag('label', array('class' => 'item-label', 'for' => $slug_name), $label_text) . $keep_updated . html_tag('div', array('class' => 'clear'), ' '); $prefix = $value->prefix; $prepend = html_tag('span', array('class' => 'add-on'), empty($prefix) ? '/' : $prefix); $input = html_tag('div', array('class' => 'input-prepend'), $prepend . $input); $clear = '<div class="clear"><!-- --></div>'; if (isset($settings['wrap']) && $settings['wrap'] === false) { return $label . $input; } return html_tag('div', $attributes, $label . $input) . $clear; }
\Config::set('security.uri_filter', array_merge(array('\\Admin::module_url_filter'), \Config::get('security.uri_filter'))); } else { if (\Config::get('cmf.module_urls', false) !== false) { \Config::set('security.uri_filter', array_merge(array('\\CMF::module_url_filter'), \Config::get('security.uri_filter'))); } } // Load up the required packages Package::load(array('email', 'parser')); // Override some external classes Autoloader::add_core_namespace('CMF\\Core', true); Autoloader::add_classes(array('CMF\\Core\\View_Twig' => __DIR__ . '/classes/CMF/Core/View_Twig.php', 'CMF\\Core\\Image_Driver' => __DIR__ . '/classes/CMF/Core/Image_Driver.php', 'CMF\\Core\\Lang' => __DIR__ . '/classes/CMF/Core/Lang.php', 'CMF\\Core\\Format' => __DIR__ . '/classes/CMF/Core/Format.php', 'CMF\\Core\\Error' => __DIR__ . '/classes/CMF/Core/Error.php', 'CMF\\Core\\HttpException' => __DIR__ . '/classes/CMF/Core/HttpException.php')); // Sort out the language \Lang::load('errors', true); \Lang::load('admin', true); \Lang::load('site', true); $lang = \CMF::lang(); // Quick and easy profiling using 'debug' in the query string if (isset($_GET['debug']) && !\Fuel::$profiling) { \Fuel::$profiling = true; \Profiler::init(); \Config::load('db', true); \Config::set('db.default.profiling', true); } // Listen for events at the beginning of the request for caching \Event::register('controller_started', 'CMF\\Cache::start'); // Add CMF's modules directory so it's modules can be autoloaded $module_paths = Config::get('module_paths'); $module_paths[] = CMFPATH . 'modules/'; Config::set('module_paths', $module_paths); if ($isAdmin) { \Admin::initialize();
/** * Set up the array of "child" languages which need to be updated by others */ protected function initLanguages() { // Only need to do this once! if ($this->childLanguages !== null) { return; } $this->childLanguages = \CMF\Model\Language::select('item', 'item', 'item.code')->where('update_from IS NOT NULL')->andWhere('update_from.code = :code')->andWhere('item.visible = true')->leftJoin('item.update_from', 'update_from')->setParameter('code', \CMF::lang())->getQuery()->getResult(); }
public static function shutdown() { if (count(static::$to_save) > 0) { $groups = static::$to_save; $output = array(); foreach ($groups as $group) { $lft_db = static::load("{$group}.db", $group, \CMF::lang(), true, true); $rgt_db = static::load("{$group}.db", $group, static::$fallback[0], true, true); $lft = \Arr::get(static::$lines, \CMF::lang() . '.' . $group, array()); $rgt = \Arr::get(static::$lines, static::$fallback[0] . '.' . $group, array()); $lft = \Arr::merge($lft_db, $lft); $rgt = \Arr::merge($rgt_db, $rgt); foreach ($rgt as $key => $phrase) { if (!isset($lft[$key])) { $lft[$key] = $phrase; } } foreach ($lft as $key => $phrase) { if (!isset($rgt[$key])) { $rgt[$key] = $phrase; } } static::save("{$group}.db", $lft, \CMF::lang()); static::save("{$group}.db", $rgt, static::$fallback[0]); } exit; } }
/** * Constructs a cache key unique to the provided URL, or for the current * url if one is not provided * * @param string $uri * @return string */ public static function uriCacheKey($uri = null) { if ($uri === null && static::$uriCacheKey !== null) { return static::$uriCacheKey; } $uri = $uri !== null ? trim($uri, '/') : trim($_SERVER['REQUEST_URI'], '/'); if ($uri == '') { $uri = '__home__'; } if (\CMF::$lang_enabled) { $uri .= \CMF::lang(); } $session_keys = \Config::get('cmf.cache.session_index', array()); $session = \Session::get(); foreach ($session as $key => $value) { if (in_array($key, $session_keys)) { return static::$uriCacheKey = $key . '/' . $value . '/' . md5($uri); } } return static::$uriCacheKey = md5($uri); }