/** * Write a segment of the array to a file. * @param string $str * The output string * @param array $arr * The array to read off * @param int $tier * The tier number, default 0 */ private function writeSegment(&$str, $arr, $tier = 0) { $indent = str_repeat(chr(9), $tier); // TODO check for a certain key to keep it in the same tier instead of going into the next? // For ordered arrays, deconstruct them if (!isAssoc($arr)) { foreach ($arr as $idx => $item) { if (is_array($item)) { foreach ($item as $key => $value) { $str .= $indent . '"' . $key . '"' . chr(9) . '"' . $value . "\"\n"; } } else { $str .= $indent . '"' . $idx . '"' . chr(9) . '"' . $item . "\"\n"; } } } else { foreach ($arr as $key => $value) { if (is_array($value)) { $key = '"' . $key . '"'; $str .= $indent . $key . "\n" . $indent . "{\n"; $this->writeSegment($str, $value, $tier + 1); $str .= $indent . "}\n"; } else { $str .= $indent . '"' . $key . '"' . chr(9) . '"' . $value . "\"\n"; } } } return $str; }
protected function _insert(array $data = null) { if ($this instanceof Model) { $isAssoc = isAssoc($data); if ($isAssoc) { if ($data) { $this->fill($data); } if ($this->timestamps) { $this->attributes['created_at'] = date('Y-m-d H:i:s', START_TIME); } DB::insert($this->table, $this->attributes); $this->attributes[$this->primaryKey] = $this->db->lastInsertId(); $response =& $this; } else { $response = []; foreach ($data as $row) { DB::insert($this->table, $row); $row[$this->primaryKey] = $this->db->lastInsertId(); $response[] = new $this($row); } } return $response; } else { return DB::insert($this->table, $data); } }
function ParseIt($data, $name = '', $level = 0, $objects = 0) { global $ordered_fields; $out = array('type' => 'object'); // Figure out if we are dealing with named objects, or section names switch ($name) { case 'weapon_upgrade': $out['sort'] = "unique"; case 'ammo': case 'explosives': case 'player_gear': case 'player_templates': case 'teams': case 'squads': case 'weapons': case 'weapon_upgrades': $objects = 1; break; default: $objects = 0; break; } // If this is an ordered field, parse the sub-items if (!isAssoc($data)) { $out['sort'] = "unique"; foreach ($data as $key => $val) { if (is_array($val)) { foreach ($val as $skey => $sval) { $title = $objects ? "@name" : $skey; $out['items'][$title] = vartype($sval); } } else { $title = $objects ? "@name" : $key; $out['items'][$title] = vartype($val); } } } else { // Otherwise, parse the data natively foreach ($data as $key => $val) { $title = $objects ? "@name" : $key; if (is_array($val)) { $setval = ParseIt($val, $title, $level + 1, $objects); foreach ($setval as $skey => $sval) { // if ($skey == "items") { $out['items'][$title][$skey] = $sval; // } else { // $out['items'][$title][$skey] = vartype($sval); // } } } else { $out['items'][$title] = vartype($val); } } } return $out; }
function convert_obj($obj) { if (is_string($obj)) { return var_export($obj, true); } elseif (is_array($obj) || isAssoc($obj)) { return var_export($obj, true); } else { return $obj; } }
/** * @param array $rangeA * @param array $rangeB * @return bool * @throws InvalidRange */ protected function hasOverLap(array $rangeA, array $rangeB) { if (isAssoc($rangeA) || isAssoc($rangeB) || count($rangeA) != 2 || count($rangeB) != 2) { throw new InvalidRange(); } if ($rangeA[1] > $rangeB[0] && $rangeA[0] < $rangeB[0] || $rangeB[1] > $rangeA[0] && $rangeB[0] < $rangeA[0]) { return false; } else { return true; } }
public function update($table, $data, $conditions) { if (!isAssoc($data)) { return false; } $conditions = $this->conditionString($conditions); $query_string = $this->conditionString($data); $query_string = str_replace(" and ", ", ", $query_string); $query_string = str_replace(" where ", "", $query_string); $query_string = "update " . $table . " set " . $query_string . $conditions; $this->db->exec($query_string); return true; }
public static function insert($table, $data) { if (isAssoc($data)) { $values = '(' . self::implodeValues($data) . ')'; $keys = self::implodeKeys($data); } else { $values = ''; foreach ($data as $row) { $values .= '(' . self::implodeValues($row) . '), '; } $values = substr($values, 0, -2); $keys = self::implodeKeys(array_shift($data)); } $query = 'INSERT INTO ' . $table . ' (' . $keys . ') VALUES ' . $values; return self::query($query); }
function toXML($data, $rootNodeName = 'api', &$xml = null) { // turn off compatibility mode as simple xml throws a wobbly if you don't. if (ini_get('zend.ze1_compatibility_mode') == 1) { ini_set('zend.ze1_compatibility_mode', 0); } if (is_null($xml)) { //$xml = simplexml_load_string( "" ); $xml = simplexml_load_string(xml_default($rootNodeName)); } // loop through the data passed in. foreach ($data as $key => $value) { $key = xml_trim($key); $numeric = false; // no numeric keys in our xml please! if (is_numeric($key)) { $numeric = 1; $key = $rootNodeName; } // delete any char not allowed in XML element names $key = preg_replace('/[^a-z0-9\\-\\_\\.\\:]/i', '', $key); // if there is another array found recrusively call this function if (is_array($value)) { $node = isAssoc($value) || $numeric ? $xml->addChild($key) : $xml; // recrusive call. if ($numeric) { $key = 'anon'; } toXml($value, $key, $node); } else { // var_dump($value); // add single node. $value = htmlentities(xml_trim($value)); $xml->addChild($key, $value); } } // pass back as XML // return $xml->asXML(); // if you want the XML to be formatted, use the below instead to return the XML $doc = new DOMDocument('1.0'); $doc->preserveWhiteSpace = false; $doc->loadXML($xml->asXML()); $doc->formatOutput = true; return $doc->saveXML(); }
public function __tostring() { $returnStr = $this->_getType(); $returnStr .= "INTO `{$this->tableName}` "; if ($this->fields !== null and is_array($this->fields)) { $returnStr .= "(`" . implode("`,`", $this->fields) . "`) "; } if (isset($this->values[0][0]) and $this->values[0][0] instanceof QueryBuilder and $this->values[0][0]->getType() == QueryBuilder::SELECT) { $returnStr .= "({$this->values[0][0]})"; } else { if ($this->fields !== null and is_array($this->fields) or isset($this->values[0]) and !isAssoc($this->values[0])) { $returnStr .= "VALUES "; foreach ($this->values as $values) { $returnStr .= "(" . $this->_getValues($values) . "),"; } $returnStr = trim($returnStr, ","); } else { $returnStr .= "(`" . implode("`,`", array_keys($this->values[0])) . "`) "; $returnStr .= "VALUES (" . $this->_getValues(array_values($this->values[0])) . ")"; } } return $returnStr; }
function print_props($obj) { if (is_array($obj) || is_object($obj)) { if (is_object($obj) || isAssoc($obj)) { print "<ul>"; foreach ($obj as $key => $value) { print "<li>" . '<b>' . check_plain($key) . ':</b> '; print_props($value); print "</li>"; } print "</ul>"; } else { print "<ol>"; foreach ($obj as $value) { print "<li>"; print_props($value); print "</li>"; } print "</ol>"; } } else { print $obj; } }
public function post() { $originalProps = $this->props; if (isAssoc($this->props)) { $this->props["Fields"] = array("Field" => array()); if (!is_null($this->columns) && is_array($this->columns)) { foreach ($this->columns as $column) { array_push($this->props['Fields']['Field'], $column); } } } else { $newProps = array(); foreach ($this->props as $DE) { $newDE = $DE; $newDE["Fields"] = array("Field" => array()); if (!is_null($DE['columns']) && is_array($DE['columns'])) { foreach ($DE['columns'] as $column) { array_push($newDE['Fields']['Field'], $column); } } array_push($newProps, $newDE); } $this->props = $newProps; } $response = parent::post(); $this->props = $originalProps; return $response; }
/** * Sprawdza czy pole powinno być zaznaczone * @param string|array $value * @param string $oKey * @param string $oName ???? * @return $this */ public function checked($value = null, $oKey = null, $oName = null) { if (is_null($value)) { return $this->getChecked(); } //Checkboxy $this->value powinny mieć wyłącznie jako "string" if (is_array($this->value)) { $this->value = $this->value[0]; } $this->checked = false; if (is_array($value)) { if (isAssoc($value)) { //W przypadku tablicy asocjacyjnej ($key=>$val) jeśli $val jest typu bool to znaczy że $key == $this->value if (is_bool(array_values($value)[0])) { if (array_key_exists($this->value, $value)) { $this->checked = $value[$this->value]; return $this; } } else { //W przeciwnym przypdaku uznajemy że tablica przechowuje pary klucz => wartosc odpowiadające $this->name => $this->value if (array_key_exists($this->name, $value)) { $this->checked = $value[$this->name] == $this->value; return $this; } } } else { $this->checked = in_array($this->value, $value); return $this; } return $this; } //Jeżeli jest obiektem to obowiązkowo należy podać drugi parametr jakim jest nazwa pola if (is_object($value) && $oKey && $oName) { foreach ($value as $v) { if (property_exists($v, $oKey)) { $prop = $v->{$oKey}; if (is_bool($prop)) { $this->checked = $prop; } else { $this->checked = $prop == $this->value; } } } return $this; } if (is_object($value) && $oKey) { if (property_exists($value, $oKey)) { $prop = $value->{$oKey}; if (is_bool($prop)) { $this->checked = $prop; } else { $this->checked = $prop == $this->value; } } } if (is_bool($value)) { $this->checked = $value; return $this; } $this->checked = $this->value == $value; return $this; }
function vntd_create_dropdown($name, $elements, $current_value, $folds = NULL) { $folds_class = $selected = ''; if ($folds) { $folds_class = ' folds'; } echo '<select name="' . $name . '" class="select' . $folds_class . '">'; if (isAssoc($elements)) { foreach ($elements as $title => $key) { if ($key == $current_value) { $selected = 'selected'; } echo '<option value="' . $key . '"' . $selected . '>' . $title . '</option>'; $selected = ''; } } else { foreach ($elements as $key) { if ($key == $current_value) { $selected = 'selected'; } echo '<option value="' . $key . '"' . $selected . '>' . $key . '</option>'; $selected = ''; } } echo '</select>'; }
public function find_by($args, $order_by = '', $limit = '', $join_type = '', $foreign_table = '') { $type = new PdoValueBinder($this->db->_dbh); //loop through find by and get the where statments if (isset($args) && is_array($args)) { try { // set default where string $sql_where = ''; // quote string $quote = ''; // total arguments provided $total_args = count($args); // count for the array $cnt = 1; // defult string for the AND clause $and = ''; $where = ''; $values = []; // if the array is an associative array if (isAssoc($args)) { //loop through the data provided to the find_by function foreach ($args as $key => $value) { // set $and var if there are more args to come if ($cnt < $total_args) { $and = 'AND '; } else { $and = ''; } // if the value is an array lets loop through it and build the actual sql clause if (is_array($value)) { // values begin here $where = $this->table_name() . '.? IN ('; $values[] = $type->type($key); // loop through array to get the values for ($i = 0; $i < count($value); $i++) { // check if string if (is_string($value[0])) { if ($i + 1 != count($value)) { $where .= '?, '; $values[] = $type->type($value[$i]); } else { $where .= '?)'; $values[] = $type->type($value[$i]); } // else its a numeric value } else { if ($i + 1 != count($value)) { $where .= '?, '; $values[] = $type->type($value[$i]); } else { $where .= '?)'; $values[] = $type->type($value[$i]); } } } $sql_where .= $where; if ($cnt != count($args)) { $sql_where .= ' OR '; } } else { $sql_where .= '`' . $this->table_name() . '`.`' . $key . '` = ? ' . $and; $values[] = $type->type($value); } $cnt++; } // Array is not associative } else { $where = ''; for ($i = 0; $i < count($args); $i++) { if ($i + 1 != count($args)) { $where .= '?, '; $values[] = $type->type($args[$i]); } else { $where .= '?)'; $values[] = $type->type($args[$i]); } } $sql_where .= $this->table_name() . '.id IN (' . $where; } $sql_where = ' WHERE ' . $sql_where; } catch (Exception $e) { $debugbar = app()->debugbar; $debugbar::$debugbar['exceptions']->addException($e); } } else { // if the just provided a single numeric value send it to find to handle return static::find($args, $join_type, $foreign_table); } if ($limit == '') { $order_by .= ';'; } $sql2 = $this->_getSql($join_type, $order_by, $foreign_table, $sql_where, $limit); $x2 = $this->getResult($sql2[0], $values); return $x2; }
/** * Function to create Radio */ function getIOARadioInput($params) { $value = array(); if (isset($params['value']) && trim($params['value']) != "") { $value = explode(",", $params['value']); } else { $value = explode(",", $params['default']); } $opts = ''; $i = 0; $useKey = true; if (!isAssoc($params['options'])) { $useKey = false; } foreach ($params['options'] as $key => $option) { $v = $option; if ($useKey) { $v = $key; } if (in_array($v, $value)) { $opts .= "<input type='radio' name='" . $params['name'] . "' id='" . $params['name'] . $i . "' checked='checked' value='" . $v . "' /><label for='" . $params['name'] . $i . "'> " . $option . "</label>"; } else { $opts .= "<input type='radio' name='" . $params['name'] . "' id='" . $params['name'] . $i . "' value='" . $v . "' /><label for='" . $params['name'] . $i . "'> " . $option . "</label>"; } $i++; } $str = " <div class='ioa_radio_wrap'> " . $opts . " </div>"; return $str; }
/** * // TODO Make this documentation better later * Take in ARRAY or SINGLE of raw question data from model and create array * of Question instances. */ private static function parseRawData(array $data) { if (count($data) == 0) { return []; } if (!isAssoc($data)) { $questions = []; foreach ($data as $rawQuestion) { $questions[] = new Question($rawQuestion); } return $questions; } // Not an array, so just parse single question. return new Question($data); }
public function assertHeaders(array $assertedHeaders = array()) { if (empty($this->headers)) { $headersRaw = substr($this->response, 0, $this->getCurlInfo(CURLINFO_HEADER_SIZE)); $this->headers = array_change_key_case(http_parse_headers($headersRaw), CASE_LOWER); } //// // Associated array //// if (isAssoc($assertedHeaders)) { $assertedHeaders = array_change_key_case($assertedHeaders, CASE_LOWER); foreach ($assertedHeaders as $k => $v) { if (!array_key_exists($k, $this->headers)) { throw new \Exception("Asserted header '{$k}' is not set."); } if (is_array($this->headers[$k])) { if (!in_array($v, $this->headers[$k])) { throw new \Exception("Asserted header '{$k}' exists, but the response header value '{$v}' is not equal."); } } else { if ($v !== $this->headers[$k]) { throw new \Exception("Asserted header '{$k}={$v}' does not equal response header '{$k}=" . $this->headers[$k] . "'."); } } } } else { $this->assertHeadersExist($assertedHeaders); } return $this; }
function var2html($var_) { if (is_null($var_)) { return 'null'; } if (is_array($var_)) { if (isAssoc($var_)) { $var2 = array(); foreach ($var_ as $k => $v) { array_push($var2, hash2html($k, $v)); } $var_ = $var2; } return '[<span style="font-size: 80%;">' . implode(', ', $var_) . '</span>]'; } return $var_; }
function arrayToList($array, $list_class = NULL, $item_class = NULL) { $list = "<ul class='{$list_class}'>"; if (!is_array($array)) { return $array; } if (isAssoc($array)) { return $array; } foreach ($array as $a) { $list .= "<li class='{$item_class}'>" . $a . "</li>"; } $list .= "</ul>"; return $list; }
public function insert($fields = array()) { try { if (count($fields)) { $keys = array_keys($fields); $x = 1; $values = ''; foreach ($fields as $field) { $values .= '?'; if ($x < count($fields)) { $values .= ', '; } $x++; } $this->sql['action'] = "INSERT INTO"; if ($fields) { if (isAssoc($fields)) { $this->sql['table'] = substr($this->sql['table'], 5) . "(`" . implode('`, `', $keys) . "`)"; } else { $this->sql['table'] = substr($this->sql['table'], 5); } } $this->sql['fields'] = "VALUES({$values})"; $query = implode(" ", $this->sql); //return $this; return !$this->query($query, $fields)->error(); } } catch (PDOException $e) { die($e->getMessage()); } return false; }
} } ?> </div> <form method="get" class="appnitro" action=""> <label for="D_assoc">Selecionar Associado</label> <input id="D_assoc" type="text" name="D_assoc" placeholder="RG do associado" value="<?php echo @$_GET['D_assoc']; ?> "> <input type="submit" value="BUSCA"> </form> <form id="form_1044499" class="appnitro" method="post" action=""> <?php if (isAssoc(@$_GET['D_assoc'])) { getAssoc($_GET['D_assoc']); echo "<br>"; getDep($_GET['D_assoc']); print "\n <form id='form_1044499' class='appnitro' method='post' action=''>\n <ul >\n <li id='li_1' >\n <label class='description' for='element_1'>Nome </label>\n\t\t<span>\n\t\t\t<input id='element_1_1' name='D_nome' class='element text' maxlength='255' size='38' required/>\n\t\t\t<label>Nome completo</label>\n </li>\n <li id='li_3' >\n <label class='description' for='element_3'>Data de nascimento </label>\n\t\t<span>\n <input id='element_3_2' name='D_datanascDD' class='element text' size='2' maxlength='2' value='' type='number'> /\n\t\t\t<label for='element_3_2'>DD</label>\n\n\t\t</span>\n\t\t<span>\n\t\t\t<input id='element_3_1' name='D_datanascMM' class='element text' size='2' maxlength='2' value='' type='number'> /\n\t\t\t<label for='element_3_1'>MM</label>\n\t\t</span>\n\t\t<span>\n\t \t\t<input id='element_3_3' name='D_datanascYYYY' class='element text' size='4' maxlength='4' value='' type='number'>\n\t\t\t<label for='element_3_3'>YYYY</label>\n\t\t</span>\n\n\t\t<span id='calendar_3'>\n\t\t\t<img id='cal_img_3' class='datepicker' src='../img/calendar.gif' alt='Pick a date.'>\n\t\t</span>\n <script type='text/javascript'>\n Calendar.setup({\n inputField\t : 'element_3_3',\n baseField : 'element_3',\n displayArea : 'calendar_3',\n button\t\t : 'cal_img_3',\n ifFormat\t : '%B %e, %Y',\n onSelect\t : selectDate\n });\n </script>\n\n </li>\n <li id='li_10' >\n <label class='description' for='element_10'>Grau de Parentesco </label>\n <div>\n <select class='element select medium' id='element_10' name='D_parentesco' required>\n <option value='Mâe' >Mae</option>\n <option value='Pai' selected='selected'>PAI</option>\n <option value='Filho' >Filho</option>\n <option value='Filha'>Filha</option>\n <option value='Sobrinho' >Sobrinho</option>\n <option value='Sobrinha' >Sobrinha</option>\n <option value='Tio' >Tio</option>\n <option value='Tia' >Tio</option>\n <option value='Marido' >Marido</option>\n <option value='Esposa' >Esposa</option>\n <option value='Irmão' >Irmão</option> \n <option value='Irmã' >Irmã</option> \n <option value='Primo' >Primo</option> \n <option value='Prima' >Prima</option> \n <option value='Sogro' >Sogro</option> \n <option value='Sogra' >Sogra</option> \n <option value='Outros' >Outros</option> \n </select>\n </div>\n </li>\n\n <li class='buttons'>\n <input type='hidden' name='form_id' value='677' />\n\n <input id='saveForm' class='button_text' type='submit' name='submit' value='Cadastrar' />\n </li>\n </ul>\n </form>\n"; } else { echo "<p style='color: #22a20b;'>Busque por um associado para adicionar dependentte</p>"; } ?> <div id="footer"> </div> </div> <img id="bottom" src="../img/bottom.png" alt=""> </body> </html>
/** * 执行请求处理 */ public function doService() { $config = $this->config; if (!empty($config['json'])) { if (isAssoc($config['json'])) { foreach ($config['json'] as $key => $file) { $this->assign($key, readJson($file)); } } else { foreach ($config['json'] as $file) { $this->assignJsonFile($file); } } } // 固定变量 if (!empty($config['var'])) { $this->assign($config['var']); } if (!empty($config['tplData'])) { $this->assign('tplData', $config['tplData'], true); } if (!empty($config['extData'])) { $this->assign('extData', $config['extData'], true); } if (!empty($config['paramData'])) { $this->assign('paramData', $config['paramData'], true); } $templateVars = $this->smarty->getTemplateVars(); $this->doModifyData($templateVars); if (!empty($config['tplPath'])) { $tplPath = preg_replace('#^[/\\\\]+#', '', $config['tplPath']); $this->display($config['tplPath']); } }
/** * * Send a message to some technology URI or endpoint. * TODO somehow just can't create PUT method to the Asterisk server response : "message": "Invalid method" * * * @param null $to * @param null $from * @param null $body * @param null $variables - MUST BE ASSOCIATIVE ARRAY * * @return bool */ public function sendmessage($to = NULL, $from = NULL, $body = NULL, $variables = NULL) { try { if (is_null($to)) { throw new Exception("endpoint name not provided or is null", 503); } if (is_null($from)) { throw new Exception("endpoint name not provided or is null", 503); } $uri = "/endpoints/sendMessage"; /* Validate technologies */ list($res_to, $address_to) = explode(":", $to); switch (strtoupper($res_to)) { case "SIP": case "PJSIP": case "XMPP": break; default: throw new Exception("To resource is of invalid resource type"); break; } list($res_from, $address_from) = explode(":", $from); switch (strtoupper($res_from)) { case "SIP": case "PJSIP": case "XMPP": break; default: throw new Exception("From resource is of invalid resource type"); break; } $message = array('to' => $to, 'from' => $from, 'body' => $body); $message = isAssoc($variables) ? array_merge($message, $variables) : $message; $result = $this->pestObject->put($uri, $message); return $result; } catch (Exception $e) { $this->phpariObject->lasterror = $e->getMessage(); $this->phpariObject->lasttrace = $e->getTraceAsString(); return FALSE; } }
function yd_bullhorn($atts) { //Set attribute defaults $attr = shortcode_atts(array('url' => get_option('bh_rss_url')), $atts); if (!strlen($attr['url'])) { return 'Please fill in the RSS URL.'; } $unique = md5($attr['url']); //makes transient unique but persistent $view = ''; //init the view to be sent back. Super primitive stuff! if (get_option('bh_load_styling')) { wp_register_style('yd_bullhorn', plugins_url('yd_bullhorn.css', __FILE__)); wp_enqueue_style('yd_bullhorn'); } $objects = get_transient('yd_' . $unique); //see if this object exists as a transient. if (!get_option('bh_cache') || !$objects) { $objects = yd_bullhorn_get($attr['url']); //grab the RSS. $objects = json_encode($objects); //back to array; if (get_option('bh_cache')) { //if the system is set to do a cache, set it. set_transient('yd_' . $unique, $objects, 600); //600 seconds = 10 minutes } else { delete_transient('yd_' . $unique); } } $objects = json_decode($objects, true); //back to array; if (is_array($objects) && !count($objects['channel']['item'])) { return 'There are no jobs at this time. Check back later.'; } if (is_array($objects) && !isAssoc($objects['channel']['item'])) { //Definitely not my idea of awesome code, but it works. foreach ($objects['channel']['item'] as $object) { //date_default_timezone_get(); $cur_date = date("m-d-Y", strtotime($object['pubDate'])); $view .= ' <div class="bullhorn-rss-item"> <a href="' . $object['link'] . '"> <h2>' . $object['title'] . '</h2> </a> <date>' . $cur_date . '</date> <div class="content">' . $object['description'] . '</div> </div>'; } return $view; } else { $object = $objects['channel']['item']; $cur_date = date("m-d-Y", strtotime($object['pubDate'])); $view .= ' <div class="bullhorn-rss-item"> <a href="' . $object['link'] . '"> <h2>' . $object['title'] . '</h2> </a> <date>' . $cur_date . '</date> <div class="content">' . $object['description'] . '</div> </div>'; return $view; } }