/**
  * Saves the article an edit form submit
  * @param database A database connector object
  */
 function saveContent()
 {
     global $mainframe;
     // Check for request forgeries
     JRequest::checkToken() or jexit('Invalid Token');
     // Initialize variables
     $db =& JFactory::getDBO();
     $user =& JFactory::getUser();
     $dispatcher =& JDispatcher::getInstance();
     JPluginHelper::importPlugin('content');
     $details = JRequest::getVar('details', array(), 'post', 'array');
     $option = JRequest::getCmd('option');
     $task = JRequest::getCmd('task');
     $sectionid = JRequest::getVar('sectionid', 0, '', 'int');
     $redirect = JRequest::getVar('redirect', $sectionid, 'post', 'int');
     $menu = JRequest::getVar('menu', 'mainmenu', 'post', 'menutype');
     $menuid = JRequest::getVar('menuid', 0, 'post', 'int');
     $nullDate = $db->getNullDate();
     $row =& JTable::getInstance('content');
     if (!$row->bind(JRequest::get('post'))) {
         JError::raiseError(500, $db->stderr());
         return false;
     }
     $row->bind($details);
     // sanitise id field
     $row->id = (int) $row->id;
     $isNew = true;
     // Are we saving from an item edit?
     if ($row->id) {
         $isNew = false;
         $datenow =& JFactory::getDate();
         $row->modified = $datenow->toMySQL();
         $row->modified_by = $user->get('id');
     }
     $row->created_by = $row->created_by ? $row->created_by : $user->get('id');
     if ($row->created && strlen(trim($row->created)) <= 10) {
         $row->created .= ' 00:00:00';
     }
     $config =& JFactory::getConfig();
     $tzoffset = $config->getValue('config.offset');
     $date =& JFactory::getDate($row->created, $tzoffset);
     $row->created = $date->toMySQL();
     // Append time if not added to publish date
     if (strlen(trim($row->publish_up)) <= 10) {
         $row->publish_up .= ' 00:00:00';
     }
     $date =& JFactory::getDate($row->publish_up, $tzoffset);
     $row->publish_up = $date->toMySQL();
     // Handle never unpublish date
     if (trim($row->publish_down) == JText::_('Never') || trim($row->publish_down) == '') {
         $row->publish_down = $nullDate;
     } else {
         if (strlen(trim($row->publish_down)) <= 10) {
             $row->publish_down .= ' 00:00:00';
         }
         $date =& JFactory::getDate($row->publish_down, $tzoffset);
         $row->publish_down = $date->toMySQL();
     }
     // Get a state and parameter variables from the request
     $row->state = JRequest::getVar('state', 0, '', 'int');
     $params = JRequest::getVar('params', null, 'post', 'array');
     // Build parameter INI string
     if (is_array($params)) {
         $txt = array();
         foreach ($params as $k => $v) {
             $txt[] = "{$k}={$v}";
         }
         $row->attribs = implode("\n", $txt);
     }
     // Get metadata string
     $metadata = JRequest::getVar('meta', null, 'post', 'array');
     if (is_array($metadata)) {
         $txt = array();
         foreach ($metadata as $k => $v) {
             if ($k == 'description') {
                 $row->metadesc = $v;
             } elseif ($k == 'keywords') {
                 $row->metakey = $v;
             } else {
                 $txt[] = "{$k}={$v}";
             }
         }
         $row->metadata = implode("\n", $txt);
     }
     // Prepare the content for saving to the database
     ContentHelper::saveContentPrep($row);
     // Make sure the data is valid
     if (!$row->check()) {
         JError::raiseError(500, $db->stderr());
         return false;
     }
     // Increment the content version number
     $row->version++;
     $result = $dispatcher->trigger('onBeforeContentSave', array(&$row, $isNew));
     if (in_array(false, $result, true)) {
         JError::raiseError(500, $row->getError());
         return false;
     }
     // Store the content to the database
     if (!$row->store()) {
         JError::raiseError(500, $db->stderr());
         return false;
     }
     // Check the article and update item order
     $row->checkin();
     $row->reorder('catid = ' . (int) $row->catid . ' AND state >= 0');
     /*
      * We need to update frontpage status for the article.
      *
      * First we include the frontpage table and instantiate an instance of it.
      */
     require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_frontpage' . DS . 'tables' . DS . 'frontpage.php';
     $fp = new TableFrontPage($db);
     // Is the article viewable on the frontpage?
     if (JRequest::getVar('frontpage', 0, '', 'int')) {
         // Is the item already viewable on the frontpage?
         if (!$fp->load($row->id)) {
             // Insert the new entry
             $query = 'INSERT INTO #__content_frontpage' . ' VALUES ( ' . (int) $row->id . ', 1 )';
             $db->setQuery($query);
             if (!$db->query()) {
                 JError::raiseError(500, $db->stderr());
                 return false;
             }
             $fp->ordering = 1;
         }
     } else {
         // Delete the item from frontpage if it exists
         if (!$fp->delete($row->id)) {
             $msg .= $fp->stderr();
         }
         $fp->ordering = 0;
     }
     $fp->reorder();
     $cache =& JFactory::getCache('com_content');
     $cache->clean();
     $dispatcher->trigger('onAfterContentSave', array(&$row, $isNew));
     switch ($task) {
         case 'go2menu':
             $mainframe->redirect('index.php?option=com_menus&menutype=' . $menu);
             break;
         case 'go2menuitem':
             $mainframe->redirect('index.php?option=com_menus&menutype=' . $menu . '&task=edit&id=' . $menuid);
             break;
         case 'menulink':
             ContentHelper::menuLink($redirect, $row->id);
             break;
         case 'resethits':
             ContentHelper::resetHits($redirect, $row->id);
             break;
         case 'apply':
             $msg = JText::sprintf('SUCCESSFULLY SAVED CHANGES TO ARTICLE', $row->title);
             $mainframe->redirect('index.php?option=com_content&sectionid=' . $redirect . '&task=edit&cid[]=' . $row->id, $msg);
             break;
         case 'save':
         default:
             $msg = JText::sprintf('Successfully Saved Article', $row->title);
             $mainframe->redirect('index.php?option=com_content&sectionid=' . $redirect, $msg);
             break;
     }
 }
 /**
  * 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)\n\t\t\t\t\tSELECT 'content','{$row->id}',v.field_id AS field, v.id AS value\n\t\t\t\t\tFROM #__custom_properties_values v\n                                        WHERE v.parent_id = {$partidoId}\n\t\t\t\t\tAND v.id = {$zonaId}\n                                        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;
         }
     }
 }
Example #3
0
 /**
  * Persiste el contenido del modelo en la base de datos.
  *
  * @param boolean $updateNulls FALSE para no actualizar campos que contengan NULL
  * @param boolean $use_post_data TRUE para recuperar datos desde POST
  * @param Array $data Si $use_post_data es FALSE, especifica los datos a persistir
  * @return boolean TRUE si el registro fue guardado exitosamente
  */
 function store($updateNulls = false, $use_post_data = true, $data = null)
 {
     $row =& $this->getTable();
     /**
      * Decide de donde recuperar la información a persistir. Esta puede
      * provenir de las variables POST, ser los datos ya contenidos en el
      * modelo ($this->_data) o ser especificada por medio del parametro
      * $data.
      */
     if ($use_post_data) {
         $data = JRequest::get('post');
     } else {
         if (is_null($data)) {
             $data = $this->_data;
         } else {
             $this->_data = $data;
         }
     }
     /**
      * Realiza el binding de los datos a persistir con el objeto JTable, y
      * ejecuta a continuación el método afterBind(). Este último metodo
      * debe ser sobrecargado en los modelos que extiendan BaseModel.
      */
     if (!$row->bind($data)) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     $this->afterBind($row);
     // Texto generado por editor
     if (!is_null(JRequest::getVar('text', null))) {
         ContentHelper::saveContentPrep($row);
     }
     // Almancena los metadatos si estos estan presentes
     $metadata = JRequest::getVar('meta', null, 'post', 'array');
     if (is_array($metadata)) {
         $txt = array();
         foreach ($metadata as $k => $v) {
             if ($k == 'description') {
                 $row->metadesc = $v;
             } elseif ($k == 'keywords') {
                 $row->metakey = $v;
             } else {
                 $txt[] = "{$k}={$v}";
             }
         }
         $row->metadata = implode("\n", $txt);
     }
     /**
      * Realiza el chequeo de los datos a persistir. En caso de éxito pasa
      * a ejecutar el metodo afterCheck() el cual debe ser sobrecargado en
      * los modelos que extiendan BaseModel para ofrecer chequeos especificos
      * para cada caso.
      */
     if (!$row->check()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     $this->afterCheck($row);
     // Persiste el modelo en la base de datos
     if (JError::isError($row->store($updateNulls))) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     // ¿Hack?
     $this->setId($row->id);
     return true;
 }
Example #4
0
 function saveArticle()
 {
     // Initialize variables
     $db =& FabrikWorker::getDbo();
     $user =& JFactory::getUser();
     $dispatcher =& JDispatcher::getInstance();
     JPluginHelper::importPlugin('content');
     $this->_postFabrikDataAsArticleData();
     $details = JRequest::getVar('details', array(), 'post', 'array');
     $option = JRequest::getCmd('option');
     $sectionid = JRequest::getVar('sectionid', 0, '', 'int');
     $nullDate = $db->getNullDate();
     $row =& FabTable::getInstance('content');
     if (!$row->bind(JRequest::get('post'))) {
         JError::raiseError(500, $db->stderr());
         return false;
     }
     $row->bind($details);
     // sanitise id field
     $row->id = (int) $row->id;
     $this->_isNew = true;
     // Are we saving from an item edit?
     if ($row->id) {
         $this->_isNew = false;
         $datenow = JFactory::getDate();
         $row->modified = $datenow->toMySQL();
         $row->modified_by = $user->get('id');
     }
     $row->created_by = $row->created_by ? $row->created_by : $user->get('id');
     if ($row->created && strlen(trim($row->created)) <= 10) {
         $row->created .= ' 00:00:00';
     }
     $config =& JFactory::getConfig();
     $tzoffset = $config->getValue('config.offset');
     $date =& JFactory::getDate($row->created, $tzoffset);
     $row->created = $date->toMySQL();
     // Append time if not added to publish date
     if (strlen(trim($row->publish_up)) <= 10) {
         $row->publish_up .= ' 00:00:00';
     }
     $date =& JFactory::getDate($row->publish_up, $tzoffset);
     $row->publish_up = $date->toMySQL();
     // Handle never unpublish date
     if (trim($row->publish_down) == JText::_('Never') || trim($row->publish_down) == '') {
         $row->publish_down = $nullDate;
     } else {
         if (strlen(trim($row->publish_down)) <= 10) {
             $row->publish_down .= ' 00:00:00';
         }
         $date =& JFactory::getDate($row->publish_down, $tzoffset);
         $row->publish_down = $date->toMySQL();
     }
     // Get a state and parameter variables from the request
     // should probably punt this logic into the controller, but for now ...
     $articlePublishElementName = $this->_elementBaseName($this->_articlePublishElement);
     $row->state = $this->_formModel->_formData[$articlePublishElementName];
     // probably an array, i.e. coming from a yes/no radio or dropdown
     if (is_array($row->state)) {
         $row->state = $row->state[0];
     }
     $params = JRequest::getVar('params', null, 'post', 'array');
     $row->params = json_encode($params);
     // Get metadata string
     $metadata = JRequest::getVar('meta', null, 'post', 'array');
     if (is_array($metadata)) {
         $txt = array();
         foreach ($metadata as $k => $v) {
             if ($k == 'description') {
                 $row->metadesc = $v;
             } elseif ($k == 'keywords') {
                 $row->metakey = $v;
             } else {
                 $txt[] = "{$k}={$v}";
             }
         }
         $row->metadata = implode("\n", $txt);
     }
     // Prepare the content for saving to the database
     ContentHelper::saveContentPrep($row);
     // Make sure the data is valid
     if (!$row->check()) {
         JError::raiseError(500, $db->stderr());
         return false;
     }
     // Increment the content version number
     $row->version++;
     $result = $dispatcher->trigger('onBeforeContentSave', array(&$row, $this->_isNew));
     if (in_array(false, $result, true)) {
         JError::raiseError(500, $row->getError());
         return false;
     }
     // Store the content to the database
     if (!$row->store()) {
         JError::raiseError(500, $db->stderr());
         return false;
     }
     $this->_articleId = $row->id;
     // Check the article and update item order
     $row->checkin();
     $row->reorder('catid = ' . (int) $row->catid . ' AND state >= 0');
     //		*
     //		 * We need to update frontpage status for the article.
     //		 *
     //		 * First we include the frontpage table and instantiate an instance of it.
     //		 *
     require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_frontpage' . DS . 'tables' . DS . 'frontpage.php';
     $fp = new TableFrontPage($db);
     // Is the article viewable on the frontpage?
     if (JRequest::getVar('frontpage', 0, '', 'int')) {
         // Is the item already viewable on the frontpage?
         if (!$fp->load($row->id)) {
             // Insert the new entry
             $query = 'INSERT INTO #__content_frontpage' . ' VALUES ( ' . (int) $row->id . ', 1 )';
             $db->setQuery($query);
             if (!$db->query()) {
                 JError::raiseError(500, $db->stderr());
                 return false;
             }
             $fp->ordering = 1;
         }
     } else {
         // Delete the item from frontpage if it exists
         if (!$fp->delete($row->id)) {
             $msg .= $fp->stderr();
         }
         $fp->ordering = 0;
     }
     $fp->reorder();
     $cache =& JFactory::getCache('com_content');
     $cache->clean();
     $dispatcher->trigger('onAfterContentSave', array(&$row, $this->_isNew));
 }
Example #5
0
 /**
  * Salva el contenido del modelo en la base de datos.
  *
  * @param boolean $updateNulls
  * @param boolean $use_post_data
  * @param Array $data datos a almacenar (no tomar del post)
  * @return boolean true si el registro fue guardado exitosamente
  */
 function store($updateNulls = false, $use_post_data = true, $data = null)
 {
     $row =& $this->getTable();
     //$data = $use_post_data ? JRequest::get('post') : $this->_data;
     if ($use_post_data) {
         $data = JRequest::get('post');
     } else {
         if (is_null($data)) {
             $data = $this->_data;
         } else {
             $this->_data = $data;
         }
     }
     if (!$row->bind($data)) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     $this->afterBind($row);
     // Texto generado por editor
     if (!is_null(JRequest::getVar('text', null))) {
         ContentHelper::saveContentPrep($row);
     }
     // Almancena los metadatos si estos estan presentes
     $metadata = JRequest::getVar('meta', null, 'post', 'array');
     if (is_array($metadata)) {
         $txt = array();
         foreach ($metadata as $k => $v) {
             if ($k == 'description') {
                 $row->metadesc = $v;
             } elseif ($k == 'keywords') {
                 $row->metakey = $v;
             } else {
                 $txt[] = "{$k}={$v}";
             }
         }
         $row->metadata = implode("\n", $txt);
     }
     // Make sure the record is valid
     if (!$row->check()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     $this->afterCheck($row);
     // Store the table to the database
     //if (!$row->store($updateNulls)) {
     if (JError::isError($row->store($updateNulls))) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     // ¿Hack?
     $this->setId($row->id);
     return true;
 }