Ejemplo n.º 1
0
 function display()
 {
     contentbuilder::checkPermissions('listaccess', JText::_('COM_CONTENTBUILDER_PERMISSIONS_LISTACCESS_NOT_ALLOWED'), class_exists('cbFeMarker') ? '_fe' : '');
     JRequest::setVar('tmpl', JRequest::getWord('tmpl', null));
     JRequest::setVar('layout', JRequest::getWord('layout', null) == 'latest' ? null : JRequest::getWord('layout', null));
     JRequest::setVar('view', 'list');
     parent::display();
 }
 function onContentPrepare($context, &$article, &$params, $limitstart = 0)
 {
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.folder');
     if (!JFile::exists(JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'classes' . DS . 'contentbuilder.php')) {
         return true;
     }
     if (isset($article->id) && $article->id) {
         $frontend = true;
         if (JFactory::getApplication()->isAdmin()) {
             $frontend = false;
         }
         $db = JFactory::getDBO();
         $db->setQuery("Select form.`reference_id`,article.`record_id`,article.`form_id`,form.`type`,form.`published_only`,form.`own_only`,form.`own_only_fe` From #__contentbuilder_articles As article, #__contentbuilder_forms As form Where form.`published` = 1 And form.id = article.`form_id` And article.`article_id` = " . $article->id);
         $data = $db->loadAssoc();
         require_once JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'classes' . DS . 'contentbuilder.php';
         $form = contentbuilder::getForm($data['type'], $data['reference_id']);
         if (!$form || !$form->exists) {
             return true;
         }
         if ($form && !(JRequest::getVar('option', '') == 'com_contentbuilder' && JRequest::getVar('controller', '') == 'edit')) {
             JFactory::getLanguage()->load('com_contentbuilder');
             contentbuilder::setPermissions($data['form_id'], $data['record_id'], $frontend ? '_fe' : '');
             if (JRequest::getCmd('view') == 'article') {
                 contentbuilder::checkPermissions('view', JText::_('COM_CONTENTBUILDER_PERMISSIONS_VIEW_NOT_ALLOWED'), $frontend ? '_fe' : '');
             } else {
                 if ($frontend) {
                     if (!contentbuilder::authorizeFe('view')) {
                         $article->text = JText::_('COM_CONTENTBUILDER_PERMISSIONS_VIEW_NOT_ALLOWED');
                     }
                 } else {
                     if (!contentbuilder::authorize('view')) {
                         $article->text = JText::_('COM_CONTENTBUILDER_PERMISSIONS_VIEW_NOT_ALLOWED');
                     }
                 }
             }
         }
     }
     return true;
 }
Ejemplo n.º 3
0
 function copy()
 {
     $table = $this->getTable('form');
     $cids = JRequest::getVar('cid', array(), '', 'array');
     JArrayHelper::toInteger($cids);
     if (!count($cids)) {
         return;
     }
     $this->_db->setQuery(' Select * From #__contentbuilder_forms ' . '  Where id In ( ' . implode(',', $cids) . ')');
     $result = $this->_db->loadObjectList();
     foreach ($result as $obj) {
         $origId = $obj->id;
         unset($obj->id);
         $obj->name = 'Copy of ' . $obj->name;
         $obj->published = 0;
         $this->_db->insertObject('#__contentbuilder_forms', $obj);
         $insertId = $this->_db->insertid();
         // elements
         $this->_db->setQuery(' Select * From #__contentbuilder_elements ' . '  Where form_id = ' . $origId);
         $elements = $this->_db->loadObjectList();
         foreach ($elements as $element) {
             unset($element->id);
             $element->form_id = $insertId;
             $this->_db->insertObject('#__contentbuilder_elements', $element);
         }
         // list states
         $this->_db->setQuery(' Select * From #__contentbuilder_list_states ' . '  Where form_id = ' . $origId);
         $elements = $this->_db->loadObjectList();
         foreach ($elements as $element) {
             unset($element->id);
             $element->form_id = $insertId;
             $this->_db->insertObject('#__contentbuilder_list_states', $element);
         }
         contentbuilder::createBackendMenuItem($insertId, $obj->name, true);
     }
     $table->reorder();
 }
 function onContentPrepare($context, &$article, &$params, $limitstart = 0, $is_list = false, $form = null, $item = null)
 {
     $protect = false;
     $plugin = JPluginHelper::getPlugin('content', 'contentbuilder_download');
     jimport('joomla.html.parameter');
     $pluginParams = CBCompat::getParams($plugin->params);
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.folder');
     if (!JFile::exists(JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'classes' . DS . 'contentbuilder.php')) {
         return true;
     }
     $lang = JFactory::getLanguage();
     $lang->load('plg_content_contentbuilder_download', JPATH_ADMINISTRATOR);
     /*
      * As of Joomla! 1.6 there is just the text passed if the article data is not passed in article context.
      * (for instance with categories).
      * But we need the article id, so we use the article id flag from content generation.
      */
     if (is_object($article) && !isset($article->id) && !isset($article->cbrecord) && isset($article->text) && $article->text) {
         preg_match_all("/<!--\\(cbArticleId:(\\d{1,})\\)-->/si", $article->text, $matched_id);
         if (isset($matched_id[1]) && isset($matched_id[1][0])) {
             $article->id = intval($matched_id[1][0]);
         }
     }
     // if this content plugin has been called from within list context
     if ($is_list) {
         if (!trim($article->text)) {
             return true;
         }
         $article->cbrecord = $form;
         $article->cbrecord->items = array();
         $article->cbrecord->items[0] = $item;
         $article->cbrecord->record_id = $item->colRecord;
     }
     if (!JFolder::exists(JPATH_SITE . DS . 'media' . DS . 'contentbuilder')) {
         JFolder::create(JPATH_SITE . DS . 'media' . DS . 'contentbuilder');
     }
     if (!JFile::exists(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'index.html')) {
         JFile::write(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'index.html', $def = '');
     }
     if (!JFolder::exists(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins')) {
         JFolder::create(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins');
     }
     if (!JFile::exists(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins' . DS . 'index.html')) {
         JFile::write(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins' . DS . 'index.html', $def = '');
     }
     if (!JFolder::exists(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins' . DS . 'download')) {
         JFolder::create(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins' . DS . 'download');
     }
     if (!JFile::exists(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins' . DS . 'download' . DS . 'index.html')) {
         JFile::write(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins' . DS . 'image_scale' . DS . 'index.html', $def = '');
     }
     if (isset($article->id) || isset($article->cbrecord)) {
         $db = JFactory::getDBO();
         $matches = array();
         preg_match_all("/\\{CBDownload([^}]*)\\}/i", $article->text, $matches);
         if (isset($matches[0]) && is_array($matches[0]) && isset($matches[1]) && is_array($matches[1])) {
             $record = null;
             $default_title = '';
             $protect = 0;
             $form_id = 0;
             $record_id = 0;
             $type = '';
             $frontend = true;
             if (JFactory::getApplication()->isAdmin()) {
                 $frontend = false;
             }
             if (isset($article->id) && $article->id && !isset($article->cbrecord)) {
                 // try to obtain the record id if if this is just an article
                 $db->setQuery("Select form.`title_field`,form.`protect_upload_directory`,form.`reference_id`,article.`record_id`,article.`form_id`,form.`type`,form.`published_only`,form.`own_only`,form.`own_only_fe` From #__contentbuilder_articles As article, #__contentbuilder_forms As form Where form.`published` = 1 And form.id = article.`form_id` And article.`article_id` = " . $article->id);
                 $data = $db->loadAssoc();
                 require_once JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'classes' . DS . 'contentbuilder.php';
                 $form = contentbuilder::getForm($data['type'], $data['reference_id']);
                 if (!$form || !$form->exists) {
                     return true;
                 }
                 if ($form) {
                     $protect = $data['protect_upload_directory'];
                     $record = $form->getRecord($data['record_id'], $data['published_only'], $frontend ? $data['own_only_fe'] ? JFactory::getUser()->get('id', 0) : -1 : ($data['own_only'] ? JFactory::getUser()->get('id', 0) : -1), true);
                     $default_title = $data['title_field'];
                     $form_id = $data['form_id'];
                     $record_id = $data['record_id'];
                     $type = $data['type'];
                 }
             } else {
                 if (isset($article->cbrecord) && isset($article->cbrecord->id) && $article->cbrecord->id) {
                     $protect = $article->cbrecord->protect_upload_directory;
                     $record = $article->cbrecord->items;
                     $default_title = $article->cbrecord->title_field;
                     $form_id = $article->cbrecord->id;
                     $record_id = $article->cbrecord->record_id;
                     $type = $article->cbrecord->type;
                 }
             }
             if (!$is_list) {
                 contentbuilder::setPermissions($form_id, $record_id, $frontend ? '_fe' : '');
                 if ($frontend) {
                     if (!contentbuilder::authorizeFe('view')) {
                         if (JRequest::getVar('contentbuilder_download_file', '', 'GET', 'STRING', JREQUEST_ALLOWRAW)) {
                             ob_end_clean();
                             die('No Access');
                         } else {
                             return true;
                         }
                     }
                 } else {
                     if (!contentbuilder::authorize('view')) {
                         if (JRequest::getVar('contentbuilder_download_file', '', 'GET', 'STRING', JREQUEST_ALLOWRAW)) {
                             ob_end_clean();
                             die('No Access');
                         } else {
                             return true;
                         }
                     }
                 }
             }
             if (!trim($default_title)) {
                 $default_title = strtotime('now');
             }
             $i = 0;
             foreach ($matches[1] as $match) {
                 $out = '';
                 $field = $is_list ? $article->cbrecord->items[0]->recName : '';
                 $box_style = 'border-width:thin::border-color:#000000::border-style:dashed::padding:5px::';
                 $info_style = '';
                 $align = '';
                 $info = true;
                 $hide_filename = false;
                 $hide_mime = false;
                 $hide_size = false;
                 $hide_downloads = false;
                 $options = explode(';', trim($match));
                 foreach ($options as $option) {
                     $keyval = explode(':', trim($option), 2);
                     if (count($keyval) == 2) {
                         $value = trim($keyval[1]);
                         switch (strtolower(trim($keyval[0]))) {
                             case 'field':
                                 $field = $value;
                                 break;
                             case 'info-style':
                                 $info_style = $value;
                                 break;
                             case 'box-style':
                                 $box_style = $value;
                                 break;
                             case 'align':
                                 $align = $value;
                                 break;
                             case 'info':
                                 $info = $value == 'true' ? true : false;
                                 break;
                             case 'hide-filename':
                                 $hide_filename = $value == 'true' ? true : false;
                                 break;
                             case 'hide-mime':
                                 $hide_mime = $value == 'true' ? true : false;
                                 break;
                             case 'hide-size':
                                 $hide_size = $value == 'true' ? true : false;
                                 break;
                             case 'hide-downloads':
                                 $hide_downloads = $value == 'true' ? true : false;
                                 break;
                         }
                     }
                 }
                 $is_series = false;
                 if ($field && isset($record) && $record !== null && is_array($record)) {
                     foreach ($record as $item) {
                         if ($default_title == $item->recElementId) {
                             $default_title = $item->recValue;
                             break;
                         }
                     }
                     foreach ($record as $item) {
                         if ($item->recName == $field) {
                             $the_files = explode("\n", str_replace("\r", '', $item->recValue));
                             $the_files_size = count($the_files);
                             if ($the_files_size > 0) {
                                 $is_series = true;
                             }
                             for ($fcnt = 0; $fcnt < $the_files_size; $fcnt++) {
                                 $the_value = str_replace(array('{CBSite}', '{cbsite}'), JPATH_SITE, trim($the_files[$fcnt]));
                                 if ($the_value) {
                                     $exists = JFile::exists($the_value);
                                     if ($exists) {
                                         $phpversion = explode('-', phpversion());
                                         $phpversion = $phpversion[0];
                                         // because of mime_content_type deprecation
                                         if (version_compare($phpversion, '5.3', '<')) {
                                             if (function_exists('mime_content_type')) {
                                                 $mime = mime_content_type($the_value);
                                             } else {
                                                 // fallback if not even that one exists
                                                 $mime = $this->mime_content_type($the_value);
                                             }
                                         } else {
                                             if (function_exists('finfo_open')) {
                                                 $finfo = finfo_open(FILEINFO_MIME_TYPE);
                                                 $mime = finfo_file($finfo, $the_value);
                                                 finfo_close($finfo);
                                             } else {
                                                 $mime = $this->mime_content_type($the_value);
                                             }
                                         }
                                         if (JRequest::getVar('contentbuilder_download_file', '', 'GET', 'STRING', JREQUEST_ALLOWRAW) == sha1($field . $the_value)) {
                                             $download_name = basename(JFilterOutput::stringURLSafe($default_title) . '_' . $the_value);
                                             $file_id = md5($type . $item->recElementId . $the_value);
                                             if (!JFactory::getSession()->get('downloaded' . $type . $item->recElementId . $file_id, false, 'com_contentbuilder.plugin.download')) {
                                                 $db->setQuery("Select hits From #__contentbuilder_resource_access Where `type` = " . $db->Quote($type) . " And resource_id = '" . $file_id . "' And element_id = " . $db->Quote($item->recElementId));
                                                 if ($db->loadResult() === null) {
                                                     $db->setQuery("Insert Into #__contentbuilder_resource_access (`type`, form_id, element_id, resource_id, hits) values (" . $db->Quote($type) . "," . intval($form_id) . ", " . $db->Quote($item->recElementId) . ", '" . $file_id . "',1)");
                                                 } else {
                                                     $db->setQuery("Update #__contentbuilder_resource_access Set `type` = " . $db->Quote($type) . ", resource_id = '" . $file_id . "', form_id = " . intval($form_id) . ", element_id = " . $db->Quote($item->recElementId) . ", hits = hits + 1 Where `type` = " . $db->Quote($type) . " And resource_id = '" . $file_id . "' And element_id = " . $db->Quote($item->recElementId));
                                                 }
                                                 $db->query();
                                             }
                                             JFactory::getSession()->set('downloaded' . $type . $item->recElementId . $file_id, true, 'com_contentbuilder.plugin.download');
                                             // clean up before displaying
                                             @ob_end_clean();
                                             header('Content-Type: application/octet-stream; name="' . $download_name . '"');
                                             header('Content-Disposition: inline; filename="' . $download_name . '"');
                                             header('Content-Length: ' . @filesize($the_value));
                                             // NOTE: if running IIS and CGI, raise the CGI timeout to serve large files
                                             @$this->readfile_chunked($the_value);
                                             exit;
                                         }
                                         $info_style_ = $info_style;
                                         $box_style_ = $box_style;
                                         $info_ = $info;
                                         $align_ = $align;
                                         $download_name = basename(JFilterOutput::stringURLSafe($default_title) . '_' . $the_value);
                                         $file_id = md5($type . $item->recElementId . $the_value);
                                         $db->setQuery("Select hits From #__contentbuilder_resource_access Where resource_id = '" . $file_id . "' And `type` = " . intval($type) . " And element_id = " . $db->Quote($item->recElementId));
                                         $hits = $db->loadResult();
                                         if (!$hits) {
                                             $hits = 0;
                                         }
                                         $size = @number_format(filesize($the_value) / (1024 * 1024), 2) . ' MB';
                                         if (!floatval($size)) {
                                             $size = @number_format(filesize($the_value) / 1024, 2) . ' kb';
                                         }
                                         $hide_filename_ = $hide_filename;
                                         $hide_mime_ = $hide_mime;
                                         $hide_size_ = $hide_size;
                                         $hide_downloads_ = $hide_downloads;
                                         $url = JURI::getInstance()->toString();
                                         $open_ = JRoute::_($url . (strstr($url, '?') !== false ? '&' : '?') . 'contentbuilder_download_file=' . sha1($field . $the_value));
                                         $out .= '<div style="' . ($align_ ? 'float: ' . $align_ . ';' : '') . str_replace('::', ';', $box_style_) . '">
                                                     <a href="' . $open_ . '">' . JText::_('COM_CONTENTBUILDER_PLUGIN_DOWNLOAD_DOWNLOAD') . '</a>' . ($info_ ? '<div style="' . str_replace('::', ';', $info_style_) . '">
                                                                 ' . ($hide_filename_ ? '' : '<span class="cbPluginDownloadFilename">' . JText::_('COM_CONTENTBUILDER_PLUGIN_DOWNLOAD_FILENAME') . ':</span> ' . $download_name . '<br/>') . '
                                                                 ' . ($hide_mime_ ? '' : '<span class="cbPluginDownloadMime">' . JText::_('COM_CONTENTBUILDER_PLUGIN_DOWNLOAD_MIME') . ':</span> ' . $mime . '<br/>') . '
                                                                 ' . ($hide_size_ ? '' : '<span ' . ($hide_size_ ? ' style="display:none;" ' : '') . 'class="cbPluginDownloadSize">' . JText::_('COM_CONTENTBUILDER_PLUGIN_DOWNLOAD_SIZE') . ':</span> ' . $size . '<br/>') . '
                                                                 ' . ($hide_downloads_ ? '' : '<span ' . ($hide_downloads_ ? ' style="display:none;" ' : '') . 'class="cbPluginDownloadDownloads">' . JText::_('COM_CONTENTBUILDER_PLUGIN_DOWNLOAD_DOWNLOADS') . ':</span> ' . $hits . '<br/>') . '
                                                              </div>' : '') . '</div>';
                                         if ($is_series && $align_ && (strtolower($align_) == 'left' || strtolower($align_) == 'right')) {
                                             $out .= '<div style="float:' . strtolower($align_) . ';width: 5px;">&nbsp;</div>';
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 if ($is_series && $align && (strtolower($align) == 'left' || strtolower($align) == 'right')) {
                     $out .= '<div style="clear:' . strtolower($align) . ';"></div>';
                 }
                 $article->text = str_replace($matches[0][$i], $out, $article->text);
                 $i++;
             }
         }
     }
     return true;
 }
Ejemplo n.º 5
0
 /**
  * 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;
 }
Ejemplo n.º 6
0
    if (!(JRequest::getCmd('controller', '') == 'elementoptions' || JRequest::getCmd('controller', '') == 'storages' || JRequest::getCmd('controller', '') == 'forms' || JRequest::getCmd('controller', '') == 'users') && !JFactory::getUser()->authorise('contentbuilder.admin', 'com_contentbuilder')) {
        return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));
    }
    $db = JFactory::getDBO();
    $db->setQuery("Select id From `#__menu` Where `alias` = 'root'");
    if (!$db->loadResult()) {
        $db->setQuery("INSERT INTO `#__menu` VALUES(1, '', 'Menu_Item_Root', 'root', '', '', '', '', 1, 0, 0, 0, 0, 0, '0000-00-00 00:00:00', 0, 0, '', 0, '', 0, 67, 0, '*', 0)");
        $db->query();
    }
}
require_once JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'classes' . DS . 'contentbuilder.php';
$db = JFactory::getDBO();
$db->setQuery("Select `id`,`name` From #__contentbuilder_forms Where display_in In (1,2) And published = 1");
$forms = $db->loadAssocList();
foreach ($forms as $form) {
    contentbuilder::createBackendMenuItem($form['id'], $form['name'], true);
}
// Require the base controller
require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'controller.php';
if (version_compare($version->getShortVersion(), '1.6', '>=')) {
    JSubMenuHelper::addEntry(JText::_('COM_CONTENTBUILDER_STORAGES'), 'index.php?option=com_contentbuilder&controller=storages', JRequest::getVar('controller', '') == 'storages');
    JSubMenuHelper::addEntry(JText::_('COM_CONTENTBUILDER_LIST'), 'index.php?option=com_contentbuilder&controller=forms', JRequest::getVar('controller', '') == 'forms');
    JSubMenuHelper::addEntry('Try BreezingForms!', 'index.php?option=com_contentbuilder&view=contentbuilder&market=true', false);
    JSubMenuHelper::addEntry(JText::_('COM_CONTENTBUILDER_ABOUT'), 'index.php?option=com_contentbuilder&view=contentbuilder', JRequest::getVar('view', '') == 'contentbuilder');
}
// Require specific controller if requested
$controller = trim(JRequest::getWord('controller'));
if ($controller) {
    $path = JPATH_COMPONENT_ADMINISTRATOR . DS . 'controllers' . DS . $controller . '.php';
    if (file_exists($path)) {
        require_once $path;
Ejemplo n.º 7
0
 /**
  * Gets the currencies
  * @return array List of currencies
  */
 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_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;
             $data->record_id = $this->_record_id;
             if ($data->type && $data->reference_id) {
                 $data->form = contentbuilder::getForm($data->type, $data->reference_id);
                 $data->labels = $data->form->getElementLabels();
                 $ids = array();
                 foreach ($data->labels as $reference_id => $label) {
                     $ids[] = $this->_db->Quote($reference_id);
                 }
                 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'];
                     }
                 }
                 if ($this->_latest) {
                     $rec = $data->form->getListRecords($ids, '', array(), 0, 1, '', array(), 'desc', 0, false, JFactory::getUser()->get('id', 0), 0, -1, -1, -1, -1, array(), true, null);
                     if (count($rec) > 0) {
                         $rec = $rec[0];
                         $rec2 = $data->form->getRecord($rec->colRecord, false, -1, true);
                         $data->record_id = $rec->colRecord;
                         JRequest::setVar('record_id', $data->record_id);
                         $this->_record_id = $data->record_id;
                     } else {
                         JRequest::setVar('cbIsNew', 1);
                         contentbuilder::setPermissions(JRequest::getInt('id', 0), 0, $this->frontend ? '_fe' : '');
                         $auth = $this->frontend ? contentbuilder::authorizeFe('new') : contentbuilder::authorize('new');
                         if ($auth) {
                             JFactory::getApplication()->redirect(JRoute::_('index.php?option=com_contentbuilder&controller=edit&latest=1&backtolist=' . JRequest::getInt('backtolist', 0) . '&id=' . $this->_id . '&record_id=&limitstart=' . JRequest::getInt('limitstart', 0) . '&filter_order=' . JRequest::getVar('filter_order', ''), false));
                         } else {
                             JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_ADD_ENTRY_FIRST'));
                             JFactory::getApplication()->redirect('index.php', false);
                         }
                     }
                 }
                 $data->show_page_heading = $this->_show_page_heading;
                 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();
                     }
                 }
                 if ($this->frontend) {
                     $document = JFactory::getDocument();
                     $document->setTitle($data->page_title);
                 }
                 $data->show_back_button = $this->_show_back_button;
                 if (isset($rec2) && count($rec2)) {
                     $data->items = $rec2;
                 } else {
                     $data->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);
                 }
                 if (count($data->items)) {
                     $user = null;
                     if ($data->act_as_registration) {
                         $meta = $data->form->getRecordMetadata($this->_record_id);
                         $this->_db->setQuery("Select * From #__users Where id = " . $meta->created_id);
                         $user = $this->_db->loadObject();
                     }
                     $label = '';
                     foreach ($data->items as $rec) {
                         if ($rec->recElementId == $data->title_field) {
                             if ($data->act_as_registration && $user !== null) {
                                 if ($data->registration_name_field == $rec->recElementId) {
                                     $rec->recValue = $user->name;
                                 } else {
                                     if ($data->registration_username_field == $rec->recElementId) {
                                         $item->recValue = $user->username;
                                     } else {
                                         if ($data->registration_email_field == $item->recElementId) {
                                             $rec->recValue = $user->email;
                                         } else {
                                             if ($data->registration_email_repeat_field == $rec->recElementId) {
                                                 $rec->recValue = $user->email;
                                             }
                                         }
                                     }
                                 }
                             }
                             $label = cbinternal($rec->recValue);
                             break;
                         }
                     }
                     $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_FROM') . ' ' . 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->page_title .= $ordered_extra_title;
                     // trying first element if no title field given
                     if (!$label) {
                         $label = cbinternal($data->items[0]->recValue);
                     }
                     // "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 {
                             $data->page_title .= $label ? (!$data->page_title ? '' : (!$ordered_extra_title ? ': ' : ' &raquo; ')) . $label : '';
                         }
                         if ($this->frontend) {
                             $document = JFactory::getDocument();
                             $document->setTitle(html_entity_decode($data->page_title, ENT_QUOTES, 'UTF-8'));
                         }
                     } else {
                         if ($this->_show_page_heading && $this->_page_title != '' && !JRequest::getInt('cb_prefix_in_title', 1)) {
                             $data->page_title = $this->_page_title;
                         } else {
                             $data->page_title .= $label ? (!$data->page_title ? '' : (!$ordered_extra_title ? ': ' : ' &raquo; ')) . $label : '';
                         }
                         if ($this->frontend) {
                             $document = JFactory::getDocument();
                             $document->setTitle(html_entity_decode($data->page_title, ENT_QUOTES, 'UTF-8'));
                         }
                     }
                     $data->template = contentbuilder::getTemplate($this->_id, $this->_record_id, $data->items, $ids);
                     $metadata = $data->form->getRecordMetadata($this->_record_id);
                     if ($metadata instanceof stdClass && $data->metadata) {
                         $data->created = $metadata->created ? $metadata->created : '';
                         $data->created_by = $metadata->created_by ? $metadata->created_by : '';
                         $data->modified = $metadata->modified ? $metadata->modified : '';
                         $data->modified_by = $metadata->modified_by ? $metadata->modified_by : '';
                         $data->metadesc = $metadata->metadesc;
                         $data->metakey = $metadata->metakey;
                         $data->author = $metadata->author;
                         $data->rights = $metadata->rights;
                         $data->robots = $metadata->robots;
                         $data->xreference = $metadata->xreference;
                     } else {
                         $data->created = '';
                         $data->created_by = '';
                         $data->modified = '';
                         $data->modified_by = '';
                         $data->metadesc = '';
                         $data->metakey = '';
                         $data->author = '';
                         $data->rights = '';
                         $data->robots = '';
                         $data->xreference = '';
                     }
                 } else {
                     JError::raiseError(404, JText::_('COM_CONTENTBUILDER_RECORD_NOT_FOUND'));
                 }
             }
             return $data;
         }
     }
     return null;
 }
 function onAfterInitialize()
 {
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.folder');
     if (!JFile::exists(JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'classes' . DS . 'contentbuilder.php')) {
         return;
     }
     $app = JFactory::getApplication();
     if (!$app->isSite()) {
         return;
     }
     // synch the records if there are any changes
     if ($app->isSite()) {
         $db = JFactory::getDBO();
         $user = JFactory::getUser();
         $db->setQuery("\n                    Update\n                        #__contentbuilder_articles As articles,\n                        #__content As content, \n                        #__contentbuilder_forms As forms,\n                        #__contentbuilder_registered_users As cbusers,\n                        #__users As users\n                    Set \n                        content.state = 0\n                    Where \n                        articles.article_id = content.id\n                    And\n                        content.state = 1\n                    And\n                        articles.form_id = forms.id\n                    And\n                        forms.act_as_registration = 1\n                    And\n                        forms.id = cbusers.form_id\n                    And\n                        content.created_by = cbusers.user_id\n                    And\n                      (\n                        (\n                            users.id = cbusers.user_id\n                          And\n                            users.block = 1\n                        )\n                      )\n                    ");
         $db->query();
         $db->setQuery("\n                    Update \n                        #__contentbuilder_articles As articles,\n                        #__content As content, \n                        #__contentbuilder_forms As forms,\n                        #__contentbuilder_records As records,\n                        #__contentbuilder_registered_users As cbusers,\n                        #__users As users\n                    Set \n                        content.state = forms.auto_publish\n                    Where \n                        articles.article_id = content.id\n                    And\n                        content.state = 0\n                    And\n                        articles.form_id = forms.id\n                    And\n                        forms.act_as_registration = 1\n                    And\n                        forms.id = cbusers.form_id\n                    And\n                        content.created_by = cbusers.user_id\n                    And\n                        users.id = cbusers.user_id\n                    And\n                        records.record_id = cbusers.record_id\n                    And\n                        records.`type` = forms.`type`\n                    And\n                        users.block = 0\n                    ");
         $db->query();
         $pluginParams = CBCompat::getPluginParams($this, 'system', 'contentbuilder_system');
         require_once JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'classes' . DS . 'contentbuilder.php';
         $db->setQuery("\n                Select \n                    form.id As form_id,\n                    form.act_as_registration,\n                    form.default_category,\n                    form.registration_name_field, \n                    form.registration_username_field, \n                    form.registration_email_field, \n                    form.registration_email_repeat_field, \n                    form.`last_update`,\n                    article.`article_id`,\n                    form.`title_field`,\n                    form.`create_articles`,\n                    form.`name`,\n                    form.`use_view_name_as_title`,\n                    form.`protect_upload_directory`,\n                    form.`reference_id`,\n                    records.`record_id`,\n                    form.`type`,\n                    form.`published_only`,\n                    form.`own_only`,\n                    form.`own_only_fe`,\n                    records.`last_update` As record_last_update,\n                    article.`last_update` As article_last_update\n                From\n                    #__contentbuilder_records As records\n                    Left Join #__contentbuilder_forms As form On ( form.`type` = records.`type` And form.reference_id = records.reference_id )\n                    Left Join #__contentbuilder_articles As article On ( form.`type` = records.`type` And form.reference_id = records.reference_id And article.form_id = form.id And article.record_id = records.record_id )\n                    Left Join #__content As content On ( form.`type` = records.`type` And form.reference_id = records.reference_id And article.article_id = content.id And article.form_id = form.id And article.record_id = records.record_id )\n                Where \n                    form.`published` = 1\n                And\n                    form.create_articles = 1\n                And\n                    form.`type` = records.`type`\n                And \n                    form.reference_id = records.reference_id\n                And\n                   (\n                     (\n                        article.form_id = form.id \n                      And \n                        article.record_id = records.record_id\n                      And \n                        article.article_id = content.id \n                      And \n                        ( content.state = 1 Or content.state = 0 )\n                      And\n                      (\n                        form.`last_update` > article.`last_update`   \n                       Or\n                        records.`last_update` > article.`last_update`\n                      )\n                     )\n                     Or\n                     (\n                        form.id Is Not Null And records.id Is Not Null And content.id Is Null And article.id Is Null\n                     )\n                   )\n                Limit " . intval($pluginParams->def('limit_per_turn', 50)));
         $list = $db->loadAssocList();
         if (isset($list[0])) {
             $lang = JFactory::getLanguage();
             $lang->load('com_contentbuilder', JPATH_ADMINISTRATOR);
         }
         $jdate = JFactory::getDate();
         $now = CBCompat::toSql($jdate);
         foreach ($list as $data) {
             if (is_array($data)) {
                 $form = contentbuilder::getForm($data['type'], $data['reference_id']);
                 if (!$form || !$form->exists) {
                     return;
                 }
                 // creating the article
                 if ($data['create_articles']) {
                     $data['labels'] = $form->getElementLabels();
                     $ids = array();
                     foreach ($data['labels'] as $reference_id => $label) {
                         $ids[] = $db->Quote($reference_id);
                     }
                     if (count($ids)) {
                         $db->setQuery("Select Distinct `label`, reference_id From #__contentbuilder_elements Where form_id = " . intval($data['form_id']) . " And reference_id In (" . implode(',', $ids) . ") And published = 1 Order By ordering");
                         $rows = $db->loadAssocList();
                         $ids = array();
                         foreach ($rows as $row) {
                             $ids[] = $row['reference_id'];
                         }
                     }
                     $data['items'] = $form->getRecord($data['record_id'], false, -1, true);
                     $article_id = contentbuilder::createArticle($data['form_id'], $data['record_id'], $data['items'], $ids, $data['title_field'], $form->getRecordMetadata($data['record_id']), array(), false, 1, $data['default_category']);
                     if ($article_id) {
                         $db->setQuery("Update #__contentbuilder_articles Set `last_update`=" . $db->Quote($now) . " Where article_id = " . $db->Quote($article_id) . " And record_id = " . $db->Quote($data['record_id']) . " And form_id = " . $db->Quote($data['form_id']));
                         $db->query();
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 9
0
         if (JFile::exists(JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'classes' . DS . 'contentbuilder.php')) {
             require_once JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'classes' . DS . 'contentbuilder.php';
             $cbForm = contentbuilder::getForm('com_breezingforms', $formId);
             $db = JFactory::getDBO();
             $db->setQuery("Select id From #__contentbuilder_forms Where `type` = 'com_breezingforms' And `reference_id` = " . intval($formId));
             jimport('joomla.version');
             $version = new JVersion();
             if (version_compare($version->getShortVersion(), '3.0', '>=')) {
                 $cbForms = $db->loadColumn();
             } else {
                 $cbForms = $db->loadResultArray();
             }
             if (is_object($cbForm) && count($cbForms)) {
                 require_once JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'tables' . DS . 'elements.php';
                 foreach ($cbForms as $dataId) {
                     contentbuilder::synchElements($dataId, $cbForm);
                     $elements_table = new TableElements($db);
                     $elements_table->reorder('form_id=' . $dataId);
                 }
             }
         }
         ob_end_clean();
         echo $formId;
         exit;
         // CONTENTBUILDER END
     }
     exit;
     break;
 case 'save':
     $formId = JRequest::getInt('form', 0);
     $fOptions = $quickMode->getFormOptions($formId);
Ejemplo n.º 10
0
 function __construct()
 {
     parent::__construct();
     contentbuilder::setPermissions(JRequest::getInt('id', 0), 0, class_exists('cbFeMarker') ? '_fe' : '');
 }
Ejemplo n.º 11
0
 /**
  * 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;
 }
Ejemplo n.º 12
0
 function __construct($config)
 {
     parent::__construct($config);
     $this->frontend = JFactory::getApplication()->isSite();
     $mainframe = JFactory::getApplication();
     $option = 'com_contentbuilder';
     $plugin = JRequest::getVar('plugin', '');
     $verification_name = JRequest::getVar('verification_name', '');
     $verification_id = JRequest::getVar('verification_id', '');
     $setup = '';
     $user_id = 0;
     if (!$verification_id) {
         $user_id = JFactory::getUser()->get('id', 0);
         $setup = JFactory::getSession()->get($plugin . $verification_name, '', 'com_contentbuilder.verify.' . $plugin . $verification_name);
     } else {
         $this->_db->setQuery("Select `setup`,`user_id` From #__contentbuilder_verifications Where `verification_hash` = " . $this->_db->Quote($verification_id));
         $setup = $this->_db->loadAssoc();
         if (is_array($setup)) {
             $user_id = $setup['user_id'];
             $setup = $setup['setup'];
         }
     }
     $out = array();
     if ($setup) {
         parse_str($setup, $out);
     }
     if (isset($out['plugin']) && $out['plugin'] && isset($out['verification_name']) && $out['verification_name'] && isset($out['verify_view']) && $out['verify_view']) {
         // alright
     } else {
         JFactory::getApplication()->redirect('index.php', 'Spoofed data or invalid verification id', 'error');
     }
     if (isset($out['plugin_options'])) {
         $options = base64_decode($out['plugin_options']);
         parse_str($options, $opts);
         $out['plugin_options'] = $opts;
         if (!count($out['plugin_options'])) {
             $out['plugin_options'] = array();
         }
     } else {
         $out['plugin_options'] = array();
     }
     $_now = JFactory::getDate();
     //$this->_db->setQuery("Select count(id) From #__contentbuilder_verifications Where Timestampdiff(Second, `start_date`, '".strtotime($_now->toMySQL())."') < 1 And ip = " . $this->_db->Quote($_SERVER['REMOTE_ADDR']));
     //$ver = $this->_db->loadResult();
     //if($ver >= 5){
     //    $this->_db->setQuery("Delete From #__contentbuilder_verifications Where `verification_date` = '0000-00-00 00:00:00' And ip = " . $this->_db->Quote($_SERVER['REMOTE_ADDR']));
     //    $this->_db->query();
     //    JError::raiseError(500, 'Penetration Denied');
     //}
     //$this->_db->setQuery("Delete From #__contentbuilder_verifications Where Timestampdiff(Second, `start_date`, '".strtotime($_now->toMySQL())."') > 86400 And `verification_date` = '0000-00-00 00:00:00'");
     //$this->_db->query();
     $rec = null;
     $redirect_view = '';
     if (isset($out['require_view']) && is_numeric($out['require_view']) && intval($out['require_view']) > 0) {
         if (JFactory::getSession()->get('cb_last_record_user_id', 0, 'com_contentbuilder')) {
             $user_id = JFactory::getSession()->get('cb_last_record_user_id', 0, 'com_contentbuilder');
             JFactory::getSession()->clear('cb_last_record_user_id', 'com_contentbuilder');
         }
         $id = intval($out['require_view']);
         $this->_db->setQuery("Select `type`, `reference_id`, `show_all_languages_fe` From #__contentbuilder_forms Where published = 1 And id = " . $id);
         $formsettings = $this->_db->loadAssoc();
         if (!is_array($formsettings)) {
             JError::raiseError(500, 'Verification Setup failed. Reason: View id ' . $out['require_view'] . ' has been requested but is not available (not existent or unpublished). Please update your content template or publish the view.');
         }
         $form = contentbuilder::getForm($formsettings['type'], $formsettings['reference_id']);
         $labels = $form->getElementLabels();
         $ids = array();
         foreach ($labels as $reference_id => $label) {
             $ids[] = $reference_id;
         }
         if (intval($user_id) == 0) {
             JFactory::getApplication()->redirect('index.php?option=com_contentbuilder&lang=' . JRequest::getCmd('lang', '') . '&return=' . base64_encode(JURI::getInstance()->toString()) . '&controller=edit&record_id=&id=' . $id . '&rand=' . rand(0, getrandmax()));
         }
         $rec = $form->getListRecords($ids, '', array(), 0, 1, '', array(), 'desc', 0, false, $user_id, 0, -1, -1, -1, -1, array(), true, null);
         if (count($rec) > 0) {
             $rec = $rec[0];
             $rec = $form->getRecord($rec->colRecord, false, -1, true);
         }
         if (!$form->getListRecordsTotal($ids)) {
             JFactory::getApplication()->redirect('index.php?option=com_contentbuilder&lang=' . JRequest::getCmd('lang', '') . '&return=' . base64_encode(JURI::getInstance()->toString()) . '&controller=edit&record_id=&id=' . $id . '&rand=' . rand(0, getrandmax()));
         }
     }
     // clearing session after possible required view to make re-visits possible
     JFactory::getSession()->clear($plugin . $verification_name, 'com_contentbuilder.verify.' . $plugin . $verification_name);
     $verification_data = '';
     if (is_array($rec) && count($rec)) {
         foreach ($rec as $value) {
             $verification_data .= urlencode(str_replace(array("\r", "\n"), '', $value->recTitle)) . "=" . urlencode(str_replace(array("\r", "\n"), '', $value->recValue)) . "&";
         }
         $verification_data = rtrim($verification_data, '&');
     }
     if (!JRequest::getBool('verify', 0) && !JRequest::getVar('token', '')) {
         jimport('joomla.version');
         $version = new JVersion();
         if (version_compare($version->getShortVersion(), '3.0', '>=')) {
             $___now = $_now->toSql();
         } else {
             $___now = $_now->toMySQL();
         }
         $verification_id = md5(uniqid(null, true) . mt_rand(0, mt_getrandmax()) . $user_id);
         $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=normal&' . $verification_data) . ",\n                    " . $user_id . ",\n                    " . $this->_db->Quote($plugin) . ",\n                    " . $this->_db->Quote($_SERVER['REMOTE_ADDR']) . ",\n                    " . $this->_db->Quote($setup) . ",\n                    " . intval($out['client']) . "\n                    )\n            ");
         $this->_db->query();
     }
     /*
     if(intval($out['client']) && !JFactory::getApplication()->isAdmin()){
        parse_str(JURI::getInstance()->getQuery(), $data1);
        $this_page = JURI::getInstance()->base() . 'administrator/index.php?'.http_build_query($data1, '', '&');
             }else{
        parse_str(JURI::getInstance()->getQuery(), $data1);
        $urlex = explode('?', JURI::getInstance()->toString());
        $this_page = $urlex[0] . '?' . http_build_query($data1, '', '&');
             }
     */
     if (intval($out['client']) && !JFactory::getApplication()->isAdmin()) {
         $this_page = JURI::getInstance()->base() . 'administrator/index.php?' . JURI::getInstance()->getQuery();
     } else {
         $this_page = JURI::getInstance()->toString();
     }
     JPluginHelper::importPlugin('contentbuilder_verify', $plugin);
     $dispatcher = JDispatcher::getInstance();
     $setup_result = $dispatcher->trigger('onSetup', array($this_page, $out));
     if (!implode('', $setup_result)) {
         if (!JRequest::getBool('verify', 0)) {
             if (JFactory::getApplication()->isAdmin()) {
                 $local = explode('/', JURI::getInstance()->base());
                 unset($local[count($local) - 1]);
                 unset($local[count($local) - 1]);
                 parse_str(JURI::getInstance()->getQuery(), $data);
                 $this_page = implode('/', $local) . '/index.php?' . http_build_query($data, '', '&') . '&verify=1&verification_id=' . $verification_id;
             } else {
                 parse_str(JURI::getInstance()->getQuery(), $data);
                 $urlex = explode('?', JURI::getInstance()->toString());
                 $this_page = $urlex[0] . '?' . http_build_query($data, '', '&') . '&verify=1&verification_id=' . $verification_id;
             }
             $forward_result = $dispatcher->trigger('onForward', array($this_page, $out));
             $forward = implode('', $forward_result);
             if ($forward) {
                 JFactory::getApplication()->redirect($forward);
             }
         } else {
             if ($verification_id) {
                 $msg = '';
                 $verify_result = $dispatcher->trigger('onVerify', array($this_page, $out));
                 if (count($verify_result)) {
                     if ($verify_result[0] === false) {
                         $msg = JText::_('COM_CONTENTBUILDER_VERIFICATION_FAILED');
                     } else {
                         if (isset($verify_result[0]['msg']) && $verify_result[0]['msg']) {
                             $msg = $verify_result[0]['msg'];
                         } else {
                             if (isset($out['verification_msg']) && $out['verification_msg']) {
                                 $msg = urldecode($out['verification_msg']);
                             } else {
                                 $msg = JText::_('COM_CONTENTBUILDER_VERIFICATION_SUCCESS');
                             }
                         }
                         if (!$out['client'] && (!isset($out['return-site']) || !$out['return-site']) || $out['client'] && (!isset($out['return-admin']) || !$out['return-admin'])) {
                             if (intval($out['client']) && !JFactory::getApplication()->isAdmin()) {
                                 $redirect_view = JURI::getInstance()->base() . 'administrator/index.php?option=com_contentbuilder&controller=list&lang=' . JRequest::getCmd('lang', '') . '&id=' . $out['verify_view'];
                             } else {
                                 $redirect_view = 'index.php?option=com_contentbuilder&controller=list&lang=' . JRequest::getCmd('lang', '') . '&id=' . $out['verify_view'];
                             }
                         }
                         $this->_db->setQuery("Select id From #__contentbuilder_users Where userid = " . $this->_db->Quote($user_id) . " And form_id = " . intval($out['verify_view']));
                         $usertableid = $this->_db->loadResult();
                         $levels = explode(',', $out['verify_levels']);
                         jimport('joomla.version');
                         $version = new JVersion();
                         if (version_compare($version->getShortVersion(), '3.0', '>=')) {
                             $___now = $_now->toSql();
                         } else {
                             $___now = $_now->toMySQL();
                         }
                         if ($usertableid) {
                             $this->_db->setQuery("Update #__contentbuilder_users\n                                Set\n                                " . (in_array('view', $levels) ? ' verified_view=1, verification_date_view=' . $this->_db->Quote($___now) . ", " : '') . "\n                                " . (in_array('new', $levels) ? ' verified_new=1, verification_date_new=' . $this->_db->Quote($___now) . ", " : '') . "\n                                " . (in_array('edit', $levels) ? ' verified_edit=1, verification_date_edit=' . $this->_db->Quote($___now) . ", " : '') . "\n                                published = 1\n                                Where id = {$usertableid}\n                                ");
                             $this->_db->query();
                         } else {
                             $this->_db->setQuery("\n                                Insert Into #__contentbuilder_users\n                                (\n                                " . (in_array('view', $levels) ? 'verified_view, verification_date_view,' : '') . "\n                                " . (in_array('new', $levels) ? 'verified_new, verification_date_new,' : '') . "\n                                " . (in_array('edit', $levels) ? 'verified_edit, verification_date_edit,' : '') . "\n                                published,\n                                userid,\n                                form_id\n                                )\n                                Values\n                                (\n                                " . (in_array('view', $levels) ? '1, ' . $this->_db->Quote($___now) . ',' : '') . "\n                                " . (in_array('new', $levels) ? '1, ' . $this->_db->Quote($___now) . ',' : '') . "\n                                " . (in_array('edit', $levels) ? '1, ' . $this->_db->Quote($___now) . ',' : '') . "\n                                1,\n                                " . $this->_db->Quote($user_id) . ",\n                                " . intval($out['verify_view']) . "\n                                )\n                                ");
                             $this->_db->query();
                         }
                         $verification_data = ($verification_data ? '&' : '') . '';
                         if (isset($verify_result[0]['data']) && is_array($verify_result[0]['data']) && count($verify_result[0]['data'])) {
                             foreach ($verify_result[0]['data'] as $key => $value) {
                                 $verification_data .= urlencode(str_replace(array("\r", "\n"), '', $key)) . "=" . urlencode(str_replace(array("\r", "\n"), '', $value)) . "&";
                             }
                             $verification_data = rtrim($verification_data, '&');
                         }
                         $this->_db->setQuery("\n                                Update #__contentbuilder_verifications\n                                Set\n                                `verification_hash` = '',\n                                `is_test` = " . (isset($verify_result[0]['is_test']) ? intval(isset($verify_result[0]['is_test'])) : 0) . ",\n                                `verification_date` = " . $this->_db->Quote($___now) . " \n                                " . ($verification_data ? ',verification_data = concat(verification_data, ' . $this->_db->Quote($verification_data) . ') ' : '') . "\n                                Where\n                                verification_hash = " . $this->_db->Quote($verification_id) . "\n                                And\n                                verification_hash <> ''\n                                And\n                                `verification_date` = '0000-00-00 00:00:00'\n                                \n                            ");
                         $this->_db->query();
                         // token check if given
                         if (JRequest::getVar('token', '')) {
                             jimport('joomla.version');
                             $version = new JVersion();
                             if (version_compare($version->getShortVersion(), '1.6', '>=')) {
                                 $this->activate(JRequest::getVar('token', ''));
                             } else {
                                 $this->activate15(JRequest::getVar('token', ''));
                             }
                         }
                         // exit if requested
                         if (count($verify_result) && isset($verify_result[0]['exit']) && $verify_result[0]['exit']) {
                             @ob_end_clean();
                             if (isset($verify_result[0]['header']) && $verify_result[0]['header']) {
                                 header($verify_result[0]['header']);
                             }
                             exit;
                         }
                     }
                 }
             } else {
                 $msg = JText::_('COM_CONTENTBUILDER_VERIFICATION_NOT_EXECUTED');
             }
             if (!$out['client']) {
                 JFactory::getApplication()->redirect($redirect_view ? $redirect_view : (!$out['client'] && isset($out['return-site']) && $out['return-site'] ? base64_decode($out['return-site']) : 'index.php'), $msg);
             } else {
                 JFactory::getApplication()->redirect($redirect_view ? $redirect_view : ($out['client'] && isset($out['return-admin']) && $out['return-admin'] ? base64_decode($out['return-admin']) : 'index.php'), $msg);
             }
         }
     } else {
         JError::raiseError(500, 'Verification Setup failed. Reason: ' . implode('', $setup_result));
     }
 }
Ejemplo n.º 13
0
 function display()
 {
     if (JRequest::getCmd('record_id', '')) {
         contentbuilder::checkPermissions('edit', JText::_('COM_CONTENTBUILDER_PERMISSIONS_EDIT_NOT_ALLOWED'), class_exists('cbFeMarker') ? '_fe' : '');
     } else {
         contentbuilder::checkPermissions('new', JText::_('COM_CONTENTBUILDER_PERMISSIONS_NEW_NOT_ALLOWED'), class_exists('cbFeMarker') ? '_fe' : '');
     }
     JRequest::setVar('tmpl', JRequest::getWord('tmpl', null));
     JRequest::setVar('layout', JRequest::getWord('layout', null) == 'latest' ? null : JRequest::getWord('layout', null));
     JRequest::setVar('view', 'edit');
     parent::display();
 }
Ejemplo n.º 14
0
<?php

/**
 * @package     ContentBuilder
 * @author      Markus Bopp
 * @link        http://www.crosstec.de
 * @license     GNU/GPL
*/
defined('_JEXEC') or die('Restricted access');
$new_allowed = class_exists('cbFeMarker') ? contentbuilder::authorizeFe('new') : contentbuilder::authorize('new');
$edit_allowed = class_exists('cbFeMarker') ? contentbuilder::authorizeFe('edit') : contentbuilder::authorize('edit');
$delete_allowed = class_exists('cbFeMarker') ? contentbuilder::authorizeFe('delete') : contentbuilder::authorize('delete');
$view_allowed = class_exists('cbFeMarker') ? contentbuilder::authorizeFe('view') : contentbuilder::authorize('view');
$fullarticle_allowed = class_exists('cbFeMarker') ? contentbuilder::authorizeFe('fullarticle') : contentbuilder::authorize('fullarticle');
JFactory::getDocument()->addStyleDeclaration($this->theme_css);
JFactory::getDocument()->addScriptDeclaration($this->theme_js);
?>
<a name="article_up"></a>
<script type="text/javascript">
<!--
function contentbuilder_delete(){
    var confirmed = confirm('<?php 
echo JText::_('COM_CONTENTBUILDER_CONFIRM_DELETE_MESSAGE');
?>
');
    if(confirmed){
        location.href = '<?php 
echo 'index.php?option=com_contentbuilder&controller=edit&task=delete' . (JRequest::getVar('tmpl', '') != '' ? '&tmpl=' . JRequest::getVar('tmpl', '') : '') . (JRequest::getVar('layout', '') != '' ? '&layout=' . JRequest::getVar('layout', '') : '') . '&view=edit&id=' . JRequest::getInt('id', 0) . '&cid[]=' . JRequest::getCmd('record_id', 0) . '&Itemid=' . JRequest::getInt('Itemid', 0) . '&limitstart=' . JRequest::getInt('limitstart', 0) . '&filter_order=' . JRequest::getCmd('filter_order');
?>
';
    }
Ejemplo n.º 15
0
require_once "./dbconnection.php";
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>FeRoSch</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
    <link rel="stylesheet" href="css/myStyle.css">
</head>
<body>
<?php 
$menubuilder = new menubuilder();
$menubuilder->print_menu();
$contenbuilder = new contentbuilder();
$contenbuilder->build();
?>

<?php 
if (isset($_GET['complete'])) {
    ?>
    <script type="text/javascript">
        alert(<?php 
    echo $_GET['complete'];
    ?>
);
    </script>
<?php 
}
?>
Ejemplo n.º 16
0
<?php

/**
 * @package     ContentBuilder
 * @author      Markus Bopp
 * @link        http://www.crosstec.de
 * @license     GNU/GPL
*/
defined('_JEXEC') or die('Restricted access');
$edit_allowed = class_exists('cbFeMarker') ? contentbuilder::authorizeFe('edit') : contentbuilder::authorize('edit');
$delete_allowed = class_exists('cbFeMarker') ? contentbuilder::authorizeFe('delete') : contentbuilder::authorize('delete');
$view_allowed = class_exists('cbFeMarker') ? contentbuilder::authorizeFe('view') : contentbuilder::authorize('view');
JFactory::getDocument()->addScript(JURI::root(true) . '/components/com_contentbuilder/assets/js/contentbuilder.js');
?>

<?php 
if ($this->author) {
    JFactory::getDocument()->setMetaData('author', $this->author);
}
if ($this->robots) {
    JFactory::getDocument()->setMetaData('robots', $this->robots);
}
if ($this->rights) {
    JFactory::getDocument()->setMetaData('rights', $this->rights);
}
if ($this->metakey) {
    JFactory::getDocument()->setMetaData('keywords', $this->metakey);
}
if ($this->metadesc) {
    JFactory::getDocument()->setMetaData('description', $this->metadesc);
}
Ejemplo n.º 17
0
 function store()
 {
     if (JRequest::getInt('type_change', 0)) {
         $this->_db->setQuery("Update #__contentbuilder_elements Set `type`=" . $this->_db->Quote(JRequest::getCmd('type_selection', '')) . " Where id = " . $this->_element_id);
         $this->_db->query();
         return 1;
     }
     $query = '';
     $plugins = contentbuilder::getFormElementsPlugins();
     $type = JRequest::getCmd('field_type', '');
     switch ($type) {
         case in_array(JRequest::getCmd('field_type', ''), contentbuilder::getFormElementsPlugins()):
             $hint = JRequest::getVar('hint', '', 'POST', 'STRING', JREQUEST_ALLOWHTML);
             $removables = array();
             $plgs = CBPluginHelper::importPlugin('contentbuilder_form_elements', JRequest::getCmd('field_type', ''));
             $removables = array_merge($removables, $plgs);
             $dispatcher = JDispatcher::getInstance();
             $results = $dispatcher->trigger('onSettingsStore', array());
             if (count($results)) {
                 $results = $results[0];
             }
             foreach ($removables as $removable) {
                 $dispatcher->detach($removable);
             }
             $the_item = $results;
             $query = " `options`='" . base64_encode(serialize($the_item['options'])) . "', `type`=" . $this->_db->Quote(JRequest::getCmd('field_type', '')) . ", `change_type`=" . $this->_db->Quote(JRequest::getCmd('field_type', '')) . ", `hint`=" . $this->_db->Quote($hint) . ", `default_value`=" . $this->_db->Quote($the_item['default_value']) . " ";
             break;
         case '':
         case 'text':
             $length = JRequest::getVar('length', '');
             $maxlength = JRequest::getInt('maxlength', '');
             $password = JRequest::getInt('password', 0);
             $readonly = JRequest::getInt('readonly', 0);
             $default_value = JRequest::getVar('default_value', '');
             $allow_raw = JRequest::getInt('allow_encoding', 0) == 2 ? true : false;
             // 0 = filter on, 1 = allow html, 2 = allow raw
             $allow_html = JRequest::getInt('allow_encoding', 0) == 1 ? true : false;
             $hint = JRequest::getVar('hint', '', 'POST', 'STRING', JREQUEST_ALLOWHTML);
             $options = new stdClass();
             $options->length = $length;
             $options->maxlength = $maxlength;
             $options->password = $password;
             $options->readonly = $readonly;
             $options->allow_raw = $allow_raw;
             $options->allow_html = $allow_html;
             $query = " `options`='" . base64_encode(serialize($options)) . "', `type`='text', `change_type`='text', `hint`=" . $this->_db->Quote($hint) . ", `default_value`=" . $this->_db->Quote($default_value) . " ";
             break;
         case 'textarea':
             $maxlength = JRequest::getInt('maxlength', '');
             $width = JRequest::getVar('width', '');
             $height = JRequest::getVar('height', '');
             $default_value = JRequest::getVar('default_value', '');
             $readonly = JRequest::getInt('readonly', 0);
             $allow_raw = JRequest::getInt('allow_encoding', 0) == 2 ? true : false;
             // 0 = filter on, 1 = allow html, 2 = allow raw
             $allow_html = JRequest::getInt('allow_encoding', 0) == 1 ? true : false;
             $hint = JRequest::getVar('hint', '', 'POST', 'STRING', JREQUEST_ALLOWHTML);
             $options = new stdClass();
             $options->maxlength = $maxlength;
             $options->width = $width;
             $options->height = $height;
             $options->readonly = $readonly;
             $options->allow_raw = $allow_raw;
             $options->allow_html = $allow_html;
             $query = " `options`='" . base64_encode(serialize($options)) . "', `type`='textarea', `change_type`='textarea', `hint`=" . $this->_db->Quote($hint) . ", `default_value`=" . $this->_db->Quote($default_value) . " ";
             break;
         case 'checkboxgroup':
         case 'radiogroup':
         case 'select':
             $seperator = ',';
             //JRequest::getVar('seperator',',');
             $default_value = implode($seperator, JRequest::getVar('default_value', array()));
             $allow_raw = JRequest::getInt('allow_encoding', 0) == 2 ? true : false;
             // 0 = filter on, 1 = allow html, 2 = allow raw
             $allow_html = JRequest::getInt('allow_encoding', 0) == 1 ? true : false;
             $hint = JRequest::getVar('hint', '', 'POST', 'STRING', JREQUEST_ALLOWHTML);
             $options = new stdClass();
             $options->seperator = $seperator;
             $options->allow_raw = $allow_raw;
             $options->allow_html = $allow_html;
             if ($type == 'select') {
                 $multi = JRequest::getInt('multiple', 0);
                 $options->multiple = $multi;
                 $options->length = JRequest::getVar('length', '');
             }
             if ($type == 'checkboxgroup' || $type == 'radiogroup') {
                 $options->horizontal = JRequest::getBool('horizontal', 0);
                 $options->horizontal_length = JRequest::getVar('horizontal_length', '');
             }
             $query = " `options`='" . base64_encode(serialize($options)) . "', `type`='" . $type . "', `change_type`='" . $type . "', `hint`=" . $this->_db->Quote($hint) . ", `default_value`=" . $this->_db->Quote($default_value) . " ";
             break;
         case 'upload':
             jimport('joomla.filesystem.file');
             jimport('joomla.filesystem.folder');
             $this->_db->setQuery("Select upload_directory, protect_upload_directory From #__contentbuilder_forms Where id = " . $this->_id);
             $setup = $this->_db->loadAssoc();
             // rel check for setup
             $tokens = '';
             $upl_ex = explode('|', $setup['upload_directory']);
             $setup['upload_directory'] = $upl_ex[0];
             $upl_ex2 = explode('|', trim(JRequest::getVar('upload_directory', '')));
             JRequest::setVar('upload_directory', $upl_ex2[0]);
             $is_relative = strpos(strtolower($setup['upload_directory']), '{cbsite}') === 0;
             $tmp_upload_directory = $setup['upload_directory'];
             $upload_directory = $is_relative ? str_replace(array('{CBSite}', '{cbsite}'), JPATH_SITE, $setup['upload_directory']) : $setup['upload_directory'];
             // rel check for element options
             $is_opt_relative = strpos(strtolower(trim(JRequest::getVar('upload_directory', ''))), '{cbsite}') === 0;
             $tmp_opt_upload_directory = trim(JRequest::getVar('upload_directory', ''));
             JRequest::setVar('upload_directory', $is_relative ? str_replace(array('{CBSite}', '{cbsite}'), JPATH_SITE, trim(JRequest::getVar('upload_directory', ''))) : trim(JRequest::getVar('upload_directory', '')));
             $protect = $setup['protect_upload_directory'];
             if (!trim(JRequest::getVar('upload_directory', '')) && !JFolder::exists($upload_directory)) {
                 if (!JFolder::exists(JPATH_SITE . DS . 'media' . DS . 'contentbuilder')) {
                     JFolder::create(JPATH_SITE . DS . 'media' . DS . 'contentbuilder');
                     JFile::write(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'index.html', $def = '');
                 }
                 if (!JFolder::exists(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'upload')) {
                     JFolder::create(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'upload');
                     JFile::write(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'upload' . DS . 'index.html', $def = '');
                 }
                 $upload_directory = JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'upload';
                 if ($is_opt_relative) {
                     $is_relative = 1;
                     $tmp_upload_directory = '{CBSite}' . DS . 'media' . DS . 'contentbuilder' . DS . 'upload';
                 }
                 if (isset($upl_ex[1])) {
                     $tokens = '|' . $upl_ex[1];
                 }
                 JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_FALLBACK_UPLOAD_CREATED') . ' (' . DS . 'media' . DS . 'contentbuilder' . DS . 'upload' . ')', 'warning');
             } else {
                 if (trim(JRequest::getVar('upload_directory', '')) != '' && !JFolder::exists(contentbuilder::makeSafeFolder(JRequest::getVar('upload_directory', '')))) {
                     $upload_directory = contentbuilder::makeSafeFolder(JRequest::getVar('upload_directory', ''));
                     JFolder::create($upload_directory);
                     JFile::write($upload_directory . DS . 'index.html', $def = '');
                     if ($is_opt_relative) {
                         $is_relative = 1;
                         $tmp_upload_directory = $tmp_opt_upload_directory;
                     }
                     if (isset($upl_ex2[1])) {
                         $tokens = '|' . $upl_ex2[1];
                     }
                     JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_FALLBACK_UPLOAD_CREATED') . ' (' . $upload_directory . ')', 'warning');
                 } else {
                     if (trim(JRequest::getVar('upload_directory', '')) != '' && JFolder::exists(contentbuilder::makeSafeFolder(JRequest::getVar('upload_directory', '')))) {
                         $upload_directory = contentbuilder::makeSafeFolder(JRequest::getVar('upload_directory', ''));
                         if ($is_opt_relative) {
                             $is_relative = 1;
                             $tmp_upload_directory = $tmp_opt_upload_directory;
                         }
                         if (isset($upl_ex2[1])) {
                             $tokens = '|' . $upl_ex2[1];
                         }
                     } else {
                         if (isset($upl_ex[1])) {
                             $tokens = '|' . $upl_ex[1];
                         }
                     }
                 }
             }
             if ($protect && JFolder::exists($upload_directory)) {
                 JFile::write(contentbuilder::makeSafeFolder($upload_directory) . DS . '.htaccess', $def = 'deny from all');
             } else {
                 if (!$protect && JFolder::exists($upload_directory)) {
                     if (JFile::exists(contentbuilder::makeSafeFolder($upload_directory) . DS . '.htaccess')) {
                         JFile::delete(contentbuilder::makeSafeFolder($upload_directory) . DS . '.htaccess');
                     }
                 }
             }
             $default_value = JRequest::getVar('default_value', '');
             $hint = JRequest::getVar('hint', '', 'POST', 'STRING', JREQUEST_ALLOWHTML);
             $options = new stdClass();
             $options->upload_directory = JFolder::exists($upload_directory) ? ($is_relative ? $tmp_upload_directory : $upload_directory) . $tokens : '';
             $options->allowed_file_extensions = JRequest::getVar('allowed_file_extensions', '');
             $options->max_filesize = JRequest::getVar('max_filesize', '');
             $query = " `options`='" . base64_encode(serialize($options)) . "', `type`='" . $type . "', `change_type`='" . $type . "', `hint`=" . $this->_db->Quote($hint) . ", `default_value`=" . $this->_db->Quote($default_value) . " ";
             break;
         case 'captcha':
             $default_value = JRequest::getVar('default_value', '');
             $hint = JRequest::getVar('hint', '', 'POST', 'STRING', JREQUEST_ALLOWHTML);
             $options = new stdClass();
             $query = " `options`='" . base64_encode(serialize($options)) . "', `type`='" . $type . "', `change_type`='" . $type . "', `hint`=" . $this->_db->Quote($hint) . ", `default_value`=" . $this->_db->Quote($default_value) . " ";
             break;
         case 'calendar':
             $length = JRequest::getVar('length', '');
             $format = JRequest::getVar('format', '');
             $transfer_format = JRequest::getVar('transfer_format', '');
             $maxlength = JRequest::getInt('maxlength', '');
             $readonly = JRequest::getInt('readonly', 0);
             $default_value = JRequest::getVar('default_value', '');
             $hint = JRequest::getVar('hint', '', 'POST', 'STRING', JREQUEST_ALLOWHTML);
             $options = new stdClass();
             $options->length = $length;
             $options->maxlength = $maxlength;
             $options->readonly = $readonly;
             $options->format = $format;
             $options->transfer_format = $transfer_format;
             $query = " `options`='" . base64_encode(serialize($options)) . "', `type`='calendar', `change_type`='calendar', `hint`=" . $this->_db->Quote($hint) . ", `default_value`=" . $this->_db->Quote($default_value) . " ";
             break;
         case 'hidden':
             $allow_raw = JRequest::getInt('allow_encoding', 0) == 2 ? true : false;
             // 0 = filter on, 1 = allow html, 2 = allow raw
             $allow_html = JRequest::getInt('allow_encoding', 0) == 1 ? true : false;
             $default_value = JRequest::getVar('default_value', '');
             $hint = '';
             $options = new stdClass();
             $options->allow_raw = $allow_raw;
             $options->allow_html = $allow_html;
             $query = " `options`='" . base64_encode(serialize($options)) . "', `type`='" . $type . "', `change_type`='" . $type . "', `hint`=" . $this->_db->Quote($hint) . ", `default_value`=" . $this->_db->Quote($default_value) . " ";
             break;
     }
     if ($query) {
         $custom_init_script = JRequest::getVar('custom_init_script', '', 'POST', 'STRING', JREQUEST_ALLOWRAW);
         $custom_action_script = JRequest::getVar('custom_action_script', '', 'POST', 'STRING', JREQUEST_ALLOWRAW);
         $custom_validation_script = JRequest::getVar('custom_validation_script', '', 'POST', 'STRING', JREQUEST_ALLOWRAW);
         $validation_message = JRequest::getVar('validation_message', '');
         $validations = JRequest::getVar('validations', array());
         $other = " `validations`=" . $this->_db->Quote(implode(',', $validations)) . ", ";
         $other .= " `custom_init_script`=" . $this->_db->Quote($custom_init_script) . ", ";
         $other .= " `custom_action_script`=" . $this->_db->Quote($custom_action_script) . ", ";
         $other .= " `custom_validation_script`=" . $this->_db->Quote($custom_validation_script) . ", ";
         $other .= " `validation_message`=" . $this->_db->Quote($validation_message) . ", ";
         $this->_db->setQuery("Update #__contentbuilder_elements Set {$other} {$query} Where id = " . $this->_element_id);
         $this->_db->query();
         return true;
     }
     return false;
 }
Ejemplo n.º 18
0
 function change_list_language()
 {
     $this->_db->setQuery('Select reference_id,`type` From #__contentbuilder_forms Where id = ' . intval($this->_id));
     $typeref = $this->_db->loadAssoc();
     if (!is_array($typeref)) {
         return;
     }
     $reference_id = $typeref['reference_id'];
     $type = $typeref['type'];
     $items = JRequest::getVar('cid', array(), 'request', 'array');
     $sef = '';
     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(JRequest::getVar('list_language', '*')));
         $sef = $this->_db->loadResult();
     } else {
         $codes = contentbuilder::getLanguageCodes();
         foreach ($codes as $code) {
             if ($code == JRequest::getVar('list_language', '*')) {
                 $sef = explode('-', $code);
                 if (count($sef)) {
                     $sef = strtolower($sef[0]);
                 }
                 break;
             }
         }
     }
     foreach ($items as $item) {
         $this->_db->setQuery("Select id From #__contentbuilder_records Where `type` = " . $this->_db->Quote($type) . " And `reference_id` = " . $this->_db->Quote($reference_id) . " And record_id = " . $this->_db->Quote($item));
         $res = $this->_db->loadResult();
         if (!$res) {
             $this->_db->setQuery("Insert Into #__contentbuilder_records (`type`,lang_code, sef, record_id, reference_id) Values (" . $this->_db->Quote($type) . "," . $this->_db->Quote(JRequest::getVar('list_language', '*')) . ", " . $this->_db->Quote($sef) . ", " . $this->_db->Quote($item) . ", " . $this->_db->Quote($reference_id) . ")");
             $this->_db->query();
         } else {
             $this->_db->setQuery("Update #__contentbuilder_records Set sef = " . $this->_db->Quote($sef) . ", lang_code = " . $this->_db->Quote(JRequest::getVar('list_language', '*')) . " Where `type` = " . $this->_db->Quote($type) . " And `reference_id` = " . $this->_db->Quote($reference_id) . " And record_id = " . $this->_db->Quote($item));
             $this->_db->query();
         }
         if (version_compare($version->getShortVersion(), '1.6', '>=')) {
             $this->_db->setQuery("Update #__contentbuilder_articles As articles, #__content As content Set content.language = " . $this->_db->Quote(JRequest::getVar('list_language', '*')) . " Where ( content.state = 1 Or content.state = 0 ) And content.id = articles.article_id And articles.`type` = " . intval($type) . " And articles.reference_id = " . $this->_db->Quote($reference_id) . " And articles.record_id = " . $this->_db->Quote($item));
             $this->_db->query();
         } else {
             $this->_db->setQuery("Select attribs From #__contentbuilder_articles As articles, #__content As content Where ( content.state = 1 Or content.state = 0 ) And content.id = articles.article_id And articles.form_id = " . intval($this->_id) . " And articles.record_id = " . $this->_db->Quote($item));
             $attribs = $this->_db->loadResult();
             if ($attribs) {
                 $params = new JParameter($attribs);
                 $params->set('language', JRequest::getVar('list_language', '*'));
                 $this->_db->setQuery("Update #__contentbuilder_articles As articles, #__content As content Set attribs = " . $this->_db->Quote($params->toString()) . " Where ( content.state = 1 Or content.state = 0 ) And content.id = articles.article_id And articles.`type` = " . intval($type) . " And articles.reference_id = " . $this->_db->Quote($reference_id) . " And articles.record_id = " . $this->_db->Quote($item));
                 $this->_db->query();
             }
         }
     }
     $cache = JFactory::getCache('com_content');
     $cache->clean();
     $cache = JFactory::getCache('com_contentbuilder');
     $cache->clean();
 }
Ejemplo n.º 19
0
 static function save($option, $pkg, $form, $page)
 {
     global $database;
     $database = JFactory::getDBO();
     $row = new facileFormsElements($database);
     // bind it to the table
     if (!$row->bind($_POST)) {
         echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n";
         exit;
     }
     // if
     if ($row->script1flag1 == null) {
         $row->script1flag1 = 0;
     }
     if ($row->script1flag2 == null) {
         $row->script1flag2 = 0;
     }
     if ($row->script2flag1 == null) {
         $row->script2flag1 = 0;
     }
     if ($row->script2flag2 == null) {
         $row->script2flag2 = 0;
     }
     if ($row->script2flag3 == null) {
         $row->script2flag3 = 0;
     }
     if ($row->script2flag4 == null) {
         $row->script2flag4 = 0;
     }
     if ($row->script2flag5 == null) {
         $row->script2flag5 = 0;
     }
     // store it in the db
     if (!$row->store()) {
         echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n";
         exit;
     }
     // if
     $row->reorder("form={$form} and page={$page}");
     // CONTENTBUILDER
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.folder');
     if (JFile::exists(JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'classes' . DS . 'contentbuilder.php')) {
         $formId = $form;
         require_once JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'classes' . DS . 'contentbuilder.php';
         $cbForm = contentbuilder::getForm('com_breezingforms', $formId);
         $db = JFactory::getDBO();
         $db->setQuery("Select id From #__contentbuilder_forms Where `type` = 'com_breezingforms' And `reference_id` = " . intval($formId));
         jimport('joomla.version');
         $version = new JVersion();
         if (version_compare($version->getShortVersion(), '3.0', '>=')) {
             $cbForms = $db->loadColumn();
         } else {
             $cbForms = $db->loadResultArray();
         }
         if (is_object($cbForm) && count($cbForms)) {
             require_once JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'tables' . DS . 'elements.php';
             foreach ($cbForms as $dataId) {
                 contentbuilder::synchElements($dataId, $cbForm);
                 $elements_table = new TableElements($db);
                 $elements_table->reorder('form_id=' . $dataId);
             }
         }
     }
     // CONTENTBUILDER END
     JFactory::getApplication()->redirect("index.php?option={$option}&act=editpage&form={$form}&page={$page}&pkg={$pkg}", BFText::_('COM_BREEZINGFORMS_ELEMENTS_SAVED'));
 }
 function onContentPrepare($context, &$article, &$params, $limitstart = 0, $is_list = false, $form = null, $item = null)
 {
     static $use_title;
     static $use_form;
     if (!extension_loaded('gd') || !function_exists('gd_info')) {
         return true;
     }
     $protect = false;
     $time_passed = 0;
     $start_time = $this->measureTime();
     $max_exec_time = 15;
     if (function_exists('ini_get')) {
         $max_exec_time = @ini_get('max_execution_time');
     }
     $max_time = !empty($max_exec_time) ? intval($max_exec_time) / 2 : 15;
     $plugin = JPluginHelper::getPlugin('content', 'contentbuilder_image_scale');
     jimport('joomla.html.parameter');
     $pluginParams = CBCompat::getParams($plugin->params);
     $max_filesize = 8 * 8 * 8 * 1024 * 2 * intval($pluginParams->def('max_filesize', 4));
     // 4M default
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.folder');
     if (!JFile::exists(JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'classes' . DS . 'contentbuilder.php')) {
         return true;
     }
     /*
      * As of Joomla! 1.6 there is just the text passed if the article data is not passed in article context.
      * (for instance with categories).
      * But we need the article id, so we use the article id flag from content generation.
      */
     if (is_object($article) && !isset($article->id) && !isset($article->cbrecord) && isset($article->text) && $article->text) {
         preg_match_all("/<!--\\(cbArticleId:(\\d{1,})\\)-->/si", $article->text, $matched_id);
         if (isset($matched_id[1]) && isset($matched_id[1][0])) {
             $article->id = intval($matched_id[1][0]);
         }
     }
     // if this content plugin has been called from within list context
     if ($is_list) {
         if (!trim($article->text)) {
             return true;
         }
         $article->cbrecord = $form;
         $article->cbrecord->items = array();
         $article->cbrecord->items[0] = $item;
         $article->cbrecord->record_id = $item->colRecord;
     }
     if (!JFolder::exists(JPATH_SITE . DS . 'media' . DS . 'contentbuilder')) {
         JFolder::create(JPATH_SITE . DS . 'media' . DS . 'contentbuilder');
     }
     if (!JFile::exists(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'index.html')) {
         JFile::write(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'index.html', $def = '');
     }
     if (!JFolder::exists(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins')) {
         JFolder::create(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins');
     }
     if (!JFile::exists(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins' . DS . 'index.html')) {
         JFile::write(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins' . DS . 'index.html', $def = '');
     }
     if (!JFolder::exists(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins' . DS . 'image_scale')) {
         JFolder::create(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins' . DS . 'image_scale');
     }
     if (isset($article->id) || isset($article->cbrecord)) {
         $db = JFactory::getDBO();
         $matches = array();
         preg_match_all("/\\{CBImageScale([^}]*)\\}/i", $article->text, $matches);
         if (isset($matches[0]) && is_array($matches[0]) && isset($matches[1]) && is_array($matches[1])) {
             $record = null;
             $default_title = '';
             $protect = 0;
             $form_id = 0;
             $record_id = 0;
             $frontend = true;
             if (JFactory::getApplication()->isAdmin()) {
                 $frontend = false;
             }
             if (isset($article->id) && $article->id && !isset($article->cbrecord)) {
                 // try to obtain the record id if if this is just an article
                 $db->setQuery("Select form.`title_field`,form.`protect_upload_directory`,form.`reference_id`,article.`record_id`,article.`form_id`,form.`type`,form.`published_only`,form.`own_only`,form.`own_only_fe` From #__contentbuilder_articles As article, #__contentbuilder_forms As form Where form.`published` = 1 And form.id = article.`form_id` And article.`article_id` = " . $article->id);
                 $data = $db->loadAssoc();
                 require_once JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'classes' . DS . 'contentbuilder.php';
                 $form = contentbuilder::getForm($data['type'], $data['reference_id']);
                 if (!$form || !$form->exists) {
                     return true;
                 }
                 if ($form) {
                     $protect = $data['protect_upload_directory'];
                     $record = $form->getRecord($data['record_id'], $data['published_only'], $frontend ? $data['own_only_fe'] ? JFactory::getUser()->get('id', 0) : -1 : ($data['own_only'] ? JFactory::getUser()->get('id', 0) : -1), true);
                     $default_title = $data['title_field'];
                     $form_id = $data['form_id'];
                     $record_id = $data['record_id'];
                     $ref_id = $record_id = $data['reference_id'];
                     $ref_type = $data['type'];
                     $ref_published_only = $data['published_only'];
                     $ref_own_only_fe = $data['own_only_fe'];
                     $ref_own_only = $data['own_only'];
                 }
             } else {
                 if (isset($article->cbrecord) && isset($article->cbrecord->id) && $article->cbrecord->id) {
                     $protect = $article->cbrecord->protect_upload_directory;
                     $record = $article->cbrecord->items;
                     $default_title = $article->cbrecord->title_field;
                     $form_id = $article->cbrecord->id;
                     $record_id = $article->cbrecord->record_id;
                     $ref_id = $article->cbrecord->reference_id;
                     $ref_type = $article->cbrecord->type;
                     $ref_published_only = $article->cbrecord->published_only;
                     $ref_own_only_fe = $article->cbrecord->own_only_fe;
                     $ref_own_only = $article->cbrecord->own_only;
                 }
             }
             if (!JFile::exists(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins' . DS . 'image_scale' . DS . 'index.html')) {
                 JFile::write(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins' . DS . 'image_scale' . DS . 'index.html', $def = '');
             }
             if (!JFolder::exists(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins' . DS . 'image_scale' . DS . 'cache')) {
                 JFolder::create(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins' . DS . 'image_scale' . DS . 'cache');
             }
             if (!JFile::exists(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins' . DS . 'image_scale' . DS . 'cache' . DS . 'index.html')) {
                 JFile::write(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins' . DS . 'image_scale' . DS . 'cache' . DS . 'index.html', $def = '');
             }
             if (!JFolder::exists(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins' . DS . 'image_scale' . DS . 'cache' . DS . $form_id)) {
                 JFolder::create(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins' . DS . 'image_scale' . DS . 'cache' . DS . $form_id);
             }
             if (!JFile::exists(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins' . DS . 'image_scale' . DS . 'cache' . DS . $form_id . DS . 'index.html')) {
                 JFile::write(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins' . DS . 'image_scale' . DS . 'cache' . DS . $form_id . DS . 'index.html', $def = '');
             }
             if ($protect) {
                 if (!JFile::exists(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins' . DS . 'image_scale' . DS . 'cache' . DS . $form_id . DS . '.htaccess')) {
                     JFile::write(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins' . DS . 'image_scale' . DS . 'cache' . DS . $form_id . DS . '.htaccess', $def = 'deny from all');
                 }
             } else {
                 if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins' . DS . 'image_scale' . DS . 'cache' . DS . $form_id . DS . '.htaccess')) {
                     JFile::delete(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins' . DS . 'image_scale' . DS . 'cache' . DS . $form_id . DS . '.htaccess');
                 }
             }
             $default_folder = JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins' . DS . 'image_scale' . DS . 'cache' . DS . $form_id;
             // if it is a list, permissions will be handled by the list
             if (!$is_list) {
                 contentbuilder::setPermissions($form_id, $record_id, $frontend ? '_fe' : '');
                 if ($frontend) {
                     if (!contentbuilder::authorizeFe('view')) {
                         if (JRequest::getInt('contentbuilder_display', 0) || $protect && JRequest::getInt('contentbuilder_display_detail', 0)) {
                             ob_end_clean();
                             die('No Access');
                         } else {
                             return true;
                         }
                     }
                 } else {
                     if (!contentbuilder::authorize('view')) {
                         if (JRequest::getInt('contentbuilder_display', 0) || $protect && JRequest::getInt('contentbuilder_display_detail', 0)) {
                             ob_end_clean();
                             die('No Access');
                         } else {
                             return true;
                         }
                     }
                 }
             }
             if (!trim($default_title)) {
                 $default_title = strtotime('now');
             }
             $i = 0;
             foreach ($matches[1] as $match) {
                 $alt = '';
                 $out = '';
                 $width = 0;
                 $height = 0;
                 $original_width = 0;
                 $original_height = 0;
                 $field = $is_list ? $article->cbrecord->items[0]->recName : '';
                 $folder = $default_folder;
                 $bgcolor = null;
                 $title = '';
                 $type = '';
                 $cache = 86400;
                 $global_cache = 86400;
                 $align = '';
                 $open = '';
                 $default_image = '';
                 $default_image_width = 50;
                 $default_image_height = 50;
                 $options = explode(';', trim($match));
                 foreach ($options as $option) {
                     $keyval = explode(':', trim($option), 2);
                     if (count($keyval) == 2) {
                         $value = trim($keyval[1]);
                         switch (strtolower(trim($keyval[0]))) {
                             case 'width':
                                 $width = $value;
                                 break;
                             case 'height':
                                 $height = $value;
                                 break;
                             case 'original-width':
                                 $original_width = $value;
                                 break;
                             case 'original-height':
                                 $original_height = $value;
                                 break;
                             case 'field':
                                 $field = $is_list ? $article->items[0]->recName : $value;
                                 break;
                             case 'background-color':
                                 $bgcolor = $value;
                                 break;
                             case 'folder':
                                 $folder = $value;
                                 break;
                             case 'alt':
                                 $alt = $value;
                                 break;
                             case 'title':
                                 $title = $value;
                                 break;
                             case 'type':
                                 $type = $value;
                                 break;
                             case 'cache':
                                 $cache = $value;
                                 break;
                             case 'global_cache':
                                 $global_cache = $value;
                                 break;
                             case 'align':
                                 $align = $value;
                                 break;
                             case 'open':
                                 $open = $value;
                                 break;
                             case 'default-image':
                                 $default_image = $value;
                                 break;
                             case 'default-image-width':
                                 $default_image_width = $value;
                                 break;
                             case 'default-image-height':
                                 $default_image_height = $value;
                                 break;
                         }
                     }
                 }
                 if ($is_list && $alt == 'USE-TITLE') {
                     if (!$use_form) {
                         require_once JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'classes' . DS . 'contentbuilder.php';
                         $use_form = contentbuilder::getForm($ref_type, $ref_id);
                     }
                     if ($use_form && $use_form->exists) {
                         if (!is_array($use_title) || !isset($use_title[intval($default_title)])) {
                             $use_record = $use_form->getRecord($record_id, $ref_published_only, $frontend ? $ref_own_only_fe ? JFactory::getUser()->get('id', 0) : -1 : ($ref_own_only ? JFactory::getUser()->get('id', 0) : -1), true);
                             foreach ($use_record as $use_item) {
                                 if ($default_title == $use_item->recElementId) {
                                     $default_title = cbinternal($item->recValue);
                                     if (!$is_list && $alt == 'USE-TITLE') {
                                         $alt = $default_title;
                                         $title = $default_title;
                                     }
                                     break;
                                 }
                             }
                             $use_title[intval($default_title)] = $db->loadResult();
                         }
                         $alt = $use_title[intval($default_title)];
                         $title = $use_title[intval($default_title)];
                     }
                 } else {
                     if ($is_list && trim($alt) == '') {
                         $alt = cbinternal($article->cbrecord->items[0]->recValue);
                         $title = cbinternal($article->cbrecord->items[0]->recValue);
                     }
                 }
                 $is_series = false;
                 if ($field && ($width || $height)) {
                     if ($record !== null) {
                         if (isset($record) && is_array($record)) {
                             foreach ($record as $item) {
                                 if ($default_title == $item->recElementId) {
                                     $default_title = cbinternal($item->recValue);
                                     if (!$is_list && $alt == 'USE-TITLE') {
                                         $alt = $default_title;
                                         $title = $default_title;
                                     }
                                     break;
                                 }
                             }
                             foreach ($record as $item) {
                                 if ($item->recName == $field) {
                                     if (trim($alt) == '') {
                                         $alt = cbinternal($item->recValue);
                                         $title = cbinternal($item->recValue);
                                     }
                                     $the_files = explode("\n", str_replace("\r", '', $item->recValue));
                                     $the_files_size = count($the_files);
                                     if ($the_files_size > 0) {
                                         $is_series = true;
                                     }
                                     for ($fcnt = 0; $fcnt < $the_files_size; $fcnt++) {
                                         $the_value = str_replace(array('{CBSite}', '{cbsite}'), JPATH_SITE, trim($the_files[$fcnt]));
                                         if ($the_value && ($width || $height)) {
                                             $image = @getimagesize($the_value);
                                             if ($image !== false) {
                                                 if ($type != 'simple') {
                                                     if (!$width || $width < 0) {
                                                         $width = $height;
                                                     }
                                                     if (!$height || $height < 0) {
                                                         $height = $width;
                                                     }
                                                 }
                                                 if ($width > 16384) {
                                                     $width = 16384;
                                                 }
                                                 if ($height > 16384) {
                                                     $height = 16384;
                                                 }
                                                 $exif_type = exif_imagetype($the_value);
                                                 // displaying the original file on request
                                                 if (JRequest::getInt('contentbuilder_display_detail', 0)) {
                                                     if (JRequest::getVar('contentbuilder_detail_file', '', 'REQUEST', 'STRING', JREQUEST_ALLOWRAW) == sha1($field . $the_value)) {
                                                         // clean up before displaying
                                                         ob_end_clean();
                                                         switch ($exif_type) {
                                                             case IMAGETYPE_JPEG2000:
                                                                 header('Content-Type: ' . @image_type_to_mime_type(IMAGETYPE_JPEG2000));
                                                                 break;
                                                             case IMAGETYPE_JPEG:
                                                                 header('Content-Type: ' . @image_type_to_mime_type(IMAGETYPE_JPEG));
                                                                 break;
                                                             case IMAGETYPE_GIF:
                                                                 header('Content-Type: ' . @image_type_to_mime_type(IMAGETYPE_GIF));
                                                                 break;
                                                             case IMAGETYPE_PNG:
                                                                 header('Content-Type: ' . @image_type_to_mime_type(IMAGETYPE_PNG));
                                                                 break;
                                                         }
                                                         header('Content-Disposition: inline; filename="' . basename(JFilterOutput::stringURLSafe($title) . '_' . $the_value) . '"');
                                                         header('Content-Length: ' . @filesize($the_value));
                                                         @$this->readfile_chunked($the_value);
                                                         exit;
                                                     }
                                                 }
                                                 $filename = '';
                                                 $pathinfo = pathinfo($the_value);
                                                 $basename = basename($the_value, '.' . $pathinfo['extension']) . '_' . $width . 'x' . $height . '_cbresized';
                                                 if ($folder && JFolder::exists($folder)) {
                                                     $filename = $folder . DS . $basename . image_type_to_extension($exif_type);
                                                 } else {
                                                     $filename = $pathinfo['dirname'] . DS . $basename . image_type_to_extension($exif_type);
                                                     $folder = $pathinfo['dirname'];
                                                 }
                                                 if (is_numeric($global_cache)) {
                                                     $limit = intval($global_cache);
                                                     $sourcePath = $folder . DS;
                                                     if (@file_exists($sourcePath) && @is_readable($sourcePath) && @is_dir($sourcePath) && ($handle = @opendir($sourcePath))) {
                                                         while (false !== ($file = @readdir($handle))) {
                                                             if ($file != "." && $file != "..") {
                                                                 $parts = explode('_', $file);
                                                                 $exparts = explode('.', isset($parts[count($parts) - 1]) ? $parts[count($parts) - 1] : array());
                                                                 if (isset($exparts[0]) && $exparts[0] == 'cbresized') {
                                                                     if (@JFile::exists($sourcePath . $file) && @is_readable($sourcePath . $file)) {
                                                                         $fileCreationTime = @filectime($sourcePath . $file);
                                                                         $fileAge = time() - $fileCreationTime;
                                                                         if ($fileAge >= $limit) {
                                                                             JFile::delete($sourcePath . $file);
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                         @closedir($handle);
                                                     }
                                                 }
                                                 $image_changed = false;
                                                 $image_filesize = @filesize($filename);
                                                 if ($image_filesize !== null) {
                                                     $existing_image = @getimagesize($filename);
                                                     if ($existing_image[0] != $width || $existing_image[1] != $height) {
                                                         $image_changed = true;
                                                     }
                                                 }
                                                 $create = false;
                                                 switch ($cache) {
                                                     case 'none':
                                                         $create = true;
                                                         break;
                                                     default:
                                                         if (is_numeric($cache) && JFile::exists($filename)) {
                                                             $limit = intval($cache);
                                                             $fileCreationTime = @filectime($filename);
                                                             $fileAge = time() - $fileCreationTime;
                                                             if ($fileAge >= $limit) {
                                                                 JFile::delete($filename);
                                                                 $create = true;
                                                             }
                                                         }
                                                 }
                                                 $max_ok = true;
                                                 if (@filesize($the_value) > $max_filesize) {
                                                     $max_ok = false;
                                                 }
                                                 if ($max_ok && ($create || $image_filesize === false || $image_changed)) {
                                                     $col_ = $bgcolor;
                                                     if ($bgcolor !== null) {
                                                         $col = array();
                                                         $col[0] = intval(@hexdec(@substr($bgcolor, 1, 2)));
                                                         $col[1] = intval(@hexdec(@substr($bgcolor, 3, 2)));
                                                         $col[2] = intval(@hexdec(@substr($bgcolor, 5, 2)));
                                                         $col_ = $col;
                                                     }
                                                     $resized = false;
                                                     $resource = false;
                                                     // try to prevent memory issues
                                                     $memory = true;
                                                     $imageInfo = $image;
                                                     $MB = 1048576;
                                                     $K64 = 65536;
                                                     $TWEAKFACTOR = 1.5;
                                                     $memoryNeeded = round(($imageInfo[0] * $imageInfo[1] * @$imageInfo['bits'] * (@$imageInfo['channels'] / 8) + $K64) * $TWEAKFACTOR);
                                                     $ini = 8 * $MB;
                                                     if (ini_get('memory_limit') !== false) {
                                                         $ini = $this->returnBytes(ini_get('memory_limit'));
                                                     }
                                                     $memoryLimit = $ini;
                                                     if (function_exists('memory_get_usage') && memory_get_usage() + $memoryNeeded > $memoryLimit) {
                                                         $memory = false;
                                                     }
                                                     if ($memory) {
                                                         switch ($exif_type) {
                                                             case IMAGETYPE_JPEG2000:
                                                             case IMAGETYPE_JPEG:
                                                                 $resource = @imagecreatefromjpeg($the_value);
                                                                 if ($resource) {
                                                                     $resized = @$this->resize_image($resource, $width, $height, $type == 'crop' ? 1 : ($type == 'simple' ? 3 : 2), $col_);
                                                                     if ($resized) {
                                                                         @imagejpeg($resized, $filename);
                                                                     }
                                                                     if ($resized) {
                                                                         @imagedestroy($resized);
                                                                     }
                                                                     if ($image[0] != $original_width && $image[1] != $original_height && ($original_width > 0 || $original_height > 0)) {
                                                                         if ($original_width != 0 && $original_height == 0) {
                                                                             $original_height = $original_width;
                                                                         }
                                                                         if ($original_width == 0 && $original_height != 0) {
                                                                             $original_width = $original_height;
                                                                         }
                                                                         $resized2 = @$this->resize_image($resource, $original_width, $original_height, $type == 'crop' ? 1 : ($type == 'simple' ? 3 : 2), $col_);
                                                                         if ($resized2) {
                                                                             @imagejpeg($resized2, $the_value);
                                                                             @imagedestroy($resized2);
                                                                             $image = @getimagesize($the_value);
                                                                         }
                                                                     }
                                                                     @imagedestroy($resource);
                                                                 }
                                                                 break;
                                                             case IMAGETYPE_GIF:
                                                                 $resource = @imagecreatefromgif($the_value);
                                                                 if ($resource) {
                                                                     $resized = @$this->resize_image($resource, $width, $height, $type == 'crop' ? 1 : ($type == 'simple' ? 3 : 2), $col_);
                                                                     if ($resized) {
                                                                         @imagegif($resized, $filename);
                                                                     }
                                                                     if ($resized) {
                                                                         @imagedestroy($resized);
                                                                     }
                                                                     if ($image[0] != $original_width && $image[1] != $original_height && ($original_width > 0 || $original_height > 0)) {
                                                                         if ($original_width != 0 && $original_height == 0) {
                                                                             $original_height = $original_width;
                                                                         }
                                                                         if ($original_width == 0 && $original_height != 0) {
                                                                             $original_width = $original_height;
                                                                         }
                                                                         $resized2 = @$this->resize_image($resource, $original_width, $original_height, $type == 'crop' ? 1 : ($type == 'simple' ? 3 : 2), $col_);
                                                                         if ($resized2) {
                                                                             @imagegif($resized2, $the_value);
                                                                             @imagedestroy($resized2);
                                                                             $image = @getimagesize($the_value);
                                                                         }
                                                                     }
                                                                     @imagedestroy($resource);
                                                                 }
                                                                 break;
                                                             case IMAGETYPE_PNG:
                                                                 $resource = @imagecreatefrompng($the_value);
                                                                 if ($resource) {
                                                                     $resized = @$this->resize_image($resource, $width, $height, $type == 'crop' ? 1 : ($type == 'simple' ? 3 : 2), $col_);
                                                                     if ($resized) {
                                                                         @imagepng($resized, $filename);
                                                                     }
                                                                     if ($resized) {
                                                                         @imagedestroy($resized);
                                                                     }
                                                                     if ($image[0] != $original_width && $image[1] != $original_height && ($original_width > 0 || $original_height > 0)) {
                                                                         if ($original_width != 0 && $original_height == 0) {
                                                                             $original_height = $original_width;
                                                                         }
                                                                         if ($original_width == 0 && $original_height != 0) {
                                                                             $original_width = $original_height;
                                                                         }
                                                                         $resized2 = @$this->resize_image($resource, $original_width, $original_height, $type == 'crop' ? 1 : ($type == 'simple' ? 3 : 2), $col_);
                                                                         if ($resized2) {
                                                                             @imagepng($resized2, $the_value);
                                                                             @imagedestroy($resized2);
                                                                             $image = @getimagesize($the_value);
                                                                         }
                                                                     }
                                                                     @imagedestroy($resource);
                                                                 }
                                                                 break;
                                                         }
                                                     }
                                                 }
                                                 if ($filename) {
                                                     $the_image = @getimagesize($filename);
                                                     if ($the_image !== false) {
                                                         if (JRequest::getInt('contentbuilder_display', 0)) {
                                                             if (JRequest::getVar('contentbuilder_field', '', 'REQUEST', 'STRING', JREQUEST_ALLOWRAW) == sha1($field . $filename)) {
                                                                 // clean up before displaying
                                                                 ob_end_clean();
                                                                 switch ($exif_type) {
                                                                     case IMAGETYPE_JPEG2000:
                                                                         header('Content-Type: ' . @image_type_to_mime_type(IMAGETYPE_JPEG2000));
                                                                         break;
                                                                     case IMAGETYPE_JPEG:
                                                                         header('Content-Type: ' . @image_type_to_mime_type(IMAGETYPE_JPEG));
                                                                         break;
                                                                     case IMAGETYPE_GIF:
                                                                         header('Content-Type: ' . @image_type_to_mime_type(IMAGETYPE_GIF));
                                                                         break;
                                                                     case IMAGETYPE_PNG:
                                                                         header('Content-Type: ' . @image_type_to_mime_type(IMAGETYPE_PNG));
                                                                         break;
                                                                 }
                                                                 header('Content-Disposition: inline; filename="' . JFilterOutput::stringURLSafe($title) . '_' . basename($filename) . '"');
                                                                 header('Content-Length: ' . @filesize($filename));
                                                                 @$this->readfile_chunked($filename);
                                                                 exit;
                                                             }
                                                         } else {
                                                             $align_ = $align;
                                                             $open_ = '';
                                                             $close_ = '';
                                                             $url = JURI::getInstance()->toString();
                                                             if (trim($open) == 'true') {
                                                                 if ($protect) {
                                                                     $open_ = JRoute::_($url . (strstr($url, '?') !== false ? '&' : '?') . 'contentbuilder_display_detail=1&contentbuilder_detail_file=' . sha1($field . $the_value));
                                                                 } else {
                                                                     $ex = explode(JPATH_SITE . DS, JPath::clean($the_value), 2);
                                                                     $open_ = JURI::root(true) . '/' . str_replace("\\", "/", $ex[count($ex) - 1]);
                                                                 }
                                                             }
                                                             if ($open_) {
                                                                 $inPopup = false;
                                                                 JHTML::_('behavior.modal');
                                                                 if ($image[0] > 960) {
                                                                     $inPopup = true;
                                                                 }
                                                                 if ($image[1] > 720) {
                                                                     $inPopup = true;
                                                                 }
                                                                 $hrefalign = $align_ ? 'style="float: ' . $align_ . ';" ' : '';
                                                                 if ($inPopup) {
                                                                     $open_ = '<a href="javascript:var win = window.open(\'' . $open_ . '\',\'ImageSizer\',\'height=' . $image[1] . ',width=' . $image[0] . ',scrollbars=1\');win.focus();void(0);" ' . $hrefalign . '>';
                                                                 } else {
                                                                     $open_ = '<a href="' . $open_ . '" ' . $hrefalign . 'class="modal" rel="{handler:\'iframe\',size:{x:' . ($image[0] + 20) . ',y:' . ($image[1] + 20) . '}}">';
                                                                 }
                                                                 $close_ = '</a>';
                                                             }
                                                             if ($protect) {
                                                                 $src = JRoute::_($url . (strstr($url, '?') !== false ? '&' : '?') . 'contentbuilder_display=1&contentbuilder_field=' . sha1($field . $filename));
                                                             } else {
                                                                 $ex = explode(JPATH_SITE . DS, $filename, 2);
                                                                 $src = JURI::root(true) . '/' . str_replace("\\", "/", $ex[count($ex) - 1]);
                                                             }
                                                             $out .= $open_ . '<img border="0" ' . $the_image[3] . ' ' . ($align_ ? 'style="float: ' . $align_ . ';" ' : '') . 'alt="' . $alt . '" title="' . $title . '" src="' . $src . '"/>' . $close_;
                                                             if ($is_series && $align_ && (strtolower($align_) == 'left' || strtolower($align_) == 'right')) {
                                                                 $out .= '<div style="float:' . strtolower($align_) . ';width: 5px;">&nbsp;</div>';
                                                             }
                                                             $align_ = '';
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                         $time_passed = $this->measureTime();
                                         if ($time_passed - $start_time > $max_time) {
                                             break;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 if (trim($out) == '' && JFile::exists(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins' . DS . 'image_scale' . DS . basename($default_image))) {
                     $out = '<img width="' . $default_image_width . '" height="' . $default_image_height . '" alt="" src="' . JURI::root(true) . '/media/contentbuilder/plugins/image_scale/' . basename($default_image) . '"/>';
                 }
                 if ($is_series && $align && (strtolower($align) == 'left' || strtolower($align) == 'right')) {
                     $out .= '<div style="clear:' . strtolower($align) . ';"></div>';
                 }
                 $article->text = str_replace($matches[0][$i], $out, $article->text);
                 $i++;
             }
         }
     }
     return true;
 }
Ejemplo n.º 21
0
/**
 * @package     ContentBuilder
 * @author      Markus Bopp
 * @link        http://www.crosstec.de
 * @license     GNU/GPL
*/
defined('_JEXEC') or die('Restricted access');
jimport('joomla.version');
$version = new JVersion();
if (version_compare($version->getShortVersion(), '1.7', '>=')) {
    require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'classes' . DS . 'plugin_helper.php';
} else {
    require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'classes' . DS . 'plugin_helper15.php';
}
$plugins = contentbuilder::getFormElementsPlugins();
$removables = array();
$plgs = CBPluginHelper::importPlugin('contentbuilder_form_elements', $this->element->type);
$removables = array_merge($removables, $plgs);
$dispatcher = JDispatcher::getInstance();
$results = $dispatcher->trigger('onSettingsDisplay', array($this->element->options));
if (count($results)) {
    $results = $results[0];
}
foreach ($removables as $removable) {
    $dispatcher->detach($removable);
}
$the_item = $results;
$is_plugin = false;
?>
<style type="text/css">
 function onContentPrepare($context, &$article, &$params, $limitstart = 0, $is_list = false, $form = null, $item = null)
 {
     $protect = false;
     $plugin = JPluginHelper::getPlugin('content', 'contentbuilder_rating');
     jimport('joomla.html.parameter');
     $pluginParams = CBCompat::getParams($plugin->params);
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.folder');
     if (!JFile::exists(JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'classes' . DS . 'contentbuilder.php')) {
         return true;
     }
     require_once JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'classes' . DS . 'contentbuilder.php';
     $lang = JFactory::getLanguage();
     $lang->load('plg_content_contentbuilder_rating', JPATH_ADMINISTRATOR);
     /*
      * As of Joomla! 1.6 there is just the text passed if the article data is not passed in article context.
      * (for instance with categories).
      * But we need the article id, so we use the article id flag from content generation.
      */
     if (is_object($article) && !isset($article->id) && !isset($article->cbrecord) && isset($article->text) && $article->text) {
         preg_match_all("/<!--\\(cbArticleId:(\\d{1,})\\)-->/si", $article->text, $matched_id);
         if (isset($matched_id[1]) && isset($matched_id[1][0])) {
             $article->id = intval($matched_id[1][0]);
         }
     }
     // if this content plugin has been called from within list context
     if ($is_list) {
         if (!trim($article->text)) {
             return true;
         }
         $article->cbrecord = $form;
         $article->cbrecord->items = array();
         $article->cbrecord->items[0] = $item;
         $article->cbrecord->record_id = $item->colRecord;
     }
     if (!JFolder::exists(JPATH_SITE . DS . 'media' . DS . 'contentbuilder')) {
         JFolder::create(JPATH_SITE . DS . 'media' . DS . 'contentbuilder');
     }
     if (!JFile::exists(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'index.html')) {
         JFile::write(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'index.html', $def = '');
     }
     if (!JFolder::exists(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins')) {
         JFolder::create(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins');
     }
     if (!JFile::exists(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins' . DS . 'index.html')) {
         JFile::write(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins' . DS . 'index.html', $def = '');
     }
     if (isset($article->id) || isset($article->cbrecord)) {
         $db = JFactory::getDBO();
         $matches = array();
         preg_match_all("/\\{CBRating([^}]*)\\}/i", $article->text, $matches);
         if (isset($matches[0]) && is_array($matches[0]) && isset($matches[1]) && is_array($matches[1])) {
             $form_id = 0;
             $record_id = 0;
             $frontend = true;
             if (JFactory::getApplication()->isAdmin()) {
                 $frontend = false;
             }
             if (isset($article->id) && $article->id && !isset($article->cbrecord)) {
                 // try to obtain the record id if if this is just an article
                 $db->setQuery("Select form.rating_slots,form.`title_field`,form.`protect_upload_directory`,form.`reference_id`,article.`record_id`,article.`form_id`,form.`type`,form.`published_only`,form.`own_only`,form.`own_only_fe` From #__contentbuilder_articles As article, #__contentbuilder_forms As form Where form.`published` = 1 And form.id = article.`form_id` And article.`article_id` = " . $article->id);
                 $data = $db->loadAssoc();
                 require_once JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'classes' . DS . 'contentbuilder.php';
                 $form = contentbuilder::getForm($data['type'], $data['reference_id']);
                 if (!$form || !$form->exists) {
                     return true;
                 }
                 if ($form) {
                     $form_id = $data['form_id'];
                     $record_id = $data['record_id'];
                     $rating_slots = $data['rating_slots'];
                 }
             } else {
                 if (isset($article->cbrecord) && isset($article->cbrecord->id) && $article->cbrecord->id) {
                     $form = $article->cbrecord->form;
                     $form_id = $article->cbrecord->id;
                     $record_id = $article->cbrecord->record_id;
                     $rating_slots = $article->cbrecord->rating_slots;
                 }
             }
             $rating = 0;
             $rating_count = 0;
             $rating_sum = 0;
             if (!is_object($form)) {
                 return true;
             }
             $record = $form->getRecord($record_id, false, -1, true);
             if (count($record)) {
                 $rating = $record[0]->recRating;
                 $rating_count = $record[0]->recRatingCount;
                 $rating_sum = $record[0]->recRatingSum;
             }
             $rating_allowed = true;
             if (!$is_list) {
                 contentbuilder::setPermissions($form_id, $record_id, $frontend ? '_fe' : '');
                 if ($frontend) {
                     if (!contentbuilder::authorizeFe('rating')) {
                         $rating_allowed = false;
                     }
                 } else {
                     if (!contentbuilder::authorize('rating')) {
                         $rating_allowed = false;
                     }
                 }
             }
             $i = 0;
             foreach ($matches[1] as $match) {
                 $options = explode(';', trim($match));
                 foreach ($options as $option) {
                     $keyval = explode(':', trim($option), 2);
                     if (count($keyval) == 2) {
                         $value = trim($keyval[1]);
                         switch (strtolower(trim($keyval[0]))) {
                             default:
                         }
                     }
                 }
                 $out = contentbuilder::getRating($form_id, $record_id, $rating, $rating_slots, JRequest::getCmd('lang', ''), $rating_allowed, $rating_count, $rating_sum);
                 $article->text = str_replace($matches[0][$i], $out, $article->text);
                 $i++;
             }
         }
     }
     return true;
 }
Ejemplo n.º 23
0
 function getPermissions()
 {
     $perms = array();
     if ($this->show_permissions) {
         foreach ($this->items as $item) {
             contentbuilder::setPermissions($item->id, '', '_fe');
             $view = contentbuilder::authorizeFe('view');
             $new = contentbuilder::authorizeFe('new');
             $edit = contentbuilder::authorizeFe('edit');
             $perms[$item->id] = array('view' => $view, 'new' => $new, 'edit' => $edit);
         }
     }
     return $perms;
 }
Ejemplo n.º 24
0
 public static function createArticle($contentbuilder_form_id, $record_id, array $record, array $elements_allowed, $title_field = '', $metadata = null, $config = array(), $full = false, $limited_options = true, $menu_cat_id = null)
 {
     $tz = new DateTimeZone(JFactory::getApplication()->getCfg('offset'));
     if (isset($config['publish_up']) && $config['publish_up'] && $config['publish_up'] != '0000-00-00 00:00:00') {
         $config['publish_up'] = JFactory::getDate($config['publish_up'], $tz);
         $config['publish_up'] = $config['publish_up']->format('Y-m-d H:i:s');
     } else {
         $config['publish_up'] = '0000-00-00 00:00:00';
     }
     if (isset($config['created']) && $config['created'] && $config['created'] != '0000-00-00 00:00:00') {
         $config['created'] = JFactory::getDate($config['created'], $tz);
         $config['created'] = $config['created']->format('Y-m-d H:i:s');
     } else {
         $config['created'] = '0000-00-00 00:00:00';
     }
     if (isset($config['publish_down']) && $config['publish_down'] && $config['publish_down'] != '0000-00-00 00:00:00') {
         $config['publish_down'] = JFactory::getDate($config['publish_down'], $tz);
         $config['publish_down'] = $config['publish_down']->format('Y-m-d H:i:s');
     } else {
         $config['publish_down'] = '0000-00-00 00:00:00';
     }
     $is15 = true;
     $version = new JVersion();
     if (version_compare($version->getShortVersion(), '1.6', '>=')) {
         $is15 = false;
     }
     $tpl = self::getTemplate($contentbuilder_form_id, $record_id, $record, $elements_allowed, true);
     if (!$tpl) {
         return 0;
     }
     $db = JFactory::getDBO();
     $db->setQuery("Select * From #__contentbuilder_forms Where id = " . intval($contentbuilder_form_id) . " And published = 1");
     $form = $db->loadAssoc();
     if (!$form) {
         return 0;
     }
     if ($is15 && $menu_cat_id !== null) {
         if (intval($menu_cat_id) > -2) {
             $menu_cat_id = explode(':', $menu_cat_id);
             if (count($menu_cat_id) == 2) {
                 $form['default_category'] = $menu_cat_id[1];
                 $form['default_section'] = $menu_cat_id[0];
             }
         }
     } else {
         if ($menu_cat_id !== null && intval($menu_cat_id) > -2) {
             $form['default_category'] = $menu_cat_id;
         }
     }
     $user = null;
     if ($form['act_as_registration']) {
         if ($record_id) {
             $form_ = contentbuilder::getForm($form['type'], $form['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();
             }
         }
     }
     $label = '';
     foreach ($record as $rec) {
         if ($rec->recElementId == $title_field) {
             if ($form['act_as_registration'] && $user !== null) {
                 if ($form['registration_name_field'] == $rec->recElementId) {
                     $rec->recValue = $user->name;
                 } else {
                     if ($form['registration_username_field'] == $rec->recElementId) {
                         $rec->recValue = $user->username;
                     } else {
                         if ($form['registration_email_field'] == $rec->recElementId) {
                             $rec->recValue = $user->email;
                         } else {
                             if ($form['registration_email_repeat_field'] == $rec->recElementId) {
                                 $rec->recValue = $user->email;
                             }
                         }
                     }
                 }
             }
             $label = cbinternal($rec->recValue);
             break;
         }
     }
     // trying first element if no title field given
     if (!$label && !count($record)) {
         $label = 'Unnamed';
     } else {
         if (!$label && count($record)) {
             $label = cbinternal($record[0]->recValue);
         }
     }
     // Clean text for xhtml transitional compliance
     $introtext = '';
     $fulltext = '';
     $tpl = str_replace('<br>', '<br />', $tpl);
     // Search for the {readmore} tag and split the text up accordingly.
     $pattern = '#<hr\\s+id=("|\')system-readmore("|\')\\s*\\/*>#i';
     $tagPos = preg_match($pattern, $tpl);
     if ($tagPos == 0) {
         $introtext = $tpl;
     } else {
         list($introtext, $fulltext) = preg_split($pattern, $tpl, 2);
     }
     // retrieve the publish state from the list view
     $state = 1;
     $db->setQuery("Select published, is_future, publish_up, publish_down From #__contentbuilder_records Where `type` = " . $db->Quote($form['type']) . " And reference_id = " . $db->Quote($form['reference_id']) . " And record_id = " . $db->Quote($record_id));
     $state = $db->loadAssoc();
     $publish_up_record = $state['publish_up'];
     $publish_down_record = $state['publish_down'];
     $state = $state['is_future'] ? 1 : $state['published'];
     // save/update articles
     $alias = '';
     $db->setQuery("Select articles.`article_id`, content.`alias` 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($contentbuilder_form_id) . " And articles.record_id = " . $db->Quote($record_id));
     $article = $db->loadAssoc();
     if (is_array($article)) {
         $alias = $article['alias'];
         $article = $article['article_id'];
     }
     // params
     $attribs = '';
     $meta = '';
     $rules = '';
     $metakey = '';
     $metadesc = '';
     $created_by = 0;
     $created_by_alias = '';
     $created_article = null;
     $_now = JFactory::getDate();
     $created_up = $publish_up_record;
     $created_down = $publish_down_record;
     if (is_array($article) && isset($article['article_id']) && intval($form['default_publish_up_days']) != 0) {
         // this will cause errors on 64bit systems, as strtotime's behavior is different for null dates
         // $date = JFactory::getDate(strtotime('now +'.intval($form['default_publish_up_days']).' days'));
         // fix as of forum post http://crosstec.de/forums/37-contentbuilder-general-forum-english/62084-64-bit-strtotime-bug.html#62084
         // thanks to user Fremmedkar
         $date = JFactory::getDate(strtotime(($created_up !== null && $created_up != '0000-00-00 00:00:00' ? $created_up : $_now) . ' +' . intval($form['default_publish_down_days']) . ' days'));
         if (version_compare($version->getShortVersion(), '3.0', '>=')) {
             $created_up = $date->toSql();
         } else {
             $created_up = $date->toMySQL();
         }
     }
     $publish_up = $created_up;
     if (is_array($article) && isset($article['article_id']) && intval($form['default_publish_down_days']) != 0) {
         //$date = JFactory::getDate(strtotime( ($created_up !== null ? $created_up : $_now).' +'.intval($form['default_publish_down_days']).' days'));
         $date = JFactory::getDate(strtotime(($created_up !== null && $created_up != '0000-00-00 00:00:00' ? $created_up : $_now) . ' +' . intval($form['default_publish_down_days']) . ' days'));
         if (version_compare($version->getShortVersion(), '3.0', '>=')) {
             $created_down = $date->toSql();
         } else {
             $created_down = $date->toMySQL();
         }
     }
     $publish_down = $created_down;
     $featured = $form['default_featured'];
     $ignore_lang_code = '*';
     if ($form['default_lang_code_ignore']) {
         if (!$is15) {
             $db->setQuery("Select lang_code From #__languages Where published = 1 And sef = " . $db->Quote(JRequest::getCmd('lang', '')));
             $ignore_lang_code = $db->loadResult();
             if (!$ignore_lang_code) {
                 $ignore_lang_code = '*';
             }
         } else {
             $ignore_lang_code = '';
             $codes = self::getLanguageCodes();
             foreach ($codes as $code) {
                 if (strstr(strtolower($code), strtolower(trim(JRequest::getCmd('lang', 'xxxxx')))) !== false) {
                     $ignore_lang_code = $code;
                     break;
                 }
             }
         }
     }
     $language = $form['default_lang_code_ignore'] ? $ignore_lang_code : $form['default_lang_code'];
     if ($is15) {
         // an exception regarding limited options for language
         if (!isset($config['params'])) {
             $registry = new JRegistry();
             $attr = array('language' => $language);
             $registry->loadArray($attr);
             $attribs = (string) $registry->toString();
         }
     }
     $access = $form['default_access'];
     $ordering = 0;
     if (!$is15 && $full) {
         //$state = isset($config['state']) ? $config['state'] : $state;
         // change the state in the CB records as well if coming from article settings
         //if(isset($config['state'])){
         //    $db->setQuery("Update #__contentbuilder_records Set `published` = ".( intval($config['state'])  == 1 ? 1 : 0 )." Where reference_id = ".$db->Quote($form['reference_id'])." And record_id = " . $db->Quote($record_id));
         //    $db->query();
         //}
         // limited
         $alias = isset($config['alias']) ? $config['alias'] : $alias;
         // limited
         $form['default_category'] = isset($config['catid']) ? $config['catid'] : $form['default_category'];
         // limited
         $access = isset($config['access']) ? $config['access'] : $access;
         // limited
         $featured = isset($config['featured']) ? $config['featured'] : 0;
         // limited
         $language = isset($config['language']) ? $config['language'] : $language;
         if ($form['article_record_impact_language'] && isset($config['language'])) {
             $db->setQuery("Select sef From #__languages Where published = 1 And lang_code = " . $db->Quote($config['language']));
             $sef = $db->loadResult();
             if ($sef === null) {
                 $sef = '';
             }
             $db->setQuery("Update #__contentbuilder_records Set sef = " . $db->Quote($sef) . ", lang_code = " . $db->Quote($config['language']) . " Where `type` = " . $db->Quote($form['type']) . " And reference_id = " . $db->Quote($form['reference_id']) . " And record_id = " . $db->Quote($record_id));
             $db->query();
         }
         // limited
         $created_by_alias = isset($config['created_by_alias']) ? $config['created_by_alias'] : '';
         if ($form['article_record_impact_publish'] && isset($config['publish_up']) && $config['publish_up'] != $publish_up) {
             // check in strtotime due to php's different behavior on 64bit machines
             if (version_compare($version->getShortVersion(), '3.0', '>=')) {
                 $___now = $_now->toSql();
             } else {
                 $___now = $_now->toMySQL();
             }
             $db->setQuery("Update #__contentbuilder_records Set " . (strtotime($config['publish_up'] == '0000-00-00 00:00:00' ? '1976-03-07 22:10:00' : $config['publish_up']) >= strtotime($___now) ? 'published = 0, is_future = 1, ' : '') . " publish_up = " . $db->Quote($config['publish_up']) . " Where `type` = " . $db->Quote($form['type']) . " And reference_id = " . $db->Quote($form['reference_id']) . " And record_id = " . $db->Quote($record_id));
             $db->query();
         }
         // limited
         $publish_up = isset($config['publish_up']) ? $config['publish_up'] : $publish_up;
         if ($form['article_record_impact_publish'] && isset($config['publish_down']) && $config['publish_down'] != $publish_down) {
             if (version_compare($version->getShortVersion(), '3.0', '>=')) {
                 $___now = $_now->toSql();
             } else {
                 $___now = $_now->toMySQL();
             }
             $db->setQuery("Update #__contentbuilder_records Set " . (strtotime($config['publish_down'] == '0000-00-00 00:00:00' ? '1976-03-07 22:10:00' : $config['publish_down']) <= strtotime($___now) ? 'published = 0,' : '') . "  publish_down = " . $db->Quote($config['publish_down']) . " Where `type` = " . $db->Quote($form['type']) . " And reference_id = " . $db->Quote($form['reference_id']) . " And record_id = " . $db->Quote($record_id));
             $db->query();
         }
         // limited
         $publish_down = isset($config['publish_down']) ? $config['publish_down'] : $publish_down;
         // limited
         $metakey = isset($config['metakey']) ? $config['metakey'] : '';
         // limited
         $metadesc = isset($config['metadesc']) ? $config['metadesc'] : '';
         $robots = '';
         $author = '';
         $rights = '';
         $xreference = '';
         if (!$limited_options) {
             // FULL
             $created_article = isset($config['created']) ? $config['created'] : null;
             // FULL
             if (JFactory::getApplication()->isAdmin()) {
                 $created_by = isset($config['created_by']) ? $config['created_by'] : 0;
             }
             // FULL
             if (isset($config['attribs']) && is_array($config['attribs'])) {
                 $registry = new JRegistry();
                 $registry->loadArray($config['attribs']);
                 $attribs = (string) $registry;
             }
             // FULL
             if (isset($config['metadata']) && is_array($config['metadata'])) {
                 if (isset($config['metadata']['robots'])) {
                     $robots = $config['metadata']['robots'];
                 }
                 if (isset($config['metadata']['author'])) {
                     $author = $config['metadata']['author'];
                 }
                 if (isset($config['metadata']['rights'])) {
                     $rights = $config['metadata']['rights'];
                 }
                 if (isset($config['metadata']['xreference'])) {
                     $xreference = $config['metadata']['xreference'];
                 }
                 $registry = new JRegistry();
                 $registry->loadArray($config['metadata']);
                 $meta = (string) $registry;
             }
         }
         $db->setQuery("Update #__contentbuilder_records Set robots = " . $db->Quote($robots) . ", author = " . $db->Quote($author) . ", rights = " . $db->Quote($rights) . ", xreference = " . $db->Quote($xreference) . ", metakey = " . $db->Quote($metakey) . ", metadesc = " . $db->Quote($metadesc) . " Where `type` = " . $db->Quote($form['type']) . " And reference_id = " . $db->Quote($form['reference_id']) . " And record_id = " . $db->Quote($record_id));
         $db->query();
         // Trigger the onContentBeforeSave event.
         $isNew = true;
         $dispatcher = JDispatcher::getInstance();
         $table = JTable::getInstance('content');
         if ($article > 0) {
             $table->load($article);
             $isNew = false;
         }
         $dispatcher->trigger('onContentBeforeSave', array('com_content.article', &$table, $isNew));
     } else {
         if ($full) {
             //$state = isset($config['state']) ? $config['state'] : $state;
             // change the state in the CB records as well if coming from article settings
             //if(isset($config['state'])){
             //    $db->setQuery("Update #__contentbuilder_records Set `published` = ".( intval($config['state'])  == 1 ? 1 : 0 )." Where reference_id = ".$db->Quote($form['reference_id'])." And record_id = " . $db->Quote($record_id));
             //    $db->query();
             //}
             // limited
             $alias = isset($config['alias']) ? $config['alias'] : $alias;
             // limited
             $form['default_category'] = isset($config['catid']) ? $config['catid'] : $form['default_category'];
             // limited
             $form['default_section'] = isset($config['sectionid']) ? $config['sectionid'] : $form['default_section'];
             // limited
             $access = isset($config['details']) && isset($config['details']['access']) ? $config['details']['access'] : $access;
             // limited
             $created_by_alias = isset($config['details']) && isset($config['details']['created_by_alias']) ? $config['details']['created_by_alias'] : '';
             // limited
             $ordering = isset($config['ordering']) && isset($config['ordering']) ? intval($config['ordering']) : 0;
             if ($form['article_record_impact_publish'] && isset($config['details']) && isset($config['details']['publish_up']) && $config['details']['publish_up'] != $publish_up) {
                 if (version_compare($version->getShortVersion(), '3.0', '>=')) {
                     $___now = $_now->toSql();
                 } else {
                     $___now = $_now->toMySQL();
                 }
                 $db->setQuery("Update #__contentbuilder_records Set " . (strtotime($config['details']['publish_up'] == '0000-00-00 00:00:00' ? '1976-03-07 22:10:00' : $config['details']['publish_up']) >= strtotime($___now) ? 'published = 0,' : '') . " publish_up = " . $db->Quote($config['details']['publish_up']) . ", is_future = 1 Where `type` = " . $db->Quote($form['type']) . " And reference_id = " . $db->Quote($form['reference_id']) . " And record_id = " . $db->Quote($record_id));
                 $db->query();
             }
             // limited
             $publish_up = isset($config['details']) && isset($config['details']['publish_up']) ? $config['details']['publish_up'] == JText::_('Never') ? '0000-00-00 00:00:00' : $config['details']['publish_up'] : $publish_up;
             if ($form['article_record_impact_publish'] && isset($config['details']) && isset($config['details']['publish_down']) && $config['details']['publish_down'] != $publish_down) {
                 if (version_compare($version->getShortVersion(), '3.0', '>=')) {
                     $___now = $_now->toSql();
                 } else {
                     $___now = $_now->toMySQL();
                 }
                 $db->setQuery("Update #__contentbuilder_records Set " . (strtotime($config['details']['publish_down'] == '0000-00-00 00:00:00' ? '1976-03-07 22:10:00' : $config['details']['publish_down']) <= strtotime($___now) ? 'published = 0,' : '') . " publish_down = " . $db->Quote($config['details']['publish_down']) . " Where `type` = " . $db->Quote($form['type']) . " And reference_id = " . $db->Quote($form['reference_id']) . " And record_id = " . $db->Quote($record_id));
                 $db->query();
             }
             // limited
             $publish_down = isset($config['details']) && isset($config['details']['publish_down']) ? $config['details']['publish_down'] == JText::_('Never') ? '0000-00-00 00:00:00' : $config['details']['publish_down'] : $publish_down;
             // limited
             $metakey = isset($config['meta']) && isset($config['meta']['keywords']) ? $config['meta']['keywords'] : '';
             // limited
             $metadesc = isset($config['meta']) && isset($config['meta']['description']) ? $config['meta']['description'] : '';
             $robots = '';
             $author = '';
             $rights = '';
             // an exception regarding limited options for language
             if (!isset($config['params'])) {
                 $ex = explode('-', $language);
                 $sef = '';
                 if (count($ex)) {
                     $sef = strtolower($ex[0]);
                 }
                 if ($form['article_record_impact_language']) {
                     $db->setQuery("Update #__contentbuilder_records Set sef = " . $db->Quote($sef) . ", lang_code = " . $db->Quote($language) . " Where `type` = " . $db->Quote($form['type']) . " And reference_id = " . $db->Quote($form['reference_id']) . " And record_id = " . $db->Quote($record_id));
                     $db->query();
                 }
                 $registry = new JRegistry();
                 $attr = array('language' => $language);
                 $registry->loadArray($attr);
                 $attribs = (string) $registry->toString();
             }
             if (!$limited_options) {
                 // FULL
                 $created_by = isset($config['details']) && isset($config['details']['created_by']) ? $config['details']['created_by'] : 0;
                 // FULL
                 $created_article = isset($config['details']) && isset($config['details']['created']) ? $config['details']['created'] == JText::_('Never') ? '0000-00-00 00:00:00' : $config['details']['created'] : null;
                 // FULL
                 if (isset($config['params']) && is_array($config['params'])) {
                     if (isset($config['params']['language'])) {
                         if ($form['article_record_impact_language'] && $config['params']['language'] != $language) {
                             $ex = explode('-', $config['params']['language']);
                             $sef = '';
                             if (count($ex)) {
                                 $sef = strtolower($ex[0]);
                             }
                             $db->setQuery("Update #__contentbuilder_records Set sef = " . $db->Quote($sef) . ", lang_code = " . $db->Quote($config['params']['language']) . " Where `type` = " . $db->Quote($form['type']) . " And reference_id = " . $db->Quote($form['reference_id']) . " And record_id = " . $db->Quote($record_id));
                             $db->query();
                         } else {
                             $config['params']['language'] = $language;
                         }
                     }
                     $registry = new JRegistry();
                     $registry->loadArray($config['params']);
                     $attribs = (string) $registry->toString();
                 }
                 // FULL
                 if (isset($config['meta']) && is_array($config['meta'])) {
                     if (isset($config['meta']['robots'])) {
                         $robots = $config['meta']['robots'];
                     }
                     if (isset($config['meta']['author'])) {
                         $author = $config['meta']['author'];
                     }
                     if (isset($config['meta']['rights'])) {
                         $rights = $config['meta']['rights'];
                     }
                     $registry = new JRegistry();
                     $registry->loadArray($config['meta']);
                     $meta = (string) $registry->toString();
                 }
             }
             $db->setQuery("Update #__contentbuilder_records Set robots = " . $db->Quote($robots) . ", author = " . $db->Quote($author) . ", rights = " . $db->Quote($rights) . ", xreference = '', metakey = " . $db->Quote($metakey) . ", metadesc = " . $db->Quote($metadesc) . " Where `type` = " . $db->Quote($form['type']) . " And reference_id = " . $db->Quote($form['reference_id']) . " And record_id = " . $db->Quote($record_id));
             $db->query();
             $dispatcher = JDispatcher::getInstance();
             $isNew = true;
             $dispatcher = JDispatcher::getInstance();
             $table = JTable::getInstance('content');
             $isNew = true;
             if ($article > 0) {
                 $table->load($article);
                 $isNew = false;
             }
             $dispatcher->trigger('onBeforeContentSave', array(&$table, $isNew));
         }
     }
     $created_by = $created_by ? $created_by : $metadata->created_id;
     $date = JFactory::getDate();
     if (version_compare($version->getShortVersion(), '3.0', '>=')) {
         $created = $date->toSql();
     } else {
         $created = $date->toMySQL();
     }
     $created = $created_article ? $created_article : ($metadata->created ? $metadata->created : $created);
     if ($created && strlen(trim($created)) <= 10) {
         $created .= ' 00:00:00';
     }
     if (!$publish_up || $publish_up == '0000-00-00 00:00:00') {
         $publish_up = $created;
     }
     if (!$publish_down && !$article) {
         $publish_down = '0000-00-00 00:00:00';
     }
     $alias = $alias ? self::stringURLUnicodeSlug($alias) : self::stringURLUnicodeSlug($label);
     if (trim(str_replace('-', '', $alias)) == '') {
         $datenow = JFactory::getDate();
         if (version_compare($version->getShortVersion(), '3.0', '>=')) {
             $alias = $datenow->format("%Y-%m-%d-%H-%M-%S");
         } else {
             $alias = $datenow->toFormat("%Y-%m-%d-%H-%M-%S");
         }
     }
     // not existing, create
     if (!$article) {
         $db->setQuery("Insert Into \n                    #__content \n                        (\n                         `title`,\n                         `alias`,\n                         `introtext`,\n                         `fulltext`,\n                         `state`,\n                         " . ($is15 ? "`sectionid`," : '') . "\n                         `catid`,\n                         `created`,\n                         `created_by`,\n                         `modified`,\n                         `modified_by`,\n                         `checked_out`,\n                         `checked_out_time`,\n                         `publish_up`,\n                         `publish_down`,\n                         `attribs`,\n                         `version`,\n                         `metakey`,\n                         `metadesc`,\n                         `metadata`,\n                         `access`,\n                         `created_by_alias`,\n                         `ordering`\n                         " . (!$is15 ? ',featured' : '') . "\n                         " . (!$is15 ? ',language' : '') . "\n                         " . (!$is15 ? ',xreference' : '') . "\n                        ) \n                    Values \n                        (\n                          " . $db->Quote($label) . ",\n                          " . $db->Quote($alias) . ",\n                          " . $db->Quote($introtext) . ",\n                          " . $db->Quote($fulltext) . ",\n                          " . $db->Quote($state) . ",\n                          " . ($is15 ? intval($form['default_section']) . "," : '') . "\n                          " . intval($form['default_category']) . ",\n                          " . $db->Quote($created) . ",\n                          " . $db->Quote($created_by ? $created_by : JFactory::getUser()->get('id', 0)) . ",\n                          '0000-00-00 00:00:00',\n                          '0',\n                          '0',\n                          '0000-00-00 00:00:00',\n                          " . $db->Quote($publish_up) . ",\n                          " . $db->Quote($publish_down) . ",\n                          " . $db->Quote($attribs) . ",\n                          '1',\n                          " . $db->Quote($metakey) . ",\n                          " . $db->Quote($metadesc) . ",\n                          " . $db->Quote($meta) . ",\n                          " . $db->Quote($access) . ",\n                          " . $db->Quote($created_by_alias) . ",\n                          " . $db->Quote($ordering) . "\n                          " . (!$is15 ? ',' . $db->Quote($featured) : '') . "\n                          " . (!$is15 ? ',' . $db->Quote($language) : '') . "\n                          " . (!$is15 ? ',' . $db->Quote(is_array($config) && isset($config['metadata']) && is_array($config['metadata']) && isset($config['metadata']['xreference']) ? $config['metadata']['xreference'] : '') : '') . "\n                        )\n            ");
         $db->query();
         $article = $db->insertid();
         $datenow = JFactory::getDate();
         if (version_compare($version->getShortVersion(), '3.0', '>=')) {
             $___datenow = $datenow->toSql();
         } else {
             $___datenow = $datenow->toMySQL();
         }
         $db->setQuery("Insert Into #__contentbuilder_articles (`type`,`reference_id`,`last_update`,`article_id`,`record_id`,`form_id`) Values (" . $db->Quote($form['type']) . "," . $db->Quote($form['reference_id']) . "," . $db->Quote($___datenow) . ",{$article}," . $db->Quote($record_id) . "," . intval($contentbuilder_form_id) . ")");
         $db->query();
         $db->setQuery("Update #__content Set introtext = concat('<div style=\\'display:none;\\'><!--(cbArticleId:{$article})--></div>', introtext) Where id = {$article}");
         $db->query();
         // existing, update
     } else {
         $datenow = JFactory::getDate();
         if (version_compare($version->getShortVersion(), '3.0', '>=')) {
             $___datenow = $datenow->toSql();
         } else {
             $___datenow = $datenow->toMySQL();
         }
         $modified = $metadata->modified ? $metadata->modified : $___datenow;
         $modified_by = $metadata->modified_id ? $metadata->modified_id : JFactory::getUser()->get('id', 0);
         if ($full) {
             $db->setQuery("Update \n                        #__content \n                            Set\n                             `title` = " . $db->Quote($label) . ",\n                             `alias` = " . $db->Quote($alias) . ",\n                             `introtext` = " . $db->Quote('<div style=\'display:none;\'><!--(cbArticleId:' . $article . ')--></div>' . $introtext) . ",\n                             `fulltext` = " . $db->Quote($fulltext . '<div style=\'display:none;\'><!--(cbArticleId:' . $article . ')--></div>') . ",\n                             `state` = " . $db->Quote($state) . ",\n                             " . ($is15 ? "`sectionid` = " . intval($form['default_section']) . "," : '') . "\n                             `catid` = " . intval($form['default_category']) . ",\n                             `modified` = " . $db->Quote($modified) . ",\n                             `modified_by` = " . $db->Quote($modified_by ? $modified_by : JFactory::getUser()->get('id', 0)) . ",\n                             `attribs` = " . $db->Quote($attribs) . ",\n                             `metakey` = " . $db->Quote($metakey) . ",\n                             `metadesc` = " . $db->Quote($metadesc) . ",\n                             `metadata` = " . $db->Quote($meta) . ",\n                             `version` = `version`+1,\n                             `created` = " . $db->Quote($created) . ",\n                             `created_by` = " . $db->Quote($created_by) . ",\n                             `created_by_alias` = " . $db->Quote($created_by_alias) . ",\n                             `publish_up` = " . $db->Quote($publish_up) . ",\n                             `publish_down` = " . $db->Quote($publish_down) . ",\n                             `access` = " . $db->Quote($access) . ",\n                             `ordering` = " . $db->Quote($ordering) . "\n                             " . (!$is15 ? ',featured=' . $db->Quote($featured) : '') . "\n                             " . (!$is15 ? ',language=' . $db->Quote($language) : '') . "\n                             " . (!$is15 ? ',xreference=' . $db->Quote(is_array($config) && isset($config['metadata']) && is_array($config['metadata']) && isset($config['metadata']['xreference']) ? $config['metadata']['xreference'] : '') : '') . "\n                        Where id = {$article}\n                ");
         } else {
             $db->setQuery("Update \n                        #__content \n                            Set\n                             `title` = " . $db->Quote($label) . ",\n                             `alias` = " . $db->Quote($alias) . ",\n                             `introtext` = " . $db->Quote('<div style=\'display:none;\'><!--(cbArticleId:' . $article . ')--></div>' . $introtext) . ",\n                             `fulltext` = " . $db->Quote($fulltext . '<div style=\'display:none;\'><!--(cbArticleId:' . $article . ')--></div>') . ",\n                             `state` = " . $db->Quote($state) . ",\n                             `modified` = " . $db->Quote($modified) . ",\n                             `modified_by` = " . $db->Quote($modified_by ? $modified_by : JFactory::getUser()->get('id', 0)) . ",\n                             `version` = `version`+1\n                             " . (!$is15 ? ',language=' . $db->Quote($language) : '') . "\n                        Where id = {$article}\n                ");
         }
         $db->query();
         // here we do not limit to the form_id, as this is a record change and all articles should be notified
         if (version_compare($version->getShortVersion(), '3.0', '>=')) {
             $___datenow = $datenow->toSql();
         } else {
             $___datenow = $datenow->toMySQL();
         }
         $db->setQuery("Update #__contentbuilder_articles Set `last_update` = " . $db->Quote($___datenow) . " Where `type` = " . $db->Quote($form['type']) . " And form_id = " . intval($contentbuilder_form_id) . " And reference_id = " . $db->Quote($form['reference_id']) . " And record_id = " . $db->Quote($record_id));
         $db->query();
     }
     // Bind the rules.
     /*
             if ($full && !$is15 && $article && isset($config['rules']) && is_array($config['rules'])) {
                 
                 // Cleaning the rules
                 $new = array();
                 foreach($config['rules'] As $key => $the_rules){
                     foreach($the_rules As $key2 => $the_rule){
                         if(!isset($new[$key])){
                             $new[$key] = array();
                         }
                         if(trim($the_rule) != ''){
                             $new[$key][$key2] = intval($the_rule);
                         }
                     }
                 }
                 $config['rules'] = $new;
                 
                 $registry = new JRegistry();
                 $registry->loadArray($config['rules']);
                 $json_rules = (string) $registry;
                 
                 $cat_asset = JTable::getInstance('Asset');
                 $cat_asset->loadByName('com_content.category.' . $form['default_category']);
     
                 $article_asset = JTable::getInstance('Asset');
                 $article_asset->loadByName('com_content.article.' . $article);
                 
                 if($cat_asset->id != $article_asset->parent_id){
                     $article_asset->setLocation($cat_asset->id, 'last-child');
                 }
                 
                 $article_asset->name = 'com_content.article.'.$article;
                 $article_asset->rules = $json_rules;
                 $article_asset->title = $label;
                 
                 $article_asset->store();
                 
                 $db->setQuery("Update #__content Set asset_id = " . $article_asset->id. " Where id = " . $article);
                 $db->query();
             }*/
     if ($article && $is15) {
         $row = JTable::getInstance('content');
         if ($row->load($article)) {
             $row->reorder('sectionid = ' . (int) $form['default_section'] . ' And catid = ' . (int) $form['default_category'] . ' AND state >= 0');
         }
     } else {
         if ($article) {
             $row = JTable::getInstance('content');
             if ($row->load($article)) {
                 $row->reorder('catid = ' . (int) $form['default_category'] . ' AND state >= 0');
             }
         }
     }
     if (!$is15) {
         // cleaning cache
         // Trigger the onContentCleanCache event.
         $conf = JFactory::getConfig();
         $options = array('defaultgroup' => 'com_content', 'cachebase' => $conf->get('cache_path', JPATH_SITE . DS . 'cache'));
         $cache = JFactory::getCache('com_content');
         $cache->clean();
         $cache = JFactory::getCache('com_contentbuilder');
         $cache->clean();
         $dispatcher = JDispatcher::getInstance();
         $dispatcher->trigger('onContentCleanCache', $options);
         //// trigger onContentAfterSave event
         $isNew = true;
         $dispatcher = JDispatcher::getInstance();
         $table = JTable::getInstance('content');
         if ($article > 0) {
             $table->load($article);
             $isNew = false;
         }
         $dispatcher->trigger('onContentAfterSave', array('com_content.article', &$table, $isNew));
     } else {
         //if($article && $full){
         $frontpage = isset($config['frontpage']) ? $config['frontpage'] : $featured;
         if ($frontpage !== null) {
             if (!$frontpage) {
                 $query = 'Delete From #__content_frontpage Where content_id = ' . (int) $article;
                 $db->setQuery($query);
                 $db->query();
             } else {
                 $query = 'Select content_id From #__content_frontpage Where content_id = ' . (int) $article;
                 $db->setQuery($query);
                 if (!$db->loadResult()) {
                     $query = 'Insert Into #__content_frontpage (content_id) Values (' . (int) $article . ')';
                     $db->setQuery($query);
                     $db->query();
                 }
             }
             JTable::addIncludePath(JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_frontpage' . DS . 'tables');
             $fp = JTable::getInstance('frontpage', 'Table');
             $fp->reorder();
         }
         //}
         $cache = JFactory::getCache('com_content');
         $cache->clean();
         $cache = JFactory::getCache('com_contentbuilder');
         $cache->clean();
         $isNew = true;
         $table = JTable::getInstance('content');
         if ($article > 0) {
             $table->load($article);
             $isNew = false;
         }
         $dispatcher = JDispatcher::getInstance();
         $dispatcher->trigger('onAfterContentSave', array(&$table, $isNew));
     }
     JPluginHelper::importPlugin('contentbuilder_listaction');
     $dispatcher = JDispatcher::getInstance();
     $result = $dispatcher->trigger('onAfterArticleCreation', array($contentbuilder_form_id, $record_id, $article));
     $msg = implode('', $result);
     if ($msg) {
         JFactory::getApplication()->enqueueMessage($msg);
     }
     return $article;
 }
Ejemplo n.º 25
0
 function logToDatabase($cbResult = null)
 {
     // CONTENTBUILDER
     global $database, $ff_config;
     $database = JFactory::getDBO();
     if ($this->dying) {
         return;
     }
     if (!is_object($cbResult['form']) && $this->editable && $this->editable_override) {
         $database->setQuery("Select id From #__facileforms_records Where form = " . $database->Quote($this->form) . " And user_id = " . $database->Quote(JFactory::getUser()->get('id', 0)) . " And user_id <> 0");
         $records = $database->loadObjectList();
         foreach ($records as $record) {
             $database->setQuery("Delete From #__facileforms_subrecords Where record = " . $record->id);
             $database->query();
             $database->setQuery("Delete From #__facileforms_records Where id = " . $record->id);
             $database->query();
         }
     }
     $record = new facileFormsRecords($database);
     $record->submitted = $this->submitted;
     $record->form = $this->form;
     $record->title = $this->formrow->title;
     $record->name = $this->formrow->name;
     $record->ip = $this->ip;
     $record->browser = $this->browser;
     $record->opsys = $this->opsys;
     $record->provider = $this->provider;
     $record->viewed = 0;
     $record->exported = 0;
     $record->archived = 0;
     if (JFactory::getUser()->get('id', 0) > 0) {
         $record->user_id = JFactory::getUser()->get('id', 0);
         $record->username = JFactory::getUser()->get('username', '');
         $record->user_full_name = JFactory::getUser()->get('name', '');
     } else {
         $record->user_id = JFactory::getUser()->get('id', 0);
         $record->username = '******';
         $record->user_full_name = '-';
     }
     // CONTENTBUILDER WILL TAKE OVER SAVING/UPDATE IF EXISTS
     $cbFileFields = array();
     if (!is_object($cbResult['form'])) {
         if (!$record->store()) {
             $this->status = _FF_STATUS_SAVERECORD_FAILED;
             $this->message = $record->getError();
             return;
         }
         // if
         $record_return = $record->id;
         if ($record_return && JFile::exists(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_contentbuilder' . DS . 'contentbuilder.xml')) {
             $last_update = JFactory::getDate();
             jimport('joomla.version');
             $version = new JVersion();
             $is3 = false;
             if (version_compare($version->getShortVersion(), '3.0', '>=')) {
                 $is3 = true;
             }
             $last_update = $is3 ? $last_update->toSql() : $last_update->toMySQL();
             $db = JFactory::getDBO();
             $db->setQuery("Select id From #__contentbuilder_records Where `type` = 'com_breezingforms' And `reference_id` = " . $db->Quote($this->form) . " And record_id = " . $db->Quote($record_return));
             $res = $db->loadResult();
             if (!$res) {
                 $db->setQuery("Insert Into #__contentbuilder_records (session_id,`type`,last_update, published, record_id, reference_id) Values ('" . JFactory::getSession()->getId() . "','com_breezingforms'," . $db->Quote($last_update) . ",0, " . $db->Quote($record_return) . ", " . $db->Quote($this->form) . ")");
                 $db->query();
             } else {
                 $db->setQuery("Update #__contentbuilder_records Set last_update = " . $db->Quote($last_update) . ",edited = edited + 1 Where `type` = 'com_breezingforms' And `reference_id` = " . $db->Quote($this->form) . " And record_id = " . $db->Quote($record_return));
                 $db->query();
             }
         }
     }
     $this->record_id = $record->id;
     $names = array();
     $subrecord = new facileFormsSubrecords($database);
     $subrecord->record = $record->id;
     if (count($this->savedata)) {
         $cbData = array();
         // CONTENTBUILDER file deletion/upgrade
         if (is_object($cbResult['form'])) {
             $db = JFactory::getDBO();
             $db->setQuery('Select SQL_CALC_FOUND_ROWS * From #__contentbuilder_forms Where id = ' . JRequest::getInt('cb_form_id', 0) . ' And published = 1');
             $_settings = $db->loadObject();
             $_record = $cbResult['form']->getRecord(JRequest::getInt('record_id', 0), $_settings->published_only, $cbResult['frontend'] ? $_settings->own_only_fe ? JFactory::getUser()->get('id', 0) : -1 : ($_settings->own_only ? JFactory::getUser()->get('id', 0) : -1), true);
             foreach ($_record as $_rec) {
                 $_files_deleted = array();
                 if ($_rec->recType == 'File Upload') {
                     $_array = JRequest::getVar('cb_delete_' . $_rec->recElementId, array(), '', 'ARRAY');
                     foreach ($_array as $_key => $_arr) {
                         if ($_arr == 1) {
                             $_values = explode("\n", $_rec->recValue);
                             if (isset($_values[$_key])) {
                                 if (strpos(strtolower($_values[$_key]), '{cbsite}') === 0) {
                                     $_values[$_key] = str_replace(array('{cbsite}', '{CBSite}'), array(JPATH_SITE, JPATH_SITE), $_values[$_key]);
                                 }
                                 if (JFile::exists($_values[$_key])) {
                                     JFile::delete($_values[$_key]);
                                 }
                                 if (!isset($_files_deleted[$_rec->recElementId])) {
                                     $_files_deleted[$_rec->recElementId] = array();
                                 }
                                 $_files_deleted[$_rec->recElementId][] = $_key;
                             }
                         }
                     }
                     if (isset($_files_deleted[$_rec->recElementId]) && is_array($_files_deleted[$_rec->recElementId]) && count($_files_deleted[$_rec->recElementId])) {
                         $_i = 0;
                         foreach ($this->savedata as $data) {
                             if ($data[_FF_DATA_ID] == $_rec->recElementId) {
                                 $_is_values = explode("\n", $_rec->recValue);
                                 $_j = 0;
                                 foreach ($_is_values as $_is_value) {
                                     if (!in_array($_j, $_files_deleted[$_rec->recElementId])) {
                                         $this->savedata[$_i][_FF_DATA_VALUE] .= $_is_value . "\n";
                                     }
                                     $_j++;
                                 }
                                 $this->savedata[$_i][_FF_DATA_VALUE] = rtrim($this->savedata[$_i][_FF_DATA_VALUE]);
                                 break;
                             }
                             $_i++;
                         }
                     } else {
                         if (true) {
                             $next = count($this->savedata);
                             $this->savedata[$next] = array();
                             $this->savedata[$next][_FF_DATA_ID] = $_rec->recElementId;
                             $this->savedata[$next][_FF_DATA_NAME] = $_rec->recName;
                             $this->savedata[$next][_FF_DATA_TITLE] = $_rec->recTitle;
                             $this->savedata[$next][_FF_DATA_TYPE] = $_rec->recType;
                             $this->savedata[$next][_FF_DATA_VALUE] = '';
                             $_is_values = explode("\n", $_rec->recValue);
                             foreach ($_is_values as $_is_value) {
                                 $this->savedata[$next][_FF_DATA_VALUE] .= $_is_value . "\n";
                             }
                             $this->savedata[$next][_FF_DATA_VALUE] = rtrim($this->savedata[$next][_FF_DATA_VALUE]);
                         }
                     }
                 }
             }
         }
         $_savedata = array();
         if (!is_object($cbResult['form'])) {
             foreach ($this->savedata as $data) {
                 if ($data[_FF_DATA_TYPE] == 'File Upload') {
                     if (!isset($_savedata[$data[_FF_DATA_ID]])) {
                         $_savedata[$data[_FF_DATA_ID]] = '';
                     }
                     $_savedata[$data[_FF_DATA_ID]] .= $data[_FF_DATA_VALUE] . "\n";
                 }
             }
         }
         $isset = array();
         foreach ($this->savedata as $data) {
             // CONTENTBUILDER WILL TAKE OVER SAVING/UPDATE IF EXISTS
             if (!is_object($cbResult['form'])) {
                 $subrecord->id = NULL;
                 $subrecord->element = $data[_FF_DATA_ID];
                 $subrecord->name = $data[_FF_DATA_NAME];
                 $subrecord->title = $data[_FF_DATA_TITLE];
                 $subrecord->type = $data[_FF_DATA_TYPE];
                 if (isset($_savedata[$data[_FF_DATA_ID]]) && !isset($isset[$data[_FF_DATA_ID]])) {
                     $subrecord->value = trim($_savedata[$data[_FF_DATA_ID]]);
                 } else {
                     $subrecord->value = $data[_FF_DATA_VALUE];
                 }
                 if (!isset($isset[$data[_FF_DATA_ID]])) {
                     if (!$subrecord->store()) {
                         $this->status = _FF_STATUS_SAVESUBRECORD_FAILED;
                         $this->message = $subrecord->getError();
                         return;
                     }
                 }
                 if ($data[_FF_DATA_TYPE] == 'File Upload') {
                     $isset[$data[_FF_DATA_ID]] = true;
                 }
             } else {
                 require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_contentbuilder' . DS . 'classes' . DS . 'contentbuilder.php';
                 $cbNonEditableFields = contentbuilder::getListNonEditableElements($cbResult['data']['id']);
                 if (!in_array($data[_FF_DATA_ID], $cbNonEditableFields)) {
                     switch ($data[_FF_DATA_TYPE]) {
                         case 'Checkbox':
                         case 'Checkbox Group':
                         case 'Radio Button':
                         case 'Radio Group':
                         case 'Select List':
                             if (!isset($cbData[$data[_FF_DATA_ID]])) {
                                 $cbData[$data[_FF_DATA_ID]] = array();
                             }
                             $cbData[$data[_FF_DATA_ID]][] = $data[_FF_DATA_VALUE];
                             break;
                         case 'File Upload':
                             if (!isset($cbData[$data[_FF_DATA_ID]])) {
                                 $cbData[$data[_FF_DATA_ID]] = '';
                                 $cbFileFields[] = $data[_FF_DATA_ID];
                             }
                             $cbData[$data[_FF_DATA_ID]] .= $data[_FF_DATA_VALUE] . "\n";
                             break;
                         default:
                             $cbData[$data[_FF_DATA_ID]] = $data[_FF_DATA_VALUE];
                     }
                 }
             }
         }
         // foreach
         // CONTENTBUILDER BEGIN
         if (is_object($cbResult['form'])) {
             JPluginHelper::importPlugin('contentbuilder_submit');
             $submit_dispatcher = JDispatcher::getInstance();
             jimport('joomla.version');
             $version = new JVersion();
             $is15 = true;
             if (version_compare($version->getShortVersion(), '1.6', '>=')) {
                 $is15 = false;
             }
             $values = array();
             $names = $cbResult['form']->getAllElements();
             foreach ($names as $id => $name) {
                 if (isset($cbData[$id])) {
                     if (in_array($id, $cbFileFields) && trim($cbData[$id]) == '') {
                         $values[$id] = '';
                     } else {
                         if (in_array($id, $cbFileFields) && trim($cbData[$id]) != '') {
                             $values[$id] = trim($cbData[$id]);
                         } else {
                             $values[$id] = $cbData[$id];
                         }
                     }
                 }
             }
             $submit_before_result = $submit_dispatcher->trigger('onBeforeSubmit', array(JRequest::getInt('cb_record_id', 0), $cbResult['form'], $values));
             $record_return = $cbResult['form']->saveRecord(JRequest::getInt('cb_record_id', 0), $values);
             $db = JFactory::getDBO();
             $db->setQuery('Select SQL_CALC_FOUND_ROWS * From #__contentbuilder_forms Where id = ' . JRequest::getInt('cb_form_id', 0) . ' And published = 1');
             $cbData = $db->loadObject();
             if ($record_return) {
                 $this->record_id = $record_return;
                 $sef = '';
                 $ignore_lang_code = '*';
                 if ($cbResult['data']['default_lang_code_ignore']) {
                     jimport('joomla.version');
                     $version = new JVersion();
                     if (version_compare($version->getShortVersion(), '1.6', '>=')) {
                         $db->setQuery("Select lang_code From #__languages Where published = 1 And sef = " . $db->Quote(trim(JRequest::getCmd('lang', ''))));
                         $ignore_lang_code = $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', '>=')) {
                         $db->setQuery("Select sef From #__languages Where published = 1 And lang_code = " . $db->Quote($cbResult['data']['default_lang_code']));
                         $sef = $db->loadResult();
                     } else {
                         $codes = contentbuilder::getLanguageCodes();
                         foreach ($codes as $code) {
                             if ($code == $cbResult['data']['default_lang_code']) {
                                 $sef = explode('-', $code);
                                 if (count($sef)) {
                                     $sef = strtolower($sef[0]);
                                 }
                                 break;
                             }
                         }
                     }
                 }
                 $language = $cbResult['data']['default_lang_code_ignore'] ? $ignore_lang_code : $cbResult['data']['default_lang_code'];
                 $db->setQuery("Select id From #__contentbuilder_records Where `type` = 'com_breezingforms' And `reference_id` = " . $db->Quote($cbResult['form']->getReferenceId()) . " And record_id = " . $db->Quote($record_return));
                 $res = $db->loadResult();
                 $last_update = JFactory::getDate();
                 $version = new JVersion();
                 $is3 = false;
                 if (version_compare($version->getShortVersion(), '3.0', '>=')) {
                     $is3 = true;
                 }
                 $last_update = $is3 ? $last_update->toSql() : $last_update->toMySQL();
                 if (!$res) {
                     $is_future = 0;
                     $created_up = JFactory::getDate();
                     $created_up = $is3 ? $created_up->toSql() : $created_up->toMySQL();
                     if (intval($cbData->default_publish_up_days) != 0) {
                         $is_future = 1;
                         $date = JFactory::getDate(strtotime('now +' . intval($cbData->default_publish_up_days) . ' days'));
                         $created_up = $is3 ? $date->toSql() : $date->toMySQL();
                     }
                     $created_down = '0000-00-00 00:00:00';
                     if (intval($cbData->default_publish_down_days) != 0) {
                         $date = JFactory::getDate(strtotime($created_up . ' +' . intval($cbData->default_publish_down_days) . ' days'));
                         $created_down = $is3 ? $date->toSql() : $date->toMySQL();
                     }
                     $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() . "','com_breezingforms'," . $db->Quote($last_update) . ",{$is_future}, " . $db->Quote($language) . "," . $db->Quote(trim($sef)) . "," . $db->Quote($cbData->auto_publish && !$is_future ? 1 : 0) . ", " . $db->Quote($record_return) . ", " . $db->Quote($cbResult['form']->getReferenceId()) . ", " . $db->Quote($created_up) . ", " . $db->Quote($created_down) . ")");
                     $db->query();
                 } else {
                     $db->setQuery("Update #__contentbuilder_records Set last_update = " . $db->Quote($last_update) . ",lang_code = " . $db->Quote($language) . ", sef = " . $db->Quote(trim($sef)) . ", edited = edited + 1 Where `type` = 'com_breezingforms' And `reference_id` = " . $db->Quote($cbResult['form']->getReferenceId()) . " And record_id = " . $db->Quote($record_return));
                     $db->query();
                 }
             }
             $article_id = 0;
             // creating the article
             if (is_object($cbData) && $cbData->create_articles) {
                 JRequest::setVar('cb_category_id', null);
                 JRequest::setVar('cb_controller', null);
                 jimport('joomla.version');
                 $version = new JVersion();
                 if (JFactory::getApplication()->isSite() && JRequest::getInt('Itemid', 0)) {
                     if (version_compare($version->getShortVersion(), '1.6', '>=')) {
                         $menu = JSite::getMenu();
                         $item = $menu->getActive();
                         if (is_object($item)) {
                             JRequest::setVar('cb_category_id', $item->params->get('cb_category_id', null));
                             JRequest::setVar('cb_controller', $item->params->get('cb_controller', null));
                         }
                     } else {
                         $params = JComponentHelper::getParams('com_contentbuilder');
                         JRequest::setVar('cb_category_id', $params->get('cb_category_id', null));
                         JRequest::setVar('cb_controller', $params->get('cb_controller', null));
                     }
                 }
                 $cbData->page_title = $cbData->use_view_name_as_title ? $cbData->name : $cbResult['form']->getPageTitle();
                 $cbData->labels = $cbResult['form']->getElementLabels();
                 $ids = array();
                 foreach ($cbData->labels as $reference_id => $label) {
                     $ids[] = $db->Quote($reference_id);
                 }
                 $cbData->labels = array();
                 if (count($ids)) {
                     $db->setQuery("Select Distinct `label`, reference_id From #__contentbuilder_elements Where form_id = " . JRequest::getInt('cb_form_id', 0) . " And reference_id In (" . implode(',', $ids) . ") And published = 1 Order By ordering");
                     $rows = $db->loadAssocList();
                     $ids = array();
                     foreach ($rows as $row) {
                         $ids[] = $row['reference_id'];
                     }
                 }
                 $cbData->items = $cbResult['form']->getRecord($record_return, $cbData->published_only, $cbResult['frontend'] ? $cbData->own_only_fe ? JFactory::getUser()->get('id', 0) : -1 : ($cbData->own_only ? JFactory::getUser()->get('id', 0) : -1), true);
                 if (!count($cbData->items)) {
                     JError::raiseError(404, JText::_('COM_CONTENTBUILDER_RECORD_NOT_FOUND'));
                 }
                 $config = array();
                 $full = false;
                 $article_id = contentbuilder::createArticle(JRequest::getInt('cb_form_id', 0), $record_return, $cbData->items, $ids, $cbData->title_field, $cbResult['form']->getRecordMetadata($record_return), $config, $full, true, JRequest::getVar('cb_category_id', null));
                 $cache = JFactory::getCache('com_content');
                 $cache->clean();
                 $cache = JFactory::getCache('com_contentbuilder');
                 $cache->clean();
             }
             $submit_after_result = $submit_dispatcher->trigger('onAfterSubmit', array($record_return, $article_id, $cbResult['form'], $values));
         }
         // CONTENTBUILDER END
         // joomla 3 tagging
         $db = JFactory::getDBO();
         jimport('joomla.version');
         $version = new JVersion();
         if (version_compare($version->getShortVersion(), '3.1', '>=') && $this->formrow->tags_content != '') {
             $title = '';
             $tags_body = '';
             if (trim($this->formrow->tags_content_template) == '') {
                 $lol = 0;
                 $tags_body = '<ul class="category list-striped list-condensed">' . "\n";
                 foreach ($this->savedata as $data) {
                     if ($data[_FF_DATA_ID] == $this->formrow->tags_content_template_default_element) {
                         $title = $data[_FF_DATA_VALUE];
                     }
                     if ($lol == 1) {
                         $lol = 0;
                     }
                     $tagvalue = '';
                     if (is_array($data[_FF_DATA_VALUE])) {
                         $tagvalue = implode(', ', $data[_FF_DATA_VALUE]);
                     } else {
                         $tagvalue = $data[_FF_DATA_VALUE];
                     }
                     $tagvalue = bf_cleanString($tagvalue);
                     $tags_body .= '<li class="cat-list-row' . $lol . '"><strong class="list-title">' . htmlentities($data[_FF_DATA_TITLE], ENT_QUOTES, 'UTF-8') . '</strong><div>' . htmlentities($tagvalue, ENT_QUOTES, 'UTF-8') . '</div></li>' . "\n";
                     $lol++;
                 }
                 $tags_body .= '</ul>' . "\n";
             } else {
                 $tags_body = $this->formrow->tags_content_template;
                 foreach ($this->savedata as $data) {
                     if ($data[_FF_DATA_ID] == $this->formrow->tags_content_template_default_element) {
                         $title = $data[_FF_DATA_VALUE];
                     }
                     $tagvalue = '';
                     if (is_array($data[_FF_DATA_VALUE])) {
                         $tagvalue = implode(', ', $data[_FF_DATA_VALUE]);
                     } else {
                         $tagvalue = $data[_FF_DATA_VALUE];
                     }
                     $tagvalue = bf_cleanString($tagvalue);
                     $tags_body = str_replace('{' . $data[_FF_DATA_NAME] . ':label}', htmlentities($data[_FF_DATA_TITLE], ENT_QUOTES, 'UTF-8'), $tags_body);
                     $tags_body = str_replace('{' . $data[_FF_DATA_NAME] . ':value}', htmlentities($tagvalue, ENT_QUOTES, 'UTF-8'), $tags_body);
                 }
                 $matches = array();
                 preg_match_all("/\\{BFImageScale([^}]*)\\}/i", $tags_body, $matches);
                 if (isset($matches[0]) && isset($matches[1]) && is_array($matches[1]) && count($matches[1]) > 0) {
                     $i = 0;
                     foreach ($matches[1] as $match) {
                         $options = explode(';', trim($match));
                         $options_length = count($options);
                         for ($x = 0; $x < $options_length; $x++) {
                             $options[$x] = trim($options[$x]);
                             if ($options[$x] == '') {
                                 unset($options[$x]);
                             }
                         }
                         $options[] = 'record-id: ' . $this->record_id;
                         $options[] = 'form-id: ' . $this->form;
                         $out = implode('; ', $options);
                         $tags_body = str_replace($matches[0][$i], '{BFImageScale ' . $out . '}', $tags_body);
                         $i++;
                     }
                 }
                 $matches = array();
                 preg_match_all("/\\{BFDownload([^}]*)\\}/i", $tags_body, $matches);
                 if (isset($matches[0]) && isset($matches[1]) && is_array($matches[1]) && count($matches[1]) > 0) {
                     $i = 0;
                     foreach ($matches[1] as $match) {
                         $options = explode(';', trim($match));
                         $options_length = count($options);
                         for ($x = 0; $x < $options_length; $x++) {
                             $options[$x] = trim($options[$x]);
                             if ($options[$x] == '') {
                                 unset($options[$x]);
                             }
                         }
                         $options[] = 'record-id: ' . $this->record_id;
                         $options[] = 'form-id: ' . $this->form;
                         $out = implode('; ', $options);
                         $tags_body = str_replace($matches[0][$i], '{BFDownload ' . $out . '}', $tags_body);
                         $i++;
                     }
                 }
             }
             if (trim($title) == '' && isset($this->savedata[0])) {
                 $title = $this->savedata[0][_FF_DATA_TITLE];
             } else {
                 if (trim($title) == '' && !isset($this->savedata[0])) {
                     $title = 'Unknown';
                 }
             }
             $tag_date = JFactory::getDate();
             // Clean text for xhtml transitional compliance
             $introtext = '';
             $fulltext = '';
             $tags_body = str_replace('<br>', '<br />', $tags_body);
             // Search for the {readmore} tag and split the text up accordingly.
             $pattern = '#<hr\\s+id=("|\')system-readmore("|\')\\s*\\/*>#i';
             $tagPos = preg_match($pattern, $tags_body);
             if ($tagPos == 0) {
                 $introtext = $tags_body;
             } else {
                 list($introtext, $fulltext) = preg_split($pattern, $tags_body, 2);
             }
             $db->setQuery("Insert Into \n                    #__content \n                        (\n                         `title`,\n                         `alias`,\n                         `introtext`,\n                         `fulltext`,\n                         `state`,\n                         `catid`,\n                         `created`,\n                         `created_by`,\n                         `modified`,\n                         `modified_by`,\n                         `checked_out`,\n                         `checked_out_time`,\n                         `publish_up`,\n                         `publish_down`,\n                         `attribs`,\n                         `version`,\n                         `metakey`,\n                         `metadesc`,\n                         `metadata`,\n                         `access`,\n                         `created_by_alias`,\n                         `language`,\n                         `featured`\n                        ) \n                    Values \n                        (\n                          " . $db->quote($title) . ",\n                          " . $db->quote(bf_stringURLUnicodeSlug($item_id . '-' . $title)) . ",\n                          " . $db->quote($introtext) . ",\n                          " . $db->quote($fulltext) . ",\n                          " . intval($this->formrow->tags_content_default_state) . ",\n                          " . intval($this->formrow->tags_content_default_category) . ",\n                          '" . $tag_date->toSql() . "',\n                          " . $db->quote(JFactory::getUser()->get('id', 0)) . ",\n                          '" . $tag_date->toSql() . "',\n                          " . $db->quote(JFactory::getUser()->get('id', 0)) . ",\n                          '0',\n                          '0000-00-00 00:00:00',\n                          '" . ($this->formrow->tags_content_default_publishup == '' || $this->formrow->tags_content_default_publishup == '0000-00-00 00:00:00' ? $tag_date->toSql() : $this->formrow->tags_content_default_publishup) . "',\n                          '" . ($this->formrow->tags_content_default_publishdown == '' || $this->formrow->tags_content_default_publishdown == '0000-00-00 00:00:00' ? '0000-00-00 00:00:00' : $this->formrow->tags_content_default_publishdown) . "',\n                          '',\n                          '1',\n                          '',\n                          '',\n                          '',\n                          " . intval($this->formrow->tags_content_default_access) . ",\n                          " . $db->quote(JFactory::getUser()->get('username', 'Anonymous')) . ",\n                          " . $db->quote($this->formrow->tags_content_default_language) . ",\n                          " . intval($this->formrow->tags_content_default_featured) . "\n                       )\n                ");
             $db->query();
             $item_id = $db->insertid();
             JFactory::getDbo()->setQuery("Select type_id From #__content_types Where type_alias = 'com_content.article'");
             $tag_typeid = JFactory::getDbo()->loadResult();
             $db->setQuery("Insert Into #__ucm_content (\n                    core_catid,\n                    core_content_item_id,\n                    core_type_alias, \n                    core_title, \n                    core_alias, \n                    core_body, \n                    core_created_time,\n                    core_modified_time,\n                    core_created_user_id,\n                    core_created_by_alias,\n                    core_modified_user_id,\n                    core_state,\n                    core_access,\n                    core_language,\n                    core_type_id,\n                    core_featured,\n                    core_publish_up,\n                    core_publish_down\n                 ) Values (\n                    " . intval($this->formrow->tags_content_default_category) . ",\n                    '" . $item_id . "',\n                    'com_content.article',\n                    " . $db->quote($title) . ",\n                    " . $db->quote(bf_stringURLUnicodeSlug($title)) . ",\n                    " . $db->quote($tags_body) . ",\n                    '" . $tag_date->toSql() . "',\n                    '" . $tag_date->toSql() . "',\n                    " . $db->quote(JFactory::getUser()->get('id', 0)) . ",\n                    " . $db->quote(JFactory::getUser()->get('username', 'Anonymous')) . ",\n                    " . $db->quote(JFactory::getUser()->get('id', 0)) . ",\n                    " . intval($this->formrow->tags_content_default_state) . ",\n                    " . intval($this->formrow->tags_content_default_access) . ",\n                    " . $db->quote($this->formrow->tags_content_default_language) . ",\n                    " . intval($tag_typeid) . ",\n                    " . intval($this->formrow->tags_content_default_featured) . ",\n                    '" . ($this->formrow->tags_content_default_publishup == '' || $this->formrow->tags_content_default_publishup == '0000-00-00 00:00:00' ? $tag_date->toSql() : $this->formrow->tags_content_default_publishup) . "',\n                    '" . ($this->formrow->tags_content_default_publishdown == '' || $this->formrow->tags_content_default_publishdown == '0000-00-00 00:00:00' ? '0000-00-00 00:00:00' : $this->formrow->tags_content_default_publishdown) . "'\n                 )");
             $db->query();
             $ucm_id = $db->insertid();
             JFactory::getDbo()->setQuery("Select lang_id From #__languages Where lang_code=" . $db->quote($this->formrow->tags_content_default_language));
             $lang_id = JFactory::getDbo()->loadColumn();
             JFactory::getDbo()->setQuery("Insert Into #__ucm_base (\n                    ucm_id, \n                    ucm_item_id, \n                    ucm_type_id, \n                    ucm_language_id\n                 ) Values (\n                    " . $ucm_id . ",\n                    " . $item_id . ",\n                    " . intval($tag_typeid) . ",\n                    " . ($lang_id ? intval($lang_id) : 0) . "\n                 )");
             JFactory::getDbo()->query();
             $tags_content = explode(',', $this->formrow->tags_content);
             JArrayHelper::toInteger($tags_content);
             foreach ($tags_content as $tags_content_entry) {
                 JFactory::getDbo()->setQuery("Insert Into #__contentitem_tag_map (\n                        type_alias, \n                        core_content_id, \n                        content_item_id, \n                        tag_id, \n                        tag_date, \n                        type_id\n                     ) Values (\n                        'com_content.article',\n                        " . $ucm_id . ",\n                        " . $item_id . ",\n                        " . $tags_content_entry . ",\n                        '" . $tag_date->toSql() . "',\n                        " . $tag_typeid . "\n                     )");
                 try {
                     JFactory::getDbo()->query();
                 } catch (Exception $e) {
                 }
             }
         }
         // joomla 3 tagging end
     }
     require_once JPATH_SITE . '/administrator/components/com_breezingforms/libraries/crosstec/classes/BFIntegrate.php';
     $integrate = new BFIntegrate($this->form);
     if (count($this->savedata)) {
         foreach ($this->savedata as $data) {
             $integrate->field($data);
         }
     }
     $integrate->commit();
     if (isset($record_return)) {
         return $record_return;
     }
 }
Ejemplo n.º 26
0
 function display($tpl = null)
 {
     // Get data from the model
     $subject = $this->get('Data');
     if (!class_exists('cbFeMarker')) {
         echo '
         <style type="text/css">
         .icon-48-logo_left { background-image: url(../administrator/components/com_contentbuilder/views/logo_left.png); }
         </style>
         ';
         jimport('joomla.version');
         $version = new JVersion();
         if (version_compare($version->getShortVersion(), '3.0', '<')) {
             JToolBarHelper::title('<img src="components/com_contentbuilder/views/logo_right.png" alt="" align="top" /> <span style="display:inline-block; vertical-align:middle"> :: ' . $subject->page_title . '</span>', 'logo_left.png');
         } else {
             JToolBarHelper::title($subject->page_title . '</span>', 'logo_left.png');
         }
     }
     $event = new stdClass();
     JFactory::getDBO()->setQuery("Select articles.`article_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($subject->form_id) . " And articles.record_id = " . JFactory::getDBO()->Quote($subject->record_id));
     $article = JFactory::getDBO()->loadResult();
     $table = JTable::getInstance('content');
     jimport('joomla.version');
     $version = new JVersion();
     // required for pagebreak plugin
     JRequest::setVar('view', 'article');
     if (version_compare($version->getShortVersion(), '1.6', '>=')) {
         require_once JPATH_SITE . DS . 'components' . DS . 'com_content' . DS . 'helpers' . DS . 'route.php';
         $isNew = true;
         if ($article > 0) {
             $table->load($article);
             $isNew = false;
         }
         $table->cbrecord = $subject;
         $table->text = $table->cbrecord->template;
         $alias = $table->alias ? contentbuilder::stringURLUnicodeSlug($table->alias) : contentbuilder::stringURLUnicodeSlug($subject->page_title);
         if (trim(str_replace('-', '', $alias)) == '') {
             $datenow = JFactory::getDate();
             $alias = $datenow->toFormat("%Y-%m-%d-%H-%M-%S");
         }
         // we pass the slug with a flag in the end, and see in the end if the slug has been used in the output
         $table->slug = ($article > 0 ? $article : 0) . ':' . $alias . ':contentbuilder_slug_used';
         $registry = new JRegistry();
         if (version_compare($version->getShortVersion(), '3.0', '>=')) {
             $registry->loadString($table->attribs);
         } else {
             $registry->loadJSON($table->attribs);
         }
         JPluginHelper::importPlugin('content');
         $dispatcher = JDispatcher::getInstance();
         // seems to be a joomla bug. if sef urls is enabled, "start" is used for paging in articles, else "limitstart" will be used
         $limitstart = JRequest::getVar('limitstart', 0, '', 'int');
         $start = JRequest::getVar('start', 0, '', 'int');
         $dispatcher->trigger('onContentPrepare', array('com_content.article', &$table, &$registry, $limitstart ? $limitstart : $start));
         $subject->template = $table->text;
         $results = $dispatcher->trigger('onContentAfterTitle', array('com_content.article', &$table, &$registry, $limitstart ? $limitstart : $start));
         $event->afterDisplayTitle = trim(implode("\n", $results));
         $results = $dispatcher->trigger('onContentBeforeDisplay', array('com_content.article', &$table, &$registry, $limitstart ? $limitstart : $start));
         $event->beforeDisplayContent = trim(implode("\n", $results));
         $results = $dispatcher->trigger('onContentAfterDisplay', array('com_content.article', &$table, &$registry, $limitstart ? $limitstart : $start));
         $event->afterDisplayContent = trim(implode("\n", $results));
         // if the slug has been used, we would like to stay in com_contentbuilder, so we re-arrange the resulting url a little
         if (strstr($subject->template, 'contentbuilder_slug_used') !== false) {
             $matches = array(array(), array());
             preg_match_all("/\\\"([^\"]*contentbuilder_slug_used[^\"]*)\\\"/i", $subject->template, $matches);
             foreach ($matches[1] as $match) {
                 $sub = '';
                 $parameters = explode('?', $match);
                 if (count($parameters) == 2) {
                     $parameters[1] = str_replace('&amp;', '&', $parameters[1]);
                     $parameter = explode('&', $parameters[1]);
                     foreach ($parameter as $par) {
                         $keyval = explode('=', $par);
                         if ($keyval[0] != '' && $keyval[0] != 'option' && $keyval[0] != 'id' && $keyval[0] != 'record_id' && $keyval[0] != 'view' && $keyval[0] != 'catid' && $keyval[0] != 'Itemid' && $keyval[0] != 'lang') {
                             $sub .= '&' . $keyval[0] . '=' . (isset($keyval[1]) ? $keyval[1] : '');
                         }
                     }
                 }
                 $subject->template = str_replace($match, JRoute::_('index.php?option=com_contentbuilder&controller=details&id=' . JRequest::getInt('id') . '&record_id=' . JRequest::getCmd('record_id', '') . '&Itemid=' . JRequest::getInt('Itemid', 0) . $sub), $subject->template);
             }
         }
         // the same for the case a toc has been created
         if (isset($table->toc) && strstr($table->toc, 'contentbuilder_slug_used') !== false) {
             preg_match_all("/\\\"([^\"]*contentbuilder_slug_used[^\"]*)\\\"/i", $table->toc, $matches);
             foreach ($matches[1] as $match) {
                 $sub = '';
                 $parameters = explode('?', $match);
                 if (count($parameters) == 2) {
                     $parameters[1] = str_replace('&amp;', '&', $parameters[1]);
                     $parameter = explode('&', $parameters[1]);
                     foreach ($parameter as $par) {
                         $keyval = explode('=', $par);
                         if ($keyval[0] != '' && $keyval[0] != 'option' && $keyval[0] != 'id' && $keyval[0] != 'record_id' && $keyval[0] != 'view' && $keyval[0] != 'catid' && $keyval[0] != 'Itemid' && $keyval[0] != 'lang') {
                             $sub .= '&' . $keyval[0] . '=' . (isset($keyval[1]) ? $keyval[1] : '');
                         }
                     }
                 }
                 $table->toc = str_replace($match, JRoute::_('index.php?option=com_contentbuilder&controller=details&id=' . JRequest::getInt('id') . '&record_id=' . JRequest::getCmd('record_id', '') . '&Itemid=' . JRequest::getInt('Itemid', 0) . $sub), $table->toc);
             }
         }
     } else {
         $params =& JComponentHelper::getParams('com_content');
         $isNew = true;
         if ($article > 0) {
             $table->load($article);
             $isNew = false;
         }
         $params->merge($table->attribs);
         $table->cbrecord = $subject;
         $table->text = $table->cbrecord->template;
         JPluginHelper::importPlugin('content');
         $dispatcher = JDispatcher::getInstance();
         $dispatcher->trigger('onPrepareContent', array(&$table, &$params, JRequest::getVar('limitstart', 0, '', 'int')));
         $subject->template = $table->text;
         $results = $dispatcher->trigger('onAfterDisplayTitle', array(&$table, &$params, JRequest::getVar('limitstart', 0, '', 'int')));
         $event->afterDisplayTitle = trim(implode("\n", $results));
         $results = $dispatcher->trigger('onBeforeDisplayContent', array(&$table, &$params, JRequest::getVar('limitstart', 0, '', 'int')));
         $event->beforeDisplayContent = trim(implode("\n", $results));
         $results = $dispatcher->trigger('onAfterDisplayContent', array(&$table, &$params, JRequest::getVar('limitstart', 0, '', 'int')));
         $event->afterDisplayContent = trim(implode("\n", $results));
     }
     if (!isset($table->toc)) {
         $table->toc = '';
     }
     $pattern = '#<hr\\s+id=("|\')system-readmore("|\')\\s*\\/*>#i';
     $subject->template = preg_replace($pattern, '', $subject->template);
     JPluginHelper::importPlugin('contentbuilder_themes', $subject->theme_plugin);
     $dispatcher = JDispatcher::getInstance();
     $results = $dispatcher->trigger('getContentTemplateCss', array());
     $this->assignRef('theme_css', implode('', $results));
     JPluginHelper::importPlugin('contentbuilder_themes', $subject->theme_plugin);
     $dispatcher = JDispatcher::getInstance();
     $results = $dispatcher->trigger('getContentTemplateJavascript', array());
     $this->assignRef('theme_js', implode('', $results));
     $this->assignRef('toc', $table->toc);
     $this->assignRef('event', $event);
     $this->assignRef('show_page_heading', $subject->show_page_heading);
     $this->assignRef('tpl', $subject->template);
     $this->assignRef('page_title', $subject->page_title);
     $this->assignRef('created', $subject->created);
     $this->assignRef('created_by', $subject->created_by);
     $this->assignRef('modified', $subject->modified);
     $this->assignRef('modified_by', $subject->modified_by);
     $this->assignRef('metadesc', $subject->metadesc);
     $this->assignRef('metakey', $subject->metakey);
     $this->assignRef('author', $subject->author);
     $this->assignRef('rights', $subject->rights);
     $this->assignRef('robots', $subject->robots);
     $this->assignRef('xreference', $subject->xreference);
     $this->assignRef('print_button', $subject->print_button);
     $this->assignRef('show_back_button', $subject->show_back_button);
     parent::display($tpl);
 }
Ejemplo n.º 27
0
 function display()
 {
     contentbuilder::checkPermissions('view', JText::_('COM_CONTENTBUILDER_PERMISSIONS_VIEW_NOT_ALLOWED'), class_exists('cbFeMarker') ? '_fe' : '');
     JRequest::setVar('tmpl', JRequest::getWord('tmpl', null));
     JRequest::setVar('layout', JRequest::getWord('layout', null) == 'latest' ? null : JRequest::getWord('layout', null));
     if (JRequest::getWord('view', '') == 'latest') {
         JRequest::setVar('cb_latest', 1);
     }
     JRequest::setVar('view', 'details');
     parent::display();
 }
Ejemplo n.º 28
0
echo JText::_('COM_CONTENTBUILDER_EDITABLE');
?>
</span>
                    </th>
                    <th>
                        <span class="editlinktip hasTip" title="<?php 
echo JText::_('COM_CONTENTBUILDER_LIST_WORDWRAP_TIP');
?>
" ><?php 
echo JText::_('COM_CONTENTBUILDER_LIST_WORDWRAP');
?>
</span>
                    </th>
                    <th width="150">
                        <span class="editlinktip hasTip" title="<?php 
echo contentbuilder::allhtmlentities(JText::_('COM_CONTENTBUILDER_LIST_ITEM_WRAPPER_TIP'));
?>
" ><?php 
echo JText::_('COM_CONTENTBUILDER_LIST_ITEM_WRAPPER');
?>
</span>
                    </th>
                    <th>
                        <?php 
echo JText::_('COM_CONTENTBUILDER_PUBLISHED');
?>
                    </th>
                    <th width="120">
                        <?php 
echo JHTML::_('grid.sort', JText::_('COM_CONTENTBUILDER_ORDERBY'), 'ordering', 'desc', @$this->lists['order'], 'edit');
?>
Ejemplo n.º 29
0
             <?php 
         echo htmlentities($row->colAuthor, ENT_QUOTES, 'UTF-8');
         ?>
             <?php 
     }
     ?>
         </td>
         <?php 
 }
 ?>
         <?php 
 if ($this->list_rating) {
     ?>
         <td class="hidden-phone">
             <?php 
     echo contentbuilder::getRating(JRequest::getInt('id', 0), $row->colRecord, $row->colRating, $this->rating_slots, JRequest::getCmd('lang', ''), $rating_allowed, $row->colRatingCount, $row->colRatingSum);
     ?>
         </td>
         <?php 
 }
 ?>
         <?php 
 $label_count = 0;
 $hidden = ' class="hidden-phone"';
 foreach ($row as $key => $value) {
     // filtering out disallowed columns
     if (in_array(str_replace('col', '', $key), $this->visible_cols)) {
         if ($label_count == 0) {
             $hidden = '';
         } else {
             $hidden = ' class="hidden-phone"';
Ejemplo n.º 30
0
 function store()
 {
     $db = JFactory::getDBO();
     $row = $this->getTable();
     $form = $this->getForm();
     $form_id = 0;
     $data = JRequest::get('post');
     $data['details_template'] = JRequest::getVar('details_template', '', 'POST', 'STRING', JREQUEST_ALLOWRAW);
     $data['editable_template'] = JRequest::getVar('editable_template', '', 'POST', 'STRING', JREQUEST_ALLOWRAW);
     $data['details_prepare'] = JRequest::getVar('details_prepare', '', 'POST', 'STRING', JREQUEST_ALLOWRAW);
     $data['editable_prepare'] = JRequest::getVar('editable_prepare', '', 'POST', 'STRING', JREQUEST_ALLOWRAW);
     $data['intro_text'] = JRequest::getVar('intro_text', '', 'POST', 'STRING', JREQUEST_ALLOWHTML);
     $data['editable'] = JRequest::getVar('editable', '', 'POST', 'STRING', JREQUEST_ALLOWHTML);
     $data['email_admin_template'] = JRequest::getVar('email_admin_template', '', 'POST', 'STRING', JREQUEST_ALLOWRAW);
     $data['email_template'] = JRequest::getVar('email_template', '', 'POST', 'STRING', JREQUEST_ALLOWRAW);
     #### SETTINGS
     $data['create_articles'] = JRequest::getInt('create_articles', 0);
     $data['protect_upload_directory'] = JRequest::getInt('protect_upload_directory', 0);
     //$data['upload_directory'] = JPATH_SITE . DS . 'media/contentbuilder/upload';
     //$data['protect_upload_directory'] = 1;
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.folder');
     // determine if it contains a replacement
     $tokens = '';
     $upl_ex = explode('|', $data['upload_directory']);
     $data['upload_directory'] = $upl_ex[0];
     $is_relative = strpos(strtolower($data['upload_directory']), '{cbsite}') === 0;
     $tmp_upload_directory = $data['upload_directory'];
     $upload_directory = $is_relative ? str_replace(array('{CBSite}', '{cbsite}'), JPATH_SITE, $data['upload_directory']) : $data['upload_directory'];
     $data['upload_directory'] = $upload_directory;
     $protect = $data['protect_upload_directory'];
     // if not exissting, we create the fallback directory
     if (!JFolder::exists($upload_directory)) {
         if (!JFolder::exists(JPATH_SITE . DS . 'media' . DS . 'contentbuilder')) {
             JFolder::create(JPATH_SITE . DS . 'media' . DS . 'contentbuilder');
             JFile::write(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'index.html', $def = '');
         }
         if (!JFolder::exists(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'upload')) {
             JFolder::create(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'upload');
             JFile::write(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'upload' . DS . 'index.html', $def = '');
             if ($protect) {
                 JFile::write(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'upload' . DS . '.htaccess', $def = 'deny from all');
             }
         }
         $data['upload_directory'] = JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'upload';
         if ($is_relative) {
             $tmp_upload_directory = '{CBSite}' . DS . 'media' . DS . 'contentbuilder' . DS . 'upload';
         }
         JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_FALLBACK_UPLOAD_CREATED') . ' (' . DS . 'media' . DS . 'contentbuilder' . DS . 'upload' . ')', 'warning');
     }
     if (isset($upl_ex[1])) {
         $tokens = '|' . $upl_ex[1];
     }
     if ($data['protect_upload_directory'] && JFolder::exists(contentbuilder::makeSafeFolder($data['upload_directory']))) {
         if (!JFile::exists(contentbuilder::makeSafeFolder($data['upload_directory']) . DS . 'index.html')) {
             JFile::write(contentbuilder::makeSafeFolder($data['upload_directory']) . DS . 'index.html', $def = '');
         }
     }
     if ($data['protect_upload_directory'] && JFolder::exists(contentbuilder::makeSafeFolder($data['upload_directory']))) {
         if (!JFile::exists(contentbuilder::makeSafeFolder($data['upload_directory']) . DS . '.htaccess')) {
             JFile::write(contentbuilder::makeSafeFolder($data['upload_directory']) . DS . '.htaccess', $def = 'deny from all');
         }
     } else {
         if (JFile::exists(contentbuilder::makeSafeFolder($data['upload_directory']) . DS . '.htaccess')) {
             JFile::delete(contentbuilder::makeSafeFolder($data['upload_directory']) . DS . '.htaccess');
         }
     }
     // reverting back to possibly including cbsite replacement
     $data['upload_directory'] = $tmp_upload_directory . $tokens;
     #### USERS
     $data['verification_required_view'] = JRequest::getInt('verification_required_view', 0);
     $data['verification_required_new'] = JRequest::getInt('verification_required_new', 0);
     $data['verification_required_edit'] = JRequest::getInt('verification_required_edit', 0);
     #### MISC
     $data['show_all_languages_fe'] = JRequest::getInt('show_all_languages_fe', 0);
     if (!$data['show_all_languages_fe'] && !$data['default_lang_code_ignore']) {
         JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_LANGUAGE_WARNING'), 'warning');
     }
     #### PERMISSIONS
     $gmap = array();
     $config = array();
     $config['permissions'] = array();
     $config['permissions_fe'] = array();
     $config['own'] = array();
     $config['own_fe'] = array();
     // backend
     if (isset($data['own']) && isset($data['own']['view']) && intval($data['own']['view']) == 1) {
         $config['own']['view'] = true;
     }
     if (isset($data['own']) && isset($data['own']['edit']) && intval($data['own']['edit']) == 1) {
         $config['own']['edit'] = true;
     }
     if (isset($data['own']) && isset($data['own']['delete']) && intval($data['own']['delete']) == 1) {
         $config['own']['delete'] = true;
     }
     if (isset($data['own']) && isset($data['own']['state']) && intval($data['own']['state']) == 1) {
         $config['own']['state'] = true;
     }
     if (isset($data['own']) && isset($data['own']['publish']) && intval($data['own']['publish']) == 1) {
         $config['own']['publish'] = true;
     }
     if (isset($data['own']) && isset($data['own']['fullarticle']) && intval($data['own']['fullarticle']) == 1) {
         $config['own']['fullarticle'] = true;
     }
     if (isset($data['own']) && isset($data['own']['listaccess']) && intval($data['own']['listaccess']) == 1) {
         $config['own']['listaccess'] = true;
     }
     if (isset($data['own']) && isset($data['own']['new']) && intval($data['own']['new']) == 1) {
         $config['own']['new'] = true;
     }
     if (isset($data['own']) && isset($data['own']['language']) && intval($data['own']['language']) == 1) {
         $config['own']['language'] = true;
     }
     if (isset($data['own']) && isset($data['own']['rating']) && intval($data['own']['rating']) == 1) {
         $config['own']['rating'] = true;
     }
     // frontend
     if (isset($data['own_fe']) && isset($data['own_fe']['view']) && intval($data['own_fe']['view']) == 1) {
         $config['own_fe']['view'] = true;
     }
     if (isset($data['own_fe']) && isset($data['own_fe']['edit']) && intval($data['own_fe']['edit']) == 1) {
         $config['own_fe']['edit'] = true;
     }
     if (isset($data['own_fe']) && isset($data['own_fe']['delete']) && intval($data['own_fe']['delete']) == 1) {
         $config['own_fe']['delete'] = true;
     }
     if (isset($data['own_fe']) && isset($data['own_fe']['state']) && intval($data['own_fe']['state']) == 1) {
         $config['own_fe']['state'] = true;
     }
     if (isset($data['own_fe']) && isset($data['own_fe']['publish']) && intval($data['own_fe']['publish']) == 1) {
         $config['own_fe']['publish'] = true;
     }
     if (isset($data['own_fe']) && isset($data['own_fe']['fullarticle']) && intval($data['own_fe']['fullarticle']) == 1) {
         $config['own_fe']['fullarticle'] = true;
     }
     if (isset($data['own_fe']) && isset($data['own_fe']['listaccess']) && intval($data['own_fe']['listaccess']) == 1) {
         $config['own_fe']['listaccess'] = true;
     }
     if (isset($data['own_fe']) && isset($data['own_fe']['new']) && intval($data['own_fe']['new']) == 1) {
         $config['own_fe']['new'] = true;
     }
     if (isset($data['own_fe']) && isset($data['own_fe']['language']) && intval($data['own_fe']['language']) == 1) {
         $config['own_fe']['language'] = true;
     }
     if (isset($data['own_fe']) && isset($data['own_fe']['rating']) && intval($data['own_fe']['rating']) == 1) {
         $config['own_fe']['rating'] = true;
     }
     jimport('joomla.version');
     $version = new JVersion();
     if (version_compare($version->getShortVersion(), '1.6', '<')) {
         $acl = JFactory::getACL();
         $gmap = $acl->get_group_children_tree(null, 'USERS', false);
     } else {
         $db = JFactory::getDbo();
         $query = 'SELECT CONCAT( REPEAT(\'..\', COUNT(parent.id) - 1), node.title) as text, node.id as value' . ' FROM #__usergroups AS node, #__usergroups AS parent' . ' WHERE node.lft BETWEEN parent.lft AND parent.rgt' . ' GROUP BY node.id' . ' ORDER BY node.lft';
         $db->setQuery($query);
         $gmap = $db->loadObjectList();
     }
     foreach ($gmap as $entry) {
         // backend
         if (isset($data['perms'][$entry->value]) && isset($data['perms'][$entry->value]['listaccess']) && intval($data['perms'][$entry->value]['listaccess']) == 1) {
             $config['permissions'][$entry->value]['listaccess'] = true;
         }
         if (isset($data['perms'][$entry->value]) && isset($data['perms'][$entry->value]['view']) && intval($data['perms'][$entry->value]['view']) == 1) {
             $config['permissions'][$entry->value]['view'] = true;
         }
         if (isset($data['perms'][$entry->value]) && isset($data['perms'][$entry->value]['new']) && intval($data['perms'][$entry->value]['new']) == 1) {
             $config['permissions'][$entry->value]['new'] = true;
         }
         if (isset($data['perms'][$entry->value]) && isset($data['perms'][$entry->value]['edit']) && intval($data['perms'][$entry->value]['edit']) == 1) {
             $config['permissions'][$entry->value]['edit'] = true;
         }
         if (isset($data['perms'][$entry->value]) && isset($data['perms'][$entry->value]['delete']) && intval($data['perms'][$entry->value]['delete']) == 1) {
             $config['permissions'][$entry->value]['delete'] = true;
         }
         if (isset($data['perms'][$entry->value]) && isset($data['perms'][$entry->value]['state']) && intval($data['perms'][$entry->value]['state']) == 1) {
             $config['permissions'][$entry->value]['state'] = true;
         }
         if (isset($data['perms'][$entry->value]) && isset($data['perms'][$entry->value]['publish']) && intval($data['perms'][$entry->value]['publish']) == 1) {
             $config['permissions'][$entry->value]['publish'] = true;
         }
         if (isset($data['perms'][$entry->value]) && isset($data['perms'][$entry->value]['fullarticle']) && intval($data['perms'][$entry->value]['fullarticle']) == 1) {
             $config['permissions'][$entry->value]['fullarticle'] = true;
         }
         if (isset($data['perms'][$entry->value]) && isset($data['perms'][$entry->value]['language']) && intval($data['perms'][$entry->value]['language']) == 1) {
             $config['permissions'][$entry->value]['language'] = true;
         }
         if (isset($data['perms'][$entry->value]) && isset($data['perms'][$entry->value]['rating']) && intval($data['perms'][$entry->value]['rating']) == 1) {
             $config['permissions'][$entry->value]['rating'] = true;
         }
         // frontend
         if (isset($data['perms_fe'][$entry->value]) && isset($data['perms_fe'][$entry->value]['listaccess']) && intval($data['perms_fe'][$entry->value]['listaccess']) == 1) {
             $config['permissions_fe'][$entry->value]['listaccess'] = true;
         }
         if (isset($data['perms_fe'][$entry->value]) && isset($data['perms_fe'][$entry->value]['view']) && intval($data['perms_fe'][$entry->value]['view']) == 1) {
             $config['permissions_fe'][$entry->value]['view'] = true;
         }
         if (isset($data['perms_fe'][$entry->value]) && isset($data['perms_fe'][$entry->value]['new']) && intval($data['perms_fe'][$entry->value]['new']) == 1) {
             $config['permissions_fe'][$entry->value]['new'] = true;
         }
         if (isset($data['perms_fe'][$entry->value]) && isset($data['perms_fe'][$entry->value]['edit']) && intval($data['perms_fe'][$entry->value]['edit']) == 1) {
             $config['permissions_fe'][$entry->value]['edit'] = true;
         }
         if (isset($data['perms_fe'][$entry->value]) && isset($data['perms_fe'][$entry->value]['delete']) && intval($data['perms_fe'][$entry->value]['delete']) == 1) {
             $config['permissions_fe'][$entry->value]['delete'] = true;
         }
         if (isset($data['perms_fe'][$entry->value]) && isset($data['perms_fe'][$entry->value]['state']) && intval($data['perms_fe'][$entry->value]['state']) == 1) {
             $config['permissions_fe'][$entry->value]['state'] = true;
         }
         if (isset($data['perms_fe'][$entry->value]) && isset($data['perms_fe'][$entry->value]['publish']) && intval($data['perms_fe'][$entry->value]['publish']) == 1) {
             $config['permissions_fe'][$entry->value]['publish'] = true;
         }
         if (isset($data['perms_fe'][$entry->value]) && isset($data['perms_fe'][$entry->value]['fullarticle']) && intval($data['perms_fe'][$entry->value]['fullarticle']) == 1) {
             $config['permissions_fe'][$entry->value]['fullarticle'] = true;
         }
         if (isset($data['perms_fe'][$entry->value]) && isset($data['perms_fe'][$entry->value]['language']) && intval($data['perms_fe'][$entry->value]['language']) == 1) {
             $config['permissions_fe'][$entry->value]['language'] = true;
         }
         if (isset($data['perms_fe'][$entry->value]) && isset($data['perms_fe'][$entry->value]['rating']) && intval($data['perms_fe'][$entry->value]['rating']) == 1) {
             $config['permissions_fe'][$entry->value]['rating'] = true;
         }
     }
     // remove perms
     if (isset($data['perms'])) {
         unset($data['perms']);
     }
     if (isset($data['perms_fe'])) {
         unset($data['perms_fe']);
     }
     if (isset($data['own'])) {
         unset($data['own']);
     }
     if (isset($data['own_fe'])) {
         unset($data['own_fe']);
     }
     ### PERMISSIONS END
     $list_states = $data['list_states'];
     unset($data['list_states']);
     $version = new JVersion();
     if (version_compare($version->getShortVersion(), '1.6', '>=')) {
         $data['default_category'] = JRequest::getInt('sectioncategories', 0);
     } else {
         // Joomla 1.5 begin
         $sectioncategory = explode(':', JRequest::getVar('sectioncategories', ''));
         $data['default_section'] = intval($sectioncategory[0]);
         $data['default_category'] = intval(isset($sectioncategory[1]) ? $sectioncategory[1] : 0);
         // Joomla 1.5 end
     }
     $data['edit_by_type'] = JRequest::getInt('edit_by_type', 0);
     if ($data['edit_by_type'] && $data['type'] == 'com_breezingforms') {
         if (isset($data['type_name'])) {
             $data['editable_template'] = "{BreezingForms: " . $data['type_name'] . "}";
         }
     }
     $data['act_as_registration'] = JRequest::getInt('act_as_registration', 0);
     if ($data['edit_by_type'] && $data['act_as_registration']) {
         $data['act_as_registration'] = 0;
         JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_ACT_AS_REGISTRATION_WARNING'), 'warning');
     }
     if ($data['act_as_registration'] && (!$data['registration_name_field'] || !$data['registration_username_field'] || !$data['registration_email_field'] || !$data['registration_email_repeat_field'] || !$data['registration_password_field'] || !$data['registration_password_repeat_field'])) {
         JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_ACT_AS_REGISTRATION_MISSING_FIELDS_WARNING'), 'warning');
     }
     $data['email_notifications'] = JRequest::getInt('email_notifications', 0);
     $data['limited_article_options'] = JRequest::getInt('limited_article_options', 0);
     $data['limited_article_options_fe'] = JRequest::getInt('limited_article_options_fe', 0);
     $data['own_only'] = JRequest::getInt('own_only', 0);
     $data['own_only_fe'] = JRequest::getInt('own_only_fe', 0);
     $data['config'] = base64_encode(serialize($config));
     contentbuilder::createBackendMenuItem($form->id, $form->name, JRequest::getInt('display_in', 0));
     if (JRequest::getBool('create_sample', false)) {
         $data['details_template'] .= contentbuilder::createDetailsSample($form->id, $form->form, $data['theme_plugin']);
     }
     if (JRequest::getBool('create_editable_sample', false)) {
         $data['editable_template'] .= contentbuilder::createEditableSample($form->id, $form->form, $data['theme_plugin']);
     }
     if (JRequest::getBool('email_admin_create_sample', false)) {
         $data['email_admin_template'] .= contentbuilder::createEmailSample($form->id, $form->form, JRequest::getBool('email_admin_html', false));
     }
     if (JRequest::getBool('email_create_sample', false)) {
         $data['email_template'] .= contentbuilder::createEmailSample($form->id, $form->form, JRequest::getBool('email_html', false));
     }
     if (!JRequest::getBool('show_filter', false)) {
         $data['show_filter'] = 0;
     }
     if (!JRequest::getBool('show_records_per_page', false)) {
         $data['show_records_per_page'] = 0;
     }
     if (!JRequest::getBool('metadata', false)) {
         $data['metadata'] = 0;
     }
     if (!JRequest::getBool('export_xls', false)) {
         $data['export_xls'] = 0;
     }
     if (!JRequest::getBool('print_button', false)) {
         $data['print_button'] = 0;
     }
     if (JRequest::getVar('tag', '') == '') {
         $data['tag'] = 'default';
     }
     if ($form->form) {
         $data['title'] = $form->form->getPageTitle();
     }
     $last_update = JFactory::getDate();
     $last_update = CBCompat::toSql($last_update);
     $data['last_update'] = $last_update;
     if (!$row->bind($data)) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     if (!$row->check()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     $form_id = 0;
     $storeRes = $row->store();
     if (!$storeRes) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     } else {
         if (intval($data['id']) != 0) {
             $form_id = intval($data['id']);
             foreach ($list_states as $state_id => $item) {
                 if (intval($state_id)) {
                     $db->setQuery("Update #__contentbuilder_list_states Set published = " . $db->Quote(isset($item['published']) && $item['published'] ? 1 : 0) . ", `title` = " . $db->Quote(stripslashes(strip_tags($item['title']))) . ", color = " . $db->Quote(stripslashes(strip_tags($item['color']))) . ", action = " . $db->Quote($item['action']) . " Where form_id = {$form_id} And id = " . intval($state_id));
                     $db->query();
                 }
             }
             // FALLBACK IF SOMEHOW REMOVED FROM DATABASE
             if (count($list_states) < count($this->_default_list_states)) {
                 $add_count = count($this->_default_list_states) - count($list_states);
                 for ($i = 0; $i <= $add_count; $i++) {
                     $db->setQuery("Insert Into #__contentbuilder_list_states (form_id,`title`,color,action) Values ({$form_id}," . $db->Quote('State') . "," . $db->Quote('FFFFFF') . "," . $db->Quote('') . ")");
                     $db->query();
                 }
             }
         } else {
             $form_id = $this->_db->insertid();
             foreach ($list_states as $item) {
                 $db->setQuery("Insert Into #__contentbuilder_list_states (form_id,`title`,color,action, published) Values ({$form_id}," . $db->Quote(stripslashes(strip_tags($item['title']))) . "," . $db->Quote($item['color']) . "," . $db->Quote($item['action']) . "," . $db->Quote(isset($item['published']) && $item['published'] ? 1 : 0) . ")");
                 $db->query();
             }
             // FALLBACK IF SOMEHOW REMOVED FROM DATABASE
             if (count($list_states) < count($this->_default_list_states)) {
                 $add_count = count($this->_default_list_states) - count($list_states);
                 for ($i = 0; $i <= $add_count; $i++) {
                     $db->setQuery("Insert Into #__contentbuilder_list_states (form_id,`title`,color,action) Values ({$form_id}," . $db->Quote('State') . "," . $db->Quote('FFFFFF') . "," . $db->Quote('') . ")");
                     $db->query();
                 }
             }
         }
         // is the list states empty?
         $db->setQuery("Select id From #__contentbuilder_list_states Where form_id = " . $form_id . " Limit 1");
         $has_states = $db->loadResult();
         if (!$has_states) {
             $add_count = count($this->_default_list_states);
             for ($i = 0; $i <= $add_count; $i++) {
                 $db->setQuery("Insert Into #__contentbuilder_list_states (form_id,`title`,color,action) Values ({$form_id}," . $db->Quote('State') . "," . $db->Quote('FFFFFF') . "," . $db->Quote('') . ")");
                 $db->query();
             }
         }
     }
     $row->reorder();
     $item_wrapper = JRequest::getVar('itemWrapper', '', 'POST', 'ARRAY', JREQUEST_ALLOWRAW);
     $wordwrap = JRequest::getVar('itemWordwrap', array(), 'post', 'array');
     $labels = JRequest::getVar('itemLabels', array(), 'post', 'array');
     $order_types = JRequest::getVar('itemOrderTypes', array(), 'post', 'array');
     JArrayHelper::toInteger($wordwrap);
     foreach ($item_wrapper as $elementId => $value) {
         $this->_db->setQuery("Update #__contentbuilder_elements Set `order_type` = " . $this->_db->Quote($order_types[$elementId]) . ", `label`= " . $this->_db->Quote($labels[$elementId]) . ", `wordwrap` = " . $this->_db->Quote($wordwrap[$elementId]) . ", `item_wrapper` =  " . $this->_db->Quote(trim($value)) . " Where form_id = {$form_id} And id = " . $elementId);
         $this->_db->query();
     }
     return $form_id;
 }