function object_set_options($obj, $options, $allowed_keys = array()) { $options = array_clean($options, $allowed_keys); foreach ($options as $k => $v) { $obj->{$k} = $v; } }
public function __construct() { $temp = array_clean(explode('\\', get_called_class())); $this->instance = strtolower($temp[1]); unset($temp); $this->db = \app::$db; }
public function setitems($idpost, array $items) { array_clean($items); $db = $this->db; $old = $this->getitems($idpost); $add = array_diff($items, $old); $delete = array_diff($old, $items); if (count($delete)) { $db->delete("{$this->postprop} = {$idpost} and {$this->itemprop} in (" . implode(', ', $delete) . ')'); } if (count($add)) { $vals = array(); foreach ($add as $iditem) { $vals[] = "({$idpost}, {$iditem})"; } $db->exec("INSERT INTO {$this->thistable} ({$this->postprop}, {$this->itemprop}) values " . implode(',', $vals)); } return array_merge($old, $add); }
/** * Post processes an NLM meta-data array * @param $preliminaryNlmArray array * @return array */ function &postProcessMetadataArray(&$preliminaryNlmArray) { // Clean array $preliminaryNlmArray =& array_clean($preliminaryNlmArray); // Trim punctuation $preliminaryNlmArray =& $this->_recursivelyTrimPunctuation($preliminaryNlmArray); // Parse (=filter) author/editor strings into NLM name descriptions foreach (array('author', 'editor') as $personType) { if (isset($preliminaryNlmArray[$personType])) { // Get the author/editor strings from the result $personStrings = $preliminaryNlmArray[$personType]; unset($preliminaryNlmArray[$personType]); // Parse the author/editor strings into NLM name descriptions $personStringFilter = new PersonStringNlmNameSchemaFilter(ASSOC_TYPE_AUTHOR); // Interpret a scalar as a textual authors list if (is_scalar($personStrings)) { $personStringFilter->setFilterMode(PERSON_STRING_FILTER_MULTIPLE); $persons =& $personStringFilter->execute($personStrings); } else { $persons =& array_map(array($personStringFilter, 'execute'), $personStrings); } $preliminaryNlmArray['person-group[@person-group-type="' . $personType . '"]'] = $persons; unset($persons); } } // Join comments if (isset($preliminaryNlmArray['comment']) && is_array($preliminaryNlmArray['comment'])) { // Implode comments from the result into a single string // as required by the NLM citation schema. $preliminaryNlmArray['comment'] = implode("\n", $preliminaryNlmArray['comment']); } // Normalize date strings foreach (array('date', 'conf-date', 'access-date') as $dateProperty) { if (isset($preliminaryNlmArray[$dateProperty])) { $dateFilter = new DateStringNormalizerFilter(); $preliminaryNlmArray[$dateProperty] = $dateFilter->execute($preliminaryNlmArray[$dateProperty]); } } // Cast strings to integers where necessary foreach (array('fpage', 'lpage', 'size') as $integerProperty) { if (isset($preliminaryNlmArray[$integerProperty]) && is_numeric($preliminaryNlmArray[$integerProperty])) { $preliminaryNlmArray[$integerProperty] = (int) $preliminaryNlmArray[$integerProperty]; } } // Rename elements that are stored in attributes in NLM citation $elementToAttributeMap = array('access-date' => 'date-in-citation[@content-type="access-date"]', 'issn-ppub' => 'issn[@pub-type="ppub"]', 'issn-epub' => 'issn[@pub-type="epub"]', 'pub-id-doi' => 'pub-id[@pub-id-type="doi"]', 'pub-id-publisher-id' => 'pub-id[@pub-id-type="publisher-id"]', 'pub-id-coden' => 'pub-id[@pub-id-type="coden"]', 'pub-id-sici' => 'pub-id[@pub-id-type="sici"]', 'pub-id-pmid' => 'pub-id[@pub-id-type="pmid"]', 'publication-type' => '[@publication-type]'); foreach ($elementToAttributeMap as $elementName => $nlmPropertyName) { if (isset($preliminaryNlmArray[$elementName])) { $preliminaryNlmArray[$nlmPropertyName] = $preliminaryNlmArray[$elementName]; unset($preliminaryNlmArray[$elementName]); } } return $preliminaryNlmArray; }
/** * Создание URL-кодированной строки запроса с пропуском пустых значений * * @param array $arr массив значений * @return string */ function build_query($arr) { return http_build_query(array_clean($arr, array('', false, null))); }
/** public function invite * Creates the game from _POST data * * @param void * @action creates a game * @return int game id */ public function invite() { call(__METHOD__); // DON'T sanitize the data // it gets sani'd in the MySQL->insert method $_P = $_POST; // translate (filter/sanitize) the data $_P['white_id'] = $_P['player_id']; $_P['black_id'] = $_P['opponent']; $_P['small_square_matches'] = isset($_P['small_square_matches']) && 'yes' == $_P['small_square_matches']; $_P['small_square_torus'] = isset($_P['small_square_torus']) && 'yes' == $_P['small_square_torus']; $_P['diagonal_torus'] = isset($_P['diagonal_torus']) && 'yes' == $_P['diagonal_torus']; $extra_info = array('small_square_matches' => (bool) $_P['small_square_matches'], 'small_square_torus' => (bool) $_P['small_square_torus'], 'diagonal_torus' => (bool) $_P['diagonal_torus']); call($extra_info); $diff = array_compare($extra_info, self::$_EXTRA_INFO_DEFAULTS); $extra_info = $diff[0]; ksort($extra_info); call($extra_info); if (!empty($extra_info)) { $_P['extra_info'] = serialize($extra_info); } // create the game $required = array('white_id', 'black_id'); $key_list = array_merge($required, array('extra_info')); try { $_DATA = array_clean($_P, $key_list, $required); } catch (MyException $e) { throw $e; } $_DATA['create_date '] = 'NOW( )'; // note the trailing space in the field name, this is not a typo // THIS IS THE ONLY PLACE IN THE CLASS WHERE IT BREAKS THE _pull / _save MENTALITY // BECAUSE I NEED THE INSERT ID FOR THE REST OF THE GAME FUNCTIONALITY $insert_id = $this->_mysql->insert(self::GAME_TABLE, $_DATA); if (empty($insert_id)) { throw new MyException(__METHOD__ . ': Game could not be created'); } $this->id = $insert_id; Email::send('invite', $_P['black_id'], array('player' => $GLOBALS['_PLAYERS'][$_P['white_id']])); // set the modified date $this->_mysql->insert(self::GAME_TABLE, array('modify_date' => NULL), " WHERE game_id = '{$this->id}' "); // pull the fresh data $this->_pull(); // set the next piece try { if ('random' != $_P['piece']) { $this->_quarto->next_piece = $_P['piece']; } else { $pieces = '0123456789ABCDEF'; $this->_quarto->next_piece = strtoupper(dechex(mt_rand(0, 15))); } } catch (MyException $e) { throw $e; } return $this->id; }
public function getsimilar($list) { if (!$this->showsimilar || !count($list)) { return ''; } $cats = $this->cats; $cats->loadall(); $parents = array(); foreach ($list as $id) { $parents[] = $cats->getvalue($id, 'parent'); } array_clean($parents); if (!count($parents)) { return ''; } /* without db cant sort $similar = array(); foreach ($cats->items as $id => $item) { if (in_array($item['parent'], $parents)) $similar[] = $id; } */ $parents = implode(',', $parents); $list = implode(',', $list); $similar = $cats->db->idselect("parent in ({$parents}) and id not in ({$list}) order by {$this->childsortname} asc"); array_clean($similar); if (!count($similar)) { return ''; } $theme = ttheme::i(); $args = new targs(); $items = ''; foreach ($similar as $id) { $args->add($cats->getitem($id)); $items .= $theme->parsearg($this->tml['similaritem'], $args); } $args->item = $items; return $theme->parsearg($this->tml['similaritems'], $args); }
/** protected function _save * Saves the setup data to the database * * @param string [optional] reflection type (Origin, Long, Short) * @action saves the setup data * @return void */ protected function _save($reflection = 'Origin') { call(__METHOD__); $Mysql = Mysql::get_instance(); try { $this->validate($reflection); } catch (MyException $e) { throw $e; } // DON'T sanitize the data // it gets sani'd in the MySQL->insert method // translate (filter/sanitize) the data $data['name'] = $this->name; $data['board'] = packFEN($this->board); $data['reflection'] = self::_get_reflection($this->board); $data['has_horus'] = self::has_horus($this->board); $data['has_sphynx'] = self::has_sphynx($this->board); $data['has_tower'] = self::has_tower($this->board); $data['created_by'] = (int) $this->creator; call($data); // create the setup $required = array('name', 'board'); $key_list = array_merge($required, array('reflection', 'has_horus', 'has_sphynx', 'has_tower', 'created_by')); try { $_DATA = array_clean($data, $key_list, $required); } catch (MyException $e) { throw $e; } $_DATA['created '] = 'NOW( )'; // note the trailing space in the field name, this is not a typo // grab the original setup data $query = "\n\t\t\tSELECT *\n\t\t\tFROM " . self::SETUP_TABLE . "\n\t\t\tWHERE setup_id = '{$this->id}'\n\t\t"; $setup = $Mysql->fetch_assoc($query); call($setup); if (!empty($this->id) && !$setup) { // we must have deleted the setup, just stop return false; } if (!$setup) { $this->id = $Mysql->insert(self::SETUP_TABLE, $_DATA); if (empty($this->id)) { throw new MyException(__METHOD__ . ': Setup could not be created'); } return $this->id; } $update_setup = false; // don't change the creator // in case of admin edits unset($_DATA['created_by']); foreach ($setup as $key => $value) { if (empty($_DATA[$key])) { continue; } if ($_DATA[$key] != $value) { $update_setup[$key] = $_DATA[$key]; } } call($update_setup); if ($update_setup) { $Mysql->insert(self::SETUP_TABLE, $update_setup, " WHERE setup_id = '{$this->id}' "); return true; } return false; }
/** static public function extra_info * Returns the extra info merged with the default values * * @param array [optional] extra info * @return array extra info */ public static function extra_info($extra_info = array()) { $extra_info = array_clean($extra_info, array_keys(self::$EXTRA_INFO_DEFAULTS)); return array_merge_plus(self::$EXTRA_INFO_DEFAULTS, $extra_info); }
public function postedited($idpost) { $post = $this->factory->getpost((int) $idpost); $items = $post->{$this->postpropname}; array_clean($items); if (count($items)) { $items = $this->db->idselect(sprintf('id in (%s)', implode(',', $items))); } $changed = $this->itemsposts->setitems($idpost, $items); $this->updatecount($changed); }
/** * @inheritdoc * @todo : 'custom' form property should be handled, for now it is always activated */ protected function processLabel($name, &$options) { $label_tag = null; if (array_key_exists('label', $options)) { $label = array_pull($options, 'label'); if (array_key_exists('text', $label)) { $label = array_add($label, 'class', ''); $text = array_pull($label, 'text'); array_clean($label); $label_tag = $this->edifice->form->label($name, '<span class="custom radio"></span> ' . $text, $label); } } return array('label' => $label_tag); }
/** * Processes the form input label. * * @param string $name Form input name * @param array $options Form input options, label options will be extracted * * @return array */ protected function processLabel($name, &$options) { $label_tag = null; $inline = null; if (array_key_exists('label', $options)) { $label = array_pull($options, 'label'); if (array_key_exists('text', $label)) { $label = array_add($label, 'class', ''); $inline = array_pull($label, 'inline'); $align = array_pull($label, 'align'); $text = array_pull($label, 'text'); // Processing label inline ( the processing order is important ) if ($inline === true) { array_add_to_key($label, 'class', 'inline'); } if ($align === 'left' or $align === 'right') { array_add_to_key($label, 'class', $align); } array_clean($label); $label_tag = $this->edifice->form->label($name, $text, $label); if ($inline === true) { $label_tag = create_div(array('class' => 'small-4 large-4 columns'), $label_tag); } } } return array('label' => $label_tag, 'inline' => $inline); }
/** static public function invite * Creates the game from _POST data * * @param void * @action creates an invite * @return int game id */ public static function invite() { call(__METHOD__); call($_POST); $Mysql = Mysql::get_instance(); // DON'T sanitize the data // it gets sani'd in the MySQL->insert method $_P = $_POST; // translate (filter/sanitize) the data $_P['white_id'] = (int) $_SESSION['player_id']; $_P['black_id'] = (int) $_P['opponent']; $_P['setup_id'] = (int) $_P['setup']; $_P['laser_battle'] = is_checked($_P['laser_battle_box']); $_P['battle_front_only'] = is_checked($_P['battle_front_only']); $_P['battle_hit_self'] = is_checked($_P['battle_hit_self']); $_P['move_sphynx'] = is_checked($_P['move_sphynx']); call($_P); // grab the setup $query = "\n\t\t\tSELECT setup_id\n\t\t\tFROM " . Setup::SETUP_TABLE . "\n\t\t"; $setup_ids = $Mysql->fetch_value_array($query); call($setup_ids); // check for random setup if (0 == $_P['setup_id']) { shuffle($setup_ids); shuffle($setup_ids); $_P['setup_id'] = (int) reset($setup_ids); sort($setup_ids); } // make sure the setup id is valid if (!in_array($_P['setup_id'], $setup_ids)) { throw new MyException(__METHOD__ . ': Setup is not valid'); } $query = "\n\t\t\tSELECT board\n\t\t\tFROM " . Setup::SETUP_TABLE . "\n\t\t\tWHERE setup_id = '{$_P['setup_id']}'\n\t\t"; $setup = $Mysql->fetch_value($query); // laser battle cleanup // only run this if the laser battle box was open if ($_P['laser_battle']) { ifer($_P['battle_dead'], 1, false); ifer($_P['battle_immune'], 1); // we can only hit ourselves in the sides or back, never front if ($_P['battle_front_only']) { $_P['battle_hit_self'] = false; } $extra_info = array('battle_dead' => (int) max((int) $_P['battle_dead'], 1), 'battle_immune' => (int) max((int) $_P['battle_immune'], 0), 'battle_front_only' => (bool) $_P['battle_front_only'], 'battle_hit_self' => (bool) $_P['battle_hit_self']); } $extra_info['white_color'] = $_P['color']; $extra_info['move_sphynx'] = $_P['move_sphynx']; $setup = expandFEN($setup); try { if (is_checked($_P['convert_to_1']) || is_checked($_P['rand_convert_to_1'])) { $setup = Setup::convert_to_1($setup); } elseif (is_checked($_P['convert_to_2']) || is_checked($_P['rand_convert_to_2'])) { $setup = Setup::convert_to_2($setup); } } catch (MyException $e) { throw $e; } $extra_info['invite_setup'] = packFEN($setup); call($extra_info); $diff = array_compare($extra_info, self::$_EXTRA_INFO_DEFAULTS); $extra_info = $diff[0]; ksort($extra_info); call($extra_info); if (!empty($extra_info)) { $_P['extra_info'] = serialize($extra_info); } // create the game $required = array('white_id', 'setup_id'); $key_list = array_merge($required, array('black_id', 'extra_info')); try { $_DATA = array_clean($_P, $key_list, $required); } catch (MyException $e) { throw $e; } $_DATA['state'] = 'Waiting'; $_DATA['create_date '] = 'NOW( )'; // note the trailing space in the field name, this is not a typo $_DATA['modify_date '] = 'NOW( )'; // note the trailing space in the field name, this is not a typo $insert_id = $Mysql->insert(self::GAME_TABLE, $_DATA); if (empty($insert_id)) { throw new MyException(__METHOD__ . ': Invite could not be created'); } // send the email if ($_DATA['black_id']) { Email::send('invite', $_DATA['black_id'], array('opponent' => $GLOBALS['_PLAYERS'][$_DATA['white_id']], 'page' => 'invite.php')); } return $insert_id; }
public function maybe($class) { $class = array_clean(explode('/', $class)); include __ROOT__ . '/vendor/' . join('/', $class) . '.php'; }
/** public function update * Updates player info in the system * * @param void * @action updates player in the database * @return bool success */ public function update() { call(__METHOD__); $required = array('email'); $key_list = array_merge($required, array('first_name', 'last_name')); if ($_DATA = array_clean($_POST, $key_list, $required)) { // remove any html foreach ($_DATA as &$data) { $data = preg_replace('/<.+?>/', '', $data); } unset($data); // kill the reference // first, make sure this player is not already in the system try { self::check_database('', $_DATA['email'], $this->id); } catch (MyException $e) { // the data givin is already in the database throw $e; } $where = " WHERE player_id = '{$this->id}' "; $this->_mysql->insert(self::PLAYER_TABLE, $_DATA, $where); if (!empty($_POST['password'])) { try { return $this->update_password($_POST['curpass'], $_POST['password']); } catch (MyException $e) { throw $e; } } else { $this->_pull(); return true; } } // if something went wrong with the array_clean function // such as missing required data... throw new MyException(__METHOD__ . ': Unable to update player'); }
/** * Очистка массива переданного как указатель * @param $a */ function array_clean_ref(&$a) { $a = array_clean($a); }
/** public function set_extra_info * Sets the extra info for the game * * @param array $extra_info * * @return void */ public function set_extra_info($extra_info) { call(__METHOD__); $extra_info = array_clean($extra_info, array_keys(self::$EXTRA_INFO_DEFAULTS)); $this->_extra_info = array_merge_plus(self::$EXTRA_INFO_DEFAULTS, $extra_info); // the update trade value function depends on the extra info $this->_update_trade_value($log = false); if ('none' != $this->_extra_info['conquer_type']) { // the conquer limit calculation depends on the trade value info and extra info $this->calculate_conquer_limit(); } }
/** protected function _set_player_data * Adds a player to the game and risk data * * @param array $data player data * @param int $count optional total player count * * @return void * @throws MyException */ protected function _set_player_data($data, $count = null) { call(__METHOD__); $player = array_merge_plus(self::$_PLAYER_DEFAULTS, $data); if (empty($player['player_id'])) { throw new MyException(__METHOD__ . ': Missing player ID'); } // temp fix for old serialized data fix_extra_info($player['extra_info']); $player['extra_info'] = array_merge_plus(self::$_PLAYER_EXTRA_INFO_DEFAULTS, json_decode($player['extra_info'], true)); if (!empty($player['cards'])) { array_trim($player['cards'], 'int'); } else { $player['cards'] = array(); } $player['game_id'] = $this->id; // if the player got deleted, show that try { $player['object'] = new GamePlayer($player['player_id']); } catch (MyException $e) { $player['object'] = new GamePlayer(); $player['object']->username = '******'; } // move any data we need to over to the risk class player data $risk_player = $player; $player_keys = array('player_id', 'color', 'move_date', 'object'); $player = array_clean($player, $player_keys); $risk_player_keys = array('player_id', 'order_num', 'cards', 'armies', 'state', 'extra_info'); $risk_player = array_clean($risk_player, $risk_player_keys); $this->_players[$player['player_id']] = $player; $this->_risk->players[$player['player_id']] = $risk_player; }
public function setfiles(array $list) { array_clean($list); $this->data['files'] = $list; }
/** protected function _set_player_data * Adds a player to the game and risk data * * @param array $data player data * @param int $count optional total player count * * @return void * @throws MyException */ protected function _set_player_data($data, $count = null) { call(__METHOD__); $player = array_merge_plus(self::$_PLAYER_DEFAULTS, $data); if (empty($player['player_id'])) { throw new MyException(__METHOD__ . ': Missing player ID'); } // temp fix for old serialized data fix_extra_info($player['extra_info']); $player['extra_info'] = array_merge_plus(self::$_PLAYER_EXTRA_INFO_DEFAULTS, json_decode($player['extra_info'], true)); if (!empty($player['cards'])) { array_trim($player['cards'], 'int'); } else { $player['cards'] = array(); } $player['game_id'] = $this->id; // move any data we need to over to the risk class player data $risk_player = $player; $player_keys = array('player_id', 'color', 'name'); $player = array_clean($player, $player_keys); $risk_player['armies'] = $this->_risk->get_start_armies($count); $risk_player['state'] = 'Placing'; $risk_player_keys = array('player_id', 'order_num', 'cards', 'armies', 'state', 'extra_info'); $risk_player = array_clean($risk_player, $risk_player_keys); $this->_players[$player['player_id']] = $player; $this->_risk->players[$player['player_id']] = $risk_player; }
function arrayClean($array, $keys, $reqd = array()) { return array_clean($array, $keys, $reqd); }
/** * array_clean() * * @param mixed $haystack * @return */ function array_clean(array $haystack) { foreach ($haystack as $key => $value) { if (is_array($value)) { $haystack[$key] = array_clean($value); } elseif (is_string($value)) { $value = trim($value); } if (!$value) { unset($haystack[$key]); } elseif (strlen($value) == 0) { unset($haystack[$key]); } } return $haystack; }