function __construct(&$subject, $params) { parent::__construct($subject, $params); $plugin = JPluginHelper::getPlugin('contentbuilder_verify', 'paypal'); jimport('joomla.html.parameter'); $pluginParams = CBCompat::getParams($plugin->params); if ($pluginParams->def('test', 0)) { $this->test = true; $this->business = $pluginParams->def('test_business', ''); $this->token = $pluginParams->def('test_token', ''); $this->url = 'https://www.sandbox.paypal.com'; } else { $this->business = $pluginParams->def('business', ''); $this->token = $pluginParams->def('token', ''); } }
<?php /** * @package ContentBuilder * @author Markus Bopp * @link http://www.crosstec.de * @license GNU/GPL */ // no direct access defined('_JEXEC') or die('Restricted access'); require_once JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'classes' . DS . 'joomla_compat.php'; CBCompat::requireController(); require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'classes' . DS . 'contentbuilder.php'; class ContentbuilderControllerDetails extends CBController { function __construct() { if (class_exists('cbFeMarker') && JRequest::getInt('Itemid', 0)) { $option = 'com_contentbuilder'; // try menu item jimport('joomla.version'); $version = new JVersion(); if (version_compare($version->getShortVersion(), '1.6', '>=')) { $menu = JSite::getMenu(); $item = $menu->getActive(); if (is_object($item)) { if ($item->params->get('record_id', null) !== null) { JRequest::setVar('record_id', $item->params->get('record_id', null)); $this->_show_back_button = $item->params->get('show_back_button', null); } //if($item->params->get('show_page_heading', null) !== null){
</div> <div style="clear:both;"></div> <div id="editcell"> <table class="adminlist table table-striped"> <thead> <tr> <th width="5"> <?php echo JHTML::_('grid.sort', JText::_('COM_CONTENTBUILDER_ID'), 'id', $this->lists['order_Dir'], $this->lists['order']); ?> </th> <th width="20"> <input type="checkbox" name="toggle" value="" onclick="<?php echo CBCompat::getCheckAll($this->items); ?> " /> </th> <th> <?php echo JHTML::_('grid.sort', JText::_('COM_CONTENTBUILDER_NAME'), 'name', $this->lists['order_Dir'], $this->lists['order']); ?> </th> <th> <?php echo JHTML::_('grid.sort', JText::_('COM_CONTENTBUILDER_USERNAME'), 'username', $this->lists['order_Dir'], $this->lists['order']); ?> </th> <th> <?php
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(); } } } } } }
$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"> label { display: inline; } </style> <?php $cbcompat = new CBCompat(); echo $cbcompat->initPane(array('tab0' => JText::_('COM_CONTENTBUILDER_ELEMENT_OPTIONS'), 'tab1' => JText::_('COM_CONTENTBUILDER_ELEMENT_OPTIONS_SCRIPTS'))); ?> <form action="index.php" method="post" name="adminForm" id="adminForm"> <?php echo JText::_('COM_CONTENTBUILDER_ELEMENT_TYPE'); ?> <select name="type_selection" onchange="document.getElementById('type_change').value='1';document.getElementById('task').value='save';document.adminForm.submit();"> <option value="text"<?php echo $this->element->type == 'text' || $this->element->type == '' ? ' selected="selected"' : ''; ?> ><?php echo JText::_('COM_CONTENTBUILDER_ELEMENT_TYPE_TEXT'); ?> </option>
} String.prototype.endsWith = function(suffix) { return this.indexOf(suffix, this.length - suffix.length) !== -1; }; if( typeof Joomla != 'undefined' ){ Joomla.submitbutton = submitbutton; Joomla.listItemTask = listItemTask; } </script> <style type="text/css"> label { display: inline; } </style> <?php $cbcompat = new CBCompat(); $cbcompat->initPane(array('tab0' => JText::_('COM_CONTENTBUILDER_STORAGE'))); ?> <form action="index.php" method="post" name="adminForm" id="adminForm" enctype="multipart/form-data"> <div class="col100" style="margin-left: 20px;"> <?php echo $cbcompat->startPane("view-pane"); echo $cbcompat->startPanel(JText::_('COM_CONTENTBUILDER_STORAGE'), "tab0"); ?> <table width="100%"> <tr> <td width="200" valign="top"> <fieldset class="adminform">
document.adminForm.elements[i].checked = false; } } } } </script> <style type="text/css"> .cbFieldFix{ margin-bottom: 9px; } </style> <style type="text/css"> label { display: inline; } </style> <?php $cbcompat = new CBCompat(); echo $cbcompat->initPane(array('tab0' => JText::_('COM_CONTENTBUILDER_VIEW'), 'tab1' => JText::_('COM_CONTENTBUILDER_LIST_STATES'), 'tab2' => JText::_('COM_CONTENTBUILDER_LIST_INTRO_TEXT'), 'tab3' => JText::_('COM_CONTENTBUILDER_DETAILS_TEMPLATE'), 'tab4' => JText::_('COM_CONTENTBUILDER_DETAILS_PREPARE'), 'tab5' => JText::_('COM_CONTENTBUILDER_EDITABLE_TEMPLATE'), 'tab6' => JText::_('COM_CONTENTBUILDER_EDITABLE_PREPARE'), 'tab7' => JText::_('COM_CONTENTBUILDER_EMAIL_TEMPLATES'), 'tab8' => JText::_('COM_CONTENTBUILDER_PERMISSIONS'))); ?> <form action="index.php" method="post" name="adminForm" id="adminForm"> <div class="col100 row-fluid" style="margin-left: 20px;"> <?php echo $cbcompat->startPane("view-pane"); echo $cbcompat->startPanel(JText::_('COM_CONTENTBUILDER_VIEW'), "tab0"); ?> <table width="100%"> <tr> <td valign="top"> <fieldset class="adminform">
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;"> </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; }
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; }
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;"> </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; }
function store() { JRequest::checkToken('default') or jexit(JText::_('JInvalid_Token')); JPluginHelper::importPlugin('contentbuilder_submit'); $submit_dispatcher = JDispatcher::getInstance(); JFactory::getSession()->clear('cb_failed_values', 'com_contentbuilder.' . $this->_id); JRequest::setVar('cb_submission_failed', 0); $query = $this->_buildQuery(); $this->_data = $this->_getList($query, 0, 1); if (!count($this->_data)) { JError::raiseError(404, JText::_('COM_CONTENTBUILDER_FORM_NOT_FOUND')); } foreach ($this->_data as $data) { if (!$this->frontend && $data->display_in == 0) { JError::raiseError(404, JText::_('COM_CONTENTBUILDER_RECORD_NOT_FOUND')); } else { if ($this->frontend && $data->display_in == 1) { JError::raiseError(404, JText::_('COM_CONTENTBUILDER_RECORD_NOT_FOUND')); } } $data->form_id = $this->_id; if ($data->type && $data->reference_id) { $values = array(); $data->form = contentbuilder::getForm($data->type, $data->reference_id); $meta = $data->form->getRecordMetadata($this->_record_id); if (!$data->edit_by_type) { $noneditable_fields = contentbuilder::getListNonEditableElements($this->_id); $names = $data->form->getElementNames(); $this->_db->setQuery("Select * From #__contentbuilder_elements Where form_id = " . $this->_id . " And published = 1 And editable = 1"); $fields = $this->_db->loadAssocList(); $the_fields = array(); $the_name_field = null; $the_username_field = null; $the_password_field = null; $the_password_repeat_field = null; $the_email_field = null; $the_email_repeat_field = null; $the_html_fields = array(); $the_upload_fields = array(); $the_captcha_field = null; $the_failed_registration_fields = array(); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); foreach ($fields as $special_field) { switch ($special_field['type']) { case 'text': case 'upload': case 'captcha': case 'textarea': if ($special_field['type'] == 'upload') { $options = unserialize(base64_decode($special_field['options'])); $special_field['options'] = $options; $the_upload_fields[$special_field['reference_id']] = $special_field; } else { if ($special_field['type'] == 'captcha') { $options = unserialize(base64_decode($special_field['options'])); $special_field['options'] = $options; $the_captcha_field = $special_field; } else { if ($special_field['type'] == 'textarea') { $options = unserialize(base64_decode($special_field['options'])); $special_field['options'] = $options; if (isset($special_field['options']->allow_html) && $special_field['options']->allow_html) { $the_html_fields[$special_field['reference_id']] = $special_field; } else { $the_fields[$special_field['reference_id']] = $special_field; } } else { if ($special_field['type'] == 'text') { $options = unserialize(base64_decode($special_field['options'])); $special_field['options'] = $options; if ($data->act_as_registration && $data->registration_username_field == $special_field['reference_id']) { $the_username_field = $special_field; } else { if ($data->act_as_registration && $data->registration_name_field == $special_field['reference_id']) { $the_name_field = $special_field; } else { if ($data->act_as_registration && $data->registration_password_field == $special_field['reference_id']) { $the_password_field = $special_field; } else { if ($data->act_as_registration && $data->registration_password_repeat_field == $special_field['reference_id']) { $the_password_repeat_field = $special_field; } else { if ($data->act_as_registration && $data->registration_email_field == $special_field['reference_id']) { $the_email_field = $special_field; } else { if ($data->act_as_registration && $data->registration_email_repeat_field == $special_field['reference_id']) { $the_email_repeat_field = $special_field; } else { $the_fields[$special_field['reference_id']] = $special_field; } } } } } } } } } } break; default: $options = unserialize(base64_decode($special_field['options'])); $special_field['options'] = $options; $the_fields[$special_field['reference_id']] = $special_field; } } // we have defined a captcha, so let's test it if ($the_captcha_field !== null && !in_array($the_captcha_field['reference_id'], $noneditable_fields)) { if (!class_exists('Securimage')) { require_once JPATH_SITE . DS . 'components' . DS . 'com_contentbuilder' . DS . 'images' . DS . 'securimage' . DS . 'securimage.php'; } $securimage = new Securimage(); $cap_value = JRequest::getVar('cb_' . $the_captcha_field['reference_id'], null, 'POST'); if ($securimage->check($cap_value) == false) { JRequest::setVar('cb_submission_failed', 1); JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_CAPTCHA_FAILED'), 'error'); } $values[$the_captcha_field['reference_id']] = $cap_value; $noneditable_fields[] = $the_captcha_field['reference_id']; } // now let us see if we have a registration // make sure to wait for previous errors if ($data->act_as_registration && $the_name_field !== null && $the_email_field !== null && $the_email_repeat_field !== null && $the_password_field !== null && $the_password_repeat_field !== null && $the_username_field !== null) { $pw1 = JRequest::getVar('cb_' . $the_password_field['reference_id'], '', 'POST', 'STRING', JREQUEST_NOTRIM | JREQUEST_ALLOWRAW); $pw2 = JRequest::getVar('cb_' . $the_password_repeat_field['reference_id'], '', 'POST', 'STRING', JREQUEST_NOTRIM | JREQUEST_ALLOWRAW); $email = JRequest::getVar('cb_' . $the_email_field['reference_id'], '', 'POST', 'STRING', JREQUEST_ALLOWRAW); $email2 = JRequest::getVar('cb_' . $the_email_repeat_field['reference_id'], '', 'POST', 'STRING', JREQUEST_ALLOWRAW); $name = JRequest::getVar('cb_' . $the_name_field['reference_id'], '', 'POST', 'STRING', JREQUEST_ALLOWRAW); $username = JRequest::getVar('cb_' . $the_username_field['reference_id'], '', 'POST', 'STRING', JREQUEST_NOTRIM | JREQUEST_ALLOWRAW); if (!JRequest::getVar('cb_submission_failed', 0)) { if (!trim($name)) { JRequest::setVar('cb_submission_failed', 1); JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_NAME_EMPTY'), 'error'); } if (!trim($username)) { JRequest::setVar('cb_submission_failed', 1); JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_USERNAME_EMPTY'), 'error'); } else { if (preg_match("#[<>\"'%;()&]#i", $username) || strlen(utf8_decode($username)) < 2) { JRequest::setVar('cb_submission_failed', 1); JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_USERNAME_INVALID'), 'error'); } } if (!trim($email)) { JRequest::setVar('cb_submission_failed', 1); JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_EMAIL_EMPTY'), 'error'); } else { if (!contentbuilder_is_email($email)) { JRequest::setVar('cb_submission_failed', 1); JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_EMAIL_INVALID'), 'error'); } else { if ($email != $email2) { JRequest::setVar('cb_submission_failed', 1); JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_EMAIL_MISMATCH'), 'error'); } } } if (!$meta->created_id && !JFactory::getUser()->get('id', 0)) { $this->_db->setQuery("Select count(id) From #__users Where `username` = " . $this->_db->Quote($username)); if ($this->_db->loadResult()) { JRequest::setVar('cb_submission_failed', 1); JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_USERNAME_NOT_AVAILABLE'), 'error'); } $this->_db->setQuery("Select count(id) From #__users Where `email` = " . $this->_db->Quote($email)); if ($this->_db->loadResult()) { JRequest::setVar('cb_submission_failed', 1); JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_EMAIL_NOT_AVAILABLE'), 'error'); } if ($pw1 != $pw2) { JRequest::setVar('cb_submission_failed', 1); JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_PASSWORD_MISMATCH'), 'error'); JRequest::setVar('cb_' . $the_password_field['reference_id'], ''); JRequest::setVar('cb_' . $the_password_repeat_field['reference_id'], ''); } else { if (!trim($pw1)) { JRequest::setVar('cb_submission_failed', 1); JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_PASSWORD_EMPTY'), 'error'); JRequest::setVar('cb_' . $the_password_field['reference_id'], ''); JRequest::setVar('cb_' . $the_password_repeat_field['reference_id'], ''); } } } else { if ($meta->created_id && $meta->created_id != JFactory::getUser()->get('id', 0)) { $this->_db->setQuery("Select count(id) From #__users Where id <> " . $this->_db->Quote($meta->created_id) . " And `username` = " . $this->_db->Quote($username)); if ($this->_db->loadResult()) { JRequest::setVar('cb_submission_failed', 1); JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_USERNAME_NOT_AVAILABLE'), 'error'); } $this->_db->setQuery("Select count(id) From #__users Where id <> " . $this->_db->Quote($meta->created_id) . " And `email` = " . $this->_db->Quote($email)); if ($this->_db->loadResult()) { JRequest::setVar('cb_submission_failed', 1); JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_EMAIL_NOT_AVAILABLE'), 'error'); } } else { $this->_db->setQuery("Select count(id) From #__users Where id <> " . $this->_db->Quote(JFactory::getUser()->get('id', 0)) . " And `username` = " . $this->_db->Quote($username)); if ($this->_db->loadResult()) { JRequest::setVar('cb_submission_failed', 1); JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_USERNAME_NOT_AVAILABLE'), 'error'); } $this->_db->setQuery("Select count(id) From #__users Where id <> " . $this->_db->Quote(JFactory::getUser()->get('id', 0)) . " And `email` = " . $this->_db->Quote($email)); if ($this->_db->loadResult()) { JRequest::setVar('cb_submission_failed', 1); JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_EMAIL_NOT_AVAILABLE'), 'error'); } } if (trim($pw1) != '' || trim($pw2) != '') { if ($pw1 != $pw2) { JRequest::setVar('cb_submission_failed', 1); JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_PASSWORD_MISMATCH'), 'error'); JRequest::setVar('cb_' . $the_password_field['reference_id'], ''); JRequest::setVar('cb_' . $the_password_repeat_field['reference_id'], ''); } else { if (!trim($pw1)) { JRequest::setVar('cb_submission_failed', 1); JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_PASSWORD_EMPTY'), 'error'); JRequest::setVar('cb_' . $the_password_field['reference_id'], ''); JRequest::setVar('cb_' . $the_password_repeat_field['reference_id'], ''); } } } } if (!JRequest::getVar('cb_submission_failed', 0)) { //$noneditable_fields[] = $the_name_field['reference_id']; $noneditable_fields[] = $the_password_field['reference_id']; $noneditable_fields[] = $the_password_repeat_field['reference_id']; //$noneditable_fields[] = $the_email_field['reference_id']; $noneditable_fields[] = $the_email_repeat_field['reference_id']; //$noneditable_fields[] = $the_username_field['reference_id']; } else { $the_failed_registration_fields[$the_name_field['reference_id']] = $the_name_field; //$the_failed_registration_fields[$the_password_field['reference_id']] = $the_password_field; //$the_failed_registration_fields[$the_password_repeat_field['reference_id']] = $the_password_repeat_field; $the_failed_registration_fields[$the_email_field['reference_id']] = $the_email_field; $the_failed_registration_fields[$the_email_repeat_field['reference_id']] = $the_email_repeat_field; $the_failed_registration_fields[$the_username_field['reference_id']] = $the_username_field; } } else { $the_failed_registration_fields[$the_name_field['reference_id']] = $the_name_field; //$the_failed_registration_fields[$the_password_field['reference_id']] = $the_password_field; //$the_failed_registration_fields[$the_password_repeat_field['reference_id']] = $the_password_repeat_field; $the_failed_registration_fields[$the_email_field['reference_id']] = $the_email_field; $the_failed_registration_fields[$the_email_repeat_field['reference_id']] = $the_email_repeat_field; $the_failed_registration_fields[$the_username_field['reference_id']] = $the_username_field; } } $form_elements_objects = array(); $_items = $data->form->getRecord($this->_record_id, $data->published_only, $this->frontend ? $data->own_only_fe ? JFactory::getUser()->get('id', 0) : -1 : ($data->own_only ? JFactory::getUser()->get('id', 0) : -1), $this->frontend ? $data->show_all_languages_fe : true); // asigning the proper names first foreach ($names as $id => $name) { if (!in_array($id, $noneditable_fields)) { $value = ''; $is_array = 'STRING'; if (is_array(JRequest::getVar('cb_' . $id, ''))) { $is_array = 'ARRAY'; } if (isset($the_fields[$id]['options']->allow_raw) && $the_fields[$id]['options']->allow_raw) { $value = JRequest::getVar('cb_' . $id, '', 'POST', $is_array, JREQUEST_ALLOWRAW); } else { if (isset($the_fields[$id]['options']->allow_html) && $the_fields[$id]['options']->allow_html) { $value = JRequest::getVar('cb_' . $id, '', 'POST', $is_array, JREQUEST_ALLOWHTML); } else { $value = JRequest::getVar('cb_' . $id, '', 'POST', $is_array); } } if (isset($the_fields[$id]['options']->transfer_format)) { $value = contentbuilder_convert_date($value, $the_fields[$id]['options']->format, $the_fields[$id]['options']->transfer_format); } if (isset($the_html_fields[$id])) { $the_html_fields[$id]['name'] = $name; $the_html_fields[$id]['value'] = $value; } else { if (isset($the_failed_registration_fields[$id])) { $the_failed_registration_fields[$id]['name'] = $name; $the_failed_registration_fields[$id]['value'] = $value; } else { if (isset($the_upload_fields[$id])) { $the_upload_fields[$id]['name'] = $name; $the_upload_fields[$id]['value'] = ''; $the_upload_fields[$id]['orig_value'] = ''; if ($id == $the_upload_fields[$id]['reference_id']) { // delete if triggered if (JRequest::getInt('cb_delete_' . $id, 0) == 1 && isset($the_upload_fields[$id]['validations']) && $the_upload_fields[$id]['validations'] == '') { if (count($_items)) { foreach ($_items as $_item) { if ($_item->recElementId == $the_upload_fields[$id]['reference_id']) { $_value = $_item->recValue; $_files = explode("\n", str_replace("\r", '', $_value)); foreach ($_files as $_file) { if (strpos(strtolower($_file), '{cbsite}') === 0) { $_file = str_replace(array('{cbsite}', '{CBSite}'), array(JPATH_SITE, JPATH_SITE), $_file); } if (JFile::exists($_file)) { JFile::delete($_file); } $values[$id] = ''; } } } } } $file = JRequest::getVar('cb_' . $id, null, 'files', 'array'); if (trim(JFile::makeSafe($file['name'])) != '' && $file['size'] > 0) { $filename = trim(JFile::makeSafe($file['name'])); $infile = $filename; $src = $file['tmp_name']; $dest = ''; $tmp_dest = ''; $tmp_upload_field_dir = ''; $tmp_upload_dir = ''; if (isset($the_upload_fields[$id]['options']) && isset($the_upload_fields[$id]['options']->upload_directory) && $the_upload_fields[$id]['options']->upload_directory != '') { $tmp_upload_field_dir = $the_upload_fields[$id]['options']->upload_directory; $tmp_dest = $tmp_upload_field_dir; } else { if ($data->upload_directory != '') { $tmp_upload_dir = $data->upload_directory; $tmp_dest = $tmp_upload_dir; } } if (isset($the_upload_fields[$id]['options']) && isset($the_upload_fields[$id]['options']->upload_directory) && $the_upload_fields[$id]['options']->upload_directory != '') { $dest = str_replace(array('{CBSite}', '{cbsite}'), JPATH_SITE, $the_upload_fields[$id]['options']->upload_directory); } else { if ($data->upload_directory != '') { $dest = str_replace(array('{CBSite}', '{cbsite}'), JPATH_SITE, $data->upload_directory); } } // create dest path by tokens $dest = $this->createPathByTokens($dest, $names); $msg = ''; $uploaded = false; // FILE SIZE TEST if ($dest != '' && isset($the_upload_fields[$id]['options']) && isset($the_upload_fields[$id]['options']->max_filesize) && $the_upload_fields[$id]['options']->max_filesize > 0) { $val = $the_upload_fields[$id]['options']->max_filesize; $val = trim($val); $last = strtolower($val[strlen($val) - 1]); switch ($last) { case 'g': $val *= 1024; case 'm': $val *= 1024; case 'k': $val *= 1024; } if ($file['size'] > $val) { $msg = JText::_('COM_CONTENTBUILDER_FILESIZE_EXCEEDED') . ' ' . $the_upload_fields[$id]['options']->max_filesize . 'b'; } } // FILE EXT TEST if ($dest != '' && isset($the_upload_fields[$id]['options']) && isset($the_upload_fields[$id]['options']->allowed_file_extensions) && $the_upload_fields[$id]['options']->allowed_file_extensions != '') { $allowed = explode(',', str_replace(' ', '', strtolower($the_upload_fields[$id]['options']->allowed_file_extensions))); $ext = strtolower(JFile::getExt($filename)); if (!in_array($ext, $allowed)) { $msg = JText::_('COM_CONTENTBUILDER_FILE_EXTENSION_NOT_ALLOWED'); } } // UPLOAD if ($dest != '' && $msg == '') { // limit file's name size $ext = strtolower(JFile::getExt($filename)); $stripped = JFile::stripExt($filename); // in some apache configurations unknown file extensions could lead to security risks // because it will try to find an executable extensions within the chain of dots. So we simply remove them. $filename = str_replace(array(' ', '.'), '_', $stripped) . '.' . $ext; $maxnamesize = 100; if (function_exists('mb_strlen')) { if (mb_strlen($filename) > $maxnamesize) { $filename = mb_substr($filename, mb_strlen($filename) - $maxnamesize); } } else { if (strlen($filename) > $maxnamesize) { $filename = substr($filename, strlen($filename) - $maxnamesize); } } // take care of existing filenames if (JFile::exists($dest . DS . $filename)) { $filename = md5(mt_rand(0, mt_getrandmax()) . time()) . '_' . $filename; } // create pseudo security index.html if (!JFile::exists($dest . DS . 'index.html')) { JFile::write($dest . DS . 'index.html', $buffer = ''); } if (count($_items)) { $files_to_delete = array(); foreach ($_items as $_item) { if ($_item->recElementId == $the_upload_fields[$id]['reference_id']) { $_value = $_item->recValue; $_files = explode("\n", str_replace("\r", '', $_value)); foreach ($_files as $_file) { if (strpos(strtolower($_file), '{cbsite}') === 0) { $_file = str_replace(array('{cbsite}', '{CBSite}'), array(JPATH_SITE, JPATH_SITE), $_file); } $files_to_delete[] = $_file; } break; } } foreach ($files_to_delete as $file_to_delete) { if (JFile::exists($file_to_delete)) { JFile::delete($file_to_delete); } } } // final upload file moving $uploaded = JFile::upload($src, $dest . DS . $filename); if (!$uploaded) { $msg = JText::_('COM_CONTENTBUILDER_UPLOAD_FAILED'); } } if ($dest == '' || $uploaded !== true) { JRequest::setVar('cb_submission_failed', 1); JFactory::getApplication()->enqueueMessage($msg . ' (' . $infile . ')', 'error'); $the_upload_fields[$id]['value'] = ''; } else { if (strpos(strtolower($tmp_dest), '{cbsite}') === 0) { $dest = str_replace(array(JPATH_SITE, JPATH_SITE), array('{cbsite}', '{CBSite}'), $dest); } $values[$id] = $dest . DS . $filename; $the_upload_fields[$id]['value'] = $values[$id]; } $the_upload_fields[$id]['orig_value'] = JFile::makeSafe($file['name']); } if (trim($the_upload_fields[$id]['custom_validation_script'])) { $msg = self::customValidate(trim($the_upload_fields[$id]['custom_validation_script']), $the_upload_fields[$id], $merged = array_merge($the_upload_fields, $the_fields, $the_html_fields), JRequest::getCmd('record_id', ''), $data->form, isset($values[$id]) ? $values[$id] : ''); $msg = trim($msg); if (!empty($msg)) { JRequest::setVar('cb_submission_failed', 1); JFactory::getApplication()->enqueueMessage(trim($msg), 'error'); } } $removables = array(); $validations = explode(',', $the_upload_fields[$id]['validations']); foreach ($validations as $validation) { $plgs = CBPluginHelper::importPlugin('contentbuilder_validation', $validation); $removables = array_merge($removables, $plgs); } $dispatcher = JDispatcher::getInstance(); $results = $dispatcher->trigger('onValidate', array($the_upload_fields[$id], $merged = array_merge($the_upload_fields, $the_fields, $the_html_fields), JRequest::getCmd('record_id', ''), $data->form, isset($values[$id]) ? $values[$id] : '')); foreach ($removables as $removable) { $dispatcher->detach($removable); } $all_errors = implode('', $results); if (!empty($all_errors)) { if (isset($values[$id]) && JFile::exists($values[$id])) { JFile::delete($values[$id]); } JRequest::setVar('cb_submission_failed', 1); foreach ($results as $result) { $result = trim($result); if (!empty($result)) { JFactory::getApplication()->enqueueMessage(trim($result), 'error'); } } } } } else { if (isset($the_fields[$id])) { $the_fields[$id]['name'] = $name; $the_fields[$id]['value'] = $value; } } } } } } foreach ($names as $id => $name) { if (!in_array($id, $noneditable_fields)) { if (isset($the_upload_fields[$id]) && $id == $the_upload_fields[$id]['reference_id']) { // nothing, done above already } else { $f = null; if (isset($the_html_fields[$id])) { $value = JRequest::getVar('cb_' . $id, '', 'POST', 'STRING', JREQUEST_ALLOWHTML); $f = $the_html_fields[$id]; $the_html_fields[$id]['value'] = $value; } if (isset($the_failed_registration_fields[$id])) { $value = JRequest::getVar('cb_' . $id, '', 'POST', 'STRING', JREQUEST_NOTRIM | JREQUEST_ALLOWRAW); $f = $the_failed_registration_fields[$id]; $the_failed_registration_fields[$id]['value'] = $value; } if (isset($the_fields[$id])) { $is_array = 'STRING'; if (is_array(JRequest::getVar('cb_' . $id, ''))) { $is_array = 'ARRAY'; } if (isset($the_fields[$id]['options']->allow_raw) && $the_fields[$id]['options']->allow_raw) { $value = JRequest::getVar('cb_' . $id, '', 'POST', $is_array, JREQUEST_ALLOWRAW); } else { if (isset($the_fields[$id]['options']->allow_html) && $the_fields[$id]['options']->allow_html) { $value = JRequest::getVar('cb_' . $id, '', 'POST', $is_array, JREQUEST_ALLOWHTML); } else { $value = JRequest::getVar('cb_' . $id, '', 'POST', $is_array); } } if (isset($the_fields[$id]['options']->transfer_format)) { $value = contentbuilder_convert_date($value, $the_fields[$id]['options']->format, $the_fields[$id]['options']->transfer_format); } $f = $the_fields[$id]; $the_fields[$id]['value'] = $value; } if ($f !== null) { if (trim($f['custom_validation_script'])) { $msg = self::customValidate(trim($f['custom_validation_script']), $f, $merged = array_merge($the_upload_fields, $the_fields, $the_html_fields), JRequest::getCmd('record_id', ''), $data->form, $value); $msg = trim($msg); if (!empty($msg)) { JRequest::setVar('cb_submission_failed', 1); JFactory::getApplication()->enqueueMessage(trim($msg), 'error'); } } $removables = array(); $validations = explode(',', $f['validations']); foreach ($validations as $validation) { $plgs = CBPluginHelper::importPlugin('contentbuilder_validation', $validation); $removables = array_merge($removables, $plgs); } $dispatcher = JDispatcher::getInstance(); $results = $dispatcher->trigger('onValidate', array($f, $merged = array_merge($the_upload_fields, $the_fields, $the_html_fields), JRequest::getCmd('record_id', ''), $data->form, $value)); foreach ($removables as $removable) { $dispatcher->detach($removable); } $all_errors = implode('', $results); $values[$id] = $value; if (!empty($all_errors)) { JRequest::setVar('cb_submission_failed', 1); foreach ($results as $result) { $result = trim($result); if (!empty($result)) { JFactory::getApplication()->enqueueMessage(trim($result), 'error'); } } } else { $removables = array(); $plgs = CBPluginHelper::importPlugin('contentbuilder_form_elements', $f['type']); $removables = array_merge($removables, $plgs); $dispatcher = JDispatcher::getInstance(); $plugin_validations = $dispatcher->trigger('onAfterValidationSuccess', array($f, $m = array_merge($the_upload_fields, $the_fields, $the_html_fields), JRequest::getCmd('record_id', ''), $data->form, $value)); if (count($plugin_validations)) { $form_elements_objects[] = $plugin_validations[0]; } foreach ($removables as $removable) { $dispatcher->detach($removable); } } } } } } $submit_before_result = $submit_dispatcher->trigger('onBeforeSubmit', array(JRequest::getCmd('record_id', ''), $data->form, $values)); if (JRequest::getVar('cb_submission_failed', 0)) { JFactory::getSession()->set('cb_failed_values', $values, 'com_contentbuilder.' . $this->_id); return JRequest::getCmd('record_id', ''); } $record_return = $data->form->saveRecord(JRequest::getCmd('record_id', ''), $values); foreach ($form_elements_objects as $form_elements_object) { if ($form_elements_object instanceof CBFormElementAfterValidation) { $form_elements_object->onSaveRecord($record_return); } } if ($data->act_as_registration && $record_return) { $meta = $data->form->getRecordMetadata($record_return); if (!$data->registration_bypass_plugin || $meta->created_id) { $user_id = $this->register('', '', '', $meta->created_id, JRequest::getVar('cb_' . $the_name_field['reference_id'], '', 'POST', 'STRING', JREQUEST_ALLOWRAW), JRequest::getVar('cb_' . $the_username_field['reference_id'], '', 'POST', 'STRING', JREQUEST_NOTRIM | JREQUEST_ALLOWRAW), JRequest::getVar('cb_' . $the_email_field['reference_id'], '', 'POST', 'STRING', JREQUEST_ALLOWRAW), JRequest::getVar('cb_' . $the_password_field['reference_id'], '', 'POST', 'STRING', JREQUEST_NOTRIM | JREQUEST_ALLOWRAW)); if (intval($user_id) > 0) { JFactory::getSession()->set('cb_last_record_user_id', $user_id, 'com_contentbuilder'); $data->form->saveRecordUserData($record_return, $user_id, JRequest::getVar('cb_' . $the_name_field['reference_id'], '', 'POST', 'STRING', JREQUEST_ALLOWRAW), JRequest::getVar('cb_' . $the_username_field['reference_id'], '', 'POST', 'STRING', JREQUEST_NOTRIM | JREQUEST_ALLOWRAW)); } } else { if (!$meta->created_id) { $bypass = new stdClass(); $verification_name = str_replace(array(';', '___', '|'), '-', trim($data->registration_bypass_verification_name) ? trim($data->registration_bypass_verification_name) : $data->title); $verify_view = trim($data->registration_bypass_verify_view) ? trim($data->registration_bypass_verify_view) : $data->id; $bypass->text = $orig_text = '{CBVerify plugin: ' . $data->registration_bypass_plugin . '; verification-name: ' . $verification_name . '; verify-view: ' . $verify_view . '; ' . str_replace(array("\r", "\n"), '', $data->registration_bypass_plugin_params) . '}'; $params = new stdClass(); JPluginHelper::importPlugin('content', 'contentbuilder_verify'); $bypass_dispatcher = JDispatcher::getInstance(); $bypass_result = $bypass_dispatcher->trigger('onPrepareContent', array(&$bypass, &$params)); $verification_id = ''; if ($bypass->text != $orig_text) { $verification_id = md5(uniqid(null, true) . mt_rand(0, mt_getrandmax()) . JFactory::getUser()->get('id', 0)); } $user_id = $this->register($data->registration_bypass_plugin, $verification_name, $verification_id, $meta->created_id, JRequest::getVar('cb_' . $the_name_field['reference_id'], '', 'POST', 'STRING', JREQUEST_ALLOWRAW), JRequest::getVar('cb_' . $the_username_field['reference_id'], '', 'POST', 'STRING', JREQUEST_NOTRIM | JREQUEST_ALLOWRAW), JRequest::getVar('cb_' . $the_email_field['reference_id'], '', 'POST', 'STRING', JREQUEST_ALLOWRAW), JRequest::getVar('cb_' . $the_password_field['reference_id'], '', 'POST', 'STRING', JREQUEST_NOTRIM | JREQUEST_ALLOWRAW)); if (intval($user_id) > 0) { JFactory::getSession()->set('cb_last_record_user_id', $user_id, 'com_contentbuilder'); $data->form->saveRecordUserData($record_return, $user_id, JRequest::getVar('cb_' . $the_name_field['reference_id'], '', 'POST', 'STRING', JREQUEST_ALLOWRAW), JRequest::getVar('cb_' . $the_username_field['reference_id'], '', 'POST', 'STRING', JREQUEST_NOTRIM | JREQUEST_ALLOWRAW)); } if ($bypass->text != $orig_text && intval($user_id) > 0) { $_now = JFactory::getDate(); $setup = JFactory::getSession()->get($data->registration_bypass_plugin . $verification_name, '', 'com_contentbuilder.verify.' . $data->registration_bypass_plugin . $verification_name); JFactory::getSession()->clear($data->registration_bypass_plugin . $verification_name, 'com_contentbuilder.verify.' . $data->registration_bypass_plugin . $verification_name); jimport('joomla.version'); $version = new JVersion(); if (version_compare($version->getShortVersion(), '3.0', '>=')) { $___now = $_now->toSql(); } else { $___now = $_now->toMySQL(); } $this->_db->setQuery("\n Insert Into #__contentbuilder_verifications\n (\n `verification_hash`,\n `start_date`,\n `verification_data`,\n `user_id`,\n `plugin`,\n `ip`,\n `setup`,\n `client`\n )\n Values\n (\n " . $this->_db->Quote($verification_id) . ",\n " . $this->_db->Quote($___now) . ",\n " . $this->_db->Quote('type=registration&') . ",\n " . $user_id . ",\n " . $this->_db->Quote($data->registration_bypass_plugin) . ",\n " . $this->_db->Quote($_SERVER['REMOTE_ADDR']) . ",\n " . $this->_db->Quote($setup) . ",\n " . intval(JFactory::getApplication()->isAdmin() ? 1 : 0) . "\n )\n "); $this->_db->query(); } } } } if ($this->frontend && !JRequest::getCmd('record_id', '') && $record_return && !JRequest::getVar('return', '')) { if ($data->force_login) { if (!JFactory::getUser()->get('id', 0)) { if (!$this->is15) { JRequest::setVar('return', base64_encode(JRoute::_('index.php?option=com_users&view=login&Itemid=' . JRequest::getInt('Itemid', 0), false))); } else { JRequest::setVar('return', base64_encode(JRoute::_('index.php?option=com_user&view=login&Itemid=' . JRequest::getInt('Itemid', 0), false))); } } else { if (!$this->is15) { JRequest::setVar('return', base64_encode(JRoute::_('index.php?option=com_users&view=profile&Itemid=' . JRequest::getInt('Itemid', 0), false))); } else { JRequest::setVar('return', base64_encode(JRoute::_('index.php?option=com_user&view=user&Itemid=' . JRequest::getInt('Itemid', 0), false))); } } } else { if (trim($data->force_url)) { JRequest::setVar('cbInternalCheck', 0); JRequest::setVar('return', base64_encode(trim($data->force_url))); } } } if ($record_return) { $sef = ''; $ignore_lang_code = '*'; if ($data->default_lang_code_ignore) { jimport('joomla.version'); $version = new JVersion(); if (version_compare($version->getShortVersion(), '1.6', '>=')) { $this->_db->setQuery("Select lang_code From #__languages Where published = 1 And sef = " . $this->_db->Quote(trim(JRequest::getCmd('lang', '')))); $ignore_lang_code = $this->_db->loadResult(); if (!$ignore_lang_code) { $ignore_lang_code = '*'; } } else { $codes = contentbuilder::getLanguageCodes(); foreach ($codes as $code) { if (strstr(strtolower($code), strtolower(trim(JRequest::getCmd('lang', '')))) !== false) { $ignore_lang_code = strtolower($code); break; } } } $sef = trim(JRequest::getCmd('lang', '')); if ($ignore_lang_code == '*') { $sef = ''; } } else { jimport('joomla.version'); $version = new JVersion(); if (version_compare($version->getShortVersion(), '1.6', '>=')) { $this->_db->setQuery("Select sef From #__languages Where published = 1 And lang_code = " . $this->_db->Quote($data->default_lang_code)); $sef = $this->_db->loadResult(); } else { $codes = contentbuilder::getLanguageCodes(); foreach ($codes as $code) { if ($code == $data->default_lang_code) { $sef = explode('-', $code); if (count($sef)) { $sef = strtolower($sef[0]); } break; } } } } $language = $data->default_lang_code_ignore ? $ignore_lang_code : $data->default_lang_code; $this->_db->setQuery("Select id, edited From #__contentbuilder_records Where `type` = " . $this->_db->Quote($data->type) . " And `reference_id` = " . $this->_db->Quote($data->form->getReferenceId()) . " And record_id = " . $this->_db->Quote($record_return)); $res = $this->_db->loadAssoc(); $last_update = JFactory::getDate(); jimport('joomla.version'); $version = new JVersion(); if (version_compare($version->getShortVersion(), '3.0', '>=')) { $last_update = $last_update->toSql(); } else { $last_update = $last_update->toMySQL(); } if (!is_array($res)) { $is_future = 0; $created_up = JFactory::getDate(); if (version_compare($version->getShortVersion(), '3.0', '>=')) { $created_up = $created_up->toSql(); } else { $created_up = $created_up->toMySQL(); } if (intval($data->default_publish_up_days) != 0) { $is_future = 1; $date = JFactory::getDate(strtotime('now +' . intval($data->default_publish_up_days) . ' days')); if (version_compare($version->getShortVersion(), '3.0', '>=')) { $created_up = $date->toSql(); } else { $created_up = $date->toMySQL(); } } $created_down = '0000-00-00 00:00:00'; if (intval($data->default_publish_down_days) != 0) { $date = JFactory::getDate(strtotime($created_up . ' +' . intval($data->default_publish_down_days) . ' days')); if (version_compare($version->getShortVersion(), '3.0', '>=')) { $created_down = $date->toSql(); } else { $created_down = $date->toMySQL(); } } $this->_db->setQuery("Insert Into #__contentbuilder_records (session_id,`type`,last_update,is_future,lang_code, sef, published, record_id, reference_id, publish_up, publish_down) Values ('" . JFactory::getSession()->getId() . "'," . $this->_db->Quote($data->type) . "," . $this->_db->Quote($last_update) . ",{$is_future}," . $this->_db->Quote($language) . "," . $this->_db->Quote(trim($sef)) . "," . $this->_db->Quote($data->auto_publish && !$is_future ? 1 : 0) . ", " . $this->_db->Quote($record_return) . ", " . $this->_db->Quote($data->form->getReferenceId()) . ", " . $this->_db->Quote($created_up) . ", " . $this->_db->Quote($created_down) . ")"); $this->_db->query(); } else { $this->_db->setQuery("Update #__contentbuilder_records Set last_update = " . $this->_db->Quote($last_update) . ",lang_code = " . $this->_db->Quote($language) . ", sef = " . $this->_db->Quote(trim($sef)) . ", edited = edited + 1 Where `type` = " . $this->_db->Quote($data->type) . " And `reference_id` = " . $this->_db->Quote($data->form->getReferenceId()) . " And record_id = " . $this->_db->Quote($record_return)); $this->_db->query(); } } } else { $record_return = JRequest::getCmd('record_id', ''); } $data->items = $data->form->getRecord($record_return, $data->published_only, $this->frontend ? $data->own_only_fe ? JFactory::getUser()->get('id', 0) : -1 : ($data->own_only ? JFactory::getUser()->get('id', 0) : -1), true); $data_email_items = $data->form->getRecord($record_return, false, -1, false); $data->labels = $data->form->getElementLabels(); $ids = array(); foreach ($data->labels as $reference_id => $label) { $ids[] = $this->_db->Quote($reference_id); } $data->labels = array(); if (count($ids)) { $this->_db->setQuery("Select Distinct `label`, reference_id From #__contentbuilder_elements Where form_id = " . intval($this->_id) . " And reference_id In (" . implode(',', $ids) . ") And published = 1 Order By ordering"); $rows = $this->_db->loadAssocList(); $ids = array(); foreach ($rows as $row) { $ids[] = $row['reference_id']; } } $article_id = 0; // creating the article if ($data->create_articles && count($data->items)) { $data->page_title = $data->use_view_name_as_title ? $data->name : $data->form->getPageTitle(); //if(!count($data->items)){ // JError::raiseError(404, JText::_('COM_CONTENTBUILDER_RECORD_NOT_FOUND')); //} $this->_db->setQuery("Select articles.`id` From #__contentbuilder_articles As articles, #__content As content Where content.id = articles.article_id And (content.state = 1 Or content.state = 0) And articles.form_id = " . intval($this->_id) . " And articles.record_id = " . $this->_db->Quote($record_return)); $article = $this->_db->loadResult(); $config = array(); if ($article) { if (!$this->is15) { $config = JRequest::getVar('jform', array()); } else { $config = array('ordering' => JRequest::getInt('ordering', 0), 'sectionid' => JRequest::getInt('sectionid', 0), 'catid' => JRequest::getInt('catid', 0), 'alias' => JRequest::getVar('alias', ''), 'frontpage' => JRequest::getInt('frontpage', 0), 'state' => JRequest::getInt('state', 0), 'details' => JRequest::getVar('details', array()), 'params' => JRequest::getVar('params', array()), 'meta' => JRequest::getVar('meta', array())); } } $full = $this->frontend ? contentbuilder::authorizeFe('fullarticle') : contentbuilder::authorize('fullarticle'); $article_id = contentbuilder::createArticle($this->_id, $record_return, $data->items, $ids, $data->title_field, $data->form->getRecordMetadata($record_return), $config, $full, $this->frontend ? $data->limited_article_options_fe : $data->limited_article_options, JRequest::getVar('cb_category_id', null)); if (isset($form_elements_objects)) { foreach ($form_elements_objects as $form_elements_object) { if ($form_elements_object instanceof CBFormElementAfterValidation) { $form_elements_object->onSaveArticle($article_id); } } } } // required to determine blocked users in system plugin if ($data->act_as_registration && isset($user_id) && intval($user_id) > 0) { $this->_db->setQuery("Insert Into #__contentbuilder_registered_users (user_id, form_id, record_id) Values (" . intval($user_id) . ", " . $this->_id . ", " . $this->_db->Quote($record_return) . ")"); $this->_db->query(); } if (!$data->edit_by_type) { $cleanedValues = array(); foreach ($values as $rawvalue) { if (is_array($rawvalue)) { if (isset($rawvalue[0]) && $rawvalue[0] == 'cbGroupMark') { unset($rawvalue[0]); $cleanedValues[] = array_values($rawvalue); } else { $cleanedValues[] = $rawvalue; } } else { $cleanedValues[] = $rawvalue; } } $submit_after_result = $submit_dispatcher->trigger('onAfterSubmit', array($record_return, $article_id, $data->form, $cleanedValues)); foreach ($fields as $actionField) { if (trim($actionField['custom_action_script'])) { self::customAction(trim($actionField['custom_action_script']), $record_return, $article_id, $data->form, $actionField, $fields, $cleanedValues); } } if (!JRequest::getCmd('record_id', '') && $data->email_notifications || JRequest::getCmd('record_id', '') && $data->email_update_notifications) { $from = $MailFrom = CBCompat::getJoomlaConfig('config.mailfrom'); $fromname = CBCompat::getJoomlaConfig('config.fromname'); $mailer = JFactory::getMailer(); $email_admin_template = ''; $email_template = ''; // admin email if (trim($data->email_admin_recipients)) { // sender if (trim($data->email_admin_alternative_from)) { foreach ($data->items as $item) { $data->email_admin_alternative_from = str_replace('{' . $item->recName . '}', cbinternal($item->recValue), $data->email_admin_alternative_from); } $from = $data->email_admin_alternative_from; } if (trim($data->email_admin_alternative_fromname)) { foreach ($data->items as $item) { $data->email_admin_alternative_fromname = str_replace('{' . $item->recName . '}', cbinternal($item->recValue), $data->email_admin_alternative_fromname); } $fromname = $data->email_admin_alternative_fromname; } $mailer->setSender(array(trim($MailFrom), trim($fromname))); $mailer->addReplyTo(array($from, $fromname)); // recipients foreach ($data->items as $item) { $data->email_admin_recipients = str_replace('{' . $item->recName . '}', cbinternal($item->recValue), $data->email_admin_recipients); } $recipients_checked_admin = array(); $recipients_admin = explode(';', $data->email_admin_recipients); foreach ($recipients_admin as $recipient_admin) { if (contentbuilder_is_email(trim($recipient_admin))) { $recipients_checked_admin[] = trim($recipient_admin); } } $mailer->addBCC($recipients_checked_admin); $email_admin_template = contentbuilder::getEmailTemplate($this->_id, $record_return, $data_email_items, $ids, true); // subject $subject_admin = JText::_('COM_CONTENTBUILDER_EMAIL_RECORD_RECEIVED'); if (trim($data->email_admin_subject)) { foreach ($data->items as $item) { $data->email_admin_subject = str_replace('{' . $item->recName . '}', cbinternal($item->recValue), $data->email_admin_subject); } $subject_admin = $data->email_admin_subject; $subject_admin = str_replace(array('{RECORD_ID}', '{record_id}'), $record_return, $subject_admin); $subject_admin = str_replace(array('{USER_ID}', '{user_id}'), JFactory::getUser()->get('id'), $subject_admin); $subject_admin = str_replace(array('{USERNAME}', '{username}'), JFactory::getUser()->get('username'), $subject_admin); $subject_admin = str_replace(array('{USER_FULL_NAME}', '{user_full_name}'), JFactory::getUser()->get('name'), $subject_admin); $subject_admin = str_replace(array('{EMAIL}', '{email}'), JFactory::getUser()->get('email'), $subject_admin); $subject_admin = str_replace(array('{VIEW_NAME}', '{view_name}'), $data->name, $subject_admin); $subject_admin = str_replace(array('{VIEW_ID}', '{view_id}'), $this->_id, $subject_admin); $subject_admin = str_replace(array('{IP}', '{ip}'), $_SERVER['REMOTE_ADDR'], $subject_admin); } $mailer->setSubject($subject_admin); // attachments foreach ($data->items as $item) { $data->email_admin_recipients_attach_uploads = str_replace('{' . $item->recName . '}', $item->recValue, $data->email_admin_recipients_attach_uploads); } $attachments_admin = explode(';', $data->email_admin_recipients_attach_uploads); $attached_admin = array(); foreach ($attachments_admin as $attachment_admin) { $attachment_admin = explode("\n", str_replace("\r", "", trim($attachment_admin))); foreach ($attachment_admin as $att_admin) { if (strpos(strtolower($att_admin), '{cbsite}') === 0) { $att_admin = str_replace(array('{cbsite}', '{CBSite}'), array(JPATH_SITE, JPATH_SITE), $att_admin); } if (JFile::exists(trim($att_admin))) { $attached_admin[] = trim($att_admin); } } } $mailer->addAttachment($attached_admin); $mailer->isHTML($data->email_admin_html); $mailer->setBody($email_admin_template); if (count($recipients_checked_admin)) { $send = $mailer->Send(); if ($send !== true) { JFactory::getApplication()->enqueueMessage('Error sending email: ' . $mailer->ErrorInfo, 'error'); } } $mailer->ClearAddresses(); $mailer->ClearAllRecipients(); $mailer->ClearAttachments(); } // public email if (trim($data->email_recipients)) { // sender if (trim($data->email_alternative_from)) { foreach ($data->items as $item) { $data->email_alternative_from = str_replace('{' . $item->recName . '}', cbinternal($item->recValue), $data->email_alternative_from); } $from = $data->email_alternative_from; } if (trim($data->email_alternative_fromname)) { foreach ($data->items as $item) { $data->email_alternative_fromname = str_replace('{' . $item->recName . '}', cbinternal($item->recValue), $data->email_alternative_fromname); } $fromname = $data->email_alternative_fromname; } $mailer->setSender(array(trim($MailFrom), trim($fromname))); $mailer->addReplyTo(array($from, $fromname)); // recipients foreach ($data->items as $item) { $data->email_recipients = str_replace('{' . $item->recName . '}', cbinternal($item->recValue), $data->email_recipients); } $recipients_checked = array(); $recipients = explode(';', $data->email_recipients); foreach ($recipients as $recipient) { if (contentbuilder_is_email($recipient)) { $recipients_checked[] = $recipient; } } $mailer->addBCC($recipients_checked); $email_template = contentbuilder::getEmailTemplate($this->_id, $record_return, $data_email_items, $ids, false); // subject $subject = JText::_('COM_CONTENTBUILDER_EMAIL_RECORD_RECEIVED'); if (trim($data->email_subject)) { foreach ($data->items as $item) { $data->email_subject = str_replace('{' . $item->recName . '}', cbinternal($item->recValue), $data->email_subject); } $subject = $data->email_subject; $subject = str_replace(array('{RECORD_ID}', '{record_id}'), $record_return, $subject); $subject = str_replace(array('{USER_ID}', '{user_id}'), JFactory::getUser()->get('id'), $subject); $subject = str_replace(array('{USERNAME}', '{username}'), JFactory::getUser()->get('username'), $subject); $subject = str_replace(array('{EMAIL}', '{email}'), JFactory::getUser()->get('email'), $subject); $subject = str_replace(array('{USER_FULL_NAME}', '{user_full_name}'), JFactory::getUser()->get('name'), $subject); $subject = str_replace(array('{VIEW_NAME}', '{view_name}'), $data->name, $subject); $subject = str_replace(array('{VIEW_ID}', '{view_id}'), $this->_id, $subject); $subject = str_replace(array('{IP}', '{ip}'), $_SERVER['REMOTE_ADDR'], $subject); } $mailer->setSubject($subject); // attachments foreach ($data->items as $item) { $data->email_recipients_attach_uploads = str_replace('{' . $item->recName . '}', $item->recValue, $data->email_recipients_attach_uploads); } $attachments = explode(';', $data->email_recipients_attach_uploads); $attached = array(); foreach ($attachments as $attachment) { $attachment = explode("\n", str_replace("\r", "", trim($attachment))); foreach ($attachment as $att) { if (strpos(strtolower($att), '{cbsite}') === 0) { $att = str_replace(array('{cbsite}', '{CBSite}'), array(JPATH_SITE, JPATH_SITE), $att); } if (JFile::exists(trim($att))) { $attached[] = trim($att); } } } $mailer->addAttachment($attached); $mailer->isHTML($data->email_html); $mailer->setBody($email_template); if (count($recipients_checked)) { $send = $mailer->Send(); if ($send !== true) { JFactory::getApplication()->enqueueMessage('Error sending email: ' . $mailer->ErrorInfo, 'error'); } } $mailer->ClearAddresses(); $mailer->ClearAllRecipients(); $mailer->ClearAttachments(); } } } return $record_return; } } if (!$this->is15) { $cache = JFactory::getCache('com_content'); $cache->clean(); $cache = JFactory::getCache('com_contentbuilder'); $cache->clean(); } else { $cache = JFactory::getCache('com_content'); $cache->clean(); $cache = JFactory::getCache('com_contentbuilder'); $cache->clean(); } return false; }
function installAndUpdate() { require_once JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'classes' . DS . 'joomla_compat.php'; $db = JFactory::getDBO(); $tables = CBCompat::getTableFields(JFactory::getDBO()->getTableList()); // articles updates if (isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_articles'])) { if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_articles']['type'])) { JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_articles` ADD `type` VARCHAR( 55 ) NOT NULL DEFAULT '' AFTER `article_id` , ADD `reference_id` VARCHAR( 100 ) NOT NULL DEFAULT '' AFTER `type` "); JFactory::getDBO()->query(); } } // storages updates if (isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_storages'])) { if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_storages']['bytable'])) { JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_storages` ADD `bytable` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `title` "); JFactory::getDBO()->query(); } } // forms updates if (isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_forms'])) { if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_forms']['initial_order_dir'])) { JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_forms` ADD `initial_order_dir` VARCHAR( 4 ) NOT NULL DEFAULT 'desc' AFTER `initial_sort_order` "); JFactory::getDBO()->query(); } if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_forms']['list_rating'])) { JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_forms` ADD `list_rating` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `theme_plugin` "); JFactory::getDBO()->query(); } if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_forms']['rating_slots'])) { JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_forms` ADD `rating_slots` TINYINT( 1 ) NOT NULL DEFAULT '5' AFTER `list_rating` "); JFactory::getDBO()->query(); } if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_forms']['rand_date_update'])) { JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_forms` ADD `rand_date_update` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `rating_slots` , ADD INDEX ( `rand_date_update` ) "); JFactory::getDBO()->query(); } if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_forms']['rand_update'])) { JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_forms` ADD `rand_update` INT NOT NULL DEFAULT '86400' AFTER `rand_date_update` "); JFactory::getDBO()->query(); } if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_forms']['article_record_impact_publish'])) { JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_forms` ADD `article_record_impact_publish` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `rand_update` , ADD `article_record_impact_language` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `article_record_impact_publish` "); JFactory::getDBO()->query(); } if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_forms']['allow_external_filter'])) { JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_forms` ADD `allow_external_filter` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `article_record_impact_language` "); JFactory::getDBO()->query(); } if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_forms']['show_filter'])) { JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_forms` ADD `show_filter` TINYINT( 1 ) NOT NULL DEFAULT '1' AFTER `allow_external_filter` "); JFactory::getDBO()->query(); } if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_forms']['show_records_per_page'])) { JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_forms` ADD `show_records_per_page` TINYINT( 1 ) NOT NULL DEFAULT '1' AFTER `show_filter` "); JFactory::getDBO()->query(); } if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_forms']['initial_list_limit'])) { JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_forms` ADD `initial_list_limit` TINYINT NOT NULL DEFAULT '20' AFTER `show_records_per_page` "); JFactory::getDBO()->query(); // exceptionally here JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_articles` ADD INDEX ( `type` )"); JFactory::getDBO()->query(); } if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_forms']['tag'])) { JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_forms` ADD `tag` VARCHAR( 255 ) NOT NULL DEFAULT '' AFTER `name`, ADD INDEX ( `tag` ) "); JFactory::getDBO()->query(); } if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_forms']['save_button_title'])) { JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_forms` ADD `save_button_title` VARCHAR( 255 ) NOT NULL DEFAULT '' AFTER `initial_list_limit` , ADD `apply_button_title` VARCHAR( 255 ) NOT NULL DEFAULT '' AFTER `save_button_title` "); JFactory::getDBO()->query(); } if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_forms']['filter_exact_match'])) { JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_forms` ADD `filter_exact_match` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `save_button_title`"); JFactory::getDBO()->query(); } if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_forms']['initial_sort_order2'])) { JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_forms` ADD `initial_sort_order2` VARCHAR( 255 ) NOT NULL DEFAULT '-1' AFTER `initial_sort_order` , ADD `initial_sort_order3` VARCHAR( 255 ) NOT NULL DEFAULT '-1' AFTER `initial_sort_order2` "); JFactory::getDBO()->query(); } } // elements updates if (isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_elements'])) { if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_elements']['order_type'])) { JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_elements` ADD `order_type` VARCHAR( 255 ) NOT NULL DEFAULT '' AFTER `published` "); JFactory::getDBO()->query(); } } // records updates if (isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_records'])) { if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_records']['rating_sum'])) { JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_records` ADD `rating_sum` INT( 10 ) NOT NULL DEFAULT '0' AFTER `is_future` "); JFactory::getDBO()->query(); } if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_records']['rating_count'])) { JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_records` ADD `rating_count` INT( 10 ) NOT NULL DEFAULT '0' AFTER `rating_sum` "); JFactory::getDBO()->query(); } if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_records']['lastip'])) { JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_records` ADD `lastip` VARCHAR( 50 ) NOT NULL DEFAULT '' AFTER `rating_count` "); JFactory::getDBO()->query(); } if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_records']['type'])) { JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_records` ADD `type` VARCHAR( 255 ) NOT NULL DEFAULT '' AFTER `id` "); JFactory::getDBO()->query(); } JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_records` ADD INDEX ( `type` )"); JFactory::getDBO()->query(); if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_records']['session_id'])) { JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_records` ADD `session_id` VARCHAR( 32 ) NOT NULL DEFAULT '' AFTER `lastip` "); JFactory::getDBO()->query(); } if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_records']['rand_date'])) { JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_records` ADD `rand_date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `published` , ADD INDEX ( `rand_date` ) "); JFactory::getDBO()->query(); } if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_records']['metadesc'])) { JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_records` ADD `metakey` TEXT NOT NULL ,ADD `metadesc` TEXT NOT NULL ,ADD `robots` VARCHAR( 255 ) NOT NULL DEFAULT '',ADD `author` VARCHAR( 255 ) NOT NULL DEFAULT '',ADD `rights` VARCHAR( 255 ) NOT NULL DEFAULT '',ADD `xreference` VARCHAR( 255 ) NOT NULL DEFAULT ''"); JFactory::getDBO()->query(); } } // element access if (isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_resource_access'])) { if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_resource_access']['type'])) { // sorry but we have to truncate the table JFactory::getDBO()->setQuery("TRUNCATE TABLE `#__contentbuilder_resource_access`"); JFactory::getDBO()->query(); JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_resource_access` ADD `type` VARCHAR( 100 ) NOT NULL DEFAULT '' FIRST "); JFactory::getDBO()->query(); JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_resource_access` DROP INDEX `form_id` "); JFactory::getDBO()->query(); JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_resource_access` ADD UNIQUE ( `type` , `element_id` , `resource_id` )"); JFactory::getDBO()->query(); } } // rating cache if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_rating_cache'])) { JFactory::getDBO()->setQuery("CREATE TABLE `#__contentbuilder_rating_cache` (\n `record_id` varchar(255) NOT NULL DEFAULT '',\n `form_id` int(11) NOT NULL DEFAULT '0',\n `ip` varchar(50) NOT NULL DEFAULT '',\n `date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',\n KEY `record_id` (`record_id`,`form_id`,`ip`),\n KEY `date` (`date`)\n ) ;"); JFactory::getDBO()->query(); } // switching to ints for record_id and reference_id if (isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_verifications'])) { if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_verifications']['create_invoice'])) { JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_verifications` ADD `create_invoice` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `verification_data` "); JFactory::getDBO()->query(); JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_articles` CHANGE `reference_id` `reference_id` INT NOT NULL DEFAULT '0', CHANGE `record_id` `record_id` BIGINT NOT NULL DEFAULT '0'"); JFactory::getDBO()->query(); JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_elements` CHANGE `reference_id` `reference_id` INT NOT NULL DEFAULT '0'"); JFactory::getDBO()->query(); JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_forms` CHANGE `reference_id` `reference_id` INT NOT NULL DEFAULT '0'"); JFactory::getDBO()->query(); JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_list_records` CHANGE `record_id` `record_id` BIGINT NOT NULL DEFAULT '0', CHANGE `reference_id` `reference_id` INT NOT NULL DEFAULT '0'"); JFactory::getDBO()->query(); JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_rating_cache` CHANGE `record_id` `record_id` BIGINT NOT NULL DEFAULT '0'"); JFactory::getDBO()->query(); JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_registered_users` CHANGE `record_id` `record_id` BIGINT NOT NULL DEFAULT '0'"); JFactory::getDBO()->query(); JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_records` CHANGE `record_id` `record_id` BIGINT NOT NULL DEFAULT '0', CHANGE `reference_id` `reference_id` INT NOT NULL DEFAULT '0'"); JFactory::getDBO()->query(); JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_resource_access` CHANGE `element_id` `element_id` INT NOT NULL DEFAULT '0'"); JFactory::getDBO()->query(); } } // trying to ease the 0.9 update pain $db->setQuery("Select `type`,`reference_id` From #__contentbuilder_forms"); $typeref = $db->loadAssocList(); foreach ($typeref as $tr) { $db->setQuery("Update #__contentbuilder_records Set `type` = " . $db->Quote($tr['type']) . " Where `type` = '' And reference_id = " . $db->Quote($tr['reference_id'])); $db->query(); } jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); jimport('joomla.version'); // cleaning up leftovers (additional list view overrides, that didn't work with J! 1.7 for ($a = 1; $a <= 5; $a++) { if (JFile::exists(JPATH_SITE . DS . 'components' . DS . 'com_contentbuilder' . DS . 'views' . DS . 'list' . DS . 'tmpl' . DS . 'custom' . $a . '.php')) { JFile::delete(JPATH_SITE . DS . 'components' . DS . 'com_contentbuilder' . DS . 'views' . DS . 'list' . DS . 'tmpl' . DS . 'custom' . $a . '.php'); } if (JFile::exists(JPATH_SITE . DS . 'components' . DS . 'com_contentbuilder' . DS . 'views' . DS . 'list' . DS . 'tmpl' . DS . 'custom' . $a . '.xml')) { JFile::delete(JPATH_SITE . DS . 'components' . DS . 'com_contentbuilder' . DS . 'views' . DS . 'list' . DS . 'tmpl' . DS . 'custom' . $a . '.xml'); } } $version = new JVersion(); $plugins = $this->getPlugins(); $base_path = JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'plugins'; $folders = JFolder::folders($base_path); $installer = new JInstaller(); foreach ($folders as $folder) { echo 'Installing plugin <b>' . $folder . '</b><br/>'; $success = $installer->install($base_path . DS . $folder); if (!$success) { echo 'Install failed for plugin <b>' . $folder . '</b><br/>'; } echo '<hr/>'; } foreach ($plugins as $folder => $subplugs) { foreach ($subplugs as $plugin) { if (version_compare($version->getShortVersion(), '1.6', '>=')) { $db->setQuery('Update #__extensions Set `enabled` = 1 WHERE `type` = "plugin" AND `element` = "' . $plugin . '" AND `folder` = "' . $folder . '"'); } else { $db->setQuery('Update #__plugins Set `published` = 1 WHERE `element` = "' . $plugin . '" AND `folder` = "' . $folder . '"'); } $db->query(); echo 'Published plugin ' . $plugin . '<hr/>'; } } }
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; } }
<?php /** * @package ContentBuilder * @author Markus Bopp * @link http://www.crosstec.de * @license GNU/GPL */ // No direct access defined('_JEXEC') or die('Restricted access'); require_once JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'classes' . DS . 'joomla_compat.php'; CBCompat::requireModel(); require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'classes' . DS . 'contentbuilder.php'; class ContentbuilderModelExport extends CBModel { private $frontend = false; private $_menu_filter = array(); private $_menu_filter_order = array(); function __construct($config) { parent::__construct($config); $this->frontend = JFactory::getApplication()->isSite(); $mainframe = JFactory::getApplication(); $option = 'com_contentbuilder'; $this->setId(JRequest::getInt('id', 0)); if (JFactory::getSession()->get($option . 'formsd_id', 0) == 0 || JFactory::getSession()->get($option . 'formsd_id', 0) == $this->_id) { $filter_order = $mainframe->getUserStateFromRequest($option . 'formsd_filter_order', 'filter_order', '', 'cmd'); $filter_order_Dir = $mainframe->getUserStateFromRequest($option . 'formsd_filter_order_Dir', 'filter_order_Dir', 'desc', 'cmd'); $filter = $mainframe->getUserStateFromRequest($option . 'formsd_filter', 'filter', '', 'string'); $filter_state = $mainframe->getUserStateFromRequest($option . 'formsd_filter_state', 'list_state_filter', 0, 'int'); $filter_publish = $mainframe->getUserStateFromRequest($option . 'formsd_filter_publish', 'list_publish_filter', -1, 'int');
public static function getLanguageCodes() { static $langs; if (is_array($langs)) { return $langs; } $db = JFactory::getDBO(); jimport('joomla.version'); $version = new JVersion(); if (version_compare($version->getShortVersion(), '1.6', '<')) { $langs = array(); $client =& JApplicationHelper::getClientInfo(0); jimport('joomla.filesystem.folder'); $path = JLanguage::getLanguagePath($client->path); $dirs = JFolder::folders($path); jimport('joomla.filesystem.folder'); $path = JLanguage::getLanguagePath($client->path); $dirs = JFolder::folders($path); foreach ($dirs as $dir) { $files = JFolder::files($path . DS . $dir, '^([-_A-Za-z]*)\\.xml$'); foreach ($files as $file) { $data = JApplicationHelper::parseXMLLangMetaFile($path . DS . $dir . DS . $file); $language = substr($file, 0, -4); if (!is_array($data)) { continue; } // if current than set published $params = JComponentHelper::getParams('com_languages'); //if ( $params->get($client->name, 'en-GB') == $language) { $langs[] = $language; //} } } return $langs; } else { $db->setQuery("Select lang_code From #__languages Where published = 1 Order By ordering"); $langs = CBCompat::loadColumn(); return $langs; } }
<?php /** * @package ContentBuilder * @author Markus Bopp * @link http://www.crosstec.de * @license GNU/GPL */ // no direct access defined('_JEXEC') or die('Restricted access'); require_once JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'classes' . DS . 'joomla_compat.php'; CBCompat::requireView(); class ContentbuilderViewVerify extends CBView { function display($tpl = null) { parent::display($tpl); } }
function delete() { jimport('joomla.database.table'); jimport('joomla.event.dispatcher'); jimport('joomla.version'); $is15 = true; $version = new JVersion(); if (version_compare($version->getShortVersion(), '1.6', '>=')) { $is15 = false; } $cids = JRequest::getVar('cid', array(0), 'post', 'array'); JArrayHelper::toInteger($cids); $row = $this->getTable(); foreach ($cids as $cid) { $this->_db->setQuery("Select article.article_id From #__contentbuilder_articles As article, #__contentbuilder_forms As form Where form.delete_articles > 0 And form.id = article.form_id And article.form_id = " . intval($cid)); $articles = CBCompat::loadColumn(); if (count($articles)) { $article_items = array(); foreach ($articles as $article) { $article_items[] = $this->_db->Quote('com_content.article.' . $article); $dispatcher = JDispatcher::getInstance(); $table = JTable::getInstance('content'); // Trigger the onContentBeforeDelete event. if (!$is15 && $table->load($article)) { $dispatcher->trigger('onContentBeforeDelete', array('com_content.article', $table)); } $this->_db->setQuery("Delete From #__content Where id = " . intval($article)); $this->_db->query(); // Trigger the onContentAfterDelete event. $table->reset(); if (!$is15) { $dispatcher->trigger('onContentAfterDelete', array('com_content.article', $table)); } } $this->_db->setQuery("Delete From #__assets Where `name` In (" . implode(',', $article_items) . ")"); $this->_db->query(); } $this->_db->setQuery("\n Delete\n `elements`.*\n From\n #__contentbuilder_elements As `elements`\n Where\n `elements`.form_id = " . $cid); $this->_db->query(); $this->_db->setQuery("\n Delete\n `states`.*\n From\n #__contentbuilder_list_states As `states`\n Where\n `states`.form_id = " . $cid); $this->_db->query(); $this->_db->setQuery("\n Delete\n `records`.*\n From\n #__contentbuilder_list_records As `records`\n Where\n `records`.form_id = " . $cid); $this->_db->query(); $this->_db->setQuery("\n Delete\n `access`.*\n From\n #__contentbuilder_resource_access As `access`\n Where\n `access`.form_id = " . $cid); $this->_db->query(); $this->_db->setQuery("\n Delete\n `users`.*\n From\n #__contentbuilder_users As `users`\n Where\n `users`.form_id = " . $cid); $this->_db->query(); $this->_db->setQuery("\n Delete\n `users`.*\n From\n #__contentbuilder_registered_users As `users`\n Where\n `users`.form_id = " . $cid); $this->_db->query(); $this->getTable('elements')->reorder('form_id = ' . $cid); jimport('joomla.version'); $version = new JVersion(); if (version_compare($version->getShortVersion(), '1.6', '<')) { $this->_db->setQuery("Delete From #__components Where admin_menu_link = 'option=com_contentbuilder&controller=list&id=" . intval($cid) . "'"); $this->_db->query(); $this->_db->setQuery("Select count(id) From #__components Where admin_menu_link Like 'option=com_contentbuilder&controller=list&id=%'"); $amount = $this->_db->loadResult(); if (!$amount) { $this->_db->setQuery("Delete From #__components Where admin_menu_link = 'option=com_contentbuilder&viewcontainer=true'"); $this->_db->query(); } } else { $this->_db->setQuery("Delete From #__menu Where `link` = 'index.php?option=com_contentbuilder&controller=list&id=" . intval($cid) . "'"); $this->_db->query(); $this->_db->setQuery("Select count(id) From #__menu Where `link` Like 'index.php?option=com_contentbuilder&controller=list&id=%'"); $amount = $this->_db->loadResult(); if (!$amount) { $this->_db->setQuery("Delete From #__menu Where `link` = 'index.php?option=com_contentbuilder&viewcontainer=true'"); $this->_db->query(); } } if (!$row->delete($cid)) { $this->setError($row->getErrorMsg()); return false; } } $row->reorder(); /* $this->_db->setQuery("Select `reference_id` From #__contentbuilder_forms"); $references = $this->_db->loadResultArray(); $cnt = count($references); if ($cnt) { $new_items = array(); for ($i = 0; $i < $cnt; $i++) { $new_items[] = $this->_db->Quote($references[$i]); } $this->_db->setQuery("Delete From #__contentbuilder_records Where `reference_id` Not In (" . implode(',',$new_items) . ") "); $this->_db->query(); }else{ $this->_db->setQuery("Delete From #__contentbuilder_records"); $this->_db->query(); }*/ // article deletion if required $this->_db->setQuery("Select `id` From #__contentbuilder_forms"); jimport('joomla.version'); $version = new JVersion(); if (version_compare($version->getShortVersion(), '3.0', '>=')) { $references = $this->_db->loadColumn(); } else { $references = $this->_db->loadResultArray(); } $cnt = count($references); if ($cnt) { $new_items = array(); for ($i = 0; $i < $cnt; $i++) { $new_items[] = $this->_db->Quote($references[$i]); } $this->_db->setQuery("Delete From #__contentbuilder_articles Where `form_id` Not In (" . implode(',', $new_items) . ") "); $this->_db->query(); } else { $this->_db->setQuery("Delete From #__contentbuilder_articles"); $this->_db->query(); } return true; }