-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.php
436 lines (363 loc) · 15.1 KB
/
controller.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
<?php
/**
* @version $Id$
* @package Zonales
* @copyright Copyright (C) 2009 Mediabit. All rights reserved.
* @license GNU/GPL, see LICENSE.php
*
* Zonales is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');
jimport('joomla.application.component.controller');
/**
* Controlador
*
* @package Zonales
* @since 1.5
*/
class ZonalesController extends JController {
/** @var class */
var $_zonalesHelper = null;
function __construct($default = array()) {
parent::__construct($default);
$this->_zonalesHelper = new comZonalesHelper();
}
function zonal() {
$option = JRequest::getCMD('option');
$document = &JFactory::getDocument();
$vType = $document->getType();
$vName = JRequest::getCmd('view', 'zonal');
$vLayout = JRequest::getCmd('layout', 'default');
$view = & $this->getView($vName, $vType);
$view->setLayout($vLayout);
$view->display();
}
function mapa() {
$option = JRequest::getCMD('option');
$document = & JFactory::getDocument();
$vType = $document->getType();
$vName = JRequest::getCmd('view', 'mapa');
$vLayout = JRequest::getCmd('layout', 'default');
$view = & $this->getView($vName, $vType);
$view->setLayout($vLayout);
$view->display();
}
/**
* Setea o actualiza la variable de sesión con el zonal actualmente
* seleccionado por el usuario, y redirecciona a la URL de retorno
* especificada.
*/
function setZonal($zname = null) {
$option = JRequest::getCMD('option');
// parametros
if (is_null($zname)) {
$zname = JRequest::getVar('zname', NULL, 'post', 'string');
}
$return = JRequest::getVar('return', 'index.php', 'post', 'string');
// al utilizar flashbar & para separar variables el url puede estar divido
$view = JRequest::getVar('view', NULL, 'post', 'string');
$item = JRequest::getVar('Itemid', NULL, 'post', 'int');
if ($view && $item)
$return .= '&view=' . $view . '&Itemid=' . $item;
$session = JFactory::getSession();
if ($zname) {
$zonal = $this->_zonalesHelper->getZonal($zname);
if ($zonal) {
$session->set('zonales_zonal_name', $zonal->name);
$session->set('zonales_zonal_label', $zonal->label);
} else {
$session->set('zonales_zonal_name', NULL);
$session->set('zonales_zonal_label', NULL);
}
} else {
$session->set('zonales_zonal_name', NULL);
$session->set('zonales_zonal_label', NULL);
}
$this->setRedirect($return);
}
/**
* Setea o actualiza la variable de sesión con el zonal actualmente
* seleccionado por el usuario, y redirecciona a la URL de retorno
* especificada.
*
* @param int $id identificador del zonal
*/
function setZonalById($id) {
if (is_null($id)) {
$id = JRequest::getVar('zonalid', NULL, 'post', 'int');
}
$dbo = & JFactory::getDBO();
$query = 'SELECT ' . $dbo->nameQuote('v.id') . ', ' . $dbo->nameQuote('v.name') . ', ' .
$dbo->nameQuote('v.label')
. ' FROM ' . $dbo->nameQuote('#__custom_properties_values') . ' v'
. ' WHERE ' . $dbo->nameQuote('v.id') . ' = ' . $id;
$dbo->setQuery($query);
$r = $dbo->loadObject();
$this->setZonal($r->name);
}
/**
* Limpia el zonal actual.
*
* @param int $id identificador del zonal
*/
function clearZonal($id) {
$this->setZonal(null);
}
/**
* Setea o actualiza la variable de sesión con el zonal actualmente
* seleccionado por el usuario, y retorna mensaje de confirmación.
* Este mètodo debe ser utilizado en operaciones tipo ajax.
*/
function setZonalAjax() {
$zname = JRequest::getVar('zname', NULL, 'post', 'string');
$sesid = JRequest::getVar('PHPSESSID', NULL, 'post', 'string');
$usemap = JRequest::getVar('usemap', true, 'post', 'string');
if ($sesid)
session_id($sesid);
$result = "failure";
$message = "Zonal desconocido";
if ($zname) {
$zonal = $this->_zonalesHelper->getZonal($zname);
if ($zonal) {
$session = JFactory::getSession();
$session->set('zonales_zonal_name', ($zonal->name));
$session->set('zonales_zonal_label', ($zonal->label));
$result = "success";
$message = $zonal->label;
} else {
$session->set('zonales_zonal_name', NULL);
$session->set('zonales_zonal_label', NULL);
}
}
if ($usemap) {
echo "result=$result&message=$message";
}
return;
}
/**
*
* @return <type>
*/
function getFieldValuesAjax() {
$partidoId = JRequest::getVar('fieldId', NULL, 'get', 'int');
if ($partidoId) {
$helper = new comZonalesHelper();
$values = $helper->getLocalidadesByPartido($partidoId);
if (sizeof($values)) {
echo JHTML::_('select.genericlist', $values, 'localidad', 'size="1" class="required"', 'id', 'label');
} else {
echo JText::_("No se han recuperado localidades");
}
} else {
echo 'prueba';
}
return;
}
/**
* Almacena la noticia enviada por el usuario a traves de una instancia
* del módulo mod_soycorresponsal.
*/
function saveCorresponsalContent() {
$mainframe=JFactory::getApplication();
jimport('json.json');
$helper = new comZonalesHelper();
$response = array();
// chequea irregularidades en el request
JRequest::checkToken() or jexit('Invalid Token');
// titulo del modulo que envio el request
$moduleTitle = JRequest::getVar('module', NULL, 'post', 'string');
// chequea que el modulo especificado en el request sea valido
if (!$moduleTitle) {
jexit($helper->getJsonResponse('failure', 'Error interno', 'No module name'));
} else {
jimport('joomla.application.module.helper');
$module = JModuleHelper::getModule('soycorresponsal', $moduleTitle);
if ($module->id == 0) {
jexit($helper->getJsonResponse('failure', 'Error interno', 'Invalid module'));
}
}
// recupera parametros del módulo
$modparams = new JParameter($module->params);
// librería recaptcha
jimport('recaptcha.recaptchalib');
// parametros del componente
$zonalesParams = &JComponentHelper::getParams('com_zonales');
$privatekey = $zonalesParams->get('recaptcha_privatekey', null);
if (!$privatekey) {
jexit($helper->getJsonResponse('failure', $modparams->get('error'), 'No recaptcha private key'));
} else {
// validamos la respuesta del usuario
$challenge = JRequest::getVar('recaptcha_challenge_field', NULL, 'post', 'string');
$response = JRequest::getVar('recaptcha_response_field', NULL, 'post', 'string');
$resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $challenge, $response);
if (!$resp->is_valid) {
jexit($helper->getJsonResponse('captcha-failure', $modparams->get('error'), 'Invalid response'));
} else {
// inicializa variables a utilizar
$db = & JFactory::getDBO();
$user = & JFactory::getUser();
if ($user->guest) {
$user = & JFactory::getUser($modparams->get('user'));
}
//$catid = $modparams->get('category', 0);
$nullDate = $db->getNullDate();
// tabla de contenidos joomla
$row = & JTable::getInstance('content');
/* if ($catid > 0) {
$category =& JTable::getInstance('category');
$category->load($catid);
$sectionid = $category->section;
} */
$nullDate = $db->getNullDate();
$row->title = JRequest::getVar('title', NULL, 'post', 'string');
$row->sectionid = 0;
$row->catid = 0;
$row->version = 0;
$row->state = 1;
$row->ordering = 0;
$row->images = array();
$row->publish_down = $nullDate;
$row->created_by = $user->get('id');
$row->modified = gmdate('Y-m-d H:i:s');
// corrección de la fecha
$config = & JFactory::getConfig();
$row->created = gmdate('Y-m-d H:i:s');
$row->publish_up = gmdate('Y-m-d 00:00:00');
// se redondea timestamp de creación
if ($row->created && strlen(trim($row->created)) <= 10) {
$row->created .= ' 00:00:00';
}
// Prepare the content for saving to the database
require_once(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_content' . DS . 'helper.php');
ContentHelper::saveContentPrep($row);
// Se agregan nombre de usuario, correo y telefono
$enviaNombre = JRequest::getVar('nombre', NULL, 'post', 'string');
$enviaEmail = JRequest::getVar('email', NULL, 'post', 'string');
$enviaTel = JRequest::getVar('telefono', NULL, 'post', 'string');
$row->introtext = $row->introtext . "<p>Envio esta noticia:</p><p>Nombre: $enviaNombre<br/>Email: $enviaEmail<br/>";
/**
* Para videos de YouTube, arreglo la url para que se pueda ver
*/
$searchString = "watch?v=";
$imgPos = 0;
while (($imgPos = strpos($row->introtext, $searchString, $imgPos))) {
$strPre = substr($row->introtext, 0, $imgPos);
$strPos = substr($row->introtext, $imgPos + strlen($searchString));
$row->introtext = $strPre . 'v/' . $strPos;
}
// Make sure the data is valid
if (!$row->check()) {
JError::raiseError(500, $db->stderr());
}
// Store the content to the database
if (!$row->store()) {
JError::raiseError(500, $db->stderr());
}
// Check the article and update item order
$row->checkin();
$row->reorder('catid = ' . (int) $row->catid . ' AND state >= 0');
// Asignamos los tags de Custom Properties según los valores de zonal y localidad
$partidoId = JRequest::getVar('provincias_sc', NULL, 'post', 'int');
$zonaId = JRequest::getVar('localidad', NULL, 'post', 'int');
$query = "REPLACE INTO #__custom_properties (ref_table, content_id,field_id,value_id)
SELECT 'content','$row->id',v.field_id AS field, v.id AS value
FROM #__custom_properties_values v
WHERE v.parent_id = $partidoId
AND v.id = $zonaId
OR v.name = 'la_voz_del_vecino'";
$database = JFactory::getDBO();
$database->setQuery($query);
$database->query();
// Process the content preparation plugins
JPluginHelper::importPlugin('content');
$dispatcher = & JDispatcher::getInstance();
$dispatcher->trigger('onAfterContentSave', array(&$row, ($row->id < 1)));
// Todo ok, enviamos confirmación
echo $helper->getJsonResponse('success', $modparams->get('confirmacion'));
return;
}
}
}
/**
* Genera un select html listando todos los values que sean hijos directos
* del tag con el identificador $id.
*
* @param int $id identificador tag padre
* @param string $name id y nombre del select html
* @return String select html
*/
function getItemsAjax($id = null, $name = null, $selected = null, $class = null) {
if (is_null($id)) {
$id = JRequest::getVar('id', NULL, 'get', 'int');
}
if (is_null($name)) {
$name = JRequest::getVar('name', NULL, 'get', 'string');
}
if (is_null($selected)) {
$selected = JRequest::getVar('selected', NULL, 'get', 'string');
}
if (is_null($class)) {
$class = JRequest::getVar('class', 'item_ajax_select', 'get', 'string');
}
$helper = new comZonalesHelper();
$parents = $helper->getItems($id);
echo JHTML::_('select.genericlist', $parents, $name,
'size="1" class="' . $class . ' required"', 'id', 'label', $selected);
return;
}
/**
* Chequea la disponibilidad del nombre de usuario suministrado por el usuario cuando intenta registrarse.
*
* @param string $username Nombre de usuario a chequear
* @return String Mensaje de error si corresponde
*/
function getUsernameDisponibility() {
$username = JRequest::getVar('username', NULL, 'get', 'string');
$r = 0;
if (!is_null($username)) {
$dbo = & JFactory::getDBO();
$query = 'SELECT count(*) '
. ' FROM ' . $dbo->nameQuote('#__users') . ' u'
. ' WHERE ' . $dbo->nameQuote('u.username') . ' = \'' . $username . '\'';
$dbo->setQuery($query);
$r = $dbo->loadResult();
}
if ($r > 0)
echo JText::_('USERNAME_ERROR_MESSAGE');
return;
}
function setFilters() {
$filters = JRequest::getVar('filters', 0, '', 'array');
if (isset($filters)) {
comZonalesHelper::setFilters($filters);
}
}
function setFilter() {
$filters = JRequest::getVar('filters', 0, '', 'array');
if (isset($filters)) {
foreach ($filters as $key => $value) {
comZonalesHelper::setFilter($key, $value);
}
}
}
function addSource(){
$source = JRequest::getVar('source', 0, '', 'string');
if (isset($source)){
comZonalesHelper::addSource($source);
}
}
function removeSource(){
$source = JRequest::getVar('source', 0, '', 'string');
if (isset($source)){
comZonalesHelper::removeSource($source);
}
}
function getZCtx(){
comZonalesHelper::getZCtx();
}
}