/** * cmsdAm is a powerful, simple, scalable, quick, secure, GPL released, PHP4 written from scratch * Content Management System framework. It is specially designed for people having some basic * PHP knowledge. You can create powerful professional sites in a while using cmsdAm, and you * don't have to rewrite each time php code for handle each section, users, search engine, ecc. * cmsdAm do all the work for you! You just have to configure it, and write HTML or PHP code * for your sections. You don't have to care about mails, HTTP headers, HTML strange tags, META * tags, HTTP cache mechanisms, ecc, just write HTML or PHP code for your sections. * * Enjoy!!! * * Copyright by (dAm2K) Dino Ciuffetti, TuxWeb S.r.l. - dino@tuxweb.it * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; version 2 of the License. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * * You should have received a copy of the GNU General Public License along * with this program (COPYING); if not, go to http://www.fsf.org/ or write * to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. * */ /* This is the main file. Almost everything begin from here */ unset ($CMSDAM); define ("CMSDAM", 1); // Handle PHP error reporting by ourself! // Comment it out for debugging reasons //error_reporting(0); /* BEGIN OF HTTP HEADERS */ // This is the first time sampler, // used to calculate the computation time PHP takes to create the page. $picktimes = explode(" ", microtime()); $time_start = $picktimes[0] + $picktimes[1]; // Turn on buffered output to avoid any header problem and to permit sending // http headers even after any output char ob_start(); // Set . as include directory ini_set("include_path", "."); // This is to prevent Variable Poisoning! ini_set("register_globals", "Off"); // Start sessions session_start(); // Get the user IP address $client_ip = getenv("REMOTE_ADDR"); if (($client_ip == "") && (defined("CMSDAM_CLIENT") == "")) { echo ("You can't run cmsdAm from command line!!\n"); echo ("Please read the documentation in docs/ directory!!\n"); exit (1); } elseif (defined("CMSDAM_CLIENT") != "") { fprintf (STDERR, "cmsdAm client: " . CMSDAM_CLIENT . "\n"); } // Import known external variables (http request, cookie, ecc...) require ("external.php"); // This is the cmsdam core, import classes require ("classes/core.php"); // Now the superobject $cms is defined and ready to use // We set PHP error reporting like written in configuration file error_reporting($cms->conf->ERROR_reporting_cmsdAm); // Activate "memcached" variables cache (if "is there any server"/"configuration enabled") if ($cms->conf->use_memcached == "YES") { // memcached support is enabled if ($cms->conf->memcached_persistant == "YES") { // Enable persistant links $_memcache_persist_links = "true"; } else { // Disable persistant links $_memcache_persist_links = "false"; } if ($cms->conf->memcached_servers != null) { // memcached support is configured $cms->memcache->cmsdam_memcache(array( 'servers' => $cms->conf->memcached_servers, 'debug' => false, 'compress_threshold' => $cms->conf->memcached_compress_threshold, 'persistant' => $_memcache_persist_links) ); } } // Set php time limit based on user choise set_time_limit($cms->conf->PHP_time_limit); // Get the client ip address $cms->http->client_ip = $client_ip; // If the cookie language is defined, set the preferred cmsdam_language, else // set the cmsdam language using the browser language $cmsdam_lang = $cms->i18n->cmsdam_set_preferred_lang($cmsdam_lang); // cmsdAm old chosen section $cms->sections->old_section = $cmsdam_oldsect; // Default template directory $cms->sections->templates_relpath = "template/lang/default"; // Default template language directory $cms->sections->templates_lang_relpath = "template/lang/$cmsdam_lang"; // Templates cmsdam relative path if (($cms->conf->LOG_level < 0) || ($cms->conf->LOG_level > 10)) { // Loglevel not valid $cms->conf->LOG_level = 6; $cms->logs->log_note(5, "WARNING: Log level not valid, setted to '6'"); } // google friendly links type disabled $cms->general->smartlink = false; // THIS IS EXPERIMENTAL AND DOES NOT WORK!!! $friendly_uri = strstr($_SERVER['REQUEST_URI'], "/index.php/uri/"); if ($friendly_uri != "") { // User wants to use the CLEAN URI method of getting section (eg: google friendly) $path_pos = strpos($_SERVER['REQUEST_URI'], "/index.php/uri/"); // This is the absolute url path of this cmsdam $path_first = substr($_SERVER['REQUEST_URI'], 0, $path_pos+1); $cms->sections->http_urlpath = $path_first; //echo "DEBUG: " . $cms->sections->http_urlpath; $friendly_uri = substr($friendly_uri, strlen("/index.php/uri/")); $temp_uri = strstr($friendly_uri, "section-"); $temp_uri = substr($temp_uri, strlen("section-")); $path_pos = strpos($temp_uri, "?"); if ($path_pos != "") { // Get the part after "?" $temp_uri = substr($temp_uri, 0, $path_pos); } if ($temp_uri != "") { // uri is something like: /index.php/uri/section-test, get "test" //echo " DEBUG: " . $temp_uri; $section = $temp_uri; // google friendly links type enabled $cms->general->smartlink = true; } else { // TODO: Redirect to $path_first $cms->general->smartlink = false; } } // END OF THIS IS EXPERIMENTAL AND DOES NOT WORK!!! $cms->sections->section_requested = $section; setcookie ("cmsdam_oldsect", $section); if ($n_c == 1) { $cms->sections->section_cached = 1; } else { $cms->sections->section_cached = 0; } // Log Browser identification and languages $cms->logs->log_note(7, "NOTE: Browser User-Agent: \"" . $_SERVER["HTTP_USER_AGENT"] . "\"."); $cms->logs->log_note(7, "NOTE: Browser Languages: \"" . $_SERVER["HTTP_ACCEPT_LANGUAGE"] . "\"."); // Log Requested section $cms->logs->log_note(5, "NOTE: Requested section: \"" . $cms->sections->section_requested . "\"."); $cms->debug->debug_write(7, "NOTE: Requested section: \"" . $cms->sections->section_requested . "\"."); // Cmsdam login controller $cms->logs->log_note(9, "USELESS NOTE: Including file: usercontrol.php"); require ("usercontrol.php"); // Verify login parameters // This is the right place to add HTTP headers, like cache mechanism, ecc... $cms->logs->log_note(9, "USELESS NOTE: Including file: index_HTTPheaders.php"); require ("index_HTTPheaders.php"); // Trying to get page from memcache if ((count ($_POST) == 0) && ($cms->sections->section_cached == 0)) { // We don't have POST data, so we can read from cache! $key_to_cache = md5($_SERVER['QUERY_STRING'].$cmsdam_lang.$cms->users->logged_user); $_return = $cms->memcache->get($key_to_cache); if ($_return != false) { $_return .= "\n\n"; $cms->logs->log_note(6, "NOTE: User=".$cms->users->logged_user.", Lang=$cmsdam_lang"); $cms->logs->log_note(5, "NOTE: MEM_HIT: Page feeded from cache. Key hash: $key_to_cache"); // Feed out the cached buffer echo $_return; // This is the last time sampler, // used to calculate the computation time PHP takes to create the page. $picktimes = explode(" ", microtime()); $time_stop = $picktimes[0] + $picktimes[1]; Header ("X-cmsdAm-ElapsedTime: " . round($time_stop - $time_start,4)); if ($cms->conf->parsetimecomment == "YES") { echo "\n\n"; } //header("Content-Length: " . strlen(ob_get_contents())); if (!(defined("CMSDAM_CLIENT"))) exit (0); } } // Try to make up the connection to the DB $cms->dbms->db_connect(); if ($cms->dbms->db_connected == 0) { // DB not connected $operation = "error"; $cmsdamItem = "db"; } // Get sections definition from the DB include ("templates.php"); $cms->logs->log_note(5, "NOTE: MEM_MISS: Page is fresh"); // Call the cmsdam_sections constructor to set the default parameters $cms->sections->cmsdam_sections(); if (isset($operation) && $operation == "admin") { // Administration interface requested // This is not a real section name, so it can be hardcoded ;-) $section = "admin"; // Linking Administration Framework $cms->sections->section_requested = $section; // cmsdam operations will NOT use memcache to store data!! $cms->sections->section_cached = 1; setcookie ("cmsdam_oldsect", $section); $cms->logs->log_note(5, "NOTE: Including Administration Framework: template/admin/index.php"); // This is the Administration Framework file, links all administration operations require ("template/admin/index.php"); } elseif (isset($operation) && $operation == "sysinfo") { // System information requested // Linking Administration Framework $cms->logs->log_note(5, "NOTE: Including System Information"); // cmsdam operations will NOT use memcache to store data!! $cms->sections->section_cached = 1; phpinfo(); if (!(defined("CMSDAM_CLIENT"))) exit (0); } elseif (isset($operation) && $operation == "error") { // Error stage invoked /* ERROR STAGE!! */ if ($cmsdamItem == "") { $cmsdamItem = "unknown"; } $cms->logs->log_note(1, "ERROR: Error stage invoked. Facility: $cmsdamItem"); } elseif (isset($operation) && $operation == "credits") { // List credits // cmsdam operations will NOT use memcache to store data!! $cms->sections->section_cached = 1; // Linking cmsdAm credits and licensing informations $cms->logs->log_note(9, "USELESS NOTE: Including CREDITS and AUTHORS: template/index.php"); $cms->general->flush_html_header_block("cmsdAm Credits"); echo "
\n"; echo "VERSION FILE\n";
require ("VERSION");
echo "\n";
echo "CREDITS FILE\n";
require ("CREDITS");
echo "\n";
echo "AUTHORS FILE\n";
require ("AUTHORS");
echo "\n";
} else { // HERE WE ARE STARTING ANY site PAGE
// Linking Template Skeleton
$cms->logs->log_note(9, "USELESS NOTE: Including main template file: template/index.php");
// This is the first template file, the skeleton, links all the sections
require ("template/index.php");
}
if ($cms->general->cmsdam_ob_cleaned == false) { // cmsdAm output buffer was not cleaned from the section
// This is the last time sampler,
// used to calculate the computation time PHP takes to create the page.
$picktimes = explode(" ", microtime());
$time_stop = $picktimes[0] + $picktimes[1];
require ("index_closepage.php");
// Trying to write data to memcache
if ((count ($_POST) == 0)&& ($cms->sections->section_cached == 0)) { // We don't have POST data, and user knows the page will be cached, so lets do it!!
$key_to_cache = md5($_SERVER['QUERY_STRING'].$cmsdam_lang.$cms->users->logged_user);
$output_data = ob_get_contents();
$_cached = $cms->memcache->add($key_to_cache, $output_data, time() + $cms->conf->HTTP_maxage);
if ($_cached == false) { // Error adding page to memcached
$cms->logs->log_note(5, "WARNING: Error adding page to memcached");
} else {
$cms->logs->log_note(5, "NOTE: The page was added to memcache. Key hash: $key_to_cache, TTL: ".$cms->conf->HTTP_maxage);
}
// echo "md5hash: $key_to_cache\n";
// echo "val2cache: $output_data\n";
} else {
$cms->logs->log_note(6, "NOTE: This section was NOT added to cache due to user request or POST data");
}
//header("Content-Length: " . strlen(ob_get_contents()));
}
?>