Example #1
0
 /**
  * Just makes attributes more flexible. If it's just a string, build an
  * attribute array of ['class' => $attributes]
  * if it's an indexed array, assume array of classes, implode, and do the same
  * NOTE: Overridden in subclasses to customize attributes (like SubForm)
  * @param array|string $attributes
  */
 public function cleanAttributes($attributes)
 {
     if (is_array_indexed($attributes)) {
         $attributes = implode(' ', $attributes);
     }
     if (is_string($attributes)) {
         $attributes = ['class' => $attributes];
     }
     return $attributes;
 }
Example #2
0
 /** Returns an array with its 'class' key set to an array or string, combining
  * values from $arg1 & $arg2 
  */
 public function mergeClass($arg1, $arg2 = null)
 {
     if (is_string($arg1)) {
         $arg1 = ['class' => $arg1];
     }
     if (is_array($arg1)) {
         if (empty($arg1['class'])) {
             if (is_string($arg2) || is_array_indexed($arg2)) {
                 $arg1['class'] = $arg2;
                 return $arg1;
             }
         }
         if (is_array($arg1['class'])) {
             if (is_string($arg2)) {
                 $arg1['class'][] = $arg2;
             } else {
                 if (is_array($arg2)) {
                     $arg1['class'] = array_merge($arg1['class'], $arg2);
                 }
             }
             return $arg1;
         }
         if (is_string($arg1['class'])) {
             if (is_array($arg2)) {
                 $arg2[] = $arg1['class'];
                 $arg1['class'] = $arg2;
             } else {
                 if (is_string($arg2)) {
                     $arg1['class'] .= " {$arg2} ";
                 }
             }
         }
     }
     return $arg1;
 }
Example #3
0
function is_arrayish_indexed($val) {
  $arrCopy = getAsArray($val);
  if (!$arrCopy || !is_array($arrCopy) || !count($arrCopy)) return false;
  if (is_array($arrCopy)) return is_array_indexed($arrCopy);
  return false;
}
Example #4
0
 /**
  * Set user's groups
  *
  * @param int[]		$groups
  * @param bool|int	$user
  *
  * @return bool
  */
 function set_groups($groups, $user = false)
 {
     $user = (int) ($user ?: $this->id);
     if (!$user) {
         return false;
     }
     if (!empty($groups) && is_array_indexed($groups)) {
         foreach ($groups as $i => &$group) {
             if (!($group = (int) $group)) {
                 unset($groups[$i]);
             }
         }
     }
     unset($i, $group);
     $existing = $this->get_groups($user);
     $return = true;
     $insert = array_diff($groups, $existing);
     $delete = array_diff($existing, $groups);
     unset($existing);
     if (!empty($delete)) {
         $delete = implode(', ', $delete);
         $return = $return && $this->db_prime()->q("DELETE FROM `[prefix]users_groups`\n\t\t\t\tWHERE\n\t\t\t\t\t`id`\t='{$user}' AND\n\t\t\t\t\t`group`\tIN ({$delete})");
     }
     unset($delete);
     if (!empty($insert)) {
         foreach ($insert as &$i) {
             $i = [$user, $i];
         }
         unset($i);
         $return = $return && $this->db_prime()->insert("INSERT INTO `[prefix]users_groups`\n\t\t\t\t\t(\n\t\t\t\t\t\t`id`,\n\t\t\t\t\t\t`group`\n\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t'%s',\n\t\t\t\t\t\t'%s'\n\t\t\t\t\t)", $insert);
     }
     unset($insert);
     $update = [];
     foreach ($groups as $i => $group) {
         $update[] = "UPDATE `[prefix]users_groups`\n\t\t\t\tSET `priority` = '{$i}'\n\t\t\t\tWHERE\n\t\t\t\t\t`id`\t= '{$user}' AND\n\t\t\t\t\t`group`\t= '{$group}'\n\t\t\t\tLIMIT 1";
     }
     $return = $return && $this->db_prime()->q($update);
     $Cache = $this->cache;
     unset($Cache->{"groups/{$user}"}, $Cache->{"permissions/{$user}"});
     return $return;
 }
Example #5
0
 /**
  * Processing of complicated rendering structures
  *
  * @static
  *
  * @param string			$input
  * @param array|bool|string	$data
  *
  * @return string
  */
 static function __callStatic($input, $data)
 {
     if ($data === false) {
         return false;
     }
     if (is_scalar($data)) {
         $data = [$data];
     } elseif (isset($data[1]) && $data[1] === false && !isset($data[2])) {
         unset($data[1]);
     }
     $input = trim($input);
     /**
      * Analysis of called tag. If nested tags presented
      */
     if (static::analyze_selector($input)) {
         /**
          * If tag name ends with pipe "|" symbol - for every element of array separate copy of current tag will be created
          */
         if (strpos($input[0], '|') !== false) {
             $input[0] = substr($input[0], 0, -1);
             $output = [];
             /**
              * When parameters are not taken in braces - make this operation, if it is necessary
              */
             if (count($data) > 2 || isset($data[1]) && is_array_indexed($data[1])) {
                 $data = [$data];
             }
             foreach ($data[0] as $d) {
                 if (isset($d[0]) && is_array_indexed($d[0]) && !in_array($d[0][0], static::$unit_atributes)) {
                     if (isset($d[1]) && (!is_array($d[1]) || is_array_indexed($d[1]) && !in_array($d[1][0], static::$unit_atributes))) {
                         $output_ = [];
                         foreach ($d as $d_) {
                             $output_[] = static::__callStatic($input[1], $d_);
                         }
                         $output[] = $output_;
                         unset($output_);
                     } else {
                         $output[] = [static::__callStatic($input[1], $d[0]), isset($d[1]) ? $d[1] : ''];
                     }
                 } else {
                     $output[] = static::__callStatic($input[1], $d);
                 }
             }
             unset($d);
         } elseif (!isset($data[1]) || is_array_assoc($data[1])) {
             $output = static::__callStatic($input[1], [isset($data[0]) ? $data[0] : '', isset($data[1]) ? $data[1] : false]);
             $data[1] = [];
         } else {
             $output = static::__callStatic($input[1], $data);
             $data[1] = [];
         }
         return static::__callStatic($input[0], [$output, isset($data[1]) ? $data[1] : false]);
     }
     if (substr($input, -1) == '|') {
         $input = substr($input, 0, -1);
         $data = [$data];
     }
     /**
      * Fix for textarea tag, which can accept array as content
      */
     if (strpos($input, 'textarea') === 0 && isset($data[0]) && is_array_indexed($data[0]) && !is_array($data[0][0])) {
         $data[0] = implode("\n", $data[0]);
     }
     /**
      * If associative array given then for every element of array separate copy of current tag will be created
      */
     if (is_array_indexed($data)) {
         if (count($data) > 2) {
             $output = '';
             foreach ($data as $d) {
                 $output .= static::__callStatic($input, $d);
             }
             return $output;
         } elseif (strpos($input, 'select') !== 0 && strpos($input, 'datalist') !== 0 && strpos($input, 'input') !== 0 && (is_array_indexed($data[0]) && (!isset($data[1]) || !is_array($data[1]) || is_array_indexed($data[1]) && !in_array($data[1][0], static::$unit_atributes)))) {
             $output = '';
             foreach ($data as $d) {
                 $output .= static::__callStatic($input, $d);
             }
             return $output;
         } elseif (is_array_indexed($data[0]) && (strpos($input, 'select') !== 0 && strpos($input, 'datalist') !== 0 || is_array_indexed($data[0][0]) && !in_array($data[0][0][0], static::$unit_atributes))) {
             $output = '';
             foreach ((array) $data[0] as $d) {
                 $data[1] = isset($data[1]) ? $data[1] : [];
                 if (!is_array($d) || !isset($d[1]) || !is_array($d[1])) {
                     $output .= static::__callStatic($input, [$d, $data[1]]);
                 } elseif (is_array_indexed($d[1]) && !in_array($d[1], static::$unit_atributes)) {
                     $output .= static::__callStatic($input, [$d[0], $data[1]]) . static::__callStatic($input, [$d[1], $data[1]]);
                 } else {
                     $output .= static::__callStatic($input, [$d[0], static::array_merge($data[1], $d[1])]);
                 }
             }
             return $output;
         } elseif (!is_array($data[0]) && !in_array($data[0], static::$unit_atributes) && isset($data[1]) && (!is_array($data[1]) || is_array_indexed($data[1]) && !in_array($data[1][0], static::$unit_atributes))) {
             $output = '';
             foreach ($data as $d) {
                 $output .= static::__callStatic($input, $d);
             }
             return $output;
         }
     } else {
         $data[0] = $data;
     }
     if (!isset($data[0])) {
         $data[0] = '';
     }
     /**
      * Second part of expression - fix for "select" and "datalist" tags because they accept array as values
      */
     if (!is_array($data[0]) || (strpos($input, 'select') === 0 || strpos($input, 'datalist') === 0) && !isset($data[0]['in'])) {
         $data[0] = ['in' => $data[0]];
     }
     if (isset($data[1])) {
         $data = static::array_merge($data[0], $data[1]);
     } else {
         $data = $data[0];
     }
     $attrs = [];
     /**
      * Attributes processing
      */
     if (($pos = mb_strpos($input, '[')) !== false) {
         $attrs_ = explode('][', mb_substr($input, $pos + 1, -1));
         $input = mb_substr($input, 0, $pos);
         foreach ($attrs_ as &$attr) {
             $attr = explode('=', $attr, 2);
             if (isset($attr[1])) {
                 $attrs[$attr[0]] = $attr[1];
             } else {
                 $attrs[] = $attr[0];
             }
         }
         unset($attrs_, $attr);
     }
     /**
      * Classes processing
      */
     if (($pos = mb_strpos($input, '.')) !== false) {
         if (!isset($attrs['class'])) {
             $attrs['class'] = '';
         }
         $attrs['class'] = trim($attrs['class'] . ' ' . str_replace('.', ' ', mb_substr($input, $pos)));
         $input = mb_substr($input, 0, $pos);
     }
     unset($pos);
     /**
      * Id and tag determination
      */
     $input = explode('#', $input);
     $tag = $input[0];
     if (isset($input[1])) {
         $attrs['id'] = $input[1];
     }
     $attrs = static::array_merge($attrs, $data);
     unset($data);
     if ($tag == 'select' || $tag == 'datalist') {
         if (isset($attrs['value'])) {
             $in = ['in' => $attrs['in'], 'value' => $attrs['value']];
             unset($attrs['in'], $attrs['value']);
         } else {
             $in = ['in' => $attrs['in']];
             unset($attrs['in']);
         }
     } elseif (isset($attrs['in'])) {
         $in = $attrs['in'];
         unset($attrs['in']);
     } else {
         $in = '';
     }
     if (isset($attrs['insert'])) {
         $insert = $attrs['insert'];
         unset($attrs['insert']);
         $data = [$in, $attrs];
         static::inserts_processing($data, $insert);
         $html = '';
         foreach ($data as $d) {
             if (method_exists(get_called_class(), $tag)) {
                 $html .= static::$tag($d[0], $d[1]);
             } elseif (in_array($tag, static::$unpaired_tags)) {
                 $d[1]['tag'] = $tag;
                 $d[1]['in'] = $d[0];
                 $html .= static::u_wrap($d[1]);
             } else {
                 $html .= static::wrap($d[0], $d[1], $tag);
             }
         }
         return $html;
     }
     if (method_exists(get_called_class(), $tag)) {
         $in = static::$tag($in, $attrs);
     } elseif (in_array($tag, static::$unpaired_tags)) {
         $attrs['tag'] = $tag;
         $attrs['in'] = $in;
         $in = static::u_wrap($attrs);
     } else {
         $in = static::wrap($in, $attrs, $tag);
     }
     return $in;
 }