Interface Decorator { static function decorate($valor = ""); } ?> class ConfigManager { private static $instancia; private static $config; private static $environment = ""; private function __construct() { global $config; $staticConfig = parse_ini_file(_DEFAULT_CONFIGURATION_FILE, true); if ($staticConfig) { foreach($staticConfig as $param=>$value) { $config[ $param ] = $value; } if (!empty($config["environment"])) { self::$environment = $config["environment"]; } } self::$config = $config; } public static function getInstance() { global $config; self::$config = $config; if (!empty($config["environment"])) { self::$environment = $config["environment"]; } if (!self::$instancia instanceof self) { self::$instancia = new self; } return self::$instancia; } public static function getAll() { if (!empty(self::$environment)) { $configs = array(); foreach (self::$config as $param => $value) { $configs[ str_replace(".".self::$environment, "", $param) ] = self::get($param); } return $configs; } else { return self::$config; } } public static function get($param) { if (!empty(self::$environment)) { if (isset(self::$config[ $param.".".self::$environment ])) { return self::$config[ $param.".".self::$environment ]; } else if (isset(self::$config[ $param ])) { return self::$config[ $param ]; } } else if (isset(self::$config[ $param ])) { return self::$config[ $param ]; } else { return null; } } public static function getAllFor($module) { if (isset(self::$config["modules"][ $module ])) { return self::$config["modules"][ $module ]; } else { return null; } } public static function getFor($module, $property, $simple=false) { if ($simple) { if (isset(self::$config["modules"][ $module ][ $property ])) { return self::$config["modules"][ $module ][ $property ]; } } if ((!empty(self::$environment))&&(empty($module))) { self::$config["modules"][ $property.".".self::$environment ]; } else if (isset(self::$config["modules"][ $module ][ $property ])) { self::$config["modules"][ $module ][ $property ]; } else { return null; } } } class Session { static function init() { @session_start(); } static function get($param) { self::init(); if (isset($_SESSION[ $param ])) { return $_SESSION[ $param ]; } else { return null; } } static function remove($key) { self::init(); unset($_SESSION[$param]); } static function set($param, $value) { self::init(); $_SESSION[$param] = $value; } static function store( $key, $params ) { self::init(); $_SESSION[ $key ] = $params; } static function recover( $key ) { self::init(); if (isset($_SESSION[ $key ])) { return $_SESSION[ $key ]; } else { return null; } } } class PropertiesManager { private static $instancia; private static $lang; private function __construct() { self::loadFile( _DEFAULT_PROPERTIES_FILE ); } public static function loadFile( $fileName ) { global $lang; if (file_exists($fileName)) { $staticProperties = parse_ini_file($fileName, true); if (!isset($staticProperties[ ConfigManager::getInstance()->get("languaje") ])) { // get the first one $langs = array_keys($staticProperties); if (count( $langs ) >= 0) { $staticProperties = $staticProperties[ $langs[0] ]; } else { return; } } else { $staticProperties = $staticProperties[ ConfigManager::getInstance()->get("languaje") ]; } if ($staticProperties) { foreach($staticProperties as $key=>$value) { $lang[ $key ] = $value; } } } self::$lang = $lang; } public static function getInstance() { if (!self::$instancia instanceof self) { self::$instancia = new self; } return self::$instancia; } public static function getAll() { return self::$lang; } public static function get( $param ) { if (isset(self::$lang[ $param ])) { return self::$lang[ $param ]; } else { return $param; } } } /** * Clase con funciones utiles * version 3.9 * Agregada funcion createFilterInFromArray * version 3.8 * Agregada funcion orderMultiDimensionalArray * version 3.7 * Agregada funcion compararFechas * version 3.6 * Reemplazo de la funcion split (deprecated > 5.3) por explode * version 3.5 * Agregadas funciones: obtenerNumeroEnteroDeUnaFecha, array_orderby * version 3.4 * Agregadas funciones: cleanSlashes, stripslashes_deep, fullhtmlentities * @author Adrián Prause para www.mediaclic.com.ar */ class Utils { static function daysBetween($date1, $date2) { $date1=str_replace("/","-",$date1); $date2=str_replace("/","-",$date2); $dias= (@strtotime($date1)-@strtotime($date2))/86400; $dias = abs($dias); $dias = floor($dias); return $dias; } static function createFilterInFromArray($theList) { $i = 0; if (!empty($theList)) { if (is_array($theList)) { foreach($theList as $key => $value) { if ($i == 0) { if (is_integer($value)) $filter = "0"; if (is_string($value)) $filter.=""; $i++; } if (is_integer($value)) $filter.=",".$value; if (is_string($value)) $filter.=",".$value.""; } } } else { return null; } return $filter; } static function isValidURL($strURL) { if( preg_match( '/^(http|https|ftp):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}' .'((:[0-9]{1,5})?\/.*)?$/i' ,$strURL)) { return true; } else { return false; } } static function slug($text, $puntos=0){ if (is_string($text) || is_numeric($text)) { // replace non letter or digits by - $text = preg_replace('~[^\pL\d]+~u', '-', $text); // transliterate $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text); // remove unwanted characters $text = preg_replace('~[^-\w]+~', '', $text); // trim $text = trim($text, '-'); // remove duplicate - $text = preg_replace('~-+~', '-', $text); // lowercase $text = strtolower($text); if (empty($text)) { return 'n-a'; } return $text; } else { } } static function isInteger($value){ if (preg_match("^([0-9]+)$",$value)) return 1; else return 0; } function isIntegerOfSize($value,$size){ if (preg_match("[0-9]{".$size."}",$value)) return 1; else return 0; } static function lastDayOfMonth($month,$year){ $lastDay=28; while (checkdate($$month,$lastDay + 1,$year)){ $lastDay++; } return $lastDay; } static function fechaMesesAntes($meses){ return date( "d/m/Y", mktime(0,0,0, date("m")-$meses, date("d"), date("Y"))); } static function lastMonth(){ return date( "d/m/Y", mktime(0,0,0, date("m")-1, date("d"), date("Y"))); } static function isCorrectDate($theDate){ if (strlen($theDate)<10) return 0; $f1=substr($theDate,2,1); $f2=substr($theDate,5,1); if ( ($f1!="/") || ($f2!="/") ) return 0; list ($d,$m,$a)=explode("/",$theDate); if ($d>31) return 0; if ($m>12) return 0; return 1; } static function dateFormat($theDate,$type){ if ($type=="PHP") { if ($theDate==""){ return ""; } else { preg_match( "([0-9]{2,4})-([0-9]{1,2})-([0-9]{1,2})", $theDate, $myDate); $newDate=$myDate[3]."/".$myDate[2]."/".$myDate[1]; return $newDate; } } else { if ($theDate==""){ return ""; }else{ preg_match( "([0-9]{1,2})/([0-9]{1,2})/([0-9]{2,4})", $theDate, $myDate); $newDate=$myDate[3]."-".$myDate[2]."-".$myDate[1]; return $newDate; } } } static function dump($x){ echo "
"; var_dump($x); echo ""; } static function isValidEmail($email){ $mail_correcto=0; //compruebo unas cosas primeras if ((strlen($email) >= 6) && (substr_count($email,"@") == 1) && (substr($email,0,1) != "@") && (substr($email,strlen($email)-1,1) != "@")){ if ((!strstr($email,"'")) && (!strstr($email,"\"")) && (!strstr($email,"\\")) && (!strstr($email,"\$")) && (!strstr($email," "))) { //miro si tiene caracter . if (substr_count($email,".")>= 1){ //obtengo la terminacion del dominio $term_dom=substr(strrchr ($email, '.'),1); //compruebo que la terminación del dominio sea correcta if (strlen($term_dom)>1 && strlen($term_dom)<5 && (!strstr($term_dom,"@")) ){ //compruebo que lo de antes del dominio sea correcto $antes_dom=substr($email,0,strlen($email) - strlen($term_dom) - 1); $caracter_ult=substr($antes_dom,strlen($antes_dom)-1,1); if ($caracter_ult != "@" && $caracter_ult != "."){ $mail_correcto=1; } } } } } if ($mail_correcto) return 1; else return 0; } static function isNum($var) { if (is_numeric($var)) { return 1; } else return false; } static function cleanSlashes(&$data) { if (get_magic_quotes_gpc()) { $data = array_map('stripslashes_deep', $data); } } static function stripslashes_deep($value) { $value = is_array($value)?array_map('stripslashes_deep', $value):stripslashes($value); return $value; } static function fullhtmlentities(&$value) { if (is_array($value)) return $value; $value = @is_array($value)?@array_map('htmlentities', $value):@htmlentities ($value); return $value; } static function orderMultiDimensionalArray ($toOrderArray, $field, $inverse = false) { $position = array(); $newRow = array(); foreach ($toOrderArray as $key => $row) { $position[$key] = $row[$field]; $newRow[$key] = $row; } if ($inverse) { arsort($position); } else { asort($position); } $returnArray = array(); foreach ($position as $key => $pos) { $returnArray[] = $newRow[$key]; } return $returnArray; } /** * */ static function getLocationDate($location = 'Posadas') { $nro_dia = date ( 'w' ); $nro_mes = date ( 'n' ); $nro_anio = date ( 'Y' ); $listado_dias = self::getDays (); $listado_meses = self::getMonths (); $lugar_y_fecha = $location . ', ' . $listado_dias [$nro_dia] . ' ' . date ( 'j' ) . ' de ' . $listado_meses [$nro_mes] . ' de ' . $nro_anio; return $lugar_y_fecha; } static function getDays() { $listado_dias = array (); $listado_dias [0] = 'Domingo'; $listado_dias [1] = 'Lunes'; $listado_dias [2] = 'Martes'; $listado_dias [3] = 'Miercoles'; $listado_dias [4] = 'Jueves'; $listado_dias [5] = 'Viernes'; $listado_dias [6] = 'Sabado'; return $listado_dias; } static function getMonths() { $listado_meses = array (); $listado_meses [1] = 'Enero'; $listado_meses [2] = 'Febrero'; $listado_meses [3] = 'Marzo'; $listado_meses [4] = 'Abril'; $listado_meses [5] = 'Mayo'; $listado_meses [6] = 'Junio'; $listado_meses [7] = 'Julio'; $listado_meses [8] = 'Agosto'; $listado_meses [9] = 'Septiembre'; $listado_meses [10] = 'Octubre'; $listado_meses [11] = 'Noviembre'; $listado_meses [12] = 'Diciembre'; return $listado_meses; } /** * * Formato gerenal de numeros. * Por defecto formatea el numero con dos decimales, coma para separar decimales, sin separador de miles * @param number|float $number * @param number $decimals * @param char $dec_point * @param char $thousands_sep * @param bool $is_money */ static function formatNumber($number, $decimals = 2, $dec_point = ',', $thousands_sep = '.',$is_money = false) { if (!empty($number)) { $v = number_format($number,$decimals,$dec_point,$thousands_sep); } else { return ''; } if ($is_money) { return '$ '.$v; } else { return $v; } } static function getCurrentDate() { return @date("d/m/Y"); } } /*3.0*/ class image{ var $OriginalImage=""; var $ImageType=""; var $DestinationName=""; var $DestinationType=""; var $Width=""; var $Height=""; var $WaterMark=""; function setOriginalImage($OriginalImage){ $this->OriginalImage=$OriginalImage; } function getOriginalImage(){ return $this->OriginalImage; } function setImageType($ImageType){ $this->ImageType=$ImageType; } function getImageType(){ return $this->ImageType; } function setDestinationName($DestinationName){ $this->DestinationName=$DestinationName; } function getDestinationName(){ return $this->DestinationName; } function setWidth($Width){ $this->Width=$Width; } function getWidth(){ return $this->Width; } function setHeight($Height){ $this->Height=$Height; } function getHeight(){ return $this->Height; } function setWaterMark($WaterMark){ $this->WaterMark=$WaterMark; } function getWaterMark(){ return $this->WaterMark; } function getInfo(){ return getimagesize($this->getOriginalImage(), $info); } function copyImage(){ copy($this->getOriginalImage(), $this->getDestinationName()); } function getSource(){ $info=$this->getInfo(); if ($info["mime"]=="image/gif"){ $src = ImageCreateFromGif($this->getOriginalImage()); } else if ($info["mime"]=="image/pjpeg"){ $src = ImageCreateFromJpeg($this->getOriginalImage()); } else if ($info["mime"]=="image/jpeg"){ $src = ImageCreateFromJpeg($this->getOriginalImage()); } else if ($info["mime"]=="image/bmp"){ $src = ImageCreateFromwBmp($this->getOriginalImage()); } else if ($info["mime"]=="image/png"){ $src = ImageCreateFrompng($this->getOriginalImage()); } return $src; } function Resize(){ $info=$this->getInfo(); $this->copyImage(); $dst = ImageCreateTrueColor($this->getWidth(), $this->getHeight()); ImageCopyResampled($dst, $this->getSource(), 0, 0, 0, 0, $this->getWidth(), $this->getHeight(), $info[0], $info[1]); ImageJpeg($dst, $this->getDestinationName(), 95); ImageDestroy($dst); } function Fit(){ $info=$this->getInfo(); $this->copyImage(); if ($info[0]>=$info[1]){ //mas ancho que alto $proporcion=$info[1] / $info[0]; $this->setHeight( intval($this->getWidth()*$proporcion) ); } else { //mas alto que ancho $proporcion=$info[0] / $info[1]; $this->setWidth( intval($this->getHeight()*$proporcion) ); } $dst = ImageCreateTrueColor($this->getWidth(), $this->getHeight()); ImageCopyResampled($dst, $this->getSource(), 0, 0, 0, 0, $this->getWidth(), $this->getHeight(), $info[0], $info[1]); if ($this->getWaterMark()!=""){ ImageAlphaBlending($dst, true); $sizem = GetImageSize($this->getWaterMark()); /* ubica en el centro $x=($ancho-$sizem[0])/2; $y=($alto-$sizem[1])/2; $src = ImageCreateFrompng($marca); imagecopy ( $dst, $src, $x, $y, 0, 0, $sizem[0], $sizem[1] ); */ $x=($this->getWidth()-$sizem[0]); $y=($this->getHeight()-$sizem[1]); $src = ImageCreateFrompng($this->getWaterMark()); imagecopy ( $dst, $src, $x, $y, 0, 0, $sizem[0], $sizem[1] ); } ImageJpeg($dst, $this->getDestinationName(), 95); ImageDestroy($dst); } function ResizeToWidth(){ $info=$this->getInfo(); $this->copyImage(); $proporcion=$info[1] / $info[0]; $this->setHeight( intval($this->getWidth()*$proporcion) ); $dst = ImageCreateTrueColor($this->getWidth(), $this->getHeight()); ImageCopyResampled($dst, $this->getSource(), 0, 0, 0, 0, $this->getWidth(), $this->getHeight(), $info[0], $info[1]); if ($this->getWaterMark()!=""){ ImageAlphaBlending($dst, true); $sizem = GetImageSize($this->getWaterMark()); /* ubica en el centro $x=($ancho-$sizem[0])/2; $y=($alto-$sizem[1])/2; $src = ImageCreateFrompng($marca); imagecopy ( $dst, $src, $x, $y, 0, 0, $sizem[0], $sizem[1] ); */ $x=($this->getWidth()-$sizem[0]); $y=($this->getHeight()-$sizem[1]); $src = ImageCreateFrompng($this->getWaterMark()); imagecopy ( $dst, $src, $x, $y, 0, 0, $sizem[0], $sizem[1] ); } ImageJpeg($dst, $this->getDestinationName(), 95); ImageDestroy($dst); } function ResizeToHeight(){ $info=$this->getInfo(); $this->copyImage(); $proporcion=$info[0] / $info[1]; $this->setWidth( intval($this->getHeight()*$proporcion) ); $dst = ImageCreateTrueColor($this->getWidth(), $this->getHeight()); ImageCopyResampled($dst, $this->getSource(), 0, 0, 0, 0, $this->getWidth(), $this->getHeight(), $info[0], $info[1]); if ($this->getWaterMark()!=""){ ImageAlphaBlending($dst, true); $sizem = GetImageSize($this->getWaterMark()); /* ubica en el centro $x=($ancho-$sizem[0])/2; $y=($alto-$sizem[1])/2; $src = ImageCreateFrompng($marca); imagecopy ( $dst, $src, $x, $y, 0, 0, $sizem[0], $sizem[1] ); */ $x=($this->getWidth()-$sizem[0]); $y=($this->getHeight()-$sizem[1]); $src = ImageCreateFrompng($this->getWaterMark()); imagecopy ( $dst, $src, $x, $y, 0, 0, $sizem[0], $sizem[1] ); } ImageJpeg($dst, $this->getDestinationName(), 95); ImageDestroy($dst); } function FitIfBigger(){ $info=$this->getInfo(); $this->copyImage(); if (($info[0]<$this->getWidth())||($info[1]<$this->getHeight())) { $this->setWidth($info[0]); $this->setHeight($info[1]); } else { if ($info[0]>=$info[1]){ //mas ancho que alto $proporcion=$info[1] / $info[0]; $this->setHeight( intval($this->getWidth()*$proporcion) ); } else { //mas alto que ancho $proporcion=$info[0] / $info[1]; $this->setWidth( intval($this->getHeight()*$proporcion) ); } } $dst = ImageCreateTrueColor($this->getWidth(), $this->getHeight()); ImageCopyResampled($dst, $this->getSource(), 0, 0, 0, 0, $this->getWidth(), $this->getHeight(), $info[0], $info[1]); if ($this->getWaterMark()!=""){ ImageAlphaBlending($dst, true); $sizem = GetImageSize($this->getWaterMark()); /* ubica en el centro $x=($ancho-$sizem[0])/2; $y=($alto-$sizem[1])/2; $src = ImageCreateFrompng($marca); imagecopy ( $dst, $src, $x, $y, 0, 0, $sizem[0], $sizem[1] ); */ $x=($this->getWidth()-$sizem[0]); $y=($this->getHeight()-$sizem[1]); $src = ImageCreateFrompng($this->getWaterMark()); imagecopy ( $dst, $src, $x, $y, 0, 0, $sizem[0], $sizem[1] ); } ImageJpeg($dst, $this->getDestinationName(), 95); ImageDestroy($dst); } } /* $image=new image; $image->setOriginalImage("sin_foto.jpg"); $image->setDestinationName("estrella2.jpg"); $image->setWidth(126); $image->setHeight(86); $image->Resize(); //Redimensiona deformando a las medidas pasadas $image->Fit(); //Redimensiona proporcionalmente dentro del recuadro de las medidas pasadas */ class ActionManager { const AJAX = "ajax"; const FULL = "full"; const PARAM_FOR_ACTION = "action"; const PARAM_FOR_MODE = "mode"; static $module = "CMS"; static $method = "main"; static $mode = "full"; static $action; function __construct() { if (isset($_REQUEST[self::PARAM_FOR_ACTION])) { self::$action = $_REQUEST[self::PARAM_FOR_ACTION]; if (!strpos(self::$action,"::")) self::$action .= "::main"; list(self::$module, self::$method)=explode('::', self::$action); } else { self::$action = ""; } } static function isDefined() { return (isset($_REQUEST[self::PARAM_FOR_ACTION])); } static function getModule() { $action = (isset($_REQUEST[self::PARAM_FOR_ACTION])) ? $_REQUEST[self::PARAM_FOR_ACTION] : ""; if ($action == "") return self::$module; if (!strpos($action,"::")) $action .= "::main"; list($module, $method)=explode('::', $action); return ucFirst($module); } static function getMethod() { $action = (isset($_REQUEST[self::PARAM_FOR_ACTION])) ? $_REQUEST[self::PARAM_FOR_ACTION] : ""; if ($action == "") return self::$method; if (!strpos($action,"::")) $action .= "::main"; list($module, $method)=explode('::', $action); return ($method); } static function getMode() { $mode = (isset($_REQUEST[self::PARAM_FOR_MODE])) ? $_REQUEST[self::PARAM_FOR_MODE] : ""; if ($mode == "") return self::$mode; } static function redirect($action, $messages = null) { $_REQUEST[self::PARAM_FOR_ACTION] = $action; return self::run($messages); } static function runController($controller, $method, $params, $messages = null) { $_REQUEST = $params; $_REQUEST["action"] = $controller."::".$method; return ActionManager::run($messages); } static function run($messages = null) { $module = self::getModule(); $method = self::getMethod(); $classToInstaciate=$module."_controller"; if (class_exists($classToInstaciate)){ $claseTemp=new $classToInstaciate; if ($messages != null) $claseTemp->messages = $messages; if (method_exists($classToInstaciate,$method)){ $html=call_user_func_array(array($claseTemp, $method),array()); } else { $html=PropertiesManager::get("error.actionDoesntExists"); } } else { $html=PropertiesManager::get("error.actionDoesntExists"); } return $html; } } /** * Clase model abstracta para el manejo de ABM comun. * Todos los m�todos pueden sobreescribirse para cambiar su comportamiento. * Los m�todos b�sicos son: save, delete, get, search. * Por cada uno de los m�todos b�sicos, tiene un m�todo "doBefore" y "doAfter" que se ejecutan antes y despues * del m�todo principal. * * Versi�n 9.0: * - corregido para que debugue al eliminar * - corregido para que no pase como referencia en el query. * Versi�n 8.0: * - agregado $data = stripslashes_deep($data); en save * * @author Adri�n Prause para www.mediaclic.com.ar */ class AbstractCommonCrudModel { const _RSS_TITLE = "title"; const _RSS_DATE = "pubDate"; const _RSS_DESCRIPTION = "description"; const _RSS_LINK = "link"; const _RSS_POSITION = "position"; var $db; var $debug; var $module = ""; var $installSql = ""; var $addSql = ""; var $countSql = "select count(1) as total from ( {searchSql} ) as temp"; var $updateSql = ""; var $searchSql = ""; var $getSql = ""; var $deleteSql = ""; var $rewriteRules = array( ); var $metatags = array( ); function createHtaccess() { // Get cURL resource $curl = curl_init(); // Set some options - we are passing in a useragent too here curl_setopt_array($curl, array( CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => ConfigManager::get("baseHrefTemp")."index.php?action=install", CURLOPT_USERAGENT => 'Codular Sample cURL Request' )); // Send the request & save response to $resp $resp = curl_exec($curl); //dump($resp); // Close request to clear up some resources curl_close($curl); } function void($params = null) { return false; } function catalog_YesNo() { $catalog = new Catalog(); return $catalog->habilitado(); } function getCatalogs() { $catalog = array(); $methods = get_class_methods($this); foreach($methods as $method) { if (substr($method, 0, 8) == "catalog_") { $name = str_replace("catalog_", "", $method); $catalog[$name] = $method; } } return $catalog; } function getRewriteRules() { return $this->rewriteRules; } function __construct() { global $db, $config; $this->logEverything = $config["logEverything"]; $this->db = $db; $this->debug = $config["debug"]; $this->module = lcFirst(str_replace("Web_model", "", get_class($this))); $this->module = lcFirst(str_replace("_model", "", $this->module)); if (isset($config["modules"][$this->module])) { foreach ($config["modules"][$this->module] as $i => $configParam) { $this->$i = $configParam; } $configuracion_model = new Configuracion_model(); $parameters = $configuracion_model->setParametersToModule($this); } } protected function getNotifications($params = null) { return null; } function inicializeParams($sql, $params) { $newParams = array(); $pattern = '#\{([^\{\}]*)\}#'; preg_match_all($pattern, $sql, $result); foreach ($result[1] as $key => $value) { if (!isset($params[$value])) { $newParams[$value] = null; } else { $newParams[$value] = $params[$value]; } } return $newParams; } function orderParams($sql, $params) { $newParams = array(); foreach ($params as $key => $value) { $i = strpos($sql, "{" . $key . "}"); if ($i != null) { $newParams[$i] = $value; } } return array_values($newParams); } function replaceParamsAsOptional($sql, $params) { foreach ($params as $key => $value) { $sql = str_replace("{" . $key . "}", "%S", $sql); } return $sql; } function replaceParams($sql, $params) { foreach ($params as $key => $value) { $sql = str_replace("{" . $key . "}", "%s", $sql); } return $sql; } protected function doBeforeSearch(&$data) { //sobreescribir } function search(&$filters) { $this->doBeforeSearch($filters); $safesql = new SafeSQL_MySQL(); $filters = $this->inicializeParams($this->searchSql, $filters); $query = $safesql->query( $this->replaceParamsAsOptional($this->searchSql, $filters), $this->orderParams($this->searchSql, $filters) ); $result = $this->db->select($query); if ($this->debug) { echo "