00001 <?php
00031 include_once("include/classes/content.php");
00032
00036 class CMSkey {
00040 const SYSMSG_NOTIFY = 0;
00041 const SYSMSG_WARNING = 1;
00042 const SYSMSG_ERROR = 2;
00043
00044 private $lp = array();
00045 private $title = NULL;
00046 private $layout = array();
00051 function __construct() {
00052 global $cfg;
00053
00054
00055 $this->lp['border_dx'] = $cfg->getConfig("LAYOUT_BORDER_DX");
00056 $this->lp['color_center'] = strtoupper($cfg->getConfig("LAYOUT_COLOR_CENTER"));
00057 $this->lp['color_left'] = strtoupper($cfg->getConfig("LAYOUT_COLOR_LEFT"));
00058 $this->lp['color_right'] = strtoupper($cfg->getConfig("LAYOUT_COLOR_RIGHT"));
00059 $this->lp['cols'] = $cfg->getConfig("LAYOUT_COLS");
00060 $this->lp['rail_pos'] = $cfg->getConfig("LAYOUT_RAIL_POS");
00061 $this->lp['type'] = $cfg->getConfig("LAYOUT_TYPE");
00062 $this->lp['width_center'] = $cfg->getConfig("LAYOUT_WIDTH_CENTER");
00063 $this->lp['width_left'] = $cfg->getConfig("LAYOUT_WIDTH_LEFT");
00064 $this->lp['width_right'] = $cfg->getConfig("LAYOUT_WIDTH_RIGHT");
00065 $this->lp['logo_width'] = $cfg->getConfig("LAYOUT_LOGO_WIDTH");
00066 $this->lp['logo_height'] = $cfg->getConfig("LAYOUT_LOGO_HEIGHT");
00067 $this->lp['width_total'] = $this->lp['width_center'] + $this->lp['width_left'] + $this->lp['width_right'];
00068
00069
00070 $res = mysql_query("SELECT * FROM layout ORDER BY location, position");
00071 while ($line = mysql_fetch_assoc($res)) {
00072 $item = array();
00073 $item['id_content'] = $line['id_content'];
00074 $item['id_is_type'] = $line['id_is_type'];
00075 $item['id_renderer'] = $line['id_renderer'];
00076 $item['id_container'] = $line['id_container'];
00077 if (!is_array($this->layout[$line['location']])) { $this->layout[$line['location']] = array(); }
00078 $this->layout[$line['location']][$line['position']] = $item;
00079 }
00080 mysql_free_result($res);
00081 }
00082
00089 public static function postOrGet($varname) {
00090 return (isset($_POST[$varname]) ? $_POST[$varname] : "") | (isset($_GET[$varname]) ? $_GET[$varname] : "");
00091 }
00092
00101 public static function getQueryString($excluded = "") {
00102 $excl = explode("|", $excluded);
00103
00104 if ($_SERVER['QUERY_STRING']) {
00105 $q = explode("&", $_SERVER['QUERY_STRING']);
00106 for ($i = 0; $i < count($q); $i++) {
00107 $item = explode("=", $q[$i]);
00108 if (!in_array($item[0], $excl)) {
00109 if ($qs) { $qs .= "&"; }
00110 $qs .= $q[$i];
00111 }
00112 }
00113 }
00114 if ($qs) { $qs = "?" . $qs; }
00115
00116 return $qs;
00117 }
00118
00124 public function getPageTitle() {
00125 global $cfg;
00126
00127 if (is_null($this->title)) {
00128 return $cfg->getConfig("SITE_TITLE");
00129 } else {
00130 return $this->title;
00131 }
00132 }
00133
00139 private function getLoginStatus() {
00140 global $cfg, $session;
00141
00142 if ($this->isloggedin) {
00143 $ls = LANG_LOGGEDINAS .
00144 " <strong>" . $session->getValue("userid") .
00145 "</strong> - <a href=\"" . $cfg->getConfig("DEFAULT_PAGE") .
00146 "?a=logout\">" . LANG_LOGOUT . "</a>";
00147 } else {
00148 if ($cfg->getConfig("LOGIN_LINK_VISIBLE") == "Y") {
00149 $ls = "<a href=\"" . $cfg->getConfig("DEFAULT_PAGE") .
00150 "?login=1\">" . LANG_LOGIN . "</a>";
00151 }
00152 }
00153 return "<div id=\"loginstatus\">\n" . $ls . "\n</div><!-- loginstatus -->";
00154 }
00155
00161 private function getSearchForm() {
00162 global $cfg;
00163
00164 if (isset($_POST['q'])) {
00165 $searchvalue = $_POST['q'];
00166 } else {
00167 $searchvalue = LANG_SEARCH;
00168 }
00169 return "<div id=\"search\">\n" .
00170 "<script type=\"text/javascript\">\n" .
00171 "//<![CDATA[\n" .
00172 "\tfunction submitSearchForm() {\n" .
00173 "\t\tvar f = document.getElementById('searchform');\n" .
00174 "\t\tf.submit();\n" .
00175 "\t}\n" .
00176 "//]]>\n" .
00177 "</script>\n" .
00178 "<form id=\"searchform\" method=\"post\" action=\"" . $cfg->getConfig("DEFAULT_PAGE") . "\">\n" .
00179 "<fieldset>\n" .
00180 "<input type=\"text\" name=\"q\" value=\"" . $searchvalue . "\" onfocus=\"javascript:f=getElementById('searchform');f.q.value='';\" />\n" .
00181 "<input type=\"hidden\" name=\"a\" value=\"search\" />\n" .
00182 "<a href=\"javascript: submitSearchForm();\"><img src=\"images/search_icon.png\" alt=\"search icon\" /></a>\n" .
00183 "</fieldset>\n" .
00184 "</form>\n" .
00185 "</div><!-- search -->\n";
00186 }
00187
00193 private function getHeader() {
00194 global $cfg, $lang;
00195
00196 $extra_style = " style=\"height: " . $this->lp['logo_height'] . "px; margin-left: ";
00197 if ($this->lp['type'] == "L") {
00198 $extra_style .= "-" . $this->lp['width_left'] . "px; margin-right: -" . $this->lp['width_right'] . "px; width: auto;\"";
00199 } else {
00200 $extra_style .= "auto; margin-right: auto; width: " . $this->lp['width_total'] . "px;\"";
00201 }
00202
00203 return "<div id=\"header\"" . $extra_style . ">\n" .
00204 "<div id=\"logo\" style=\"width:" . $this->lp['logo_width'] . "px;\"><a href=\"" . $cfg->getConfig("DEFAULT_PAGE") .
00205 "\"><img src=\"" . $cfg->getConfig("LOGO") . "\" alt=\"logo\" /></a></div>\n" .
00206 "<div id=\"langmenu\">\n" . $lang->getLanguageMenu() . "\n</div><!-- langmenu -->\n" .
00207 $this->getLoginStatus() .
00208 $this->getSearchForm() .
00209 "</div><!-- header -->\n";
00210 }
00211
00217 function getTopBar() {
00218 global $cfg;
00219
00220 if ($cfg->getConfig("TOPBAR_VISIBLE") == "0") { return; }
00221
00222
00223 if ($this->lp['type'] == "L") {
00224 $extra_style = " style=\"margin-left: -" . $this->lp['width_left'] . "px; margin-right: -" . $this->lp['width_right'] . "px; width: auto;\"";
00225 }
00226
00227 if (is_array($this->layout['T'])) {
00228 foreach ($this->layout['T'] as $key => $value) {
00229 $cnt = new Content($value['id_content'], ($value['id_is_type'] != "0"));
00230 $t .= $cnt->getRenderedContent($value['id_renderer'], $value['id_container']);
00231 unset($cnt);
00232 }
00233 }
00234 return "<div id=\"topbar\"" . $extra_style . ">\n" . $t . "</div><!-- topbar -->\n";
00235 }
00236
00242 private function getFooter() {
00243 global $cfg;
00244
00245 if ($this->lp['type'] == "L") {
00246 $extra_style = " style=\"margin-left: -" . $this->lp['width_left'] . "px; margin-right: -" . $this->lp['width_right'] . "px; width: auto;\"";
00247 }
00248
00249 $footer_text = $cfg->getConfig("FOOTER_TEXT");
00250 if ($footer_text) { $footer_text .= "<br />\n"; }
00251 return "<div id=\"footer\"" . $extra_style . ">\n" .
00252 $footer_text . "powered by <a href=\"http://www.cmskey.org/\"><strong>CMSkey</strong></a> (v. " . Config::CMSKEY_VERSION . ")\n" .
00253 "</div><!-- footer -->\n";
00254 }
00255
00262 private function getSideContent($side) {
00263 $thisside = ($side == "R" ? "right" : "left");
00264 $otherside = ($side == "L" ? "right" : "left");
00265
00266
00267 $extra_style = " style=\"float: " . ($this->lp['cols'] == 2 ? $otherside : $thisside) . ";" .
00268 " width: " . $this->lp['width_' . $thisside] . "px;";
00269 if ($this->lp['cols'] == 2) {
00270 $extra_style .= " background-color: #" . $this->lp['color_' . $thisside] . ";";
00271 } else {
00272 $extra_style .= " position: relative;";
00273 }
00274 if (($this->lp['cols'] == 3) || ($this->lp['type'] == "L")) {
00275 $extra_style .= " margin-" . $thisside . ": -" . $this->lp['width_' . $thisside] . "px;";
00276 }
00277 $extra_style .= "\"";
00278
00279 if (is_array($this->layout[$side])) {
00280 foreach ($this->layout[$side] as $key => $value) {
00281 $cnt = new Content($value['id_content'], ($value['id_is_type'] != "0"));
00282 $c .= $cnt->getRenderedContent($value['id_renderer']);
00283 unset($cnt);
00284 }
00285 }
00286
00287 return "<div id=\"" . $thisside . "content\"" . $extra_style . ">\n" .
00288 $c .
00289 "</div><!-- " . $thisside . "content -->\n";
00290 }
00291
00297 private function getRightContent() {
00298 return $this->getSideContent("R");
00299 }
00300
00306 private function getLeftContent() {
00307 return $this->getSideContent("L");
00308 }
00309
00315 private function getMiddleContent() {
00316
00317 $extra_style = " style=\"";
00318 if ($this->lp['cols'] > 1) {
00319 $width = $this->lp['type'] == "L" ? "100%" : $this->lp['width_center'] . "px";
00320 if ($this->lp['cols'] == "2") {
00321 $lrpos = ($this->lp['rail_pos'] == "L" ? "left" : "right");
00322 $extra_style .= "float: " . ($this->lp['rail_pos'] == "L" ? "right" : "left") . ";" .
00323 " background-color: #" . $this->lp['color_center'] . ";" .
00324 " border-" . $lrpos .
00325 ": " . $this->lp['width_' . $lrpos] .
00326 "px solid #" . $this->lp['color_' . $lrpos] . ";" .
00327 " margin-" . $lrpos . ": -" . $this->lp['width_' . $lrpos] . "px;";
00328 } else {
00329 $extra_style .= "float: left;" .
00330 " margin-right: -" . $width . ";";
00331 }
00332 $extra_style .= " width: " . $width . ";";
00333 } else {
00334 $extra_style .= " background-color: #" . $this->lp['color_center'] . ";";
00335 }
00336 $extra_style .= "\"";
00337
00338 if (isset($_GET['id'])) {
00339 $cnt = new Content($_GET['id']);
00340 $c = "<strong>" . $cnt->cnt[0]['title'] . "</strong><br />\n" . $cnt->cnt[0]['description'];
00341 } else {
00342 if (is_array($this->layout['M'])) {
00343 foreach ($this->layout['M'] as $key => $value) {
00344 $cnt = new Content($value['id_content'], ($value['id_is_type'] != "0"));
00345 $c .= $cnt->getRenderedContent($value['id_renderer'], $value['id_container']);
00346 unset($cnt);
00347 }
00348 }
00349 }
00350 return "<div id=\"middlecontent\"" . $extra_style . ">\n" .
00351 $c .
00352 "</div><!-- middlecontent -->\n";
00353 }
00354
00360 private function getMainContent() {
00361 $middlecontent = $this->getMiddleContent();
00362 if ($this->lp['cols'] > 1) {
00363 $extra_style = " style=\" background-color: #" . $this->lp['color_center'] . ";";
00364 if ($this->lp['cols'] == 2) {
00365 $extra_style .= " overflow: hidden;";
00366 if ($this->lp['type'] == "F") {
00367 $extra_style .= " position: relative; margin-left: auto; margin-right: auto;" .
00368 " width: " .
00369 ($this->lp['width_center'] + ($this->lp['rail_pos'] == "L" ? $this->lp['width_left'] : $this->lp['width_right'])) .
00370 "px;";
00371 } else {
00372 $extra_style .= " margin: 0 " . $this->lp['border_dx'] . "px; padding-" .
00373 ($this->lp['rail_pos'] == "L" ? "left" : "right") . ": " .
00374 ($this->lp['rail_pos'] == "L" ? $this->lp['width_left'] : $this->lp['width_right']) . "px;" .
00375 " height: 1%;";
00376 }
00377 $sidecontent = ($this->lp['rail_pos'] == "L" ? $this->getLeftContent() : $this->getRightContent());
00378 } else {
00379 $extra_style .= " width: " . ($this->lp['type'] == "F" ? $this->lp['width_center'] . "px" : "100%") . ";" .
00380 " float: left;" .
00381 " border-left: " . $this->lp['width_left'] . "px solid #" . $this->lp['color_left'] . ";" .
00382 " border-right: " . $this->lp['width_right'] . "px solid #" . $this->lp['color_right'] . ";";
00383 if ($this->lp['type'] == "L") {
00384 $extra_style .= " margin-left: -" . $this->lp['width_left'] . "px;" .
00385 " margin-right: -" . $this->lp['width_right'] . "px;" .
00386 " display: inline;";
00387 }
00388 $sidecontent = $this->getLeftContent() . $this->getRightContent();
00389 }
00390 $extra_style .= "\"";
00391 $middlecontent .= $sidecontent;
00392 }
00393 return "<div id=\"maincontent\"" . $extra_style . ">\n" .
00394 $middlecontent .
00395 "</div><!-- maincontent -->\n";
00396 }
00397
00403 public function getHTML() {
00404 if (($this->lp['cols'] != 2) && ($this->lp['type'] == "L")) {
00405 $body_extra_style = " style=\"margin: 0 " . $this->lp['border_dx'] . "px; " .
00406 "padding-right: " . $this->lp['width_right'] . "px; " .
00407 "padding-left: " . $this->lp['width_left'] . "px;\"";
00408 }
00409
00410 $html = $this->getHeader() . $this->getTopBar() . $this->getMainContent() . $this->getFooter();
00411 if ($this->lp['type'] == "F") {
00412 $html = "<div id=\"container\" style=\"width: " . $this->lp['width_total'] . "px;\">\n" . $html . "</div><!-- container -->\n";
00413 }
00414 return "<body" . $body_extra_style . ">\n" . $html . "</body>\n";
00415 }
00416
00424 public function doAction($action) {
00425
00426 switch ($action) {
00427 default:
00428 }
00429 return;
00430 }
00431 }
00432 ?>