Ejemplo n.º 1
0
 private function optGrp(&$cells, $selected, $grp, $title)
 {
     $cells[] = "\n\t<optgroup label=\"{$title}\">";
     foreach ($grp as $v => $l) {
         $v = SPLang::entities($v, true);
         if (is_array($l)) {
             self::optGrp($cells, $selected, $l, $v);
         } else {
             $sel = in_array((string) $v, $selected, true) ? ' selected="selected" ' : null;
             $l = SPLang::entities(self::translate($l), true);
             $cells[] = "\t<option {$sel}value=\"{$v}\">{$l}</option>";
         }
     }
     $cells[] = "</optgroup>\n\t";
 }
Ejemplo n.º 2
0
 /**
  * Add a keywords to the site header
  * @param $keys
  * @internal param string $key
  * @return SPHeader
  */
 public function &addKeyword($keys)
 {
     if (is_string($keys)) {
         $checksum = md5($keys);
         if (!isset($this->_checksums[__FUNCTION__][$checksum])) {
             $this->_checksums[__FUNCTION__][$checksum] = true;
             $this->store(get_defined_vars(), __FUNCTION__);
             if (strlen($keys)) {
                 $keys = explode(Sobi::Cfg('string.meta_keys_separator', ','), $keys);
                 if (!empty($keys)) {
                     $this->count++;
                     foreach ($keys as $key) {
                         $this->keywords[] = strip_tags(trim(SPLang::entities($key, true)));
                     }
                 }
             }
         }
     }
     return $this;
 }
Ejemplo n.º 3
0
 protected function edit()
 {
     SPLoader::loadClass('html.tooltip');
     $this->_type = 'entry_form';
     $id = $this->get('entry.id');
     if ($id) {
         $this->addHidden($id, 'entry.id');
     }
     if (Sobi::Cfg('legacy.sigsiutree', false)) {
         /* load the SigsiuTree class */
         $tree = SPLoader::loadClass('mlo.tree');
         /* create new instance */
         $tree = new $tree(Sobi::Cfg('list.categories_ordering'));
         $link = "javascript:SP_selectCat( '{sid}' )";
         $tree->setHref($link);
         $tree->setTask('category.chooser');
         $tree->disable(Sobi::Section());
         $tree->init(Sobi::Section());
         $head = SPFactory::header();
         $params = array();
         $params['URL'] = Sobi::Url(array('task' => 'category.parents', 'out' => 'json'), true, false, true);
         $params['MAXCATS'] = Sobi::Cfg('legacy.maxCats', '5');
         $params['SEPARATOR'] = Sobi::Cfg('string.path_separator', ' > ');
         $head->addJsVarFile('edit', md5(Sobi::Section() . Sobi::Section(true) . serialize($params)), $params);
     }
     $type = $this->key('template_type', 'xslt');
     if ($type != 'php' && Sobi::Cfg('global.disable_xslt', false)) {
         $type = 'php';
     }
     if ($type == 'xslt') {
         $data = $this->entryData(false);
         $fields = $this->get('fields');
         $f = array();
         if (count($fields)) {
             foreach ($fields as $field) {
                 if ($field->enabled('form')) {
                     $pf = null;
                     $pfm = null;
                     if (!$field->get('isFree') && $field->get('fee') && !Sobi::Can('entry.payment.free')) {
                         $pf = SPLang::currency($field->get('fee'));
                         $pfm = Sobi::Txt('EN.FIELD_NOT_FREE_MSG', array('fee' => $pf, 'fieldname' => $field->get('name')));
                     }
                     $f[$field->get('nid')] = array('_complex' => 1, '_data' => array('label' => array('_complex' => 1, '_data' => $field->get('name'), '_attributes' => array('lang' => Sobi::Lang(false), 'show' => $field->__get('showEditLabel'))), 'data' => array('_complex' => 1, '_xml' => 1, '_data' => $field->field(true)), 'description' => array('_complex' => 1, '_xml' => 1, '_data' => $field->get('description')), 'fee' => $pf, 'fee_msg' => $pfm), '_attributes' => array('id' => $field->get('id'), 'type' => $field->get('type'), 'suffix' => $field->get('suffix'), 'position' => $field->get('position'), 'required' => $field->get('required'), 'css_edit' => $field->get('cssClassEdit'), 'width' => $field->get('bsWidth'), 'css_class' => strlen($field->get('cssClass')) ? $field->get('cssClass') : 'spField'));
                 }
             }
         }
         $f['save_button'] = array('_complex' => 1, '_data' => array('data' => array('_complex' => 1, '_xml' => 1, '_data' => SPHtml_Input::submit('save', Sobi::Txt('EN.SAVE_ENTRY_BT')))));
         $f['cancel_button'] = array('_complex' => 1, '_data' => array('data' => array('_complex' => 1, '_xml' => 1, '_data' => SPHtml_Input::button('cancel', Sobi::Txt('EN.CANCEL_BT'), array('onclick' => 'SPcancelEdit();')))));
         if (Sobi::Cfg('legacy.sigsiutree', false)) {
             $data['entry']['_data']['category_chooser'] = array('path' => array('_complex' => 1, '_xml' => 1, '_data' => SPHtml_Input::textarea('parent_path', $this->get('parent_path'), false, 500, 60, array('id' => 'entry.path', 'class' => 'inputbox required', 'readonly' => 'readonly'))), 'selected' => array('_complex' => 1, '_xml' => 1, '_data' => SPHtml_Input::text('entry.parent', $this->get('parents'), array('id' => 'entry.parent', 'size' => 15, 'maxlength' => 50, 'class' => 'inputbox required', 'readonly' => 'readonly', 'style' => 'text-align:center;'))));
         }
         $data['entry']['_data']['fields'] = array('_complex' => 1, '_data' => $f, '_attributes' => array('lang' => Sobi::Lang(false)));
         if (Sobi::Cfg('legacy.sigsiutree', false)) {
             $data['tree'] = array('_complex' => 1, '_xml' => 1, '_data' => SPLang::entities($tree->display(true), true));
         }
         $this->_attr = $data;
         Sobi::Trigger($this->_type, ucfirst(__FUNCTION__), array(&$this->_attr));
     }
 }
Ejemplo n.º 4
0
 /**
  * @param $data
  * @param $parent
  * @param $name
  * @return unknown_type
  */
 private function createNode($data, &$parent, $name = null)
 {
     if ($name) {
         $e = $this->_xml->createElement($this->elName($name));
     } else {
         $e = $parent;
     }
     /* not complex data - without attributes aso */
     if (is_array($data) && !isset($data['_complex'])) {
         foreach ($data as $label => $values) {
             /* half-complex data - just to define custom child tag */
             if (is_array($values) && isset($values['_value'])) {
                 if (isset($values['_class']) || isset($values['_id'])) {
                     $label = isset($values['_tag']) ? $values['_tag'] : $label;
                     $attr = array();
                     if (isset($values['_class'])) {
                         $attr['class'] = $values['_class'];
                     }
                     if (isset($values['_id'])) {
                         $attr['id'] = $values['_id'];
                     }
                     $values = array('_complex' => 1, '_data' => $values['_value'], '_attributes' => $attr);
                 } else {
                     $label = isset($values['_tag']) ? $values['_tag'] : $label;
                     $values = $values['_value'];
                 }
             }
             if (!$label || is_integer($label)) {
                 $label = SPLang::singular($name);
             }
             $this->createNode($values, $e, $label);
         }
     } elseif (is_array($data) && isset($data['_complex'])) {
         if (isset($data['_xml']) && $data['_xml']) {
             $_t = new DOMDocument();
             $_t->formatOutput = true;
             /* html entities to compatible XML within textareas */
             $data['_data'] = preg_replace_callback('/(<textarea.*>)(.*)(<\\/textarea>)/s', 'SPTemplateXSLT::entities', $data['_data']);
             try {
                 /* im trying to catch this damn error already :( */
                 /* assuming the XML-Structure was ok */
                 if (@$_t->loadXML('<span>' . $data['_data'] . '</span>')) {
                     $nodes = $_t->firstChild->childNodes;
                 } elseif (class_exists('tidy') && @$_t->loadXML('<span>' . $this->repairHtml($data['_data']) . '</span>')) {
                     $nodes = $_t->firstChild->childNodes;
                 } else {
                     /* pass as escaped html text to the template */
                     $data['_attributes']['escaped'] = 'true';
                     if (!@$_t->loadXML('<span>' . htmlentities($data['_data']) . '</span>')) {
                         /* in case even this failed - pass as CDATA section */
                         $e->appendChild($this->_xml->createCDATASection($data['_data']));
                         $nodes = null;
                     } else {
                         $nodes = $_t->firstChild->childNodes;
                     }
                 }
             } catch (DOMException $x) {
                 Sobi::Error('template', $x->getMessage(), SPC::WARNING, 0, __LINE__, __FILE__);
             }
             if (count($nodes)) {
                 foreach ($nodes as $node) {
                     if ($node instanceof DOMNode) {
                         $node = $this->_xml->importNode($node, true);
                         $e->appendChild($node);
                     } else {
                         Sobi::Error('template', 'Cannot parse data', SPC::WARNING, 0, __LINE__, __FILE__);
                     }
                 }
             }
         } elseif (isset($data['_cdata']) && $data['_cdata']) {
             $e->appendChild($this->_xml->createCDATASection($data['_data']));
         } elseif (isset($data['_data']) && is_array($data['_data'])) {
             $this->createNode($data['_data'], $e);
         } elseif (isset($data['_data'])) {
             //$data[ '_attributes' ][ 'escaped' ] = 'true';
             $e->appendChild($this->_xml->createTextNode($data['_data']));
         }
         if (isset($data['_attributes']) && is_array($data['_attributes']) && count($data['_attributes'])) {
             foreach ($data['_attributes'] as $an => $av) {
                 $an = SPLang::varName($an);
                 // legacy for 1.0
                 // data- is allowed html5 attribute but data_ will not be valid
                 if (strstr($an, '-') && !strstr($an, 'data-')) {
                     $a = $this->_xml->createAttribute(str_replace('-', '_', $an));
                     $a->appendChild($this->_xml->createTextNode($av));
                     $e->appendChild($a);
                 }
                 $a = $this->_xml->createAttribute($an);
                 $a->appendChild($this->_xml->createTextNode($av));
                 $e->appendChild($a);
             }
         }
     } elseif ($name) {
         $e = $this->_xml->createElement($this->elName($name), SPLang::entities($data, true));
     }
     if ($name) {
         $parent->appendChild($e);
     }
 }