" . print_r($var, TRUE) . ""; } } function string_replace($string, $array){ /**************************************************************************** * Handles the string replacing of an array of key=>value pairs into html * {key} in html will be replaced with value * * ------ Variables --------------------------------------------------------- * string - the html containing {key}'s * array - the data consisting of key=>value pairs to be put into the string ***************************************************************************/ $searchArray = array(); $replaceArray = array(); foreach($array as $search => $replace){ $searchArray[] = "{" . $search . "}"; $replaceArray[] = $replace; } $string = str_replace($searchArray, $replaceArray, $string); return $string; } function getRSS($rssDetails){ /********************************************************************** * Creates an RSS feed * * ------------------ Required Variables ------------------------------ * $rssDetails - details for the feed * EG.$rssArray = array( * "title" => "test feed", * "link" => "www.google.com", * "description" => "Testing feed", * "language" => "English", * "items" => array( * "1" => array( * "title" => "Item number 1", * "link" => "www.example.com", * "description" => "test item 1", * ), * "2" => array( * "title" => "Item 2", * "link" => "www.firstviewmedia.com", * "description" => "test for item number 2 of the test feed", * ) * ) * ); * * ------------------ Returns ----------------------------------------- * string in xml format of the rss feed *********************************************************************/ // build the feed // $rss = " " . $rssDetails['title'] . " " . $rssDetails['link'] . " " . $rssDetails['description'] . " " . $rssDetails['language'] . ""; /*$rss = " " . $rssDetails['img_title'] . " " . $rssDetails['img_url'] . " " . $rssDetails['img_link'] . " " . $rssDetails['img_width'] . " " . $rssDetails['img_height'] . " ";*/ // cycle through the items // foreach($rssDetails['items'] as $item){ $rss .= " " . $item['link'] . " " . $item['title'] . " " . $item['link'] . " " . date('r', $item['pdt']) . " "; } $rss .= ' '; // return the feed // return $rss; } ?> tags to be included in the header from the minify script // private $minCssArray = ""; // String of "; } // include the js includes // $searchArray[] = "{class_js_includes}"; $replaceArray[] = $string; // prepare all the CSS files for replacing into the header // $string = ""; foreach($this->includeCssArray as $file){ $string .= ""; } // includes the cs includes // $searchArray[] = "{class_css_includes}"; $replaceArray[] = $string; // includes the scripts to minify css files // $searchArray[] = "{minified_css_includes}"; $replaceArray[] = $this->minCssArray; // includes the scripts to minify the js files // $searchArray[] = "{minified_js_includes}"; $replaceArray[] = $this->minJsArray; // adds active class for header menu nav items // $searchArray[] = '{header_nav_class_' . $this->root . '}'; $replaceArray[] = HEADER_NAV_CLASS; if(isset($this->bodyArray)){ $searchArray[] = '{body_root}'; $replaceArray[] = implode("", $this->bodyArray);//set_body('root').set_body('subpage');//$_GET['root']; } // get the header and replace the variables // $header = file_get_contents($this->contentRootDir . "/header.php"); $header = str_replace($searchArray, $replaceArray, $header); // echo the header ... check the note in the main comment as to why it is echo'd and not included // echo $header; } function set_body($body, $asIs = FALSE){ /**************************************************** * Sets an array that will be used as the title * The array will be imploded with a | when the * header is outputted * * ----- VARIABLES ---------------------------------- * title - the text to go in the title * NOTE: root and subpage are predefined as * the root and subpage being loaded * asIs - if set to true no defined wordsw ill work ***************************************************/ // is asIs is set add the text to the array // if($asIs){ $this->bodyArray[] = $body; } else { // check if it is a predefined word // switch(strtolower($body)){ case "root": // out($this->root); $this->bodyArray[] = $this->root; $rootSet = TRUE; break; case "subpage": // check that the subpage doesnt already exist in the array, the subpage can be the same as the root // $body = $this->subpage; // $bodyLower = strtolower($body); if(!in_array($body, $this->bodyArray)){ $this->bodyArray[] = str_replace(' ','',$body); } break; default: $this->bodyArray[] = $body; break; } } } function include_index_code(){ //TODO $dataToAdd = index(); // out($dataToAdd); if(is_array($dataToAdd)){ $this->codeData[] = $dataToAdd; } else { $this->codeData[] = array(); } $this->set_replace_buffer_data(); } function include_code(){ /******************************************** * Inclides the relevant code page and * excecutes the revelant function * * ------- Logic ---------------------------- * If the file exists include it * If the required function exists execute * the function * If either one of the top if's fail add a * blank array to codeData *******************************************/ $codeDataTemp = array(); // check if the file exists // if(file_exists($this->codeFile)){ // include the file // include ($this->codeFile); // get the function to run from the code page // $codeFunction = $this->get_subpage(); // if the function exists run it and add the details to be replaced into the buffer // if(function_exists($codeFunction)){ $codeDataTemp = $codeFunction(); // check if an array is returned from the code page, if not add a blank array to be replaced into the buffer // if(is_array($codeDataTemp)){ $this->codeData = $codeDataTemp; } else { $this->codeData = array(); } } else { // else add a blank array to be replaced into the buffer // $this->codeData = array(); } } else { // else add a blank array to be replaced into the buffer // $this->codeData = array(); } if(DEV_MODE){ $this->check_constants(); } } function include_footer(){ /********************************************** * Includes the footer * * ------- Logic ------------------------------ * Checks if the file must be included due to * ajax, includes it accordingly *********************************************/ if($this->handle_ajax("footer")){ return ""; } $footerHtml = ""; $searchArray = array(); $replaceArray = array(); $footerHtml = file_get_contents($this->contentRootDir . "/footer.php"); $searchArray[] = "{google_analytics}"; $replaceArray[] = $this->include_google_analytics(); $footerHtml = str_replace($searchArray, $replaceArray, $footerHtml); echo $footerHtml; } function include_file($file){ include ($file); } /********************************************** * MAIN *********************************************/ function clean_url(){ /************************************************************************* * Translates the URL into variables and data to be used by the framework * * ------ Logic ---------------------------------------------------------- * Checks if the pages/directories exist before adding them to * appropriate variables ************************************************************************/ $uri = array(); $pageUri = array(); // check if the root exists in the url, if not default to the home page // if(!key_exists('root', $_GET) || $_GET['root'] == ""){ $root = "home"; } else { $root = $_GET['root']; } // check if the subpage exists in the url, if not default it to the home page // if(!key_exists("subpage", $_GET)){ $subpage = $root; } else { $subpage = $_GET['subpage']; } // if uri exists in the url get it and make it an array of values // if(key_exists("uri", $_GET)){ $uri = explode("/", $_GET['uri']); } // set the path to the file to load // $loadFile = $this->contentRootDir . "/" . $root . "/" . $this->add_ext($subpage); // keep a backup of the file the user requested // $originalFile = $loadFile; // set the code page to load // $codeFile = "code/code." . $root . ".php"; // check if the file exists // if(!file_exists($loadFile)){ // if it doesnt add the subpage to the uri array // $pageUri[] = $subpage; // make the subpage the root name // $subpage = $root; // set the file name to load // $loadFile = $this->contentRootDir . "/" . $root . "/" . $subpage . ".php"; // check if the file exists // if(!file_exists($loadFile)){ // if it doesnt add the root to the uri array // if(!in_array($root, $pageUri)){ $pageUri[] = $root; } // set the file to load to the 404 error page // $loadFile = $this->contentRootDir . "/error/404.php"; // set the code page to the error page // $codeFile = "code/code.error.php"; // set the root to the error pages // $root = "error"; // set the subpage to the 404 page // $subpage = "404"; } } // merge the page uri and the uri ... this will include the subpage and root if they do not exist as if they where passed in as variables // $uri = array_merge(array_reverse($pageUri), $uri); // cycle through to remove blanks and add the other to the get array so they are globally available // foreach($uri as $key => $value){ if(trim($value) == ""){ unset($value); } else { $_GET[$key] = $value; } } // check if the script is in the cms, if it is set a constant // if(key_exists('cms', $_GET)){ define('IS_CMS', TRUE); $this->set_cms_include_path("../"); } else { define('IS_CMS', FALSE); } // set the constant for dev_mode // $this->handle_dev_mode(); // set the constant for the cms include path // if(IS_CMS){ define('CMS_PATH', $this->cmsPath); } else { define('CMS_PATH', ''); } // sets the maintanence page to show ... will only show if dev_mode_html is not on // if(!DEV_MODE_HTML && MAINTENACE){ $_REQUEST['return_page'] = array("content"); $_REQUEST['ajax_on'] = TRUE; $codeFile = "code.maintanence.php"; $root = "maintenance"; $subpage = "maintenance"; $loadFile = "pages/maintenance/maintenance.php"; } // sets the coming soon page to show ... will only show if dev_mode_html is not on // if(!DEV_MODE_HTML && COMING_SOON){ $_REQUEST['return_page'] = array("content"); $_REQUEST['ajax_on'] = TRUE; $codeFile = "code.comingSoon.php"; $root = "comingSoon"; $subpage = "comingSoon"; $loadFile = "pages/comingSoon/comingSoon.php"; } // set all the relevant class/global variables // $this->uri = $uri; $this->codeFile = $codeFile; $this->contentFile = $loadFile; $this->root = $root; $this->subpage = $subpage; $_GET['root'] = $root; $_GET['subpage'] = $subpage; } function check_user_perm(){ /******************************************* * Checks if the user is signed into the cms, * Sets the user permissions appropriatly *********************************************/ } function handle_basic_cms_login(){ /************************************************** * Handles the basic login into the cms, just one * hard coded admin user * * ---- Logic ------------------------------------- * sets the required session if it is not set * if the user is not logged in will redirect to * the login page *************************************************/ if(!key_exists("user_logged_in", $_SESSION)){ $_SESSION['user_logged_in'] = FALSE; } // check if the user is logged in, if not redirect to the home page. // // Also checks if the user is not already on the login page else a redirect loop will be started // if(!$_SESSION['user_logged_in'] && $this->root !== 'login'){ header("Location: login"); } } private function get_dev_type($type){ /******************************************** * Used by the handle_dev_mode function * returns what type of dev mode is * requested to turn on *******************************************/ switch($type){ case "1": case "php": $type = 1; break; case "2": case "html": $type = 2; break; default: $type = 1; break; } return $type; } private function handle_dev_mode(){ /******************************************************* * Handles dev mode * * Dev mode is used for developing so that certain features * and functions only work if you want them to and * dont get in the way if you dont. * * eg. * The out function is used to pring formatted arrays * to the screen, this is only used by the php devs and * can throw out styles so the html devs do not want to * see the output, the php dev will turn on dev_mode * and see the output while the html dev will not see it * * ----- SETS ------------------------------------------ * DEV_MODE - master dev_mode * options: TRUE or FALSE * DEV_MODE_HTML - dev mode for html, doesnt activate * some things * options: TRUE or FALSE ******************************************************/ // checks if the ip is coming from one specified to always have dev_mode on // // checks that it is not being foceably turned off in the url // // checks that the script is trunning on the local server // if((in_array($_SERVER['REMOTE_ADDR'], $this->devModeIpArray)) && (!key_exists("dev_mode_off", $_GET)) && IS_LOCAL){ $_SESSION['dev_mode_on'] = TRUE; $_SESSION['dev_mode_type'] = 1; } else { // check if it is being turned on in the url // if(key_exists("dev_mode_on", $_GET)){ $_SESSION['dev_mode_on'] = TRUE; $_SESSION['dev_mode_type'] = $this->get_dev_type($_GET['type']); } // check if it is being turned off in the url // if(key_exists("dev_mode_off", $_GET)){ $_SESSION['dev_mode_on'] = FALSE; $_SESSION['dev_mode_type'] = 0; } } // set the constant based on the session // if(!key_exists('dev_mode_on', $_SESSION)){ define('DEV_MODE', FALSE); define('DEV_MODE_HTML', FALSE); } else { switch($_SESSION['dev_mode_type']){ case 0: define('DEV_MODE', FALSE); define('DEV_MODE_HTML', FALSE); break; case 1: define('DEV_MODE', $_SESSION['dev_mode_on']); define('DEV_MODE_HTML', $_SESSION['dev_mode_on']); break; case 2: define('DEV_MODE', FALSE); define('DEV_MODE_HTML', $_SESSION['dev_mode_on']); break; } } } function string_replace_buffer(){ /*********************************************************************************** * Replaces the data from the code page into the buffer * Runs all the loop and is true statements **********************************************************************************/ // get the contents of the buffer // $this->html = ob_get_clean(); if(!ob_start('ob_gzhandler')){ ob_start(); }; // replace the data into the html // $this->string_replace(); // output the buffer to the screen // $this->output_buffer(); } function string_replace_file($fileName, $data){ /*********************************************************************************** * uses the framework string replace on a file * * ------- Variables --------------------------------------------------------------- * $fileName - The name of the file to be read in and replaced * $data - the array to replace into the file * * ------- Returns ----------------------------------------------------------------- * The html with the data in **********************************************************************************/ // set the data // $this->set_replace_buffer_data($data); // set the html to the contents of the file and string replace it // $this->string_replace(file_get_contents('pages/deals/test.php')); // return the replaced html // return $this->get_replaced_html(); } function string_replace($html = NULL){ /********************************************* * Used to string replace data into the html * * ------ Variables -------------------------- * html - the html to be used * * ------ Logic ------------------------------ * removes the html comments * checks for and handles tags * checks for and handles tags * checks for and handles tags * checks for and handles tags * replaces all {} with data ********************************************/ if(!is_null($html)){ $this->html = $html; } // remove the html comments // $this->remove_comments(); // handle the is true statements // $this->get_istrue(); // handle is false statements // $this->get_isfalse(); // handle user access rights // $this->get_access(); // handle the loop statements // $this->get_loop(); // replace the relevant information // $this->get_straight_replace($this->html, $this->data); // string replace all the data into the html // $this->html = str_replace($this->searchArray, $this->replaceArray, $this->html); } function output_buffer(){ /**************************************************************** * Outputs the contents ***************************************************************/ echo $this->html; } function handle_class_includes($path){ /********************************************************** * Used to handle the includes required for class includes * * ---- Requires ------------------------------------------ * $path - the path to the settings file * * ---- Notes --------------------------------------------- * Uses regular expressions to pass the settings file * and add the include paths to the appropriate arrays * in the class to be included when needed * * For an example of the settings file look at the commenting * of load_class() which is where this function is called * from * * ---- Still to do --------------------------------------- * Find a way to incorporate the files into the minifier *********************************************************/ if(file_exists($path)){ $settings = file_get_contents($path); // get all the js files // preg_match_all("!(.+?)!s", $settings, $includeArray); foreach($includeArray[1] as $file){ $this->include_js($file); } // get all the css files // preg_match_all("!(.+?)!s", $settings, $includeArray); foreach($includeArray[1] as $file){ $this->include_css($file); } // get all the php includes // preg_match_all("!(.+?)!s", $settings, $includeArray); foreach($includeArray[1] as $file){ require_once(CMS_PATH . $file); } // get the defines // preg_match_all("!(.+?)!s", $settings, $includeArray); foreach($includeArray[1] as $define){ $this->set_required_define($define); } } } function load_class($function){ /************************************************************************ * Loads a class/module into the framework to be used * Handles all the required includes and setting * up that is required to use it, includes the class, * the class functions, sets up the required constants * array. * * Each case in the switch contains everything to make * the class/module work * * A settings file has been introduced that will * contain everything that will be required for the * class to run * * ---- Examples -------------------------------------------------------- * Settings file: * * js/someFileForModule.js * js/someMoreJs.js * * css/someCssToUse.css * css/someMoreCss.css * * inc/classes/moduleName/moduleFunctions.php * inc/classes/moduleName/moduleClass.php * * SOME_SETTING_THAT_NEEDS_TO_BE_SET_IN_CONSTANTS * MORE_CONSTANTS * EVEN_MORE * * * NOTE: all includes need to start with the constant * CMS_PATH so that the cms can be pulled out and the * includes will still work * * ---- To Do ---------------------------------------------------------- * Move all classes to use the settings.xml file, * this feature was added in later so most are still * using the old way of including everything in here * * Look at using a default in switch to automaticlayy load * a class without haveing to add a new case. * eg. * $function = mail; * will load : CMS_PATH . "inc/classes/mail.settings.xml" * unless otherwise specified in a case statment * This will work but will take away some freedom in * using the framework. *********************************************************************/ // check that the function isnt already loaded // /*if(function_exists($function)){ return ""; }*/ // load the correct function // switch($function){ case "email": /*$this->include_js(""); $this->include_css("");*/ $this->handle_class_includes(CMS_PATH . "inc/classes/email/settings.xml"); /*$this->set_required_define(array( //"EMAIL_HOST", "EMAIL_USERNAME", "EMAIL_PASSWORD" ));*/ //require_once(CMS_PATH . "inc/classes/email/functions.php"); break; case "geoip": /*$this->include_js("js/testjs2.js");*/ require_once(CMS_PATH . "inc/classes/geoip/functions.php"); break; case "node": require_once(CMS_PATH . "inc/classes/node/functions.php"); break; case "cm": require_once(CMS_PATH . "inc/classes/campaignMonitor/functions.php"); break; case "db": $this->set_required_define(array( "DB_SERVER", "DB_USERNAME", "DB_PASSWORD", "DB_DATABASE", "DB_PREFIX" )); require_once(CMS_PATH . "inc/classes/dataBase/db.class.php"); /********************************************************************* * $db will not be able to be accessed outside of this class so is * pointless to have here but it is here as an example for * what needs to be done when using this module ********************************************************************/ $db = new db(array( "host" => DB_SERVER, "username" => DB_USERNAME, "password" => DB_PASSWORD, "database" => DB_DATABASE )); $connection = $db->db_get_connection(); break; case "shorturl": require_once(CMS_PATH . "inc/classes/google/shorturl/functions.php"); break; case "tagCloud": require_once(CMS_PATH . "inc/classes/tagCloud/tagCloud.class.php"); require_once(CMS_PATH . "inc/classes/tagCloud/functions.php"); break; case "file_handling": require_once(CMS_PATH . "inc/classes/file/file.class.php"); require_once(CMS_PATH . "inc/classes/file/functions.php"); break; case "image": require_once(CMS_PATH . "inc/classes/image/image.class.php"); require_once(CMS_PATH . "inc/classes/image/functions.php"); break; case "string": require_once(CMS_PATH . "inc/classes/string/string.class.php"); break; case "minify": require_once(CMS_PATH . "inc/classes/min/utils.php"); break; case "date": require_once(CMS_PATH . "inc/classes/date/date.class.php"); break; case "facebook": $this->set_required_define(array( "FACEBOOK_APP_ID", "FACEBOOK_SECRET", "FACEBOOK_OK_SESSION" )); break; case "ck": $this->set_required_define(array( "CK_PATH", "CK_DOCUMENT_ROOT" )); require_once(CMS_PATH . "inc/classes/ck/ckeditor/ckeditor.php"); require_once(CMS_PATH . "inc/classes/ck/functions.php"); break; case "twitter": $this->set_required_define(array( "TWITTER_USERNAME", "TWITTER_SHOW_COUNT" )); require_once(CMS_PATH . "inc/classes/twitter/twitter.class.php"); break; case "article": require_once(CMS_PATH . "inc/classes/category.class.php"); require_once(CMS_PATH . "inc/classes/tag.class.php"); require_once(CMS_PATH . "inc/classes/article.class.php"); break; case "tag": require_once(CMS_PATH . "inc/classes/tag.class.php"); break; case "category": require_once(CMS_PATH . "inc/classes/category.class.php"); require_once(CMS_PATH . "inc/classes/sub_category.class.php"); break; case "menu": require_once(CMS_PATH . "inc/classes/menu/functions.php"); require_once(CMS_PATH . "inc/classes/menu/menu.class.php"); break; case "cookie": require_once(CMS_PATH . "inc/classes/cookie/cookie.class.php"); break; case "faq": require_once(CMS_PATH . "inc/classes/category.class.php"); require_once(CMS_PATH . "inc/classes/tag.class.php"); require_once(CMS_PATH . "inc/classes/user_response.class.php"); require_once(CMS_PATH . "inc/classes/faq.class.php"); break; case "user_response": require_once(CMS_PATH . "inc/classes/user_response.class.php"); break; case "filter": require_once(CMS_PATH . "inc/classes/filter/filter.class.php"); default: $this->handle_class_includes(CMS_PATH . "inc/classes/" . $function . "/settings.xml"); break; } } /*********************************************** * HELPERS **********************************************/ function include_google_analytics(){ /******************************************************** * Handles including of google analytics * Analytics will only be included if the site is live * and the ip connecting is not from FV ip address *******************************************************/ $analyticsHTML = ""; if(INCLUDE_GOOGLE_ANALYTICS){ $analyticsHTML = ""; } return $analyticsHTML; } function handle_google_analytics(){ /****************************************************** * Used to set the INCLUDE_GOOGLE_ANALYTICS constant * * Will be set to FALSE if: * The site is running off the local server * The user is connecting with FirstViews IP * A get variable of google_analytics is set to false *****************************************************/ $getVarFound = FALSE; // check if get variable is being used, this will overwrite any other setting // if(key_exists('google_analytics', $_GET)){ $getVarFound = TRUE; // if it is true unset the analytics session // if($_GET['google_analytics']){ unset($_SESSION['google_analytics']); } } // if the site is hosted on FV local or FV's IP is connected to it, and that the session does not exist // if((IS_LOCAL || IS_FV) && (!key_exists('google_analytics', $_SESSION))){ $_SESSION['google_analytics'] = FALSE; } // if the get is set overwrite the session to that value // if($getVarFound){ $_SESSION['google_analytics'] = $_GET['google_analytics']; } // set the constant dependant on the session // if(key_exists('google_analytics', $_SESSION)){ define('INCLUDE_GOOGLE_ANALYTICS', $_SESSION['google_analytics']); } else { define('INCLUDE_GOOGLE_ANALYTICS', TRUE); } } private function add_ext($file){ /******************************************************************* * checks if the file name has he .php extension, if not it adds it ******************************************************************/ if(strrpos($file,".php") !== (strlen($file) - 4)){ $file .= ".php"; } return $file; } private function handle_ajax($page = null){ /*********************************************************** * checks if a page/section must be loaded * * ----- Variables ----------------------------------------- * $page = The page that is being checked * * ----- Logic --------------------------------------------- * If ajax is not set the page will be included * If ajax is set and the $page is not in the return_page * array, or the return_page array is not set the * page will not be included * If ajax is set but the $page is in the return_page * array the page will be included **********************************************************/ if(key_exists("ajax_on", $_REQUEST)){ if(!defined('AJAX_ON')){ define('AJAX_ON', TRUE); } if(key_exists('return_page', $_REQUEST)){ if(in_array($page, $_REQUEST['return_page'])){ //define('AJAX_ON', FALSE); return FALSE; } else { //define('AJAX_ON', TRUE); return TRUE; } } else { //define('AJAX_ON', TRUE); return TRUE; } } else { if(!defined('AJAX_ON')){ define('AJAX_ON', FALSE); } return FALSE; } } /****************************************************** * buffer string replace *****************************************************/ private function add_replace($replace){ /*************************************** * Adds a variable to the replace array * for the final string replace **************************************/ if(is_array($replace)){ foreach($replace as $value){ $this->replaceArray[] = $value; } } else { $this->replaceArray[] = $replace; } } private function add_search($search){ /*************************************** * Adds a variable to the search array * for the final string replace **************************************/ if(is_array($search)){ foreach($search as $value){ $this->searchArray[] = $value; } } else { $this->searchArray[] = $search; } } private function get_straight_replace($string, $array, $return = FALSE){ /************************************************************ * Used to replace {key} in $string from $array * * ----- Variables ------------------------------------------ * string - the string containing {key}'s * array - the data used to replace the {key}'s * return - if set to TRUE the data will be replaced and return * if set to false the data will be added to the global * serach and replace variables ***********************************************************/ // Find items to replace // $replace = array(); preg_match_all('%{([a-zA-Z0-9/|/_//.]+)}%', $string, $matches); foreach($matches[1] as $match){ $exp = explode('|', $match); $str=''; foreach($exp as $val){ $str .= '[\''.$val.'\']'; } // Create replacement array out of data // eval('if(isset($array' . $str . ')){ $each = $array' . $str . '; } else { $each = ""; }'); if(strlen($each) > 0){ eval('$replace[] = $array' . $str . ';'); } else { $replace[] = ''; } } if($return){ return str_replace($matches[0], $replace, $string); } else { if(!empty($matches[0])){ $this->add_replace($replace); $this->add_search($matches[0]); } } } private function get_istrue(){ /********************************************************* * Handles the replacing of the tags * eg. * Returned from the code page function: * Array( * "show_edit" => TRUE * ) * * In the HTML: * * * * *
Sorry you cant edit
* * * Result in the DOM: * ********************************************************/ // get all the ISTRUE id's // $start = preg_quote("(.+?)!s", $this->html, $idArray); // cycle through them to check if they must be there // foreach($idArray[1] as $key => $id){ // array variables are seperated by | so explode the string to get all the keys // $vars = explode("|", $id); $str = ""; // build the string to get the data required // foreach($vars as $var){ $str .= "['" . $var ."']"; } // this needs to be evaled as the we dont know how many levels down the data is in the array // eval('if((!isset($this->data' . $str . ')) || (!$this->data' . $str . ' === TRUE)){ $idArray[2][$key] = ""; }'); } // replace the data into the html // $this->html = str_replace($idArray[0], $idArray[2], $this->html); } private function get_isfalse(){ /********************************************************* * Handles the replacing of the tags * * eg. * Returned from the code page function: * Array( * "show_edit" => FALSE * ) * * In the HTML: * * * * *
Sorry you cant edit
* * * Result in the DOM: *
Sorry you cant edit
* ********************************************************/ // get all the ISTRUE id's // $start = preg_quote("(.+?)!s", $this->html, $detailsArray); // cycle through them to check if they must be there // foreach($detailsArray[1] as $key => $id){ // array variables are seperated by | so explode the string to get all the keys // $vars = explode("|", $id); $str = ""; // build the string to get the data required // foreach($vars as $var){ $str .= "['" . $var ."']"; } // this needs to be evaled as the we dont know how many levels down the data is in the array // eval('if((isset($this->data' . $str . ')) && ($this->data' . $str . ' === TRUE)){ $detailsArray[2][$key] = ""; }'); } // replace the data into the html // $this->html = str_replace($detailsArray[0], $detailsArray[2], $this->html); } private function get_access(){ /************************************************************************************* * Handles the replacing of the tags * * eg. * Set the user permission somewhere in the code * $framework->set_user_perm('1'); * * Add the section in the html: * *
Only users with access permission of 1,4 or 5 will see this
* ***********************************************************************************/ $allow = FALSE; // get the details // $start = preg_quote("(.+?)!s", $this->html, $detailsArray); // cycle through the returned id's // foreach($detailsArray[1] as $key => $id){ $vars = explode(",", $id); // if its not in the array set the contents to blank // if(!in_array($this->userPerm, $vars)){ $detailsArray[2][$key] = ""; } } $this->html = str_replace($detailsArray[0], $detailsArray[2], $this->html); } private function get_inner_loop($originalContent){ /********************************************* * Handles the innerloop tag * * ---- Variables ---------------------------- * originalContent - the content to look in ********************************************/ // set up a blank array for the looped/replaced content // $newContentArray = array(); // get all the instances of inner loop // $start = preg_quote("(.+?)!s", $originalContent, $detailsArray); foreach($detailsArray[1] as $key => $id){ $newContentArray[$key] = ""; $vars = explode("|", $id); $str = ""; foreach($vars as $var){ $str .= "['" . $var ."']"; } eval('if(isset($this->data' . $str . ')){ $data = $this->data' . $str . '; } else { $data = array(); }'); foreach($data as $array){ $newContentArray[$key] .= $this->get_straight_replace($detailsArray[2][$key], $array, TRUE); } } $originalContent = str_replace($detailsArray[0], $newContentArray, $originalContent); return $originalContent; } private function remove_comments(){ /***************************************************** * Removes html comments with a regular expression * * looks for "" * or * "" ****************************************************/ $this->html = preg_replace("!<\!-- (.+?)-->|<\!--\n(.+?)-->!s", "", $this->html); } private function get_loop(){ /************************************************************ * Handles the tag * * is used inside the html so that data can be looped * whithout putting a php foreach loop into the html. * * The return data from the code page function is used as data * * eg. * Return from code page: * Array( * "items" => array( * "0" => array( * "title" => "Product 1", * "price" => "100.00" * ), * "1" => array( * "title" => "Product 2", * "price" => "200.00" * ) * ) * ) * * In the html: * *
Item {title} costs R{price}
*
* * Result in the dom: *
Item Product 1 costs R100.00
*
Item Product 2 costs R200.00
***********************************************************/ // get all the details // $start = preg_quote("(.+?)!s", $this->html, $detailsArray); $idArray = $detailsArray[1]; $count = 0; $newContentArray = array(); foreach($idArray as $key => $id){ $count++; $newContentArray[$key] = ""; // replace tags // $content = $this->get_inner_loop(trim($detailsArray[2][$key])); // if the id is numeric just reproduce the data that many times // if(is_numeric($id)){ for($j=0;$j<$id;$j++){ $newContentArray[$key] .= $content; } } else { // else replace teh data according to the array specified // $vars = explode("|", $id); $str = ""; foreach($vars as $var){ $str .= "['" . $var ."']"; } eval('if(isset($this->data' . $str . ')){ $data = $this->data' . $str . '; } else { $data = array(); }'); // reaplce the data into a new array that can be used to replace into the main html // foreach($data as $array){ $newContentArray[$key] .= $this->get_straight_replace($content, $array, TRUE); } } } // replace the data into the html // $this->html = str_replace($detailsArray[0], $newContentArray, $this->html); } function minify($group, $type){ /*********************************************************** * Handles minifying css and js * * ------ Variables ---------------------------------------- * group - the group defined in the minify groupConfog file * type - the type of files that are in the group * options: css, js **********************************************************/ // check if dev_mode is on for html so that minifying can be turned off // if(DEV_MODE_HTML){ // include the groupConfig file // $pagesArray = include("inc/classes/min/groupsConfig.php"); // remove the directory information from the name // $pagesArray = $this->remove_directory($pagesArray[$group]); // cycle through the pages and add them to the appropriate variable // foreach($pagesArray as $page){ switch($type){ case "css": $this->minCssArray .= ""; break; case "js": $this->minJsArray .= ""; break; } } } else { // if dev mode is not turned on add links to minify the groups // switch($type){ case "css": $this->minCssArray .= ""; break; case "js": $this->minJsArray .= ""; break; } } } private function remove_directory($array){ /************************************ * Used in the minify function * Removes the ../ from the string * so it can be included correctly ***********************************/ foreach($array as $key => $var){ $array[$key] = str_replace("../", "", $var); } return $array; } private function check_constants(){ /**************************************************** * Checks if the constants required are set, * Also checks that they are not set to local * details ***************************************************/ // set the return array // $returnArray = array( "defined" => array(), "undefined" => array() ); // cycle through the required constants // foreach($this->requiredDefines as $item){ // check if it is defined and that it is not set to something for local testing // if(defined($item) && constant($item) != "" && strpos(constant($item), "firstview") === FALSE && strpos(constant($item), "10.0.1.19") === FALSE && strpos(constant($item), "_Internal") === FALSE && strpos(constant($item), "DEV_SOURCE") === FALSE){ // if its defined set the value to be returned $returnArray['defined'][$item] = constant($item); } else { // the item could be defined but to something local, if so set the value to be returned // if(defined($item)){ $returnArray['undefined'][$item] = constant($item); } else { // else set it to blank // $returnArray['undefined'][$item] = ""; } } } return $returnArray; } private function split_camel_case($text){ /****************************************************************************** * Used to split up camelCase * * ---- Variables ------------------------------------------------------------- * $text - the string to be seperated * * ---- Returns --------------------------------------------------------------- * String - the seperated $text * * EG. * INPUT = camelCase * OUTPUT = camel Case * * ---- Logic ----------------------------------------------------------------- * Cycle through all the letters in the $text input * check if the letter is uppercase and if the previous letter wasnt uppercase * checks if the next letter is lowercase, if it is adds a space before the * current letter * if the letter is not uppercase check that it is not a special character *****************************************************************************/ $newText = ""; $prevCapsIndex = 0; // cycle through every character // for($i=0; $i