Example #1
0
 /**
  * Constructor
  *
  * Instantiate the datalist text input form element
  *
  * @param  string $name
  * @param  array  $values
  * @param  string $value
  * @param  string $indent
  * @return Datalist
  */
 public function __construct($name, array $values, $value = null, $indent = null)
 {
     parent::__construct($name, $value, $indent);
     $this->setAttribute('list', $name . '_datalist');
     if (null !== $values) {
         $this->datalist = new Child('datalist', null, null, $this->indent);
         $this->datalist->setAttribute('id', $name . '_datalist');
         foreach ($values as $key => $val) {
             $this->datalist->addChild((new Child('option', $val))->setAttribute('value', $key));
         }
     }
 }
Example #2
0
 /**
  * Constructor
  *
  * Instantiate the set of checkbox input form elements
  *
  * @param  string       $name
  * @param  array        $values
  * @param  string       $indent
  * @param  string|array $marked
  * @return CheckboxSet
  */
 public function __construct($name, array $values, $indent = null, $marked = null)
 {
     if (null !== $marked) {
         if (!is_array($marked)) {
             $marked = [$marked];
         }
     } else {
         $marked = [];
     }
     parent::__construct('fieldset', null, null, false, $indent);
     $this->attributes['class'] = 'checkbox-fieldset';
     $this->setMarked($marked);
     $this->setName($name . '[]');
     // Create the checkbox elements and related span elements.
     $i = null;
     foreach ($values as $k => $v) {
         $checkbox = new Input\Checkbox($name . '[]', null, $indent);
         $checkbox->setAttributes(['class' => 'checkbox', 'id' => $name . $i, 'value' => $k]);
         // Determine if the current radio element is checked.
         if (in_array($k, $this->marked)) {
             $checkbox->setAttribute('checked', 'checked');
         }
         $span = new Child('span', null, null, false, $indent);
         $span->setAttribute('class', 'checkbox-span');
         $span->setNodeValue($v);
         $this->addChildren([$checkbox, $span]);
         $this->checkboxes[] = $checkbox;
         $i++;
     }
     $this->value = $values;
 }
Example #3
0
 /**
  * Constructor
  *
  * Instantiate the radio input form elements
  *
  * @param  string $name
  * @param  array  $values
  * @param  string $indent
  * @param  string $marked
  * @return RadioSet
  */
 public function __construct($name, array $values, $indent = null, $marked = null)
 {
     parent::__construct('fieldset', null, null, false, $indent);
     $this->attributes['class'] = 'radio-fieldset';
     $this->setMarked($marked);
     $this->setName($name);
     // Create the radio elements and related span elements.
     $i = null;
     foreach ($values as $k => $v) {
         $radio = new Input\Radio($name, null, $indent);
         $radio->setAttributes(['class' => 'radio', 'id' => $name . $i, 'value' => $k]);
         // Determine if the current radio element is checked.
         if (null !== $this->marked && $k == $this->marked) {
             $radio->setAttribute('checked', 'checked');
         }
         $span = new Child('span', null, null, false, $indent);
         $span->setAttribute('class', 'radio-span');
         $span->setNodeValue($v);
         $this->addChildren([$radio, $span]);
         $this->radios[] = $radio;
         $i++;
     }
     $this->value = $values;
 }
Example #4
0
 /**
  * Constructor
  *
  * Instantiate the select form element object
  *
  * @param  string       $name
  * @param  string|array $values
  * @param  string       $indent
  * @param  array        $config
  * @return Select
  */
 public function __construct($name, $values, $indent = null, array $config = null)
 {
     $marked = isset($config['marked']) ? $config['marked'] : null;
     $multiple = isset($config['multiple']) ? (bool) $config['multiple'] : false;
     $data = isset($config['data']) ? $config['data'] : null;
     parent::__construct($this->type, null, null, false, $indent);
     $this->setAttributes(['name' => $name, 'id' => $name]);
     $this->setAsMultiple($multiple);
     $this->setMarked($marked);
     $values = self::parseValues($values, $data);
     // Create the child option elements.
     foreach ($values as $k => $v) {
         if (is_array($v)) {
             $opt = new Child('optgroup', null, null, false, $indent);
             $opt->setAttribute('label', $k);
             foreach ($v as $ky => $vl) {
                 $o = new Child('option', null, null, false, $indent);
                 $o->setAttribute('value', $ky);
                 // Determine if the current option element is selected.
                 if (is_array($this->marked)) {
                     if (in_array($ky, $this->marked, true)) {
                         $o->setAttribute('selected', 'selected');
                     }
                 } else {
                     if (null !== $this->marked && $ky == $this->marked) {
                         $o->setAttribute('selected', 'selected');
                     }
                 }
                 $o->setNodeValue($vl);
                 $opt->addChild($o);
             }
         } else {
             $opt = new Child('option', null, null, false, $indent);
             $opt->setAttribute('value', $k);
             // Determine if the current option element is selected.
             if (is_array($this->marked)) {
                 if (in_array($k, $this->marked, true)) {
                     $opt->setAttribute('selected', 'selected');
                 }
             } else {
                 if (null !== $this->marked && $k == $this->marked) {
                     $opt->setAttribute('selected', 'selected');
                 }
             }
             $opt->setNodeValue($v);
         }
         $this->addChild($opt);
     }
     $this->setValue($values);
     $this->setName($name);
 }
Example #5
0
 /**
  * Build single view
  *
  * @param  mixed  $object
  * @param  string $dateFormat
  * @throws \Phire\Exception
  * @return mixed
  */
 public function buildSingle($object, $dateFormat = null)
 {
     if (!isset($this->data['id'])) {
         throw new \Phire\Exception('Error: A view has not been selected.');
     }
     $view = null;
     $viewName = str_replace(' ', '-', strtolower($this->data['name']));
     $linkField = $this->hasLinkField($this->data['single_fields_names']);
     $dateField = $this->hasDateField($this->data['single_fields_names']);
     if (null === $linkField && isset($object->uri)) {
         $linkField = 'uri';
     }
     if (null === $dateField && isset($object->publish)) {
         $dateField = 'publish';
     }
     switch ($this->data['single_style']) {
         case 'table':
             $view = new Child('table');
             $view->setAttributes(['id' => $viewName . '-single-view-' . $this->data['id'], 'class' => $viewName . '-single-view']);
             foreach ($this->data['single_fields_names'] as $field) {
                 if ($field !== $linkField) {
                     $tr = new Child('tr');
                     if ($this->data['single_headers']) {
                         $tr->addChild(new Child('th', ucwords(str_replace(['_', '-'], [' ', ' '], $field)) . ':'));
                     }
                     if ($field == 'title' && null !== $linkField && isset($object[$field]) && isset($object[$linkField])) {
                         $td = new Child('td');
                         $a = new Child('a', $object[$field]);
                         $a->setAttribute('href', $object[$linkField]);
                         $td->addChild($a);
                         $tr->addChild($td);
                     } else {
                         if ($field !== $linkField) {
                             if (isset($object[$field])) {
                                 if ($field === $dateField && null !== $dateFormat) {
                                     $value = date($dateFormat, strtotime($object[$field]));
                                 } else {
                                     $value = $object[$field];
                                 }
                             } else {
                                 $value = ' ';
                             }
                             $tr->addChild(new Child('td', $value));
                         }
                     }
                     $view->addChild($tr);
                 }
             }
             break;
         case 'ul':
         case 'ol':
             $view = new Child('div');
             $view->setAttributes(['id' => $viewName . '-single-view-' . $this->data['id'], 'class' => $viewName . '-single-view']);
             $list = $this->data['single_style'] == 'ol' ? new Child('ol') : new Child('ul');
             foreach ($this->data['single_fields_names'] as $field) {
                 $li = new Child('li', null, null, true);
                 if ($this->data['single_headers'] && $field !== $linkField) {
                     $li->addChild(new Child('strong', ucwords(str_replace(['_', '-'], [' ', ' '], $field)) . ':'));
                 }
                 if ($field == 'title' && null !== $linkField && isset($object[$field]) && isset($object[$linkField])) {
                     $a = new Child('a', $object[$field]);
                     $a->setAttribute('href', $object[$linkField]);
                     $li->addChild($a);
                     $list->addChild($li);
                 } else {
                     if ($field !== $linkField) {
                         if (isset($object[$field])) {
                             if ($field === $dateField && null !== $dateFormat) {
                                 $value = date($dateFormat, strtotime($object[$field]));
                             } else {
                                 $value = $object[$field];
                             }
                         } else {
                             $value = ' ';
                         }
                         $li->setNodeValue($value);
                         $list->addChild($li);
                     }
                 }
             }
             $view->addChild($list);
             break;
         case 'div':
             $view = new Child('div');
             $view->setAttributes(['id' => $viewName . '-single-view-' . $this->data['id'], 'class' => $viewName . '-single-view']);
             $section = new Child('section');
             if (in_array('title', $this->data['single_fields_names']) && isset($object['title'])) {
                 if (null !== $linkField && isset($object[$linkField])) {
                     $h2 = new Child('h2');
                     $a = new Child('a', $object['title']);
                     $a->setAttribute('href', $object[$linkField]);
                     $h2->addChild($a);
                 } else {
                     $h2 = new Child('h2', $object['title']);
                 }
                 $section->addChild($h2);
             }
             if (null !== $dateField && null !== $dateFormat) {
                 if (in_array($dateField, $this->data['single_fields_names']) && isset($object[$dateField])) {
                     $section->addChild(new Child('h5', date($dateFormat, strtotime($object[$dateField]))));
                 }
             }
             foreach ($this->data['single_fields_names'] as $field) {
                 if ($field !== 'title' && ($field !== $dateField || null === $dateFormat) && $field !== $linkField) {
                     $value = isset($object[$field]) ? $object[$field] : ' ';
                     if ($this->data['single_headers']) {
                         $value = '<strong>' . ucwords(str_replace(['_', '-'], [' ', ' '], $field)) . '</strong>: ' . $value;
                     }
                     $section->addChild(new Child('p', $value));
                 }
             }
             $view->addChild($section);
             break;
     }
     return $view;
 }
Example #6
0
 /**
  * Render view template file
  *
  * @return void
  */
 protected function renderTemplate()
 {
     if (null !== $this->form) {
         // Get names and labels
         $children = $this->form->getChildren();
         $template = $this->template;
         // Loop through the child elements of the form.
         foreach ($children as $child) {
             // Clear the password field from display.
             if ($child->getAttribute('type') == 'password') {
                 $child->setValue(null);
                 $child->setAttribute('value', null);
             }
             // Get the element name.
             if ($child->getNodeName() == 'fieldset') {
                 $chdrn = $child->getChildren();
                 $attribs = $chdrn[0]->getAttributes();
             } else {
                 $attribs = $child->getAttributes();
             }
             $name = isset($attribs['name']) ? $attribs['name'] : '';
             $name = str_replace('[]', '', $name);
             // Set the element's label, if applicable.
             if (null !== $child->getLabel()) {
                 // Format the label name.
                 $label = new Child('label', $child->getLabel());
                 $label->setAttribute('for', $name);
                 $labelAttributes = $child->getLabelAttributes();
                 if (null !== $labelAttributes) {
                     foreach ($labelAttributes as $a => $v) {
                         $label->setAttribute($a, $v);
                     }
                 } else {
                     if ($child->isRequired()) {
                         $label->setAttribute('class', 'required');
                     }
                 }
                 // Swap the element's label placeholder with the rendered label element.
                 $labelReplace = $label->render(true);
                 $labelReplace = substr($labelReplace, 0, -1);
                 ${$name . '_label'} = $labelReplace;
             }
             // Calculate the element's indentation.
             $childIndent = substr($template, 0, strpos($template, '[{' . $name . '}]'));
             $childIndent = substr($childIndent, strrpos($childIndent, "\n") + 1);
             // Some whitespace clean up
             $length = strlen($childIndent);
             $last = 0;
             $matches = [];
             preg_match_all('/[^\\s]/', $childIndent, $matches, PREG_OFFSET_CAPTURE);
             if (isset($matches[0])) {
                 foreach ($matches[0] as $str) {
                     $childIndent = str_replace($str[0], null, $childIndent);
                     $last = $str[1];
                 }
             }
             // Final whitespace clean up
             $childIndent = substr($childIndent, 0, 0 - abs($length - $last));
             // Set each child element's indentation.
             $childChildren = $child->getChildren();
             $child->removeChildren();
             foreach ($childChildren as $cChild) {
                 $cChild->setIndent($childIndent . '    ');
                 $child->addChild($cChild);
             }
             // Swap the element's placeholder with the rendered element.
             $elementReplace = $child->render(true, 0, null, $childIndent);
             $elementReplace = substr($elementReplace, 0, -1);
             $elementReplace = str_replace('</select>', $childIndent . '</select>', $elementReplace);
             $elementReplace = str_replace('</fieldset>', $childIndent . '</fieldset>', $elementReplace);
             ${$name} = $elementReplace;
         }
         $action = $this->form->getAttribute('action');
         $method = $this->form->getAttribute('method');
         $form = $this->form;
     }
     ob_start();
     include $this->template;
     $this->output = ob_get_clean();
 }
Example #7
0
 /**
  * Method to render the form using a basic 1:1 DT/DD layout
  *
  * @return string
  */
 protected function renderWithoutTemplate()
 {
     // Initialize properties.
     $this->output = null;
     $children = $this->getChildren();
     $this->removeChildren();
     $id = null !== $this->getAttribute('id') ? $this->getAttribute('id') . '-field-group' : 'pop-form-field-group';
     // Create DL element.
     $i = 1;
     $dl = new Child('dl', null, null, false, $this->getIndent());
     $dl->setAttribute('id', $id . '-' . $i);
     $dl->setAttribute('class', $id);
     // Loop through the children and create and attach the appropriate DT and DT elements, with labels where applicable.
     foreach ($children as $child) {
         if ($child->getNodeName() == 'fieldset') {
             $chdrn = $child->getChildren();
             if (isset($chdrn[0])) {
                 $attribs = $chdrn[0]->getAttributes();
             }
         } else {
             $attribs = $child->getAttributes();
         }
         $name = isset($attribs['name']) ? $attribs['name'] : '';
         $name = str_replace('[]', '', $name);
         if (count($this->groups) > 0) {
             if (isset($this->groups[$i]) && $this->groups[$i] == $name) {
                 $this->addChild($dl);
                 $i++;
                 $dl = new Child('dl', null, null, false, $this->getIndent());
                 $dl->setAttribute('id', $id . '-' . $i);
                 $dl->setAttribute('class', $id);
             }
         }
         // Clear the password field from display.
         if ($child->getAttribute('type') == 'password') {
             $child->setValue(null);
             $child->setAttribute('value', null);
         }
         // If the element label is set, render the appropriate DT and DD elements.
         if ($child instanceof Element\AbstractElement && null !== $child->getLabel()) {
             // Create the DT and DD elements.
             $dt = new Child('dt', null, null, false, $this->getIndent() . '    ');
             $dd = new Child('dd', null, null, false, $this->getIndent() . '    ');
             // Format the label name.
             $lblName = $child->getNodeName() == 'fieldset' ? '1' : '';
             $label = new Child('label', $child->getLabel(), null, false, $this->getIndent() . '        ');
             $label->setAttribute('for', $name . $lblName);
             $labelAttributes = $child->getLabelAttributes();
             if (null !== $labelAttributes) {
                 foreach ($labelAttributes as $a => $v) {
                     $label->setAttribute($a, $v);
                 }
             } else {
                 if ($child->isRequired()) {
                     $label->setAttribute('class', 'required');
                 }
             }
             // Add the appropriate children to the appropriate elements.
             $dt->addChild($label);
             $child->setIndent($this->getIndent() . '        ');
             $childChildren = $child->getChildren();
             $child->removeChildren();
             foreach ($childChildren as $cChild) {
                 $cChild->setIndent($this->getIndent() . '            ');
                 $child->addChild($cChild);
             }
             $dd->addChild($child);
             $dl->addChildren([$dt, $dd]);
             // Else, render only a DD element.
         } else {
             $dd = new Child('dd', null, null, false, $this->getIndent() . '    ');
             $child->setIndent($this->getIndent() . '        ');
             $dd->addChild($child);
             $dl->addChild($dd);
         }
     }
     // Add the DL element and its children to the form element.
     $this->addChild($dl);
     return parent::render(true);
 }
Example #8
0
 /**
  * Traverse the config object
  *
  * @param  array  $tree
  * @param  int    $depth
  * @param  string $parentHref
  * @throws Exception
  * @return \Pop\Dom\Child
  */
 protected function traverse(array $tree, $depth = 1, $parentHref = null)
 {
     // Create overriding top level parent, if set
     if ($depth == 1 && isset($this->config['top'])) {
         $parent = isset($this->config['top']) && isset($this->config['top']['node']) ? $this->config['top']['node'] : 'nav';
         $child = null;
         if (isset($this->config['child']) && isset($this->config['child']['node'])) {
             $child = $this->config['child']['node'];
         } else {
             if ($parent == 'nav') {
                 $child = 'nav';
             }
         }
         // Create parent node
         $nav = new Child($parent);
         if (null !== $this->indent) {
             $nav->setIndent(str_repeat($this->indent, $depth));
         }
         // Set top attributes if they exist
         if (isset($this->config['top']) && isset($this->config['top']['id'])) {
             $nav->setAttribute('id', $this->config['top']['id']);
         }
         if (isset($this->config['top']) && isset($this->config['top']['class'])) {
             $nav->setAttribute('class', $this->config['top']['class']);
         }
         if (isset($this->config['top']['attributes'])) {
             foreach ($this->config['top']['attributes'] as $attrib => $value) {
                 $nav->setAttribute($attrib, $value);
             }
         }
     } else {
         // Set up parent/child node names
         $parent = isset($this->config['parent']) && isset($this->config['parent']['node']) ? $this->config['parent']['node'] : 'nav';
         $child = null;
         if (isset($this->config['child']) && isset($this->config['child']['node'])) {
             $child = $this->config['child']['node'];
         } else {
             if ($parent == 'nav') {
                 $child = 'nav';
             }
         }
         // Create parent node
         $nav = new Child($parent);
         if (null !== $this->indent) {
             $nav->setIndent(str_repeat($this->indent, $depth));
         }
         // Set parent attributes if they exist
         if (isset($this->config['parent']) && isset($this->config['parent']['id'])) {
             $nav->setAttribute('id', $this->config['parent']['id'] . '-' . $this->parentLevel);
         }
         if (isset($this->config['parent']) && isset($this->config['parent']['class'])) {
             $nav->setAttribute('class', $this->config['parent']['class'] . '-' . $depth);
         }
         if (isset($this->config['parent']['attributes'])) {
             foreach ($this->config['parent']['attributes'] as $attrib => $value) {
                 $nav->setAttribute($attrib, $value);
             }
         }
     }
     $this->parentLevel++;
     $depth++;
     // Recursively loop through the nodes
     foreach ($tree as $node) {
         $allowed = true;
         if (isset($node['acl'])) {
             if (null === $this->acl) {
                 throw new Exception('The access control object is not set.');
             }
             if (null === $this->role) {
                 $allowed = false;
             } else {
                 $resource = isset($node['acl']['resource']) ? $node['acl']['resource'] : null;
                 $permission = isset($node['acl']['permission']) ? $node['acl']['permission'] : null;
                 $allowed = $this->acl->isAllowed($this->role, $resource, $permission);
             }
         }
         if ($allowed && isset($node['name']) && isset($node['href'])) {
             // Create child node and child link node
             $a = new Child('a', $node['name']);
             if (substr($node['href'], 0, 1) == '#' || substr($node['href'], -1) == '#' || substr($node['href'], 0, 4) == 'http' || substr($node['href'], 0, 7) == 'mailto:') {
                 $href = $node['href'];
             } else {
                 if (substr($node['href'], 0, 1) == '/') {
                     $href = $this->baseUrl . $node['href'];
                 } else {
                     if (substr($parentHref, -1) == '/') {
                         $href = $parentHref . $node['href'];
                     } else {
                         $href = $parentHref . '/' . $node['href'];
                     }
                 }
             }
             $a->setAttribute('href', $href);
             if ($this->returnFalse && ($href == '#' || substr($href, -1) == '#')) {
                 $a->setAttribute('onclick', 'return false;');
             }
             $url = $_SERVER['REQUEST_URI'];
             if (strpos($url, '?') !== false) {
                 $url = substr($url, strpos($url, '?'));
             }
             $linkClass = null;
             if ($href == $url) {
                 if (isset($this->config['on'])) {
                     $linkClass = $this->config['on'];
                 }
             } else {
                 if (isset($this->config['off'])) {
                     $linkClass = $this->config['off'];
                 }
             }
             // If the node has any attributes
             if (isset($node['attributes'])) {
                 foreach ($node['attributes'] as $attrib => $value) {
                     $value = $attrib == 'class' && null !== $linkClass ? $value . ' ' . $linkClass : $value;
                     $a->setAttribute($attrib, $value);
                 }
             } else {
                 if (null !== $linkClass) {
                     $a->setAttribute('class', $linkClass);
                 }
             }
             if (null !== $child) {
                 $navChild = new Child($child);
                 // Set child attributes if they exist
                 if (isset($this->config['child']) && isset($this->config['child']['id'])) {
                     $navChild->setAttribute('id', $this->config['child']['id'] . '-' . $this->childLevel);
                 }
                 if (isset($this->config['child']) && isset($this->config['child']['class'])) {
                     $navChild->setAttribute('class', $this->config['child']['class'] . '-' . ($depth - 1));
                 }
                 if (isset($this->config['child']['attributes'])) {
                     foreach ($this->config['child']['attributes'] as $attrib => $value) {
                         $navChild->setAttribute($attrib, $value);
                     }
                 }
                 // Add link node
                 $navChild->addChild($a);
                 $this->childLevel++;
                 // If there are children, loop through and add them
                 if (isset($node['children']) && is_array($node['children']) && count($node['children']) > 0) {
                     $childrenAllowed = true;
                     // Check if the children are allowed
                     $i = 0;
                     foreach ($node['children'] as $nodeChild) {
                         if (isset($nodeChild['acl'])) {
                             if (null === $this->acl) {
                                 throw new Exception('The access control object is not set.');
                             }
                             if (null === $this->role) {
                                 $childrenAllowed = false;
                             } else {
                                 $resource = isset($nodeChild['acl']['resource']) ? $nodeChild['acl']['resource'] : null;
                                 $permission = isset($nodeChild['acl']['permission']) ? $nodeChild['acl']['permission'] : null;
                                 if (!$this->acl->isAllowed($this->role, $resource, $permission)) {
                                     $i++;
                                 }
                             }
                         }
                     }
                     if ($i == count($node['children'])) {
                         $childrenAllowed = false;
                     }
                     if ($childrenAllowed) {
                         $nextChild = $this->traverse($node['children'], $depth, $href);
                         if ($nextChild->hasChildren() || null !== $nextChild->getNodeValue()) {
                             $navChild->addChild($nextChild);
                         }
                     }
                 }
                 // Add child node
                 $nav->addChild($navChild);
             } else {
                 $nav->addChild($a);
             }
         }
     }
     return $nav;
 }
Example #9
0
 /**
  * Build social nav
  *
  * @return mixed
  */
 public function buildNav()
 {
     $nav = null;
     $hasUrl = false;
     $config = Table\Config::findById('social_config');
     if (isset($config->value) && !empty($config->value) && $config->value != '') {
         $cfg = unserialize($config->value);
         $style = $cfg['style'];
         $this->data = array_merge($this->data, $cfg);
         switch ($cfg['size']) {
             case 'large':
                 $size = 64;
                 break;
             case 'medium':
                 $size = 48;
                 break;
             default:
                 $size = 32;
         }
         $nav = new Child('nav');
         $nav->setAttribute('class', 'social-media-' . $size);
         foreach ($cfg['order'] as $name) {
             if (!empty($cfg['urls'][$name]['url']) && $cfg['urls'][$name]['url'] != '') {
                 $a = new Child('a', ucfirst($name));
                 $a->setAttributes(['class' => $name . '-' . $size . '-' . $style, 'href' => $cfg['urls'][$name]['url']]);
                 if ($cfg['urls'][$name]['new']) {
                     $a->setAttribute('target', '_blank');
                 }
                 $nav->addChild($a);
                 $hasUrl = true;
             }
         }
         if (!$hasUrl) {
             $nav = null;
         }
     }
     return $nav;
 }
Example #10
0
 /**
  * Get content archive
  *
  * @param  boolean $count
  * @return mixed
  */
 public function getArchive($count = true)
 {
     $sql = Table\Content::sql();
     $sql->select(['publish' => DB_PREFIX . 'content.publish', 'in_date' => DB_PREFIX . 'content_types.in_date']);
     $sql->select()->join(DB_PREFIX . 'content_types', [DB_PREFIX . 'content_types.id' => DB_PREFIX . 'content.type_id']);
     $sql->select()->where('status = :status')->where('in_date = :in_date');
     $sql->select()->orderBy('publish', 'DESC');
     $params = ['status' => 1, 'in_date' => 1];
     $content = Table\Content::execute((string) $sql, $params);
     $archive = [];
     foreach ($content->rows() as $c) {
         $year = substr($c->publish, 0, 4);
         if (isset($archive[$year])) {
             $archive[$year]++;
         } else {
             $archive[$year] = 1;
         }
     }
     $archiveNav = null;
     if (count($archive) > 0) {
         $archiveNav = new Child('ul');
         $archiveNav->setAttributes(['id' => 'archive-nav', 'class' => 'archive-nav']);
         foreach ($archive as $year => $num) {
             $link = $count ? $year . ' <span>(' . $num . ')</span>' : $year;
             $a = new Child('a', $link);
             $a->setAttribute('href', BASE_PATH . '/' . $year);
             $li = new Child('li');
             $li->addChild($a);
             $archiveNav->addChild($li);
         }
     }
     return $archiveNav;
 }