Exemplo n.º 1
0
 /**
  * Processes the value of this field before getting set to the model in the populate() method
  * @see \CMF\Model\Base::populate()
  * @param mixed $value The value about to be set
  * @param array $settings The settings for this field
  * @param object $model The model
  * @return mixed The value ready for setting on the model
  */
 public static function process($value, $settings, $model)
 {
     if (!(isset($settings['auto_update']) && !$settings['auto_update']) && (isset($settings['template']) && !empty($settings['template']))) {
         $post_data = $context = \Input::post();
         if (!is_array($context)) {
             $context = array();
         }
         $context['model'] = $model;
         if (class_exists('Model_Settings')) {
             $context['settings'] = \Model_Settings::instance();
         }
         $twig = \View_Twig::parser();
         $loader = \View_Twig::loader();
         if (!isset($loader) || is_null($loader)) {
             $loader = new Twig_Loader_String();
             $twig->setLoader($loader);
             \View_Twig::setLoader($loader);
         }
         return $twig->render($settings['template'], $context);
     }
     return $value;
 }
Exemplo n.º 2
0
 /**
  * Loops through the provided nocache names and injects their executed values
  * into the content
  * 
  */
 public static function addNoCacheAreas($names, $content, $context)
 {
     if (count($names) === 0 || !$names) {
         return $content;
     }
     static::$modified = true;
     // Set up the twig environment for rendering the non-cached parts
     \View_Twig::initLoader();
     $env = \View_Twig::parser();
     $template = new \CMF\Twig\TemplateInclude($env);
     if (empty($context)) {
         $context = array();
     }
     if (!empty($context['template'])) {
         $module = @$context['module'];
         // Determine whether the ViewModel class exists...
         if ($viewClass = \CMF::hasViewModel($context['template'])) {
             $context['view'] = new $viewClass('view', false, $context['template']);
         } else {
             try {
                 $viewClass = ucfirst($module) . '\\View_Base';
                 if (!class_exists($viewClass)) {
                     $viewClass = '\\View_Base';
                 }
                 $context['view'] = new $viewClass('view', false, $context['template']);
             } catch (\Exception $e) {
             }
         }
     }
     foreach ($names as $name => $include) {
         $content = preg_replace('/<!-- nocache_' . $name . ' .*<!-- endnocache_' . $name . ' -->/sU', $template->renderInclude($include, $context), $content);
     }
     return $content;
 }