Пример #1
0
 /**
  * Test array_unset_key
  */
 function test_array_unset_key()
 {
     $data = array('first' => 'one', 'second' => 'two', 'third' => 'three');
     array_unset_key($data, 'first');
     $this->assertFalse(array_has_key($data, "first"));
     $this->assertTrue(array_has_key($data, "third"));
     array_unset_key($data, 'third');
     $this->assertFalse(array_has_key($data, "third"));
     array_unset_key($data, 'notpresent');
     $this->assertFalse(array_has_key($data, "notpresent"));
 }
Пример #2
0
 /**
  * \private
  *
  * Build a block level HTML element with the specified properties.
  *
  * \param $tag_name
  *   The name of the XHTML tag that should be created. Only a few
  *   block-level tags can be handled.
  *
  * \param $parsed_block
  *   A parsed block
  *
  * \return
  *   XHTML snippet as a string
  */
 function _build_html_block_element($tag_name, $parsed_block)
 {
     assert('is_string($tag_name); // tag name must be a string');
     assert('in_array($tag_name, explode(",", "p,h1,h2,h3,h4,h5,h6,div")); // invalid tag name');
     $attr = array();
     /* Class, id and language attributes can be copied. */
     foreach (array('class', 'id', 'lang') as $key) {
         if (!is_null($parsed_block[$key])) {
             $attr[$key] = $parsed_block[$key];
         }
     }
     /* The style attribute is a bit trickier, since the alignment and padding
      * specificiers must be incorporated as well. */
     $attr['style'] = '';
     if (!is_null($parsed_block['style'])) {
         $attr['style'] = $parsed_block['style'];
         /* Make sure the style declaration ends with a semicolon, so that we
          * can safely append other CSS snippets. */
         if (!str_has_suffix($attr['style'], ';')) {
             $attr['style'] .= ';';
         }
     }
     /* Alignment */
     if (!is_null($parsed_block['align'])) {
         $spec_to_value_mapping = array('<' => 'left', '>' => 'right', '=' => 'center', '<>' => 'justify');
         $attr['style'] .= sprintf(' text-align: %s;', $spec_to_value_mapping[$parsed_block['align']]);
     }
     /* Padding */
     if ($parsed_block['padding-left'] > 0) {
         $attr['style'] .= sprintf(' padding-left: %dem;', $parsed_block['padding-left']);
     }
     if ($parsed_block['padding-right'] > 0) {
         $attr['style'] .= sprintf(' padding-right: %dem;', $parsed_block['padding-right']);
     }
     /* Only include style attribute if needed */
     if (strlen($attr['style']) == 0) {
         array_unset_key($attr, 'style');
     }
     /* Generate the result */
     switch ($tag_name) {
         case 'p':
             $el = new AnewtXHTMLParagraph(null);
             break;
         case 'div':
             $el = new AnewtXHTMLDiv(null);
             break;
         case 'h1':
             $el = new AnewtXHTMLHeader1(null);
             break;
         case 'h2':
             $el = new AnewtXHTMLHeader2(null);
             break;
         case 'h3':
             $el = new AnewtXHTMLHeader3(null);
             break;
         case 'h4':
             $el = new AnewtXHTMLHeader4(null);
             break;
         case 'h5':
             $el = new AnewtXHTMLHeader5(null);
             break;
         case 'h6':
             $el = new AnewtXHTMLHeader6(null);
             break;
         default:
             assert('false; // unknown block tag name');
             break;
     }
     $el->append_child(ax_raw($parsed_block['markup']));
     $el->set_attributes($attr);
     return $el;
 }
Пример #3
0
 /**
  * Delete a variable from the configuration data.
  *
  * \param $name
  *   The name of the variable to delete.
  */
 public static function delete($name)
 {
     assert('is_string($name)');
     global $_anewt_config;
     array_unset_key($_anewt_config, $name);
 }
Пример #4
0
/* test array_has_key and array_has_value */
$data = array('first' => 'one', 'second' => 'two', 'third' => 'three');
assert('true === array_has_key($data, "first")');
assert('false === array_has_key($data, "foo")');
assert('false === array_has_key($data, "one")');
assert('true === array_has_value($data, "three")');
assert('false === array_has_value($data, "foo")');
assert('false === array_has_value($data, "first")');
/* test array_unset_key */
$data = array('first' => 'one', 'second' => 'two', 'third' => 'three');
array_unset_key($data, 'first');
assert('false === array_has_key($data, "first")');
assert('true === array_has_key($data, "third")');
array_unset_key($data, 'third');
assert('false === array_has_key($data, "third")');
array_unset_key($data, 'notpresent');
assert('false === array_has_key($data, "notpresent")');
/* test array_unset_keys */
$data = array('first' => 'one', 'second' => 'two', 'third' => 'three');
$keys_to_remove = array('first', 'second', 'notpresent');
array_unset_keys($data, $keys_to_remove);
assert('false === array_has_key($data, "first")');
assert('false === array_has_key($data, "second")');
assert('true === array_has_key($data, "third")');
assert('false === array_has_key($data, "notpresent")');
/* test array_clear */
$data = array('first' => 'one', 'second' => 'two', 'third' => 'three');
array_clear($data);
assert('count($data) == 0');
/* test array_flip_string_keys */
$data = array('first' => 'one', 'second' => 'two', 'third' => 'three', 4 => 'four', 5 => 'five', 'six' => 6);
Пример #5
0
 /**
  * 获取id levaeName对
  *
  * 可适用于列表以及下拉列表
  *
  * @return array
  */
 public function getValueOptions($tree = NULL)
 {
     $tree = $tree ? $tree : $this->tree;
     $returnList = array();
     foreach ($tree as $item) {
         $tmp = array();
         $item[$this->fields[2]] = $this->getLevelName($item[$this->fields[0]]);
         $tmp[$item[$this->fields[0]]] = array_unset_key($item, 'child');
         $returnList = my_array_merge($returnList, $tmp);
         if (isset($item['child']) && $item['child']) {
             $childList = $this->getValueOptions($item['child']);
             $returnList = my_array_merge($returnList, $childList);
         }
     }
     return $returnList;
 }