I am using Kemana directory and intergrating it as a module into my RN 2.40.1
Only registered users can see links on this board! Get registered or login to the forums!
I am trying to be able to add height and width parameters to resize an image. Now if you look at the bottom of the code it seems that height is defined as $2 and width as $1. So it looks as if the values area already accounted for I just dont know what I should change in this code! Thanks to any help anyone can give!
Specific BBCode in includes/function.php
Code:
// http://duncan.xtreme.net.nz/bbCode.php.txt
// convert bbcode to html, eg [b]bold[/b] to <b>bold</b>
function BBCode($Text)
{
// Declare the format for layout
$CodeLayout = '<div class="code"><b>Code:</b><br />$1</div>';
// Declare the format for [quote] layout
$QuoteLayout = '<blockquote><b>Quote:</b><br />$1</blockquote>';
// Set up the parameters for a URL search string
$URLSearchString = " a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\'";
// Set up the parameters for a MAIL search string
$MAILSearchString = $URLSearchString . " a-zA-Z0-9\.@";
<?php
// part of qEngine
// copyright (c) C97.net, usage of this script outside C97 is strictly prohibited!
// please write to us for licensing:
Only registered users can see links on this board! Get registered or login to the forums!
/* Strucure:
// Description
// Parameters - if no info, means the parameter is self explanatory
// Sample of usage - if no sample, means it's quite easy (title is self explanatory)
// Used in (this function is used by ??) - if no info, means used by many ---> used_by only indicates that the function is used within qEngine, so it may be used by other script not listed here
*/
/* ------- ( GENERAL FUNCTIONS ) ------- */
// sending message and just die
function msg_die ($msg_id = '', $msg_txt = '', $url = '')
{
global $config;
if (empty ($url)) @$url = $_SERVER['HTTP_REFERER'];
$msg_txt = safe_send ($msg_txt);
$url = urlencode ($url);
$foo = 'MSG|'.$msg_txt.'|'.$url;
ip_config_update ('system_msg', $foo);
redir ("$config[site_url]/msg.php?admin=0&id=$msg_id");
die ();
}
// like msg_die, but in popup template
function popup_die ($msg_id = '', $msg_txt = '')
{
global $config;
$msg_txt = safe_send ($msg_txt);
$foo = 'MSG|'.$msg_txt;
ip_config_update ('system_msg', $foo);
redir ("$config[site_url]/msg.php?admin=0&popup=1&id=$msg_id");
die ();
}
// generate random string
// param: $l = string length
// $lower = 1 -> lower case only (i.e: abcdef). use $lower = 0 for mixed case (i.e: AbCdEf)
// $hex = 1 -> 0-9, A-F; $hex = 0 -> 0-9, A-Z
function random_str ($len, $lower = 1, $hex = 1)
{
if ($hex)
$ch = "ABCDEF1234567890";
else
$ch = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrtuvwxyz1234567890";
if ($lower) $str = strtolower ($str);
return $str;
}
// get paramenter from GET, POST or COOKIE ... see also date_param()
// $mode = 'noslash' = ' & " will not be slashed !!!!
// 'nohtml' = remove all HTML tags, ' & " -> \' & \"
// 'filterhtml' = remove selected HTML tags (defined in config), '
// 'html' = allow html (be ware of XSS)
// DEFAULT = add slash, convert html, sql ready
function filter_param ($param, $mode)
{
global $config; $html = 0;
if (!$config['gpc_quotes']) $param = addslashes ($param);
if (($cm == 'rte') && ($config['wysiwyg'])) $html = 1;
if (($cm == 'rte') && (!$config['wysiwyg'])) $html = 0;
}
if ($html)
return $param;
else
return htmlspecialchars ($param, ENT_QUOTES);
}
// get_param, post_param & cookie_param will extract vars => WE CAN'T TRY EXTERNAL INPUT (incl. COOKIE's)
// $var_name -> if integer will extract in this fashion: index.php?var1,var2,var3 (0: var1,var2,var3; 1: var1; 2: var2...)
// $mode -> see filter_param ()
// default: in sql ready (' -> \'), convert all HTML tags (" -> ")!
function get_param ($var_name, $default = '', $mode = '')
{
if (is_integer ($var_name))
{
if (!isset ($_SERVER['QUERY_STRING'])) return $default;
$p = $_SERVER['QUERY_STRING'];
$g = explode (',', $p);
array_unshift ($g, $p);
if (empty ($g[$var_name])) return $default;
$v = $g[$var_name];
}
else
{
if (!isset ($_GET[$var_name])) return $default;
$v = $_GET[$var_name];
}
$v = filter_param ($v, $mode);
return trim ($v);
}
// like get_param but for POST method
function post_param ($var_name, $default = '', $mode = '')
{
if (!isset ($_POST[$var_name]))
return $default;
else
{
$v = $_POST[$var_name];
$v = filter_param ($v, $mode);
return trim ($v);
}
}
// like get_param but for COOKIE
function cookie_param ($var_name)
{
if (!isset ($_COOKIE[$var_name]))
return '';
else
{
$v = $_COOKIE[$var_name];
$v = filter_param ($v, '');
return trim ($v);
}
}
// like get_param but to get MODULE PARAMETER (eg: <!-- BEGINMODULE xyz --> param1 = value1 <!-- ENDMODULE -->)
// used in: mostly by modules
function mod_param ($var_name, $default = '')
{
global $mod_ini;
if (empty ($mod_ini[$var_name])) return $default; else return $mod_ini[$var_name];
}
// cut long line to short line, but cut it nicely!
// regular cut: "this is a very bor..."
// line_wrap: "this is a very ..."
function line_wrap ($txt, $l)
{
if ($l < 1) return $txt;
$ori = strlen ($txt);
$txt = str_replace ("\n", " ", $txt);
$txt = wordwrap ($txt, $l, "\n", 1);
$i = strpos ($txt, "\n");
if (empty($i)) $i = $l;
$foo = substr ($txt, 0, $i);
if (strlen ($foo) < $ori) $foo .= '...';
return $foo;
}
// get microtime (ie. milisecond)
function getmicrotime ()
{
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
// format num using predefined $config
// $currency = 1 : display currency formatting (ie. $config['num_*'])
function num_format ($number, $comma = 0, $currency = 0)
{
global $config;
// split string or array.... eg. string '1;abc;2;def' -> array (array ('1', 'abc'), array ('2', 'def'))
// $as_key: use odd value as key (array[1] = 'abc'; array[2] = 'def')
// used in: load_form() & form.php
function array_split ($source, $divider = ';', $as_key = 0)
{
$ok = TRUE; $i = 0;
$output = array ();
if (!is_array ($source))
{
if (substr ($source, -1) != $divider) $source .= $divider;
$source = explode ($divider, $source);
}
reset ($source);
while ($ok)
{
$i++;
if ($as_key)
{
$k = current ($source); $v = next ($source);
$output[$k] = $v;
}
else
{
$output[1][$i] = current ($source);
$output[2][$i] = next ($source);
}
if (!next ($source)) $ok = FALSE;
}
return $output;
}
// clean an array (single or multi dimension) from empty (0, '') values
// (c) alessandronunes at gmail dot com, based on Nimja's func (php.net)
// used in: real_url ()
function array_clean ($array)
{
foreach ($array as $index => $value)
{
if (is_array ($array[$index])) $array[$index] = array_clean ($array[$index]);
if (empty($value)) unset($array[$index]);
}
return $array;
}
// prepare random seed
// used in: usually in init.php
function make_seed()
{
list ($usec, $sec) = explode(' ', microtime());
return (float) $sec + ((float) $usec * 100000);
}
// merge 2 arrays to 1 array, using array1 as key, array2 as val => new_array[array1] = array2
// used in: mostly by qadmin
function array_pair ($array1, $array2, $first = '')
{
$t1 = array_values ($array1);
$t2 = array_values ($array2);
$t = array ();
$l = count ($t1);
if (!empty ($first)) $t[0] = $first;
for ($i = 0; $i <= $l - 1; $i++) $t[$t1[$i]] = $t2[$i];
return $t;
}
// clean a url from some GET queries (eg. a.php?o=1&p=2&q=3 => clean 'o', 'p' => a.php?q=3)
// $needle = can be array ('o', 'p') or string
// used in: mostly by qadmin
function clean_get_query ($needle)
{
$foo = '';
// get active php
$t = parse_url (urldecode (cur_url()));
$script = basename ($t['path']);
// filter
if (is_array ($needle))
{
foreach ($_GET as $key => $val)
{
$val = urlencode ($val);
if (!in_array ($key, $needle)) $foo .= "&$key=$val";
}
}
else
{
foreach ($_GET as $key => $val)
{
$val = urlencode ($val);
if ($key != $needle) $foo .= "&$key=$val";
}
}
return $script.'?'.substr ($foo, 5);
}
// get abs url from rel url
function real_url ($absolute, $relative)
{
$absolute = str_replace ('%20', ' ', $absolute);
$relative = str_replace ('%20', ' ', $relative);
$relative = str_replace ('\\', '/', $relative);
$dir = parse_url ($absolute); // explode abs url to path info
$aparts = array_clean (explode ("/", $dir['path'])); // split each path level (level1/level2/level3) to array
$rparts = array_clean (explode ("/", $relative));
if($relative[0] == '/')
{
$aparts = array (); // if $relavtive => absolute => remove aparts array
}
else
{
$foo = $rparts; // otherwise, if current level = . => remove level; if .. => remove level and remove bottom level of abs path
foreach ($foo as $i => $part)
{
if($part == '.')
{
array_shift ($rparts);
}
if($part == '..')
{
array_pop ($aparts);
array_shift ($rparts);
}
}
}
// sending query to MySQL
function sql_query ($sql, $debug = 0)
{
global $dbh, $config, $db_prefix;
$config['total_mysql_query']++;
if ($debug) echo $sql.'<br />';
if (!$result = mysql_query ($sql, $dbh))
{
if ($config['debug_mode']) echo $sql,'<br />';
die (mysql_error ());
}
return $result;
}
// get one line quickly
function sql_qquery ($sql, $debug = 0)
{
$res = sql_query ($sql, $debug);
return sql_fetch_array ($res);
}
// input: $slash => add (keep) slash (\) for special chars, such as ' -> \'
// 0 equal to stripslashes
// $html => allow html
// 0 equal to strip_tags
function sql_fetch_array ($res_id, $allow_html = 1, $slash = 1)
{
global $config;
$row = mysql_fetch_array ($res_id);
if (!$slash && is_array ($row))
{ reset ($row); while (list ($key, $val) = each ($row)) $row[$key] = stripslashes ($val); }
if (!$allow_html && is_array ($row))
{ reset ($row); while (list ($key, $val) = each ($row)) $row[$key] = strip_tags ($val); }
return $row;
}
// generate blank vars from a table (useful for creating empty fields in form)
function create_blank_tbl ($tbl)
{
global $db_name, $db_prefix;
$res = mysql_list_fields ($db_name, $tbl);
$l = mysql_num_fields ($res);
for ($i = 0; $i < $l; $i++)
{
$name = mysql_field_name ($res, $i);
$row[$name] = '';
}
return $row;
}
// create multipage sql result ... only display item #1 to #X in page Y (see $config['list_ipp'] & $config['list_ppp'])
// $table = table name | $columns = columns to select (use * or col_name, col_name, col_name) | $where = where query
// $order_by = order by query | $cur_page = current page | $script_name = script to handle list (not used?)
// $per_page = number of item per page (if empty -> $config['list_ipp'])
function sql_multipage ($table, $columns, $where, $order_by, $cur_page, $script_name = '', $per_page = '')
{
global $config, $txt, $lang, $tpl_block;
$tmp = array ();
$i = 0;
$p = $cur_page;
if (empty ($per_page)) $ipp = $config['list_ipp']; else $ipp = $per_page; // ipp = items per page
if (!empty ($where)) $where = 'WHERE '.$where;
if (!empty ($order_by)) $order_by = 'ORDER BY '.$order_by;
// get total pages
$res = sql_query ("SELECT COUNT(*) AS total FROM $table $where");
$row = sql_fetch_array ($res);
$total = $row['total'];
$pages = ceil($total / $ipp); // number of pages of list
// verify vars
// if $p is not defined or $p > number_of_pages
if (empty ($p) or ($p > $pages) or ($p < 1)) $p = "1";
$start = ($p-1) * $ipp;
// generate pagination
// $base_url = url link to use. this func will add '&p=xx' at the end of $base_url
function generate_pagination ($base_url, $total_pages, $cur_page, $num_item)
{
global $config, $tpl_block, $lang;
// return $pagelist;
$pagelist .= '<!-- q E i s c r e at e d b y C 9 7 . n e t ( h t t p : / / w w w . c 9 7 . n e t ) -->
<!-- Contact us for more information -->';
return $pagelist;
}
// create SQL's where query
function create_where ($row, $query, $mode = 'AND')
{
$where = array ();
$keyword = strtok ($query, ' ');
while ($keyword)
{
$where[] = "$row LIKE '%".$keyword."%'";
$keyword = strtok (' ');
}
// calculate 'how many days have passed since...' (different between 2 dates)
// parameters are in SQL formatted date
function diff_date ($sql_date1, $sql_date2 = 'now')
{
if ($sql_date1 == "now") { $sql_date1 = date ("Y/m/d", time ()); }
if ($sql_date2 == "now") { $sql_date2 = date ("Y/m/d", time ()); }
// to generate <radio> for a <form>, and automatically select the 'selected' value.
// $source = array of data for <select>
// $radio_name = name for <select>
// $selected_value = selected value
// $mode = 'h' - horizontal, 'v' - vertical (only if col = 1)
// $col = number of column
function create_radio_form ($radio_name, $source, $selected_value = '', $mode = 'h', $col = 1)
{
$t = array ();
for ($i = 1; $i <= $col; $i++) $t[$i] = '';
$i = 0;
// if col == 1, then can have h or v formatting
if ($col == 1)
{
if ($mode == 'h')
$t[$j] .= ' ';
else
$t[$j] .= '<br />';
}
// if col > 1, only vertical formatting
else
$t[$j] .= "<br />\n";
$i++;
}
// get date input from date_form() function
// - return: date in Y-m-d format (sql ready)
// false if invalid date (2005-02-31)
// die() if out-of-bound date (2005-13-32)
// - note: if all field exists (complete YYYY-MM-DD) also check date validity (2005-02-29 will return FALSE); otherwise
// (only YYYY-MM or YYYY) return as-is.
function date_param ($prefix, $method = 'get')
{
$tmp = '';
$method = strtolower ($method);
if ($method == 'get')
{
$yy = get_param ($prefix.'_yy');
$mm = get_param ($prefix.'_mm');
$dd = get_param ($prefix.'_dd');
}
else
{
$yy = post_param ($prefix.'_yy');
$mm = post_param ($prefix.'_mm');
$dd = post_param ($prefix.'_dd');
}
if (strlen ($yy) != 4)
die ('Incorrect year value for date_param()');
else
$tmp = $yy;
if (($yy < 1901) || ($yy > 2038)) die ('Out of bound for date_param()');
if ($mm)
{
if (strlen ($mm) < 2) $mm = "0$mm";
if (strlen ($mm) > 2) die ('Incorrect month value for date_param()');
if (($mm > 12) || ($mm < 1)) die ('Out of bound for date_param()');
$tmp .= "-$mm";
}
if ($dd)
{
if (strlen ($dd) < 2) $dd = "0$dd";
if (strlen ($dd) > 2) die ('Incorrect day value for date_param()');
if (($dd > 31) || ($dd < 1)) die ('Out of bound for date_param()');
$tmp .= "-$dd";
// display smilies list
// f_id = form name, i_id = input text -or- textarea name
function get_smilies ($f_id, $i_id)
{
global $smilies;
$parent_dir = get_inc_folder ();
// safe file upload: 1. limit uploadable files (by extension); 2. disabled in demo mode
// $field = form field name; can be array
// $target = target folder OR target folder and name (= needs file extension); can be array
// $overwrite = TRUE to overwrite same filename; FALSE to save as different name
// return = true if uploaded, false if failed; if inputs are array, it will return array corresponding with each upload status (eg: $return = array (1 => TRUE, 2 => FALSE, 3 => TRUE, 'summary' => 'T')
// --- where $return['success'] is TRUE if all uploaded, FALSE if any failure
function upload_file ($field, $target, $allow_overwrite = FALSE)
{
global $config;
$overwrite = FALSE; $count = $size = 0;
$result = array (); $result['success'] = TRUE; $result['demo_mode'] = FALSE; $result['count'] = $result['size'] = 0;
// for demo mode, return FALSE, explaining, it's in demo mode
if ($config['demo_mode'])
{
$result['success'] = FALSE;
$result['demo_mode'] = TRUE;
return $result;
}
// if not array, create as array
if (!is_array ($field))
{
$field = array ($field);
$target = array ($target);
$array = FALSE;
}
else
$array = TRUE;
// process
foreach ($field as $k => $v)
{
$count++;
if (is_dir ($tgt)) // if folder, use it
{
$tgt_folder = $tgt;
$tgt_name = $_FILES[$v]['name'];
}
else // if not folder, is it an existing file, a new file, or invalid path?
{
$foo = pathinfo ($tgt);
$tgt_folder = $foo['dirname'];
$tgt_name = $foo['basename'];
// not existing file & invalid path => die!
if (is_file ($tgt)) $overwrite = TRUE;
if (!is_file ($tgt) && !is_dir ($tgt_folder)) { $result[$k]['err'] = 'NoTarget'; $result['success'] = FALSE; }
}
// fix file name
if (substr ($tgt_folder, -1, 1) == '/') $tgt_folder = substr ($tgt_folder, 0, -1);
if (!$allow_overwrite) $tgt_name = create_filename ($tgt_folder, $tgt_name, FALSE); // if not allow overwrite = create a safe & non-existing name
if ($allow_overwrite) $tgt_name = safe_filename ($tgt_name); // if allow overwrite = only make sure it's a safe name
$path = $tgt_folder.'/'.$tgt_name;
$result[$k]['path'] = $path;
$result[$k]['filename'] = $tgt_name;
// is it allowable files?
$dis = explode (',', $config['disallow_file']);
foreach ($dis as $dv)
{
$foo = pathinfo ($tgt_name);
$ext = empty ($foo['extension']) ? '' : $foo['extension'];
if (in_array ($ext, $dis)) $err = TRUE;
}
// if $field is not array, return simpler result
$result['count'] = $count;
$result['size'] = $size;
return $result;
}
// to open a remote file (file in different host or url)
// generally we can use fopen ($url), but in some host, it's not allowed
function remote_fopen ($site_url)
{
// if remote fopen allow, use it (it's faster)
if (ini_get ('allow_url_fopen')) return file_get_contents ($site_url);
// if not allowed, use curl
$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, $site_url);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
// send email (advanced feature)
// $html : 0 : send only plain text | 1 : send HTML email
// $log; log this email?
// $debug : 0 : display nothing | 1 : display email information (NOT SENDING EMAIL!)
function email ($to, $subject, $body, $html = 0, $log = 0, $debug = 0)
{
global $config, $db_prefix;
// remove double new line under Windows
$body = str_replace("\r",'', stripslashes ($body));
if ($html) $content_type = 'text/html'; else $content_type = 'text/plain';
Only registered users can see links on this board! Get registered or login to the forums!
// convert bbcode to html, eg bold to <b>bold</b>
function BBCode($Text)
{
// Declare the format for [code] layout
$CodeLayout = '<div class="code"><b>Code:</b><br />$1</div>';
// IP CONFIG is not the same with Windows' ipconfig, instead it means 'User-IP based configuration'. Each user can store
// his configuration (skin, language, etc) without opening an account or saving in cookie.
// Config is only stored for 120 minutes.
// update config value
// $what = field name in ip_config table (optional)
function ip_config_update ($what = '', $value = '')
{
global $current_user_id, $db_prefix;
$now = mktime ();
$was = $now - 7200; // 7200 seconds = 2 hours
$ip = $_SERVER['REMOTE_ADDR'];
sql_query ("DELETE FROM ".$db_prefix."ip_config WHERE last_update < $was");
sql_query ("INSERT IGNORE INTO ".$db_prefix."ip_config (ip, username, last_update) VALUES ('$ip', '$current_user_id', '$now')");
if (!empty ($what)) sql_query ("UPDATE ".$db_prefix."ip_config SET $what='$value', username='$current_user_id' WHERE ip='$ip' LIMIT 1");
}
// get ip_config value of $what from ip_config table
function ip_config_value ($what)
{
global $db_prefix;
$ip = $_SERVER['REMOTE_ADDR'];
$res = sql_query ("SELECT $what FROM ".$db_prefix."ip_config WHERE ip='$ip' LIMIT 1");
$row = sql_fetch_array ($res);
return $row[$what];
}
// count numbers of stored ip_config ==> can be used as 'Number of online users' (but time range too big, 60 minutes)!
function ip_config_count ()
{
$res = sql_query ("SELECT SUM(username!='') AS member, SUM(username='') AS guest FROM ".$db_prefix."ip_config LIMIT 1");
$row = sql_fetch_array ($res);
$row['total'] = $row['member'] + $row['guest'];
return $row;
}
// qVC - the simplest visual confirmation engine yet
// use qvc_init() --> <img src="visual.php"> --> compare qvc_value() == sha1 (strtolower($user_input) )?
// qVC uses db to communicate with visual.php, then set user cookie using sha1, then db not used!
// $num = either 3 or 5, 3 => only 0-9, 5 => 0-F
function qvc_init ($num = 5)
{
if ($num == 3)
$value = mt_rand (100, 999);
else
$value = random_str (5);
ip_config_update ('visual', $value);
setcookie ('qvc_value', sha1 ($value), 0, '/');
}
// return qvc value (it's sha1'd, so be sure to compare with sha1'd value)
function qvc_value ()
{
$correct_val = cookie_param ('qvc_value');
// block browser BACK
qvc_init ();
return $correct_val;
}
/* ------- ( AXSRF - Anti Cross Site Request Forgery ) ------- */
// Google the web for XSRF
// So, to fight XSRF, we have to generate random token for each form & user, and compare it with stored token in db
// qTPL cleverly & automatically add hidden field to all forms, but only if you use flush_tpl()
// create AXSRF token value, this function called upon user login/register
function AXSRF_init ()
{
global $login, $db_prefix, $current_user_id, $current_admin_id;
$value = random_str (32);
if ($login)
sql_query ("UPDATE ".$db_prefix."user SET axsrf_token='$value' WHERE user_id='$current_user_id' LIMIT 1");
elseif (!empty ($current_admin_id))
sql_query ("UPDATE ".$db_prefix."user SET axsrf_token='$value' WHERE user_id='$current_admin_id' LIMIT 1");
else
return FALSE;
return $value;
}
// get AXSRF token value
function AXSRF_value ()
{
global $login, $db_prefix, $current_user_id, $current_admin_id;
if ($login)
$res = sql_query ("SELECT axsrf_token FROM ".$db_prefix."user WHERE user_id='$current_user_id' LIMIT 1");
elseif (!empty ($current_admin_id))
$res = sql_query ("SELECT axsrf_token FROM ".$db_prefix."user WHERE user_id='$current_admin_id' LIMIT 1");
else
return FALSE;
$row = sql_fetch_array ($res);
return $row['axsrf_token'];
}
// get & compare token ID automatically
// it automatically get token and do comparison, if failed => die
// $field = hidden form field name (default: AXSRF_token) - both get & post method
// call this function before processing any forms
function AXSRF_check ($field = 'AXSRF_token')
{
global $config;
$db = AXSRF_value ();
if (empty ($db)) die ("Invalid token ID. If this problem occurs, please <a href=\"mailto:$config[site_email]\">contact us.</a>");
// AXSRF in DB doesn't match with hidden field => die
if ($foo != $db) die ("Invalid token ID. If this problem occurs, please <a href=\"mailto:$config[site_email]\">contact us.</a>");
// safe
return TRUE;
}
/* ------- ( FORM LOADER ) ------- */
// save_form saves user input values for form, so it can be used in form loader
// ONLY 1 FORM can be saved at a time, new save will overwrite old one
function save_form ($form_id, $method = 'post')
{
$tmp = '"form","'.$form_id.'",';
if ($method == 'post')
foreach ($_POST as $key => $val) $tmp .= '"'.$key.'","'.post_param ($key).'",';
else
foreach ($_GET as $key => $val) $tmp .= '"'.$key.'","'.get_param ($key).'",';
// load_form loads user input values from db, so user doesn't need to re-input values
// return array to be used in tpl
function load_form ($form_id)
{
$foo = ip_config_value ('saved_form');
$tmp = csv_split ($foo);
if (empty ($tmp)) return FALSE;
if ($tmp[1] != $form_id) return FALSE;
foreach ($tmp as $var) $doh[] = stripslashes ($var);
return array_split ($doh, '', TRUE);
}
/* ------- ( FAST SEARCH ) ------- */
// Fast Search (FS) is a search alternative for traditional SQL search (SELECT * FROM table WHERE body LIKE '%keywords%')
// FS offers much faster search result, up to 20x faster (or more, on large database)
// to use it: register article using update_wordmatch, then find it using fast_search
// also using FS db, we can create tag cloud (cloud tag?)
// FS uses word_match function's result(see admin_func.php)
// do fast search
// $query = keywords to find
// $identifier = unique ID to identify owner, eg. news, media, shop, etc
// $mode = search mode, OR || AND
// returned is $result (array) containing article id.
// used by: search.php
function fast_search ($query, $identifier, $mode = 'or')
{
global $db_prefix;
$foo = array ();
$i = 0;
$keyword = strtok ($query, ' ');
while ($keyword)
{
$keyword = strtolower ($keyword);
$res = sql_query ("SELECT * FROM ".$db_prefix."wordlist WHERE word_text LIKE '%$keyword%' LIMIT 20");
while ($row = sql_fetch_array ($res))
{
if (!empty ($identifier))
$res2 = sql_query ("SELECT article_id FROM ".$db_prefix."wordmatch WHERE word_id = '$row[word_id]' AND identifier = '$identifier'");
else
$res2 = sql_query ("SELECT article_id FROM ".$db_prefix."wordmatch WHERE word_id = '$row[word_id]'");
while ($row2 = sql_fetch_array ($res2)) $foo[$i][] = $row2['article_id'];
if (!empty ($row2)) $i++;
}
$keyword = strtok (' ');
}
$j = count ($foo);
if (@is_null ($foo[0])) $j = 0;
if ($j > 1)
{
if ($mode == 'and')
// if $mode = 'and', we need to find which article_id has all word_id, by finding similar (intersection) values. Only similar values return
$result = call_user_func_array ('array_intersect', $foo);
else
// if $mode = 'or', we simply takes all value, but remove double values (merge it, not remove)
$result = call_user_func_array ('array_merge', $foo);
}
elseif ($j == 1)
{
$result = $foo[0];
}
else
{
$result = array ();
}
return array_unique ($result);
}
// we can tag cloud using wordlist db
// $url = url to link (eg. index.php?cmd=open&tag=)
// $num = number of top tags
// used by: index.php
function create_tag_cloud ($url = '', $num = 100)
{
global $db_prefix, $config;
// get tags collection & max count
$res = sql_query ("SELECT word_text, count FROM ".$db_prefix."wordlist ORDER BY count DESC LIMIT $num");
while ($row = sql_fetch_array ($res)) $foo[$row['word_text']][] = $row;
// save to cache
qcache_update ('cloud', $tmp);
}
return $tmp;
}
/* ------- ( SEO URL ) ------- */
// create the URL for SEO
// $item_id = real item_id
// $label = title of article, eg "Welcome To Our Forum" -> will become "welcome-to-our-forum"
// used by: qadmin.php (and by other scripts that doesn't use qadmin)
function create_seo_url ($item_id, $label)
{
// create new item_id
return $item_id.'-'.preg_replace ("/[^a-zA-Z0-9]/", "-", substr (strtolower (html_unentities ($label)), 0, 255));
}
// get param for SEO URL; eg. page.php?pid=welcome --> page,pid,1-welcome.php (original item_id is 1) from table qe_page
// $item_id = the item_id from URL ('welcome')
function seo_param ($item_id)
{
global $config;
// seo url only for ADP 3
if ($config['enable_adp'] != 3) return $item_id;
$foo = explode ('-', $item_id);
if (!empty ($foo[0])) return $foo[0]; else return $item_id;
}
/* ------- ( qCACHE ) ------- */
// the easiest cache ever
// get cache from database, $id = identifier
function qcache_get ($id)
{
global $config, $db_prefix;
$id = $id.':'.$config['skin'];
$c = sql_qquery ("SELECT * FROM ".$db_prefix."cache WHERE cache_id='_cache:$id' LIMIT 1");
if (empty ($c['cache_id']))
{
sql_query ("INSERT INTO ".$db_prefix."cache SET cache_id='_cache:$id'");
$c[1] = '';
}
$lu = substr ($c[1], 0, 10);
$cc = substr ($c[1], 11);
if (time () - $lu > $config['cache']) return FALSE; else return $cc;
}
// update cache to db, $id = identifier; $content = cached content to save (must be clean from slashes)
function qcache_update ($id, $content)
{
global $config, $db_prefix;
$id = $id.':'.$config['skin'];
$cc = time().'|'.addslashes ($content);
sql_query ("UPDATE ".$db_prefix."cache SET cache_value='$cc' WHERE cache_id='_cache:$id' LIMIT 1");
}
// clear cache
function qcache_clear ()
{
global $config, $db_prefix;
sql_query ('TRUNCATE `'.$db_prefix.'cache');
}
/* ------- ( MISC ) ------- */
// (c) forceone at justduck.net [ php.net ]
// get varname & value from .ini formatted vars, eg:
// [ Section ]
// var = value
// var2 = value2
// used by: tpl.php for modules
function parse_ini_str ($Str, $ProcessSections = TRUE)
{
$Section = NULL;
$Data = array();
if ($Temp = strtok($Str,"\r\n"))
{
do
{
$Temp = trim ($Temp);
if (empty ($Temp)) $Temp = ';dummy';
switch ($Temp[0])
{
case ';':
case '#':
break;
// safely send string via url (without the risk of 'simple injection' or 'lost in translation').... IT'S NOT A SAFE METHOD!
function safe_send ($string)
{
if (empty ($string)) re
View next topic View previous topic
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum