Ejemplo n.º 1
0
 public function compileTag()
 {
     $this->openTag('style', ['type' => 'text/css']);
     $this->text(['/* ', $this->getNode('value'), " */\n"]);
     $this->compiler->write("print file_get_contents('" . \Fierce\Env::get('base_path') . "' . ")->subcompile($this->getNode('value'))->write(");\n");
     $this->closeTag('style');
 }
Ejemplo n.º 2
0
 public function compileTag()
 {
     // apply class to the field
     $classNode = new \Twig_Node_Expression_Constant('photo_upload ', $this->lineno);
     if ($this->hasNode('class')) {
         $classNode = new \Twig_Node([$classNode, $this->getNode('class')]);
     }
     $this->setNode('class', $classNode);
     // upload field id
     $this->compiler->write('$context[\'_fierce_photo_field_id\'] = trim(preg_replace(\'/[^a-zA-Z0-9_]+/\', \'_\', ')->subcompile($this->getNode('name'))->raw("), '_') . '_field';\n");
     $uploadFieldIdNode = new \Twig_Node_Expression_Name('_fierce_photo_field_id', $this->lineno);
     // preview nodes
     $this->compiler->write('$context[\'_fierce_photo_preview_wrapper_id\'] = trim(preg_replace(\'/[^a-zA-Z0-9_]+/\', \'_\', ')->subcompile($this->getNode('name'))->raw("), '_') . '_preview_wrapper';\n");
     $uploadPreviewWrapperIdNode = new \Twig_Node_Expression_Name('_fierce_photo_preview_wrapper_id', $this->lineno);
     $this->compiler->write('$context[\'_fierce_photo_preview_id\'] = trim(preg_replace(\'/[^a-zA-Z0-9_]+/\', \'_\', ')->subcompile($this->getNode('name'))->raw("), '_') . '_preview';\n");
     $uploadPreviewIdNode = new \Twig_Node_Expression_Name('_fierce_photo_preview_id', $this->lineno);
     $uploadPreviewSrcNode = new \Twig_Node_Expression_GetAttr(new \Twig_Node_Expression_Name('_fierce_current_form_data', $this->lineno), new \Twig_Node_Expression_Binary_Concat($this->getNode('name'), new \Twig_Node_Expression_Constant('_src', $this->lineno), $this->lineno), null, 'any', $this->lineno);
     // output upload field (for seleting files)
     $this->openTag('input', ['type' => 'file', 'class' => $classNode, 'name' => $this->getNode('name')]);
     // output hidden field (for actually holding the file contents)
     $this->openTag('input', ['type' => 'hidden', 'id' => $uploadFieldIdNode, 'name' => $this->getNode('name')]);
     // output preview
     $this->openTag('div', ['id' => $uploadPreviewWrapperIdNode, 'class' => 'photo_preview_wrapper']);
     $this->openTag('img', ['id' => $uploadPreviewIdNode, 'src' => $uploadPreviewSrcNode]);
     self::closeTag('div');
     // add js
     $this->requireScript(\Fierce\Env::get('fierce_src') . 'scripts/photo-field.controller.js');
 }
Ejemplo n.º 3
0
 public function compileTag()
 {
     $this->openTag('select', ['id' => $this->idNode(), 'name' => $this->getNode('name')]);
     $this->compiler->addDebugInfo($this)->write("\$context['_fierce_select_options'] = twig_ensure_traversable(")->subcompile($this->getNode('options'))->raw(");\n");
     $this->compiler->write("\$fierceSelectUseNameAsValue = array_keys(\$context['_fierce_select_options']) === range(0, count(\$context['_fierce_select_options']) - 1);\n")->write("foreach (\$context['_fierce_select_options'] as \$fierceSelectOptionValue => \$fierceSelectOptionName) {\n")->indent()->write("\$valueHtml = \$fierceSelectUseNameAsValue ? '' : 'value=\"' . htmlspecialchars(\$fierceSelectOptionValue) . '\"';\n")->write("\$value = \$fierceSelectUseNameAsValue ? \$fierceSelectOptionName : \$fierceSelectOptionValue;\n")->write("\$selectedHtml = \$value == ")->subcompile($this->valueNode())->raw(" ? 'selected' : '';\n")->write("print \"<option \$valueHtml \$selectedHtml>\" . htmlspecialchars(\$fierceSelectOptionName) . \"</option>\";\n")->outdent()->write("}\n");
     $this->closeTag('select');
     // add js
     $this->requireScript(\Fierce\Env::get('fierce_src') . 'scripts/tag-field.controller.js');
 }
Ejemplo n.º 4
0
 public function compileTag()
 {
     if (!$this->hasNode('class')) {
         $this->setNode('class', new \Twig_Node_Expression_Constant('date_field', $this->lineno));
     }
     parent::compileTag();
     $this->requireCss(\Fierce\Env::get('fierce_src') . 'css/date-field.css');
     $this->requireScript(\Fierce\Env::get('fierce_src') . 'scripts/calendar-field.controller.js');
 }
Ejemplo n.º 5
0
 public function compileTag()
 {
     $attributes = ['name' => $this->getNode('name'), 'id' => $this->idNode(), 'class' => 'wysiwyg'];
     $this->openTag('textarea', $attributes);
     $this->text($this->valueNode());
     $this->closeTag('textarea');
     $this->requireScript(\Fierce\Env::get('fierce_src') . 'scripts/wysiwyg.controller.js');
     $this->requireScript(\Fierce\Env::get('fierce_src') . 'third-party/ckeditor/ckeditor.js');
 }
Ejemplo n.º 6
0
 public static function printNav($identifier = 'main')
 {
     // fetch all pages, sorted by position
     $pages = \Fierce\Page::all('navPositionLeft');
     print '<ul class="nav">';
     $depth = 0;
     $first = true;
     foreach ($pages as $navPage) {
         // is this page in the nav?
         if (@$navPage->nav != $identifier) {
             continue;
         }
         // no change to depth? close the list item we left open in the last iteration.
         if (!$first && $navPage->navPositionDepth == $depth) {
             print '</li>';
         }
         // increase depth?
         while ($navPage->navPositionDepth > $depth) {
             print '<ul>';
             $depth++;
         }
         // reduce depth?
         if ($navPage->navPositionDepth < $depth) {
             while ($navPage->navPositionDepth < $depth) {
                 print '</li></ul>';
                 $depth--;
             }
             print '</li>';
         }
         // generate a nav item, leaving the list item open.
         $href = ltrim($navPage->url, '/');
         if ($href == '') {
             $href = './';
         }
         $href = htmlspecialchars($href);
         $name = htmlspecialchars($navPage->name);
         $isCurrent = \Fierce\Env::get('request_url') == $navPage->url;
         $classHtml = $isCurrent ? ' class="current"' : '';
         print '<li' . $classHtml . '><a href="' . $href . '">' . $name . '</a>';
         $first = false;
     }
     // close off open tags
     while ($depth >= 0) {
         print '</li></ul>';
         $depth--;
     }
 }
Ejemplo n.º 7
0
 public function compileTag()
 {
     // apply class to the field
     $classNode = new \Twig_Node_Expression_Constant('tag_field large ', $this->lineno);
     if ($this->hasNode('class')) {
         $classNode = new \Twig_Node([$classNode, $this->getNode('class')]);
     }
     $this->setNode('class', $classNode);
     // create list id node
     $this->compiler->write('$context[\'_fierce_tag_list_id\'] = trim(preg_replace(\'/[^a-zA-Z0-9_]+/\', \'_\', ')->subcompile($this->getNode('name'))->raw("), '_') . '_tags';\n");
     $listIdNode = new \Twig_Node_Expression_Name('_fierce_tag_list_id', $this->lineno);
     // output field
     parent::compileTag();
     // output list
     $this->openTag('ul', ['id' => $listIdNode, 'class' => 'tag_list']);
     $this->compiler->addDebugInfo($this)->write("\$context['_fierce_tag_list_options'] = twig_ensure_traversable(")->subcompile($this->getNode('options'))->raw(");\n");
     $this->compiler->write("foreach (\$context['_fierce_tag_list_options'] as \$fierceTagListOption) {\n")->indent()->write("print '<li>' . htmlspecialchars(\$fierceTagListOption) . '</li>';\n")->outdent()->write("}\n");
     self::closeTag('ul');
     // add js
     $this->requireScript(\Fierce\Env::get('fierce_src') . 'scripts/tag-field.controller.js');
 }