Ejemplo n.º 1
0
 /**
  * process the plugin, called afer form is submitted
  *
  * !!!! NOTE this is the ONLY form plugin that should use onLastProcess
  *
  * @param object $params (with the current active plugin values in them)
  * @param object form
  */
 function onLastProcess($params, &$formModel)
 {
     $session =& JFactory::getSession();
     $context = 'com_fabrik.form.' . $formModel->_id . '.redirect.';
     //get existing session params
     $surl = (array) $session->get($context . 'url', array());
     $stitle = (array) $session->get($context . 'title', array());
     $smsg = (array) $session->get($context . 'msg', array());
     $sshowsystemmsg = (array) $session->get($context . 'showsystemmsg', array());
     $app =& JFactory::getApplication();
     $this->formModel =& $formModel;
     $w = new FabrikWorker();
     $this->_data = new stdClass();
     $this->_data->append_jump_url = $params->get('append_jump_url');
     $this->_data->save_in_session = $params->get('save_insession');
     $form =& $formModel->getForm();
     // $$$ hugh - swapped args round, otherwise _formData takes precedence,
     // which makes getEmailData() pretty much redundant.
     // NOTE - this may cause some issues with existing usage for things like checkboxes
     //$this->data 		= array_merge($this->getEmailData(), $formModel->_formData);
     $this->data = array_merge($formModel->_formData, $this->getEmailData());
     $this->_data->jump_page = $w->parseMessageForPlaceHolder($params->get('jump_page'), $this->data);
     // $$$ hugh - added helper func to pull a URL apart and urlencode any QS args.
     // Fixes issue where people use &foo={table___element} in their jump URL's and the data
     // has special characters in it.
     $this->_data->jump_page = FabrikString::encodeurl($this->_data->jump_page);
     $this->_data->thanks_message = $w->parseMessageForPlaceHolder($params->get('thanks_message'), $this->data);
     if (!$this->shouldRedirect($params)) {
         //clear any sessoin redirects
         unset($surl[$this->renderOrder]);
         unset($stitle[$this->renderOrder]);
         unset($smsg[$this->renderOrder]);
         unset($sshowsystemmsg[$this->renderOrder]);
         $session->set($context . 'url', $surl);
         $session->set($context . 'title', $stitle);
         $session->set($context . 'msg', $smsg);
         $session->set($context . 'showsystemmsg', $sshowsystemmsg);
         return true;
     }
     $this->_storeInSession($formModel);
     $sshowsystemmsg[$this->renderOrder] = $this->_data->thanks_message == '' ? false : true;
     $session->set($context . 'showsystemmsg', $sshowsystemmsg);
     if ($this->_data->jump_page != '') {
         $this->_data->jump_page = $this->_buildJumpPage($formModel);
         if (JRequest::getVar('fabrik_postMethod', '') != 'ajax' || $params->get('redirect_inajax') == 1) {
             //dont redirect if form is in part of a package (or a module with 'use ajax' option turned on)
             $surl[$this->renderOrder] = $this->_data->jump_page;
             $session->set($context . 'url', $surl);
         }
     } else {
         $sshowsystemmsg[$this->renderOrder] = false;
         $session->set($context . 'showsystemmsg', $sshowsystemmsg);
         $stitle[$this->renderOrder] = $form->label;
         $session->set($context . 'title', $stitle);
         $surl[$this->renderOrder] = 'index.php?option=com_fabrik&controller=plugin&g=form&plugin=fabrikredirect&method=displayThanks&task=pluginAjax';
         $session->set($context . 'url', $surl);
     }
     $smsg[$this->renderOrder] = $this->_data->thanks_message;
     $session->set($context . 'msg', $smsg);
     return true;
 }
Ejemplo n.º 2
0
 /**
  * Manipulates posted form data for insertion into database
  *
  * @param   mixed  $val   this elements posted form data
  * @param   array  $data  posted form data
  *
  * @return  mixed
  */
 public function storeDatabaseFormat($val, $data)
 {
     /* $$$ hugh - added 'normalization' of links, to add http:// if no :// in the link.
      * not sure if we really want to do it here, or only when rendering?
      * $$$ hugh - quit normalizing links.
      */
     $params = $this->getParams();
     if (is_array($val)) {
         if ($params->get('use_bitly')) {
             require_once JPATH_SITE . '/components/com_fabrik/libs/bitly/bitly.php';
             $login = $params->get('bitly_login');
             $key = $params->get('bitly_apikey');
             $bitly = new bitly($login, $key);
         }
         foreach ($val as $key => &$v) {
             if (is_array($v)) {
                 if ($params->get('use_bitly')) {
                     /* bitly will return an error if you try and shorten a shortened link,
                      * and the class file we are using doesn't check for this
                      */
                     if (!strstr($v['link'], 'bit.ly/') && $v['link'] !== '') {
                         $v['link'] = (string) $bitly->shorten($v['link']);
                     }
                 }
             } else {
                 if ($key == 'link') {
                     $v = FabrikString::encodeurl($v);
                 }
                 // Not in repeat group
                 if ($key == 'link' && $params->get('use_bitly')) {
                     if (!strstr($v, 'bit.ly/') && $v !== '') {
                         $v = (string) $bitly->shorten($v);
                     }
                 }
             }
         }
     } else {
         if (json_decode($val)) {
             return $val;
         }
     }
     $return = json_encode($val);
     return $return;
 }