Author: Nick Sagona, III (dev@nolainteractive.com)
Inheritance: extends Pop\Dom\AbstractNode
Example #1
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 #2
0
 /**
  * Render the child and its child nodes
  *
  * @param  boolean $ret
  * @param  int     $depth
  * @param  string  $indent
  * @param  string  $errorIndent
  * @return mixed
  */
 public function render($ret = false, $depth = 0, $indent = null, $errorIndent = null)
 {
     $datalist = parent::render(true, $depth, $indent) . $this->datalist->render(true, $depth, $indent);
     // Return or print the rendered child node output.
     if ($ret) {
         return $datalist;
     } else {
         echo $datalist;
     }
 }
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
<?php

require_once '../../bootstrap.php';
use Pop\Dom\Child;
try {
    $children = array(array('nodeName' => 'h1', 'nodeValue' => 'This is a header', 'attributes' => array('class' => 'headerClass', 'style' => 'font-size: 3.0em;'), 'childrenFirst' => false, 'childNodes' => null), array('nodeName' => 'div', 'nodeValue' => 'This is a div element', 'attributes' => array('id' => 'contentDiv'), 'childrenFirst' => false, 'childNodes' => array(array('nodeName' => 'p', 'nodeValue' => 'This is a paragraph1', 'attributes' => array('style' => 'font-size: 0.9em;'), 'childrenFirst' => false, 'childNodes' => array(array('nodeName' => 'strong', 'nodeValue' => 'This is bold!', 'attributes' => array('style' => 'font-size: 1.2em;')))), array('nodeName' => 'p', 'nodeValue' => 'This is another paragraph!', 'attributes' => array('style' => 'font-size: 0.9em;')))));
    $parent = new Child('div');
    $parent->setIndent('    ')->addChildren($children);
    $parent->render();
} catch (\Exception $e) {
    echo $e->getMessage() . PHP_EOL . PHP_EOL;
}
Example #5
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 #6
0
 /**
  * Build rate request
  *
  * @return void
  */
 protected function buildRateRequest()
 {
     $rating = new Child('RatingServiceSelectionRequest');
     $request = new Child('Request');
     $transaction = new Child('TransactionReference');
     $pickup = new Child('PickupType');
     $shipment = new Child('Shipment');
     $customer = new Child('CustomerContext', 'Rating and Service');
     $xpci = new Child('XpciVersion', '1.0');
     $requestAction = new Child('RequestAction', 'Rate');
     $requestOption = new Child('RequestOption', 'Shop');
     $transaction->addChild($customer)->addChild($xpci);
     $request->addChild($transaction)->addChild($requestAction)->addChild($requestOption);
     $pickup->addChild(new Child('Code', $this->pickupType))->addChild(new Child('Description', self::$pickupTypes[$this->pickupType]));
     $shipment->addChild(new Child('Description', 'Rate'));
     $shipper = new Child('Shipper');
     $shipper->addChild(new Child('ShipperNumber', $this->userId));
     $shipTo = new Child('ShipTo');
     $shipFrom = new Child('ShipFrom');
     if (null !== $this->shipTo['CompanyName']) {
         $shipTo->addChild(new Child('CompanyName', $this->shipTo['CompanyName']));
     }
     if (null !== $this->shipFrom['CompanyName']) {
         $shipFrom->addChild(new Child('CompanyName', $this->shipFrom['CompanyName']));
     }
     $shipToAddress = new Child('Address');
     foreach ($this->shipTo as $key => $value) {
         if ($key !== 'CompanyName') {
             $shipToAddress->addChild(new Child($key, $value));
         }
     }
     $shipFromAddress = new Child('Address');
     foreach ($this->shipFrom as $key => $value) {
         if ($key !== 'CompanyName') {
             $shipFromAddress->addChild(new Child($key, $value));
         }
     }
     $shipTo->addChild($shipToAddress);
     $shipFrom->addChild($shipFromAddress);
     $shipper->addChild($shipFromAddress);
     $service = new Child('Service');
     $service->addChild(new Child('Code', $this->service))->addChild(new Child('Description', self::$services[$this->service]));
     $package = new Child('Package');
     $packageType = new Child('PackagingType');
     $packageType->addChild(new Child('Code', $this->packageType))->addChild(new Child('Description', self::$packagingTypes[$this->packageType]));
     $package->addChild($packageType)->addChild(new Child('Description', 'Rate'));
     if (null !== $this->dimensions['Length'] && null !== $this->dimensions['Width'] && null !== $this->dimensions['Height']) {
         $dimensions = new Child('Dimensions');
         $unit = new Child('UnitOfMeasurement');
         $unit->addChild(new Child('Code', $this->dimensions['UnitOfMeasurement']));
         $dimensions->addChild($unit)->addChild(new Child('Length', $this->dimensions['Length']))->addChild(new Child('Width', $this->dimensions['Width']))->addChild(new Child('Height', $this->dimensions['Height']));
         $package->addChild($dimensions);
     }
     $weight = new Child('PackageWeight');
     $unit = new Child('UnitOfMeasurement');
     $unit->addChild(new Child('Code', $this->weight['UnitOfMeasurement']));
     $weight->addChild($unit)->addChild(new Child('Weight', $this->weight['Weight']));
     $package->addChild($weight);
     $shipment->addChild($shipper)->addChild($shipTo)->addChild($shipFrom)->addChild($service)->addChild($package);
     $rating->addChild($request)->addChild($pickup)->addChild($shipment);
     $this->rateRequest->addChild($rating);
 }
Example #7
0
 /**
  * Method to render the form using the template
  *
  * @return void
  */
 protected function renderWithTemplate()
 {
     // Initialize properties and variables.
     $isFile = !(stripos($this->template, '.phtml') === false && stripos($this->template, '.php') === false);
     $template = $this->template;
     $fileContents = $isFile ? file_get_contents($this->template) : null;
     $this->output = null;
     $children = $this->form->getChildren();
     // 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->setAttributes('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->setAttributes('for', $name);
             $labelAttributes = $child->getLabelAttributes();
             if (null !== $labelAttributes) {
                 foreach ($labelAttributes as $a => $v) {
                     $label->setAttributes($a, $v);
                 }
             } else {
                 if ($child->isRequired()) {
                     $label->setAttributes('class', 'required');
                 }
             }
             // Swap the element's label placeholder with the rendered label element.
             $labelSearch = '[{' . $name . '_label}]';
             $labelReplace = $label->render(true);
             $labelReplace = substr($labelReplace, 0, -1);
             $template = str_replace($labelSearch, $labelReplace, $template);
             ${$name . '_label'} = $labelReplace;
         }
         // Calculate the element's indentation.
         if (null === $fileContents) {
             $childIndent = substr($template, 0, strpos($template, '[{' . $name . '}]'));
             $childIndent = substr($childIndent, strrpos($childIndent, "\n") + 1);
         } else {
             $childIndent = substr($fileContents, 0, strpos($fileContents, '$' . $name));
             $childIndent = substr($childIndent, strrpos($childIndent, "\n") + 1);
         }
         // Some whitespace clean up
         $length = strlen($childIndent);
         $last = 0;
         $matches = array();
         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
         if (null !== $fileContents) {
             $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.
         $elementSearch = '[{' . $name . '}]';
         $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);
         $template = str_replace($elementSearch, $elementReplace, $template);
         ${$name} = $elementReplace;
     }
     // Set the rendered form content and remove the children.
     if (!$isFile) {
         $this->form->setNodeValue("\n" . $template . "\n" . $this->form->getIndent());
         $this->form->removeChildren();
         $this->output = $this->form->render(true);
     } else {
         $action = $this->action;
         $method = $this->method;
         ob_start();
         include $this->template;
         $this->output = ob_get_clean();
     }
 }
Example #8
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 #9
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;
 }
Example #10
0
<?php

require_once '../../bootstrap.php';
use Pop\Dom\Child;
use Pop\Dom\Dom;
try {
    $title = new Child('title', 'This is the title');
    $meta = new Child('meta');
    $meta->setAttributes(array('http-equiv' => 'Content-Type', 'content' => 'text/html; charset=utf-8'));
    $head = new Child('head');
    $head->addChildren(array($title, $meta));
    $h1 = new Child('h1', 'This is a header');
    $p = new Child('p', 'This is a paragraph.');
    $div = new Child('div');
    $div->setAttributes('id', 'contentDiv');
    $div->addChildren(array($h1, $p));
    $body = new Child('body');
    $body->addChild($div);
    $html = new Child('html');
    $html->setAttributes(array('xmlns' => 'http://www.w3.org/1999/xhtml', 'xml:lang' => 'en'));
    $html->addChildren(array($head, $body));
    $doc = new Dom(Dom::XHTML11, 'utf-8', $html);
    $doc->render();
} catch (\Exception $e) {
    echo $e->getMessage() . PHP_EOL . PHP_EOL;
}
Example #11
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'] : 'ul';
         $child = null;
         if (isset($this->config['child']) && isset($this->config['child']['node'])) {
             $child = $this->config['child']['node'];
         } else {
             if ($parent == 'ul') {
                 $child = 'li';
             }
         }
         // Create parent node
         $nav = new Child($parent);
         // Set top attributes if they exist
         if (isset($this->config['top']) && isset($this->config['top']['id'])) {
             $nav->setAttributes('id', $this->config['top']['id']);
         }
         if (isset($this->config['top']) && isset($this->config['top']['class'])) {
             $nav->setAttributes('class', $this->config['top']['class']);
         }
         if (isset($this->config['top']['attributes'])) {
             foreach ($this->config['top']['attributes'] as $attrib => $value) {
                 $nav->setAttributes($attrib, $value);
             }
         }
     } else {
         // Set up parent/child node names
         $parent = isset($this->config['parent']) && isset($this->config['parent']['node']) ? $this->config['parent']['node'] : 'ul';
         $child = null;
         if (isset($this->config['child']) && isset($this->config['child']['node'])) {
             $child = $this->config['child']['node'];
         } else {
             if ($parent == 'ul') {
                 $child = 'li';
             }
         }
         // Create parent node
         $nav = new Child($parent);
         // Set parent attributes if they exist
         if (isset($this->config['parent']) && isset($this->config['parent']['id'])) {
             $nav->setAttributes('id', $this->config['parent']['id'] . '-' . $this->parentLevel);
         }
         if (isset($this->config['parent']) && isset($this->config['parent']['class'])) {
             $nav->setAttributes('class', $this->config['parent']['class'] . '-' . $depth);
         }
         if (isset($this->config['parent']['attributes'])) {
             foreach ($this->config['parent']['attributes'] as $attrib => $value) {
                 $nav->setAttributes($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) {
                 throw new Exception('The current role is not set.');
             }
             $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'], 0, 1) == '#' || substr($node['href'], -1) == '#' || substr($node['href'], 0, 4) == 'http') {
                 $href = $node['href'];
             } else {
                 if (substr($parentHref, -1) == '/') {
                     $href = $parentHref . $node['href'];
                 } else {
                     $href = $parentHref . '/' . $node['href'];
                 }
             }
             $a->setAttributes('href', $href);
             if ($this->returnFalse && ($href == '#' || substr($href, -1) == '#')) {
                 $a->setAttributes('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->setAttributes($attrib, $value);
                 }
             } else {
                 if (null !== $linkClass) {
                     $a->setAttributes('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->setAttributes('id', $this->config['child']['id'] . '-' . $this->childLevel);
                 }
                 if (isset($this->config['child']) && isset($this->config['child']['class'])) {
                     $navChild->setAttributes('class', $this->config['child']['class'] . '-' . ($depth - 1));
                 }
                 if (isset($this->config['child']['attributes'])) {
                     foreach ($this->config['child']['attributes'] as $attrib => $value) {
                         $navChild->setAttributes($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
                     if (isset($node['acl'])) {
                         $i = 0;
                         foreach ($node['children'] as $nodeChild) {
                             if (null === $this->acl) {
                                 throw new Exception('The access control object is not set.');
                             }
                             if (null === $this->role) {
                                 throw new Exception('The current role is not set.');
                             }
                             $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) {
                         $navChild->addChild($this->traverse($node['children'], $depth, $href));
                     }
                 }
                 // Add child node
                 $nav->addChild($navChild);
             } else {
                 $nav->addChild($a);
             }
         }
     }
     return $nav;
 }
Example #12
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 #13
0
 /**
  * Build social nav
  *
  * @param  string $description
  * @param  string $keywords
  * @return mixed
  */
 public function buildMetaTags($description = null, $keywords = null)
 {
     $metas = null;
     $hasDesc = false;
     $hasKeys = false;
     $config = Table\Config::findById('seo_config');
     if (isset($config->value) && !empty($config->value) && $config->value != '') {
         $cfg = unserialize($config->value);
         if (count($cfg['meta']) > 0) {
             foreach ($cfg['meta'] as $meta) {
                 $content = $meta['content'];
                 if ($meta['name'] == 'description') {
                     $hasDesc = true;
                     if (null !== $description && $description != '') {
                         $content = $description;
                     }
                 }
                 if ($meta['name'] == 'keywords') {
                     $hasKeys = true;
                     if (null !== $keywords && $keywords != '') {
                         $content = $keywords;
                     }
                 }
                 $m = new Child('meta');
                 $m->setAttributes(['name' => $meta['name'], 'content' => htmlentities($content, ENT_QUOTES, 'UTF-8')]);
                 $metas .= '    ' . (string) $m;
             }
             if (!$hasDesc && null !== $description && $description != '') {
                 $m = new Child('meta');
                 $m->setAttributes(['name' => 'description', 'content' => htmlentities($description, ENT_QUOTES, 'UTF-8')]);
                 $metas .= '    ' . (string) $m;
             }
             if (!$hasKeys && null !== $keywords && $keywords != '') {
                 $m = new Child('meta');
                 $m->setAttributes(['name' => 'keywords', 'content' => htmlentities($keywords, ENT_QUOTES, 'UTF-8')]);
                 $metas .= '    ' . (string) $m;
             }
         }
     }
     if (null === $metas) {
         if (null !== $description && $description != '') {
             $m = new Child('meta');
             $m->setAttributes(['name' => 'description', 'content' => htmlentities($description, ENT_QUOTES, 'UTF-8')]);
             $metas .= '    ' . (string) $m;
         }
         if (null !== $keywords && $keywords != '') {
             $m = new Child('meta');
             $m->setAttributes(['name' => 'keywords', 'content' => htmlentities($keywords, ENT_QUOTES, 'UTF-8')]);
             $metas .= '    ' . (string) $m;
         }
     }
     return $metas;
 }
Example #14
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 = '&nbsp;';
                             }
                             $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 = '&nbsp;';
                         }
                         $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] : '&nbsp;';
                     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 #15
0
 /**
  * Initialize the feed.
  *
  * @throws Exception
  * @return void
  */
 protected function init()
 {
     if ($this->feedType == Writer::RSS) {
         // Set up the RSS child node.
         $rss = new Child('rss');
         $rss->setAttributes('version', '2.0');
         $rss->setAttributes('xmlns:content', 'http://purl.org/rss/1.0/modules/content/');
         $rss->setAttributes('xmlns:wfw', 'http://wellformedweb.org/CommentAPI/');
         // Set up the Channel child node and the header children.
         $channel = new Child('channel');
         foreach ($this->headers as $key => $value) {
             $channel->addChild(new Child($key, $value));
         }
         // Set up the Item child nodes and add them to the Channel child node.
         foreach ($this->items as $itm) {
             $item = new Child('item');
             foreach ($itm as $key => $value) {
                 $item->addChild(new Child($key, $value));
             }
             $channel->addChild($item);
         }
         // Add the Channel child node to the RSS child node, add the RSS child node to the DOM.
         $rss->addChild($channel);
         $this->addChild($rss);
     } else {
         if ($this->feedType == Writer::ATOM) {
             // Set up the Feed child node.
             $feed = new Child('feed');
             $feed->setAttributes('xmlns', 'http://www.w3.org/2005/Atom');
             if (isset($this->headers['language'])) {
                 $feed->setAttributes('xml:lang', $this->headers['language']);
             }
             // Set up the header children.
             foreach ($this->headers as $key => $value) {
                 if ($key == 'author') {
                     $auth = new Child($key);
                     $auth->addChild(new Child('name', $value));
                     $feed->addChild($auth);
                 } else {
                     if ($key == 'link') {
                         $link = new Child($key);
                         $link->setAttributes('href', $value);
                         $feed->addChild($link);
                     } else {
                         if ($key != 'language') {
                             $val = stripos($key, 'date') !== false || stripos($key, 'published') !== false ? date($this->dateFormat, strtotime($value)) : $value;
                             $feed->addChild(new Child($key, $val));
                         }
                     }
                 }
             }
             // Set up the Entry child nodes and add them to the Feed child node.
             foreach ($this->items as $itm) {
                 $item = new Child('entry');
                 foreach ($itm as $key => $value) {
                     if ($key == 'link') {
                         $link = new Child($key);
                         $link->setAttributes('href', $value);
                         $item->addChild($link);
                     } else {
                         $val = stripos($key, 'date') !== false || stripos($key, 'published') !== false ? date($this->dateFormat, strtotime($value)) : $value;
                         $item->addChild(new Child($key, $val));
                     }
                 }
                 $feed->addChild($item);
             }
             // Add the Feed child node to the DOM.
             $this->addChild($feed);
         } else {
             if ($this->feedType == Writer::JSON || $this->feedType == Writer::PHP) {
                 // Set up the header data.
                 foreach ($this->headers as $key => $value) {
                     $val = stripos($key, 'date') !== false || stripos($key, 'published') !== false ? date($this->dateFormat, strtotime($value)) : $value;
                     $this->data[$key] = $val;
                 }
                 // Set up the items data
                 $this->data['items'] = array();
                 foreach ($this->items as $itm) {
                     foreach ($itm as $key => $value) {
                         $val = stripos($key, 'date') !== false || stripos($key, 'published') !== false ? date($this->dateFormat, strtotime($value)) : $value;
                         $itm[$key] = $val;
                     }
                     $this->data['items'][] = $itm;
                 }
                 // Set the content type
                 $this->contentType = $this->feedType == Writer::JSON ? 'application/json' : 'text/plain';
             } else {
                 throw new Exception('Error: The feed type must be only RSS, ATOM, JSON or PHP.');
             }
         }
     }
 }
Example #16
0
 /**
  * Render the child and its child nodes
  *
  * @param  boolean $ret
  * @param  int     $depth
  * @param  string  $indent
  * @param  string  $errorIndent
  * @return string
  */
 public function render($ret = false, $depth = 0, $indent = null, $errorIndent = null)
 {
     $output = parent::render(true, $depth, $indent);
     $errors = null;
     $container = $this->errorDisplay['container'];
     $attribs = null;
     foreach ($this->errorDisplay['attributes'] as $a => $v) {
         $attribs .= ' ' . $a . '="' . $v . '"';
     }
     // Add error messages if there are any.
     if (count($this->errors) > 0) {
         foreach ($this->errors as $msg) {
             if ($this->errorDisplay['pre']) {
                 $errors .= "{$indent}{$this->indent}<" . $container . $attribs . ">{$msg}</" . $container . ">\n{$errorIndent}";
             } else {
                 $errors .= "{$errorIndent}{$indent}{$this->indent}<" . $container . $attribs . ">{$msg}</" . $container . ">\n";
             }
         }
     }
     $this->output = $this->errorDisplay['pre'] ? $errors . $output : $output . $errors;
     if ($ret) {
         return $this->output;
     } else {
         echo $this->output;
     }
 }
Example #17
0
 /**
  * Build rate request
  *
  * @return void
  */
 protected function buildRequest()
 {
     $package = new Child('Package');
     $package->setAttributes('ID', '1ST');
     $package->addChild(new Child('Service', 'ALL'))->addChild(new Child('ZipOrigination', $this->shipFrom['ZipOrigination']))->addChild(new Child('ZipDestination', $this->shipTo['ZipDestination']))->addChild(new Child('Pounds', $this->weight['Pounds']))->addChild(new Child('Ounces', $this->weight['Ounces']))->addChild(new Child('Container', $this->container))->addChild(new Child('Size', $this->containerSize));
     if (null !== $this->dimensions['Length'] && null !== $this->dimensions['Width'] && null !== $this->dimensions['Height']) {
         $package->addChild(new Child('Width', $this->dimensions['Width']))->addChild(new Child('Length', $this->dimensions['Length']))->addChild(new Child('Height', $this->dimensions['Height']));
         if (null == $this->dimensions['Girth']) {
             $this->dimensions['Girth'] = 2 * $this->dimensions['Width'] + 2 * $this->dimensions['Height'];
         }
         $package->addChild(new Child('Girth', $this->dimensions['Girth']));
     }
     $package->addChild(new Child('Machinable', $this->machinable))->addChild(new Child('DropOffTime', '12:00'))->addChild(new Child('ShipDate', date('Y-m-d')));
     $this->request->addChild($package);
 }
Example #18
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 #19
0
 public function testSetAndGetNodeName()
 {
     $c = new Child('p', 'This is a paragraph');
     $c->setNodeName('span');
     $this->assertEquals('span', $c->getNodeName());
 }