function store($post_replace = null) { $isNew = false; $db = JFactory::getDBO(); $row = $this->getTable(); $storage = $this->getStorage(); $storage_id = 0; if ($post_replace === null) { $data = JRequest::get('post'); } else { $data = $post_replace; } $bytable = isset($data['bytable']) ? $data['bytable'] : ''; if (isset($data['bytable'])) { unset($data['bytable']); } // forcing to lower as database exports may lead to tablename lowering $data['name'] = isset($data['name']) ? strtolower($data['name']) : ''; if ($bytable) { $data['bytable'] = 1; $newname = $bytable; $data['name'] = $newname; if (!trim($data['title'])) { $newtitle = $newname; } else { $newtitle = trim($data['title']); } $data['title'] = $newtitle; } else { $data['bytable'] = 0; $newname = str_replace(array(' ', "\n", "\r", "\t"), array(''), preg_replace("/[^a-zA-Z0-9_\\s]/isU", "_", trim($data['name']))); $newname = preg_replace("/^([0-9\\s])/isU", "field\$1\$2", $newname); $newname = $newname == '' ? 'field' . mt_rand(0, mt_getrandmax()) : $newname; // required for csv $this->target_table = $newname; $data['name'] = $newname; if (!trim($data['title'])) { $newtitle = $newname; } else { $newtitle = trim($data['title']); } $data['title'] = $newtitle; } $listnames = isset($data['itemNames']) ? $data['itemNames'] : array(); $listtitles = isset($data['itemTitles']) ? $data['itemTitles'] : array(); $listisgroup = isset($data['itemIsGroup']) ? $data['itemIsGroup'] : array(); $listgroupdefinitions = JRequest::getVar('itemGroupDefinitions', array(), 'POST', 'ARRAY', JREQUEST_ALLOWRAW); unset($data['itemIsGroup']); unset($data['itemGroupDefinitions']); unset($data['itemNames']); unset($data['itemTitles']); // case of new field $newfieldname = ''; $newfieldtitle = ''; $is_group = 0; $group_definition = ''; $fieldexists = false; if (isset($data['fieldname']) && trim($data['fieldname'])) { $newfieldname = str_replace(array(' ', "\n", "\r", "\t"), array('_'), preg_replace("/[^a-zA-Z0-9_\\s]/isU", "_", trim($data['fieldname']))); $newfieldname = preg_replace("/^([0-9\\s])/isU", "field\$1\$2", $newfieldname); $newfieldname = $newfieldname == '' ? 'field' . mt_rand(0, mt_getrandmax()) : $newfieldname; if (!trim($data['fieldtitle'])) { $newfieldtitle = $newfieldname; } else { $newfieldtitle = trim($data['fieldtitle']); } $this->_db->setQuery("Select `name` From #__contentbuilder_storage_fields Where `name` = " . $this->_db->Quote($newfieldname) . " And storage_id = " . JRequest::getInt('id', 0)); $fieldexists = $this->_db->loadResult(); if ($fieldexists) { $newfieldname = $fieldexists; } $is_group = intval($data['is_group']); $group_definition = $data['group_definition']; unset($data['is_group']); unset($data['group_definition']); unset($data['fieldname']); unset($data['fieldtitle']); } if (!$row->bind($data)) { $this->setError($this->_db->getErrorMsg()); return false; } if (!$row->check()) { $this->setError($this->_db->getErrorMsg()); return false; } $storeRes = $row->store(); if (!$storeRes) { $this->setError($this->_db->getErrorMsg()); return false; } else { if (intval($data['id']) != 0) { $storage_id = intval($data['id']); } else { $isNew = true; $storage_id = $this->_db->insertid(); $this->_id = $storage_id; } // required for csv $this->_id = $storage_id; } $row->reorder(); $this->_db->setQuery("Select Max(ordering)+1 From #__contentbuilder_storage_fields Where storage_id = " . $this->_id . ""); $max = intval($this->_db->loadResult()); // we have a new field, so let's add it if (!$bytable && $this->_id && $newfieldname && !$fieldexists) { $this->_db->setQuery("Insert Into #__contentbuilder_storage_fields (ordering, storage_id,`name`,`title`,`is_group`,`group_definition`) Values ({$max}," . intval($this->_id) . "," . $this->_db->Quote($newfieldname) . "," . $this->_db->Quote($newfieldtitle) . "," . $is_group . "," . $this->_db->Quote($group_definition) . ")"); $this->_db->query(); } // table // create or update the corresponding table, field synch below $last_update = JFactory::getDate(); $last_update = CBCompat::toSql($last_update); $tables = CBCompat::getTableFields(JFactory::getDBO()->getTableList()); if (!$bytable && !isset($tables[JFactory::getDBO()->getPrefix() . $data['name']])) { if ($storage->name && isset($tables[JFactory::getDBO()->getPrefix() . $storage->name])) { $this->_db->setQuery("Rename Table #__" . $storage->name . " To #__" . $data['name']); $this->_db->query(); } else { try { $this->_db->setQuery(' CREATE TABLE `#__' . $data['name'] . '` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, `storage_id` INT NOT NULL DEFAULT "' . $this->_id . '", `user_id` INT NOT NULL DEFAULT "0", `created` DATETIME NOT NULL DEFAULT "' . $last_update . '", `created_by` VARCHAR( 255 ) NOT NULL DEFAULT "", `modified_user_id` INT NOT NULL DEFAULT "0", `modified` DATETIME NOT NULL DEFAULT "0000-00-00 00:00:00", `modified_by` VARCHAR( 255 ) NOT NULL DEFAULT "" ) ; '); $this->_db->query(); JFactory::getDBO()->setQuery("ALTER TABLE `#__" . $data['name'] . "` ADD INDEX ( `storage_id` )"); JFactory::getDBO()->query(); JFactory::getDBO()->setQuery("ALTER TABLE `#__" . $data['name'] . "` ADD INDEX ( `user_id` )"); JFactory::getDBO()->query(); JFactory::getDBO()->setQuery("ALTER TABLE `#__" . $data['name'] . "` ADD INDEX ( `created` )"); JFactory::getDBO()->query(); JFactory::getDBO()->setQuery("ALTER TABLE `#__" . $data['name'] . "` ADD INDEX ( `modified_user_id` )"); JFactory::getDBO()->query(); JFactory::getDBO()->setQuery("ALTER TABLE `#__" . $data['name'] . "` ADD INDEX ( `modified` )"); JFactory::getDBO()->query(); } catch (Exception $e) { } } } else { if ($bytable) { // creating the storage fields in custom table if not existing already $system_fields = array('id', 'storage_id', 'user_id', 'created', 'created_by', 'modified_user_id', 'modified', 'modified_by'); $allfields = array(); $fieldin = ''; $fields = $tables[$data['name']]; foreach ($fields as $field => $type) { $fieldin .= "'" . $field . "',"; } $fieldin = rtrim($fieldin, ','); if ($fieldin) { $this->_db->setQuery("Select `name` From #__contentbuilder_storage_fields Where `name` In (" . $fieldin . ") And storage_id = " . $this->_id); jimport('joomla.version'); $version = new JVersion(); if (version_compare($version->getShortVersion(), '3.0', '>=')) { $fieldnames = $this->_db->loadColumn(); } else { $fieldnames = $this->_db->loadResultArray(); } foreach ($fields as $field => $type) { if (!in_array($field, $fieldnames) && !in_array($field, $system_fields)) { $this->_db->setQuery("Insert Into #__contentbuilder_storage_fields (ordering,storage_id,`name`,`title`,`is_group`,`group_definition`) Values ({$max}," . intval($this->_id) . "," . $this->_db->Quote($field) . "," . $this->_db->Quote($field) . ",0,'')"); $this->_db->query(); } $allfields[] = $field; } // now we add missing system columns into the custom table try { foreach ($system_fields as $missing) { if (!in_array($missing, $allfields)) { switch ($missing) { case 'id': $this->_db->setQuery("ALTER TABLE `" . $data['name'] . "` ADD `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY "); $this->_db->query(); break; case 'storage_id': $this->_db->setQuery("ALTER TABLE `" . $data['name'] . "` ADD `storage_id` INT NOT NULL DEFAULT " . $this->_id . ", ADD INDEX ( `storage_id` )"); $this->_db->query(); break; case 'user_id': $this->_db->setQuery("ALTER TABLE `" . $data['name'] . "` ADD `user_id` INT NOT NULL DEFAULT 0, ADD INDEX ( `user_id` ) "); $this->_db->query(); break; case 'created': $this->_db->setQuery("ALTER TABLE `" . $data['name'] . "` ADD `created` DATETIME NOT NULL DEFAULT '" . $last_update . "', ADD INDEX ( `created` ) "); $this->_db->query(); break; case 'created_by': $this->_db->setQuery("ALTER TABLE `" . $data['name'] . "` ADD `created_by` VARCHAR( 255 ) NOT NULL DEFAULT '' "); $this->_db->query(); break; case 'modified_user_id': $this->_db->setQuery("ALTER TABLE `" . $data['name'] . "` ADD `modified_user_id` INT NOT NULL DEFAULT 0, ADD INDEX ( `modified_user_id` ) "); $this->_db->query(); break; case 'modified': $this->_db->setQuery("ALTER TABLE `" . $data['name'] . "` ADD `modified` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', ADD INDEX ( `modified` ) "); $this->_db->query(); break; case 'modified_by': $this->_db->setQuery("ALTER TABLE `" . $data['name'] . "` ADD `modified_by` VARCHAR( 255 ) NOT NULL DEFAULT '' "); $this->_db->query(); break; } } } } catch (Exception $e) { } // importing records if ($isNew) { $this->_db->setQuery("Alter Table `" . $data['name'] . "` Alter Column `storage_id` Set Default '" . $this->_id . "'"); $this->_db->query(); $this->_db->setQuery("Update `" . $data['name'] . "` Set `storage_id` = '" . $this->_id . "'"); $this->_db->query(); $this->_db->setQuery("Select id From `" . $data['name'] . "`"); jimport('joomla.version'); $version = new JVersion(); if (version_compare($version->getShortVersion(), '3.0', '>=')) { $third_party_ids = $this->_db->loadColumn(); } else { $third_party_ids = $this->_db->loadResultArray(); } foreach ($third_party_ids as $third_party_id) { $this->_db->setQuery("Insert Into #__contentbuilder_records (\n `type`,\n last_update,\n is_future,\n lang_code, \n sef, \n published, \n record_id, \n reference_id\n ) \n Values \n (\n 'com_contentbuilder',\n " . $this->_db->Quote($last_update) . ",\n 0,\n '*',\n '',\n 1,\n " . $this->_db->Quote(intval($third_party_id)) . ",\n " . $this->_db->Quote($this->_id) . "\n )"); // ignore already imported records $this->_db->query(); } } } } } $tables = CBCompat::getTableFields(JFactory::getDBO()->getTableList()); foreach ($listnames as $field_id => $name) { $name = str_replace(array(' ', "\n", "\r", "\t"), array(''), preg_replace("/[^a-zA-Z0-9_\\s]/isU", "_", trim($name))); $name = preg_replace("/^([0-9\\s])/isU", "field\$1\$2", $name); $name = $name == '' ? 'field' . mt_rand(0, mt_getrandmax()) : $name; if (!trim($listtitles[$field_id])) { $listtitles[$field_id] = $name; } else { $listtitles[$field_id] = trim($listtitles[$field_id]); } if (!$bytable) { $this->_db->setQuery("Select `name` From #__contentbuilder_storage_fields Where id = " . intval($field_id)); $old_name = $this->_db->loadResult(); $this->_db->setQuery("Update #__contentbuilder_storage_fields Set group_definition = " . $this->_db->Quote($listgroupdefinitions[$field_id]) . ", is_group = " . intval($listisgroup[$field_id]) . ",`name` = " . $this->_db->Quote($name) . ", `title` = " . $this->_db->Quote($listtitles[$field_id]) . " Where id = " . intval($field_id)); $this->_db->query(); if ($old_name != $name) { $this->_db->setQuery("ALTER TABLE `#__" . $data['name'] . "` CHANGE `" . $old_name . "` `" . $name . "` TEXT "); $this->_db->query(); } } else { $this->_db->setQuery("Update #__contentbuilder_storage_fields Set group_definition = " . $this->_db->Quote($listgroupdefinitions[$field_id]) . ", is_group = " . intval($listisgroup[$field_id]) . ", `title` = " . $this->_db->Quote($listtitles[$field_id]) . " Where id = " . intval($field_id)); $this->_db->query(); } } $this->getTable('storage_fields')->reorder('storage_id = ' . $this->_id); if (!$bytable) { // fields // synch non-existing fields $fields = $this->getFields(); foreach ($fields as $field) { if (!isset($field->name)) { continue; } $fieldname = $field->name; if ($fieldname && !isset($tables[JFactory::getDBO()->getPrefix() . $data['name']][$fieldname])) { try { $this->_db->setQuery("ALTER TABLE `#__" . $data['name'] . "` ADD `" . $fieldname . "` TEXT NOT NULL "); $this->_db->query(); } catch (Exception $e) { } } } } if ($post_replace === null) { return $this->_id; } else { return $newfieldname; } }
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(); } } } } } }
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; }