public static function writeUrl(&$db, $loc, $lastMod = null, $changeFreq = null, $priority = null, $tableName = 'sitemap') { try { $loc = trim($loc); $checksum = crc32($loc); /* get the host name from url */ preg_match('@^(?:https?:\\/\\/)?((?:www\\.)?[^\\/]+)@i', $loc, $matches); $host = $matches[1]; $row = $db->select_1('select * from sitemap where loc = %s', $loc); /* new location */ if (is_null($row)) { $db->insert('sitemap', 'checksum = \'%l\'::bigint', $checksum, 'host = %s', $host, 'loc = %s', $loc, 'last_mod = %T', $lastMod, 'change_freq = %S', $changeFreq, 'priority = %l', is_null($priority) ? 'NULL' : $priority); /* update as details have changed */ } elseif ($row->t_last_mod != $lastMod || $row->s_change_freq != $changeFreq || $row->s_priority != $priority) { $db->update_1('sitemap', 'loc = %s', $loc, 'last_mod = %T', $lastMod, 'change_freq = %S', $changeFreq, 'priority = %l', is_null($priority) ? 'NULL' : $priority); } /* nulling used variables (big sitemaps need every scrap of memory!) */ $row = null; $host = null; $checksum = null; $matches = null; } catch (Exception $e) { Atsumi::error__listen($e); } }
public static function processTemplateString($templateString, $data, $supressErrors = false) { if (empty($templateString) || $templateString == '' || !$templateString) { return; } extract($data, EXTR_SKIP); ob_start(); try { eval("?>" . $templateString . '<?php '); } catch (Exception $e) { Atsumi::error__listen($e); if (!$supressErrors) { throw $e; } else { Atsumi::error__recover($e); } } return ob_get_clean(); }
static function interpolate($str, $vars) { $originalStr = $str; while (preg_match('/\\$\\{(.*?)\\}/sm', $str, $m)) { list($src, $var) = $m; // retrieve variable to interpolate in context, throw an exception // if not found. if (!array_key_exists($var, $vars)) { // TODO: Add a custom exception Atsumi::error__listen(new Exception(sf('Locale interpolation failed in for var: "%s" in str: "%s"', $var, $originalStr))); $value = ''; } else { $value = $vars[$var]; } $str = str_replace($src, $value, $str); } foreach ($vars as $key => $replacement) { $str = str_replace('${' . $key . '}', $replacement, $str); } return $str; }
public function render($options = array()) { // If elementOnly is specified, only the form element itself is returned if (isset($options['elementOnly']) && $options['elementOnly']) { $out = $this->renderElement(); } else { $out = $this->preRender(); $out .= sfl('<div class="row%s%s%s row_%s"%s>', $this->style ? " " . $this->style : "", $this->cssClass ? " " . $this->cssClass : "", $this->submitted && !$this->validates ? " error" : "", $this->name, $this->cssStyle ? " style='" . $this->cssStyle . "'" : ""); try { $out .= sf('%s%s<div class="element">%s</div>', $this->renderErrors(), ($this->label != '' || $this->getRequired()) && (!array_key_exists('label', $options) || $options['label'] !== false) ? $this->renderLabel() : '', $this->renderElement()); } catch (Exception $e) { // if in debug mode display exception details if (atsumi_Debug::getActive()) { $out .= sfl('Element Exception "%s": %s #%s', $e->getMessage(), $e->getFile(), $e->getLine()); } // fire error listeners Atsumi::error__listen($e); } $out .= '</div>'; $out .= $this->postRender(); } return $out; }
public function add($elementClass, $args) { if (!class_exists($elementClass)) { throw new Exception(sf("Form Element does not exist : %s", $elementClass)); } // if the user has submitted data validate the element if (empty($this->userInput) && empty($this->userFiles)) { $args['submitted'] = false; } else { $args['submitted'] = true; } //TODO: All of these special handles need to moved to the elements.... if ($elementClass == 'widget_FileElement') { $this->encoding = 'multipart/form-data'; } $element = new $elementClass($args); $element->setSubmitted($this->getSubmitted()); // validators to use on element if (array_key_exists('validators', $args)) { $element->setValidators($args['validators']); } // name $element->setName($args['name']); // default value if (array_key_exists('default', $args)) { $element->setDefault($args['default']); } // elements label if (array_key_exists('label', $args)) { $element->setLabel($args['label']); } // css style if (array_key_exists('style', $args)) { $element->setStyle($args['style']); } // css style if (array_key_exists('cssStyle', $args)) { $element->setCssStyle($args['cssStyle']); } // tabindexes if (array_key_exists('tabindex', $args)) { $element->setTabindex($args['tabindex']); } // css style if (array_key_exists('cssClass', $args)) { $element->setCssClass($args['cssClass']); } if (array_key_exists('force_default', $args)) { $element->setForceDefault($args['force_default']); } // If form not yet submitted element is prefilled with the value entered in spec.. if (!$this->submitted && array_key_exists('name', $args) && array_key_exists('value', $args)) { $this->userInput[$args['name']] = $args['value']; } try { $element->setValue($this->userInput, $this->userFiles); } catch (Exception $e) { Atsumi::error__listen($e); $element->setError($e); } $element->validate(); // save the new element to the form... $this->elements[] = $element; $this->elementMap[$element->getName()] =& $element; }