コード例 #1
0
 function onValidate($field, $fields, $record_id, $form, $value)
 {
     $lang = JFactory::getLanguage();
     $lang->load('plg_contentbuilder_validation_date_not_before', JPATH_ADMINISTRATOR);
     foreach ($fields as $other_field) {
         if (isset($other_field['name']) && isset($other_field['value']) && isset($field['name']) && $field['name'] . '_later' == $other_field['name']) {
             if (is_array($value)) {
                 return JText::_('COM_CONTENTBUILDER_VALIDATION_DATE_NOT_BEFORE_GROUPS');
             }
             $other_value = $other_field['value'];
             $other_value = contentbuilder_convert_date($other_value, $other_field['options']->transfer_format, 'YYYY-MM-DD');
             $value = contentbuilder_convert_date($value, $field['options']->transfer_format, 'YYYY-MM-DD');
             if (is_array($other_value)) {
                 return JText::_('COM_CONTENTBUILDER_VALIDATION_DATE_NOT_BEFORE_GROUPS');
             }
             $value = preg_replace("/[^0-9]/", '', $value);
             $other_value = preg_replace("/[^0-9]/", '', $other_value);
             if ($other_value < $value) {
                 return JText::_('COM_CONTENTBUILDER_VALIDATION_DATE_NOT_BEFORE') . ': ' . $other_field['label'] . ' (' . $other_field['value'] . ')';
             }
             return '';
         }
     }
     return '';
 }
コード例 #2
0
ファイル: export.php プロジェクト: ranrolls/ras-full-portal
 /**
  * Gets the currencies
  * @return array List of products
  */
 function getData()
 {
     // Lets load the data if it doesn't already exist
     if (empty($this->_data)) {
         $query = $this->_buildQuery();
         $this->_data = $this->_getList($query, 0, 1);
         if (!count($this->_data)) {
             JError::raiseError(404, JText::_('COM_CONTENTBUILDER_FORM_NOT_FOUND'));
         }
         foreach ($this->_data as $data) {
             if (!$this->frontend && $data->display_in == 0) {
                 JError::raiseError(404, JText::_('COM_CONTENTBUILDER_FORM_NOT_FOUND'));
             } else {
                 if ($this->frontend && $data->display_in == 1) {
                     JError::raiseError(404, JText::_('COM_CONTENTBUILDER_FORM_NOT_FOUND'));
                 }
             }
             if (!count($data->export_xls)) {
                 JError::raiseError(500, JText::_('Not exportable error'));
             }
             $data->form_id = $this->_id;
             if ($data->type && $data->reference_id) {
                 $data->form = contentbuilder::getForm($data->type, $data->reference_id);
                 if (!$data->form->exists) {
                     JError::raiseError(404, JText::_('COM_CONTENTBUILDER_FORM_NOT_FOUND'));
                 }
                 $searchable_elements = contentbuilder::getListSearchableElements($this->_id);
                 $data->labels = $data->form->getElementLabels();
                 if (JFactory::getSession()->get('com_contentbuilder.filter_signal.' . $this->_id, false) && $data->allow_external_filter) {
                     $orders = array();
                     $filters = array();
                     $filters_from = array();
                     $filters_to = array();
                     $calendar_formats = array();
                     $filters = JFactory::getSession()->get('com_contentbuilder.filter.' . $this->_id, array());
                     $filters_from = JFactory::getSession()->get('com_contentbuilder.calendar_filter_from.' . $this->_id, array());
                     $filters_to = JFactory::getSession()->get('com_contentbuilder.calendar_filter_to.' . $this->_id, array());
                     $calendar_formats = JFactory::getSession()->get('com_contentbuilder.calendar_formats.' . $this->_id, array());
                     $filter_keywords = JFactory::getSession()->get('com_contentbuilder.filter_keywords.' . $this->_id, '');
                     $filter_cats = JFactory::getSession()->get('com_contentbuilder.filter_article_categories.' . $this->_id, -1);
                     if ($filter_keywords != '') {
                         $this->setState('formsd_filter', $filter_keywords);
                     }
                     if ($filter_cats != -1) {
                         $this->setState('article_category_filter', $filter_cats);
                     }
                     foreach ($calendar_formats as $col => $calendar_format) {
                         if (isset($filters[$col])) {
                             $filter_exploded = explode('/', $filters[$col]);
                             if (isset($filter_exploded[2])) {
                                 $to_exploded = explode('to', $filter_exploded[2]);
                                 switch (count($to_exploded)) {
                                     case 2:
                                         if ($to_exploded[0] != '') {
                                             $filters[$col] = '@range/date/' . contentbuilder_convert_date(trim($to_exploded[0]), $calendar_format) . ' to ' . contentbuilder_convert_date(trim($to_exploded[1]), $calendar_format);
                                         } else {
                                             $filters[$col] = '@range/date/to ' . contentbuilder_convert_date(trim($to_exploded[1]), $calendar_format);
                                         }
                                         break;
                                     case 1:
                                         $filters[$col] = '@range/date/' . contentbuilder_convert_date(trim($to_exploded[0]), $calendar_format);
                                         break;
                                 }
                                 if (isset($to_exploded[0]) && isset($to_exploded[1]) && trim($to_exploded[0]) == '' && trim($to_exploded[1]) == '') {
                                     $filters[$col] = '';
                                 }
                                 if (isset($to_exploded[0]) && !isset($to_exploded[1]) && trim($to_exploded[0]) == '') {
                                     $filters[$col] = '';
                                 }
                             }
                         }
                     }
                     $new_filters = array();
                     $i = 1;
                     foreach ($filters as $filter_key => $filter) {
                         if ($filter != '') {
                             $orders[$filter_key] = $i;
                             $new_filters[$filter_key] = explode('|', $filter);
                         }
                         $i++;
                     }
                     $this->_menu_filter = $new_filters;
                     $this->_menu_filter_order = $orders;
                 }
                 $ordered_extra_title = '';
                 foreach ($this->_menu_filter_order as $order_key => $order) {
                     if (isset($this->_menu_filter[$order_key])) {
                         // range test
                         $is_range = strstr(strtolower(implode(',', $this->_menu_filter[$order_key])), '@range') !== false;
                         $is_match = strstr(strtolower(implode(',', $this->_menu_filter[$order_key])), '@match') !== false;
                         if ($is_range) {
                             $ex = explode('/', implode(', ', $this->_menu_filter[$order_key]));
                             if (count($ex) == 3) {
                                 $ex2 = explode('to', trim($ex[2]));
                                 $out = '';
                                 $val = $ex2[0];
                                 $val2 = '';
                                 if (isset($ex2[1])) {
                                     $val2 = $ex2[1];
                                 }
                                 if (strtolower(trim($ex[1])) == 'date') {
                                     $val = JHTML::_('date', $ex2[0], JText::_('DATE_FORMAT_LC3'));
                                     if (isset($ex2[1])) {
                                         $val2 = JHTML::_('date', $ex2[1], JText::_('DATE_FORMAT_LC3'));
                                     }
                                 }
                                 if (count($ex2) == 2) {
                                     $out = (trim($ex2[0]) ? JText::_('COM_CONTENTBUILDER_FROM') . ' ' . trim($val) : '') . ' ' . JText::_('COM_CONTENTBUILDER_TO') . ' ' . trim($val2);
                                 } else {
                                     if (count($ex2) > 0) {
                                         $out = JText::_('COM_CONTENTBUILDER_FROM2') . ' ' . trim($val);
                                     }
                                 }
                                 if ($out) {
                                     $this->_menu_filter[$order_key] = $ex;
                                     $ordered_extra_title .= ' &raquo; ' . htmlentities($data->labels[$order_key], ENT_QUOTES, 'UTF-8') . ': ' . htmlentities($out, ENT_QUOTES, 'UTF-8');
                                 }
                             }
                         } else {
                             if ($is_match) {
                                 $ex = explode('/', implode(', ', $this->_menu_filter[$order_key]));
                                 if (count($ex) == 2) {
                                     $ex2 = explode(';', trim($ex[1]));
                                     $out = '';
                                     $size = count($ex2);
                                     $i = 0;
                                     foreach ($ex2 as $val) {
                                         if ($i + 1 < $size) {
                                             $out .= trim($val) . ' ' . JText::_('COM_CONTENTBUILDER_AND') . ' ';
                                         } else {
                                             $out .= trim($val);
                                         }
                                         $i++;
                                     }
                                     if ($out) {
                                         $this->_menu_filter[$order_key] = $ex;
                                         $ordered_extra_title .= ' &raquo; ' . htmlentities($data->labels[$order_key], ENT_QUOTES, 'UTF-8') . ': ' . htmlentities($out, ENT_QUOTES, 'UTF-8');
                                     }
                                 }
                             } else {
                                 $ordered_extra_title .= ' &raquo; ' . htmlentities($data->labels[$order_key], ENT_QUOTES, 'UTF-8') . ': ' . htmlentities(implode(', ', $this->_menu_filter[$order_key]), ENT_QUOTES, 'UTF-8');
                             }
                         }
                     }
                 }
                 $order_types = array();
                 $ids = array();
                 foreach ($data->labels as $reference_id => $label) {
                     $ids[] = $this->_db->Quote($reference_id);
                 }
                 if (count($ids)) {
                     $this->_db->setQuery("Select Distinct `id`,`label`, reference_id, `order_type` From #__contentbuilder_elements Where form_id = " . intval($this->_id) . " And reference_id In (" . implode(',', $ids) . ") And published = 1 Order By ordering");
                     $rows = $this->_db->loadAssocList();
                     $ids = array();
                     foreach ($rows as $row) {
                         // cleaned up, in desired order
                         $ids[] = $row['reference_id'];
                         $labels[] = $row['label'];
                         $order_types['col' . $row['reference_id']] = $row['order_type'];
                     }
                 }
                 $data->visible_cols = $ids;
                 $data->visible_labels = $labels;
                 $act_as_registration = array();
                 if ($data->act_as_registration && $data->registration_username_field && $data->registration_name_field && $data->registration_email_field && $data->registration_email_repeat_field && $data->registration_password_field && $data->registration_password_repeat_field) {
                     $act_as_registration[$data->registration_username_field] = 'registration_username_field';
                     $act_as_registration[$data->registration_name_field] = 'registration_name_field';
                     $act_as_registration[$data->registration_email_field] = 'registration_email_field';
                 }
                 $data->items = $data->form->getListRecords($ids, $this->getState('formsd_filter'), $searchable_elements, 0, 0, $this->getState('formsd_filter_order'), $order_types, $this->getState('formsd_filter_order_Dir'), 0, $data->published_only, $this->frontend && $data->own_only_fe ? JFactory::getUser()->get('id', 0) : -1, $this->getState('formsd_filter_state'), $this->getState('formsd_filter_publish'), $data->initial_sort_order == -1 ? -1 : 'col' . $data->initial_sort_order, $data->initial_sort_order2 == -1 ? -1 : 'col' . $data->initial_sort_order2, $data->initial_sort_order3 == -1 ? -1 : 'col' . $data->initial_sort_order3, $this->_menu_filter, $this->frontend ? $data->show_all_languages_fe : true, $this->getState('formsd_filter_language'), $act_as_registration, $data, $this->getState('article_category_filter'));
             }
             return $data;
         }
     }
     return null;
 }
コード例 #3
0
 public static function getEditableTemplate($contentbuilder_form_id, $record_id, array $record, array $elements_allowed, $execPrepare = true)
 {
     jimport('joomla.version');
     $version = new JVersion();
     if (version_compare($version->getShortVersion(), '1.6', '>=')) {
         JHtml::_('behavior.framework');
     }
     $failed_values = JFactory::getSession()->get('cb_failed_values', null, 'com_contentbuilder.' . $contentbuilder_form_id);
     if ($failed_values !== null) {
         JFactory::getSession()->clear('cb_failed_values', 'com_contentbuilder.' . $contentbuilder_form_id);
     }
     $db = JFactory::getDBO();
     $db->setQuery("Select `type`, reference_id, editable_template, editable_prepare, edit_by_type, act_as_registration, registration_name_field, registration_username_field, registration_email_field, registration_email_repeat_field, registration_password_field, registration_password_repeat_field From #__contentbuilder_forms Where id = " . intval($contentbuilder_form_id));
     $result = $db->loadAssoc();
     if (is_array($result) && $result['editable_template']) {
         $user = null;
         if ($result['act_as_registration']) {
             if ($record_id) {
                 $form = contentbuilder::getForm($result['type'], $result['reference_id']);
                 $meta = $form->getRecordMetadata($record_id);
                 $db->setQuery("Select * From #__users Where id = " . $meta->created_id);
                 $user = $db->loadObject();
             } else {
                 if (JFactory::getUser()->get('id', 0)) {
                     $db->setQuery("Select * From #__users Where id = " . JFactory::getUser()->get('id', 0));
                     $user = $db->loadObject();
                 }
             }
         }
         $labels = array();
         $validations = array();
         if (!$result['edit_by_type']) {
             $db->setQuery("Select `label`,`reference_id`,`validations` From #__contentbuilder_elements Where form_id = " . intval($contentbuilder_form_id));
             $labels_ = $db->loadAssocList();
             foreach ($labels_ as $label_) {
                 $labels[$label_['reference_id']] = $label_['label'];
                 $validations[$label_['reference_id']] = $label_['validations'];
             }
         }
         $hasLabels = count($labels);
         $form_type = $result['type'];
         $form_reference_id = $result['reference_id'];
         $form = self::getForm($form_type, $form_reference_id);
         $template = $result['editable_template'];
         $items = array();
         foreach ($record as $item) {
             if (in_array($item->recElementId, $elements_allowed)) {
                 $items[$item->recName] = array();
                 $items[$item->recName]['id'] = $item->recElementId;
                 $items[$item->recName]['label'] = $hasLabels ? $labels[$item->recElementId] : $item->recTitle;
                 if ($result['act_as_registration'] && $user !== null) {
                     if ($result['registration_name_field'] == $item->recElementId) {
                         $item->recValue = $user->name;
                     } else {
                         if ($result['registration_username_field'] == $item->recElementId) {
                             $item->recValue = $user->username;
                         } else {
                             if ($result['registration_email_field'] == $item->recElementId) {
                                 $item->recValue = $user->email;
                             } else {
                                 if ($result['registration_email_repeat_field'] == $item->recElementId) {
                                     $item->recValue = $user->email;
                                 }
                             }
                         }
                     }
                 }
                 $items[$item->recName]['value'] = $item->recValue ? $item->recValue : '';
             }
         }
         // in case if there is no record given, provide the element data but an empty value
         $hasRecords = true;
         if (!count($record)) {
             $hasRecords = false;
             $names = $form->getElementNames();
             if (!count($labels)) {
                 $labels = $form->getElementLabels();
             }
             foreach ($names as $elementId => $name) {
                 if (!isset($items[$name])) {
                     $items[$name] = array();
                 }
                 $items[$name]['id'] = $elementId;
                 $items[$name]['label'] = $labels[$elementId];
                 $items[$name]['value'] = '';
             }
         }
         $item = null;
         if ($execPrepare) {
             eval($result['editable_prepare']);
         }
         $the_init_scripts = "\n" . '<script type="text/javascript">' . "\n" . '<!--' . "\n";
         foreach ($items as $key => $item) {
             $db->setQuery("Select * From #__contentbuilder_elements Where published = 1 And editable = 1 And reference_id = " . $db->Quote($item['id']) . " And form_id = " . intval($contentbuilder_form_id) . " Order By ordering");
             $element = $db->loadAssoc();
             $autocomplete = '';
             if ($result['act_as_registration']) {
                 if ($result['registration_name_field'] == $element['reference_id']) {
                     $element['default_value'] = $user !== null ? $user->name : '';
                     $autocomplete = 'autocomplete="off" ';
                 } else {
                     if ($result['registration_username_field'] == $element['reference_id']) {
                         $element['default_value'] = $user !== null ? $user->username : '';
                         $autocomplete = 'autocomplete="off" ';
                     } else {
                         if ($result['registration_email_field'] == $element['reference_id']) {
                             $element['default_value'] = $user !== null ? $user->email : '';
                             $autocomplete = 'autocomplete="off" ';
                         } else {
                             if ($result['registration_email_repeat_field'] == $element['reference_id']) {
                                 $element['default_value'] = $user !== null ? $user->email : '';
                                 $autocomplete = 'autocomplete="off" ';
                             } else {
                                 if ($result['registration_password_field'] == $element['reference_id']) {
                                     $element['force_password'] = true;
                                     $autocomplete = 'autocomplete="off" ';
                                 } else {
                                     if ($result['registration_password_repeat_field'] == $element['reference_id']) {
                                         $element['force_password'] = true;
                                         $autocomplete = 'autocomplete="off" ';
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if (!$element['default_value'] && !$hasRecords) {
                 $element['default_value'] = $item['value'];
             }
             $asterisk = '';
             if (is_array($element)) {
                 if ($element['type'] == 'captcha' || trim($element['validations']) != '' || trim($element['custom_validation_script']) != '') {
                     $asterisk = ' <span class="cbRequired" style="color:red;">*</span>';
                 }
                 $options = unserialize(base64_decode($element['options']));
                 $the_item = '';
                 switch ($element['type']) {
                     case in_array($element['type'], self::getFormElementsPlugins()):
                         $removables = array();
                         $plgs = CBPluginHelper::importPlugin('contentbuilder_form_elements', $element['type']);
                         $removables = array_merge($removables, $plgs);
                         $dispatcher = JDispatcher::getInstance();
                         $results = $dispatcher->trigger('onRenderElement', array($item, $element, $options, $failed_values, $result, $hasRecords));
                         if (count($results)) {
                             $results = $results[0];
                         }
                         foreach ($removables as $removable) {
                             $dispatcher->detach($removable);
                         }
                         $the_item = $results;
                         break;
                     case '':
                     case 'text':
                         if (!isset($options->length)) {
                             $options->length = '';
                         }
                         if (!isset($options->maxlength)) {
                             $options->maxlength = '';
                         }
                         if (!isset($options->password)) {
                             $options->password = '';
                         }
                         if (!isset($options->readonly)) {
                             $options->readonly = '';
                         }
                         $the_item = '<div class="cbFormField cbTextField"><input ' . $autocomplete . '' . ($options->readonly ? 'readonly="readonly" ' : '') . 'style="' . ($options->length ? 'width:' . $options->length . ';' : '') . '" ' . ($options->maxlength ? 'maxlength="' . intval($options->maxlength) . '" ' : '') . 'type="' . (isset($element['force_password']) || $options->password ? 'password' : 'text') . '" id="cb_' . $item['id'] . '" name="cb_' . $item['id'] . '" value="' . htmlentities($failed_values !== null && isset($failed_values[$element['reference_id']]) ? $failed_values[$element['reference_id']] : ($hasRecords ? $item['value'] : $element['default_value']), ENT_QUOTES, 'UTF-8') . '"/></div>';
                         break;
                     case 'textarea':
                         if (!isset($options->width)) {
                             $options->width = '';
                         }
                         if (!isset($options->height)) {
                             $options->height = '';
                         }
                         if (!isset($options->maxlength)) {
                             $options->maxlength = '';
                         }
                         if (!isset($options->readonly)) {
                             $options->readonly = '';
                         }
                         if (!isset($options->allow_html)) {
                             $options->allow_html = false;
                         }
                         if (!isset($options->allow_raw)) {
                             $options->allow_raw = false;
                         }
                         if ($options->allow_html || $options->allow_raw) {
                             JImport('joomla.html.editor');
                             $editor = JFactory::getEditor();
                             $the_item = '<div class="cbFormField cbTextArea">' . $editor->display('cb_' . $item['id'], htmlentities($failed_values !== null && isset($failed_values[$element['reference_id']]) ? $failed_values[$element['reference_id']] : ($hasRecords ? $item['value'] : $element['default_value']), ENT_QUOTES, 'UTF-8'), $options->width ? $options->width : '100%', $options->height ? $options->height : '550', '75', '20') . '</div>';
                         } else {
                             $the_item = '<div class="cbFormField cbTextArea"><textarea ' . ($options->readonly ? 'readonly="readonly" ' : '') . 'style="' . ($options->width || $options->height ? ($options->width ? 'width:' . $options->width . ';' : '') . ($options->height ? 'height:' . $options->height . ';' : '') : '') . '" id="cb_' . $item['id'] . '" name="cb_' . $item['id'] . '">' . htmlentities($failed_values !== null && isset($failed_values[$element['reference_id']]) ? $failed_values[$element['reference_id']] : ($hasRecords ? $item['value'] : $element['default_value']), ENT_QUOTES, 'UTF-8') . '</textarea></div>';
                         }
                         break;
                     case 'checkboxgroup':
                     case 'radiogroup':
                         //if(!isset($options->seperator)){
                         //    $options->seperator = ',';
                         //}
                         $options->seperator = ',';
                         if (!isset($options->horizontal)) {
                             $options->horizontal = false;
                         }
                         if (!isset($options->horizontal_length)) {
                             $options->horizontal_length = '';
                         }
                         if ($form->isGroup($item['id'])) {
                             $groupdef = $form->getGroupDefinition($item['id']);
                             $i = 0;
                             $sep = $options->seperator;
                             $group = explode($sep, $failed_values !== null && isset($failed_values[$element['reference_id']]) && is_array($failed_values[$element['reference_id']]) ? implode($sep, $failed_values[$element['reference_id']]) : ($hasRecords ? $item['value'] : $element['default_value']));
                             $groupSize = count($groupdef);
                             $groupSize = !$groupSize ? 1 : $groupSize;
                             $the_item = '<input name="cb_' . $item['id'] . '[]" type="hidden" value="cbGroupMark"/>';
                             foreach ($groupdef as $value => $label) {
                                 $checked = '';
                                 $for = '';
                                 if ($i != 0) {
                                     $for = '_' . $i;
                                 }
                                 foreach ($group as $selected_value) {
                                     if (trim($value) == trim($selected_value)) {
                                         $checked = ' checked="checked"';
                                         break;
                                     }
                                 }
                                 $the_item .= '<div style="' . ($options->horizontal ? 'float: left;' . ($options->horizontal_length ? 'width: ' . $options->horizontal_length . ';' : '') . 'display: inline; margin-right: 2px;' : '') . '" class="cbFormField cbGroupField"><input id="cb_' . $item['id'] . $for . '" name="cb_' . $item['id'] . '[]" type="' . ($element['type'] == 'checkboxgroup' ? 'checkbox' : 'radio') . '" value="' . htmlentities(trim($value), ENT_QUOTES, 'UTF-8') . '"' . $checked . '/> <label for="cb_' . $item['id'] . $for . '">' . htmlentities(trim($label), ENT_QUOTES, 'UTF-8') . '</label> </div>';
                                 $i++;
                             }
                             if ($options->horizontal) {
                                 $the_item .= '<div style="clear:both;"></div>';
                             }
                         } else {
                             $the_item .= '<span style="color:red">ELEMENT IS NOT A GROUP</span>';
                         }
                         break;
                     case 'select':
                         //if(!isset($options->seperator)){
                         //    $options->seperator = ',';
                         //}
                         $options->seperator = ',';
                         if (!isset($options->multiple)) {
                             $options->multiple = 0;
                         }
                         if (!isset($options->length)) {
                             $options->length = '';
                         }
                         if ($form->isGroup($item['id'])) {
                             $groupdef = $form->getGroupDefinition($item['id']);
                             $i = 0;
                             $sep = $options->seperator;
                             $multi = $options->multiple;
                             $group = explode($sep, $failed_values !== null && isset($failed_values[$element['reference_id']]) && is_array($failed_values[$element['reference_id']]) ? implode($sep, $failed_values[$element['reference_id']]) : ($hasRecords ? $item['value'] : $element['default_value']));
                             $the_item = '<input name="cb_' . $item['id'] . '[]" type="hidden" value="cbGroupMark"/>';
                             $the_item .= '<div class="cbFormField cbSelectField"><select class="chzn-done" id="cb_' . $item['id'] . '" ' . ($options->length ? 'style="width:' . $options->length . ';" ' : '') . 'name="cb_' . $item['id'] . '[]"' . ($multi ? ' multiple="multiple"' : '') . '>';
                             foreach ($groupdef as $value => $label) {
                                 $checked = '';
                                 foreach ($group as $selected_value) {
                                     if (trim($value) == trim($selected_value)) {
                                         $checked = ' selected="selected"';
                                         break;
                                     }
                                 }
                                 $the_item .= '<option value="' . htmlentities(trim($value), ENT_QUOTES, 'UTF-8') . '"' . $checked . '>' . htmlentities(trim($label), ENT_QUOTES, 'UTF-8') . '</option>';
                                 $i++;
                             }
                             $the_item .= '</select></div>';
                         } else {
                             $the_item .= '<span style="color:red">ELEMENT IS NOT A GROUP</span>';
                         }
                         break;
                     case 'upload':
                         $deletable = false;
                         if (isset($validations[$item['id']]) && $validations[$item['id']] == '') {
                             $deletable = true;
                         }
                         $the_item = '<div class="cbFormField cbUploadField">';
                         $the_item .= '<input type="file" id="cb_' . $item['id'] . '" name="cb_' . $item['id'] . '"/>';
                         if (trim($item['value']) != '') {
                             $the_item .= '<div>' . ($deletable ? '<label for="cb_delete_' . $item['id'] . '">' . JText::_('COM_CONTENTBUILDER_DELETE') . '</label> <input type="checkbox" id="cb_delete_' . $item['id'] . '" name="cb_delete_' . $item['id'] . '" value="1"/> ' : '') . htmlentities(basename($item['value']), ENT_QUOTES, 'UTF-8') . '</div><div style="clear:both;"></div>';
                         }
                         $the_item .= '</div>';
                         break;
                     case 'captcha':
                         $the_item = '<div class="cbFormField cbCaptchaField">';
                         if (JFactory::getApplication()->isSite()) {
                             $captcha_url = JURI::root(true) . '/components/com_contentbuilder/images/securimage/securimage_show.php';
                         } else {
                             $captcha_url = JURI::root(true) . '/administrator/components/com_contentbuilder/assets/images/securimage_show.php';
                         }
                         $the_item .= '<img width="250" height="80" id="cbCaptcha" alt="captcha" src="' . $captcha_url . '?rand=' . rand(0, getrandmax()) . '"/>';
                         $the_item .= '<div>';
                         $the_item .= '<input autocomplete="off" id="cb_' . $item['id'] . '" name="cb_' . $item['id'] . '" type="text" maxlength="12" />';
                         $the_item .= '<img style="cursor: pointer; padding-left: 7px;" onclick="document.getElementById(\'cbCaptcha\').src = \'' . $captcha_url . '?\' + Math.random(); blur(); return false" border="0" width="15" height="18" alt="refresh" src="' . JURI::root(true) . '/components/com_contentbuilder/images/securimage/images/refresh.png"/>';
                         $the_item .= '</div>';
                         $the_item .= '</div>';
                         break;
                     case 'calendar':
                         JHTML::_('behavior.calendar');
                         if (!isset($options->length)) {
                             $options->length = '';
                         }
                         if (!isset($options->maxlength)) {
                             $options->maxlength = '';
                         }
                         if (!isset($options->readonly)) {
                             $options->readonly = '';
                         }
                         if (!isset($options->format)) {
                             $options->format = '%Y-%m-%d';
                         }
                         if (!isset($options->transfer_format)) {
                             $options->transfer_format = 'YYYY-mm-dd';
                         }
                         $calval = htmlentities($failed_values !== null && isset($failed_values[$element['reference_id']]) ? $failed_values[$element['reference_id']] : ($hasRecords ? $item['value'] : $element['default_value']), ENT_QUOTES, 'UTF-8');
                         $calval = contentbuilder_convert_date($calval, $options->transfer_format, $options->format);
                         $the_item = '<div class="cbFormField cbCalendarField"><input ' . ($options->readonly ? 'readonly="readonly" ' : '') . 'style="' . ($options->length ? 'width:' . $options->length . ';' : '') . '" ' . ($options->maxlength ? 'maxlength="' . intval($options->maxlength) . '" ' : '') . 'type="text" id="cb_' . $item['id'] . '" name="cb_' . $item['id'] . '" value="' . $calval . '"/> <button class="button cbFormField cbCalendarButton" id="cb_' . $item['id'] . '_calendarButton">' . JText::_('COM_CONTENTBUILDER_CALENDAR_BUTTON_TEXT') . '</button></div>';
                         $the_item .= '<script type="text/javascript">
                                     <!--
                                     Calendar.setup({
                                             inputField     :    "cb_' . $item['id'] . '",
                                             ifFormat       :    "' . $options->format . '",
                                             button         :    "cb_' . $item['id'] . '_calendarButton",
                                             align          :    "Bl",
                                             singleClick    :    true
                                         });
                                     //-->
                                     </script>' . "\n";
                         break;
                     case 'hidden':
                         $the_item = '<input type="hidden" id="cb_' . $item['id'] . '" name="cb_' . $item['id'] . '" value="' . htmlentities($failed_values !== null && isset($failed_values[$element['reference_id']]) ? $failed_values[$element['reference_id']] : ($hasRecords ? $item['value'] : $element['default_value']), ENT_QUOTES, 'UTF-8') . '"/>';
                         break;
                 }
                 if ($element['custom_init_script']) {
                     $the_init_scripts .= $element['custom_init_script'] . "\n";
                 }
                 if ($the_item) {
                     $tip = 'hasTip';
                     $tip_prefix = htmlentities($item['label'], ENT_QUOTES, 'UTF-8') . '::';
                     /* new joomla 3 tooltip styles maybe at a later point
                        if (JFactory::getApplication()->isSite() && version_compare($version->getShortVersion(), '3.0', '>=')) {
                            $tip = 'hasTooltip';
                            $tip_prefix = '';
                        }*/
                     $template = str_replace('{' . $key . ':label}', '<label ' . ($element['hint'] ? 'class="editlinktip ' . $tip . '" title="' . $tip_prefix . $element['hint'] . '" ' : '') . 'for="cb_' . $item['id'] . '">' . $item['label'] . $asterisk . ($element['hint'] ? ' <img style="cursor: pointer;" src="' . JURI::root(true) . '/components/com_contentbuilder/images/icon_info.png" border="0"/>' : '') . '</label>', $template);
                     $template = str_replace('{' . $key . ':item}', $the_item, $template);
                 }
             }
         }
         return $template . $the_init_scripts . "\n" . '//-->' . '</script>' . "\n";
     } else {
         JError::raiseError(404, JText::_('COM_CONTENTBUILDER_TEMPLATE_NOT_FOUND'));
     }
     return '';
 }
コード例 #4
0
ファイル: edit.php プロジェクト: ranrolls/ras-full-portal
 function store()
 {
     JRequest::checkToken('default') or jexit(JText::_('JInvalid_Token'));
     JPluginHelper::importPlugin('contentbuilder_submit');
     $submit_dispatcher = JDispatcher::getInstance();
     JFactory::getSession()->clear('cb_failed_values', 'com_contentbuilder.' . $this->_id);
     JRequest::setVar('cb_submission_failed', 0);
     $query = $this->_buildQuery();
     $this->_data = $this->_getList($query, 0, 1);
     if (!count($this->_data)) {
         JError::raiseError(404, JText::_('COM_CONTENTBUILDER_FORM_NOT_FOUND'));
     }
     foreach ($this->_data as $data) {
         if (!$this->frontend && $data->display_in == 0) {
             JError::raiseError(404, JText::_('COM_CONTENTBUILDER_RECORD_NOT_FOUND'));
         } else {
             if ($this->frontend && $data->display_in == 1) {
                 JError::raiseError(404, JText::_('COM_CONTENTBUILDER_RECORD_NOT_FOUND'));
             }
         }
         $data->form_id = $this->_id;
         if ($data->type && $data->reference_id) {
             $values = array();
             $data->form = contentbuilder::getForm($data->type, $data->reference_id);
             $meta = $data->form->getRecordMetadata($this->_record_id);
             if (!$data->edit_by_type) {
                 $noneditable_fields = contentbuilder::getListNonEditableElements($this->_id);
                 $names = $data->form->getElementNames();
                 $this->_db->setQuery("Select * From #__contentbuilder_elements Where form_id = " . $this->_id . " And published = 1 And editable = 1");
                 $fields = $this->_db->loadAssocList();
                 $the_fields = array();
                 $the_name_field = null;
                 $the_username_field = null;
                 $the_password_field = null;
                 $the_password_repeat_field = null;
                 $the_email_field = null;
                 $the_email_repeat_field = null;
                 $the_html_fields = array();
                 $the_upload_fields = array();
                 $the_captcha_field = null;
                 $the_failed_registration_fields = array();
                 jimport('joomla.filesystem.file');
                 jimport('joomla.filesystem.folder');
                 foreach ($fields as $special_field) {
                     switch ($special_field['type']) {
                         case 'text':
                         case 'upload':
                         case 'captcha':
                         case 'textarea':
                             if ($special_field['type'] == 'upload') {
                                 $options = unserialize(base64_decode($special_field['options']));
                                 $special_field['options'] = $options;
                                 $the_upload_fields[$special_field['reference_id']] = $special_field;
                             } else {
                                 if ($special_field['type'] == 'captcha') {
                                     $options = unserialize(base64_decode($special_field['options']));
                                     $special_field['options'] = $options;
                                     $the_captcha_field = $special_field;
                                 } else {
                                     if ($special_field['type'] == 'textarea') {
                                         $options = unserialize(base64_decode($special_field['options']));
                                         $special_field['options'] = $options;
                                         if (isset($special_field['options']->allow_html) && $special_field['options']->allow_html) {
                                             $the_html_fields[$special_field['reference_id']] = $special_field;
                                         } else {
                                             $the_fields[$special_field['reference_id']] = $special_field;
                                         }
                                     } else {
                                         if ($special_field['type'] == 'text') {
                                             $options = unserialize(base64_decode($special_field['options']));
                                             $special_field['options'] = $options;
                                             if ($data->act_as_registration && $data->registration_username_field == $special_field['reference_id']) {
                                                 $the_username_field = $special_field;
                                             } else {
                                                 if ($data->act_as_registration && $data->registration_name_field == $special_field['reference_id']) {
                                                     $the_name_field = $special_field;
                                                 } else {
                                                     if ($data->act_as_registration && $data->registration_password_field == $special_field['reference_id']) {
                                                         $the_password_field = $special_field;
                                                     } else {
                                                         if ($data->act_as_registration && $data->registration_password_repeat_field == $special_field['reference_id']) {
                                                             $the_password_repeat_field = $special_field;
                                                         } else {
                                                             if ($data->act_as_registration && $data->registration_email_field == $special_field['reference_id']) {
                                                                 $the_email_field = $special_field;
                                                             } else {
                                                                 if ($data->act_as_registration && $data->registration_email_repeat_field == $special_field['reference_id']) {
                                                                     $the_email_repeat_field = $special_field;
                                                                 } else {
                                                                     $the_fields[$special_field['reference_id']] = $special_field;
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                             break;
                         default:
                             $options = unserialize(base64_decode($special_field['options']));
                             $special_field['options'] = $options;
                             $the_fields[$special_field['reference_id']] = $special_field;
                     }
                 }
                 // we have defined a captcha, so let's test it
                 if ($the_captcha_field !== null && !in_array($the_captcha_field['reference_id'], $noneditable_fields)) {
                     if (!class_exists('Securimage')) {
                         require_once JPATH_SITE . DS . 'components' . DS . 'com_contentbuilder' . DS . 'images' . DS . 'securimage' . DS . 'securimage.php';
                     }
                     $securimage = new Securimage();
                     $cap_value = JRequest::getVar('cb_' . $the_captcha_field['reference_id'], null, 'POST');
                     if ($securimage->check($cap_value) == false) {
                         JRequest::setVar('cb_submission_failed', 1);
                         JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_CAPTCHA_FAILED'), 'error');
                     }
                     $values[$the_captcha_field['reference_id']] = $cap_value;
                     $noneditable_fields[] = $the_captcha_field['reference_id'];
                 }
                 // now let us see if we have a registration
                 // make sure to wait for previous errors
                 if ($data->act_as_registration && $the_name_field !== null && $the_email_field !== null && $the_email_repeat_field !== null && $the_password_field !== null && $the_password_repeat_field !== null && $the_username_field !== null) {
                     $pw1 = JRequest::getVar('cb_' . $the_password_field['reference_id'], '', 'POST', 'STRING', JREQUEST_NOTRIM | JREQUEST_ALLOWRAW);
                     $pw2 = JRequest::getVar('cb_' . $the_password_repeat_field['reference_id'], '', 'POST', 'STRING', JREQUEST_NOTRIM | JREQUEST_ALLOWRAW);
                     $email = JRequest::getVar('cb_' . $the_email_field['reference_id'], '', 'POST', 'STRING', JREQUEST_ALLOWRAW);
                     $email2 = JRequest::getVar('cb_' . $the_email_repeat_field['reference_id'], '', 'POST', 'STRING', JREQUEST_ALLOWRAW);
                     $name = JRequest::getVar('cb_' . $the_name_field['reference_id'], '', 'POST', 'STRING', JREQUEST_ALLOWRAW);
                     $username = JRequest::getVar('cb_' . $the_username_field['reference_id'], '', 'POST', 'STRING', JREQUEST_NOTRIM | JREQUEST_ALLOWRAW);
                     if (!JRequest::getVar('cb_submission_failed', 0)) {
                         if (!trim($name)) {
                             JRequest::setVar('cb_submission_failed', 1);
                             JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_NAME_EMPTY'), 'error');
                         }
                         if (!trim($username)) {
                             JRequest::setVar('cb_submission_failed', 1);
                             JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_USERNAME_EMPTY'), 'error');
                         } else {
                             if (preg_match("#[<>\"'%;()&]#i", $username) || strlen(utf8_decode($username)) < 2) {
                                 JRequest::setVar('cb_submission_failed', 1);
                                 JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_USERNAME_INVALID'), 'error');
                             }
                         }
                         if (!trim($email)) {
                             JRequest::setVar('cb_submission_failed', 1);
                             JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_EMAIL_EMPTY'), 'error');
                         } else {
                             if (!contentbuilder_is_email($email)) {
                                 JRequest::setVar('cb_submission_failed', 1);
                                 JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_EMAIL_INVALID'), 'error');
                             } else {
                                 if ($email != $email2) {
                                     JRequest::setVar('cb_submission_failed', 1);
                                     JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_EMAIL_MISMATCH'), 'error');
                                 }
                             }
                         }
                         if (!$meta->created_id && !JFactory::getUser()->get('id', 0)) {
                             $this->_db->setQuery("Select count(id) From #__users Where `username` = " . $this->_db->Quote($username));
                             if ($this->_db->loadResult()) {
                                 JRequest::setVar('cb_submission_failed', 1);
                                 JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_USERNAME_NOT_AVAILABLE'), 'error');
                             }
                             $this->_db->setQuery("Select count(id) From #__users Where `email` = " . $this->_db->Quote($email));
                             if ($this->_db->loadResult()) {
                                 JRequest::setVar('cb_submission_failed', 1);
                                 JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_EMAIL_NOT_AVAILABLE'), 'error');
                             }
                             if ($pw1 != $pw2) {
                                 JRequest::setVar('cb_submission_failed', 1);
                                 JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_PASSWORD_MISMATCH'), 'error');
                                 JRequest::setVar('cb_' . $the_password_field['reference_id'], '');
                                 JRequest::setVar('cb_' . $the_password_repeat_field['reference_id'], '');
                             } else {
                                 if (!trim($pw1)) {
                                     JRequest::setVar('cb_submission_failed', 1);
                                     JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_PASSWORD_EMPTY'), 'error');
                                     JRequest::setVar('cb_' . $the_password_field['reference_id'], '');
                                     JRequest::setVar('cb_' . $the_password_repeat_field['reference_id'], '');
                                 }
                             }
                         } else {
                             if ($meta->created_id && $meta->created_id != JFactory::getUser()->get('id', 0)) {
                                 $this->_db->setQuery("Select count(id) From #__users Where id <> " . $this->_db->Quote($meta->created_id) . " And `username` = " . $this->_db->Quote($username));
                                 if ($this->_db->loadResult()) {
                                     JRequest::setVar('cb_submission_failed', 1);
                                     JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_USERNAME_NOT_AVAILABLE'), 'error');
                                 }
                                 $this->_db->setQuery("Select count(id) From #__users Where id <> " . $this->_db->Quote($meta->created_id) . " And `email` = " . $this->_db->Quote($email));
                                 if ($this->_db->loadResult()) {
                                     JRequest::setVar('cb_submission_failed', 1);
                                     JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_EMAIL_NOT_AVAILABLE'), 'error');
                                 }
                             } else {
                                 $this->_db->setQuery("Select count(id) From #__users Where id <> " . $this->_db->Quote(JFactory::getUser()->get('id', 0)) . " And `username` = " . $this->_db->Quote($username));
                                 if ($this->_db->loadResult()) {
                                     JRequest::setVar('cb_submission_failed', 1);
                                     JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_USERNAME_NOT_AVAILABLE'), 'error');
                                 }
                                 $this->_db->setQuery("Select count(id) From #__users Where id <> " . $this->_db->Quote(JFactory::getUser()->get('id', 0)) . " And `email` = " . $this->_db->Quote($email));
                                 if ($this->_db->loadResult()) {
                                     JRequest::setVar('cb_submission_failed', 1);
                                     JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_EMAIL_NOT_AVAILABLE'), 'error');
                                 }
                             }
                             if (trim($pw1) != '' || trim($pw2) != '') {
                                 if ($pw1 != $pw2) {
                                     JRequest::setVar('cb_submission_failed', 1);
                                     JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_PASSWORD_MISMATCH'), 'error');
                                     JRequest::setVar('cb_' . $the_password_field['reference_id'], '');
                                     JRequest::setVar('cb_' . $the_password_repeat_field['reference_id'], '');
                                 } else {
                                     if (!trim($pw1)) {
                                         JRequest::setVar('cb_submission_failed', 1);
                                         JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_PASSWORD_EMPTY'), 'error');
                                         JRequest::setVar('cb_' . $the_password_field['reference_id'], '');
                                         JRequest::setVar('cb_' . $the_password_repeat_field['reference_id'], '');
                                     }
                                 }
                             }
                         }
                         if (!JRequest::getVar('cb_submission_failed', 0)) {
                             //$noneditable_fields[] = $the_name_field['reference_id'];
                             $noneditable_fields[] = $the_password_field['reference_id'];
                             $noneditable_fields[] = $the_password_repeat_field['reference_id'];
                             //$noneditable_fields[] = $the_email_field['reference_id'];
                             $noneditable_fields[] = $the_email_repeat_field['reference_id'];
                             //$noneditable_fields[] = $the_username_field['reference_id'];
                         } else {
                             $the_failed_registration_fields[$the_name_field['reference_id']] = $the_name_field;
                             //$the_failed_registration_fields[$the_password_field['reference_id']] = $the_password_field;
                             //$the_failed_registration_fields[$the_password_repeat_field['reference_id']] = $the_password_repeat_field;
                             $the_failed_registration_fields[$the_email_field['reference_id']] = $the_email_field;
                             $the_failed_registration_fields[$the_email_repeat_field['reference_id']] = $the_email_repeat_field;
                             $the_failed_registration_fields[$the_username_field['reference_id']] = $the_username_field;
                         }
                     } else {
                         $the_failed_registration_fields[$the_name_field['reference_id']] = $the_name_field;
                         //$the_failed_registration_fields[$the_password_field['reference_id']] = $the_password_field;
                         //$the_failed_registration_fields[$the_password_repeat_field['reference_id']] = $the_password_repeat_field;
                         $the_failed_registration_fields[$the_email_field['reference_id']] = $the_email_field;
                         $the_failed_registration_fields[$the_email_repeat_field['reference_id']] = $the_email_repeat_field;
                         $the_failed_registration_fields[$the_username_field['reference_id']] = $the_username_field;
                     }
                 }
                 $form_elements_objects = array();
                 $_items = $data->form->getRecord($this->_record_id, $data->published_only, $this->frontend ? $data->own_only_fe ? JFactory::getUser()->get('id', 0) : -1 : ($data->own_only ? JFactory::getUser()->get('id', 0) : -1), $this->frontend ? $data->show_all_languages_fe : true);
                 // asigning the proper names first
                 foreach ($names as $id => $name) {
                     if (!in_array($id, $noneditable_fields)) {
                         $value = '';
                         $is_array = 'STRING';
                         if (is_array(JRequest::getVar('cb_' . $id, ''))) {
                             $is_array = 'ARRAY';
                         }
                         if (isset($the_fields[$id]['options']->allow_raw) && $the_fields[$id]['options']->allow_raw) {
                             $value = JRequest::getVar('cb_' . $id, '', 'POST', $is_array, JREQUEST_ALLOWRAW);
                         } else {
                             if (isset($the_fields[$id]['options']->allow_html) && $the_fields[$id]['options']->allow_html) {
                                 $value = JRequest::getVar('cb_' . $id, '', 'POST', $is_array, JREQUEST_ALLOWHTML);
                             } else {
                                 $value = JRequest::getVar('cb_' . $id, '', 'POST', $is_array);
                             }
                         }
                         if (isset($the_fields[$id]['options']->transfer_format)) {
                             $value = contentbuilder_convert_date($value, $the_fields[$id]['options']->format, $the_fields[$id]['options']->transfer_format);
                         }
                         if (isset($the_html_fields[$id])) {
                             $the_html_fields[$id]['name'] = $name;
                             $the_html_fields[$id]['value'] = $value;
                         } else {
                             if (isset($the_failed_registration_fields[$id])) {
                                 $the_failed_registration_fields[$id]['name'] = $name;
                                 $the_failed_registration_fields[$id]['value'] = $value;
                             } else {
                                 if (isset($the_upload_fields[$id])) {
                                     $the_upload_fields[$id]['name'] = $name;
                                     $the_upload_fields[$id]['value'] = '';
                                     $the_upload_fields[$id]['orig_value'] = '';
                                     if ($id == $the_upload_fields[$id]['reference_id']) {
                                         // delete if triggered
                                         if (JRequest::getInt('cb_delete_' . $id, 0) == 1 && isset($the_upload_fields[$id]['validations']) && $the_upload_fields[$id]['validations'] == '') {
                                             if (count($_items)) {
                                                 foreach ($_items as $_item) {
                                                     if ($_item->recElementId == $the_upload_fields[$id]['reference_id']) {
                                                         $_value = $_item->recValue;
                                                         $_files = explode("\n", str_replace("\r", '', $_value));
                                                         foreach ($_files as $_file) {
                                                             if (strpos(strtolower($_file), '{cbsite}') === 0) {
                                                                 $_file = str_replace(array('{cbsite}', '{CBSite}'), array(JPATH_SITE, JPATH_SITE), $_file);
                                                             }
                                                             if (JFile::exists($_file)) {
                                                                 JFile::delete($_file);
                                                             }
                                                             $values[$id] = '';
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                         $file = JRequest::getVar('cb_' . $id, null, 'files', 'array');
                                         if (trim(JFile::makeSafe($file['name'])) != '' && $file['size'] > 0) {
                                             $filename = trim(JFile::makeSafe($file['name']));
                                             $infile = $filename;
                                             $src = $file['tmp_name'];
                                             $dest = '';
                                             $tmp_dest = '';
                                             $tmp_upload_field_dir = '';
                                             $tmp_upload_dir = '';
                                             if (isset($the_upload_fields[$id]['options']) && isset($the_upload_fields[$id]['options']->upload_directory) && $the_upload_fields[$id]['options']->upload_directory != '') {
                                                 $tmp_upload_field_dir = $the_upload_fields[$id]['options']->upload_directory;
                                                 $tmp_dest = $tmp_upload_field_dir;
                                             } else {
                                                 if ($data->upload_directory != '') {
                                                     $tmp_upload_dir = $data->upload_directory;
                                                     $tmp_dest = $tmp_upload_dir;
                                                 }
                                             }
                                             if (isset($the_upload_fields[$id]['options']) && isset($the_upload_fields[$id]['options']->upload_directory) && $the_upload_fields[$id]['options']->upload_directory != '') {
                                                 $dest = str_replace(array('{CBSite}', '{cbsite}'), JPATH_SITE, $the_upload_fields[$id]['options']->upload_directory);
                                             } else {
                                                 if ($data->upload_directory != '') {
                                                     $dest = str_replace(array('{CBSite}', '{cbsite}'), JPATH_SITE, $data->upload_directory);
                                                 }
                                             }
                                             // create dest path by tokens
                                             $dest = $this->createPathByTokens($dest, $names);
                                             $msg = '';
                                             $uploaded = false;
                                             // FILE SIZE TEST
                                             if ($dest != '' && isset($the_upload_fields[$id]['options']) && isset($the_upload_fields[$id]['options']->max_filesize) && $the_upload_fields[$id]['options']->max_filesize > 0) {
                                                 $val = $the_upload_fields[$id]['options']->max_filesize;
                                                 $val = trim($val);
                                                 $last = strtolower($val[strlen($val) - 1]);
                                                 switch ($last) {
                                                     case 'g':
                                                         $val *= 1024;
                                                     case 'm':
                                                         $val *= 1024;
                                                     case 'k':
                                                         $val *= 1024;
                                                 }
                                                 if ($file['size'] > $val) {
                                                     $msg = JText::_('COM_CONTENTBUILDER_FILESIZE_EXCEEDED') . ' ' . $the_upload_fields[$id]['options']->max_filesize . 'b';
                                                 }
                                             }
                                             // FILE EXT TEST
                                             if ($dest != '' && isset($the_upload_fields[$id]['options']) && isset($the_upload_fields[$id]['options']->allowed_file_extensions) && $the_upload_fields[$id]['options']->allowed_file_extensions != '') {
                                                 $allowed = explode(',', str_replace(' ', '', strtolower($the_upload_fields[$id]['options']->allowed_file_extensions)));
                                                 $ext = strtolower(JFile::getExt($filename));
                                                 if (!in_array($ext, $allowed)) {
                                                     $msg = JText::_('COM_CONTENTBUILDER_FILE_EXTENSION_NOT_ALLOWED');
                                                 }
                                             }
                                             // UPLOAD
                                             if ($dest != '' && $msg == '') {
                                                 // limit file's name size
                                                 $ext = strtolower(JFile::getExt($filename));
                                                 $stripped = JFile::stripExt($filename);
                                                 // in some apache configurations unknown file extensions could lead to security risks
                                                 // because it will try to find an executable extensions within the chain of dots. So we simply remove them.
                                                 $filename = str_replace(array(' ', '.'), '_', $stripped) . '.' . $ext;
                                                 $maxnamesize = 100;
                                                 if (function_exists('mb_strlen')) {
                                                     if (mb_strlen($filename) > $maxnamesize) {
                                                         $filename = mb_substr($filename, mb_strlen($filename) - $maxnamesize);
                                                     }
                                                 } else {
                                                     if (strlen($filename) > $maxnamesize) {
                                                         $filename = substr($filename, strlen($filename) - $maxnamesize);
                                                     }
                                                 }
                                                 // take care of existing filenames
                                                 if (JFile::exists($dest . DS . $filename)) {
                                                     $filename = md5(mt_rand(0, mt_getrandmax()) . time()) . '_' . $filename;
                                                 }
                                                 // create pseudo security index.html
                                                 if (!JFile::exists($dest . DS . 'index.html')) {
                                                     JFile::write($dest . DS . 'index.html', $buffer = '');
                                                 }
                                                 if (count($_items)) {
                                                     $files_to_delete = array();
                                                     foreach ($_items as $_item) {
                                                         if ($_item->recElementId == $the_upload_fields[$id]['reference_id']) {
                                                             $_value = $_item->recValue;
                                                             $_files = explode("\n", str_replace("\r", '', $_value));
                                                             foreach ($_files as $_file) {
                                                                 if (strpos(strtolower($_file), '{cbsite}') === 0) {
                                                                     $_file = str_replace(array('{cbsite}', '{CBSite}'), array(JPATH_SITE, JPATH_SITE), $_file);
                                                                 }
                                                                 $files_to_delete[] = $_file;
                                                             }
                                                             break;
                                                         }
                                                     }
                                                     foreach ($files_to_delete as $file_to_delete) {
                                                         if (JFile::exists($file_to_delete)) {
                                                             JFile::delete($file_to_delete);
                                                         }
                                                     }
                                                 }
                                                 // final upload file moving
                                                 $uploaded = JFile::upload($src, $dest . DS . $filename);
                                                 if (!$uploaded) {
                                                     $msg = JText::_('COM_CONTENTBUILDER_UPLOAD_FAILED');
                                                 }
                                             }
                                             if ($dest == '' || $uploaded !== true) {
                                                 JRequest::setVar('cb_submission_failed', 1);
                                                 JFactory::getApplication()->enqueueMessage($msg . ' (' . $infile . ')', 'error');
                                                 $the_upload_fields[$id]['value'] = '';
                                             } else {
                                                 if (strpos(strtolower($tmp_dest), '{cbsite}') === 0) {
                                                     $dest = str_replace(array(JPATH_SITE, JPATH_SITE), array('{cbsite}', '{CBSite}'), $dest);
                                                 }
                                                 $values[$id] = $dest . DS . $filename;
                                                 $the_upload_fields[$id]['value'] = $values[$id];
                                             }
                                             $the_upload_fields[$id]['orig_value'] = JFile::makeSafe($file['name']);
                                         }
                                         if (trim($the_upload_fields[$id]['custom_validation_script'])) {
                                             $msg = self::customValidate(trim($the_upload_fields[$id]['custom_validation_script']), $the_upload_fields[$id], $merged = array_merge($the_upload_fields, $the_fields, $the_html_fields), JRequest::getCmd('record_id', ''), $data->form, isset($values[$id]) ? $values[$id] : '');
                                             $msg = trim($msg);
                                             if (!empty($msg)) {
                                                 JRequest::setVar('cb_submission_failed', 1);
                                                 JFactory::getApplication()->enqueueMessage(trim($msg), 'error');
                                             }
                                         }
                                         $removables = array();
                                         $validations = explode(',', $the_upload_fields[$id]['validations']);
                                         foreach ($validations as $validation) {
                                             $plgs = CBPluginHelper::importPlugin('contentbuilder_validation', $validation);
                                             $removables = array_merge($removables, $plgs);
                                         }
                                         $dispatcher = JDispatcher::getInstance();
                                         $results = $dispatcher->trigger('onValidate', array($the_upload_fields[$id], $merged = array_merge($the_upload_fields, $the_fields, $the_html_fields), JRequest::getCmd('record_id', ''), $data->form, isset($values[$id]) ? $values[$id] : ''));
                                         foreach ($removables as $removable) {
                                             $dispatcher->detach($removable);
                                         }
                                         $all_errors = implode('', $results);
                                         if (!empty($all_errors)) {
                                             if (isset($values[$id]) && JFile::exists($values[$id])) {
                                                 JFile::delete($values[$id]);
                                             }
                                             JRequest::setVar('cb_submission_failed', 1);
                                             foreach ($results as $result) {
                                                 $result = trim($result);
                                                 if (!empty($result)) {
                                                     JFactory::getApplication()->enqueueMessage(trim($result), 'error');
                                                 }
                                             }
                                         }
                                     }
                                 } else {
                                     if (isset($the_fields[$id])) {
                                         $the_fields[$id]['name'] = $name;
                                         $the_fields[$id]['value'] = $value;
                                     }
                                 }
                             }
                         }
                     }
                 }
                 foreach ($names as $id => $name) {
                     if (!in_array($id, $noneditable_fields)) {
                         if (isset($the_upload_fields[$id]) && $id == $the_upload_fields[$id]['reference_id']) {
                             // nothing, done above already
                         } else {
                             $f = null;
                             if (isset($the_html_fields[$id])) {
                                 $value = JRequest::getVar('cb_' . $id, '', 'POST', 'STRING', JREQUEST_ALLOWHTML);
                                 $f = $the_html_fields[$id];
                                 $the_html_fields[$id]['value'] = $value;
                             }
                             if (isset($the_failed_registration_fields[$id])) {
                                 $value = JRequest::getVar('cb_' . $id, '', 'POST', 'STRING', JREQUEST_NOTRIM | JREQUEST_ALLOWRAW);
                                 $f = $the_failed_registration_fields[$id];
                                 $the_failed_registration_fields[$id]['value'] = $value;
                             }
                             if (isset($the_fields[$id])) {
                                 $is_array = 'STRING';
                                 if (is_array(JRequest::getVar('cb_' . $id, ''))) {
                                     $is_array = 'ARRAY';
                                 }
                                 if (isset($the_fields[$id]['options']->allow_raw) && $the_fields[$id]['options']->allow_raw) {
                                     $value = JRequest::getVar('cb_' . $id, '', 'POST', $is_array, JREQUEST_ALLOWRAW);
                                 } else {
                                     if (isset($the_fields[$id]['options']->allow_html) && $the_fields[$id]['options']->allow_html) {
                                         $value = JRequest::getVar('cb_' . $id, '', 'POST', $is_array, JREQUEST_ALLOWHTML);
                                     } else {
                                         $value = JRequest::getVar('cb_' . $id, '', 'POST', $is_array);
                                     }
                                 }
                                 if (isset($the_fields[$id]['options']->transfer_format)) {
                                     $value = contentbuilder_convert_date($value, $the_fields[$id]['options']->format, $the_fields[$id]['options']->transfer_format);
                                 }
                                 $f = $the_fields[$id];
                                 $the_fields[$id]['value'] = $value;
                             }
                             if ($f !== null) {
                                 if (trim($f['custom_validation_script'])) {
                                     $msg = self::customValidate(trim($f['custom_validation_script']), $f, $merged = array_merge($the_upload_fields, $the_fields, $the_html_fields), JRequest::getCmd('record_id', ''), $data->form, $value);
                                     $msg = trim($msg);
                                     if (!empty($msg)) {
                                         JRequest::setVar('cb_submission_failed', 1);
                                         JFactory::getApplication()->enqueueMessage(trim($msg), 'error');
                                     }
                                 }
                                 $removables = array();
                                 $validations = explode(',', $f['validations']);
                                 foreach ($validations as $validation) {
                                     $plgs = CBPluginHelper::importPlugin('contentbuilder_validation', $validation);
                                     $removables = array_merge($removables, $plgs);
                                 }
                                 $dispatcher = JDispatcher::getInstance();
                                 $results = $dispatcher->trigger('onValidate', array($f, $merged = array_merge($the_upload_fields, $the_fields, $the_html_fields), JRequest::getCmd('record_id', ''), $data->form, $value));
                                 foreach ($removables as $removable) {
                                     $dispatcher->detach($removable);
                                 }
                                 $all_errors = implode('', $results);
                                 $values[$id] = $value;
                                 if (!empty($all_errors)) {
                                     JRequest::setVar('cb_submission_failed', 1);
                                     foreach ($results as $result) {
                                         $result = trim($result);
                                         if (!empty($result)) {
                                             JFactory::getApplication()->enqueueMessage(trim($result), 'error');
                                         }
                                     }
                                 } else {
                                     $removables = array();
                                     $plgs = CBPluginHelper::importPlugin('contentbuilder_form_elements', $f['type']);
                                     $removables = array_merge($removables, $plgs);
                                     $dispatcher = JDispatcher::getInstance();
                                     $plugin_validations = $dispatcher->trigger('onAfterValidationSuccess', array($f, $m = array_merge($the_upload_fields, $the_fields, $the_html_fields), JRequest::getCmd('record_id', ''), $data->form, $value));
                                     if (count($plugin_validations)) {
                                         $form_elements_objects[] = $plugin_validations[0];
                                     }
                                     foreach ($removables as $removable) {
                                         $dispatcher->detach($removable);
                                     }
                                 }
                             }
                         }
                     }
                 }
                 $submit_before_result = $submit_dispatcher->trigger('onBeforeSubmit', array(JRequest::getCmd('record_id', ''), $data->form, $values));
                 if (JRequest::getVar('cb_submission_failed', 0)) {
                     JFactory::getSession()->set('cb_failed_values', $values, 'com_contentbuilder.' . $this->_id);
                     return JRequest::getCmd('record_id', '');
                 }
                 $record_return = $data->form->saveRecord(JRequest::getCmd('record_id', ''), $values);
                 foreach ($form_elements_objects as $form_elements_object) {
                     if ($form_elements_object instanceof CBFormElementAfterValidation) {
                         $form_elements_object->onSaveRecord($record_return);
                     }
                 }
                 if ($data->act_as_registration && $record_return) {
                     $meta = $data->form->getRecordMetadata($record_return);
                     if (!$data->registration_bypass_plugin || $meta->created_id) {
                         $user_id = $this->register('', '', '', $meta->created_id, JRequest::getVar('cb_' . $the_name_field['reference_id'], '', 'POST', 'STRING', JREQUEST_ALLOWRAW), JRequest::getVar('cb_' . $the_username_field['reference_id'], '', 'POST', 'STRING', JREQUEST_NOTRIM | JREQUEST_ALLOWRAW), JRequest::getVar('cb_' . $the_email_field['reference_id'], '', 'POST', 'STRING', JREQUEST_ALLOWRAW), JRequest::getVar('cb_' . $the_password_field['reference_id'], '', 'POST', 'STRING', JREQUEST_NOTRIM | JREQUEST_ALLOWRAW));
                         if (intval($user_id) > 0) {
                             JFactory::getSession()->set('cb_last_record_user_id', $user_id, 'com_contentbuilder');
                             $data->form->saveRecordUserData($record_return, $user_id, JRequest::getVar('cb_' . $the_name_field['reference_id'], '', 'POST', 'STRING', JREQUEST_ALLOWRAW), JRequest::getVar('cb_' . $the_username_field['reference_id'], '', 'POST', 'STRING', JREQUEST_NOTRIM | JREQUEST_ALLOWRAW));
                         }
                     } else {
                         if (!$meta->created_id) {
                             $bypass = new stdClass();
                             $verification_name = str_replace(array(';', '___', '|'), '-', trim($data->registration_bypass_verification_name) ? trim($data->registration_bypass_verification_name) : $data->title);
                             $verify_view = trim($data->registration_bypass_verify_view) ? trim($data->registration_bypass_verify_view) : $data->id;
                             $bypass->text = $orig_text = '{CBVerify plugin: ' . $data->registration_bypass_plugin . '; verification-name: ' . $verification_name . '; verify-view: ' . $verify_view . '; ' . str_replace(array("\r", "\n"), '', $data->registration_bypass_plugin_params) . '}';
                             $params = new stdClass();
                             JPluginHelper::importPlugin('content', 'contentbuilder_verify');
                             $bypass_dispatcher = JDispatcher::getInstance();
                             $bypass_result = $bypass_dispatcher->trigger('onPrepareContent', array(&$bypass, &$params));
                             $verification_id = '';
                             if ($bypass->text != $orig_text) {
                                 $verification_id = md5(uniqid(null, true) . mt_rand(0, mt_getrandmax()) . JFactory::getUser()->get('id', 0));
                             }
                             $user_id = $this->register($data->registration_bypass_plugin, $verification_name, $verification_id, $meta->created_id, JRequest::getVar('cb_' . $the_name_field['reference_id'], '', 'POST', 'STRING', JREQUEST_ALLOWRAW), JRequest::getVar('cb_' . $the_username_field['reference_id'], '', 'POST', 'STRING', JREQUEST_NOTRIM | JREQUEST_ALLOWRAW), JRequest::getVar('cb_' . $the_email_field['reference_id'], '', 'POST', 'STRING', JREQUEST_ALLOWRAW), JRequest::getVar('cb_' . $the_password_field['reference_id'], '', 'POST', 'STRING', JREQUEST_NOTRIM | JREQUEST_ALLOWRAW));
                             if (intval($user_id) > 0) {
                                 JFactory::getSession()->set('cb_last_record_user_id', $user_id, 'com_contentbuilder');
                                 $data->form->saveRecordUserData($record_return, $user_id, JRequest::getVar('cb_' . $the_name_field['reference_id'], '', 'POST', 'STRING', JREQUEST_ALLOWRAW), JRequest::getVar('cb_' . $the_username_field['reference_id'], '', 'POST', 'STRING', JREQUEST_NOTRIM | JREQUEST_ALLOWRAW));
                             }
                             if ($bypass->text != $orig_text && intval($user_id) > 0) {
                                 $_now = JFactory::getDate();
                                 $setup = JFactory::getSession()->get($data->registration_bypass_plugin . $verification_name, '', 'com_contentbuilder.verify.' . $data->registration_bypass_plugin . $verification_name);
                                 JFactory::getSession()->clear($data->registration_bypass_plugin . $verification_name, 'com_contentbuilder.verify.' . $data->registration_bypass_plugin . $verification_name);
                                 jimport('joomla.version');
                                 $version = new JVersion();
                                 if (version_compare($version->getShortVersion(), '3.0', '>=')) {
                                     $___now = $_now->toSql();
                                 } else {
                                     $___now = $_now->toMySQL();
                                 }
                                 $this->_db->setQuery("\n                                            Insert Into #__contentbuilder_verifications\n                                            (\n                                            `verification_hash`,\n                                            `start_date`,\n                                            `verification_data`,\n                                            `user_id`,\n                                            `plugin`,\n                                            `ip`,\n                                            `setup`,\n                                            `client`\n                                            )\n                                            Values\n                                            (\n                                            " . $this->_db->Quote($verification_id) . ",\n                                            " . $this->_db->Quote($___now) . ",\n                                            " . $this->_db->Quote('type=registration&') . ",\n                                            " . $user_id . ",\n                                            " . $this->_db->Quote($data->registration_bypass_plugin) . ",\n                                            " . $this->_db->Quote($_SERVER['REMOTE_ADDR']) . ",\n                                            " . $this->_db->Quote($setup) . ",\n                                            " . intval(JFactory::getApplication()->isAdmin() ? 1 : 0) . "\n                                            )\n                                    ");
                                 $this->_db->query();
                             }
                         }
                     }
                 }
                 if ($this->frontend && !JRequest::getCmd('record_id', '') && $record_return && !JRequest::getVar('return', '')) {
                     if ($data->force_login) {
                         if (!JFactory::getUser()->get('id', 0)) {
                             if (!$this->is15) {
                                 JRequest::setVar('return', base64_encode(JRoute::_('index.php?option=com_users&view=login&Itemid=' . JRequest::getInt('Itemid', 0), false)));
                             } else {
                                 JRequest::setVar('return', base64_encode(JRoute::_('index.php?option=com_user&view=login&Itemid=' . JRequest::getInt('Itemid', 0), false)));
                             }
                         } else {
                             if (!$this->is15) {
                                 JRequest::setVar('return', base64_encode(JRoute::_('index.php?option=com_users&view=profile&Itemid=' . JRequest::getInt('Itemid', 0), false)));
                             } else {
                                 JRequest::setVar('return', base64_encode(JRoute::_('index.php?option=com_user&view=user&Itemid=' . JRequest::getInt('Itemid', 0), false)));
                             }
                         }
                     } else {
                         if (trim($data->force_url)) {
                             JRequest::setVar('cbInternalCheck', 0);
                             JRequest::setVar('return', base64_encode(trim($data->force_url)));
                         }
                     }
                 }
                 if ($record_return) {
                     $sef = '';
                     $ignore_lang_code = '*';
                     if ($data->default_lang_code_ignore) {
                         jimport('joomla.version');
                         $version = new JVersion();
                         if (version_compare($version->getShortVersion(), '1.6', '>=')) {
                             $this->_db->setQuery("Select lang_code From #__languages Where published = 1 And sef = " . $this->_db->Quote(trim(JRequest::getCmd('lang', ''))));
                             $ignore_lang_code = $this->_db->loadResult();
                             if (!$ignore_lang_code) {
                                 $ignore_lang_code = '*';
                             }
                         } else {
                             $codes = contentbuilder::getLanguageCodes();
                             foreach ($codes as $code) {
                                 if (strstr(strtolower($code), strtolower(trim(JRequest::getCmd('lang', '')))) !== false) {
                                     $ignore_lang_code = strtolower($code);
                                     break;
                                 }
                             }
                         }
                         $sef = trim(JRequest::getCmd('lang', ''));
                         if ($ignore_lang_code == '*') {
                             $sef = '';
                         }
                     } else {
                         jimport('joomla.version');
                         $version = new JVersion();
                         if (version_compare($version->getShortVersion(), '1.6', '>=')) {
                             $this->_db->setQuery("Select sef From #__languages Where published = 1 And lang_code = " . $this->_db->Quote($data->default_lang_code));
                             $sef = $this->_db->loadResult();
                         } else {
                             $codes = contentbuilder::getLanguageCodes();
                             foreach ($codes as $code) {
                                 if ($code == $data->default_lang_code) {
                                     $sef = explode('-', $code);
                                     if (count($sef)) {
                                         $sef = strtolower($sef[0]);
                                     }
                                     break;
                                 }
                             }
                         }
                     }
                     $language = $data->default_lang_code_ignore ? $ignore_lang_code : $data->default_lang_code;
                     $this->_db->setQuery("Select id, edited From #__contentbuilder_records Where `type` = " . $this->_db->Quote($data->type) . " And `reference_id` = " . $this->_db->Quote($data->form->getReferenceId()) . " And record_id = " . $this->_db->Quote($record_return));
                     $res = $this->_db->loadAssoc();
                     $last_update = JFactory::getDate();
                     jimport('joomla.version');
                     $version = new JVersion();
                     if (version_compare($version->getShortVersion(), '3.0', '>=')) {
                         $last_update = $last_update->toSql();
                     } else {
                         $last_update = $last_update->toMySQL();
                     }
                     if (!is_array($res)) {
                         $is_future = 0;
                         $created_up = JFactory::getDate();
                         if (version_compare($version->getShortVersion(), '3.0', '>=')) {
                             $created_up = $created_up->toSql();
                         } else {
                             $created_up = $created_up->toMySQL();
                         }
                         if (intval($data->default_publish_up_days) != 0) {
                             $is_future = 1;
                             $date = JFactory::getDate(strtotime('now +' . intval($data->default_publish_up_days) . ' days'));
                             if (version_compare($version->getShortVersion(), '3.0', '>=')) {
                                 $created_up = $date->toSql();
                             } else {
                                 $created_up = $date->toMySQL();
                             }
                         }
                         $created_down = '0000-00-00 00:00:00';
                         if (intval($data->default_publish_down_days) != 0) {
                             $date = JFactory::getDate(strtotime($created_up . ' +' . intval($data->default_publish_down_days) . ' days'));
                             if (version_compare($version->getShortVersion(), '3.0', '>=')) {
                                 $created_down = $date->toSql();
                             } else {
                                 $created_down = $date->toMySQL();
                             }
                         }
                         $this->_db->setQuery("Insert Into #__contentbuilder_records (session_id,`type`,last_update,is_future,lang_code, sef, published, record_id, reference_id, publish_up, publish_down) Values ('" . JFactory::getSession()->getId() . "'," . $this->_db->Quote($data->type) . "," . $this->_db->Quote($last_update) . ",{$is_future}," . $this->_db->Quote($language) . "," . $this->_db->Quote(trim($sef)) . "," . $this->_db->Quote($data->auto_publish && !$is_future ? 1 : 0) . ", " . $this->_db->Quote($record_return) . ", " . $this->_db->Quote($data->form->getReferenceId()) . ", " . $this->_db->Quote($created_up) . ", " . $this->_db->Quote($created_down) . ")");
                         $this->_db->query();
                     } else {
                         $this->_db->setQuery("Update #__contentbuilder_records Set last_update = " . $this->_db->Quote($last_update) . ",lang_code = " . $this->_db->Quote($language) . ", sef = " . $this->_db->Quote(trim($sef)) . ", edited = edited + 1 Where `type` = " . $this->_db->Quote($data->type) . " And  `reference_id` = " . $this->_db->Quote($data->form->getReferenceId()) . " And record_id = " . $this->_db->Quote($record_return));
                         $this->_db->query();
                     }
                 }
             } else {
                 $record_return = JRequest::getCmd('record_id', '');
             }
             $data->items = $data->form->getRecord($record_return, $data->published_only, $this->frontend ? $data->own_only_fe ? JFactory::getUser()->get('id', 0) : -1 : ($data->own_only ? JFactory::getUser()->get('id', 0) : -1), true);
             $data_email_items = $data->form->getRecord($record_return, false, -1, false);
             $data->labels = $data->form->getElementLabels();
             $ids = array();
             foreach ($data->labels as $reference_id => $label) {
                 $ids[] = $this->_db->Quote($reference_id);
             }
             $data->labels = array();
             if (count($ids)) {
                 $this->_db->setQuery("Select Distinct `label`, reference_id From #__contentbuilder_elements Where form_id = " . intval($this->_id) . " And reference_id In (" . implode(',', $ids) . ") And published = 1 Order By ordering");
                 $rows = $this->_db->loadAssocList();
                 $ids = array();
                 foreach ($rows as $row) {
                     $ids[] = $row['reference_id'];
                 }
             }
             $article_id = 0;
             // creating the article
             if ($data->create_articles && count($data->items)) {
                 $data->page_title = $data->use_view_name_as_title ? $data->name : $data->form->getPageTitle();
                 //if(!count($data->items)){
                 //     JError::raiseError(404, JText::_('COM_CONTENTBUILDER_RECORD_NOT_FOUND'));
                 //}
                 $this->_db->setQuery("Select articles.`id` From #__contentbuilder_articles As articles, #__content As content Where content.id = articles.article_id And (content.state = 1 Or content.state = 0) And articles.form_id = " . intval($this->_id) . " And articles.record_id = " . $this->_db->Quote($record_return));
                 $article = $this->_db->loadResult();
                 $config = array();
                 if ($article) {
                     if (!$this->is15) {
                         $config = JRequest::getVar('jform', array());
                     } else {
                         $config = array('ordering' => JRequest::getInt('ordering', 0), 'sectionid' => JRequest::getInt('sectionid', 0), 'catid' => JRequest::getInt('catid', 0), 'alias' => JRequest::getVar('alias', ''), 'frontpage' => JRequest::getInt('frontpage', 0), 'state' => JRequest::getInt('state', 0), 'details' => JRequest::getVar('details', array()), 'params' => JRequest::getVar('params', array()), 'meta' => JRequest::getVar('meta', array()));
                     }
                 }
                 $full = $this->frontend ? contentbuilder::authorizeFe('fullarticle') : contentbuilder::authorize('fullarticle');
                 $article_id = contentbuilder::createArticle($this->_id, $record_return, $data->items, $ids, $data->title_field, $data->form->getRecordMetadata($record_return), $config, $full, $this->frontend ? $data->limited_article_options_fe : $data->limited_article_options, JRequest::getVar('cb_category_id', null));
                 if (isset($form_elements_objects)) {
                     foreach ($form_elements_objects as $form_elements_object) {
                         if ($form_elements_object instanceof CBFormElementAfterValidation) {
                             $form_elements_object->onSaveArticle($article_id);
                         }
                     }
                 }
             }
             // required to determine blocked users in system plugin
             if ($data->act_as_registration && isset($user_id) && intval($user_id) > 0) {
                 $this->_db->setQuery("Insert Into #__contentbuilder_registered_users (user_id, form_id, record_id) Values (" . intval($user_id) . ", " . $this->_id . ", " . $this->_db->Quote($record_return) . ")");
                 $this->_db->query();
             }
             if (!$data->edit_by_type) {
                 $cleanedValues = array();
                 foreach ($values as $rawvalue) {
                     if (is_array($rawvalue)) {
                         if (isset($rawvalue[0]) && $rawvalue[0] == 'cbGroupMark') {
                             unset($rawvalue[0]);
                             $cleanedValues[] = array_values($rawvalue);
                         } else {
                             $cleanedValues[] = $rawvalue;
                         }
                     } else {
                         $cleanedValues[] = $rawvalue;
                     }
                 }
                 $submit_after_result = $submit_dispatcher->trigger('onAfterSubmit', array($record_return, $article_id, $data->form, $cleanedValues));
                 foreach ($fields as $actionField) {
                     if (trim($actionField['custom_action_script'])) {
                         self::customAction(trim($actionField['custom_action_script']), $record_return, $article_id, $data->form, $actionField, $fields, $cleanedValues);
                     }
                 }
                 if (!JRequest::getCmd('record_id', '') && $data->email_notifications || JRequest::getCmd('record_id', '') && $data->email_update_notifications) {
                     $from = $MailFrom = CBCompat::getJoomlaConfig('config.mailfrom');
                     $fromname = CBCompat::getJoomlaConfig('config.fromname');
                     $mailer = JFactory::getMailer();
                     $email_admin_template = '';
                     $email_template = '';
                     // admin email
                     if (trim($data->email_admin_recipients)) {
                         // sender
                         if (trim($data->email_admin_alternative_from)) {
                             foreach ($data->items as $item) {
                                 $data->email_admin_alternative_from = str_replace('{' . $item->recName . '}', cbinternal($item->recValue), $data->email_admin_alternative_from);
                             }
                             $from = $data->email_admin_alternative_from;
                         }
                         if (trim($data->email_admin_alternative_fromname)) {
                             foreach ($data->items as $item) {
                                 $data->email_admin_alternative_fromname = str_replace('{' . $item->recName . '}', cbinternal($item->recValue), $data->email_admin_alternative_fromname);
                             }
                             $fromname = $data->email_admin_alternative_fromname;
                         }
                         $mailer->setSender(array(trim($MailFrom), trim($fromname)));
                         $mailer->addReplyTo(array($from, $fromname));
                         // recipients
                         foreach ($data->items as $item) {
                             $data->email_admin_recipients = str_replace('{' . $item->recName . '}', cbinternal($item->recValue), $data->email_admin_recipients);
                         }
                         $recipients_checked_admin = array();
                         $recipients_admin = explode(';', $data->email_admin_recipients);
                         foreach ($recipients_admin as $recipient_admin) {
                             if (contentbuilder_is_email(trim($recipient_admin))) {
                                 $recipients_checked_admin[] = trim($recipient_admin);
                             }
                         }
                         $mailer->addBCC($recipients_checked_admin);
                         $email_admin_template = contentbuilder::getEmailTemplate($this->_id, $record_return, $data_email_items, $ids, true);
                         // subject
                         $subject_admin = JText::_('COM_CONTENTBUILDER_EMAIL_RECORD_RECEIVED');
                         if (trim($data->email_admin_subject)) {
                             foreach ($data->items as $item) {
                                 $data->email_admin_subject = str_replace('{' . $item->recName . '}', cbinternal($item->recValue), $data->email_admin_subject);
                             }
                             $subject_admin = $data->email_admin_subject;
                             $subject_admin = str_replace(array('{RECORD_ID}', '{record_id}'), $record_return, $subject_admin);
                             $subject_admin = str_replace(array('{USER_ID}', '{user_id}'), JFactory::getUser()->get('id'), $subject_admin);
                             $subject_admin = str_replace(array('{USERNAME}', '{username}'), JFactory::getUser()->get('username'), $subject_admin);
                             $subject_admin = str_replace(array('{USER_FULL_NAME}', '{user_full_name}'), JFactory::getUser()->get('name'), $subject_admin);
                             $subject_admin = str_replace(array('{EMAIL}', '{email}'), JFactory::getUser()->get('email'), $subject_admin);
                             $subject_admin = str_replace(array('{VIEW_NAME}', '{view_name}'), $data->name, $subject_admin);
                             $subject_admin = str_replace(array('{VIEW_ID}', '{view_id}'), $this->_id, $subject_admin);
                             $subject_admin = str_replace(array('{IP}', '{ip}'), $_SERVER['REMOTE_ADDR'], $subject_admin);
                         }
                         $mailer->setSubject($subject_admin);
                         // attachments
                         foreach ($data->items as $item) {
                             $data->email_admin_recipients_attach_uploads = str_replace('{' . $item->recName . '}', $item->recValue, $data->email_admin_recipients_attach_uploads);
                         }
                         $attachments_admin = explode(';', $data->email_admin_recipients_attach_uploads);
                         $attached_admin = array();
                         foreach ($attachments_admin as $attachment_admin) {
                             $attachment_admin = explode("\n", str_replace("\r", "", trim($attachment_admin)));
                             foreach ($attachment_admin as $att_admin) {
                                 if (strpos(strtolower($att_admin), '{cbsite}') === 0) {
                                     $att_admin = str_replace(array('{cbsite}', '{CBSite}'), array(JPATH_SITE, JPATH_SITE), $att_admin);
                                 }
                                 if (JFile::exists(trim($att_admin))) {
                                     $attached_admin[] = trim($att_admin);
                                 }
                             }
                         }
                         $mailer->addAttachment($attached_admin);
                         $mailer->isHTML($data->email_admin_html);
                         $mailer->setBody($email_admin_template);
                         if (count($recipients_checked_admin)) {
                             $send = $mailer->Send();
                             if ($send !== true) {
                                 JFactory::getApplication()->enqueueMessage('Error sending email: ' . $mailer->ErrorInfo, 'error');
                             }
                         }
                         $mailer->ClearAddresses();
                         $mailer->ClearAllRecipients();
                         $mailer->ClearAttachments();
                     }
                     // public email
                     if (trim($data->email_recipients)) {
                         // sender
                         if (trim($data->email_alternative_from)) {
                             foreach ($data->items as $item) {
                                 $data->email_alternative_from = str_replace('{' . $item->recName . '}', cbinternal($item->recValue), $data->email_alternative_from);
                             }
                             $from = $data->email_alternative_from;
                         }
                         if (trim($data->email_alternative_fromname)) {
                             foreach ($data->items as $item) {
                                 $data->email_alternative_fromname = str_replace('{' . $item->recName . '}', cbinternal($item->recValue), $data->email_alternative_fromname);
                             }
                             $fromname = $data->email_alternative_fromname;
                         }
                         $mailer->setSender(array(trim($MailFrom), trim($fromname)));
                         $mailer->addReplyTo(array($from, $fromname));
                         // recipients
                         foreach ($data->items as $item) {
                             $data->email_recipients = str_replace('{' . $item->recName . '}', cbinternal($item->recValue), $data->email_recipients);
                         }
                         $recipients_checked = array();
                         $recipients = explode(';', $data->email_recipients);
                         foreach ($recipients as $recipient) {
                             if (contentbuilder_is_email($recipient)) {
                                 $recipients_checked[] = $recipient;
                             }
                         }
                         $mailer->addBCC($recipients_checked);
                         $email_template = contentbuilder::getEmailTemplate($this->_id, $record_return, $data_email_items, $ids, false);
                         // subject
                         $subject = JText::_('COM_CONTENTBUILDER_EMAIL_RECORD_RECEIVED');
                         if (trim($data->email_subject)) {
                             foreach ($data->items as $item) {
                                 $data->email_subject = str_replace('{' . $item->recName . '}', cbinternal($item->recValue), $data->email_subject);
                             }
                             $subject = $data->email_subject;
                             $subject = str_replace(array('{RECORD_ID}', '{record_id}'), $record_return, $subject);
                             $subject = str_replace(array('{USER_ID}', '{user_id}'), JFactory::getUser()->get('id'), $subject);
                             $subject = str_replace(array('{USERNAME}', '{username}'), JFactory::getUser()->get('username'), $subject);
                             $subject = str_replace(array('{EMAIL}', '{email}'), JFactory::getUser()->get('email'), $subject);
                             $subject = str_replace(array('{USER_FULL_NAME}', '{user_full_name}'), JFactory::getUser()->get('name'), $subject);
                             $subject = str_replace(array('{VIEW_NAME}', '{view_name}'), $data->name, $subject);
                             $subject = str_replace(array('{VIEW_ID}', '{view_id}'), $this->_id, $subject);
                             $subject = str_replace(array('{IP}', '{ip}'), $_SERVER['REMOTE_ADDR'], $subject);
                         }
                         $mailer->setSubject($subject);
                         // attachments
                         foreach ($data->items as $item) {
                             $data->email_recipients_attach_uploads = str_replace('{' . $item->recName . '}', $item->recValue, $data->email_recipients_attach_uploads);
                         }
                         $attachments = explode(';', $data->email_recipients_attach_uploads);
                         $attached = array();
                         foreach ($attachments as $attachment) {
                             $attachment = explode("\n", str_replace("\r", "", trim($attachment)));
                             foreach ($attachment as $att) {
                                 if (strpos(strtolower($att), '{cbsite}') === 0) {
                                     $att = str_replace(array('{cbsite}', '{CBSite}'), array(JPATH_SITE, JPATH_SITE), $att);
                                 }
                                 if (JFile::exists(trim($att))) {
                                     $attached[] = trim($att);
                                 }
                             }
                         }
                         $mailer->addAttachment($attached);
                         $mailer->isHTML($data->email_html);
                         $mailer->setBody($email_template);
                         if (count($recipients_checked)) {
                             $send = $mailer->Send();
                             if ($send !== true) {
                                 JFactory::getApplication()->enqueueMessage('Error sending email: ' . $mailer->ErrorInfo, 'error');
                             }
                         }
                         $mailer->ClearAddresses();
                         $mailer->ClearAllRecipients();
                         $mailer->ClearAttachments();
                     }
                 }
             }
             return $record_return;
         }
     }
     if (!$this->is15) {
         $cache = JFactory::getCache('com_content');
         $cache->clean();
         $cache = JFactory::getCache('com_contentbuilder');
         $cache->clean();
     } else {
         $cache = JFactory::getCache('com_content');
         $cache->clean();
         $cache = JFactory::getCache('com_contentbuilder');
         $cache->clean();
     }
     return false;
 }
コード例 #5
0
ファイル: list.php プロジェクト: ranrolls/ras-full-portal
 /**
  * Gets the currencies
  * @return array List of products
  */
 function getData()
 {
     $mainframe = JFactory::getApplication();
     $option = 'com_contentbuilder';
     // Lets load the data if it doesn't already exist
     if (empty($this->_data)) {
         $query = $this->_buildQuery();
         $this->_data = $this->_getList($query, 0, 1);
         if (!count($this->_data)) {
             JError::raiseError(404, JText::_('COM_CONTENTBUILDER_FORM_NOT_FOUND'));
         }
         foreach ($this->_data as $data) {
             if (!$this->frontend && $data->display_in == 0) {
                 JError::raiseError(404, JText::_('COM_CONTENTBUILDER_FORM_NOT_FOUND'));
             } else {
                 if ($this->frontend && $data->display_in == 1) {
                     JError::raiseError(404, JText::_('COM_CONTENTBUILDER_FORM_NOT_FOUND'));
                 }
             }
             // filter by category if requested by menu item
             if (JRequest::getVar('cb_category_menu_filter', null) !== null && JRequest::getVar('cb_category_menu_filter', 0) == 1 && JRequest::getVar('cb_category_id', null) !== null) {
                 if (JRequest::getInt('cb_category_id', -1) > -2) {
                     $this->setState('article_category_filter', JRequest::getInt('cb_category_id', -1));
                 } else {
                     $this->setState('article_category_filter', $data->default_category);
                 }
             }
             $data->show_page_heading = $this->_show_page_heading;
             $data->page_class = $this->_page_class;
             $data->form_id = $this->_id;
             if ($data->type && $data->reference_id) {
                 $data->form = contentbuilder::getForm($data->type, $data->reference_id);
                 if (!$data->form->exists) {
                     JError::raiseError(404, JText::_('COM_CONTENTBUILDER_FORM_NOT_FOUND'));
                 }
                 $data->page_title = '';
                 if (JRequest::getInt('cb_prefix_in_title', 1)) {
                     if (!$this->_menu_item) {
                         $data->page_title = $data->use_view_name_as_title ? $data->name : $data->form->getPageTitle();
                     } else {
                         $data->page_title = $data->use_view_name_as_title ? $data->name : JFactory::getDocument()->getTitle();
                     }
                 }
                 // enables the record randomizer
                 $now = JFactory::getDate();
                 $data->rand_update = intval($data->rand_update);
                 if ($data->rand_update < 1) {
                     $data->rand_update = 86400;
                 }
                 jimport('joomla.version');
                 $version = new JVersion();
                 if (version_compare($version->getShortVersion(), '3.0', '>=')) {
                     $___now = $now->toSql();
                 } else {
                     $___now = $now->toMySQL();
                 }
                 if ($data->initial_sort_order == 'Rand' && ($data->rand_date_update == '0000-00-00 00:00:00' || $now->toUnix() - strtotime($data->rand_date_update) >= $data->rand_update)) {
                     $this->_db->setQuery("UPDATE #__contentbuilder_records SET rand_date = '" . $___now . "' + interval rand()*10000 day Where `type` = " . $this->_db->Quote($data->type) . " And reference_id = " . $this->_db->Quote($data->reference_id));
                     $this->_db->query();
                     $this->_db->setQuery("Update #__contentbuilder_forms Set rand_date_update = '" . $___now . "'");
                     $this->_db->query();
                 }
                 $data->labels = $data->form->getElementLabels();
                 if (JRequest::getBool('filter_reset', false)) {
                     JFactory::getSession()->clear('com_contentbuilder.filter_signal.' . $this->_id);
                     JFactory::getSession()->clear('com_contentbuilder.filter.' . $this->_id);
                     JFactory::getSession()->clear('com_contentbuilder.calendar_filter_from.' . $this->_id);
                     JFactory::getSession()->clear('com_contentbuilder.calendar_filter_to.' . $this->_id);
                     JFactory::getSession()->clear('com_contentbuilder.calendar_formats.' . $this->_id);
                     JFactory::getSession()->clear('com_contentbuilder.filter_keywords.' . $this->_id);
                     JFactory::getSession()->clear('com_contentbuilder.filter_article_categories.' . $this->_id);
                 } else {
                     if ((JFactory::getSession()->get('com_contentbuilder.filter_signal.' . $this->_id, false) || JRequest::getBool('contentbuilder_filter_signal', false)) && $data->allow_external_filter) {
                         $orders = array();
                         $filters = array();
                         $filters_from = array();
                         $filters_to = array();
                         $calendar_formats = array();
                         // renew on request
                         if (JRequest::getBool('contentbuilder_filter_signal', false)) {
                             if (JRequest::getVar('cbListFilterKeywords', '')) {
                                 $this->setState('formsd_filter', JRequest::getVar('cbListFilterKeywords', ''));
                             }
                             if (JRequest::getVar('cbListFilterArticleCategories', -1) > -1) {
                                 $this->setState('article_category_filter', JRequest::getInt('cbListFilterArticleCategories', -1));
                             }
                             $filters = JRequest::getVar('cb_filter', array(), 'POST', 'array');
                             $filters_from = JRequest::getVar('cbListFilterCalendarFrom', array(), 'POST', 'array');
                             $filters_to = JRequest::getVar('cbListFilterCalendarTo', array(), 'POST', 'array');
                             $calendar_formats = JRequest::getVar('cb_filter_calendar_format', array(), 'POST', 'array');
                             JFactory::getSession()->set('com_contentbuilder.filter_signal.' . $this->_id, true);
                             JFactory::getSession()->set('com_contentbuilder.filter.' . $this->_id, $filters);
                             JFactory::getSession()->set('com_contentbuilder.filter_keywords.' . $this->_id, JRequest::getVar('cbListFilterKeywords', ''));
                             JFactory::getSession()->set('com_contentbuilder.filter_article_categories.' . $this->_id, JRequest::getInt('cbListFilterArticleCategories', -1));
                             JFactory::getSession()->set('com_contentbuilder.calendar_filter_from.' . $this->_id, $filters_from);
                             JFactory::getSession()->set('com_contentbuilder.calendar_filter_to.' . $this->_id, $filters_to);
                             JFactory::getSession()->set('com_contentbuilder.calendar_formats.' . $this->_id, $calendar_formats);
                             // else pick from session
                         } else {
                             if (JFactory::getSession()->get('com_contentbuilder.filter_signal.' . $this->_id, false)) {
                                 $filters = JFactory::getSession()->get('com_contentbuilder.filter.' . $this->_id, array());
                                 $filters_from = JFactory::getSession()->get('com_contentbuilder.calendar_filter_from.' . $this->_id, array());
                                 $filters_to = JFactory::getSession()->get('com_contentbuilder.calendar_filter_to.' . $this->_id, array());
                                 $calendar_formats = JFactory::getSession()->get('com_contentbuilder.calendar_formats.' . $this->_id, array());
                                 $filter_keywords = JFactory::getSession()->get('com_contentbuilder.filter_keywords.' . $this->_id, '');
                                 $filter_cats = JFactory::getSession()->get('com_contentbuilder.filter_article_categories.' . $this->_id, -1);
                                 if ($filter_keywords != '') {
                                     $this->setState('formsd_filter', $filter_keywords);
                                 }
                                 if ($filter_cats != -1) {
                                     $this->setState('article_category_filter', $filter_cats);
                                 }
                             }
                         }
                         foreach ($calendar_formats as $col => $calendar_format) {
                             if (isset($filters[$col])) {
                                 $filter_exploded = explode('/', $filters[$col]);
                                 if (isset($filter_exploded[2])) {
                                     $to_exploded = explode('to', $filter_exploded[2]);
                                     switch (count($to_exploded)) {
                                         case 2:
                                             if ($to_exploded[0] != '') {
                                                 $filters[$col] = '@range/date/' . contentbuilder_convert_date(trim($to_exploded[0]), $calendar_format) . ' to ' . contentbuilder_convert_date(trim($to_exploded[1]), $calendar_format);
                                             } else {
                                                 $filters[$col] = '@range/date/to ' . contentbuilder_convert_date(trim($to_exploded[1]), $calendar_format);
                                             }
                                             break;
                                         case 1:
                                             $filters[$col] = '@range/date/' . contentbuilder_convert_date(trim($to_exploded[0]), $calendar_format);
                                             break;
                                     }
                                     if (isset($to_exploded[0]) && isset($to_exploded[1]) && trim($to_exploded[0]) == '' && trim($to_exploded[1]) == '') {
                                         $filters[$col] = '';
                                     }
                                     if (isset($to_exploded[0]) && !isset($to_exploded[1]) && trim($to_exploded[0]) == '') {
                                         $filters[$col] = '';
                                     }
                                 }
                             }
                         }
                         $new_filters = array();
                         $i = 1;
                         foreach ($filters as $filter_key => $filter) {
                             if ($filter != '') {
                                 $orders[$filter_key] = $i;
                                 $new_filters[$filter_key] = explode('|', $filter);
                             }
                             $i++;
                         }
                         $this->_menu_filter = $new_filters;
                         $this->_menu_filter_order = $orders;
                     }
                 }
                 $ordered_extra_title = '';
                 foreach ($this->_menu_filter_order as $order_key => $order) {
                     if (isset($this->_menu_filter[$order_key])) {
                         // range test
                         $is_range = strstr(strtolower(implode(',', $this->_menu_filter[$order_key])), '@range') !== false;
                         $is_match = strstr(strtolower(implode(',', $this->_menu_filter[$order_key])), '@match') !== false;
                         if ($is_range) {
                             $ex = explode('/', implode(', ', $this->_menu_filter[$order_key]));
                             if (count($ex) == 3) {
                                 $ex2 = explode('to', trim($ex[2]));
                                 $out = '';
                                 $val = $ex2[0];
                                 $val2 = '';
                                 if (isset($ex2[1])) {
                                     $val2 = $ex2[1];
                                 }
                                 if (strtolower(trim($ex[1])) == 'date') {
                                     $val = JHTML::_('date', $ex2[0], JText::_('DATE_FORMAT_LC3'));
                                     if (isset($ex2[1])) {
                                         $val2 = JHTML::_('date', $ex2[1], JText::_('DATE_FORMAT_LC3'));
                                     }
                                 }
                                 if (count($ex2) == 2) {
                                     $out = (trim($ex2[0]) ? JText::_('COM_CONTENTBUILDER_FROM') . ' ' . trim($val) : '') . ' ' . JText::_('COM_CONTENTBUILDER_TO') . ' ' . trim($val2);
                                 } else {
                                     if (count($ex2) > 0) {
                                         $out = JText::_('COM_CONTENTBUILDER_FROM2') . ' ' . trim($val);
                                     }
                                 }
                                 if ($out) {
                                     $this->_menu_filter[$order_key] = $ex;
                                     $ordered_extra_title .= ' &raquo; ' . htmlentities($data->labels[$order_key], ENT_QUOTES, 'UTF-8') . ': ' . htmlentities($out, ENT_QUOTES, 'UTF-8');
                                 }
                             }
                         } else {
                             if ($is_match) {
                                 $ex = explode('/', implode(', ', $this->_menu_filter[$order_key]));
                                 if (count($ex) == 2) {
                                     $ex2 = explode(';', trim($ex[1]));
                                     $out = '';
                                     $size = count($ex2);
                                     $i = 0;
                                     foreach ($ex2 as $val) {
                                         if ($i + 1 < $size) {
                                             $out .= trim($val) . ' ' . JText::_('COM_CONTENTBUILDER_AND') . ' ';
                                         } else {
                                             $out .= trim($val);
                                         }
                                         $i++;
                                     }
                                     if ($out) {
                                         $this->_menu_filter[$order_key] = $ex;
                                         $ordered_extra_title .= ' &raquo; ' . htmlentities($data->labels[$order_key], ENT_QUOTES, 'UTF-8') . ': ' . htmlentities($out, ENT_QUOTES, 'UTF-8');
                                     }
                                 }
                             } else {
                                 $ordered_extra_title .= ' &raquo; ' . htmlentities($data->labels[$order_key], ENT_QUOTES, 'UTF-8') . ': ' . htmlentities(implode(', ', $this->_menu_filter[$order_key]), ENT_QUOTES, 'UTF-8');
                             }
                         }
                     }
                 }
                 $data->slug = $data->page_title;
                 $data->slug2 = '';
                 // "buddy quaid hack", should be an option in future versions
                 jimport('joomla.version');
                 $version = new JVersion();
                 if (version_compare($version->getShortVersion(), '1.6', '>=')) {
                     if ($this->_show_page_heading && $this->_page_title != '' && $this->_page_heading != '' && $this->_page_title == $this->_page_heading) {
                         $data->page_title = $this->_page_title;
                     } else {
                         if (JRequest::getInt('cb_filter_in_title', 1)) {
                             $data->slug2 = str_replace(' &raquo; ', '', $ordered_extra_title);
                             $data->page_title .= $ordered_extra_title;
                         }
                     }
                 } else {
                     if ($this->_show_page_heading && $this->_page_title != '' && !JRequest::getInt('cb_prefix_in_title', 1)) {
                         $data->page_title = $this->_page_title;
                     } else {
                         if (JRequest::getInt('cb_filter_in_title', 1)) {
                             $data->slug2 = str_replace(' &raquo; ', '', $ordered_extra_title);
                             $data->page_title .= $ordered_extra_title;
                         }
                     }
                 }
                 if ($this->frontend) {
                     $document = JFactory::getDocument();
                     $document->setTitle(html_entity_decode($data->page_title, ENT_QUOTES, 'UTF-8'));
                 }
                 $ids = array();
                 foreach ($data->labels as $reference_id => $label) {
                     $ids[] = $this->_db->Quote($reference_id);
                 }
                 $searchable_elements = contentbuilder::getListSearchableElements($this->_id);
                 $data->display_filter = count($searchable_elements) && $data->show_filter;
                 $data->linkable_elements = contentbuilder::getListLinkableElements($this->_id);
                 $data->labels = array();
                 $order_types = array();
                 if (count($ids)) {
                     $this->_db->setQuery("Select Distinct `id`,`label`, reference_id, `order_type` From #__contentbuilder_elements Where form_id = " . intval($this->_id) . " And reference_id In (" . implode(',', $ids) . ") And published = 1 And list_include = 1 Order By ordering");
                     $rows = $this->_db->loadAssocList();
                     $ids = array();
                     foreach ($rows as $row) {
                         // cleaned up, in desired order
                         $data->labels[$row['reference_id']] = $row['label'];
                         $ids[] = $row['reference_id'];
                         $order_types['col' . $row['reference_id']] = $row['order_type'];
                     }
                 }
                 $act_as_registration = array();
                 if ($data->act_as_registration && $data->registration_username_field && $data->registration_name_field && $data->registration_email_field && $data->registration_email_repeat_field && $data->registration_password_field && $data->registration_password_repeat_field) {
                     $act_as_registration[$data->registration_username_field] = 'registration_username_field';
                     $act_as_registration[$data->registration_name_field] = 'registration_name_field';
                     $act_as_registration[$data->registration_email_field] = 'registration_email_field';
                 }
                 $data->items = $data->form->getListRecords($ids, $this->getState('formsd_filter'), $searchable_elements, $this->getState('limitstart'), $this->getState('limit'), $this->getState('formsd_filter_order'), $order_types, $this->getState('formsd_filter_order_Dir') ? $this->getState('formsd_filter_order_Dir') : $data->initial_order_dir, 0, $data->published_only, $this->frontend ? $data->own_only_fe ? JFactory::getUser()->get('id', 0) : -1 : ($data->own_only ? JFactory::getUser()->get('id', 0) : -1), $this->getState('formsd_filter_state'), $this->getState('formsd_filter_publish'), $data->initial_sort_order == -1 ? -1 : 'col' . $data->initial_sort_order, $data->initial_sort_order2 == -1 ? -1 : 'col' . $data->initial_sort_order2, $data->initial_sort_order3 == -1 ? -1 : 'col' . $data->initial_sort_order3, $this->_menu_filter, $this->frontend ? $data->show_all_languages_fe : true, $this->getState('formsd_filter_language'), $act_as_registration, $data, $this->getState('article_category_filter'));
                 if ($data->items === null) {
                     $mainframe->setUserState($option . 'formsd_filter_order', '');
                     JError::raiseError(500, JText::_('Stale list setup detected. Please reload view.'));
                 }
                 $data->items = contentbuilder::applyItemWrappers($this->_id, $data->items, $data);
                 $this->_total = $data->form->getListRecordsTotal($ids, $this->getState('formsd_filter'), $searchable_elements);
                 $data->visible_cols = $ids;
                 $data->states = array();
                 $data->state_colors = array();
                 $data->state_titles = array();
                 $data->published_items = array();
                 $data->states = contentbuilder::getListStates($this->_id);
                 if ($data->list_state) {
                     $data->state_colors = contentbuilder::getStateColors($data->items, $this->_id);
                     $data->state_titles = contentbuilder::getStateTitles($data->items, $this->_id);
                 }
                 if ($data->list_publish) {
                     $data->published_items = contentbuilder::getRecordsPublishInfo($data->items, $data->type, $data->reference_id);
                 }
                 $data->lang_codes = array();
                 if ($data->list_language) {
                     $data->lang_codes = contentbuilder::getRecordsLanguage($data->items, $data->type, $data->reference_id);
                 }
                 $data->languages = contentbuilder::getLanguageCodes();
                 // Search for the {readmore} tag and split the text up accordingly.
                 $pattern = '#<hr\\s+id=("|\')system-readmore("|\')\\s*\\/*>#i';
                 $tagPos = preg_match($pattern, $data->intro_text);
                 $fulltext = '';
                 if ($tagPos == 0) {
                     $introtext = $data->intro_text;
                 } else {
                     list($introtext, $fulltext) = preg_split($pattern, $data->intro_text, 2);
                 }
                 $data->intro_text = $introtext . ($fulltext ? '<br/><br/>' . $fulltext : '');
             }
             return $data;
         }
     }
     return null;
 }