// autocomplete textbox if ($ajax_quicksearch) { foreach ($result as $item) { $title = $item['title']; if ($item['subtitle']) { $title .= ' - ' . $item['subtitle']; } $title = preg_replace('/(' . $q . ')/Ui', '<em>\\1</em>', $title); $ret .= "<li id='" . $item['id'] . "'>" . $title . "</li>"; } $ret = "<ul>{$ret}</ul>"; echo $ret; exit; } // store query result in session for prev/next navigation session_set('query_result', array_extract($result, 'id')); } // process asynchronous refresh if ($ajax_render) { ajax_render(); } // prepare templates tpl_page('search', $q); tpl_list($result); $smarty->assign('q', $q); $smarty->assign('q_q', formvar($q)); $smarty->assign('search_fields', $search_fields); $smarty->assign('genreselect', out_genres($genres)); $smarty->assign('genres', out_genres2($genres)); //2015-10-6 Alex ADD start $smarty->assign('studioselect', out_studios($studios));
/** * Function combines multiple actor thumbnail queries into single SQL query */ function get_actor_thumbnails_batched(&$actors) { if (!count($actors)) { return; } $ids = "'" . join("','", array_map('addslashes', array_extract($actors, 'id'))) . "'"; $SQL = 'SELECT actorid, name, imgurl, UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(checked) AS cacheage FROM ' . TBL_ACTORS . ' WHERE actorid IN (' . $ids . ')'; $result = runSQL($SQL); $result = array_associate($result, 'actorid'); // loop over actors from full-text field foreach ($actors as $idx => $actor) { // check for actor thumbnail $batch_result = $result[$actor['id']]; if ($batch_result) { $actors[$idx]['imgurl'] = get_actor_image_from_cache($batch_result, $actor['name'], $actor['id']); } else { $actors[$idx]['imgurl'] = getActorThumbnail($actor['name'], $actor['id'], false); } } }
static function DoRoutes($url) { $routes = Url::GetRoutes(); // add slash $url = preg_replace('/([^\\/])$/', '${1}/', $url); foreach ($routes as $pattern => $data) { $pattern = "%^{$pattern}\$%Uis"; // add pattern defaults & flags if (preg_match($pattern, $url) !== 0) { // redirect? if ($redirect = array_get($data, 'redirect')) { header('Location: ' . str_replace('DOMAIN', DOMAIN, $redirect)); die; } // params $params = array_extract($data, array('replace', 'continue'), true); $url = preg_replace($pattern, $params['replace'], $url); Url::$data = array_merge(Url::$data, $data); // break? if (!$params['continue']) { break; } } } // d($url);d_arr(Url::$data);die; // clean and return return preg_replace('/\\/$/', '', strtolower($url)); }
/** * @return array */ public function getValues() { return array_extract($this->values, $this->fields); }
/** * SQL wrapper for all Database accesses * * @param string $sql_string The SQL-Statement to execute * @return mixed either the resultset as an array with hashes or the insertid */ function runSQL($sql_string, $verify = true) { global $config, $dbh, $SQLtrace; if ($config['debug']) { dlog("\n" . $_SERVER['REQUEST_URI']); if (function_exists('xdebug_get_function_stack')) { dlog(join(' -> ', array_extract(xdebug_get_function_stack(), 'function'))); } dlog($sql_string); $timestamp = getmicrotime(); } if (!is_resource($dbh)) { $dbh = getConnection(); } $res = mysqli_query($dbh, $sql_string); // mysqli_db_query returns either positive result ressource or true/false for an insert/update statement if ($res === false) { $result = false; if ($verify) { // report DB Problem errorpage('Database Problem', mysqli_error($dbh) . "\n<br />\n" . $sql_string, true); } } elseif ($res === true) { // on insert, return id of created record $result = mysqli_insert_id($dbh); } else { // return associative result array $result = array(); for ($i = 0; $i < mysqli_num_rows($res); $i++) { $result[] = mysqli_fetch_assoc($res); } mysqli_free_result($res); } if ($config['debug']) { $timestamp = getmicrotime() - $timestamp; dlog('Time: ' . $timestamp); // collect all SQL info for debugging $SQLtrace[] = array('sql' => $sql_string, 'time' => $timestamp); } # mysqli_close($dbh); return $result; }
/** * SQL wrapper for all Database accesses * * @param string $sql_string The SQL-Statement to execute * @return mixed either the resultset as an array with hashes or the insertid */ function runSQL($sql_string, $verify = true) { global $config, $db_link, $SQLtrace; if ($config['debug']) { dlog("\n" . $_SERVER['REQUEST_URI']); if (function_exists('xdebug_get_function_stack')) { dlog(join(' -> ', array_extract(xdebug_get_function_stack(), 'function'))); } dlog($sql_string); $timestamp = getmicrotime(); } if (!is_resource($db_link)) { $db_link = mysql_pconnect($config['db_server'], $config['db_user'], $config['db_password']) or errorpage('DB Connection Error', "<p>Edit the database settings in <code>" . CONFIG_FILE . "</code>.</p>\n <p>Alternatively, consider running the <a href='install.php'>installation script</a>.</p>"); mysql_select_db($config['db_database'], $db_link) || errorpage('DB Connection Error', "Couldn't select database: " . $config['db_database'] . "<p>Please verify your database is up and running and validate your database settings in <code>" . CONFIG_FILE . "</code>.</p>\n <p>Alternatively, consider running the <a href='install.php'>installation script</a>.</p>"); if (DB_CHARSET) { mysql_query("SET NAMES '" . DB_CHARSET . "'", $db_link) || errorpage('DB Link Error', 'Couldn\'t set encoding to ' . DB_ENCODING); } } $res = mysql_query($sql_string, $db_link); // mysql_db_query returns either positive result ressource or true/false for an insert/update statement if ($res === false) { if ($verify) { // report DB Problem errorpage('Database Problem', mysql_error($db_link) . "\n<br />\n" . $sql_string, true); } else { // ignore problem but forward the information $result = false; } } elseif ($res === true) { // on insert, return id of created record $result = mysql_insert_id($db_link); } else { // return associative result array $result = array(); for ($i = 0; $i < mysql_num_rows($res); $i++) { $result[] = mysql_fetch_assoc($res); } mysql_free_result($res); } if ($config['debug']) { $timestamp = getmicrotime() - $timestamp; dlog('Time: ' . $timestamp); // collect all SQL info for debugging $SQLtrace[] = array('sql' => $sql_string, 'time' => $timestamp); } # mysql_close($db_link); return $result; }
/** * Generates a new array where each element is a list of values extracted from the corresponding element on the input * array. * Result: array - An array with the same cardinality as the input array. * * @param array $keys The keys of the values to be extracted from each $array element. * * @return PowerArray Self, for chaining. */ function extract(array $keys) { $this->A = array_extract($this->A, $keys); return $this; }
/** * Alias for array_extract() */ function array_sub($arr, $key) { return array_extract($arr, $key); }
static function CollectionExtract($collection, $keys) { $output = array(); foreach ($collection as $key => $value) { $output[$key] = array_extract($value, $keys); } return $output; }