public function __construct($flags = 0, $goodtags = null, $emptytags = null) { if ($goodtags === null) { $goodtags = ["a", "abbr", "acronym", "address", "area", "b", "bdi", "bdo", "big", "blockquote", "br", "button", "caption", "center", "cite", "code", "col", "colgroup", "dd", "del", "details", "dir", "div", "dfn", "dl", "dt", "em", "figcaption", "figure", "font", "h1", "h2", "h3", "h4", "h5", "h6", "hr", "i", "img", "ins", "kbd", "label", "legend", "li", "link", "map", "mark", "menu", "menuitem", "meter", "noscript", "ol", "optgroup", "option", "p", "pre", "q", "rp", "rt", "ruby", "s", "samp", "section", "select", "small", "span", "strike", "strong", "sub", "summary", "sup", "table", "tbody", "td", "textarea", "tfoot", "th", "thead", "time", "title", "tr", "tt", "u", "ul", "var", "wbr"]; } if ($emptytags === null) { $emptytags = ["area", "base", "br", "col", "hr", "img", "input", "link", "meta", "param", "wbr"]; } $this->flags = 0; $this->goodtags = is_associative_array($goodtags) ? $goodtags : array_flip($goodtags); $this->emptytags = is_associative_array($emptytags) ? $emptytags : array_flip($emptytags); }
function get_arr_result($child_node) { $result = array(); if (isset($child_node)) { if (is_associative_array($child_node)) { $result[] = $child_node; } else { foreach ($child_node as $curr_node) { $result[] = $curr_node; } } } return $result; }
function array_to_object_recursive($a) { if (is_associative_array($a)) { $o = (object) array(); foreach ($a as $k => $v) { if ($k !== "") { $o->{$k} = array_to_object_recursive($v); } } return $o; } else { return $a; } }
/** * Extracts relation overrides from build options * * @param array $overrides * @return array */ protected function extractRelationOverrides($overrides) { return array_filter($overrides, function ($value) { return is_associative_array($value); }); }
function parse_options($args, $options) { if (!is_associative_array($args)) { $args = $this->associative_args($args, $options); if ($this->error != "") { return; } } foreach ($args as $key => $val) { if (!isset($options[$key])) { continue; } // for action ($vars) $type = $options[$key][0]; switch ($type) { case 'bool': if ($val == "" || $val == "on" || $val == "true") { $options[$key][1] = true; } elseif ($val == "off" || $val == "false") { $options[$key][1] = false; } else { $this->error = htmlspecialchars("{$key}={$val}") . " is invalid. "; $this->error .= "The option, {$key}, accepts only a boolean value."; $this->error .= "#{$this->plugin}({$key}) or #{$this->plugin}({$key}=on) or #{$this->plugin}({$key}=true) for true. "; $this->error .= "#{$this->plugin}({$key}=off) or #{$this->plugin}({$key}=false) for false. "; return; } break; case 'string': $options[$key][1] = $val; break; case 'sanitize': $options[$key][1] = htmlspecialchars($val); break; case 'number': // Do not parse yet, parse after getting min and max. Here, just format checking if ($val === '') { $options[$key][1] = ''; break; } if ($val[0] === '(' && $val[strlen($val) - 1] == ')') { $val = substr($val, 1, strlen($val) - 2); } foreach (explode(",", $val) as $range) { if (preg_match('/^-?\\d+$/', $range)) { } elseif (preg_match('/^-?\\d*\\:-?\\d*$/', $range)) { } elseif (preg_match('/^-?\\d+\\+-?\\d+$/', $range)) { } else { $this->error = htmlspecialchars("{$key}={$val}") . " is invalid. "; $this->error .= "The option, " . $key . ", accepts number values such as 1, 1:3, 1+3, 1,2,4. "; $this->error .= "Specify options as \"{$key}=1,2,4\" or {$key}=(1,2,3) when you want to use \",\". "; $this->error .= "In more details, a style like (1:3,5:7,9:) is also possible. 9: means from 9 to the last. "; $this->error .= "Furtermore, - means backward. -1:-3 means 1,2,3 from the tail. "; return; } } $options[$key][1] = $val; break; case 'enum': if ($val == "") { $options[$key][1] = $options[$key][2][0]; } elseif (in_array($val, $options[$key][2])) { $options[$key][1] = $val; } else { $this->error = htmlspecialchars("{$key}={$val}") . " is invalid. "; $this->error .= "The option, " . $key . ", accepts values from one of (" . join(",", $options[$key][2]) . "). "; $this->error .= "By the way, #{$this->plugin}({$key}) equals to #{$this->plugin}({$key}=" . $options[$key][2][0] . "). "; return; } break; case 'array': if ($val == '') { $options[$key][1] = array(); break; } if ($val[0] === '(' && $val[strlen($val) - 1] == ')') { $val = substr($val, 1, strlen($val) - 2); } $val = explode(',', $val); //$val = $this->support_paren($val); $options[$key][1] = $val; break; case 'enumarray': if ($val == '') { $options[$key][1] = $options[$key][2]; break; } if ($val[0] === '(' && $val[strlen($val) - 1] == ')') { $val = substr($val, 1, strlen($val) - 2); } $val = explode(',', $val); //$val = $this->support_paren($val); $options[$key][1] = $val; foreach ($options[$key][1] as $each) { if (!in_array($each, $options[$key][2])) { $this->error = "{$key}=" . htmlspecialchars(join(",", $options[$key][1])) . " is invalid. "; $this->error .= "The option, " . $key . ", accepts sets of values from (" . join(",", $options[$key][2]) . "). "; $this->error .= "By the way, #{$this->plugin}({$key}) equals to #{$this->plugin}({$key}=(" . join(',', $options[$key][2]) . ")). "; return; } } break; default: } } return $options; }
/** * Edit a customer * * Method will edit a customer's details * * @access public * @param array $input The customer's details * @param int $customerId The optional customer ID. Default will be $input[$this->primaryKeyName] * @param bool $isFullAddressBook TRUE to delete any addresses first before adding them in. Default is FALSE * @param bool $filterUniqueAddress TRUE to only insert unique addresses, FALSE not to check. Default is FALSE * @return bool TRUE if the customer exists and the details were updated successfully, FALSE oterwise */ public function edit($input, $customerId='', $isFullAddressBook=false, $filterUniqueAddress=false) { if (!parent::edit($input, $customerId)) { return false; } if (!isId($customerId)) { $customerId = $input[$this->primaryKeyName]; } if (array_key_exists("addresses", $input) && is_array($input["addresses"]) && !empty($input["addresses"])) { /** * Do we need to clear out our address book first? */ if ($isFullAddressBook) { $this->shipping->deleteByCustomer($customerId); } /** * Sanatise the addresses, just in case */ if (is_associative_array($input["addresses"])) { $input["addresses"] = array($input["addresses"]); } foreach ($input["addresses"] as $address) { $address['shipcustomerid'] = $customerId; if (!$isFullAddressBook && array_key_exists("shipid", $address) && isId($address["shipid"])) { $this->shipping->edit($address); } else if (!$filterUniqueAddress || !$this->shipping->basicSearch($address)) { $this->shipping->add($address); } } } if (isset($input['custpassword']) && !empty($input['custpassword'])) { // change password from edit screen $this->updatePassword($customerId, $input['custpassword']); } return true; }
function save_book_structure($response, $book) { $units = isset($response['libros']['libro']['unidades']['unidad']) ? $response['libros']['libro']['unidades']['unidad'] : false; // Guarda los datos del libro $book->structureforaccess = count($units) > 0 ? 1 : 0; $bookid = rcommon_book::add_update($book); if (!$bookid) { return; } if ($units) { $docleaning = true; // If we have no errors, we will clean old units and activities $timemodified = time(); // Time to do the cleaning // If is not associtive, it will have only one unit if (is_associative_array($units)) { $units = array($units); } foreach ($units as $unit) { $actividades = isset($unit['actividades']['actividad']) ? $unit['actividades']['actividad'] : false; // Unit with no code detected! if (!isset($unit['id']) || empty($unit['id'])) { $docleaning = false; continue; } $unitinstance = new stdClass(); $unitinstance->bookid = $bookid; $unitinstance->code = $unit['id']; $unitinstance->name = isset($unit['titulo']) ? $unit['titulo'] : ""; $unitinstance->summary = $unitinstance->name; $unitinstance->sortorder = isset($unit['orden']) ? $unit['orden'] : ""; // echo "<li>Unit: {$unitinstance->name}"; $unitid = rcommon_unit::add_update($unitinstance); if (!$unitid) { // Cannot Add/Update Unit $docleaning = false; continue; } if ($actividades) { // If is not associtive, it will have only one activity if (is_associative_array($actividades)) { $actividades = array($actividades); } foreach ($actividades as $act) { // Activity with no code detected! if (!isset($act['id']) || empty($act['id'])) { $docleaning = false; continue; } $activityinstance = new stdClass(); $activityinstance->bookid = $bookid; $activityinstance->unitid = $unitid; $activityinstance->code = $act['id']; $activityinstance->name = isset($act['titulo']) ? $act['titulo'] : ""; $activityinstance->summary = $activityinstance->name; $activityinstance->sortorder = isset($act['orden']) ? $act['orden'] : ""; $activid = rcommon_activity::add_update($activityinstance); if (!$activid) { // Cannot Add/Update Activity $docleaning = false; } } } } if ($docleaning) { rcommon_book::clean($bookid, $timemodified); } } }
function processResult($result) { $ret = new xmlrpcval(); if (is_object($result)) { $result = get_object_vars($result); } if (is_associative_array($result)) { $ar = array(); $keys = array_keys($result); foreach ($keys as $k) { $tmp = new xmlrpcval(array($k => new xmlrpcval($result[$k])), 'struct'); $ar[] = $tmp; } $ret->addArray($ar); } else { if (is_array($result)) { foreach ($result as $key => $value) { if (!is_string($value)) { $tmp = processResult($value); } else { $tmp = new xmlrpcval(); $tmp->addScalar($value); } $result[$key] = $tmp; } $ret->addArray($result); } else { if (is_bool($result)) { $ret->addScalar($result, "boolean"); } else { $ret->addScalar($result); } } } return $ret; }
function set_header($header, $comment = false) { assert(!count($this->lines) && $this->headerline === ""); $this->add($header); if ($this->type == self::TYPE_TAB && $comment) { $this->lines[0] = "#" . $this->lines[0]; } if ($this->selection === null && is_associative_array($header)) { $this->selection = array_keys($header); } $this->headerline = $this->lines[0]; $this->lines = []; }
public function setRelation(&$model, $relation) { $value = $relation->getValue(); if ($relation->isToManyRelation() && is_array($value) && !is_associative_array($value)) { $value = new \Illuminate\Support\Collection($value); } $model->setRelation($relation->getName(), $value); }
function set_selection($selection) { if (is_associative_array($selection)) { $this->selection = array_keys($selection); } else { $this->selection = $selection; } }
function json_update($j, $updates) { if ($j && is_object($j)) { $j = (array) $j; } else { if (!is_array($j)) { $j = []; } } foreach ($updates as $k => $v) { if ((string) $k === "") { global $Me; error_log(json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)) . ", user {$Me->email}"); continue; } if ($v === null) { unset($j[$k]); } else { if (is_object($v) || is_associative_array($v)) { $v = json_update(isset($j[$k]) ? $j[$k] : null, $v); if ($v !== null) { $j[$k] = $v; } else { unset($j[$k]); } } else { $j[$k] = $v; } } } $n = count($j); if ($n == 0) { return null; } for ($i = 0; $i != $n; ++$i) { if (!array_key_exists($i, $j)) { return (object) $j; } } ksort($j, SORT_NUMERIC); return array_values($j); }
static function pre_text_wrap($text) { if (is_array($text) && !is_associative_array($text) && array_reduce($text, function ($x, $s) { return $x && is_string($s); }, true)) { $text = join("\n", $text); } else { if (is_array($text) || is_object($text)) { $text = var_export($text, true); } } return "<pre style=\"white-space:pre-wrap\">" . htmlspecialchars($text) . "</pre>"; }
/** * Build the WHERE clause * * Method will build the WHERE clause from either an ID, an array of IDs or an associative array * * @access protected * @param mixed $nodeId The database record ID OR numeric array of IDs if multiple primary keys OR an associative * array of fields to match up againt (fields must be in the record schema) * @return string The WHERE clause on success, FALSE on error */ protected function buildPrimaryKeyClause($nodeId) { if (isId($nodeId) && !is_array($this->primaryKeyName)) { return $this->primaryKeyName . " = " . (int)$nodeId; } else if (is_array($nodeId) && !empty($nodeId)) { $whereClause = array(); /** * This will check for the multiple primary keys. This will not order them so make sure you put it in the * same order as the $this->primaryKeyName array */ if (!is_associative_array($nodeId) && is_array($this->primaryKeyName)) { $keys = array_values($this->primaryKeyName); $idx = array_values($nodeId); foreach (array_keys($idx) as $k) { if (!isId($idx[$k])) { return false; } $whereClause[] = $keys[$k] . " = " . (int)$idx[$k]; } /** * Else this will build the where clause from an associative array. The column MUST be in the $this->schema * array so no funny business */ } else if (is_associative_array($nodeId)) { foreach ($nodeId as $column => $value) { if (trim($column) == "" || trim($value) == "" || !array_key_exists($column, $this->schema)) { return false; } $whereClause[] = $column . " = '" . $GLOBALS["ISC_CLASS_DB"]->Quote($value) . "'"; } } $whereClause = implode(" AND ", $whereClause); return $whereClause; } return false; }
public function is_associative_array() { $this->is_array(); $condition = $this->match_true === is_associative_array($this->value); $this->assert($condition, $this->name . ' must' . $this->get_negation() . ' be an associative array'); return $this; }
public static function in_list($tag, $taglist) { if (is_string($taglist)) { $taglist = explode(" ", $taglist); } list($base, $index) = self::split_index($tag); if (is_associative_array($taglist)) { return isset($taglist[$base]); } else { return in_array($base, $taglist); } }