/** * Actually Serving an image to the browser * */ function ServeImg($filename) { $img = null; if (file_exists("data/img/" . base64_encode($filename))) { $img = file_get_contents("data/img/" . base64_encode($filename)); header('Content-Type: image/jpeg'); echo $img; return; } // download from one choosen hook and cache $cnt = 0; $imgHooks = OpenBHConf::get('imghooks'); foreach ($imgHooks as $key => $val) { $cnt += $val; } $rnd = rand(0, $cnt); $cnt = 0; $i = 0; $s = array('-', '%20'); $r = array(' ', ' '); $kw = str_replace($s, $r, substr($filename, 0, strripos($filename, '.'))); foreach (array_keys($imgHooks) as $imghook) { $i++; $cnt += $imgHooks[$imghook]; if ($i == count($imgHooks)) { $ih = new $imghook(); $img = $ih->GetImage($kw); break; } if ($rnd < $cnt && $rnd > $cnt - $imgHooks[$imghook]) { $ih = new $imghook(); $img = $ih->GetImage($kw); break; } } if ($img != null) { file_put_contents("data/img/" . base64_encode($filename), $img); } else { $img = file_get_contents("config/nopic.png"); } // serve new image header('Content-Type: image/jpeg'); echo $img; return; }
// Load all content hooks foreach (glob("hooks/*.php") as $filename) { include $filename; } // Load dynamic adserving hooks foreach (glob("adhooks/*.php") as $filename) { include $filename; } // setting us up the page $page = GetPage($settings); switch ($page->responsecode) { case 404: header("HTTP/1.0 404 Not Found"); echo $page->content; break; case 302: case 301: header("Location: {$page->redirlink}"); break; case 200: if ($page->dontskin == 1) { echo $page->content; break; } echo utf8_encode($page->Skin()); break; } /* log ... */ if (OpenBHConf::get('loghits') == true) { loghit($page, $settings); }
function TemplateRewrite($filename) { $p = str_replace(str_replace('index.php', '', $_SERVER['SCRIPT_NAME']), '', $_SERVER['REQUEST_URI']); if ($p == '') { return; } $fp = sprintf('templates/%s/%s', OpenBHConf::get('template'), $p); if (file_exists($fp)) { if (stripos($fp, '.css') !== false) { header("Content-type: text/css"); } echo readfile($fp); exit; } }
function __construct($adArray) { $this->AdArray = $adArray; $this->template = file_get_contents(sprintf('templates/%s/StaticAd.html', OpenBHConf::get('template'))); }
public function ParseFeed($kw) { /* * this needs to be configured inside the config * column to var mapping * separator * * this needs to be an associative array like this: * the key will be used as token so you can map anything you like ;) * * array('prodname'=>12,'keyword'=>2,'url',3); */ $row = 1; $result = null; if (($handle = fopen("config/kw/open.txt", "r")) !== FALSE) { while (!feof($handle)) { if (strnatcmp(phpversion(), '5.3.0') >= 0) { $data = fgetcsv($handle, 10000, OpenBHConf::get('csv_delimiter'), OpenBHConf::get('csv_enclosure'), OpenBHConf::get('csv_escape')); } else { $data = fgetcsv($handle, 10000, OpenBHConf::get('csv_delimiter'), OpenBHConf::get('csv_enclosure')); } if (count($data) == 1) { // we assume there is only the keyword since we have only one column in the feed if (str_replace('-', ' ', strtolower($data[0])) != strtolower($kw)) { continue; } } else { if (str_replace('-', ' ', strtolower($data[$this->fmap['keyword']])) != strtolower($kw)) { continue; } } $result = $data; break; // $data match } fclose($handle); } // map col<>map $linemap = null; if (count($result) == 1) { $linemap['keyword'] = $result; } else { if (is_array($result)) { $lineMap = array(); foreach ($this->fmap as $k => $v) { if (count($data) < $v) { continue; } $lineMap[$k] = $data[$v]; } } } return $lineMap; }
function GetPage($settings) { $page = null; switch ($settings['filename']) { case 'robots.txt': // robots $page = new Page($settings['keyword'], true); $page->content = "Sitemap: sitemap.xml"; break; case 'sitemap.xml': $loc = ''; $page = new Page($settings['keyword'], true); foreach (glob('data/content/*', GLOB_NOSORT) as $filename) { // ... $p = Page::GetCache(base64_decode(str_replace('data/content/', '', $filename))); $loc .= sprintf('<loc><url>%s%s</url></loc>', OpenBHConf::get('domain'), $p->filename); } $page->content = sprintf(' <?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"> %s </urlset>', $loc); break; case 'rss': $rss = ''; $time = array(); $page = new Page($settings['keyword'], true); foreach (glob('data/content/*') as $filename) { $time[$filename] = filemtime($filename); } if (count($time) == 0) { break; } arsort($time); $newest = array_slice($time, 0, 10); foreach ($newest as $key => $val) { $p = Page::GetCache(base64_decode(str_replace('data/content/', '', $key))); $rss .= sprintf('<item> <title>%s</title> <link>%s%s</link> <description>%s</description> <author>admin</author> <pubDate>%s</pubDate> </item>', $p->keyword, OpenBHConf::get('domain'), $p->filename, $p->h1, date("F d Y H:i:s.", $val)); } $page->content = sprintf(' <?xml version="1.0" encoding="ISO-8859-1"?> <rss version="2.0"> <channel> <title>%s</title> <description>%s</description> <link>%s</link> <lastBuildDate></lastBuildDate> <generator>RSS</generator> %s </channel> </rss>', '', '', OpenBHConf::get('domain'), $rss); break; case 'index': // homepage - bloglike $pages = array(); $df = new DataFeed(); foreach ($df->ReturnFirstKeywords(OpenBHConf::get('startpage')) as $kw) { // check if we already cached this page otherwise open dummy for filename $page = null; $page = Page::GetCache($kw); if ($page == null) { $page = new Page($kw, false, null, true); // create empty page .. will generate filename } array_push($pages, $page); } // first hit ? if (empty($pages[0]->content)) { $datafeed = new DataFeed(); $pages[0]->advertisment = $datafeed->ParseFeed($pages[0]->keyword); $pages[0]->Init(); // this page isnt built yet because its only a skeleton holding the fake filename for navigation use } $pages[0]->SkinIndex($pages); $page = $pages[0]; break; default: $page = null; // is this page already built/cached ? if (!empty($settings['keyword'])) { $page = Page::GetCache($settings['keyword']); } else { // no keyword no page $page = new Page('', true); $page->responsecode = 404; $page->content = OpenBHConf::get('404'); break; } if ($page == null) { // check datafeed $datafeed = new DataFeed(); $feedData = $datafeed->ParseFeed($settings['keyword']); if (!is_array($feedData)) { $page = new Page('', true); $page->responsecode = 404; $page->content = OpenBHConf::get('404'); break; } // build page $page = new Page($settings['keyword'], false, $feedData); /* we could do cloaking here this way ;) - this only works for datafeeds including an url */ if (array_key_exists('url', $feedData) && OpenBHConf::get('cloak') == true) { $cloak = new Cloaker($_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_REFERER']); if ($cloak->IsBot() == false) { $page->responsecode = 301; $page->redirlink = $feedData['url']; } } } // only a skeleton ? if (empty($page->content)) { $datafeed = new DataFeed(); $page->advertisment = $datafeed->ParseFeed($settings['keyword']); $page->Init(); // this page isnt built yet because its only a skeleton holding the fake filename for navigation use } break; } return $page; }
/** * extlibs/TokenFuncs.php * This functions map onto ((functionName)) in your site.html Template * Put interesting stuff here * * Notice: The output of these functions will NOT be cached * and will be generated fresh for each hit * * @author Neek */ function domain() { return OpenBHConf::get('domain'); }
function Skin() { /* basic elements */ $this->template = str_ireplace("[[content]]", $this->content, $this->template); $this->template = str_ireplace("[[title]]", $this->title, $this->template); $this->template = str_ireplace("[[h1]]", $this->h1, $this->template); $this->template = str_ireplace("[[h2]]", $this->h2, $this->template); preg_match("/\\[\\[nav\\]\\](.+?)\\[\\[\\/nav\\]\\]/is", $this->template, $navmatch); $nav = ''; foreach ($this->navlinks as $kwf) { $nav .= str_replace("[[nav_url]]", $kwf['filename'], str_replace("[[keyword]]", $kwf['kw'], $navmatch[1])); } $this->template = preg_replace("/\\[\\[nav\\]\\](.+?)\\[\\[\\/nav\\]\\]/is", $nav, $this->template); /* $this->template = str_ireplace("[[nav_lastkw]]",sprintf('<a href="%s">%s</a>',$this->last,$this->last_kw),$this->template); $this->template = str_ireplace("[[nav_nextkw]]",sprintf('<a href="%s">%s</a>',$this->next,$this->next_kw),$this->template); */ $this->template = str_ireplace("[[nav_last]]", $this->last, $this->template); $this->template = str_ireplace("[[nav_next]]", $this->next, $this->template); $this->template = str_ireplace("[[nav_lastkw]]", $this->last_kw, $this->template); $this->template = str_ireplace("[[nav_nextkw]]", $this->next_kw, $this->template); $this->template = str_ireplace("[[keyword]]", $this->keyword, $this->template); /* ads */ if (stripos($this->template, "[[staticad(js)]]") !== FALSE || stripos($this->template, "[[staticad(html)]]") !== FALSE) { $ad = new StaticAdvertising($this->advertisment); $this->template = str_ireplace("[[staticad(js)]]", $ad->ServeAdJS(), $this->template); $this->template = str_ireplace("[[staticad(html)]]", $ad->ServeAdHTML(), $this->template); } if (stripos($this->template, "[[dynamicad(js)#") !== FALSE || stripos($this->template, "[[dynamicad(html)]]") !== FALSE) { $ad = new DynamicAdvertising($this->keyword, OpenBHConf::get('dynadhook')); $this->template = str_ireplace("[[dynamicad(js)]]", $ad->ServeAdJS()); $this->template = str_ireplace("[[dynamicad(html)]]", $ad->ServeAdHTML()); } /* on the fly function tokens.. {{funcName}} */ $this->template = preg_replace_callback("/{{(.+?)}}/", create_function('$matches', '$expl = explode(",",$matches[1]); if(function_exists($expl[0])) { if(isset($expl[1])) { return $expl[0]($expl[1]); } else { return $expl[0](); } } return "";'), $this->template); /* cached function tokens ((funcName)) */ preg_match_all('/\\(\\((.+?)\\)\\)/is', $this->template, $cachedFuncs); foreach ($cachedFuncs[1] as $cachedFunc) { if (!array_key_exists($cachedFunc, $this->cachedFuncStorage)) { if (function_exists($cachedFunc)) { $this->cachedFuncStorage[$cachedFunc] = $cachedFunc($this); } else { $this->cachedFuncStorage[$cachedFunc] = ''; } } $this->template = str_ireplace(sprintf('((%s))', $cachedFunc), $this->cachedFuncStorage[$cachedFunc], $this->template); } /* replace the rest */ $this->template = preg_replace('/\\[\\[.+?\\]\\]/', '', $this->template); $this->template = preg_replace('/\\[\\[\\/.+?\\]\\]/', '', $this->template); return $this->template; }