// pick a random row from tablename and return the img column // FIXME this is a duplicate of the function below it... // about 4 tables in global are the same thing with different schema function rid($tablename,$usetext=0) { if ($usetext) { $fields = "img,link"; } else { $fields = "img"; } $ret = mysql_global_call("select $fields from `%s` join (select floor(1+rand()*(select max(id) from `%s`)) as id) as randid using (id)", $tablename, $tablename); if ($usetext) { return mysql_fetch_row($ret); } else { return mysql_result($ret,0,0); } } //file format: //url (escaped for putting in a href) //desc (not escaped) //repeat function text_link_ad($file) { global $text_ads; global $text_ads_n; if (!isset($text_ads[$file])) { $ads = @file($file, FILE_IGNORE_NEW_LINES); shuffle($ads); $text_ads[$file] = $ads; $num_ads = count($ads); $n = 0; $text_ads_n[$file] = $n; } else { $ads = $text_ads[$file]; $n = $text_ads_n[$file]; $num_ads = count($ads); } if (!$ads) return ""; list($url,$desc) = explode("<>",$ads[$n]); if (!$url) return ""; $text = "".htmlspecialchars($desc).""; $n++; if ($n == $num_ads) $n = 0; $text_ads_n[$file] = $n; return $text; } //duplicate of rid.php //dir - absolute path from web root to dir inc. trailing slash //urlroot - what to append the name to to get the url function rid_in_directory($dir,$urlroot) { global $document_root; $realdir = "/www/global/imgtop/dontblockthis/".$dir; $ft = "$realdir/files.txt"; $names = file_array_cached($ft); if (!$names) { $arr = scandir($realdir); foreach ($arr as $fi) { if (preg_match("/\.(jpg|gif|png)$/", $fi)) { $names[] = $fi; } } file_put_contents($ft, join($names, "\n")); } return $urlroot.$names[rand(0, count($names)-1)]; } // Takes a dir and a filename and uses file() to parse it // then returns a random value. function rand_from_flatfile( $dir, $filename ) { $file = $dir . $filename; $names = file_array_cached( $file ); return $names[ rand( 0, count($names)-1 ) ]; } function form_ads(&$dat) { $error = false; // unused, errors have ads too $dat .= "