0){
for ($i=0; $i<$num; ++$i){
$data[$i]=mysql_fetch_array($result, MYSQL_ASSOC);
}
}
if ($mode=="1" and $result){
//set result to last inserted id///////////
$data=mysql_insert_id($link);
}
if ($mode=="2" and $result){
//set result to plain query return///////////
$data=$result;
}
return $data;
}
#############################################################
function db_connect(){
$link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db(DB_NAME, $link);
if (!$db_selected) {
die ('Can\'t select db: ' . mysql_error());
}
return $link;
}
#############################################################
function array2rss($array, $title, $description){
//make sure the results array keys line up with our script
$array=convert_array($array);
//$description = preg_replace("/[\r\n]/"," ",$description);
$rss= "".$title."
".SITE.$_SERVER['REQUEST_URI']."
".$description."eng-us".date("r")."".date("r")."".SITE."".MANAGING_EDITOR."".WEBMASTER."";
foreach ($array as $val){
if ($val['id']!=""){
$rss.= "
".$val['title']."
".$val['path']."
".$val['description']."".date("r", strtotime($val['cdate']))."".$val['path']."";
}
}
$rss.= "
";
return $rss;
}
#############################################################
function convert_array($array){
// ['title'] ['path'] ['description'] ['cdate']
//change array keys to match these
foreach($array as $key =>$val){
//$array[$key]['path']="http://www.majon.com/articles/".urlencode(str_replace(" ", "_", $array[$key]['Name']))."/".urlencode(str_replace(" ", "_", $array[$key]['PrimaryKeyword']))."_".$array[$key]['ID'].".html";
$array[$key]['path']="http://www.majon.com/advanced/pressreleases/" . $array[$key]['dirname'] . "/" . $array[$key]['filename'];
$array[$key]['cdate']=$array[$key]['date_created'];
$array[$key]['title']=clean_text($array[$key]['subject']);
//$array[$key]['description']=clean_text($array[$key]['body']);
//$array[$key]['description']= $array[$key]['body'];
$array[$key]['description']= "Press Release regarding: " . $array[$key]['subject'];
$array[$key]['description']=preg_replace("/([^a-z0-9!:;\\/+@%()?,\.\-_\'\"\r\n])/i", " ", $array[$key]['description']);
/*
$array[$key]['description']= $array[$key]['body'];
$array[$key]['description']=makeClickableLinks($array[$key]['description']);
//$array[$key]['description'] = preg_replace("/[\n\r<>+-]/","",$array[$key]['description']);
*/
$array[$key]['description'] = preg_replace("/[\n]/"," ",$array[$key]['description']);
$array[$key]['description'] = preg_replace("/[\r]/","",$array[$key]['description']);
$array[$key]['description']= "";
}
return $array;
}
#############################################################
function throw_404(){
header("HTTP/1.0 404 Not Found");
die("Feed not Found");
}
#############################################################
function clean_text($text){
//clean up text
//$text = strip_tags($text);
$text=preg_replace("/([^a-z0-9!?,\.\-_\'\"])/i", " ", $text);
return $text;
}
#############################################################
function cache($cachefile, $days){
//directory is always cache!
if (file_exists("cache/$cachefile")){
$mtime=filemtime("cache/$cachefile")." ";
//calculate how many days old the file is.
$age=((time()-filemtime("cache/$cachefile"))/60/60/24);
if ($age>$days){
//cache is too old
return 0;
}else{
//load and return cache
$data=@file_get_contents("cache/$cachefile");
if ($data=="") return false;
return $data;
}
}
return false;
}
#############################################################
function writecache($rss, $cachefile){
$handle=fopen("cache/$cachefile", "w");
fwrite($handle, $rss);
fclose($handle);
}
#############################################################
function makeClickableLinks($text)
{
# this functions deserves credit to the fine folks at phpbb.com
$text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text);
// pad it with a space so we can match things at the start of the 1st line.
$ret = ' ' . $text;
// matches an "xxxx://yyyy" URL at the start of a line, or after a space.
// xxxx can only be alpha characters.
// yyyy is anything up to the first space, newline, comma, double quote or <
$ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1\\2", $ret);
// matches a "www|ftp.xxxx.yyyy[/zzzz]" kinda lazy URL thing
// Must contain at least 2 dots. xxxx contains either alphanum, or "-"
// zzzz is optional.. will contain everything up to the first space, newline,
// comma, double quote or <.
$ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1\\2",
$ret);
// matches an email@domain type address at the start of a line, or after a space.
// Note: Only the followed chars are valid; alphanums, "-", "_" and or ".".
$ret = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1\\2@\\3",
$ret);
// Remove our padding..
$ret = substr($ret, 1);
return $ret;
}
?>