/** * Can the row be edited * * @param object $params plugin params * @param object $listModel list model * @param object $row current row to test * * @return boolean */ public function onCanEdit($params, $listModel, $row) { // If $row is null, we were called from the table's canEdit() in a per-table rather than per-row context, // and we don't have an opinion on per-table edit permissions, so just return true. if (is_null($row) || is_null($row[0])) { return true; } if (is_array($row[0])) { $data = JArrayHelper::toObject($row[0]); } else { $data = $row[0]; } $field = str_replace('.', '___', $params->get('caneditrow_field')); // If they provided some PHP to eval, we ignore the other settings and just run their code $caneditrow_eval = $params->get('caneditrow_eval', ''); // $$$ rob if no can edit field selected in admin return true if (trim($field) == '' && trim($caneditrow_eval) == '') { return true; } if (!empty($caneditrow_eval)) { $w = new FabrikWorker(); $data = JArrayHelper::fromObject($data); $caneditrow_eval = $w->parseMessageForPlaceHolder($caneditrow_eval, $data); $caneditrow_eval = @eval($caneditrow_eval); FabrikWorker::logEval($caneditrow_eval, 'Caught exception on eval in can edit row : %s'); return $caneditrow_eval; } else { // No PHP given, so just do a simple match on the specified element and value settings. if ($params->get('caneditrow_useraw', '0') == '1') { $field .= '_raw'; } $value = $params->get('caneditrow_value'); return $data->{$field} == $value; } }
/** * looks at the validation condition & evaulates it * if evaulation is true then the validation rule is applied *@return bol apply validation */ function shouldValidate($data, $c) { $params =& $this->getParams(); $post = JRequest::get('post'); $v = $params->get($this->_pluginName . '-validation_condition', '', '_default', 'array', $c); if (!array_key_exists($c, $v)) { return true; } $condition = $v[$c]; if ($condition == '') { return true; } $w = new FabrikWorker(); // $$$ rob merge join data into main array so we can access them in parseMessageForPlaceHolder() $joindata = JArrayHelper::getValue($post, 'join', array()); foreach ($joindata as $joinid => $joind) { foreach ($joind as $k => $v) { if ($k !== 'rowid') { $post[$k] = $v; } } } $condition = trim($w->parseMessageForPlaceHolder($condition, $post)); // $$$ hugh - this screws things up if it's more than one line of code. /* if (substr(strtolower($condition ), 0, 6) !== 'return') { $condition = "return $condition"; } */ $res = @eval($condition); if (is_null($res)) { return true; } return $res; }
/** * Run right at the end of the form processing * form needs to be set to record in database for this to hook to be called * * @param object $params plugin params * @param object &$formModel form model * * @return bool */ public function onAfterProcess($params, &$formModel) { $w = new FabrikWorker(); $config_userpass = $params->get('username') . ':' . $params->get('password'); $endpoint = $params->get('endpoint'); $headers = array('Content-Type: application/xml', 'Accept: application/xml'); // Set where we should post the REST request to $endpoint = $w->parseMessageForPlaceholder($endpoint); $endpoint = $w->parseMessageForPlaceholder($endpoint); // What is the root node for the xml data we are sending $xmlParent = $params->get('xml_parent', 'ticket'); $xmlParent = $w->parseMessageForPlaceholder($xmlParent); $xml = new SimpleXMLElement('<' . $xmlParent . '></' . $xmlParent . '>'); // Set up CURL object $chandle = curl_init(); // Set which fields should be included in the XML data. $include = $w->parseMessageForPlaceholder($params->get('include_list', 'milestone-id, status, summary')); $include = explode(',', $include); foreach ($include as $i) { if (array_key_exists($i, $formModel->_formData)) { $xml->addChild($i, $formModel->_formData[$i]); } elseif (array_key_exists($i, $formModel->_fullFormData, $i)) { $xml->addChild($i, $formModel->_fullFormData[$i]); } } $output = $xml->asXML(); $curl_options = array(CURLOPT_URL => $endpoint, CURLOPT_RETURNTRANSFER => 1, CURLOPT_HTTPHEADER => $headers, CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $output, CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_USERPWD => $config_userpass, CURLOPT_CUSTOMREQUEST => 'POST'); foreach ($curl_options as $key => $value) { curl_setopt($chandle, $key, $value); } $output = curl_exec($chandle); $httpCode = curl_getinfo($chandle, CURLINFO_HTTP_CODE); switch ($httpCode) { case '400': echo "Bad Request"; break; case '401': echo "Unauthorized"; break; case '404': echo "Not found"; break; case '405': echo "Method Not Allowed"; break; case '406': echo "Not Acceptable"; break; case '415': echo "Unsupported Media Type"; break; case '500': echo "Internal Server Error"; break; } if (curl_errno($chandle)) { die("ERROR: " . curl_error($chandle)); } curl_close($chandle); }
/** * Can the row be edited * * @param object $row Current row to test * * @return boolean */ public function onCanEdit($row) { $params = $this->getParams(); // If $row is null, we were called from the list's canEdit() in a per-table rather than per-row context, // and we don't have an opinion on per-table edit permissions, so just return true. if (is_null($row) || is_null($row[0])) { return true; } if (is_array($row[0])) { $data = ArrayHelper::toObject($row[0]); } else { $data = $row[0]; } /** * If __pk_val is not set or empty, then we've probably been called from somewhere in form processing, * and this is a new row. In which case this plugin cannot offer any opinion! */ if (!isset($data->__pk_val) || empty($data->__pk_val)) { return true; } $field = str_replace('.', '___', $params->get('caneditrow_field')); // If they provided some PHP to eval, we ignore the other settings and just run their code $caneditrow_eval = $params->get('caneditrow_eval', ''); // $$$ rob if no can edit field selected in admin return true if (trim($field) == '' && trim($caneditrow_eval) == '') { $this->acl[$data->__pk_val] = true; return true; } if (!empty($caneditrow_eval)) { $w = new FabrikWorker(); $data = ArrayHelper::fromObject($data); $caneditrow_eval = $w->parseMessageForPlaceHolder($caneditrow_eval, $data); FabrikWorker::clearEval(); $caneditrow_eval = @eval($caneditrow_eval); FabrikWorker::logEval($caneditrow_eval, 'Caught exception on eval in can edit row : %s'); $this->acl[$data['__pk_val']] = $caneditrow_eval; return $caneditrow_eval; } else { // No PHP given, so just do a simple match on the specified element and value settings. if ($params->get('caneditrow_useraw', '0') == '1') { $field .= '_raw'; } $value = $params->get('caneditrow_value'); $operator = $params->get('operator', '='); if (is_object($data->{$field})) { $data->{$field} = ArrayHelper::fromObject($data->{$field}); } switch ($operator) { case '=': default: $return = is_array($data->{$field}) ? in_array($value, $data->{$field}) : $data->{$field} == $value; break; case "!=": $return = is_array($data->{$field}) ? !in_array($value, $data->{$field}) : $data->{$field} != $value; break; } $this->acl[$data->__pk_val] = $return; return $return; } }
/** * Decorate the J2Store product information with its related Fabrik record * * @param $product * * @return object */ private function getFabrikItem(&$product) { list($component, $listId) = explode('.', $product->product_source); $key = $listId . '.' . $product->product_source_id; static $sets; if (!is_array($sets)) { $sets = array(); } if (!isset($sets[$key])) { JModelLegacy::addIncludePath(COM_FABRIK_FRONTEND . '/models', 'FabrikFEModel'); /** @var FabrikFEModelList $listModel */ $listModel = JModelLegacy::getInstance('List', 'FabrikFEModel'); $listModel->setId($listId); $formModel = $listModel->getFormModel(); $formModel->setRowId($product->product_source_id); $row = $formModel->getData(); $params = $formModel->getParams(); $index = array_search('j2store', (array) $params->get('plugins', array(), 'array')); $w = new FabrikWorker(); $plugIn = FabrikWorker::getPluginManager()->loadPlugIn('j2store', 'form'); // Set params relative to plugin render order $plugInParams = $plugIn->setParams($params, $index); $context = new stdClass(); $context->title = $w->parseMessageForPlaceHolder($plugInParams->get('j2store_product_name'), $row); $context->published = $w->parseMessageForPlaceHolder($plugInParams->get('j2store_enabled'), $row); $objectRow = JArrayHelper::toObject($row); $context->viewLink = $listModel->viewDetailsLink($objectRow); $context->editLink = $listModel->editLink($objectRow); $context->id = $objectRow->__pk_val; $sets[$key] = $context; } //echo "<pre>";print_r($sets);echo "</pre>"; return $sets[$key]; }
/** * Draws the form element * * @param array $data to pre-populate element with * @param int $repeatCounter repeat group counter * * @return string returns element html */ public function render($data, $repeatCounter = 0) { $params = $this->getParams(); $displayData = new stdClass(); $displayData->num = $params->get('fbcomment_number_of_comments', 10); $displayData->width = $params->get('fbcomment_width', 300); $displayData->colour = $params->get('fb_comment_scheme') == '' ? '' : ' colorscheme="dark" '; $displayData->href = $params->get('fbcomment_href', ''); if (empty($data->href)) { $rowId = $this->app->input->getString('rowid', '', 'string'); if ($rowId != '') { $formModel = $this->getFormModel(); $formId = $formModel->getId(); $href = 'index.php?option=com_fabrik&view=form&formid=' . $formId . '&rowid=' . $rowId; $href = JRoute::_($href); $displayData->href = COM_FABRIK_LIVESITE_ROOT . $href; } } if (!empty($displayData->href)) { $w = new FabrikWorker(); $displayData->href = $w->parseMessageForPlaceHolder($data->href, $data); $locale = $params->get('fbcomment_locale', 'en_US'); if (empty($locale)) { $locale = 'en_US'; } $displayData->graphApi = FabrikHelperHTML::facebookGraphAPI($params->get('opengraph_applicationid'), $locale); } $layout = $this->getLayout('form'); return $layout->render($displayData); }
/** * looks at the validation condition & evaulates it * if evaulation is true then the validation rule is applied *@return bol apply validation */ function shouldValidate($data, $c) { $params = $this->getParams(); $post = JRequest::get('post'); $v = (array)$params->get($this->_pluginName .'-validation_condition'); if (!array_key_exists($c, $v)) { return true; } $condition = $v[$c]; if ($condition == '') { return true; } $w = new FabrikWorker(); // $$$ rob merge join data into main array so we can access them in parseMessageForPlaceHolder() $joindata = JArrayHelper::getValue($post, 'join', array()); foreach ($joindata as $joinid => $joind) { foreach ($joind as $k => $v) { if ($k !== 'rowid') { $post[$k] = $v; } } } $condition = trim($w->parseMessageForPlaceHolder($condition, $post)); $res = @eval($condition); if (is_null($res)) { return true; } return $res; }
/** * Main setup routine for displaying the form/detail view * * @param string $tpl template * * @return void */ public function display($tpl = null) { if (parent::display($tpl) !== false) { $this->setCanonicalLink(); $this->output(); if (!$this->app->isAdmin()) { $this->state = $this->get('State'); $model = $this->getModel(); $this->params = $this->state->get('params'); $row = $model->getData(); $w = new FabrikWorker(); if ($this->params->get('menu-meta_description')) { $desc = $w->parseMessageForPlaceHolder($this->params->get('menu-meta_description'), $row); $this->doc->setDescription($desc); } if ($this->params->get('menu-meta_keywords')) { $keywords = $w->parseMessageForPlaceHolder($this->params->get('menu-meta_keywords'), $row); $this->doc->setMetadata('keywords', $keywords); } if ($this->params->get('robots')) { $this->doc->setMetadata('robots', $this->params->get('robots')); } } } }
/** * process the plugin, called when form is submitted * * @param object $params * @param object form */ function onAfterProcess($params, &$formModel) { if ($params->get('ask-receipt')) { $post = JRequest::get('post'); if (!array_key_exists('fabrik_email_copy', $post)) { return; } } $config =& JFactory::getConfig(); $w = new FabrikWorker(); $this->formModel =& $formModel; $form =& $formModel->getForm(); //getEmailData returns correctly formatted {tablename___elementname} keyed results //_formData is there for legacy and may allow you to use {elementname} only placeholders for simple forms $aData = array_merge($this->getEmailData(), $formModel->_formData); $message = $params->get('receipt_message'); $editURL = COM_FABRIK_LIVESITE . "index.php?option=com_fabrik&view=form&fabrik=" . $formModel->get('id') . "&rowid=" . JRequest::getVar('rowid'); $viewURL = COM_FABRIK_LIVESITE . "index.php?option=com_fabrik&view=details&fabrik=" . $formModel->get('id') . "&rowid=" . JRequest::getVar('rowid'); $editlink = "<a href=\"{$editURL}\">" . JText::_('EDIT') . "</a>"; $viewlink = "<a href=\"{$viewURL}\">" . JText::_('VIEW') . "</a>"; $message = str_replace('{fabrik_editlink}', $editlink, $message); $message = str_replace('{fabrik_viewlink}', $viewlink, $message); $message = str_replace('{fabrik_editurl}', $editURL, $message); $message = str_replace('{fabrik_viewurl}', $viewURL, $message); $message = $w->parseMessageForPlaceHolder($message, $aData, false); $to = $w->parseMessageForPlaceHolder($params->get('receipt_to'), $aData, false); if (empty($to)) { // $$$ hugh - not much point trying to send if we don't have a To address // (happens frequently if folk don't properly validate their form inputs and are using placeholders) // @TODO - might want to add some feedback about email not being sent return; } /* // $$$ hugh - this code doesn't seem to be used? // it sets $email, which is then never referenced? $receipt_email = $params->get('receipt_to'); if (!$form->record_in_database) { foreach ($aData as $key=>$val) { $aBits = explode('___', $key); $newKey = array_pop( $aBits); if ($newKey == $receipt_email) { $email = $val; } } } */ $subject = html_entity_decode($params->get('receipt_subject', '')); $subject = $w->parseMessageForPlaceHolder($subject, null, false); $from = $config->getValue('mailfrom'); $fromname = $config->getValue('fromname'); //darn silly hack for poor joomfish settings where lang parameters are set to overide joomla global config but not mail translations entered $rawconfig = new JConfig(); if ($from === '') { $from = $rawconfig->mailfrom; } if ($fromname === '') { $fromname = $rawconfig->fromname; } $res = JUTility::sendMail($from, $fromname, $to, $subject, $message, true); }
/** * Main setup routine for displaying the form/detail view * * @param string $tpl template * * @return void */ public function display($tpl = null) { if (parent::display($tpl) !== false) { $this->output(); if (!$this->app->isAdmin()) { $this->state = $this->get('State'); $model = $this->getModel(); $this->params = $this->state->get('params'); $row = $model->getData(); $w = new FabrikWorker(); if ($this->params->get('menu-meta_description')) { $desc = $w->parseMessageForPlaceHolder($this->params->get('menu-meta_description'), $row); $this->doc->setDescription($desc); } if ($this->params->get('menu-meta_keywords')) { $keywords = $w->parseMessageForPlaceHolder($this->params->get('menu-meta_keywords'), $row); $this->doc->setMetadata('keywords', $keywords); } if ($this->params->get('robots')) { $this->doc->setMetadata('robots', $this->params->get('robots')); } // Set the response to indicate a file download $this->app->setHeader('Content-Type', 'application/vnd.ms-word'); $name = $this->getModel()->getTable()->label; $name = JStringNormalise::toDashSeparated($name); $this->app->setHeader('Content-Disposition', "attachment;filename=\"" . $name . ".doc\""); $this->doc->setMimeEncoding('text/html; charset=Windows-1252', false); } } }
/** * Process the plugin, called after form is submitted * * @return bool */ public function onLastProcess() { $formModel = $this->getModel(); $params = $this->getParams(); $app = JFactory::getApplication(); $package = $app->getUserState('com_fabrik.package', 'fabrik'); $session = JFactory::getSession(); $context = $formModel->getRedirectContext(); // 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()); $this->formModel = $formModel; $w = new FabrikWorker(); $form = $formModel->getForm(); $this->data = $this->getProcessData(); $this->data['append_jump_url'] = $params->get('append_jump_url'); $this->data['save_in_session'] = $params->get('save_insession'); $this->data['jump_page'] = $w->parseMessageForPlaceHolder($params->get('jump_page'), $this->data); $this->data['thanks_message'] = $w->parseMessageForPlaceHolder($params->get('thanks_message'), $this->data); if (!$this->shouldRedirect($params)) { // Clear any session 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(); $sshowsystemmsg[$this->renderOrder] = true; $session->set($context . 'showsystemmsg', $sshowsystemmsg); if ($this->data['jump_page'] != '') { $this->data['jump_page'] = $this->buildJumpPage(); // 3.0 ajax/module redirect logic handled in form controller not in plugin $surl[$this->renderOrder] = $this->data['jump_page']; $session->set($context . 'url', $surl); $session->set($context . 'redirect_content_how', $params->get('redirect_content_how', 'popup')); $session->set($context . 'redirect_content_popup_width', $params->get('redirect_content_popup_width', '300')); $session->set($context . 'redirect_content_popup_height', $params->get('redirect_content_popup_height', '300')); $session->set($context . 'redirect_content_popup_x_offset', $params->get('redirect_content_popup_x_offset', '0')); $session->set($context . 'redirect_content_popup_y_offset', $params->get('redirect_content_popup_y_offset', '0')); $session->set($context . 'redirect_content_popup_title', $params->get('redirect_content_popup_title', '')); $session->set($context . 'redirect_content_popup_reset_form', $params->get('redirect_content_popup_reset_form', '1')); } 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_' . $package . '&view=plugin&g=form&plugin=redirect&method=displayThanks&task=pluginAjax'; $session->set($context . 'url', $surl); } $smsg[$this->renderOrder] = $this->data['thanks_message']; $session->set($context . 'msg', $smsg); return true; }
/** * process the plugin, called when form is submitted * * @param object $params * @param object form */ function onAfterProcess($params, &$formModel) { $this->formModel = $formModel; $emailData = $this->getEmailData(); $post = JRequest::get('post'); if (!array_key_exists('fabrik_mailchimp_signup', $post)) { return; } $listId = $params->get('mailchimp_listid'); $apiKey = $params->get('mailchimp_apikey'); if ($apiKey == '') { JError::raiseNotice(500, 'Mailchimp: no api key specified'); return; } if ($listId == '') { JError::raiseNotice(500, 'Mailchimp: no list id specified'); return; } $api = new MCAPI($params->get('mailchimp_apikey')); $opts = array(); $emailKey = $formModel->getElement($params->get('mailchimp_email'), true)->getFullName(); $firstNameKey = $formModel->getElement($params->get('mailchimp_firstname'), true)->getFullName(); if ($params->get('mailchimp_lastname') !== '') { $lastNameKey = $formModel->getElement($params->get('mailchimp_lastname'), true)->getFullName(); $lname = $formModel->_formDataWithTableName[$lastNameKey]; $opts['LNAME'] = $lname; } $email = $formModel->_formDataWithTableName[$emailKey]; $fname = $formModel->_formDataWithTableName[$firstNameKey]; $opts['FNAME'] = $fname; $w = new FabrikWorker(); $groupOpts = json_decode($params->get('mailchimp_groupopts', "[]")); if (!empty($groupOpts)) { foreach ($groupOpts as $groupOpt) { $groups = array(); if (isset($groupOpt->groups)) { $groupOpt->groups = $w->parseMessageForPlaceHolder($groupOpt->groups, $emailData); $groups[] = JArrayHelper::fromObject($groupOpt); //array('name'=>'Your Interests:', 'groups'=>'Bananas,Apples') } } $opts['GROUPINGS'] = $groups; } // By default this sends a confirmation email - you will not see new members // until the link contained in it is clicked! $emailType = $params->get('mailchimp_email_type', 'html'); $doubleOptin = (bool) $params->get('mailchimp_double_optin', true); $updateExisting = (bool) $params->get('mailchimp_update_existing'); $retval = $api->listSubscribe($listId, $email, $opts, $emailType, $doubleOptin, $updateExisting); if ($api->errorCode) { $formModel->_arErrors['mailchimp_error'] = true; JError::raiseNotice(500, $api->errorCode . ':' . $api->errorMessage); return false; } else { return true; } }
/** * do the plugin action * @return number of records updated */ function process(&$data) { $app = JFactory::getApplication(); jimport('joomla.mail.helper'); $params = $this->getParams(); $msg = $params->get('message'); $to = $params->get('to'); $w = new FabrikWorker(); $MailFrom = $app->getCfg('mailfrom'); $FromName = $app->getCfg('fromname'); $subject = $params->get('subject', 'Fabrik cron job'); $eval = $params->get('cronemail-eval'); $condition = $params->get('cronemail_condition', ''); $updates = array(); foreach ($data as $group) { if (is_array($group)) { foreach ($group as $row) { if (!empty($condition)) { $this_condition = $w->parseMessageForPlaceHolder($condition, $row); if (eval($this_condition === false)) { continue; } } $row = JArrayHelper::fromObject($row); $thisto = $w->parseMessageForPlaceHolder($to, $row); if (JMailHelper::isEmailAddress($thisto)) { $thismsg = $w->parseMessageForPlaceHolder($msg, $row); if ($eval) { $thismsg = eval($thismsg); } $thissubject = $w->parseMessageForPlaceHolder($subject, $row); $res = JUTility::sendMail( $MailFrom, $FromName, $thisto, $thissubject, $thismsg, true); } $updates[] = $row['__pk_val']; } } } $field = $params->get('cronemail-updatefield'); if (!empty( $updates) && trim($field ) != '') { //do any update found $listModel = JModel::getInstance('list', 'FabrikFEModel'); $listModel->setId($params->get('table')); $table = $listModel->getTable(); $connection = $params->get('connection'); $field = $params->get('cronemail-updatefield'); $value = $params->get('cronemail-updatefield-value'); $field = str_replace("___", ".", $field); $query = "UPDATE $table->db_table_name set $field = " . $fabrikDb->Quote($value) . " WHERE $table->db_primary_key IN (" . implode(',', $updates) . ")"; $fabrikDb = $listModel->getDb(); $fabrikDb->setQuery($query); $fabrikDb->query(); } return count($updates); }
/** * Run right at the end of the form processing * form needs to be set to record in database for this to hook to be called * * @return bool */ public function onAfterProcess() { $params = $this->getParams(); $app = JFactory::getApplication(); $input = $app->input; $formModel = $this->getModel(); $package = $app->getUserState('com_fabrik.package', 'fabrik'); if ($params->get('ask-receipt')) { if (!array_key_exists('fabrik_email_copy', $_POST)) { return; } } $rowid = $input->get('rowid'); $config = JFactory::getConfig(); $w = new FabrikWorker(); $form = $formModel->getForm(); $data = $this->getProcessData(); $message = $params->get('receipt_message'); $editURL = COM_FABRIK_LIVESITE . "index.php?option=com_" . $package . "&view=form&fabrik=" . $formModel->get('id') . "&rowid=" . $rowid; $viewURL = COM_FABRIK_LIVESITE . "index.php?option=com_" . $package . "&view=details&fabrik=" . $formModel->get('id') . "&rowid=" . $rowid; $editlink = "<a href=\"{$editURL}\">" . JText::_('EDIT') . "</a>"; $viewlink = "<a href=\"{$viewURL}\">" . JText::_('VIEW') . "</a>"; $message = str_replace('{fabrik_editlink}', $editlink, $message); $message = str_replace('{fabrik_viewlink}', $viewlink, $message); $message = str_replace('{fabrik_editurl}', $editURL, $message); $message = str_replace('{fabrik_viewurl}', $viewURL, $message); $message = $w->parseMessageForPlaceHolder($message, $data, false); $to = $w->parseMessageForPlaceHolder($params->get('receipt_to'), $data, false); if (empty($to)) { /* $$$ hugh - not much point trying to send if we don't have a To address * (happens frequently if folk don't properly validate their form inputs and are using placeholders) * @TODO - might want to add some feedback about email not being sent */ return; } $subject = html_entity_decode($params->get('receipt_subject', '')); $subject = $w->parseMessageForPlaceHolder($subject, $data, false); $from = $config->get('mailfrom', ''); $fromname = $config->get('fromname', ''); // Darn silly hack for poor joomfish settings where lang parameters are set to override joomla global config but not mail translations entered $rawconfig = new JConfig(); if ($from === '') { $from = $rawconfig->mailfrom; } if ($fromname === '') { $fromname = $rawconfig->fromname; } $from = $params->get('from_email', $from); $mail = JFactory::getMailer(); $res = $mail->sendMail($from, $fromname, $to, $subject, $message, true); if (!$res) { throw new RuntimeException('Couldn\'t send receipt', 500); } }
/** * process the plugin, called afer form is submitted * * @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->get('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(); $this->data = array_merge($this->getEmailData(), $formModel->_formData); $this->_data->jump_page = $w->parseMessageForPlaceHolder($params->get('jump_page'), $this->data); $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); /*$session->clear($context.'url'); $session->clear($context.'title'); $session->clear($context.'msg');*/ return true; } $this->_storeInSession($formModel); $sshowsystemmsg[$this->renderOrder] = true; $session->set($context . 'showsystemmsg', $sshowsystemmsg); if ($this->_data->jump_page != '') { $this->_data->jump_page = $this->_buildJumpPage($formModel); //3.0 ajax/module redirect logic handled in form controller not in plugin $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&view=plugin&g=form&plugin=redirect&method=displayThanks&task=pluginAjax'; $session->set($context . 'url', $surl); } $smsg[$this->renderOrder] = $this->_data->thanks_message; $session->set($context . 'msg', $smsg); return true; }
function parse($match) { $match = $match[0]; require_once COM_FABRIK_FRONTEND . DS . 'helpers' . DS . 'json.php'; require_once COM_FABRIK_FRONTEND . DS . 'helpers' . DS . 'parent.php'; $w = new FabrikWorker(); $w->replaceRequest($match); // stop [] for ranged filters from being removed $match = str_replace('{}', '[]', $match); $match = $w->parseMessageForPlaceHolder($match); return $match; }
function display($tmpl = 'default') { JHTML::_('behavior.calendar'); FabrikHelperHTML::packageJS(); FabrikHelperHTML::script('table.js', 'media/com_fabrik/js/'); FabrikHelperHTML::script('advanced-search.js', 'media/com_fabrik/js/'); require_once COM_FABRIK_FRONTEND . DS . 'helpers' . DS . 'html.php'; $model =& $this->getModel(); $usersConfig =& JComponentHelper::getParams('com_fabrik'); $model->setId(JRequest::getVar('id', $usersConfig->get('visualizationid', JRequest::getInt('visualizationid', 0)))); $this->row =& $model->getVisualization(); $model->setTableIds(); if ($this->row->state == 0) { JError::raiseWarning(500, JText::_('ALERTNOTAUTH')); return ''; } $this->assign('requiredFiltersFound', $this->get('RequiredFiltersFound')); if ($this->requiredFiltersFound) { $this->assign('chart', $this->get('Fusionchart')); } else { $this->assign('chart', ''); } $w = new FabrikWorker(); $w->replaceRequest($this->row->intro_text); $viewName = $this->getName(); $pluginManager =& JModel::getInstance('Pluginmanager', 'FabrikModel'); $plugin =& $pluginManager->getPlugIn('calendar', 'visualization'); $this->assign('containerId', $this->get('ContainerId')); $this->assignRef('filters', $this->get('Filters')); $this->assign('showFilters', JRequest::getInt('showfilters', 1)); $this->assign('filterFormURL', $this->get('FilterFormURL')); $pluginParams =& $model->getPluginParams(); $this->assignRef('params', $pluginParams); JHTML::stylesheet('table.css', 'media/com_fabrik/css/'); $tmpl = $pluginParams->get('fusionchart_layout', $tmpl); $tmplpath = COM_FABRIK_FRONTEND . DS . 'plugins' . DS . 'visualization' . DS . 'fusionchart' . DS . 'views' . DS . 'fusionchart' . DS . 'tmpl' . DS . $tmpl; $this->_setPath('template', $tmplpath); $ab_css_file = $tmplpath . DS . "template.css"; if (JFile::exists($ab_css_file)) { JHTML::stylesheet('template.css', 'components/com_fabrik/plugins/visualization/fusionchart/views/fusionchart/tmpl/' . $tmpl . '/', true); } //check and add a general fabrik custom css file overrides template css and generic table css FabrikHelperHTML::stylesheetFromPath("media" . DS . "com_fabrik" . DS . "css" . DS . "custom.css"); //check and add a specific biz template css file overrides template css generic table css and generic custom css FabrikHelperHTML::stylesheetFromPath("components" . DS . "com_fabrik" . DS . "plugins" . DS . "visualization" . DS . "fusionchart" . DS . "views" . DS . "fusionchart" . DS . "tmpl" . DS . $tmpl . DS . "custom.css"); //assign something to oPackage to ensure we can clear filters $str = "window.addEvent('domready', function(){\n\t\t\tfabrikFusionChart{$this->row->id} = {};"; $str .= "\n" . "oPackage.addBlock('vizualization_{$this->row->id}', fabrikFusionChart{$this->row->id});\n\t\t});"; FabrikHelperHTML::addScriptDeclaration($str); //ensure we don't have an incorrect version of mootools loaded FabrikHelperHTML::cleanMootools(); echo parent::display(); }
/** * Run right at the end of the form processing * form needs to be set to record in database for this to hook to be called * * @param object $params plugin params * @param object &$formModel form model * * @return bool */ public function onAfterProcess($params, &$formModel) { jimport('joomla.filesystem.file'); $files[] = COM_FABRIK_BASE . 'components/com_kunena/class.kunena.php'; $define = COM_FABRIK_BASE . 'components/com_kunena/lib/kunena.defines.php'; $files[] = COM_FABRIK_BASE . 'components/com_kunena/lib/kunena.defines.php'; $files[] = COM_FABRIK_BASE . 'components/com_kunena/lib/kunena.link.class.php'; $files[] = COM_FABRIK_BASE . 'components/com_kunena/lib/kunena.smile.class.php'; if (!JFile::exists($define)) { return JError::raiseError(500, 'could not find the Kunena component'); } require_once $define; foreach ($files as $file) { require_once $file; } if (JFile::exists(KUNENA_PATH_FUNCS . '/post.php')) { $postfile = KUNENA_PATH_FUNCS . '/post.php'; } else { $postfile = KUNENA_PATH_TEMPLATE_DEFAULT . '/post.php'; } $w = new FabrikWorker(); // $fbSession = CKunenaSession::getInstance(); // Don't need this, session is loaded in CKunenaPost $catid = $params->get('kunena_category', 0); $parentid = 0; $action = 'post'; // Added action in request JRequest::setVar('action', $action); $func = 'post'; $contentURL = 'empty'; JRequest::setVar('catid', $catid); $msg = $w->parseMessageForPlaceHolder($params->get('kunena_content'), $formModel->_fullFormData); $subject = $params->get('kunena_title'); JRequest::SetVar('message', $msg); $subject = $w->parseMessageForPlaceHolder($subject, $formModel->_fullFormData); // Added subject in request JRequest::SetVar('subject', $subject); $origId = JRequest::getVar('id'); JRequest::setVar('id', 0); /* ob_start(); include ($postfile); ob_end_clean(); */ ob_start(); include $postfile; $mypost = new CKunenaPost(); // Public CKunenaPost::display() will call protected method CKunenaPost::post() if JRequest action is 'post' $mypost->display(); ob_end_clean(); JRequest::setVar('id', $origId); }
/** * @access private * run sql query * @param array data * @return string result of query */ function _runSQL($data) { $db =& JFactory::getDBO(); $user =& JFactory::getUser(); $params = $this->_params; $sql = $params->get('sql'); $w = new FabrikWorker(); $sql = $w->parseMessageForPlaceHolder($sql, $data); $sql = str_replace(array("\n", "\r", "\n\r", "\r\n", "<br>", "<br/>", "<br />"), "", $sql); $db->setQuery($sql); $res = $db->loadResult(); echo $db->getErrorMsg(); return $res; }
/** * validate the elements data against the rule * @param string data to check * @param object element * @param int plugin sequence ref * @return bol true if validation passes, false if fails */ function validate($data, &$element, $c) { if (empty($data)) { return false; } $params =& $this->getParams(); $ornot = $params->get('emailexists_or_not'); $ornot = $ornot[$c]; $condition = $params->get('emailexists-validation_condition'); $condition = $condition[$c]; if ($condition !== '') { if (@eval($condition)) { return true; } } jimport('joomla.user.helper'); $db = FabrikWorker::getDbo(); $db->setQuery("SELECT id FROM #__users WHERE email = '{$data}'"); $result = $db->loadResult(); if (!$result) { if ($ornot == 'fail_if_exists') { return true; } } else { if ($ornot == 'fail_if_not_exists') { return true; } } return false; }
/** * Draws the html form element * * @param array $data To pre-populate element with * @param int $repeatCounter Repeat group counter * * @return string elements html */ public function render($data, $repeatCounter = 0) { $params = $this->getParams(); $tmp = $this->_getOptions($data, $repeatCounter, true); $layoutName = FabrikWorker::j3() ? 'form' : 'form-25'; $layout = $this->getLayout($layoutName); $layoutData = new stdClass(); $layoutData->id = $this->getHTMLId($repeatCounter); $layoutData->labels = array(); $layoutData->name = $this->getHTMLName($repeatCounter); $layoutData->fieldType = $params->get('fieldType', 'textarea'); $layoutData->editable = $this->isEditable(); $layoutData->rowid = $this->getFormModel()->getRowId(); $layoutData->primaryKey = $this->getGroupModel()->isJoin() ? $this->getJoinedGroupPkVal($repeatCounter) : $layoutData->rowid; $layoutData->rows = $tmp; $layoutData->model = $this; $layoutData->labels = array(); /* foreach ($tmp as $row) { $layoutData->labels[] = $this->getDisplayLabel($row); } */ return $layout->render($layoutData); }
/** * Clone the record * * @param object $params plugin params * @param object &$formModel form model * * @return bool */ private function _process($params, &$formModel) { $clone_times_field_id = $params->get('clone_times_field', ''); $clone_batchid_field_id = $params->get('clone_batchid_field', ''); if ($clone_times_field_id != '') { $elementModel = FabrikWorker::getPluginManager()->getElementPlugin($clone_times_field_id); $element = $elementModel->getElement(true); if ($clone_batchid_field_id != '') { $elementModel = FabrikWorker::getPluginManager()->getElementPlugin($clone_batchid_field_id); $id_element = $id_elementModel->getElement(true); $formModel->_formData[$id_element->name] = $formModel->_fullFormData['rowid']; $formModel->_formData[$id_element->name . '_raw'] = $formModel->_fullFormData['rowid']; $listModel = $formModel->getlistModel(); $listModel->_oForm = $formModel; $primaryKey = FabrikString::shortColName($listModel->getTable()->db_primary_key); $formModel->_formData[$primaryKey] = $formModel->_fullFormData['rowid']; $formModel->_formData[$primaryKey . '_raw'] = $formModel->_fullFormData['rowid']; $listModel->storeRow($formModel->_formData, $formModel->_fullFormData['rowid']); } // $clone_times_field = $elementModel->getFullName(false, true, false); $clone_times = $formModel->_formData[$element->name]; if (is_numeric($clone_times)) { $clone_times = (int) $clone_times; $formModel->_formData['Copy'] = 1; for ($x = 1; $x < $clone_times; $x++) { $formModel->processToDB(); } return true; } } JError::raiseNotice(JText::_('CLONEERR'), "Couldn't find a valid number of times to clone!"); return true; }
protected function createList($listModel, $adminListModel) { $params = $this->getParams(); $table = $params->get('create_list'); if ($table == '') { return; } $db = FabrikWorker::getDbo(); //see if we have a list that already points to the table $query = $db->getQuery(true); $query->select('id')->from('jos_{package}_lists')->where('db_table_name = ' . $db->nameQuote($table)); $db->setQuery($query); $res = (int) $db->loadResult(); $now = JFactory::getDate()->toMySQL(); $user = JFactory::getUser(); $data = array(); //fill in some default data $data['filter_action'] = 'onchange'; $data['access'] = 1; $data['id'] = $res; $data['label'] = $table; $data['connection_id'] = 1; $data['db_table_name'] = $table; $data['published'] = 1; $data['created'] = $now; $data['created_by'] = $user->get('id'); JRequest::setVar('jform', $data); $adminListModel->save($data); }
/** * Method to get the field input markup. * * @return string The field input markup. */ protected function getInput() { $app = JFactory::getApplication(); $input = $app->input; $option = $input->get('option'); if (!in_array($option, array('com_modules', 'com_menus', 'com_advancedmodules'))) { $db = FabrikWorker::getDbo(true); $query = $db->getQuery(true); $query->select('form_id')->from('#__{package}_formgroup')->where('group_id = ' . (int) $this->form->getValue('id')); $db->setQuery($query); $this->value = $db->loadResult(); $this->form->setValue('form', null, $this->value); } if ((int) $this->form->getValue('id') == 0 || !$this->element['readonlyonedit']) { return parent::getInput(); } else { $options = (array) $this->getOptions(); $v = ''; foreach ($options as $opt) { if ($opt->value == $this->value) { $v = $opt->text; } } } return '<input type="hidden" value="' . $this->value . '" name="' . $this->name . '" />' . '<input type="text" value="' . $v . '" name="form_justalabel" class="readonly" readonly="true" />'; }
function getOptions() { $db = FabrikWorker::getDbo(); $check = $this->element['checkexists'] ? (bool) $this->element['checkexists'] : false; if ($check) { $q = explode(" ", $this->element['query']); $i = array_search('FROM', $q); if (!$i) { $i = array_search('from', $q); } $i++; $tbl = $db->replacePrefix($q[$i]); $db->setQuery("SHOW TABLES"); $rows = $db->loadResultArray(); $found = in_array($tbl, $rows) ? true : false; if (!$found) { return array(JHTML::_('select.option', $tbl . ' not found', '')); } } $db->setQuery($this->element['query']); $key = $this->element['key_field'] ? $this->element['key_field'] : 'value'; $val = $this->element['value_field'] ? $this->element['value_field'] : $this->name; if ($this->element['add_select']) { $rows = array(JHTML::_('select.option', '')); $rows = array_merge($rows, (array) $db->loadObjectList()); } else { $rows = $db->loadObjectList(); } return $rows; }
/** * Clone the record * * @return bool */ private function _process() { $params = $this->getParams(); /** @var FabrikFEModelForm $formModel */ $formModel = $this->getModel(); $clone_times_field_id = $params->get('clone_times_field', ''); $clone_batchid_field_id = $params->get('clone_batchid_field', ''); if ($clone_times_field_id != '') { $elementModel = FabrikWorker::getPluginManager()->getElementPlugin($clone_times_field_id); $element = $elementModel->getElement(true); if ($clone_batchid_field_id != '') { $elementModel = FabrikWorker::getPluginManager()->getElementPlugin($clone_batchid_field_id); $id_element = $elementModel->getElement(true); $formModel->formData[$id_element->name] = $formModel->fullFormData['rowid']; $formModel->formData[$id_element->name . '_raw'] = $formModel->fullFormData['rowid']; $listModel = $formModel->getlistModel(); $listModel->setFormModel($formModel); $primaryKey = FabrikString::shortColName($listModel->getPrimaryKey()); $formModel->formData[$primaryKey] = $formModel->fullFormData['rowid']; $formModel->formData[$primaryKey . '_raw'] = $formModel->fullFormData['rowid']; $listModel->storeRow($formModel->formData, $formModel->fullFormData['rowid']); } $clone_times = $formModel->formData[$element->name]; if (is_numeric($clone_times)) { $clone_times = (int) $clone_times; $formModel->formData['Copy'] = 1; for ($x = 1; $x < $clone_times; $x++) { $formModel->processToDB(); } return true; } } throw new RuntimeException("Couldn't find a valid number of times to clone!"); }
/** * Method to get the list of groups and elements * grouped by group and element. * * @return array The field option objects as a nested array in groups. */ protected function getGroups() { $app = JFactory::getApplication(); $input = $app->input; $db = FabrikWorker::getDbo(true); $query = $db->getQuery(true); $query->select('form_id')->from($db->quoteName('#__{package}_formgroup') . ' AS fg')->join('LEFT', '#__{package}_elements AS e ON e.group_id = fg.group_id')->where('e.id = ' . $input->getInt('elementid')); $db->setQuery($query); $formId = $db->loadResult(); $formModel = JModelLegacy::getInstance('Form', 'FabrikFEModel'); $formModel->setId($formId); $rows = array(); $rows[FText::_('COM_FABRIK_GROUPS')] = array(); $rows[FText::_('COM_FABRIK_ELEMENTS')] = array(); // Get available element types $groups = $formModel->getGroupsHiarachy(); foreach ($groups as $groupModel) { $group = $groupModel->getGroup(); $label = $group->name; $value = 'fabrik_trigger_group_group' . $group->id; $rows[FText::_('COM_FABRIK_GROUPS')][] = JHTML::_('select.option', $value, $label); $elementModels = $groupModel->getMyElements(); foreach ($elementModels as $elementModel) { $label = $elementModel->getFullName(false, false); $value = 'fabrik_trigger_element_' . $elementModel->getFullName(true, false); $rows[FText::_('COM_FABRIK_ELEMENTS')][] = JHTML::_('select.option', $value, $label); } } reset($rows); asort($rows[FText::_('COM_FABRIK_ELEMENTS')]); return $rows; }
function display($tmpl = 'default') { FabrikHelperHTML::framework(); FabrikHelperHTML::script('media/com_fabrik/js/list.js'); $model = $this->getModel(); $usersConfig = JComponentHelper::getParams('com_fabrik'); $model->setId(JRequest::getVar('id', $usersConfig->get('visualizationid', JRequest::getInt('visualizationid', 0)))); $this->row = $model->getVisualization(); $model->setListIds(); if ($this->row->published == 0) { JError::raiseWarning(500, JText::_('JERROR_ALERTNOAUTHOR')); return ''; } $calendar = $model->_row; $this->media = $model->getMedia(); $params = $model->getParams(); $this->assign('params', $params); $viewName = $this->getName(); $pluginManager = FabrikWorker::getPluginManager(); $plugin = $pluginManager->getPlugIn('media', 'visualization'); $this->assign('containerId', $this->get('ContainerId')); $this->assign('showFilters', JRequest::getInt('showfilters', $params->get('show_filters')) === 1 ? 1 : 0); $this->assignRef('filters', $this->get('Filters')); $this->assign('params', $model->getParams()); $pluginParams = $model->getPluginParams(); $tmpl = $pluginParams->get('media_layout', $tmpl); $tmplpath = JPATH_ROOT . '/plugins/fabrik_visualization/media/views/media/tmpl/' . $tmpl; $this->_setPath('template', $tmplpath); FabrikHelperHTML::stylesheetFromPath('plugins/fabrik_visualization/media/views/media/tmpl/' . $tmpl . '/template.css'); echo parent::display(); }
function doCron(&$pluginManager) { $db = FabrikWorker::getDbo(); $cid = JRequest::getVar('element_id', array(), 'method', 'array'); $query = $db->getQuery(); $query->select('id, plugin')->from('#__{package}_cron'); if (!empty($cid)) { $query->where(" id IN (" . implode(',', $cid).")"); } $db->setQuery($query); $rows = $db->loadObjectList(); $viewModel = JModel::getInstance('view', 'FabrikFEModel'); $c = 0; foreach ($rows as $row) { //load in the plugin $plugin = $pluginManager->getPlugIn($row->plugin, 'cron'); $plugin->setId($row->id); $params = $plugin->getParams(); $thisViewModel = clone($viewModel); $thisViewModel->setId($params->get('table')); $table = $viewModel->getTable(); $total = $thisViewModel->getTotalRecords(); $nav = $thisViewModel->getPagination($total, 0, $total); $data = $thisViewModel->getData(); // $$$ hugh - added table model param, in case plugin wants to do further table processing $c = $c + $plugin->process($data, $thisViewModel); } $query = $db->getQuery(); $query->update('#__{package}_cron')->set('lastrun=NOW()')->where("id IN (".implode(',', $cid).")"); $db->setQuery($query); $db->query(); }
/** * Display the view */ function display() { $document = JFactory::getDocument(); $viewName = JRequest::getVar('view', 'package', 'default', 'cmd'); $viewType = $document->getType(); // Set the default view name from the Request $view = $this->getView($viewName, $viewType); //if the view is a package create and assign the table and form views $tableView = $this->getView('list', $viewType); $listModel = $this->getModel('list', 'FabrikFEModel'); $tableView->setModel($listModel, true); $view->_tableView = $tableView; $view->_formView =& $this->getView('Form', $viewType); $formModel = $this->getModel('Form', 'FabrikFEModel'); $formModel->setDbo(FabrikWorker::getDbo()); $view->_formView->setModel($formModel, true); // Push a model into the view $model = $this->getModel($viewName, 'FabrikFEModel'); $model->setDbo(FabrikWorker::getDbo()); if (!JError::isError($model)) { $view->setModel($model, true); } // Display the view $view->assign('error', $this->getError()); $view->display(); }