"", "description"=>"", "keywords"=>""); function __construct(){ global $nodisplay; ini_set("zlib.output_compression", 4096); ob_start(); gc_enable(); require_once(DOCROOT.'system/classes/db.php'); require_once(DOCROOT.'system/classes/admin.php'); require_once(DOCROOT.'system/classes/member.php'); require_once(DOCROOT.'system/classes/layouts.php'); require_once(DOCROOT.'system/classes/filebrowser.php'); require_once(DOCROOT.'system/classes/email.php'); if (MODE == "test"){ require_once(DOCROOT.'system/classes/FirePHPCore/FirePHP.class.php'); $this->fp = FirePHP::getInstance(true); } if (!empty($_GET['fbclid'])) { $_SESSION['fbclid'] = [ "fbclid"=>$_GET['fbclid'], "created"=>time() ]; } if (!empty($_GET['fbclid']) && $this->checkCookies("social")) { $cookie = json_encode(["fbclid"=>$_GET['fbclid'], "created"=>time()]) setcookie("dm-fbclid", $cookie, time() + (86400 * 90), '/'); $_COOKIE['dm-fbclid'] = $cookie; } if ($_COOKIE['dm-fbclid']) { $_SESSION['fbclid'] = json_decode($_COOKIE['dm-fbclid'], true); } $this->db = new db(); $this->layout = new layout($this); $this->files = new fileBrowser($this); $this->admin = new admin($this); $this->member = new member($this); $this->checkMobile(); $this->getOptions(); $this->getThemeConfig(); $this->getLoc(); if((!$_SERVER['HTTP_X_REQUESTED_WITH'] || strpos($_SERVER['HTTP_X_REQUESTED_WITH'], "facebook") !== false) && !$nodisplay){ $this->getSEO(); $this->getPlugins(); $this->determineRoute(); } } function __destruct(){ unset($this->db,$this->layout,$this->admin,$this->options,$this->content,$this->notifications,$this->specialPlaces,$this->plugins,$this->uri,$this->plugin,$this->seo,$this->files); if (MODE == "test"){ $this->fp->log("Peak Memory Usage: ". memory_get_peak_usage()); $this->fp->log("Memory Usage: ". memory_get_usage()); unset($this->fp); } ob_end_flush(); } private function getOptions(){ $this->db->prepare("select * from sys_options"); $this->db->run(); $options = array(); while($o = $this->db->fetch()){ $options[$o->optionTitle] = $o->optionValue; } $this->options = (object)$options; $this->db->free(); } public function addOption($title, $value){ $this->db->prepare("insert into sys_options (optionTitle, optionValue) VALUES ('?', '?')", array(array($title, 's'), array($value, 's'))); $this->db->run(); $this->getOptions(); } private function getLoc(){ $uri = preg_replace('/'.str_replace("/", "\/", ROOT).'/', '', explode("?", $_SERVER['REQUEST_URI'])[0], 1); $uri = explode("/", $uri); $this->uri = $uri; $this->host = str_replace("www.", "", $_SERVER['HTTP_HOST']); if (FORCESSL){ if(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == ""){ $redirect = "https://www.".$this->options->domain.$_SERVER['REQUEST_URI']; header("HTTP/1.1 301 Moved Permanently"); header("Location: $redirect"); } } unset($uri); } private function determineRoute(){ if (in_array($this->uri[0], $this->specialPlaces) === true){ $this->getSpecial(); } else { $this->checkPlugins(); } } public function getSpecial(){ if ($this->uri[0] == "admin"){ if ($this->admin->user){ require_once(DOCROOT.'system/classes/filebrowser.php'); if (!$this->uri[1]){ $this->uri[1] = "index"; } if(file_exists(DOCROOT.'system/admin/'.urlencode($this->uri[1]).'.php') && $this->uri[1]){ include DOCROOT.'system/admin/head.php'; include DOCROOT.'system/admin/'.urlencode($this->uri[1]).'.php'; include DOCROOT.'system/admin/foot.php'; } else { } } else { include DOCROOT.'system/admin/head.php'; include DOCROOT.'system/admin/login.php'; include DOCROOT.'system/admin/foot.php'; } } if ($this->uri[0] == "member"){ $this->memberSpecial = true; $this->checkPlugins(); } } public function checkPlugins($nocont = false){ foreach($this->plugins as $p){ if ($this->plugin){ break; } if(in_array($this->uri[0], $p->places) === true){ $this->plugin = $p; } else { foreach($p->places as $pl){ if ($pl == "%any%"){ $this->plugin = $p; } } } } if ($this->plugin && !$nocont){ $this->prepareTheme(); if (file_exists(DOCROOT.'plugins/'.$this->plugin->pluginDirectory.'/frontend.php')){ include_once(DOCROOT.'plugins/'.$this->plugin->pluginDirectory.'/frontend.php'); } $this->finalTagReplace(); $this->outputContent(); } } public function getPlugins(){ $this->db->prepare("select * from sys_plugins order by pluginId desc"); $this->db->run(); while($p = $this->db->fetch()){ if (file_exists(DOCROOT.'plugins/'.$p->pluginDirectory.'/config.php')){ $places = array(); $menuitems = array(); $quicklinks = array(); include DOCROOT.'plugins/'.$p->pluginDirectory.'/config.php'; $p->places = $places; $p->menuitems = $menuitems; $this->plugins[] = $p; if ($quicklinks){ foreach($quicklinks as $q){ $this->quickLinks[] = $q; } } } } $this->db->free(); } public function prepareTheme(){ $this->content = ''; if (is_dir(DOCROOT.'site/themes/'.strtolower(str_replace(" ", "_", $this->options->theme)).'/')){ if (file_exists(DOCROOT.'site/themes/'.$this->options->theme.'/header.html')){ $this->content .= file_get_contents(DOCROOT.'site/themes/'.$this->options->theme.'/header.html'); } if (file_exists(DOCROOT.'site/themes/'.$this->options->theme.'/main.html')){ $this->content .= file_get_contents(DOCROOT.'site/themes/'.$this->options->theme.'/main.html'); } if (file_exists(DOCROOT.'site/themes/'.$this->options->theme.'/footer.html')){ $this->content .= file_get_contents(DOCROOT.'site/themes/'.$this->options->theme.'/footer.html'); } } else { throw new Exception('Error locating theme directory.'); } } public function finalTagReplace(){ $this->content = str_replace("~~siteTitle~~", htmlentities($this->seo['title']), $this->content); $this->content = str_replace("~~siteDescription~~", htmlentities($this->seo['description']), $this->content); $this->content = str_replace("~~siteKeywords~~", htmlentities($this->seo['keywords']), $this->content); $this->loadMenus(); $this->content = str_replace("~~siteScripts~~", "", $this->content); $this->content = str_replace("~~siteCss~~", "", $this->content); $this->content = str_replace(array("~~root~~", "~~home~~"), ROOT, $this->content); $this->content = str_replace("~~themeDir~~", ROOT.'site/themes/'.$this->options->theme.'/', $this->content); $this->content = str_replace("~~uploadDir~~", ROOT.'site/uploads/', $this->content); $this->content = str_replace("~~assetDir~~", ROOT.'system/assets/', $this->content); $this->content = str_replace("~~pageContent~~", '', $this->content); $this->content = str_replace("~~adminPanel~~", '', $this->content); if (!empty($this->seo['OG:image'])){ $this->content = str_replace("", " ", $this->content); } do { $bl = $this->layout->getBlock($this->content, "~~startIsMember~~", "~~endIsMember~~"); if (!$bl) break; if ($this->member->user) $this->content = substr_replace($this->content, $bl->layout, $bl->start, $bl->finish); else $this->content = substr_replace($this->content, '', $bl->start, $bl->finish); } while(1); do { $bl = $this->layout->getBlock($this->content, "~~startNotMember~~", "~~endNotMember~~"); if (!$bl) break; if (!$this->member->user) $this->content = substr_replace($this->content, $bl->layout, $bl->start, $bl->finish); else $this->content = substr_replace($this->content, '', $bl->start, $bl->finish); } while(1); do { $bl = $this->layout->getBlock($this->content, "~~startCookies~~", "~~endCookies~~"); if (!$bl) break; if ($_COOKIE['cookie-preferences']) $this->content = substr_replace($this->content, $bl->layout, $bl->start, $bl->finish); else $this->content = substr_replace($this->content, '', $bl->start, $bl->finish); } while(1); do { $bl = $this->layout->getBlock($this->content, "~~startNoCookies~~", "~~endNoCookies~~"); if (!$bl) break; if (!$_COOKIE['cookie-preferences']) $this->content = substr_replace($this->content, $bl->layout, $bl->start, $bl->finish); else $this->content = substr_replace($this->content, '', $bl->start, $bl->finish); } while(1); $cookieTypes = ["analytics", "social"]; foreach($cookieTypes as $type){ do { $bl = $this->layout->getBlock($this->content, "~~start".ucwords($type)."Cookies~~", "~~end".ucwords($type)."Cookies~~"); if (!$bl) break; if ($this->checkCookies($type)) $this->content = substr_replace($this->content, $bl->layout, $bl->start, $bl->finish); else $this->content = substr_replace($this->content, '', $bl->start, $bl->finish); } while(1); do { $bl = $this->layout->getBlock($this->content, "~~startNo".ucwords($type)."Cookies~~", "~~endNo".ucwords($type)."Cookies~~"); if (!$bl) break; if (!$this->checkCookies($type)) $this->content = substr_replace($this->content, $bl->layout, $bl->start, $bl->finish); else $this->content = substr_replace($this->content, '', $bl->start, $bl->finish); } while(1); } $this->content = str_replace("~~ogTitle~~", $this->seo['title'], $this->content); $this->content = str_replace("~~ogSiteName~~", $this->options->title, $this->content); $this->content = str_replace("~~ogUrl~~", $this->canonical, $this->content); } public function outputContent(){ echo $this->content; } public function getPluginMenus(){ $plugins = array(); foreach($this->plugins as $p){ $adminmenu = ''; include DOCROOT.'plugins/'.$p->pluginDirectory.'/config.php'; if ($adminmenu){ $plugins[$p->pluginId] = array("plugin"=>$p->pluginDirectory, "adminmenu"=>$adminmenu); } } return $plugins; } public function getNotifications(){ } public function getThemeConfig($forceTheme=false){ if ($forceTheme){ $this->options->theme = $forceTheme; } if ($this->options->theme == "" || !is_dir(DOCROOT.'site/themes/'.$this->options->theme.'/') || !file_exists(DOCROOT.'site/themes/'.$this->options->theme.'/admin/config.php')){ return false; } $thisTheme = $this->options->theme; require_once(DOCROOT.'site/themes/'.$this->options->theme.'/admin/config.php'); if (!$theme){ return false; } $this->themeConfig = new stdClass(); $this->themeConfig->theme = $theme; $this->themeConfig->menus = $menus; $this->themeConfig->extras = $extras; $this->themeConfig->js = $jsfiles["normal"]; $this->themeConfig->css = $cssfiles["normal"]; if($this->mobile){ $this->options->theme .= "/mobile"; $this->themeConfig->js = $jsfiles["mobile"]; $this->themeConfig->css = $cssfiles["mobile"]; } } public function loadMenus($menus=false){ if (!$menus){ $menus = json_decode($this->options->menus, true); } while(1==1){ $layout = $this->layout->getBlock($this->content, "~~startMenu~~", "~~endMenu~~"); if ($layout){ $menudetails = $this->layout->getBlock($layout->layout, "{", "}"); if (!$menudetails){ $this->content = substr_replace($this->content, '', $layout->start, $layout->finish); continue; } $menu = $menus[$menudetails->layout]; if (!is_array($menu)){ $this->content = substr_replace($this->content, '', $layout->start, $layout->finish); continue; } $items = array(); $item = $menu[0]; $i = 0; while($item){ $item=$this->checkMenuSpecial($item); if (is_array($item['additional'])){ $newmenu = array(); foreach($menu as $key=>$val){ if ($key == $i){ foreach($item['additional'] as $ad){ $newmenu[] = $ad; } } else{ $newmenu[] = $val; } } $menu = $newmenu; $item = $menu[$i]; } if ($item['special'] != "membership" || ($this->options->membership == "on")){ $mhtml = $layout->layout; $mhtml = str_replace("{".$menudetails->layout."}", "", $mhtml); $mhtml = str_replace("~~itemText~~", htmlentities($item['text']), $mhtml); $mhtml = str_replace("~~itemTitle~~", htmlentities($item['title']), $mhtml); $mhtml = str_replace("~~itemLink~~", $item['link'], $mhtml); $mhtml = str_replace("~~itemFunction~~", $item['function'], $mhtml); $mhtml = str_replace("~~itemUnique~~", htmlentities($item['unique']), $mhtml); $subslayout = $this->layout->getBlock($mhtml, "~~startSubItems~~", "~~endSubItems~~"); if ($subslayout){ $sublayout = $this->layout->getBlock($subslayout->layout, "~~startSubItem~~", "~~endSubItem~~"); if ($sublayout){ $subitems = array(); if(is_array($item['subs'])){ foreach($item['subs'] as $subs){ $subs=$this->checkMenuSpecial($subs); if ($subs['special'] != "membership" || ($this->options->membership == "on")){ $shtml = $sublayout->layout; $shtml = str_replace("~~subItemText~~", htmlentities($subs['text']), $shtml); $shtml = str_replace("~~subItemTitle~~", htmlentities($subs['title']), $shtml); $shtml = str_replace("~~subItemLink~~", $subs['link'], $shtml); $shtml = str_replace("~~subItemFunction~~", $subs['function'], $shtml); $shtml = str_replace("~~subItemUnique~~", htmlentities($subs['unique']), $shtml); $subsubslayout = $this->layout->getBlock($shtml, "~~startSubSubItems~~", "~~endSubSubItems~~"); if ($subsubslayout){ $subsublayout = $this->layout->getBlock($subsubslayout->layout, "~~startSubSubItem~~", "~~endSubSubItem~~"); if ($subsublayout){ $subsubitems = array(); if (is_array($subs['subs'])){ foreach($subs['subs'] as $ssubs){ if ($ssubs['special'] != "membership" || ($this->options->membership == "on")){ $ssubs=$this->checkMenuSpecial($ssubs); $sshtml = $subsublayout->layout; $sshtml = str_replace("~~subSubItemText~~", htmlentities($ssubs['text']), $sshtml); $sshtml = str_replace("~~subSubItemTitle~~", htmlentities($ssubs['title']), $sshtml); $sshtml = str_replace("~~subSubItemLink~~", $ssubs['link'], $sshtml); $sshtml = str_replace("~~subSubItemFunction~~", $ssubs['function'], $sshtml); $sshtml = str_replace("~~subSubItemUnique~~", htmlentities($ssubs['unique']), $sshtml); $subsubitems[] = $sshtml; } } } $subsubslayout->layout = substr_replace($subsubslayout->layout, implode("", $subsubitems), $subsublayout->start, $subsublayout->finish); } $shtml = substr_replace($shtml, $subsubslayout->layout, $subsubslayout->start, $subsubslayout->finish); } $subitems[] = $shtml; } } } } $subslayout->layout = substr_replace($subslayout->layout, implode("", $subitems), $sublayout->start, $sublayout->finish); $mhtml = substr_replace($mhtml, $subslayout->layout, $subslayout->start, $subslayout->finish); } $items[] = $mhtml; } $i++; $item = $menu[$i]; } $this->content = substr_replace($this->content, implode("", $items), $layout->start, $layout->finish); } else { break; } } } public function checkMenuSpecial($item){ if ($item['special'] == "membership"){ $item['text'] = explode("/", $item['text']); if ($this->member->user){ $item['text'] = $item['text'][1]; } else { $item['text'] = $item['text'][0]; } } elseif ($item['special'] != ""){ if (file_exists(DOCROOT.'plugins/'.$item['special'].'/menuitems.php')){ include(DOCROOT.'plugins/'.$item['special'].'/menuitems.php'); } } return $item; } public function clearActivity(){ $this->db->prepare("delete from sys_admin_activity where actDate < ?", array(array(time()-604800, 's'))); $this->db->run(); $this->db->prepare("delete from sys_user_activity where actDate < ?", array(array(time()-604800, 's'))); $this->db->run(); } public function checkMobile(){ if (!$_SESSION['checked']){ $ua = $_SERVER['HTTP_USER_AGENT']; $android = strpos($ua, 'Android') ? true : false; $blackberry = strpos($ua, 'BlackBerry') ? true : false; $iphone = strpos($ua, 'iPhone') ? true : false; $palm = strpos($ua, 'Palm') ? true : false; $palm = strpos($ua, 'webOS') ? true : false; if ($android || $blackberry || $iphone || $palm) { // Android $_SESSION['mobilesite'] = true; } else { $_SESSION['mobilesite'] = false; } $_SESSION['checked'] = true; } //$this->mobile = $_SESSION['mobilesite']; //$this->mobile = true; } public function clearCache(){ if ($this->admin->user){ shell_exec("rm -r ".DOCROOT."site/uploads/sys_cache/*"); } } public function getSiteScripts(){ $dir = "normal"; if ($this->mobile){ $dir = "mobile"; } $min = ''; if (!file_exists(DOCROOT.'site/uploads/sys_cache/'.$dir.'/'.$this->host.'/js/core.js')){ require_once(DOCROOT."system/assets/minifiers/Minifier.php"); foreach($this->themeConfig->js as $j){ if(strpos($j, "http") !== false || strpos($j, ".min.") !== false ) $min .= "\n".file_get_contents($j); //echo $j;die; else $min .= "\n". \JShrink\Minifier::minify(file_get_contents($j)); } if (!is_dir(DOCROOT.'site/uploads/sys_cache/'.$dir.'/'.$this->host.'/js')){ @mkdir(DOCROOT.'site/uploads/sys_cache/'.$dir.'/'.$this->host.'/js', 0777, true); } file_put_contents(DOCROOT.'site/uploads/sys_cache/'.$dir.'/'.$this->host.'/js/core.js', $min); } else { $min = file_get_contents(DOCROOT.'site/uploads/sys_cache/'.$dir.'/'.$this->host.'/js/core.js'); } return $min; } public function getSiteCss(){ $dir = "normal"; $sc = "core"; if ($this->mobile){ $dir = "mobile"; } $min = ''; if (!file_exists(DOCROOT.'site/uploads/sys_cache/'.$dir.'/'.$this->host.'/css/'.$sc.'.css')){ require_once(DOCROOT."system/assets/minifiers/cssmin-v3.0.1-minified.php"); foreach($this->themeConfig->css as $c){ if(strpos($c,"venobox") !== false || strpos($j, ".min.") !== false ) $min .= "\n". str_replace(["../images/", "~~themeDir~~", "fonts/"], [ROOT."site/themes/".$this->options->theme."/images/", ROOT."site/themes/".$this->options->theme."/", ROOT."site/themes/".$this->options->theme."/fonts/"], file_get_contents($c)); else $min .= "\n". CssMin::minify(str_replace(["../images/", "~~themeDir~~", "fonts/"], [ROOT."site/themes/".$this->options->theme."/images/", ROOT."site/themes/".$this->options->theme."/", ROOT."site/themes/".$this->options->theme."/fonts/"], file_get_contents($c))); } if (!is_dir(DOCROOT.'site/uploads/sys_cache/'.$dir.'/'.$this->host.'/css')){ @mkdir(DOCROOT.'site/uploads/sys_cache/'.$dir.'/'.$this->host.'/css', 0777, true); } // $min = str_replace("url(\"fonts", "url(\"".ROOT."site/themes/".$this->options->theme."/fonts", $min); file_put_contents(DOCROOT.'site/uploads/sys_cache/'.$dir.'/'.$this->host.'/css/'.$sc.'.css', $min); } else { $min = file_get_contents(DOCROOT.'site/uploads/sys_cache/'.$dir.'/'.$this->host.'/css/'.$sc.'.css'); } return $min; } public function getSEO(){ $this->seo = json_decode($this->options->seo, true); } public function checkCookies($type){ $cookies = (json_decode($_COOKIE['cookie-preferences'], true)) ?: []; if (in_array($type, $cookies) !== false) return true; return false; } } ?>