');
if (substr_count($intro_text, '---') > 0) {
$intro_text = substr($intro_text, 0, strpos($intro_text, '---'));
} else {
if(strlen($intro_text)>$countcarater){
$intro_text.=" ";
$intro_text = substr($intro_text, 0, stripos($intro_text,' ',$countcarater));
$intro_text = tidy_repair_string($intro_text, array('output-xhtml' => true, 'show-body-only' => true, 'doctype' => 'transitional', 'drop-font-tags' => true, 'drop-proprietary-attributes' => true, 'lower-literals' => true, 'quote-ampersand' => true, 'wrap' => 0), 'utf8');
}
}
$intro_text = str_replace("
", "", $intro_text);
$intro_text = str_replace("
", "", $intro_text);
}
else{
if(strlen($intro_text)>$countcarater){
$intro_text.=" ";
$intro_text = substr($intro_text, 0, stripos($intro_text,' ',$countcarater));
}else{
$intro_text = substr($intro_text,0,$countcarater);
}
}
$intro_text=rtrim($intro_text," .,;:");
return $intro_text;
}
/* esta funcion tratara de cotejar los valores que se traen como array y los pasara a cadena de esa forma remplazamos directamente en el tpl */
public function analicer_data($dataContent){
ini_set('display_errors', 1);
if(count($dataContent['items'])>0 and is_array($dataContent['items'])){
/* Recorro el array de items esto puede tener uno o varios pero siempre viene en un array de items */
foreach ($dataContent['items'] as $key2 => $content) {
/* autores */
$content['commets']=(isset($content['commets']))?$content['commets']:'5';
/* Numero */
$content['num']=(isset($content['num']))?$content['num']:$key2+1;
/* autores */
$content['authors']=(isset($content['authors']) and ($content['authors']!='1'))?$content['authors']:'';
/* Sections */
$content['section_name']=(isset($content['section_name']))?$content['section_name']:'';
$content['section_url']=(isset($content['section_url']))?$content['section_url']:'';
/* Date */
$content['date']=(isset($content['date']))?$content['date']:'';
$content['date_short']=(isset($content['date_short']))?$content['date_short']:'';
if(isset($content['date_created'])){
//Calculo de fecha
if(isset($content['time_created']) and strlen($content['time_created'])<12){
$content['time_created']=($content['date_created'].' '.$content['time_created']);
$content['date']=($this->makeDateApStyle(date(DATE_FORMAT,$this->dateFromString($content['date_created']))).' '.$this->makeDateApStyle(date('h:i A',$this->dateFromString($content['time_created']))).'');
}else{
$content['date']=($this->makeDateApStyle(date(DATE_FORMAT,$this->dateFromString($content['date_created']))));
}
$content['date_short']=$this->makeDateApStyle(date(DATE_FORMAT,$this->dateFromString($content['date_created'])));
$content['date_dateF']=$this->makeDateApStyle(date('l',$this->dateFromString($content['date_created']))).'
'.$this->makeDateApStyle(date('j',$this->dateFromString($content['date_created'])));
}
/* imagenes */
if(isset($content['imagen'])){
$contentImagen=$this->ImgencontentSet($content['imagen']);
if(is_array($contentImagen)){
$content=array_merge($content,$contentImagen); // Si Hubo cambios en las imagenes los añadimos al content
}
}
if(is_array($content) and is_array($dataContent['items'][$key2])){
$dataContent['items'][$key2]=array_merge($dataContent['items'][$key2],$content); // Juntamos los dos Array donde el segundo sobreescrive al primero
}
}
}
/* Retorno el array completo */
return $dataContent;
}
function ImgencontentSet($content){
foreach ($content as $n => $cIm) {
if(is_array($cIm)){
foreach ($cIm as $key => $value) {
if($key!='caption' and $key!='credit' and $key!='title' and $key!='id'){
if($value!='' or ($content['contentvideo']!='' and $content['activevideo'])){
$contentNew['imagen'][$n][$key]['url']=$value;
if($content['activevideo']){
$contentNew[$key]='';
}else{
$hw='';
$sizesImages = json_decode($this->img_o->getRecortesImagenes(),true);
$width=$sizesImages[$key]['width'];
$height=$sizesImages[$key]['height'];
$contentNew['imagen'][$n][$key]['wh']=' width="'.$width.'px" height="'.$height.'px"';
$contentNew['imagen'][$n][$key]['width']=$sizesImages[$key]['width'];
$contentNew['imagen'][$n][$key]['height']=$sizesImages[$key]['height'];
}
}
}else{
$contentNew['imagen'][$n][$key]=$value;
}
}
}
}
/* Retorno el array completo */
return $contentNew;
}
/**
* [Renderiza un tpl]
* @param [num] $tplnum [Numero del template para buscar en themes/tpls/content/]
* @param [array] $dataContent [Son los datos planos ya Analizados]
* @param [array] $dataShow [es un array con los los valores que se decean mostrar de los tpls]
*/
public function RendericeView($tplnum,$dataContent,$dataShow){
if(is_array($dataShow) and count($dataShow)>0){
/* Tomamos los Valores almacenados para el Tpl y colocamos un _ (gion_bajo) en la key. de esa manera prevenimos sobreescritura indeceada en el array resultado */
foreach ($dataShow as $key => $value) {
$dataL['_'.$key]=$value;
}
/* Juntamos los dos Array */
$article = array_merge($dataContent,$dataL);
}else{
$article = $dataContent;
}
//($article);
/* Y renderimazos con todos los datos del array optenido */
$ret=$this->tpls->render('content/content.tpl.' .$tplnum . '.tpl', $article);
return html_entity_decode($ret);
}
public function createViewContent($dataContent, $dataTpl, $urlListitems='',$fixList=true) {
$dataContent = $dataContent['items'];
if (count($dataContent) > 0) {
$canto = 1;
$cola = array();
for ($index = 0; $index < count($dataContent); $index++) {
if(count($dataTpl)>2){ // Esta parate es para las Flex
if ($canto <= $dataTpl['repit_content1']) {
$col = $dataTpl['col_content1'];
$tpl = $dataTpl['tpl_content1'];
$data= $dataTpl['tpl_content_data1'];
} elseif (($dataTpl['repit_content2']!='0')and($canto <= ($dataTpl['repit_content1'] + $dataTpl['repit_content2'])) ){
$col = $dataTpl['col_content2'];
$tpl = $dataTpl['tpl_content2'];
$data= $dataTpl['tpl_content_data2'];
} elseif (($dataTpl['repit_content3']!='0')and($canto <= ($dataTpl['repit_content1'] + $dataTpl['repit_content2'] + $dataTpl['repit_content3']))) {
$col = $dataTpl['col_content3'];
$tpl = $dataTpl['tpl_content3'];
$data= $dataTpl['tpl_content_data3'];
}
}else{ // Esta parate es para los llamados desde Engine y Api Proces
$col = $dataTpl['0'];
$tpl = $dataTpl['1'];
$data= $dataTpl['2'];
}
$tpl=(strlen($tpl)>1)?$tpl:'0'.$tpl;
if ($col != '' and $col !='0') { //Esta Parte es cuando Añadimos una Lista encerrada en una columana
$temporalTpl=$this->RendericeView($tpl,$dataContent[$index],json_decode($data,true));
$tplT= '' .$temporalTpl.'
';
$result .= $tplT;
array_unshift($cola,$col);
if($canto>1 and $col==4 and $cola[0]==$cola[1] and $fixList){ // 50%
$result .='';
array_unshift($cola,'clear');
}
if($canto>2 and $col==5 and $cola[0]==$cola[1] and $cola[0]==$cola[2] and $fixList){ // 33%
$result .='';
array_unshift($cola,'clear');
}
if($canto>3 and $col==6 and $cola[0]==$cola[1] and $cola[0]==$cola[2] and $cola[0]==$cola[3] and $fixList){ // 25% and $cola[count($cola)-1]!=4
$result .='';
array_unshift($cola,'clear');
}
/* Marcando un FIxe para los listados */
}else{ // Esta parte es cuando solo queremos que nos Debuelva el resultado y la columna lo añadimos luego
$result .= $this->RendericeView($tpl , $dataContent[$index] , json_decode($data,true) );
}
$canto ++;
}
}
return $result;
}
public function makeDateApStyle($date_str) {
$orig = array( 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
$replace = array( 'Jan.', 'Feb.', 'March', 'April', 'May', 'June', 'July', 'Aug.', 'Sept.', 'Oct.', 'Nov.', 'Dec.');
$new_date = str_replace($orig, $replace, $date_str);
return $new_date;
}
public function dateFromString($str){
$h=$m=$s=$month=$day=$year='0';
$year=substr($str,0,4);
$month=substr($str,5,2);
$day=substr($str,8,2);
if (strlen($str)=='10'){
return mktime('0','0','0',$month,$day,$year);
}else{
$h=substr($str,11,2);
$m=substr($str,14,2);
$s=substr($str,17,2);
return mktime($h,$m,$s,$month,$day,$year);
}
}
public function GetPath($path){
$originalPath=$path;
if (is_file($path)){
return $path;
}else{
$path='../'.$path;
if (is_file($path)){
return $path;
}else{
$path='../'.$path;
if (is_file($path)){
return $path;
}else{
$path='../'.$path;
if (is_file($path)){
return $path;
}else{
$path='../'.$path;
if (is_file($path)){
return $path;
}else{
die('File not found!
Last search: "'.$path.'"
Original Path: "'.$originalPath.'"');
}
}
}
}
}
}
public function SimpleTemplate($tpl,$array,$inicio='',$fin=''){
if($inicio==''){$inicio='{';$fin='}';}
if(is_array($array)){
while (list($key, $val) = each($array)) {
$tpl=str_replace($inicio.$key.$fin,$val,$tpl);
}
}
return $tpl;
}
public function CargarTpl($file){
return $this->CargarFile($this->GetPath($file));
}
public function CargarFile($file){
if(!is_file($file)){
debug ('File Not Found: '.$file);
}
$fs = @filesize ( $file );
if($fs=='0'){
debug('to small: '.$file);
return '';
}
$f = fopen ( $file,"r" );
$temp = fread ( $f, $fs );
fclose ( $f );
return $temp;
}
public function minify_html($d) {
if(!is_array($d) and !is_object($d)){
$d = str_replace(array(chr(9), chr(10), chr(11), chr(13)), ' ', $d);
$d = preg_replace('`<\!\-\-.*\-\->`U', ' ', $d);
$d = preg_replace('/[ ]+/', ' ', $d);
$d = str_replace('> <', '><', $d);
$d=str_replace(" "," ",$d);
}
return $d;
}
}
?>
class Controller_Error extends Controller {}
?>
/**
* Controlador para los tmplates, Una forma de englobar la gran cantidad de pedidos que habra, usaremos la Api para Interactuar con la informacion del tpls
*/
class Controller_Template extends Controller {
public $schema = 'w_tpls_content';
public $defaultTpl = 'w_tpls_default';
public $contentype = 'cont_types';
public $templates = 'w_tpls';
/**
* [action_renderTpl Renderiza los Templates. Utilizando los datos de Contenido, y los Datos del Template
*
* $params['render']=$templa;
* $params['data']=$data;
* $params['fixList']=$fixList;
* $params['urlItem']=$urlItem;
* $pedido=array(
* 'class'=>'template',
* 'metodo'=>'renderTpl',
* 'params'=>$params,
*
* ]
* @return [type] [El template armado ]
*/
public function action_renderTpl(){
$fixList =(isset($this->params['fixList']))?$this->params['fixList']:true;
$urlItems =(isset($this->params['urlItem']))?$this->params['urlItem']:'';
$dataData =array();
if(isset($this->params['data']) and !is_array($this->params['data'])){
$dataData=$this->analicer_data(json_decode($this->params['data'],true));
}elseif(isset($this->params['data'])){
$dataData=$this->analicer_data($this->params['data']);
}
$dataRender =array();
if(isset($this->params['render']) and !is_array($this->params['render'])){
$dataRender=json_decode($this->params['render'],true);
}elseif(isset($this->params['render'])){
$dataRender=$this->params['render'];
}
if(!isset($dataRender['templates']) or ($dataRender['templates']=='')){ /* Si no se trae el template lo tratamos de buscar */
if(isset($dataRender['content_type2'])){$this->params['content_type2']=$dataRender['content_type2'];}
$tem=$this->action_getTemplate();
$dataRender['templates']=$tem['templates'];
}
if(count($dataData)>0 and count($dataRender)>0){
/* Tenemos los datos del template nos aseguramos pasarlo a array */
$template=$dataRender['templates'];
if(!is_array($template)){
$template=json_decode($templape,true);
}
/* llamamos a renderizar los datos */
return $this->createRende($dataData, $template, $urlItems, $fixList);
}else{
return 'No Content data or Template data Load';
}
return 'nada';
}
private function createRende($dataCon, $dataTpl, $urlListitems, $fixList){
$dataContent = $dataCon['items'];
if (count($dataContent) > 0) {
$canto = 1;
$cola = array();
$itempl=0;
//debug($dataCon);
$Config['option'] =$dataTpl[$itempl]['optionTpl'];
$Config['comp'] =$dataTpl[$itempl]['componentsTpl'];
$Config['compConf']=$dataTpl[$itempl]['componentConfig'];
$cantidad =(isset($Config['option']['repeat']))?$Config['option']['repeat']:1;
for ($index = 0; $index < count($dataContent); $index++) {
/* Vemos que Template usamos cuantas veces, y los criterios */
if ($canto <= $cantidad) {
$col =(isset($Config['option']['columns']))?$Config['option']['columns']:1;
}elseif(isset($dataTpl[$itempl+1]['optionTpl']['repeat']) and ($dataTpl[$itempl+1]['optionTpl']['repeat']!='0')){
$itempl++;
/* cambiamos los valores */
$Config['option'] =$dataTpl[$itempl]['optionTpl'];
$Config['comp'] =$dataTpl[$itempl]['componentsTpl'];
$Config['compConf'] =$dataTpl[$itempl]['componentConfig'];
$col =(isset($Config['option']['columns']))?$Config['option']['columns']:1;
$cantidad =$cantidad+$Config['option']['repeat'];
}
/* Unos controles previos por que si o si tiene que ser array */
if(!is_array($Config['comp'])){
$Config['comp']=json_decode(stripcslashes($Config['comp']),true);
}
if ($col != '' and $col !='0') { //Esta Parte es cuando Añadimos una Lista encerrada en una columana
$tplT= '' .$this->RendericeTwig($dataContent[$index],$Config).'
';
$result .= $tplT;
array_unshift($cola,$col);
if($canto>1 and $col==4 and $cola[0]==$cola[1] and $fixList){ // 50%
$result .='';
array_unshift($cola,'clear');
}
if($canto>2 and $col==5 and $cola[0]==$cola[1] and $cola[0]==$cola[2] and $fixList){ // 33%
$result .='';
array_unshift($cola,'clear');
}
if($canto>3 and $col==6 and $cola[0]==$cola[1] and $cola[0]==$cola[2] and $cola[0]==$cola[3] and $fixList){ // 25% and $cola[count($cola)-1]!=4
$result .='';
array_unshift($cola,'clear');
}
if($canto>4 and $col==7 and $cola[0]==$cola[1] and $cola[0]==$cola[2] and $cola[0]==$cola[3] and $cola[0]==$cola[4] and $fixList){ // 25% and $cola[count($cola)-1]!=4
$result .='';
array_unshift($cola,'clear');
}
/* Marcando un FIxe para los listados */
}else{ // Esta parte es cuando solo queremos que nos Debuelva el resultado y la columna lo añadimos luego
$result .= $this->RendericeTwig($dataContent[$index] , $Config );
}
$canto ++;
}
}
return $result;
}
/**
* [Renderiza un tpl]
* @param [array] $dataContent [Son los datos planos ya Analizados]
* @param [array] $dataShow [es un array con los los valores que se decean mostrar de los tpls]
*/
private function RendericeTwig($dataContent,$dataShow){
$tpl =(isset($dataShow['option']['tpl']))?$dataShow['option']['tpl']:0;
$tpl =(strlen($tpl)>1)?$tpl:'0'.$tpl; // Agremos un 0 delante de id template cuando es menor a 10
if(is_array($dataShow) and count($dataShow)>0){
/* Juntamos los dos Array */
$article['data'] = $dataContent;
$article=array_merge($article,$dataShow);
}else{
return ' Error!! Render template ';
}
//debug($article);
/* Y renderimazos con todos los datos del array optenido */
$ret=$this->tpls->render('content/content.tpl.' .$tpl . '.tpl', $article);
return html_entity_decode($ret);
}
/**
* [action_gettemplate Retorna un array con la informacion del templates dado los parametros de entrada, buscara hasta optener un tpl.Config si o si retornara un tpl.Config]
* @param [params] [params{id,content_type[,content_type2]} Los parametros son string]
* @param [id] [Id del contenido buscado]
* @param [content_type] [Content Type del contenido buscado]
* @param [content_type2] [Content Type del contenido buscado en un segundo nivel]
* @return [array] [Retorna un array con la informacion del tplate]
*/
public function action_getTemplate() {
$content_type = (isset($this->params['content_type']))?$this->params['content_type']:1;
$content_type2 = (isset($this->params['content_type2']))?$this->params['content_type2']:0;
$id = (isset($this->params['id']))?$this->params['id']:0;
## FILTERS
##########
$where=array();$where2=array();$where3=array();
$where_sql=$where_sql2=$where_sql3="";
# TYPE
$where['type'] = "{$this->schema}.content_type = '{$content_type}'";
# Type2 //Si tenemos un content_type2 Podremos tambien buscar el balor por defecto en caso que no tengamos el valor para el contenido requerido
# //Ademas podemos pedir otra opciones. por ejemplo que para Secciones no Configuradas, nos busque la de articulos,
if($content_type2!=0){
$where2['type'] = "{$this->contentype}.id = '{$content_type2}'";
$where2['tpl'] = "{$this->contentype}.templates != ''";
$where3['type'] = "{$this->contentype}.id = '{$content_type}'";
$where3['tpl'] = "{$this->contentype}.templates != ''";
}else{
$where2['type'] = "{$this->contentype}.id = '{$content_type}'";
$where2['tpl'] = "{$this->contentype}.templates != ''";
}
# ID
$where['id'] = "{$this->schema}.id_content = '{$id}'";
## Concat FILTERS
##############
if (count($where)>0){
$where_sql = ' WHERE '.implode($where, ' AND ');
}
if (count($where2)>0){
$where_sql2 = ' WHERE '.implode($where2, ' AND ');
}
if (count($where3)>0){
$where_sql3 = ' WHERE '.implode($where3, ' AND ');
}
## End Concat FILTERS
##############
#Probamos con el Type1
$sql = "SELECT {$this->schema}.templates
FROM
{$this->schema}
{$where_sql}
";
/* Buscaremos hasta encontrar una configuracion de tpl para devolver primero se busca en la tabla relacionada para esto, Luego se busca en la tabla cont_types (la 2 y 3) y por ultimo en Configuraciones Generales del sistema */
$this->db->QueryExecute($sql,false);
$Total = $this->db->GetNumRows(); /* Para sacar el total */
if($Total==0){
if($content_type2!=0){
$sql = "SELECT {$this->defaultTpl}.templates
FROM
{$this->defaultTpl}
WHERE
content_type = '{$content_type}' AND
content_type2 = '{$content_type2}' AND
templates!=''
";
$this->db->QueryExecute($sql,false);
$Total = $this->db->GetNumRows(); /* Para sacar el total */
}
if($Total==0){
//echo 'Probamos con el Type2';
$sql = "SELECT {$this->contentype}.templates
FROM
{$this->contentype}
{$where_sql2}
";
$this->db->QueryExecute($sql,false);
$Total = $this->db->GetNumRows();
if($Total==0 and $where_sql3!=''){
//echo 'Probamos con el Type2/3';
$sql = "SELECT {$this->contentype}.templates
FROM
{$this->contentype}
{$where_sql3}
";
$this->db->QueryExecute($sql,false);
$Total = $this->db->GetNumRows();
}
}
if($Total==0){
/* Si llego hasta aqui, tomaremos un template Fijo para todo el sistema. */
$sql="SELECT config_value as templates FROM `cms_configs` WHERE `config_name` LIKE 'Templates_Genral'";
}
}
//debug($sql);
$res = $this->db->QueryExecute($sql) or $this->db->raise_error();
$tplC=$this->db->FetchAssoc($res);
$tpl=$tplC['templates'];
$temp = json_decode($tpl,true);
// debug($tpl);
if(isset($temp['templates']) and is_array($temp['templates'])){
foreach( $temp['templates'] as &$t){
$value = $t['componentsTpl'];
if (!empty($value) && is_string($value)){
$value=stripslashes($value);
if(json_decode($value) != NULL ){
$t['componentsTpl'] = json_decode( $t['componentsTpl'], true );
}
}
}
}
// debug( $temp );
return $temp;
}
public function action_setTemplate() {
$this->params=$_POST['configtpl'];
$content_type = (isset($this->params['content_type']))?$this->params['content_type']:0;
$content_type2 = (isset($this->params['content_type2']))?$this->params['content_type2']:0;
$id = (isset($this->params['id']))?$this->params['id']:0;
$datatemplate['templates'] = (isset($this->params['templates']))?$this->params['templates']:array();
if ($id!=0 and $content_type!=0) {
if(count($datatemplate)>0){
$valor=json_encode($datatemplate);
$sql = "INSERT INTO w_tpls_content SET id_content='{$id}',content_type='{$content_type}',templates='{$valor}'";
$this->db->Execute($sql);
if( $this->db->GetNumRows() ){
$sql = "UPDATE w_tpls_content SET templates='{$valor}' WHERE id_content='{$id}' and content_type='{$content_type}'";
$this->db->Execute($sql);
//echo '2';
}else{
//echo '1';
}
if($content_type2!='0' and $this->params['SetDefault']!='0'){
$q="DELETE FROM w_tpls_default WHERE content_type='{$content_type}' AND content_type2='{$content_type2}'";
$this->db->Execute($q);
$sql = "INSERT INTO w_tpls_default SET content_type='{$content_type}',content_type2='{$content_type2}',templates='{$valor}'";
$this->db->Execute($sql);
}
}else{
return 'Error in Template Data';
}
}else{
if ($id==0 and $content_type2!=0) {
if(count($datatemplate)>0){
$valor=json_encode($datatemplate);
$sql = "UPDATE cont_types SET templates='{$valor}' WHERE id={$content_type2}";
$this->db->Execute($sql);
}
}
return 'Error in Template Data Information';
}
return ;
}
public function action_formTemplate() {
$TepG=$this->action_getTemplate();
//print_r($TepG);
$listRecortes=$this->img_o->getRecortesImagenes();
if(!is_array($listRecortes)){
$listRecortes=json_decode($listRecortes,true);
}
$this->params['id']=(isset($this->params['id']))?$this->params['id']:0;
$this->params['content_type']=(isset($this->params['content_type']))?$this->params['content_type']:0;
$this->params['iten']=0;
$this->params['donde']=$this->params['donde'];
$this->params['content_type2']=$this->params['content_type2'];
//print_r($arrTemp);
//die();
$numerosCol = array(1=>' 1 - width 100%', '2 - width 75%','3 - width 66%','4 - width 50%', '5 - width 33%','6 - width 25%','7 - width 20%','8 - width 14%');
/* Traemos los templates */
$qtpls="SELECT * FROM {$this->templates} order by id asc";
$rtplss=$this->db->QueryExecute($qtpls);
$fields=$this->db->GetFields(); /* Buscamos los campos de la tabla */
foreach ($fields as $key => $ro2) {
$nameF=$ro2->name;
// Colocamos en un array todo los campos
if($nameF!='id' and $nameF!='declaration' and $nameF!='especial' and $nameF!='size'){
$Campos[]=$nameF;
}
}
foreach ($rtplss as $key => $value) {
// Recorremos los campos y si el template lo tiene en 1 es por esta disponible. asi formamos que campos tendra cada template por defecto
foreach ($Campos as $field) {
if($value[$field]==1){ $tpldataSS[$value['id']][$field] =1;}
// if($value['Imagen']==1){$tpldataSS[$value['id']]['Imagen'] =1;}
}
}
$q="SELECT id, type FROM cont_types";
$res=$this->db->QueryExecute($q);
foreach ($res as $key => $r) {
$contentTypes[$key]=$r;
}
$arrTemp=array('params'=>$this->params,'template_get' => $TepG['templates'], 'template_config_set' => $rtplss, 'template_campos_set' => $tpldataSS, 'cols_set'=>$numerosCol,'imagenSize_set'=>$listRecortes , 'Campos_set'=>$Campos, 'ContentTypes_set'=>$contentTypes);
$ret=$this->tpls->render('forms/formEditTemplate.tpl', $arrTemp);
return ($ret);
}
public function action_formtemplateitem(){
$this->params['incache']=off;
$TepG=$this->action_getTemplate();
//print_r($arrTemp);
//die();
$listRecortes=$this->img_o->getRecortesImagenes();
if(!is_array($listRecortes)){
$listRecortes=json_decode($listRecortes,true);
}
$numerosCol = array(1=>' 1 - width 100%', '2 - width 75%','3 - width 66%','4 - width 50%', '5 - width 33%','6 - width 25%','7 - width 20%','8 - width 14%');
/* Traemos los templates */
$qtpls="SELECT * FROM {$this->templates} order by id asc";
$rtplss=$this->db->QueryExecute($qtpls);
$fields=$this->db->GetFields(); /* Buscamos los campos de la tabla */
foreach ($fields as $key => $ro2) {
$nameF=$ro2->name;
// Colocamos en un array todo los campos
if($nameF!='id' and $nameF!='declaration' and $nameF!='especial' and $nameF!='size'){
$Campos[]=$nameF;
}
}
foreach ($rtplss as $key => $value) {
// Recorremos los campos y si el template lo tiene en 1 es por esta disponible. asi formamos que campos tendra cada template por defecto
foreach ($Campos as $field) {
if($value[$field]==1){ $tpldataSS[$value['id']][$field] =1;}
// if($value['Imagen']==1){$tpldataSS[$value['id']]['Imagen'] =1;}
}
}
$LastTepl=array_pop($TepG['templates']);
//print_r($LastTepl);
//die();
$arrTemp=array('params'=>$this->params,'templateG' => $LastTepl, 'template_config_set' => $rtplss, 'template_campos_set' => $tpldataSS, 'cols_set'=>$numerosCol, 'imagenSize_set'=>$listRecortes, 'Campos_set'=>$Campos);
$ret=$this->tpls->render('forms/formEditTemplateItems.twig', $arrTemp);
return ($ret);
}
public function action_loadcolumnas(){
$ret=$this->tpls->render('forms/formEditTemplateItemsColumnas.twig', array('columns'=>$this->params['columns']));
return ($ret);
}
}
?>
class Controller_Article extends Controller {
public $schema = 'cont_articles';
public $sections_table = 'cont_sections';
public function action_getarticle() {
$init = (isset($this->params['init']))?$this->params['init']:0;
$content_type = (isset($this->params['content_type']))?$this->params['content_type']:1;
## FILTERS
##########
$where = array();
$where_sql = "";
# TYPE
$where['type'] = "{$this->schema}.content_type_id = '{$content_type}'";
# ACTIVE
$where['active'] = "{$this->schema}.active = '1'";
# SECTION -> INCLUDE SUBSECTIONS
if(isset($this->params['section_id']) and $this->params['section_id']!=0) {
$subsec_str="'".$this->params['section_id']."',";
$q = "SELECT id FROM cont_sections WHERE parent_id = '{$this->params['section_id']}'";
$subsections = $this->db->QueryExecute($q);
foreach ($subsections as $subsection) {
$subsec_str .= "'".$subsection['id']."',";
}
$subsec_str=trim($subsec_str,",");
$where['section_id'] = "{$this->schema}.section_id IN (".$subsec_str.")";
}
# SECTION -> INCLUDE SUBSECTIONS
if(isset($this->params['section_ids']) and $this->params['section_ids']!=0) {
$idesect=explode(",", $this->params['section_ids']);
foreach ($idesect as $key => $value) {
$sec_str .= "'".$value."',";
}
$q = "SELECT cont_sections.id FROM cont_sections WHERE cont_sections.id IN (".trim($sec_str,',').") and parent_id = '0'";
$sctions = $this->db->QueryExecute($q);
foreach ($sctions as $sction) {
$q = "SELECT cont_sections.id FROM cont_sections WHERE cont_sections.parent_id = '{$sction['id']}'";
$subsections = $this->db->QueryExecute($q);
foreach ($subsections as $subsection) {
$subsec_str .= "'".$subsection['id']."',";
}
}
$list=trim($sec_str.$subsec_str,',');
$where['section_id'] = "{$this->schema}.section_id IN ( {$list} )";
}
# AUTHOR
if(isset($this->params['author_id']) and $this->params['author_id']!=0){
$where['author_id'] = "{$this->schema}.authors_id LIKE '%x{$this->params['author_id']}x%'";
}
# AUTHORs**
if(isset($this->params['authors_id']) and $this->params['authors_id']!=0){
$authors_id =$this->params['authors_id'];
$authors_id = trim($authors_id);
$authors_id = trim($authors_id,"x");
$authors_id =str_replace("x,x","x",$authors_id);
$authors_id =str_replace("xx","x",$authors_id);
$authors_id = explode("x",$authors_id);
$inplace_authors_id=$separador = '';
foreach($authors_id as $indice => $author_id) {
if($author_id!=''){
$inplace_authors_id.= $separador."{$this->schema}.authors_id like '%".$author_id."%'";
$separador = ' or ';
}
}
if($inplace_authors_id != ''){
$where['authors_id'] = "( ".$inplace_authors_id.") ";
}
}
# STR SEARCH whit type
if(isset($this->params['str']) and $this->params['str']!=''){
$this->params['str'] = urldecode($this->params['str']);
$where['str'] = "(({$this->schema}.title LIKE '%{$this->params['str']}%') or ({$this->schema}.intro_text LIKE '%{$this->params['str']}%'))";
if(isset($this->params['typesearch']) and $this->params['typesearch']!=''){
$where['str'] = "{$this->schema}.{$this->params['typesearch']} LIKE '%{$this->params['str']}%'";
}
}
# IDS
if(isset($this->params['ids'])){
$ids=$this->LimpiaIdesList($this->params['ids']);
$w[] = "{$this->schema}.id IN ({$ids})";
}
# ID (Solo este Id)
if(isset($this->params['id']) and $this->params['id']!=0) {
unset($where);
$where['id'] = "{$this->schema}.id = '{$this->params['id']}'";
}
# ID (No con este id) //Se aplica a las listas
if(isset($this->params['noid']) and $this->params['noid']!=0) {
$where['noid'] = "{$this->schema}.id != '{$this->params['noid']}'";
}
# IDS (No con esta lista de idea) // Se aplica a las listas
if(isset($this->params['noids'])){
$noids=$this->LimpiaIdesList($this->params['noids']);
$w[] = "{$this->schema}.id IN NOT ({$noids})";
}
# Active / Inactive only
if(isset($this->params['activeonly'])) {
$where['active'] = "{$this->schema}.active = '{$this->params['activeonly']}'";
}
## END FILTERS
##############
## ORDER BY
###########
$order_sql = " ORDER BY {$this->schema}.date_created desc,{$this->schema}.time_created DESC ";
if(isset($this->params['order']) and $this->params['order']!='') {
$order_sql ="ORDER BY {$this->schema}.".$this->params['order']." desc";
if(isset($this->params['ordertype']) and $this->params['ordertype']!='') {
$order_sql ="ORDER BY {$this->schema}.".$this->params['order']." ".$this->params['ordertype'];
}
if(isset($this->params['date_created']) and $this->params['date_created']!='') {
$where['date_created'] ="{$this->schema}.date_created > '{$this->params['date_created']}'";
}
}
## END ORDER BY
###############
## Concat FILTERS
##############
if (count($where)>0){
$where_sql = ' WHERE '.implode($where, ' AND ');
}
## End Concat FILTERS
##############
//Limit
if(isset($this->params['limit'])){
$limit_sql = " LIMIT {$init}, {$this->params['limit']}" ;
}else{
$limit_sql = '';
}
switch ($this->params['view']) {
case 'full':
$fields = "{$this->schema}.*";
break;
case 'mini':
$fields = " {$this->schema}.id, {$this->schema}.content_type_id, {$this->schema}.title, {$this->schema}.subtitle,{$this->schema}.seo_title,{$this->schema}.meta_description,
{$this->schema}.author_id, {$this->schema}.authors_id,{$this->schema}.intro_text, {$this->schema}.content, {$this->schema}.date_created, {$this->schema}.section_id,
{$this->schema}.time_created, {$this->schema}.views
";
break;
default:
$fields = " {$this->schema}.id, {$this->schema}.content_type_id, {$this->schema}.id, {$this->schema}.title, {$this->schema}.subtitle,{$this->schema}.seo_title,{$this->schema}.meta_description,
{$this->schema}.author_id, {$this->schema}.authors_id, {$this->schema}.section_id, {$this->schema}.intro_text, {$this->schema}.content, {$this->schema}.date_created,
{$this->schema}.time_created, {$this->schema}.active, {$this->schema}.views, {$this->schema}.comments
";
# code...
break;
}
//Limit
if(isset($this->params['only_images']) AND ($this->params['only_images'] == 1) ){
$add_join = "INNER JOIN w_image_content ic ON ({$this->schema}.id = ic.id_engine AND ic.main=1 AND ic.content_type_id=". $content_type .") " ;
}else{
$add_join = '';
}
$sql = " SELECT
".$fields.",
cont_sections.section_name
FROM
"."{$this->schema}
LEFT JOIN
cont_sections
ON "."{$this->schema}.section_id = cont_sections.id
".$add_join."
".$where_sql. " AND cont_articles.time_created <= NOW()
GROUP BY {$this->schema}.id
".$order_sql ;
$this->db->QueryExecute($sql,false);
$articlesTotal = $this->db->GetNumRows(); /* Para sacar el total */
$sql.=$limit_sql;
if(!isset($this->params['limit'])){
$sql .= "
LIMIT
".$init.", ".$this->perPageCant;
}
$articles = $this->db->QueryExecute($sql) or $this->db->raise_error();
foreach ($articles as $article) {
$type=($article['content_type_id']==1)?'article':'blog';
$article['intro_text'] = html_entity_encode_php4(($this->cutText($article['intro_text'], $article['content'])));
if($this->params['view']=='full') {
$article['content']=html_entity_encode_php4(stripcslashes($article['content']));
}else{
$article['content']='';
}
$article['section_url'] =BASEURL.$type.'s.sec-'.$article['section_id'].'-1-'.string2Url($article['section_name']).'.html';
$article['url']=BASEURL.$type.'-'.$article['id'].'-'.string2Url($article['title']).'.html';
$article['permanetlink']=BASEURL.$type.'-permalink-'.$article['id'].'.html';
$article['social'] =$this->getsocial($article['permanetlink'],$article['id'],$article['content_type_id']);
$article['authors'] = $this->getAuthorsFromModel($article['authors_id']);
$article['imagen'] = $this->getImage($article['id'],$article['content_type_id'],0,10);
$result['items'][] = $article;
}
$result['total'] = $articlesTotal;
return $result;
}
public function action_getsections() {
$content_type = (isset($this->params['content_type']))?$this->params['content_type']:1;
if(isset($this->params['id'])){
$where['id'] = "cont_sections.id = '{$this->params['id']}'";
}else{
$where['parent_id'] = "cont_sections.parent_id = '0'";
}
# ID (Solo este Content type)
$where['type'] = "cont_sections.content_type_id = '{$content_type}'";
# ID (Solo este Content type)
$where['display_in_ss'] = "cont_sections.display_in_ss = '1'";
if (count($where)>0){
$where_sql = ' WHERE '.implode($where, ' AND ');
}
switch ($this->params['view']) {
case 'mini':
$fields = " cont_sections.id, cont_sections.content_type_id, cont_sections.section_name, cont_sections.parent_id,
cont_sections.display_in_ss, cont_sections.seo_title, cont_sections.seo_keywords, cont_sections.seo_description
";
break;
default:
case 'full':
$fields = "cont_sections.*";
break;
}
$sql = "SELECT ".$fields." FROM cont_sections
".$where_sql. "
ORDER BY
cont_sections.`order` DESC,
cont_sections.section_name ASC";
$sections = $this->db->QueryExecute($sql);
if(count($sections)>0){
foreach ($sections as $section) {
$type=($section['content_type_id']==1)?'article':'blog';
$section['section_url'] =BASEURL.$type.'s.sec-'.$section['id'].'-1-'.string2Url($section['section_name']).'.html';
$section['url'] =BASEURL.$type.'s.sec-'.$section['id'].'-1-'.string2Url($section['section_name']).'.html';
//if($this->params['view']!='mini') {
$section['subsections'] = $this->getSubSections($section['id']);
//}
$resultado[] = $section;
}
}
return $resultado;
}
private function getSubSections($id){
switch ($this->params['view']) {
case 'mini':
$fields = " cont_sections.id, cont_sections.content_type_id, cont_sections.section_name, cont_sections.parent_id,
cont_sections.display_in_ss,cont_sections.seo_title, cont_sections.seo_keywords, cont_sections.seo_description
";
break;
default:
case 'full':
$fields = "cont_sections.*";
break;
}
$sql = " SELECT
".$fields."
FROM
cont_sections
WHERE
cont_sections.parent_id = '".$id."'
ORDER BY
cont_sections.`order` DESC,
cont_sections.section_name ASC";
$sections = $this->db->QueryExecute($sql);
return $sections;
}
}
?>
class Controller_Event extends Controller {
public function action_getevent() {
#PARAMETROS INICIALES
$init = $limit = $status = $section = $category = $strin = $id = $typesearch = $order = $sort = $filter = $date = '';
$init = (isset($this->params['init'])) ? "init:".$this->params['init'] : "init:0";
$content_type = (isset($this->params['content_type'])) ? $this->params['content_type'] : 4;
$limit = (isset($this->params['limit'])) ? $this->params['limit'] : '20';
# ACTIVE
$status = "status:1/";
# CATEGORY
$category = (isset($this->params['section_id']) and $this->params['section_id'] != '') ? "categories:" . $this->params['section_id'] . "/" : "";
# STR SEARCH
$strin = (isset($this->params['str']) and $this->params['str'] != '') ? "str:" . urldecode($this->params['str']) . "/" : "";
$typesearch = (isset($this->params['typesearch']) and $this->params['typesearch'] != '' and $this->params['typesearch'] != 'title') ? "typesearch:" . urldecode($this->params['typesearch']) . "/" : "";
# SECTION -> INCLUDE SUBSECTIONS
if (isset($this->params['section_id']) and $this->params['section_id'] != 0) {
$section = "category:" . $this->params['section_id'] . "/";
}
# SECTION -> INCLUDE SUBSECTIONS
if (isset($this->params['section_ids']) and $this->params['section_ids'] != 0) {
$section = "categories:" . $this->params['section_ids'] . "/";
}
# Featured
if (isset($this->params['featured']) and $this->params['featured'] != '') {
$featured = "featured:" . $this->params['featured'] . "/";
}
# DATE
if (isset($this->params['date']) and $this->params['date'] != '') {
$date = "date:" . $this->params['date'] . "/";
}
# FILTER
if (isset($this->params['filter']) and $this->params['filter'] != '') {
$filter = "filter:" . $this->params['filter'] . "/";
}
# ID
$id = (isset($this->params['id']) and $this->params['id'] != 0) ? 'id:' . $this->params['id'] : '';
$url = "http:" . BASEURL2 . "events/no_join:no/widget:1/".$init."/Limit:" . $limit . "/" . $status . $section . $featured . $category . $strin . $id . $typesearch. $date . $filter;
// echo $url;
$events = getFromCurl($url);
$eventsData = json_decode($events, true);
$listEvents = $eventsData['resulset'];
switch ($this->params['view']) {
case 'full':
$fields = array('id' => '', 'content_type' => '', 'title' => '', 'subtitle' => '', 'place' => '',
'intro_text' => '', 'content' => '', 'date_created' => '', 'date_finished' => '', 'section_id' => '',
'time_created' => '', 'views' => '', 'display_on_m' => '', "section_name" => '',
"section_url" => '', "url" => '', "permalink" => '', 'imagen' => '',
"tags" => '', "comments" => '', "linkFromNpaper" => '', 'active' => '',
"time_created" => '', "views" => '');
break;
case 'mini':
$fields = array('id' => '', 'content_type' => '', 'title' => '', 'subtitle' => '', 'place' => '',
'intro_text' => '', 'date_created' => '', 'section_id' => '',
'time_created' => '', 'views' => '', 'display_on_m' => '', "section_name" => '',
"section_url" => '', "url" => '', "permalink" => '', 'imagen' => '', 'featured' => '');
break;
default:
$fields = array('id' => '', 'content_type' => '', 'title' => '', 'subtitle' => '', 'place' => '',
'intro_text' => '', 'content' => '', 'date_created' => '', 'section_id' => '',
'time_created' => '', 'views' => '', 'active' => '', 'comments' => '', 'author_id' => '', 'authors_id' => '', 'display_on_m' => '', "section_name" => '',
"section_url" => '', "url" => '', "permalink" => '', 'imagen' => '', 'authors'=>'');
break;
}
if (count($listEvents) > 0) {
$count = 0;
$child = '';
$result['total'] = $eventsData['header']['total'];
$baseurl='http:'.str_replace("http:","",str_replace("https:","", BASEURL));
foreach ($listEvents as $r) {
//print_r($r);
$event['id'] = $r['id'];
$event['content_type'] = $content_type;
$event['title'] = $r['event_name'];
$event['subtitle'] = $r['short_description'];
$event['intro_text'] = $this->cutText($r['short_description'], $r['description']);
$event['content']=($r['description']);
$event['date_created'] = $r['event_date'];
$event['date_finished'] = $r['event_stop_date'];
$event['featured'] = $r['featured'];
$event['imagen'] = $this->getImageEvent($r['images']);
//$event['imagen'] = $this->getImage($event['id'],$event['content_type_id'],0,10);
$event['author_id'] = $r['user_id'];
$event['authors_id'] = 'x'.$r['user_id'].'x';
$event['active'] = 1;
$event['comments'] = 0;
$event['place']['id'] = $r['Place']['id'];
$event['place']['place_name'] = $r['Place']['place_name'];
$event['place']['address'] = $r['Place']['address'];
$event['place']['city'] = $r['Place']['city'];
$event['place']['zip'] = $r['Place']['zip'];
$event['place']['state'] = $r['Place']['state'];
$event['place']['lat'] = $r['Place']['lat'];
$event['place']['lng'] = $r['Place']['lng'];
$event['place']['url'] = $baseurl . "places/view/" . $r['Place']['id'] . "/" . $this->underscore($r['Place']['place_name']) . ".html";
$event['place']['permalink'] = $baseurl . "places/view/" . $r['Place']['id'];
$event['section_id'] = $r['Acategories'][0]['id'];
$event['section_name'] = $r['Acategories'][0]['name'];
$event['section_url'] = $baseurl . "events/categories:" . $r['Acategories'][0]['id'];
$event['url'] = $baseurl . "events/view/" . $r['id'] . "/" . $this->underscore($r['event_name']) . ".html";
$event['permalink'] = $baseurl . "events/view/" . $r['id'];
$event['tags'] = $r['tags'];
$event['comments'] = $r['comments']['total'];
$event['linkFromNpaper'] = $r['paper'];
$event['active'] = $r['status'];
$event['time_created'] = $r['event_date'].' ' .$r['event_time'];
$event['views'] = $r['only_print'];
$event['authors'] = $this->getUserFromModel($event['authors_id']);
$fields = array_intersect_key($event, $fields);
$result['items'][] = $fields;
}
if(((isset($this->params['process']) and $this->params['process']==on))){
$response = $this->analicer_data($result);
$Listado=$this->createViewContent($response,explode(",",$this->params['tplscol']),'');
if(!isset($this->params['array_response']))
{
$result=$this->minify_html($Listado);
}
else
{
$result['output_response'] = $this->minify_html($Listado);
}
}
}
return $result;
}
public function action_getsections() {
$baseurl='http:'.str_replace("http:","",str_replace("https:","", BASEURL2));
if(isset($this->params['id'])){
$id = "/id:".$this->params['id'];
}else{
$id = '';
}
$url = $baseurl . "events/getListTypesWithCategories/widget:1/no_join:1".$id;
$cats = getFromCurl($url);
$categories = json_decode($cats, true);
if (count($categories) > 0) {
foreach ($categories as $cat) {
$item['id'] = $cat['id'];
$item['section_name'] = $cat['category_name'];
$item['url'] = $baseurl . "events/categories:" . $cat['id'];
$item['subsections'] = $this->getSubSections($item['id'], $categories);
$res[] = $item;
}
}
return $res;
}
private function getSubSections($id, $categories) {
$baseurl='http:'.str_replace("http:","",str_replace("https:","", BASEURL));
foreach ($categories as $cat) {
if ($id == $cat['id']) {
if (count($cat['submenu']) > 0) {
foreach ($cat['submenu'] as $sub) {
$item['id'] = $sub[0];
$item['section_name'] = $sub[1];
$item['url'] = $baseurl . "events/categories:" . $sub[0];
$item['subsections'] = array();
$res[] = $item;
}
}
break;
}
}
return $res;
}
private function getImageEvent($images) {
if (count($images) > 0) {
foreach ($images as $k=>$img) {
// if ($img['main'] > 0) {
foreach ($img as $clave => $valor) {
$res[$clave] = $valor;
}
$res['credit'] = '';
$res['caption'] = '';
$result[] = $res;
//}
}
return $result;
} else {
return array();
}
}
}
?>
class Controller_Media extends Controller {
public $schema = 'cont_videos';
public $sections_table = 'cont_sections';
public function action_getmedia() {
$init = (isset($this->params['init']))?$this->params['init']:0;
$content_type = (isset($this->params['content_type']))?$this->params['content_type']:1;
## FILTERS
##########
$where = array();
$where_sql = "";
# ACTIVE
$where['active'] = "{$this->schema}.active = '1'";
# SECTION -> INCLUDE SUBSECTIONS
if(isset($this->params['section_id']) and $this->params['section_id']!=0) {
$q = "SELECT {$this->sections_table}.id FROM {$this->sections_table} WHERE {$this->sections_table}.parent_id = '{$this->params['section_id']}'";
$subsections = $this->db->QueryExecute($q);
foreach ($subsections as $subsection) {
$subsec_str .= "'".$subsection['id']."',";
}
$where['section_id'] = "{$this->schema}.section_id IN (".$subsec_str."'".$this->params['section_id']."')";
}
# SECTION -> INCLUDE SUBSECTIONS
if(isset($this->params['section_ids']) and $this->params['section_ids']!=0) {
$idesect=explode(",", $this->params['section_ids']);
foreach ($idesect as $key => $value) {
$sec_str .= "'".$value."',";
}
$q = "SELECT {$this->sections_table}.id FROM {$this->sections_table} WHERE {$this->sections_table}.id IN (".trim($sec_str,',').") and parent_id = '0'";
$sctions = $this->db->QueryExecute($q);
foreach ($sctions as $sction) {
$q = "SELECT {$this->sections_table}.id FROM {$this->sections_table} WHERE {$this->sections_table}.parent_id = '{$sction['id']}'";
$subsections = $this->db->QueryExecute($q);
foreach ($subsections as $subsection) {
$subsec_str .= "'".$subsection['id']."',";
}
}
$list=trim($sec_str.$subsec_str,',');
$where['section_id'] = "{$this->schema}.section_id IN ( {$list} )";
}
# AUTHOR
if(isset($this->params['author_id']) and $this->params['author_id']!=0){
$where['author_id'] = "{$this->schema}.author_id ='{$this->params['author_id']}'";
}
# STR SEARCH whit type
if(isset($this->params['str']) and $this->params['str']!=''){
$this->params['str'] = urldecode($this->params['str']);
$where['str'] = "{$this->schema}.title LIKE '%{$this->params['str']}%'";
if(isset($this->params['typesearch']) and $this->params['typesearch']!=''){
$where['str'] = "{$this->schema}.{$this->params['typesearch']} LIKE '%{$this->params['str']}%'";
}
}
# IDS
if(isset($this->params['ids'])){
$ids=$this->LimpiaIdesList($this->params['ids']);
$w[] = "{$this->schema}.id IN ({$ids})";
}
# ID (ONLY THIS WHERE)
if(isset($this->params['id']) and $this->params['id']!=0) {
unset($where);
$where['id'] = "{$this->schema}.id = '{$this->params['id']}'";
}
if (count($where)>0){
$where_sql = ' WHERE '.implode($where, ' AND ');
}
## END FILTERS
##############
## ORDER BY
###########
$order_sql = " ORDER BY {$this->schema}.date_created desc";
if(isset($this->params['order']) and $this->params['order']!='') {
$order_sql ="ORDER BY {$this->schema}.".$this->params['order']." desc";
if(isset($this->params['ordertype']) and $this->params['ordertype']!='') {
$order_sql ="ORDER BY {$this->schema}.".$this->params['order']." ".$this->params['ordertype'];
}
if(isset($this->params['date_created']) and $this->params['date_created']!='') {
$where['date_created'] ="{$this->schema}.date_created > '{$this->params['date_created']}'";
}
}
## END ORDER BY
###############
//Limit
if(isset($this->params['limit'])){
$limit_sql = " LIMIT {$init}, {$this->params['limit']}" ;
}else{
$limit_sql = '';
}
$fields = "{$this->schema}.*";
//Limit
if(isset($this->params['only_images']) AND ($this->params['only_images'] == 1) ){
$add_join = "INNER JOIN w_image_content ic ON ({$this->schema}.id = ic.id_engine AND ic.main=1 AND ic.content_type_id=". $content_type .") " ;
}else{
$add_join = '';
}
$sql = " SELECT
".$fields.",
{$this->sections_table}.section_name
FROM
"."{$this->schema}
LEFT JOIN
{$this->sections_table}
ON "."{$this->schema}.section_id = {$this->sections_table}.id
".$add_join."
".$where_sql. " AND {$this->schema}.date_created <= NOW()
GROUP BY {$this->schema}.id
".$order_sql;
$this->db->QueryExecute($sql,false);
$MediasTotal = $this->db->GetNumRows(); /* Para sacar el total */
$sql.=$limit_sql;
if(!isset($this->params['limit'])){
$sql .= "
LIMIT
".$init.", ".$this->perPageCant;
}
$Medias = $this->db->QueryExecute($sql) or $this->db->raise_error();
foreach ($Medias as $Media) {
$Media['intro_text'] = html_entity_decode(htmlentities($this->cutText($Media['intro_text'], '')));
$Media['contentvideo']=$Media['content'];
$Media['content']=html_entity_decode($Media['intro_text']);
$Media['authors_id'] = 'x'.$Media['author_id'].'x';
$Media['section_url'] =BASEURL.'videos.sec-'.$Media['section_id'].'-1-'.string2Url($Media['section_name']).'.html';
$Media['url']=BASEURL.'videos-'.$Media['id'].'-'.string2Url($Media['title']).'.html';
$Media['permanetlink']=BASEURL.'videos-permalink-'.$Media['id'].'.html';
$Media['authors'] = $this->getAuthorsFromModel($Media['author_id'],'videos-');
$Media['imagen'] = $this->getImage($Media['id'],$Media['content_type_id'],0,10);
$result['items'][] = $Media;
}
$result['total'] = $MediasTotal;
return $result;
}
public function action_getsectionsss() {
$content_type = (isset($this->params['content_type']))?$this->params['content_type']:13;
if(isset($this->params['id'])){
$where['id'] = "{$this->sections_table}.id = '{$this->params['id']}'";
}else{
$where['parent_id'] = "{$this->sections_table}.parent_id = '0'";
}
if (count($where)>0){
$where_sql = ' WHERE '.implode($where, ' AND ');
}
$fields = "{$this->sections_table}.*";
$sql = " SELECT
".$fields."
FROM
{$this->sections_table}
".$where_sql. "
ORDER BY
{$this->sections_table}.section_name ASC";
//die($sql);
$sections = $this->db->QueryExecute($sql);
foreach ($sections as $section) {
if($this->params['view']!='mini') {
$section['subsections'] = $this->getSubSections($section['id']);
}
$result[] = $section;
}
return $result;
}
public function action_getsections() {
$content_type = (isset($this->params['content_type']))?$this->params['content_type']:13;
if(isset($this->params['id'])){
$where['id'] = "{$this->sections_table}.id = '{$this->params['id']}'";
}else{
$where['parent_id'] = "{$this->sections_table}.parent_id = '0'";
}
# ID (Solo este Content type)
$where['type'] = "{$this->sections_table}.content_type_id = '{$content_type}'";
if (count($where)>0){
$where_sql = ' WHERE '.implode($where, ' AND ');
}
switch ($this->params['view']) {
case 'mini':
$fields = " {$this->sections_table}.id, {$this->sections_table}.content_type_id, {$this->sections_table}.section_name, {$this->sections_table}.parent_id,
{$this->sections_table}.display_in_ss, {$this->sections_table}.seo_title, {$this->sections_table}.seo_keywords, {$this->sections_table}.seo_description
";
break;
default:
case 'full':
$fields = "cont_sections.*";
break;
}
$sql = "SELECT ".$fields." FROM cont_sections
".$where_sql. "
ORDER BY
{$this->sections_table}.`order` DESC,
{$this->sections_table}.section_name ASC";
$sections = $this->db->QueryExecute($sql);
foreach ($sections as $section) {
$section['section_url'] =BASEURL.'videos.sec-'.$section['id'].'-1-'.string2Url($section['section_name']).'.html';
$resultado[] = $section;
}
return $resultado;
}
}
?>
class Controller_Gallerie extends Controller {
public $schema = 'gals';
public $schema_cat = 'cont_sections';
public $image = 'w_image';
public $image_content = 'w_image_content';
public function action_getgallerie() {
$init = (isset($this->params['init'])) ? $this->params['init'] : 0;
$content_type = (isset($this->params['content_type'])) ? $this->params['content_type'] : 6;
## FILTERS
##########
$where = array();
$where_sql = " WHERE {$this->schema}.visible = 1 AND {$this->schema}.section_id = {$this->schema_cat}.id";
if (isset($this->params['id']) and $this->params['id'] != 0) {
$where_sql .= " AND {$this->schema}.id = {$this->params['id']}";
}
# SECTION -> INCLUDE SUBSECTIONS
if(isset($this->params['section_id']) and $this->params['section_id']!=0) {
$subsec_str="'".$this->params['section_id']."',";
$q = "SELECT id FROM cont_sections WHERE parent_id = '{$this->params['section_id']}'";
$subsections = $this->db->QueryExecute($q);
foreach ($subsections as $subsection) {
$subsec_str .= "'".$subsection['id']."',";
}
$subsec_str=trim($subsec_str,",");
$where_sql .= " AND {$this->schema}.section_id IN (".$subsec_str.")";
}
# SECTION -> INCLUDE SUBSECTIONS
if(isset($this->params['section_ids']) and $this->params['section_ids']!=0) {
$idesect=explode(",", $this->params['section_ids']);
foreach ($idesect as $key => $value) {
$sec_str .= "'".$value."',";
}
$q = "SELECT cont_sections.id FROM cont_sections WHERE cont_sections.id IN (".trim($sec_str,',').") and parent_id = '0'";
$sctions = $this->db->QueryExecute($q);
foreach ($sctions as $sction) {
$q = "SELECT cont_sections.id FROM cont_sections WHERE cont_sections.parent_id = '{$sction['id']}'";
$subsections = $this->db->QueryExecute($q);
foreach ($subsections as $subsection) {
$subsec_str .= "'".$subsection['id']."',";
}
}
$list=trim($sec_str.$subsec_str,',');
$where_sql .= " AND {$this->schema}.section_id IN ( {$list} )";
}
# SECTION -> INCLUDE SUBSECTIONS
if(isset($this->params['author_id']) and $this->params['author_id']!=0) {
$where_sql .= " AND {$this->schema}.author_id ='".$this->params['author_id']."'";
}
# STR SEARCH
if(isset($this->params['str']) and $this->params['str']!=''){
$this->params['str'] = urldecode($this->params['str']);
$where_sql .= " AND gal_name LIKE '%{$this->params['str']}%'";
}
//Limit
if (isset($this->params['limit'])) {
$limit_sql = " LIMIT {$init}, {$this->params['limit']}";
} else {
$limit_sql = '';
}
## ORDER BY
###########
$order_sql = " ORDER BY {$this->schema}.date_created desc,{$this->schema}.id DESC ";
if(isset($this->params['order']) and $this->params['order']!='') {
$order_sql ="ORDER BY ".$this->params['order']." desc";
if(isset($this->params['ordertype']) and $this->params['ordertype']!='') {
$order_sql ="ORDER BY ".$this->params['order']." ".$this->params['ordertype'];
}
if(isset($this->params['date_created']) and $this->params['date_created']!='') {
$where['date_created'] ="{$this->schema}.date_created > '{$this->params['date_created']}'";
}
}
$q = "SELECT {$this->schema}.id,
{$this->schema}.section_id,
{$this->schema}.gal_name as title,
{$this->schema}.content as intro_text,
{$this->schema}.author_id as authors_id,
{$this->schema}.content,
{$this->schema}.content_type_id,
{$this->schema}.visible,
{$this->schema}.views,
{$this->schema}.date_created,
{$this->schema_cat}.section_name
FROM {$this->schema}, {$this->schema_cat}" .
$where_sql.
" GROUP BY {$this->schema}.id ".
$order_sql;
$this->db->QueryExecute($q,false);
$totalRecords = $this->db->GetNumRows(); /* Para sacar el total */
$q .= $limit_sql;
$galleries = $this->db->QueryExecute($q);
//die($q);
foreach ($galleries as $gallery) {
$gallery['intro_text'] = $this->cutText($gallery['intro_text'], $gallery['content']);
$gallery['subtitle'] = $gallery['title'];
$gallery['time_created'] = $gallery['date_created'];
$gallery['active'] = $gallery['visible'];
$gallery['content'] = ($gallery['content']);
$gallery['url'] = BASEURL.'galleries-'.$gallery['id'].'-'.string2Url($gallery['title']).'.html';
$gallery['permanetlink'] = BASEURL.'galleries-permalink-'.$gallery['id'].'.html';
$gallery['section_url'] = BASEURL . "galleries-view-category-" . $gallery['section_id'] . '.html';
$gallery['imagen'] = $this->getImage($gallery['id'], $gallery['content_type_id'],0,15);
$gallery['authors'] = $this->getAuthorsFromModel($gallery['authors_id'],'galleries-');
$result['items'][] = $gallery;
}
$result['total'] = $totalRecords;
return $result;
}
public function action_getimages() {
$limit = (isset($this->params['limit'])) ? $this->params['limit'] : '';
if (isset($this->params['id']) and $this->params['id'] != 0) {
$q = "SELECT id,content_type_id FROM {$this->schema} WHERE {$this->schema}.id = {$this->params['id']}";
$galleries = $this->db->QueryExecute($q);
$listImg = $this->getImage($galleries[0]['id'], $galleries[0]['content_type_id'], 0, $limit);
foreach ($listImg as $value) {
$tempImg['title'] = $value['title'];
$tempImg['url'] = 'galleries-view-photo-' . $this->params['id'] . '-1-' . $value['id'] . '.html';
$tempImg['imagen'] = $value;
$result['items'][] = $tempImg;
}
} else {
$this->db->close();
$result = array();
}
return $result;
}
public function action_getsections() {
$content_type = (isset($this->params['content_type']))?$this->params['content_type']:6;
if(isset($this->params['id'])){
$where['id'] = "cont_sections.id = '{$this->params['id']}'";
}else{
$where['parent_id'] = "cont_sections.parent_id = '0'";
}
# ID (Solo este Content type)
$where['type'] = "{$this->schema_cat}.content_type_id = '{$content_type}'";
if (count($where)>0){
$where_sql = ' WHERE '.implode($where, ' AND ');
}
switch ($this->params['view']) {
case 'mini':
$fields = " cont_sections.id, cont_sections.content_type_id, cont_sections.section_name, cont_sections.parent_id,
cont_sections.display_in_ss, cont_sections.seo_title, cont_sections.seo_keywords, cont_sections.seo_description
";
break;
default:
case 'full':
$fields = "cont_sections.*";
break;
}
$sql = "SELECT ".$fields." FROM cont_sections
".$where_sql. "
ORDER BY
cont_sections.`order` DESC,
cont_sections.section_name ASC";
$sections = $this->db->QueryExecute($sql);
foreach ($sections as $section) {
$section['section_url'] = BASEURL . "galleries-view-category-" . $section['id'] . '.html';
$resultado[] = $section;
}
return $resultado;
}
}
?>
class Controller_Place extends Controller {
public function action_getplace() {
#PARAMETROS INICIALES
$init = $limit = $status = $section = $category = $strin = $id = $typesearch = $order = $sort = '';
$init = (isset($this->params['init'])) ? "init:".$this->params['init']."/" : "";
$content_type = (isset($this->params['content_type'])) ? $this->params['content_type'] : 4;
$limit = (isset($this->params['limit'])) ? "Limit:".$this->params['limit']."/" : 'Limit:20/';
# ACTIVE
$status = "status:1/";
# CATEGORY
$category = (isset($this->params['section_id']) and $this->params['section_id'] != '') ? "categories:" . $this->params['section_id'] . "/": "";
# STR SEARCH
$strin = (isset($this->params['str']) and $this->params['str'] != '') ? "str:" . ($this->params['str']) . "/" : "";
$typesearch = (isset($this->params['typesearch']) and $this->params['typesearch'] != '' and $this->params['typesearch'] != 'title') ? "typesearch:" . ($this->params['typesearch']) . "/" : "";
# SECTION -> INCLUDE SUBSECTIONS
if (isset($this->params['section_id']) and $this->params['section_id'] != 0) {
$section = "category:" . $this->params['section_id'] . "/";
}
# SECTION -> INCLUDE SUBSECTIONS
if (isset($this->params['section_ids']) and $this->params['section_ids'] != 0) {
$section = "categories:" . $this->params['section_ids'] . "/";
}
# ORDER
if (isset($this->params['order']) and $this->params['order'] != '') {
$order = "sort:" . $this->params['order'] . "/";
$sort = "ord:desc/";
if (isset($this->params['sort']) and $this->params['sort'] != '') {
$sort = "ord:" . $this->params['sort'] . "/";
}
}
# ID
$id = (isset($this->params['id']) and $this->params['id'] != 0) ? 'id:' . $this->params['id'] : '';
$url = "http:" . BASEURL2 . "places/no_join:no/widget:1/". $init . $limit . $status . $section . $category . $strin . $id . $typesearch. $order. $sort;
/*echo $url;
die();*/
$places = getFromCurl($url);
$placesData = json_decode($places, true);
$listPlaces = $placesData['resulset'];
switch ($this->params['view']) {
case 'full':
$fields = array('id' => '', 'content_type' => '', 'title' => '', 'subtitle' => '', 'place' => '',
'intro_text' => '', 'content' => '', 'date_created' => '', 'date_finished' => '', 'section_id' => '',
'time_created' => '', 'views' => '', 'display_on_m' => '', "section_name" => '',
"section_url" => '', "url" => '', "permalink" => '', 'imagen' => '',
"tags" => '', "comments" => '', "linkFromNpaper" => '', 'active' => '',
"time_created" => '', "views" => '');
break;
case 'mini':
$fields = array('id' => '', 'content_type' => '', 'title' => '', 'subtitle' => '', 'place' => '',
'intro_text' => '', 'date_created' => '', 'section_id' => '',
'time_created' => '', 'views' => '', 'display_on_m' => '', "section_name" => '',
"section_url" => '', "url" => '', "permalink" => '', 'imagen' => '');
break;
default:
$fields = array('id' => '', 'content_type' => '', 'title' => '', 'subtitle' => '', 'place' => '',
'intro_text' => '', 'content' => '', 'date_created' => '', 'section_id' => '',
'time_created' => '', 'views' => '', 'active' => '', 'comments' => '', 'author_id' => '', 'authors_id' => '', 'display_on_m' => '', "section_name" => '',
"section_url" => '', "url" => '', "permalink" => '', 'imagen' => '', 'authors'=>'');
break;
}
$result['total']=0;
if (count($listPlaces) > 0) {
$count = 0;
$child = '';
$result['total'] = $placesData['header']['total'];
$baseurl='http:'.str_replace("http:","",str_replace("https:","", BASEURL));
foreach ($listPlaces as $r) {
$place['id'] = $r['id'];
$place['title'] = html_entity_decode($r['place_name']);
$place['subtitle'] = html_entity_decode($r['short_description']);
$place['intro_text'] = html_entity_decode($this->cutText($r['medium_description'], $r['descriptionLong']));
$place['content']=html_entity_decode($r['descriptionLong']);
$place['date_created'] = $r['date_modified'];
$place['imagen'] = $this->getImageEvent($r['images']);
$place['author_id'] = $r['user_id'];
$place['authors_id'] = 'x'.$r['user_id'].'x';
$place['active'] = 1;
$place['comments'] = 0;
if(isset($place['imagen']['t1'])){
$place['imagen']['wideamini'] = $place['imagen']['t1'];
}
else{
$place['imagen']['wideamini'] = '';
}
$place['address'] = html_entity_decode($r['address']);
$place['city'] = $r['city'];
$place['zip'] = $r['zip'];
$place['state'] = $r['state'];
$place['lat'] = $r['lat'];
$place['lng'] = $r['lng'];
$place['email'] = $r['email'];
$place['url'] = $baseurl . "places/view/" . $r['id'] . "/" . $this->underscore($r['place_name']) . ".html";
$place['permalink'] = $baseurl . "places/view/" . $r['id'];
$place['tags'] = $r['tags'];
$place['linkFromNpaper'] = $r['paper'];
$place['active'] = $r['status'];
$place['views'] = $r['only_print'];
$valRan=rand(0,count($r['Acategories'])-1);
$place['section_id'] = $r['Acategories'][$valRan]['id'];
$place['section_name'] = html_entity_decode($r['Acategories'][$valRan]['name']);
$place['section_url'] = $baseurl . "places/categories:" . $r['Acategories'][$valRan]['id'];
$place['authors'] = $this->getUserFromModel($place['authors_id']);
$fields = array_intersect_key($place, $fields);
$result['items'][] = $fields;
}
if(((isset($this->params['process']) and $this->params['process']==on))){
$response = $this->analicer_data($result);
$Listado=$this->createViewContent($response,explode(",",$this->params['tplscol']),'');
if(!isset($this->params['array_response'])){
$result=$this->minify_html($Listado);
}
else{
$result['output_response'] = $this->minify_html($Listado);
}
}
}
return $result;
}
public function action_getsections() {
$baseurl='http:'.str_replace("http:","",str_replace("https:","", BASEURL));
if(isset($this->params['id'])){
$id = "/id:".$this->params['id'];
}else{
$id = '';
}
$url = "http:" . BASEURL2 . "places/getListTypesWithCategories/widget:1/no_join:1".$id;
$cats = getFromCurl($url);
$categories = json_decode($cats, true);
if (count($categories) > 0) {
foreach ($categories as $cat) {
$item['id'] = $cat['id'];
$item['section_name'] = $cat['category_name'];
$item['url'] = $baseurl. "places/categories:" . $cat['id'];
$item['subsections'] = $this->getSubSections($item['id'], $categories);
$res[] = $item;
}
}
return $res;
}
private function getSubSections($id, $categories) {
$baseurl='http:'.str_replace("http:","",str_replace("https:","", BASEURL));
foreach ($categories as $cat) {
if ($id == $cat['id']) {
if (count($cat['submenu']) > 0) {
foreach ($cat['submenu'] as $sub) {
$item['id'] = $sub[0];
$item['url'] = $baseurl . "places/categories:" . $sub[0];
$item['section_name'] = $sub[1];
$item['subsections'] = array();
$res[] = $item;
}
}
break;
}
}
return $res;
}
private function getImageEvent($images) {
if (count($images) > 0) {
foreach ($images as $img) {
//if ($img['main'] > 0) {
foreach ($img as $clave => $valor) {
$res[$clave] = $valor;
}
$res['credit'] = '';
$res['caption'] = '';
$result[] = $res;
//}
}
return $result;
} else {
return array();
}
}
}
?>
class Controller_Survey extends Controller {
public $schema = 'surveys';
public $sections_table = 'surveys_categories';
public function action_getsurvey() {
$init = (isset($this->params['init']))?$this->params['init']:0;
$content_type = (isset($this->params['content_type']))?$this->params['content_type']:5;
## FILTERS
##########
$where = array();
$where_sql = "";
# TYPE
$where['type'] = "{$this->schema}.content_type_id = '{$content_type}'";
# ACTIVE
$where['active'] = "{$this->schema}.active = '1'";
#TYPE (1 - Surveys | 2 - Contests)
if(isset($this->params['section_id']) and $this->params['section_id']!=0) {
$where['section_id'] = "{$this->schema}.survey_type_id = {$this->params['section_id']}";
}
# AUTHOR
if(isset($this->params['author_id']) and $this->params['author_id']!=0){
$where['author_id'] = "{$this->schema}.authors_id LIKE '%x{$this->params['author_id']}x%'";
}
# STR SEARCH whit type
if(isset($this->params['str']) and $this->params['str']!=''){
$this->params['str'] = urldecode($this->params['str']);
$where['str'] = "(({$this->schema}.name LIKE '%{$this->params['str']}%') or ({$this->schema}.subtitle LIKE '%{$this->params['str']}%'))";
if(isset($this->params['typesearch']) and $this->params['typesearch']!=''){
$where['str'] = "{$this->schema}.{$this->params['typesearch']} LIKE '%{$this->params['str']}%'";
}
}
# IDS
if(isset($this->params['ids'])){
$ids=$this->LimpiaIdesList($this->params['ids']);
$w[] = "{$this->schema}.id IN ({$ids})";
}
# ID (Solo este Id)
if(isset($this->params['id']) and $this->params['id']!=0) {
unset($where);
$where['id'] = "{$this->schema}.id = '{$this->params['id']}'";
}
# ID (No con este id) //Se aplica a las listas
if(isset($this->params['noid']) and $this->params['noid']!=0) {
$where['noid'] = "{$this->schema}.id != '{$this->params['noid']}'";
}
# IDS (No con esta lista de idea) // Se aplica a las listas
if(isset($this->params['noids'])){
$noids=$this->LimpiaIdesList($this->params['noids']);
$w[] = "{$this->schema}.id IN NOT ({$noids})";
}
## END FILTERS
##############
## ORDER BY
###########
$order_sql = " ORDER BY {$this->schema}.name ASC";
if(isset($this->params['order']) and $this->params['order']!='') {
$order_sql ="ORDER BY {$this->schema}.".$this->params['order']." desc";
}
## END ORDER BY
###############
## Concat FILTERS
##############
if (count($where)>0){
$where_sql = ' WHERE '.implode($where, ' AND ');
}
## End Concat FILTERS
##############
//Limit
if(isset($this->params['limit'])){
$limit_sql = " LIMIT {$init}, {$this->params['limit']}" ;
}else{
$limit_sql = '';
}
switch ($this->params['view']) {
case 'full':
$fields = "{$this->schema}.*";
break;
case 'mini':
$fields = " {$this->schema}.id, {$this->schema}.content_type_id, {$this->schema}.name, {$this->schema}.subtitle,
{$this->schema}.short_description, {$this->schema}.description
";
break;
default:
$fields = " {$this->schema}.id, {$this->schema}.content_type_id, {$this->schema}.name, {$this->schema}.subtitle,
{$this->schema}.short_description, {$this->schema}.description, {$this->schema}.active
";
# code...
break;
}
//Limit
if(isset($this->params['only_images']) AND ($this->params['only_images'] == 1) ){
$add_join = "INNER JOIN w_image_content ic ON ({$this->schema}.id = ic.id_engine AND ic.main=1 AND ic.content_type_id=". $content_type .") " ;
}else{
$add_join = '';
}
$sql = " SELECT
".$fields."
FROM
"."{$this->schema}
".$add_join."
".$where_sql. "
GROUP BY {$this->schema}.id
".$order_sql ;
//print_r($sql);
$this->db->QueryExecute($sql,false);
$surveysTotal = $this->db->GetNumRows(); /* Para sacar el total */
$sql.=$limit_sql;
if(!isset($this->params['limit'])){
$sql .= "
LIMIT
".$init.", ".$this->perPageCant;
}
$surveys = $this->db->QueryExecute($sql) or $this->db->raise_error();
foreach ($surveys as $survey) {
$type=($survey['content_type_id']==1)?'survey':'contest';
$survey['title'] = $survey['name'];
$survey['intro_text'] = html_entity_encode_php4(($this->cutText($survey['short_description'], $survey['description'])));
/*if($this->params['view']=='full') {
$survey['content']=html_entity_encode_php4(stripcslashes($survey['description']));
}else{
$survey['content']='';
}*/
$survey['content']=html_entity_encode_php4(stripcslashes($survey['description']));
$survey['permanetlink']=BASEURL.$type.'-permalink-'.$survey['id'].'-'.string2Url($survey['name']).'.html';
//$survey['section_url'] =BASEURL.$type.'s.sec-'.$survey['section_id'].'-1-'.string2Url($survey['section_name']).'.html';
$survey['url']=BASEURL.$type.'-'.$survey['id'].'-'.string2Url($survey['name']).'.html';
//$survey['permanetlink']=BASEURL.$type.'-permalink-'.$survey['id'].'.html';
//$survey['authors'] = '';
$survey['imagen'] = $this->getImage($survey['id'],$survey['content_type_id'],0,10);
$result['items'][] = $survey;
}
$result['total'] = $surveysTotal;
return $result;
}
public function action_getsections() {
$content_type = (isset($this->params['content_type']))?$this->params['content_type']:1;
if(isset($this->params['id'])){
$where['id'] = "{$this->sections_table}.id = '{$this->params['id']}'";
}
if (count($where)>0){
$where_sql = ' WHERE '.implode($where, ' AND ');
}
switch ($this->params['view']) {
case 'mini':
$fields = " {$this->sections_table}.id, {$this->sections_table}.content_type_id, {$this->sections_table}.name
";
break;
default:
case 'full':
$fields = "{$this->sections_table}.*";
break;
}
$sql = "SELECT ".$fields." FROM {$this->sections_table}
".$where_sql. " AND
{$this->sections_table}.content_type_id = ".$content_type."
ORDER BY
{$this->sections_table}.`order` DESC,
{$this->sections_table}.name ASC";
$sections = $this->db->QueryExecute($sql);
foreach ($sections as $section) {
$type=($section['content_type_id']==1)?'survey':'contest';
$section['section_url'] =BASEURL.$type.'s.sec-'.$section['id'].'-1-'.string2Url($section['name']).'.html';
if($this->params['view']!='mini') {
$section['subsections'] = $this->getSubSections($section['id']);
}
$resultado[] = $section;
}
return $resultado;
}
}
?>
class Controller_Section extends Controller {
public $schema = 'cont_sections';
public function action_getsection() {
$init = (isset($this->params['init']))?$this->params['init']:0;
## FILTERS
##########
$where = array();
$where_sql = "";
# TYPE
if(isset($this->params['type']) ){
$where['type'] = "{$this->schema}.content_type_id = {$this->params['type']}";
}
# PARENT
if(isset($this->params['parent_id']) ){
$where['parent_id'] = "{$this->schema}.parent_id = {$this->params['parent_id']}";
}
# STR SEARCH whit type
if(isset($this->params['str']) and $this->params['str']!=''){
$this->params['str'] = urldecode($this->params['str']);
$where['str'] = "({$this->schema}.section_name LIKE '%{$this->params['str']}%')";
if(isset($this->params['typesearch']) and $this->params['typesearch']!=''){
$where['str'] = "{$this->schema}.{$this->params['typesearch']} LIKE '%{$this->params['str']}%'";
}
}
# IDS
if(isset($this->params['ids'])){
$ids=$this->LimpiaIdesList($this->params['ids']);
$w[] = "{$this->schema}.id IN ({$ids})";
}
# ID (Solo este Id)
if(isset($this->params['id']) and $this->params['id']!=0) {
unset($where);
$where['id'] = "{$this->schema}.id = '{$this->params['id']}'";
}
# ID (No con este id) //Se aplica a las listas
if(isset($this->params['noid']) and $this->params['noid']!=0) {
$where['noid'] = "{$this->schema}.id != '{$this->params['noid']}'";
}
# IDS (No con esta lista de idea) // Se aplica a las listas
if(isset($this->params['noids'])){
$noids=$this->LimpiaIdesList($this->params['noids']);
$w[] = "{$this->schema}.id IN NOT ({$noids})";
}
## END FILTERS
##############
## ORDER BY
###########
$order_sql = " ORDER BY {$this->schema}.order ASC,{$this->schema}.section_name ASC ";
if(isset($this->params['order']) and $this->params['order']!='') {
$order_sql ="ORDER BY {$this->schema}.".$this->params['order']." desc";
}
## END ORDER BY
###############
## Concat FILTERS
##############
if (count($where)>0){
$where_sql = ' WHERE '.implode($where, ' AND ');
}
## End Concat FILTERS
##############
//Limit
if(isset($this->params['limit'])){
$limit_sql = " LIMIT {$init}, {$this->params['limit']}" ;
}else{
$limit_sql = '';
}
$fields = " {$this->schema}.*";
//Limit
if(isset($this->params['only_images']) AND ($this->params['only_images'] == 1) ){
$add_join = "INNER JOIN w_image_content ic ON ({$this->schema}.id = ic.id_engine AND ic.main=1 AND ic.content_type_id=11) " ;
}else{
$add_join = '';
}
$sql = " SELECT
".$fields."
FROM
"."{$this->schema}
".$add_join."
".$where_sql. "
GROUP BY {$this->schema}.id
".$order_sql ;
$this->db->QueryExecute($sql,false);
$itemsTotal = $this->db->GetNumRows(); /* Para sacar el total */
$sql.=$limit_sql;
if(!isset($this->params['limit'])){
$sql .= "
LIMIT
".$init.", ".$this->perPageCant;
}
$items = $this->db->QueryExecute($sql) or $this->db->raise_error();
foreach ($items as $item) {
$data['id'] = $item['id'];
$data['content_type_id'] = $item['content_type_id'];
# TYPE NAME
$q="SELECT id,type,icon FROM cont_types WHERE id='".$data['content_type_id']."'";
$rcla=$this->db->FetchAssoc($this->db->QueryExecute($q));
$type=strtolower($rcla['type']);
if($type == 'media')
$type = 'video';
$data['title'] = $item['section_name'];
$data['parent_id'] = $item['parent_id'];
$data['seo_title'] = $item['seo_title'];
$data['seo_description'] = $item['seo_description'];
$data['seo_keywords'] = $item['seo_keywords'];
$data['contentorder'] = $item['contentorder'];
$data['cantidad'] = $item['cantidad'];
$data['intro_text'] = html_entity_encode_php4(stripcslashes($item['top_text']));
$data['url'] = BASEURL.$type.'s.sec-'.$item['id'].'-1-'.string2Url($item['section_name']).'.html';
$data['permanetlink'] = BASEURL.$type.'s.sec-'.$item['id'].'-1-.html';
$data['imagen'] = $this->getImage($item['id'],11);
/*if($item['parent_id'] > 0)
$item['parent'] = $this->getParentSection($item['parent_id'], $type);*/
if(isset($this->params['id'])) {
if($item['parent_id'] == 0)
$data['subsections'] = $this->getSubSections($item['id'], $type);
if($item['parent_id'] > 0)
$data['parent'] = $this->getParentSection($item['parent_id'], $type);
}
$result['items'][] = $data;
}
$result['total'] = $itemsTotal;
return $result;
}
public function getParentSection($id, $type) {
$resultado = array();
$where['id'] = "cont_sections.id = '{$id}'";
if (count($where)>0){
$where_sql = ' WHERE '.implode($where, ' AND ');
}
$fields = "cont_sections.*";
$sql = "SELECT ".$fields." FROM cont_sections
".$where_sql. "
ORDER BY
cont_sections.`order` DESC,
cont_sections.section_name ASC";
$item = $this->db->FetchAssoc($this->db->QueryExecute($sql));
if(is_array($item)){
$data['id'] = $item['id'];
$data['content_type_id'] = $item['content_type_id'];
$data['section_name'] = $item['section_name'];
$data['parent_id'] = $item['parent_id'];
$data['contentorder'] = $item['contentorder'];
$data['cantidad'] = $item['cantidad'];
$data['intro_text'] = html_entity_encode_php4(stripcslashes($item['top_text']));
$data['url'] = BASEURL.$type.'s.sec-'.$item['id'].'-1-'.string2Url($item['section_name']).'.html';
$data['permanetlink'] = BASEURL.$type.'s.sec-permalink-'.$item['id'].'-1-.html';
$data['imagen'] = $this->getImage($item['id'],11);
if($data['parent_id']>0)
{
$data['parent'] = $this->getParentSection($item['parent_id'], $type);
}
$result[] = $data;
}
return $result;
}
private function getSubSections($id,$type){
switch ($this->params['view']) {
case 'mini':
$fields = " cont_sections.id, cont_sections.content_type_id, cont_sections.section_name, cont_sections.parent_id,
cont_sections.display_in_ss,cont_sections.seo_title, cont_sections.seo_keywords, cont_sections.seo_description
";
break;
default:
case 'full':
$fields = "cont_sections.*";
break;
}
$sql = " SELECT
".$fields."
FROM
cont_sections
WHERE
cont_sections.parent_id = '".$id."'
ORDER BY
cont_sections.`order` DESC,
cont_sections.section_name ASC";
$items = $this->db->QueryExecute($sql);
foreach ($items as $item) {
$data['id'] = $item['id'];
$data['content_type_id'] = $item['content_type_id'];
$data['section_name'] = $item['section_name'];
$data['parent_id'] = $item['parent_id'];
$data['intro_text'] = html_entity_encode_php4(stripcslashes($item['top_text']));
$data['url'] = BASEURL.$type.'s.sec-'.$item['id'].'-1-'.string2Url($item['section_name']).'.html';
$data['permanetlink'] = BASEURL.$type.'s.sec-permalink-'.$item['id'].'-1-.html';
$data['imagen'] = $this->getImage($item['id'],11);
$result['items'][] = $data;
}
return $result;
}
}
?>
class Controller_Author extends Controller {
public $schema = 'cont_authors';
public function action_getauthor() {
$init = (isset($this->params['init']))?$this->params['init']:0;
## FILTERS
##########
$where = array();
$where_sql = "";
# TYPE
if(isset($this->params['type']) ){
$where['type'] = "{$this->schema}.content_type_id = {$this->params['type']}";
}
# STR SEARCH whit type
if(isset($this->params['str']) and $this->params['str']!=''){
$this->params['str'] = urldecode($this->params['str']);
$where['str'] = "({$this->schema}.author_name LIKE '%{$this->params['str']}%')";
if(isset($this->params['typesearch']) and $this->params['typesearch']!=''){
$this->params['typesearch']=($this->params['typesearch']=='title')?'author_name':$this->params['typesearch'];
$where['str'] = "{$this->schema}.{$this->params['typesearch']} LIKE '%{$this->params['str']}%'";
}
}
# IDS
if(isset($this->params['ids'])){
$ids=$this->LimpiaIdesList($this->params['ids']);
$w[] = "{$this->schema}.id IN ({$ids})";
}
# ID (Solo este Id)
if(isset($this->params['id']) and $this->params['id']!=0) {
unset($where);
$where['id'] = "{$this->schema}.id = '{$this->params['id']}'";
}else{
$where['author_name'] = "{$this->schema}.author_name !=''";
}
# ID (No con este id) //Se aplica a las listas
if(isset($this->params['noid']) and $this->params['noid']!=0) {
$where['noid'] = "{$this->schema}.id != '{$this->params['noid']}'";
}
# IDS (No con esta lista de idea) // Se aplica a las listas
if(isset($this->params['noids'])){
$noids=$this->LimpiaIdesList($this->params['noids']);
$w[] = "{$this->schema}.id IN NOT ({$noids})";
}
## END FILTERS
##############
## ORDER BY
###########
$order_sql = " ORDER BY {$this->schema}.author_name ASC";
if(isset($this->params['order']) and $this->params['order']!='') {
$order_sql ="ORDER BY {$this->schema}.".$this->params['order']." desc";
}
## END ORDER BY
###############
## Concat FILTERS
##############
if (count($where)>0){
$where_sql = ' WHERE '.implode($where, ' AND ');
}
## End Concat FILTERS
##############
//Limit
if(isset($this->params['limit'])){
$limit_sql = " LIMIT {$init}, {$this->params['limit']}" ;
}else{
$limit_sql = '';
}
switch ($this->params['view']) {
default:
$fields = " {$this->schema}.*
";
break;
}
//Limit
if(isset($this->params['only_images']) AND ($this->params['only_images'] == 1) ){
$add_join = "INNER JOIN w_image_content ic ON ({$this->schema}.id = ic.id_engine AND ic.main=1 AND ic.content_type_id=8) " ;
}else{
$add_join = '';
}
$sql = " SELECT
".$fields."
FROM
"."{$this->schema}
".$add_join."
".$where_sql. "
GROUP BY {$this->schema}.id
".$order_sql ;
$this->db->QueryExecute($sql,false);
$itemsTotal = $this->db->GetNumRows(); /* Para sacar el total */
$sql.=$limit_sql;
$items = $this->db->QueryExecute($sql) or $this->db->raise_error();
foreach ($items as $item) {
$data['id'] = $item['id'];
$data['content_type_id'] = $item['content_type_id'];
$data['title'] = $item['author_name'];
$data['email'] = $item['email'];
$data['phone'] = $item['phone'];
$data['facebook'] = $item['facebook'];
$data['twitter'] = $item['twitter'];
$data['linkedin'] = $item['linkedin'];
$data['website'] = $item['website'];
$data['intro_text'] = html_entity_encode_php4(stripcslashes($item['bio']));
$data['url'] = BASEURL.'by-author-'.$data['id'].'-1.html';
$data['permanetlink'] = BASEURL.'by-author-'.$data['id'].'-1.html';
$data['imagen'] = $this->getImage($item['id'],8);
$result['items'][] = $data;
}
$result['total'] = $itemsTotal;
return $result;
}
}
?>
class Controller_Poll extends Controller {
public $schema = 'poller';
public $sections_table = 'cont_sections';
public function action_getpoll() {
$init = (isset($this->params['init']))?$this->params['init']:0;
$content_type = (isset($this->params['content_type']))?$this->params['content_type']:20;
## FILTERS
##########
$where = array();
$where_sql = "";
# ACTIVE
$where['active'] = "{$this->schema}.active = '1'";
# SECTION -> INCLUDE SUBSECTIONS
if(isset($this->params['section_id']) and $this->params['section_id']!=0) {
$q = "SELECT {$this->sections_table}.id FROM {$this->sections_table} WHERE {$this->sections_table}.parent_id = '{$this->params['section_id']}'";
$subsections = $this->db->QueryExecute($q);
foreach ($subsections as $subsection) {
$subsec_str .= "'".$subsection['id']."',";
}
$where['section_id'] = "{$this->schema}.section_id IN (".$subsec_str."'".$this->params['section_id']."')";
}
# SECTION -> INCLUDE SUBSECTIONS
if(isset($this->params['section_ids']) and $this->params['section_ids']!=0) {
$idesect=explode(",", $this->params['section_ids']);
foreach ($idesect as $key => $value) {
$sec_str .= "'".$value."',";
}
$q = "SELECT {$this->sections_table}.id FROM {$this->sections_table} WHERE {$this->sections_table}.id IN (".trim($sec_str,',').") and parent_id = '0'";
$sctions = $this->db->QueryExecute($q);
foreach ($sctions as $sction) {
$q = "SELECT {$this->sections_table}.id FROM {$this->sections_table} WHERE {$this->sections_table}.parent_id = '{$sction['id']}'";
$subsections = $this->db->QueryExecute($q);
foreach ($subsections as $subsection) {
$subsec_str .= "'".$subsection['id']."',";
}
}
$list=trim($sec_str.$subsec_str,',');
$where['section_id'] = "{$this->schema}.section_id IN ( {$list} )";
}
# STR SEARCH whit type
if(isset($this->params['str']) and $this->params['str']!=''){
$this->params['str'] = urldecode($this->params['str']);
$where['str'] = "{$this->schema}.title LIKE '%{$this->params['str']}%'";
if(isset($this->params['typesearch']) and $this->params['typesearch']!=''){
$where['str'] = "{$this->schema}.{$this->params['typesearch']} LIKE '%{$this->params['str']}%'";
}
}
# IDS
if(isset($this->params['ids'])){
$ids=$this->LimpiaIdesList($this->params['ids']);
$w[] = "{$this->schema}.id IN ({$ids})";
}
# ID (ONLY THIS WHERE)
if(isset($this->params['id']) and $this->params['id']!=0) {
unset($where);
$where['id'] = "{$this->schema}.id = '{$this->params['id']}'";
}
if (count($where)>0){
$where_sql = ' WHERE '.implode($where, ' AND ');
}
## END FILTERS
##############
## ORDER BY
###########
$order_sql = " ORDER BY {$this->schema}.date_created desc";
if(isset($this->params['order']) and $this->params['order']!='') {
$order_sql ="ORDER BY {$this->schema}.".$this->params['order']." desc";
if(isset($this->params['ordertype']) and $this->params['ordertype']!='') {
$order_sql ="ORDER BY {$this->schema}.".$this->params['order']." ".$this->params['ordertype'];
}
if(isset($this->params['date_created']) and $this->params['date_created']!='') {
$where['date_created'] ="{$this->schema}.date_created > '{$this->params['date_created']}'";
}
}
## END ORDER BY
###############
//Limit
if(isset($this->params['limit'])){
$limit_sql = " LIMIT {$init}, {$this->params['limit']}" ;
}else{
$limit_sql = '';
}
$fields = "{$this->schema}.*";
//Limit
if(isset($this->params['only_images']) AND ($this->params['only_images'] == 1) ){
$add_join = "INNER JOIN w_image_content ic ON ({$this->schema}.id = ic.id_engine AND ic.main=1 AND ic.content_type_id=". $content_type .") " ;
}else{
$add_join = '';
}
$sql = " SELECT
".$fields.",
{$this->sections_table}.section_name
FROM
"."{$this->schema}
LEFT JOIN
{$this->sections_table}
ON "."{$this->schema}.section_id = {$this->sections_table}.id
".$add_join."
".$where_sql. " AND {$this->schema}.date_created <= NOW()
GROUP BY {$this->schema}.id
".$order_sql;
$this->db->QueryExecute($sql,false);
$Total = $this->db->GetNumRows(); /* Para sacar el total */
$sql.=$limit_sql;
if(!isset($this->params['limit'])){
$sql .= "
LIMIT
".$init.", ".$this->perPageCant;
}
$Polls = $this->db->QueryExecute($sql) or $this->db->raise_error();
foreach ($Polls as $Poll) {
$dta=explode(' ',$Poll['date_created']);
$Poll['time_created']=$Poll['date_created'];
$Poll['date_created']=$dta[0];
$Poll['content_type_id'] =20;
$Poll['intro_text'] = html_entity_decode(htmlentities($this->cutText($Poll['description'], '')));
$Poll['content']=html_entity_decode($Poll['intro_text']);
$Poll['section_url'] =BASEURL.'polls.sec-'.$Poll['section_id'].'-1-'.string2Url($Poll['section_name']).'.html';
$Poll['url']=BASEURL.'poll-'.$Poll['id'].'-'.string2Url($Poll['title']).'.html';
$Poll['permanetlink']=BASEURL.'poll-permalink-'.$Poll['id'].'.html';
$Poll['social'] =$this->getsocial($Poll['permanetlink'],$Poll['id'],$Poll['content_type_id']);
$Poll['imagen'] = $this->getImage($Poll['id'],$Poll['content_type_id'],0,10);
$Poll['options'] = $this->optionsPoll($Poll['id']);
$Poll['total_votes']=$this->getTotalVotes($Poll['id']);
$result['items'][] = $Poll;
}
$result['total'] = $Total;
return $result;
}
public function optionsPoll($idpoll){
$query="SELECT id, option_text FROM poller_option WHERE poller_id='{$idpoll}' order by poller_order asc";
$rop=$this->db->QueryExecute($query);
$result=array();
if(is_array($rop[0])){
foreach ($rop as $options) {
$percent=0;
$total=$this->getTotalVotes($idpoll);
$temp=array();
$temp['id']=$options['id'];
$temp['option_text']=$options['option_text'];
$temp['votes']=$this->getVotes($options['id']);
if($temp['votes']>0){
$temp['percentage']=round(($temp['votes']*100)/$total);
}
$result[]=$temp;
}
}
return $result;
}
public function getVotes($idoption){
$query="SELECT count(id) AS cant FROM poller_vote WHERE option_id='{$idoption}' group by option_id";
//echo $query;
$rvo=$this->db->QueryExecute($query);
if($rvo[0]['cant']!=''){
return $rvo[0]['cant'];
}else{
return 0;
}
}
public function getTotalVotes($poll_id){
$query="SELECT count(id) AS cant FROM poller_vote WHERE poll_id='{$poll_id}' group by poll_id";
$rvo=$this->db->QueryExecute($query);
if($rvo[0]['cant']!=''){
return $rvo[0]['cant'];
}else{
return 0;
}
}
public function action_getpollview(){
# ID (ONLY THIS WHERE)
global $ApiData;
if(isset($this->params['id']) and $this->params['id']!=0) {
$idpoll=$this->params['id'];
$polldata=$this->action_getpoll();
$resul=$ApiData->Rendenrice('core/polls.tpl', array('data' => $polldata['items'][0]) );
//print_r($polldata);
/*
if($polldata['items'][0]['active']=='1'){
if($polldata['items'][0]['description']!=''){
$resul.=''.$polldata['items'][0]['description'].'
';
}
$resul.='';
}else{
return $this->action_getpollResulSet();
}
*/
return $resul;
}else{
return 'Error Data!!';
}
}
public function action_getpollResulSet(){
if(isset($this->params['id']) and $this->params['id']!=0 and $this->params['id']!='') {
if(isset($this->params['vote']) and $this->params['vote']!=0 and $this->params['vote']!='') {
return $this->inserVote();
}else{
return 0;
}
}
}
private function inserVote(){
$idpoll=$this->params['id'];
$idoption=$this->params['vote'];
$date=date('Y-m-d H:i:S');
$query="INSERT INTO poller_vote SET poll_id='{$idpoll}', option_id='{$idoption}', voted_on='{$date}', ip='".$this->get_client_ip()."'";
//echo $query;
return $this->db->Execute($query);
}
function get_client_ip() {
$ipaddress = '';
if (isset($_SERVER['HTTP_CLIENT_IP']))
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if(isset($_SERVER['HTTP_X_FORWARDED']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
else if(isset($_SERVER['HTTP_FORWARDED']))
$ipaddress = $_SERVER['HTTP_FORWARDED'];
else if(isset($_SERVER['REMOTE_ADDR']))
$ipaddress = $_SERVER['REMOTE_ADDR'];
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
public function action_getsectionsss() {
$content_type = (isset($this->params['content_type']))?$this->params['content_type']:20;
if(isset($this->params['id'])){
$where['id'] = "{$this->sections_table}.id = '{$this->params['id']}'";
}else{
$where['parent_id'] = "{$this->sections_table}.parent_id = '0'";
}
if (count($where)>0){
$where_sql = ' WHERE '.implode($where, ' AND ');
}
$fields = "{$this->sections_table}.*";
$sql = " SELECT
".$fields."
FROM
{$this->sections_table}
".$where_sql. "
ORDER BY
{$this->sections_table}.section_name ASC";
$sections = $this->db->QueryExecute($sql);
foreach ($sections as $section) {
if($this->params['view']!='mini') {
$section['subsections'] = $this->getSubSections($section['id']);
}
$result[] = $section;
}
return $result;
}
public function action_getsections() {
$content_type = (isset($this->params['content_type']))?$this->params['content_type']:20;
if(isset($this->params['id'])){
$where['id'] = "{$this->sections_table}.id = '{$this->params['id']}'";
}else{
$where['parent_id'] = "{$this->sections_table}.parent_id = '0'";
}
# ID (Solo este Content type)
$where['type'] = "{$this->sections_table}.content_type_id = '{$content_type}'";
if (count($where)>0){
$where_sql = ' WHERE '.implode($where, ' AND ');
}
switch ($this->params['view']) {
case 'mini':
$fields = " {$this->sections_table}.id, {$this->sections_table}.content_type_id, {$this->sections_table}.section_name, {$this->sections_table}.parent_id,
{$this->sections_table}.display_in_ss, {$this->sections_table}.seo_title, {$this->sections_table}.seo_keywords, {$this->sections_table}.seo_description
";
break;
default:
case 'full':
$fields = "cont_sections.*";
break;
}
$sql = "SELECT ".$fields." FROM cont_sections
".$where_sql. "
ORDER BY
{$this->sections_table}.`order` DESC,
{$this->sections_table}.section_name ASC";
$sections = $this->db->QueryExecute($sql);
foreach ($sections as $section) {
$section['section_url'] =BASEURL.'polls.sec-'.$section['id'].'-1-'.string2Url($section['section_name']).'.html';
$resultado[] = $section;
}
return $resultado;
}
}
?>
Fatal error: Class 'Controller' not found in /var/www/vhosts/fitpro.wehaaserver.com/httpdocs/inc/WehaaCore/ApiWehaa.php on line 37