public function __construct(Autoload $objAutoload) { $_SESSION['POST'] = serialize($_POST); $_SESSION['GET'] = serialize($_GET); parent::__construct($objAutoload); /* @var $objContent Content */ $objContent = unserialize($_SESSION['objContent']); $arrayFiles = $objAutoload->getClassName(); $module = ucfirst($this->getModule()); $action = ucfirst($this->getAction()); if (empty($module) && empty($action)) { $this->redirectIndex(MODULE_DEFAULT, ACTION_DEFAULT, array()); exit; } $module = empty($module) ? MODULE_DEFAULT : $module; $action = empty($action) ? ACTION_DEFAULT : $action; $className = "Action" . $module; if (!in_array($className . ".php", $arrayFiles)) { echo ERRO_404; $log = new Log(); $log->setLog(__FILE__, $className . ' It was found in line ' . __LINE__ . ' - Module [' . $module . '] does not exist'); return false; } $_SESSION['objContent'] = serialize($objContent); $preActionClass = new ActionGeneral(); $preLoad = new PreLoad($preActionClass); $actionClass = new $className(); $load = new Load($actionClass, $action, $module); }
public function newModule($module) { $module = ucfirst($module); if (is_dir(PATH_LAYOUTS . $module)) { $log = new Log(); $log->setLog(__FILE__, 'The directory of this module already exists: ' . PATH_LAYOUTS . $module); throw new Exception('The directory of this module already exists: ' . PATH_LAYOUTS . $module); } if (is_dir(PATH_MODULES . $module)) { $log = new Log(); $log->setLog(__FILE__, 'The directory of this module already exists: ' . PATH_MODULES . $module); throw new Exception('The directory of this module already exists: ' . PATH_MODULES . $module); } if (is_dir(PATH_TEMPLATES . $module)) { $log = new Log(); $log->setLog(__FILE__, 'The directory of this module already exists: ' . PATH_TEMPLATES . $module); throw new Exception('The directory of this module already exists: ' . PATH_TEMPLATES . $module); } if (is_dir(PATH_WEB . $module)) { $log = new Log(); $log->setLog(__FILE__, 'The directory of this module already exists: ' . PATH_WEB . $module); throw new Exception('The directory of this module already exists: ' . PATH_WEB . $module); } mkdir(PATH_LAYOUTS . $module); mkdir(PATH_MODULES . $module); mkdir(PATH_MODULES . $module . '/lib/'); mkdir(PATH_TEMPLATES . $module); mkdir(PATH_TEMPLATES . $module . '/Includes/'); mkdir(PATH_WEB . $module); mkdir(PATH_WEB . $module . '/css/'); mkdir(PATH_WEB . $module . '/images/'); mkdir(PATH_WEB . $module . '/js/'); $permission = 0777; chmod(PATH_LAYOUTS . $module, $permission); chmod(PATH_MODULES . $module, $permission); chmod(PATH_MODULES . $module . '/lib/', $permission); chmod(PATH_TEMPLATES . $module, $permission); chmod(PATH_TEMPLATES . $module . '/Includes/', $permission); chmod(PATH_WEB . $module, $permission); chmod(PATH_WEB . $module . '/css/', $permission); chmod(PATH_WEB . $module . '/images/', $permission); chmod(PATH_WEB . $module . '/js/', $permission); $templateLayout = $this->getContentTemplate($this->templateLayout); $pathLayout = PATH_LAYOUTS . $module . '/'; WriteToFile::writeContent($templateLayout, $pathLayout, 'index.php', true, true); $templateModule = $this->getContentTemplate($this->templateModule); $templateModule = str_replace("[%module%]", $module, $templateModule); $templateModule = str_replace("[%date%]", date('d/m/Y H:i:s'), $templateModule); $pathModules = PATH_MODULES . $module . '/'; $fileModule = 'Action' . $module . '.php'; WriteToFile::writeContent($templateModule, $pathModules, $fileModule, true, true); $templateTemplate = $this->getContentTemplate($this->templateTemplate); $pathTemplate = PATH_TEMPLATES . $module . '/'; WriteToFile::writeContent($templateTemplate, $pathTemplate, 'index.php', true, true); return true; }
/** * Deletes the image * @param string $directory * @param string $fileName */ public static function removeImage($directory, $fileName) { if (file_exists($directory . $fileName)) { unlink($directory . $fileName); return true; } $log = new Log(); $log->setLog(__FILE__, 'The file ' . $fileName . ' does not exist in the directory ' . $directory); return false; }
/** * Includes a template module * @param String $module * @param String $file * @return String */ public static function includeTemplate($module, $file) { $host = array_key_exists('HTTP_HOST', $_SERVER) ? $_SERVER['HTTP_HOST'] : null; $fileName = PATH . PATH_TEMPLATES . $module . "/" . PATH_INCLUDES . "/" . $file; if (!file_exists($fileName)) { $log = new Log(); $log->setLog(__FILE__, 'File Not Found ' . $fileName, true); throw new Exception('File not Found : ' . $fileName); } require $fileName; }
/** * Grab the contents of the template files * @param String $fileTemplate * @return String */ private function getContentTemplate($fileTemplate) { if (!file_exists($fileTemplate)) { $log = new Log(); $log->setLog(__FILE__, 'Could not find file -> ' . $fileTemplate); throw new Exception('Could not find file -> ' . $fileTemplate); } $open = fopen($fileTemplate, "r"); $contentTemplate = fread($open, filesize($fileTemplate)); fclose($open); return $contentTemplate; }
/** * * @param object $var */ public function __construct($var) { /* @var $objContent Content */ $objContent = unserialize($_SESSION['objContent']); $instance = "ActionGeneral"; if (!$var instanceof $instance) { echo ERRO_404; $log = new Log(); $log->setLog(__FILE__, ' The error occurred on line ' . __LINE__ . ' - Was not found to GeneralAction'); return false; } $_SESSION['objContent'] = serialize($objContent); }
public static function read($isoLang = 'pt_BR') { $file = PATH . PATH_I18N . $isoLang . '.xml'; try { $xml = simplexml_load_file($file); } catch (Exception $e) { $log = new Log(); $log->setLog(__FILE__, 'Could not open file [' . $file . '] for reading :' . $e->getMessage(), true); throw new Exception('Could not open file [' . $file . '] for reading '); } $count = count($xml->item); if ($count == 0) { $log = new Log(); $log->setLog(__FILE__, 'Open file [' . $file . '] is empty ', true); throw new Exception('Open file [' . $file . '] is empty '); } return $xml->item; }
public function executeTeste(Content &$objContent) { $objContent->getObjTemplate()->setLayout('Red'); $objEmail = new Phpmailer(); $body = "Olá mundo."; //$objEmail->IsSendmail(); $objEmail->MsgHTML("Ola Mundo"); $objEmail->AddAddress("*****@*****.**"); $objEmail->SetFrom("*****@*****.**"); $objEmail->Subject = "OKOKO"; if (!$objEmail->Send()) { $log = new Log(); $log->setLog(__FILE__, "Mailer Error: " . $objEmail->ErrorInfo); $this->var2 = "Mailer Error: " . $objEmail->ErrorInfo; } $this->var1 = $this->getRequestParameter('número') * 20; $this->var2 = "Success!!"; $this->forward1 = $this->getRequestParameter('número'); $this->forward2 = $this->getRequestParameter('oba'); $this->link = Headers::linkTo('Default', 'Index', array('culture' => $objContent->getObjCulture()->getCulture())); var_dump(Headers::linkToCss('Default', 'estilos.css')); }
/** * Write the contents of the file * @param String $content * @param String $path * @param String $fileName * @param Boolean $overwrite * @param Boolean $replace * @return Boolean */ public static function writeContent($content, $path, $fileName, $overwrite = true, $replace = true) { self::$path = $path; self::$fileName = $fileName; if (!self::checkPathExists()) { $log = new Log(); $log->setLog(__FILE__, 'The directory is not exists: ' . $path); throw new Exception('The directory is not exists: ' . $path); } if (!self::checkPathPermission()) { $log = new Log(); $log->setLog(__FILE__, 'The directory is not writable: ' . $path); throw new Exception('The directory is not writable: ' . $path); } if (!$overwrite && !$replace && self::checkFileExists()) { return false; } $owner = fileowner($path); $group = filegroup($path); $permission = 0777; $type = "w"; if ($overwrite && !$replace) { $type = "a"; $content = '\\n' . $content; } if ($overwrite && $replace) { @unlink($path . $fileName); } $open = fopen($path . $fileName, $type); fwrite($open, $content); fclose($open); chmod($path . $fileName, $permission); #chown($path.$fileName,$owner); #chgrp($path.$fileName,$group); return true; }
<?php require 'contatos.inc'; require 'database.inc'; $banco = new Database(); $banco->query("insert into contatos (nome, email,telefone, celular, endereco) values ('" . $_POST['nome'] . "','" . $_POST['email'] . "','" . $_POST['telefone'] . "','" . $_POST['celular'] . "','" . $_POST['endereco'] . "')"); include_once 'CacheArquivo.php'; include_once 'CacheSessao.php'; require 'log.inc'; $log = new Log(); $log->setLog($_COOKIE['chave'], date('Y-m-d H:i:s'), " "); $sql = $banco->query("insert into log (usuario,hora,acao) values ('" . $_COOKIE['chave'] . "','" . $log->getHora() . "','Inseriu contato')"); function guardar_valor(Cache $cache, $chave, $valor) { $cache->set_valor($chave, $valor); } function recuperar_valor(Cache $cache, $chave) { return $cache->get_valor($chave); } $cacheArquivo = new CacheArquivo(); $cacheSessao = new CacheSessao(); $sql = $banco->query("Select * from contatos"); while ($resultado = mysql_fetch_assoc($sql)) { $contato[] = array('nome' => $resultado['nome'], 'email' => $resultado['email'], 'telefone' => $resultado['telefone'], 'celular' => $resultado['celular'], 'endereco' => $resultado['endereco'], 'id' => $resultado['id']); } $dados_para_cache = array('contatos' => $contato); $valor = json_encode($dados_para_cache); $chave = $_COOKIE['chave']; guardar_valor($cacheArquivo, $chave, $valor); guardar_valor($cacheSessao, $chave, $valor);
/** * Forward the page to another * @param String $module * @param String $action * @param Content $objContent */ public function forward($module, $action) { /* @var $autoLoad Autoload */ $autoLoad = new Autoload(); $arrayFiles = $autoLoad->getClassName(); $module = ucfirst(strtolower($module)); $action = ucfirst($action); $module = empty($module) ? MODULE_DEFAULT : $module; $action = empty($action) ? ACTION_DEFAULT : $action; $className = "Action" . $module; if (!in_array($className . ".php", $arrayFiles)) { echo ERRO_404; $log = new Log(); $log->setLog(__FILE__, $className . ' It was found in line ' . __LINE__ . ' - Module [' . $module . '] does not exist'); return false; } $class = new $className(); $load = new Load($class, $action, $module); }
/** * Throw an error and logs exceptions * @param message[optional] * @param code[optional] * @param previous[optional] */ public function __construct($file = null, $message = null, $code = null, $previous = null) { $log = new Log(); $log->setLog($file, $message, true); parent::__construct($message, $code, $previous); }
/** * Checks the file exists and * @param String $file */ public function checkFilesExists($file) { $url = new Url(); $module = $url->getModule(); if (is_null($file) || $module == 'General') { return false; } if (!is_file($file)) { $log = new Log(); $log->setLog(__FILE__, 'Unable to get the contents of the template because it does not exist. -> ' . $file, true); return false; } return true; }
/** * * @param object $var * @param string $action * @param string $module */ public function __construct($var, $action, $module) { /* @var $objContent Content */ $objContent = unserialize($_SESSION['objContent']); $instance = "Action" . $module; if (!$var instanceof $instance) { echo ERRO_404; $log = new Log(); $log->setLog(__FILE__, ' The error occurred on line ' . __LINE__ . ' - Module [' . $module . '] does not exist'); return false; } $method = "execute" . $action; if (!method_exists($var, $method)) { echo ERRO_404; $log = new Log(); $log->setLog(__FILE__, ' The error occurred on line ' . __LINE__ . ' - Method [' . $method . '] does not exist'); return false; } $template = new Template(); $template->setModule($module); $template->setAction($action); $template->setLayout(); $objContent->setInformationLoad(array($var, $method)); $objContent->setTemplate($template); if (method_exists($var, 'preExecute')) { $var->preExecute($objContent); } $returnAction = $var->{$method}($objContent); $moduleTemplate = $objContent->getObjTemplate()->getModule(); $moduleTemplate = empty($moduleTemplate) ? $module : $objContent->getObjTemplate()->getModule(); $actionTemplate = $objContent->getObjTemplate()->getAction(); $actionTemplate = empty($actionTemplate) ? $action : $objContent->getObjTemplate()->getAction(); if ($moduleTemplate != $module) { $template->setModule($moduleTemplate); } if ($actionTemplate != $action) { $template->setAction($actionTemplate); } $objContent->setHasLayout($returnAction); $objContent->typeLayout($returnAction); if ($returnAction == ViewActions::VIEW_SUCCESS || is_null($returnAction)) { $file = PATH . PATH_TEMPLATES . $moduleTemplate . "/" . preg_replace(array('/^[A-Z]/'), strtolower($actionTemplate[0]), $actionTemplate) . ".php"; } if ($returnAction == ViewActions::VIEW_ERROR) { $file = PATH . PATH_TEMPLATES . $moduleTemplate . "/" . preg_replace(array('/^[A-Z]/'), strtolower($actionTemplate[0]), $actionTemplate) . "Error.php"; } if ($returnAction != ViewActions::VIEW_NONE && !is_file($file)) { if (!$var instanceof ActionGeneral) { echo ERRO_404; $log = new Log(); $log->setLog(__FILE__, ' The error occurred on line ' . __LINE__ . ' - The template file not found: [' . $file . ']'); return false; } } $templateRead = new TemplateRead(); $templateRead->getContentFromLayout($template->getPathLayout(), $var); if (isset($file)) { $templateRead->getContentFromTemplate($file, $var); } echo $templateRead->getContentFromMerge(); if (method_exists($var, 'endExecute')) { $var->endExecute($objContent); } $objContent->getObjTemplate()->setTemplateAction(null, null); try { $_SESSION['objContent'] = serialize($objContent); } catch (Exception $e) { $log = new Log(); $log->setLog(__FILE__, ' The error occurred on line ' . __LINE__ . ' - Serialize Session fail: [' . $file . '] - Message Error: ' . $e->getMessage()); } }
require 'database.inc'; require 'usuario.inc'; $usuario = new Usuario(); $usuario->setUsuario($_POST['usuario'], $_POST['senha']); $banco = new Database(); $sql = $banco->query("Select nome, username From usuarios where username='******' and senha='" . $usuario->getSenha() . "'"); $user = mysql_fetch_assoc($sql); if (empty($user)) { echo "Usuario e senha invalidos!"; } else { setcookie('chave', $usuario->getUser()); include_once 'CacheArquivo.php'; include_once 'CacheSessao.php'; require 'log.inc'; $log = new Log(); $log->setLog($usuario->getUser(), date('Y-m-d H:i:s'), "Efetuou login"); $sql = $banco->query("insert into log (usuario,hora,acao) values ('" . $usuario->getUser() . "','" . $log->getHora() . "','Efetuou Login')"); function guardar_valor(Cache $cache, $chave, $valor) { $cache->set_valor($chave, $valor); } function recuperar_valor(Cache $cache, $chave) { return $cache->get_valor($chave); } $cacheArquivo = new CacheArquivo(); $cacheSessao = new CacheSessao(); $sql = $banco->query("Select * from contatos"); while ($resultado = mysql_fetch_assoc($sql)) { $contato[] = array('nome' => $resultado['nome'], 'email' => $resultado['email'], 'telefone' => $resultado['telefone'], 'celular' => $resultado['celular'], 'endereco' => $resultado['endereco'], 'id' => $resultado['id']); }