/** * 载入外部文件或目录 */ public function import($dir, $regx = '', $options = array()) { if (is_file($dir)) { require_once $dir; } else { file_include($dir, $regx, $options); } }
function articles() { global $categorySEF, $subcatSEF, $articleSEF, $_ID, $_POS, $_catID, $_XNAME; $frontpage = s('display_page'); $title_not_found = '<h2>' . l('none_yet') . '</h2>'; if (_ADMIN) { $visible = ''; $title_not_found .= '<p>' . l('create_new') . ' <a href="' . _SITE . 'administration/" title="' . l('administration') . '">' . l('administration') . '</a></p>'; } else { $visible = ' AND a.visible=\'YES\' '; } if ($_ID || !$_catID && $frontpage != 0) { if (!$_ID) { $_ID = $frontpage; } // article or page, id as indentifier $query_articles = 'SELECT a.id AS aid,title,a.seftitle AS asef,text,a.date, a.displaytitle,a.displayinfo,a.commentable,a.visible FROM ' . _PRE . 'articles' . ' AS a WHERE id =' . $_ID . $visible; } else { if (s('display_pagination') == 'on') { $on = true; } else { $on = false; } if ($on == true) { if ($articleSEF) { $SEF = $articleSEF; } elseif ($subcatSEF) { $SEF = $subcatSEF; } else { $SEF = $categorySEF; } // pagination $currentPage = strpos($SEF, l('paginator')) === 0 ? str_replace(l('paginator'), '', $SEF) : ''; if ($_catID) { $count = 'SELECT COUNT(a.id) AS num FROM ' . _PRE . 'articles' . ' AS a WHERE position = 1 AND a.published =1 AND category = ' . $_catID . $visible . ' GROUP BY category'; } else { $count = 'SELECT COUNT(a.id) AS num FROM ' . _PRE . 'articles' . ' AS a LEFT OUTER JOIN ' . _PRE . 'categories' . ' as c ON category = c.id LEFT OUTER JOIN ' . _PRE . 'categories' . ' as x ON c.subcat = x.id AND (x.published =\'YES\') WHERE show_on_home = \'YES\' ' . $visible . ' AND position = 1 AND a.published =1 AND c.published =\'YES\' GROUP BY show_on_home'; } $count = mysql_query($count); if ($count) { $r = mysql_fetch_array($count); $num = $r['num']; } } if ($num === 0) { echo $title_not_found; } else { $articleCount = s('article_limit'); $article_limit = empty($articleCount) || $articleCount < 1 ? 100 : $articleCount; $totalPages = ceil($num / $article_limit); if (!isset($currentPage) || !is_numeric($currentPage) || $currentPage < 1) { $currentPage = 1; } // get the rows for category if ($_catID) { $query_articles = 'SELECT a.id AS aid,title,a.seftitle AS asef,text,a.date, a.displaytitle,a.displayinfo,a.commentable,a.visible FROM ' . _PRE . 'articles' . ' AS a WHERE position = 1 AND a.published =1 AND category = ' . $_catID . $visible . ' ORDER BY artorder ASC,date DESC LIMIT ' . ($currentPage - 1) * $article_limit . ',' . $article_limit; } else { $query_articles = 'SELECT a.id AS aid,title,a.seftitle AS asef,text,a.date, displaytitle,displayinfo,commentable,a.visible, c.name AS name,c.seftitle AS csef, x.name AS xname,x.seftitle AS xsef FROM ' . _PRE . 'articles' . ' AS a LEFT OUTER JOIN ' . _PRE . 'categories' . ' as c ON category = c.id LEFT OUTER JOIN ' . _PRE . 'categories' . ' as x ON c.subcat = x.id AND x.published =\'YES\' WHERE show_on_home = \'YES\' AND position = 1 AND a.published =1 AND c.published =\'YES\'' . $visible . ' ORDER BY date DESC LIMIT ' . ($currentPage - 1) * $article_limit . ',' . $article_limit; } } } $result = mysql_query($query_articles); $numrows = mysql_num_rows($result); if (!$result || !$numrows) { if (_ADMIN) { echo $title_not_found; } echo '<ul class="vertical">'; menu_articles(0, 10, 1); echo '</ul>'; } else { $link = '<a href="' . _SITE; while ($r = mysql_fetch_array($result)) { $infoline = $r['displayinfo'] == 'YES' ? true : false; $text = stripslashes($r['text']); if (!empty($currentPage)) { $short_display = strpos($text, '[break]'); $shorten = $short_display == 0 ? 9999000 : $short_display; } else { $shorten = 9999000; } $comments_query = 'SELECT id FROM ' . _PRE . 'comments' . ' WHERE articleid = ' . $r['aid'] . ' AND approved = \'True\''; $comments_result = mysql_query($comments_query); $comments_num = mysql_num_rows($comments_result); $a_date_format = date(s('date_format'), strtotime($r['date'])); if ($r['csef']) { $uri = $r['xsef'] ? $r['xsef'] . '/' . $r['csef'] : $r['csef']; } elseif ($_XNAME) { $uri = $categorySEF . '/' . $subcatSEF; } else { $uri = $categorySEF; } $title = $r['title']; if ($r['displaytitle'] == 'YES') { if (!$_ID) { echo '<h2 class="big">' . $link . $uri . '/' . $r['asef'] . '/">' . $title . '</a></h2>'; } else { echo '<h2>' . $title . '</h2>'; } } file_include(str_replace('[break]', '', $text), $shorten); $commentable = $r['commentable']; $visiblity = $r['visible'] == 'YES' ? '<a href="' . _SITE . '?action=process&task=hide&item=snews_articles&id=' . $r['aid'] . '&back=' . $uri . '">' . l('hide') . '</a>' : l('hidden') . ' ( <a href="' . _SITE . '?action=process&task=show&item=snews_articles&id=' . $r['aid'] . '&back=' . $uri . '">' . l('show') . '</a> )'; $edit_link = $link . '?action=admin_article&id=' . $r['aid'] . '" title="' . $title . '">' . l('edit') . '</a> '; $edit_link .= ' ' . l('divider') . ' ' . $visiblity; if (!empty($currentPage)) { if ($infoline == true) { $tag = explode(',', tags('infoline')); foreach ($tag as $tag) { switch (true) { case $tag == 'date': echo $a_date_format; break; case $tag == 'readmore' && strlen($r['text']) > $shorten: echo $link . $uri . '/' . $r['asef'] . '/">' . l('read_more') . '</a> '; break; case $tag == 'comments' && ($commentable == 'YES' || $commentable == 'FREEZ'): echo $link . $uri . '/' . $r['asef'] . '/#' . l('comment') . '1"> ' . l('comments') . ' (' . $comments_num . ')</a> '; break; case $tag == 'edit' && _ADMIN: echo ' ' . $edit_link; break; case $tag != 'readmore' && $tag != 'comments' && $tag != 'edit': echo $tag; break; } } } else { if (_ADMIN) { echo '<p>' . $edit_link . '</p>'; } } } else { if (empty($currentPage)) { if ($infoline == true) { $tag = explode(',', tags('infoline')); foreach ($tag as $tag) { switch ($tag) { case 'date': echo $a_date_format; break; case 'readmore': case 'comments': break; case 'edit': if (_ADMIN) { echo ' ' . $edit_link; } break; default: echo $tag; } } } else { if (_ADMIN) { echo '<p>' . $edit_link . '</p>'; } } } } } if (!empty($currentPage) && $num > $article_limit && $on) { paginator($currentPage, $totalPages, l('paginator')); } if (!empty($_POS) && empty($currentPage) && $infoline == true) { if ($commentable == 'YES') { comment('unfreezed'); } else { if ($commentable == 'FREEZ') { comment('freezed'); } } } } }
/** * Inicia a aplicação * @param array $APPConfig * @param string $PublicPath */ static function Initialize(array $APPConfig, $PublicPath = 'public_html') { APP::setGlobal('public_path', $PublicPath); $Action = $Controller = null; self::$APP_CONFIG = $APPConfig; self::$Modules = isset(self::$APP_CONFIG['modules']) ? self::$APP_CONFIG['modules'] : self::$APP_CONFIG; self::$DefaultModule = key(self::$Modules); # URL Variables $values = !empty($_GET['GET_VARS']) ? explode('/', strtolower($_GET['GET_VARS'])) : [self::$DefaultModule, 'index', 'index']; # Modulo if (isset(self::$Modules[$values[0]])) { self::$CurrentModule = $values[0]; unset($values[0]); $values = array_values($values); } else { self::$CurrentModule = self::$DefaultModule; } # Controller if (empty($values[0]) or controller_exists(strtolower($values[0])) === false) { $Controller = 'index'; } else { $Controller = $values[0]; unset($values[0]); $values = array_values($values); } # Action if (empty($values[0]) and controller_action_exists($Controller, 'index')) { $Action = 'indexAction'; } else { if (empty($values[0]) or !($Action = controller_action_exists($Controller, $values[0]))) { self::$Parans['action'] = strtolower(@$values[0]); $Action = 'notFoundPage'; } else { unset($values[0]); $values = array_values($values); } } # Parâmetros númericos self::$Parans = $values; # Parâmetros nomeados if (count(self::$Parans) > 1) { for ($i = 0; $i < count($values); $i += 2) { if (isset($values[$i + 1])) { self::$Parans[$values[$i]] = $values[$i + 1]; } } } # Modulo if (!isset(self::$Parans['module'])) { self::$Parans['module'] = APP::getCurrentModule(); } # Controller if (!isset(self::$Parans['controller'])) { self::$Parans['controller'] = APP::getControllerName(); } # Action if (!isset(self::$Parans['action'])) { self::$Parans['action'] = $Action; } # Valores GET if (preg_match('/\\?/', inputServer('REQUEST_URI'))) { parse_str(preg_replace('/.*\\?/', NULL, inputServer('REQUEST_URI')), $getValues); foreach ($getValues as $key => $value) { $_GET[$key] = $value; if (!isset(self::$Parans[$key])) { self::$Parans[$key] = $value; } } } # Action self::$Action = $Action; # Cria instancia do modulo if (file_exists($ModuleClass = ABSPATH . '/' . self::getCurrentModule(true) . '/Module.class.php')) { file_include($ModuleClass); self::$Module = new Module(); } # Executando a action self::setController($Controller); self::getController()->{$Action}(); }
/** * * @param type $file * @param array $Variables * @param boolean $return * @param boolean $autoExtractHeaders * @return type */ function view_load($file, array $Variables = null, $return = false, $autoExtractHeaders = true) { ob_start(); # Incluindo arquivo $fileName = ABSPATH . '/' . APP::getCurrentModule(true) . "/views/{$file}.phtml"; if (!file_exists($fileName)) { throw new Exception("View `{$file}` não existe."); } file_include($fileName, $Variables); # Retornando HTML if ($return) { $Body = ob_get_clean(); if ($autoExtractHeaders) { # Script preg_match_all('/<script.*?<\\/script>/is', $Body, $result); foreach ($result[0] as $html) { Seo::addJs($html); } # Style preg_match_all('/<style.*?<\\/style>/is', $Body, $result); foreach ($result[0] as $html) { Seo::addCss($html); } return preg_replace(['/<style.*?<\\/style>/is', '/<script.*?<\\/script>/is'], null, $Body); } else { return $Body; } } else { ob_end_flush(); } }