/** * Exibe uma div normal do html, mas adiciona uma variavel de template "var" * e fecha a tag: * * Ex.: << div class="blue" var=$text >> * * Result: <div class="blue">Text Value</div> * * @param $params * @param $smarty * @return string */ function smarty_function_label($params, &$smarty) { $str = "<label "; $ai = new ArrayIterator($params); while ($ai->valid()) { $exibir = true; foreach (Samus::getLangs() as $lang) { if ($ai->key() == $lang || $ai->key() == "var") { $exibir = false; break; } } if ($exibir) { $str .= $ai->key() . "='" . str_replace("'", '"', $ai->current()) . "' "; } $ai->next(); } $str .= ">" . $params["var"] . $params[$_SESSION["lang"]] . "</label>"; return $str; }
/** * @see Samus_Controller::assignClass() * * @param string $directory nome do arquivo de template sem a extensão * @param string $metodo * @param array $args */ public function assignClass($directory = "", $metodo = "", array $args = array()) { $ref = new ReflectionClass($this); if (!empty($metodo)) { /*@var $refMetodo ReflectionMethod*/ $refMetodo = $ref->getMethod($metodo); $refMetodo->invoke($this, $args); } $ref = new ReflectionObject($this); $met = $ref->getMethods(); $ai = new ArrayIterator($met); $minhaArray = array(); while ($ai->valid()) { $metName = $ai->current()->getName(); if (substr($metName, 0, 3) == "get" && $metName[3] != "_") { $prop = substr($metName, 3); $prop = strtolower(substr($prop, 0, 1)) . substr($prop, 1); $minhaArray[$prop] = $ai->current()->invoke($this); /** * Atribui para a classe de visão todas as propriedades do * objeto depois de executar o método especificado (aki é a * chave do negócio) */ $this->smarty->assign($prop, $ai->current()->invoke($this)); } $ai->next(); } $properties = $ref->getProperties(); foreach ($properties as $prop) { /*@var $prop ReflectionProperty */ if ($prop->isPublic()) { $this->smarty->assign($prop->getName(), $prop->getValue($this)); } } $directory = str_replace(Samus::getViewsDirectory() . "/", "", $directory); $this->smarty->display($directory); }
/** * Especifica o arquivo que servira como visão * @param string $templateFile */ public function setTemplateFile($templateFile) { if (substr($templateFile, count(Samus::getViewFileExtension()) * -1, count(Samus::getViewFileExtension())) != Samus::getViewFileExtension()) { $templateFile .= Samus::getViewFileExtension(); } $this->templateFile = $templateFile; }
public function getNumPages() { $r = CRUD::query("SELECT COUNT(*) as cont FROM " . Samus::getTablePrefix() . "pagina_categoria WHERE categoria=" . $this->getId()); $total = $r[0]['cont']; if (empty($total)) { $total = 0; } return $total; }
/** * Pontos representam o numero * @return int */ public function getPontos() { $r = CRUD::query("SELECT count(*) as cont FROM " . Samus::getTablePrefix() . "pagina_conteudo_tag WHERE conteudoTag=" . $this->getId()); return $r[0]['cont']; }
/** * Especifica o host * @param string $httpHost */ public static function setHttpHost($httpHost) { self::$httpHost = $httpHost; }
/** * Inclui o arquivo correto do site * * @param string $pageName */ public function displayPage() { $filterClass = ""; $url = self::getUrl(); if (empty($url[0])) { $url[0] = $this->getDefaultPage(); } $urlDir = explode("/", $url[0]); $directory = ""; if (count($urlDir) > 1) { $directory = ""; $className = array_pop($urlDir); $className = ucfirst($className); // encontro os metodos da url $metodos = explode(Samus::getMethodUrlSeparator(), $className); $className = $metodos[0]; unset($metodos[0]); foreach ($urlDir as $dir) { $directory .= $dir . "/"; } /******************************************************************* * CLASSE FILTRO * classes de filtro devem ter o mesmo nome do pacote (mas com a * primeira maiuscula) seguidas do sufixo definido em Samus::$filterSufix * e são sempre inseridos e executados quando qualquer classe do pacote * são inseridas ******************************************************************/ $filterClass = ucfirst($urlDir[count($urlDir) - 1]); $filterClass .= Samus::getFilterSufix(); } else { $className = ucfirst($url[0]); // encontro os metodos da url $metodos = explode(Samus::getMethodUrlSeparator(), $className); $className = $metodos[0]; unset($metodos[0]); } /********************************************************************** * INCLUSÃO DO FILTRO * as classes de filtro devem ter o mesmo nome do pacote e devem imple- * mentar a interface Samus_Filter *********************************************************************/ $filterFile = Samus::getControlsDirectory() . '/' . $directory . $filterClass . Samus::getControlsFileExtension(); /************************************************************************ * CLASSE FILTRO DEFAULT * caso não tenha um filtro associado ele busca o filtro padrão ************************************************************************/ if (!is_file($filterFile)) { $filterClass = Samus::getDefaultFilterClass(); $filterFile = Samus::getControlsDirectory() . '/' . $directory . $filterClass . Samus::getControlsFileExtension(); } $classFile = $className; //nome do arquivo $className = UtilString::underlineToUpper($className); //nome da classe if (Samus::isDecodeUTF8Strings()) { $className = utf8_decode($className); } $className = CleanString::clean($className, true); $className .= Samus::getControlsClassSufix(); $className = ucfirst($className); self::$controllerName = $className; $filtred = false; if (is_file($filterFile)) { require_once $filterFile; $ref = new ReflectionClass($filterClass); if ($ref->getParentClass()->getName() != "Samus_Filter") { throw new Exception("A interface Samus_Filter deve ser implementada nos filtros"); } $filtroObj = $ref->newInstance(); $this->filter = $filtroObj; $met = $ref->getMethod("getExceptions"); /*@var $met ReflectionMethod*/ $exceptionsPages = $met->invoke($filtroObj); $flickThisSamus_Controller = true; foreach ($exceptionsPages as $control) { if (strtolower($control) == strtolower($className)) { $flickThisSamus_Controller = false; break; } } // se a página não for uma exeção if ($flickThisSamus_Controller) { $met = $ref->getMethod("filter"); $met->invoke($filtroObj); } $filtred = true; } $requireFile = Samus::getControlsDirectory() . '/' . $directory . $className . Samus::getControlsFileExtension(); if (is_file($requireFile)) { require_once $requireFile; $ref = new ReflectionClass($className); $obj = $ref->newInstance(); if ($filtred) { $met = $ref->getMethod("setGlobal"); $met->invoke($obj, $this->filter); } if (!empty($metodos)) { foreach ($metodos as $met) { $metParametros = explode(Samus::getMethodUrlParameterSeparator(), $met); $met = $metParametros[0]; unset($metParametros[0]); $met = UtilString::underlineToUpper($met); //nome da classe if (Samus::isDecodeUTF8Strings()) { $met = utf8_decode($met); } $met = CleanString::clean($met, true); $met = $met . Samus::getMethodUrlSufix(); if (!method_exists($obj, $met)) { // throw new Samus_Exception("O metodo $met não existe na classe $className"); } else { $urlMet = $ref->getMethod($met); if (!empty($metParametros)) { if (Samus::isDecodeUTF8Strings()) { foreach ($metParametros as $key => $m) { $metParametros[$key] = utf8_decode($m); } } try { $urlMet->invokeArgs($obj, $metParametros); } catch (ReflectionException $ex) { throw new Samus_Exception("Você não tem permissão para acessar este metodo ou ele é invalido " . $ex->getMessage()); } } else { try { $urlMet->invoke($obj); } catch (ReflectionException $ex) { throw new Samus_Exception("Você não tem permissão para acessar este metodo ou ele é invalido " . $ex->getMessage()); } } } } } /*@var $met ReflectionMethod*/ $met = $ref->getMethod("index"); $met->invoke($obj); $met = $ref->getMethod("assignClass"); $met->invoke($obj, $directory); } else { /*************************************************************** * EXIBIÇÃO DE ARQUIVOS SEM CONTROLADORES ASSOCIADOS **************************************************************/ //$className = strtolower(substr($className, 0, 1)) . substr($className,1); //caso seja um arquivo ajax $ajaxTamanho = strlen(Samus::getAjaxPhpFileExtension()); $nClassName = str_replace(Samus::getControlsClassSufix(), "", $className); if (substr($nClassName, $ajaxTamanho * -1, $ajaxTamanho) == Samus::getAjaxPhpFileExtension()) { require_once Samus::getAjaxPhpFilesDirectory() . '/' . $classFile; } else { //caso seja um arquivo de template if (empty($className)) { $className = $this->getDefaultPage(); } if (substr($className, -8, 8) == '.inc.php') { $requireViewFile = Samus::getViewsDirectory() . '/' . strtolower($className); require $requireViewFile; } else { $requireViewFile = Samus::getViewsDirectory() . '/' . $directory . UtilString::upperToUnderline($classFile) . Samus::getViewFileExtension(); if (is_file($requireViewFile)) { require_once 'samus/Samus_DefaultController' . Samus::getControlsFileExtension(); $ref = new ReflectionClass("Samus_DefaultController"); $obj = $ref->newInstance(); /*@var $met ReflectionMethod*/ $met = $ref->getMethod("index"); $met->invoke($obj); if ($filtred) { $met = $ref->getMethod("setGlobal"); $met->invoke($obj, $filtroObj); } $met = $ref->getMethod("assignClass"); $met->invoke($obj, $requireViewFile); } else { require_once 'util/Util.php'; //echo "<h1 align='center'>Página não Encontrada!</h1>"; //echo "<h2 align='center'>".$_SERVER['REQUEST_URI']."</h2>"; $strA = ''; foreach (Samus::getURL() as $st) { $strA .= $st . '-'; } $strA = substr($strA, 0, -1); if (substr($strA, -5) != "index") { echo "Requisição não processada"; } else { //Util::redirect($this->errorPage.'-'.Samus::getURL(0), 0); } } } } } }
/** * Carrega um arquivo JavaScript * @param $params * @param $smarty * @return string */ function smarty_function_load_js($params, &$smarty) { return '<script type="text/javascript" src="' . WEB_DIR . Samus::getJavaScriptDirectory() . '/' . $params['src'] . '"></script>'; }
/** * Obtem um formulário simples para um objeto DAO * * @param object $object * @return string */ public static function htmlForm($object, $objectName = 'obj') { $crud = $object->getDao()->myCRUD(); $str = "\r\n<fieldset>\r\n\t<legend>" . ucwords(UtilString::upperToSpace($crud->getClassName())) . "</legend>\r\n "; $str .= "<form method='post' action=''>\r\n "; foreach ($crud->getAtributes() as $atr) { if ($atr == "id") { $str .= "<input type='hidden' name='id' value='" . Samus::getLeftDelimiter() . " \$" . $objectName . "->{$atr}. " . Samus::getRightDelimiter() . "' />\r\n "; } else { $str .= "<label for='{$atr}'>" . UtilString::underlineToSpace(UtilString::upperToSpace($atr)) . '</label> '; $str .= "<input type='text' name='{$atr}' value='" . Samus::getLeftDelimiter() . " \$" . $objectName . "->{$atr} " . Samus::getRightDelimiter() . "' />\r\n\t\t<br />\r\n \r\n "; } } $str .= "\r\n <label for='action'></label>\r\n <input type='submit' name='action' value='Confirmar'>\r\n "; $str .= "</form>\r\n</fieldset>\r\n "; return $str; }
<?php /******************************************************************************* * CONFIGURA��O�ES DO FRAMEWORK * -------------------------------------- * Inicia��o do frame ******************************************************************************/ require_once 'configs/config.inc.php'; require_once 'classes/samus/Samus.php'; Samus::init(); Samus::close();