function onContentPrepare($context, &$article, &$params, $limitstart = 0)
 {
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.folder');
     if (!JFile::exists(JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'classes' . DS . 'contentbuilder.php')) {
         return true;
     }
     if (isset($article->id) && $article->id) {
         $frontend = true;
         if (JFactory::getApplication()->isAdmin()) {
             $frontend = false;
         }
         $db = JFactory::getDBO();
         $db->setQuery("Select form.`reference_id`,article.`record_id`,article.`form_id`,form.`type`,form.`published_only`,form.`own_only`,form.`own_only_fe` From #__contentbuilder_articles As article, #__contentbuilder_forms As form Where form.`published` = 1 And form.id = article.`form_id` And article.`article_id` = " . $article->id);
         $data = $db->loadAssoc();
         require_once JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'classes' . DS . 'contentbuilder.php';
         $form = contentbuilder::getForm($data['type'], $data['reference_id']);
         if (!$form || !$form->exists) {
             return true;
         }
         if ($form && !(JRequest::getVar('option', '') == 'com_contentbuilder' && JRequest::getVar('controller', '') == 'edit')) {
             JFactory::getLanguage()->load('com_contentbuilder');
             contentbuilder::setPermissions($data['form_id'], $data['record_id'], $frontend ? '_fe' : '');
             if (JRequest::getCmd('view') == 'article') {
                 contentbuilder::checkPermissions('view', JText::_('COM_CONTENTBUILDER_PERMISSIONS_VIEW_NOT_ALLOWED'), $frontend ? '_fe' : '');
             } else {
                 if ($frontend) {
                     if (!contentbuilder::authorizeFe('view')) {
                         $article->text = JText::_('COM_CONTENTBUILDER_PERMISSIONS_VIEW_NOT_ALLOWED');
                     }
                 } else {
                     if (!contentbuilder::authorize('view')) {
                         $article->text = JText::_('COM_CONTENTBUILDER_PERMISSIONS_VIEW_NOT_ALLOWED');
                     }
                 }
             }
         }
     }
     return true;
 }
예제 #2
0
 function cbCheckPermissions()
 {
     // CONTENTBUILDER BEGIN
     jimport('joomla.filesystem.file');
     $cbData = null;
     $cbForm = null;
     $cbRecord = null;
     $cbFrontend = true;
     $cbFull = false;
     if (JFile::exists(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_contentbuilder' . DS . 'contentbuilder.xml')) {
         if (JFactory::getApplication()->isAdmin()) {
             $cbFrontend = false;
         }
         if ($cbFrontend) {
             JFactory::getLanguage()->load('com_contentbuilder');
         } else {
             JFactory::getLanguage()->load('com_contentbuilder', JPATH_SITE . DS . 'administrator');
         }
         $db = JFactory::getDBO();
         require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_contentbuilder' . DS . 'classes' . DS . 'contentbuilder.php';
         $db->setQuery("Select `id` From #__contentbuilder_forms Where `type` = 'com_breezingforms' And `reference_id` = " . intval($this->form) . " And published = 1");
         jimport('joomla.version');
         $version = new JVersion();
         if (version_compare($version->getShortVersion(), '3.0', '<')) {
             $cbForms = $db->loadResultArray();
         } else {
             $cbForms = $db->loadColumn();
         }
         // if no BF form is associated with contentbuilder, we don't need no further checks
         if (!count($cbForms)) {
             return array('form' => $cbForm, 'record' => $cbRecord, 'frontend' => $cbFrontend, 'data' => $cbData, 'full' => $cbFull);
         }
         // test if there is any published contentbuilder view that allows to create new submissions
         if (!JRequest::getInt('cb_record_id', 0) || !JRequest::getInt('cb_form_id', 0)) {
             $cbAuth = false;
             foreach ($cbForms as $cbFormId) {
                 contentbuilder::setPermissions($cbFormId, 0, $cbFrontend ? '_fe' : '');
                 if ($cbFrontend) {
                     $cbAuth = contentbuilder::authorizeFe('new');
                 } else {
                     $cbAuth = contentbuilder::authorize('new');
                 }
                 if ($cbAuth) {
                     break;
                 }
             }
             if (count($cbForms) && !$cbAuth) {
                 JError::raiseError(403, JText::_('COM_CONTENTBUILDER_PERMISSIONS_NEW_NOT_ALLOWED'));
             }
         }
         if (JRequest::getInt('cb_form_id', 0)) {
             // test the permissions of given record
             if (JRequest::getInt('cb_record_id', 0)) {
                 contentbuilder::setPermissions(JRequest::getInt('cb_form_id', 0), JRequest::getInt('cb_record_id', 0), $cbFrontend ? '_fe' : '');
                 contentbuilder::checkPermissions('edit', JText::_('COM_CONTENTBUILDER_PERMISSIONS_EDIT_NOT_ALLOWED'), $cbFrontend ? '_fe' : '');
             } else {
                 contentbuilder::setPermissions(JRequest::getInt('cb_form_id', 0), 0, $cbFrontend ? '_fe' : '');
                 contentbuilder::checkPermissions('new', JText::_('COM_CONTENTBUILDER_PERMISSIONS_NEW_NOT_ALLOWED'), $cbFrontend ? '_fe' : '');
             }
             $db->setQuery("Select * From #__contentbuilder_forms Where id = " . JRequest::getInt('cb_form_id', 0) . " And published = 1");
             $cbData = $db->loadAssoc();
             if (is_array($cbData)) {
                 $cbFull = $cbFrontend ? contentbuilder::authorizeFe('fullarticle') : contentbuilder::authorize('fullarticle');
                 $cbForm = contentbuilder::getForm('com_breezingforms', $cbData['reference_id']);
                 $cbRecord = $cbForm->getRecord(JRequest::getInt('cb_record_id', 0), $cbData['published_only'], $cbFrontend ? $cbData['own_only_fe'] ? JFactory::getUser()->get('id', 0) : -1 : ($cbData['own_only'] ? JFactory::getUser()->get('id', 0) : -1), $cbFrontend ? $cbData['show_all_languages_fe'] : true);
                 if (!count($cbRecord) && !JRequest::getBool('cbIsNew')) {
                     JError::raiseError(404, JText::_('COM_CONTENTBUILDER_RECORD_NOT_FOUND'));
                 }
             }
         }
     }
     return array('form' => $cbForm, 'record' => $cbRecord, 'frontend' => $cbFrontend, 'data' => $cbData, 'full' => $cbFull);
     // CONTENTBUILDER END
 }
예제 #3
0
 /**
  * Gets the currencies
  * @return array List of currencies
  */
 function getData()
 {
     // Lets load the data if it doesn't already exist
     if (empty($this->_data)) {
         $query = $this->_buildQuery();
         $this->_data = $this->_getList($query, 0, 1);
         if (!count($this->_data)) {
             JError::raiseError(404, JText::_('COM_CONTENTBUILDER_FORM_NOT_FOUND'));
         }
         foreach ($this->_data as $data) {
             if (!$this->frontend && $data->display_in == 0) {
                 JError::raiseError(404, JText::_('COM_CONTENTBUILDER_RECORD_NOT_FOUND'));
             } else {
                 if ($this->frontend && $data->display_in == 1) {
                     JError::raiseError(404, JText::_('COM_CONTENTBUILDER_RECORD_NOT_FOUND'));
                 }
             }
             $data->form_id = $this->_id;
             $data->record_id = $this->_record_id;
             if ($data->type && $data->reference_id) {
                 $data->form = contentbuilder::getForm($data->type, $data->reference_id);
                 $data->labels = $data->form->getElementLabels();
                 $ids = array();
                 foreach ($data->labels as $reference_id => $label) {
                     $ids[] = $this->_db->Quote($reference_id);
                 }
                 if (count($ids)) {
                     $this->_db->setQuery("Select Distinct `label`, reference_id From #__contentbuilder_elements Where form_id = " . intval($this->_id) . " And reference_id In (" . implode(',', $ids) . ") And published = 1 Order By ordering");
                     $rows = $this->_db->loadAssocList();
                     $ids = array();
                     foreach ($rows as $row) {
                         $ids[] = $row['reference_id'];
                     }
                 }
                 if ($this->_latest) {
                     $rec = $data->form->getListRecords($ids, '', array(), 0, 1, '', array(), 'desc', 0, false, JFactory::getUser()->get('id', 0), 0, -1, -1, -1, -1, array(), true, null);
                     if (count($rec) > 0) {
                         $rec = $rec[0];
                         $rec2 = $data->form->getRecord($rec->colRecord, false, -1, true);
                         $data->record_id = $rec->colRecord;
                         JRequest::setVar('record_id', $data->record_id);
                         $this->_record_id = $data->record_id;
                     } else {
                         JRequest::setVar('cbIsNew', 1);
                         contentbuilder::setPermissions(JRequest::getInt('id', 0), 0, $this->frontend ? '_fe' : '');
                         $auth = $this->frontend ? contentbuilder::authorizeFe('new') : contentbuilder::authorize('new');
                         if ($auth) {
                             JFactory::getApplication()->redirect(JRoute::_('index.php?option=com_contentbuilder&controller=edit&latest=1&backtolist=' . JRequest::getInt('backtolist', 0) . '&id=' . $this->_id . '&record_id=&limitstart=' . JRequest::getInt('limitstart', 0) . '&filter_order=' . JRequest::getVar('filter_order', ''), false));
                         } else {
                             JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_ADD_ENTRY_FIRST'));
                             JFactory::getApplication()->redirect('index.php', false);
                         }
                     }
                 }
                 $data->show_page_heading = $this->_show_page_heading;
                 if (!$data->form->exists) {
                     JError::raiseError(404, JText::_('COM_CONTENTBUILDER_FORM_NOT_FOUND'));
                 }
                 $data->page_title = '';
                 if (JRequest::getInt('cb_prefix_in_title', 1)) {
                     if (!$this->_menu_item) {
                         $data->page_title = $data->use_view_name_as_title ? $data->name : $data->form->getPageTitle();
                     } else {
                         $data->page_title = $data->use_view_name_as_title ? $data->name : JFactory::getDocument()->getTitle();
                     }
                 }
                 if ($this->frontend) {
                     $document = JFactory::getDocument();
                     $document->setTitle($data->page_title);
                 }
                 $data->show_back_button = $this->_show_back_button;
                 if (isset($rec2) && count($rec2)) {
                     $data->items = $rec2;
                 } else {
                     $data->items = $data->form->getRecord($this->_record_id, $data->published_only, $this->frontend ? $data->own_only_fe ? JFactory::getUser()->get('id', 0) : -1 : ($data->own_only ? JFactory::getUser()->get('id', 0) : -1), $this->frontend ? $data->show_all_languages_fe : true);
                 }
                 if (count($data->items)) {
                     $user = null;
                     if ($data->act_as_registration) {
                         $meta = $data->form->getRecordMetadata($this->_record_id);
                         $this->_db->setQuery("Select * From #__users Where id = " . $meta->created_id);
                         $user = $this->_db->loadObject();
                     }
                     $label = '';
                     foreach ($data->items as $rec) {
                         if ($rec->recElementId == $data->title_field) {
                             if ($data->act_as_registration && $user !== null) {
                                 if ($data->registration_name_field == $rec->recElementId) {
                                     $rec->recValue = $user->name;
                                 } else {
                                     if ($data->registration_username_field == $rec->recElementId) {
                                         $item->recValue = $user->username;
                                     } else {
                                         if ($data->registration_email_field == $item->recElementId) {
                                             $rec->recValue = $user->email;
                                         } else {
                                             if ($data->registration_email_repeat_field == $rec->recElementId) {
                                                 $rec->recValue = $user->email;
                                             }
                                         }
                                     }
                                 }
                             }
                             $label = cbinternal($rec->recValue);
                             break;
                         }
                     }
                     $ordered_extra_title = '';
                     foreach ($this->_menu_filter_order as $order_key => $order) {
                         if (isset($this->_menu_filter[$order_key])) {
                             // range test
                             $is_range = strstr(strtolower(implode(',', $this->_menu_filter[$order_key])), '@range') !== false;
                             $is_match = strstr(strtolower(implode(',', $this->_menu_filter[$order_key])), '@match') !== false;
                             if ($is_range) {
                                 $ex = explode('/', implode(', ', $this->_menu_filter[$order_key]));
                                 if (count($ex) == 3) {
                                     $ex2 = explode('to', trim($ex[2]));
                                     $out = '';
                                     $val = $ex2[0];
                                     $val2 = '';
                                     if (isset($ex2[1])) {
                                         $val2 = $ex2[1];
                                     }
                                     if (strtolower(trim($ex[1])) == 'date') {
                                         $val = JHTML::_('date', $ex2[0], JText::_('DATE_FORMAT_LC3'));
                                         if (isset($ex2[1])) {
                                             $val2 = JHTML::_('date', $ex2[1], JText::_('DATE_FORMAT_LC3'));
                                         }
                                     }
                                     if (count($ex2) == 2) {
                                         $out = (trim($ex2[0]) ? JText::_('COM_CONTENTBUILDER_FROM') . ' ' . trim($val) : '') . ' ' . JText::_('COM_CONTENTBUILDER_TO') . ' ' . trim($val2);
                                     } else {
                                         if (count($ex2) > 0) {
                                             $out = JText::_('COM_CONTENTBUILDER_FROM') . ' ' . trim($val);
                                         }
                                     }
                                     if ($out) {
                                         $this->_menu_filter[$order_key] = $ex;
                                         $ordered_extra_title .= ' &raquo; ' . htmlentities($data->labels[$order_key], ENT_QUOTES, 'UTF-8') . ': ' . htmlentities($out, ENT_QUOTES, 'UTF-8');
                                     }
                                 }
                             } else {
                                 if ($is_match) {
                                     $ex = explode('/', implode(', ', $this->_menu_filter[$order_key]));
                                     if (count($ex) == 2) {
                                         $ex2 = explode(';', trim($ex[1]));
                                         $out = '';
                                         $size = count($ex2);
                                         $i = 0;
                                         foreach ($ex2 as $val) {
                                             if ($i + 1 < $size) {
                                                 $out .= trim($val) . ' ' . JText::_('COM_CONTENTBUILDER_AND') . ' ';
                                             } else {
                                                 $out .= trim($val);
                                             }
                                             $i++;
                                         }
                                         if ($out) {
                                             $this->_menu_filter[$order_key] = $ex;
                                             $ordered_extra_title .= ' &raquo; ' . htmlentities($data->labels[$order_key], ENT_QUOTES, 'UTF-8') . ': ' . htmlentities($out, ENT_QUOTES, 'UTF-8');
                                         }
                                     }
                                 } else {
                                     $ordered_extra_title .= ' &raquo; ' . htmlentities($data->labels[$order_key], ENT_QUOTES, 'UTF-8') . ': ' . htmlentities(implode(', ', $this->_menu_filter[$order_key]), ENT_QUOTES, 'UTF-8');
                                 }
                             }
                         }
                     }
                     $data->page_title .= $ordered_extra_title;
                     // trying first element if no title field given
                     if (!$label) {
                         $label = cbinternal($data->items[0]->recValue);
                     }
                     // "buddy quaid hack", should be an option in future versions
                     jimport('joomla.version');
                     $version = new JVersion();
                     if (version_compare($version->getShortVersion(), '1.6', '>=')) {
                         if ($this->_show_page_heading && $this->_page_title != '' && $this->_page_heading != '' && $this->_page_title == $this->_page_heading) {
                             $data->page_title = $this->_page_title;
                         } else {
                             $data->page_title .= $label ? (!$data->page_title ? '' : (!$ordered_extra_title ? ': ' : ' &raquo; ')) . $label : '';
                         }
                         if ($this->frontend) {
                             $document = JFactory::getDocument();
                             $document->setTitle(html_entity_decode($data->page_title, ENT_QUOTES, 'UTF-8'));
                         }
                     } else {
                         if ($this->_show_page_heading && $this->_page_title != '' && !JRequest::getInt('cb_prefix_in_title', 1)) {
                             $data->page_title = $this->_page_title;
                         } else {
                             $data->page_title .= $label ? (!$data->page_title ? '' : (!$ordered_extra_title ? ': ' : ' &raquo; ')) . $label : '';
                         }
                         if ($this->frontend) {
                             $document = JFactory::getDocument();
                             $document->setTitle(html_entity_decode($data->page_title, ENT_QUOTES, 'UTF-8'));
                         }
                     }
                     $data->template = contentbuilder::getTemplate($this->_id, $this->_record_id, $data->items, $ids);
                     $metadata = $data->form->getRecordMetadata($this->_record_id);
                     if ($metadata instanceof stdClass && $data->metadata) {
                         $data->created = $metadata->created ? $metadata->created : '';
                         $data->created_by = $metadata->created_by ? $metadata->created_by : '';
                         $data->modified = $metadata->modified ? $metadata->modified : '';
                         $data->modified_by = $metadata->modified_by ? $metadata->modified_by : '';
                         $data->metadesc = $metadata->metadesc;
                         $data->metakey = $metadata->metakey;
                         $data->author = $metadata->author;
                         $data->rights = $metadata->rights;
                         $data->robots = $metadata->robots;
                         $data->xreference = $metadata->xreference;
                     } else {
                         $data->created = '';
                         $data->created_by = '';
                         $data->modified = '';
                         $data->modified_by = '';
                         $data->metadesc = '';
                         $data->metakey = '';
                         $data->author = '';
                         $data->rights = '';
                         $data->robots = '';
                         $data->xreference = '';
                     }
                 } else {
                     JError::raiseError(404, JText::_('COM_CONTENTBUILDER_RECORD_NOT_FOUND'));
                 }
             }
             return $data;
         }
     }
     return null;
 }
 function onAfterInitialize()
 {
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.folder');
     if (!JFile::exists(JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'classes' . DS . 'contentbuilder.php')) {
         return;
     }
     $app = JFactory::getApplication();
     if (!$app->isSite()) {
         return;
     }
     // synch the records if there are any changes
     if ($app->isSite()) {
         $db = JFactory::getDBO();
         $user = JFactory::getUser();
         $db->setQuery("\n                    Update\n                        #__contentbuilder_articles As articles,\n                        #__content As content, \n                        #__contentbuilder_forms As forms,\n                        #__contentbuilder_registered_users As cbusers,\n                        #__users As users\n                    Set \n                        content.state = 0\n                    Where \n                        articles.article_id = content.id\n                    And\n                        content.state = 1\n                    And\n                        articles.form_id = forms.id\n                    And\n                        forms.act_as_registration = 1\n                    And\n                        forms.id = cbusers.form_id\n                    And\n                        content.created_by = cbusers.user_id\n                    And\n                      (\n                        (\n                            users.id = cbusers.user_id\n                          And\n                            users.block = 1\n                        )\n                      )\n                    ");
         $db->query();
         $db->setQuery("\n                    Update \n                        #__contentbuilder_articles As articles,\n                        #__content As content, \n                        #__contentbuilder_forms As forms,\n                        #__contentbuilder_records As records,\n                        #__contentbuilder_registered_users As cbusers,\n                        #__users As users\n                    Set \n                        content.state = forms.auto_publish\n                    Where \n                        articles.article_id = content.id\n                    And\n                        content.state = 0\n                    And\n                        articles.form_id = forms.id\n                    And\n                        forms.act_as_registration = 1\n                    And\n                        forms.id = cbusers.form_id\n                    And\n                        content.created_by = cbusers.user_id\n                    And\n                        users.id = cbusers.user_id\n                    And\n                        records.record_id = cbusers.record_id\n                    And\n                        records.`type` = forms.`type`\n                    And\n                        users.block = 0\n                    ");
         $db->query();
         $pluginParams = CBCompat::getPluginParams($this, 'system', 'contentbuilder_system');
         require_once JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'classes' . DS . 'contentbuilder.php';
         $db->setQuery("\n                Select \n                    form.id As form_id,\n                    form.act_as_registration,\n                    form.default_category,\n                    form.registration_name_field, \n                    form.registration_username_field, \n                    form.registration_email_field, \n                    form.registration_email_repeat_field, \n                    form.`last_update`,\n                    article.`article_id`,\n                    form.`title_field`,\n                    form.`create_articles`,\n                    form.`name`,\n                    form.`use_view_name_as_title`,\n                    form.`protect_upload_directory`,\n                    form.`reference_id`,\n                    records.`record_id`,\n                    form.`type`,\n                    form.`published_only`,\n                    form.`own_only`,\n                    form.`own_only_fe`,\n                    records.`last_update` As record_last_update,\n                    article.`last_update` As article_last_update\n                From\n                    #__contentbuilder_records As records\n                    Left Join #__contentbuilder_forms As form On ( form.`type` = records.`type` And form.reference_id = records.reference_id )\n                    Left Join #__contentbuilder_articles As article On ( form.`type` = records.`type` And form.reference_id = records.reference_id And article.form_id = form.id And article.record_id = records.record_id )\n                    Left Join #__content As content On ( form.`type` = records.`type` And form.reference_id = records.reference_id And article.article_id = content.id And article.form_id = form.id And article.record_id = records.record_id )\n                Where \n                    form.`published` = 1\n                And\n                    form.create_articles = 1\n                And\n                    form.`type` = records.`type`\n                And \n                    form.reference_id = records.reference_id\n                And\n                   (\n                     (\n                        article.form_id = form.id \n                      And \n                        article.record_id = records.record_id\n                      And \n                        article.article_id = content.id \n                      And \n                        ( content.state = 1 Or content.state = 0 )\n                      And\n                      (\n                        form.`last_update` > article.`last_update`   \n                       Or\n                        records.`last_update` > article.`last_update`\n                      )\n                     )\n                     Or\n                     (\n                        form.id Is Not Null And records.id Is Not Null And content.id Is Null And article.id Is Null\n                     )\n                   )\n                Limit " . intval($pluginParams->def('limit_per_turn', 50)));
         $list = $db->loadAssocList();
         if (isset($list[0])) {
             $lang = JFactory::getLanguage();
             $lang->load('com_contentbuilder', JPATH_ADMINISTRATOR);
         }
         $jdate = JFactory::getDate();
         $now = CBCompat::toSql($jdate);
         foreach ($list as $data) {
             if (is_array($data)) {
                 $form = contentbuilder::getForm($data['type'], $data['reference_id']);
                 if (!$form || !$form->exists) {
                     return;
                 }
                 // creating the article
                 if ($data['create_articles']) {
                     $data['labels'] = $form->getElementLabels();
                     $ids = array();
                     foreach ($data['labels'] as $reference_id => $label) {
                         $ids[] = $db->Quote($reference_id);
                     }
                     if (count($ids)) {
                         $db->setQuery("Select Distinct `label`, reference_id From #__contentbuilder_elements Where form_id = " . intval($data['form_id']) . " And reference_id In (" . implode(',', $ids) . ") And published = 1 Order By ordering");
                         $rows = $db->loadAssocList();
                         $ids = array();
                         foreach ($rows as $row) {
                             $ids[] = $row['reference_id'];
                         }
                     }
                     $data['items'] = $form->getRecord($data['record_id'], false, -1, true);
                     $article_id = contentbuilder::createArticle($data['form_id'], $data['record_id'], $data['items'], $ids, $data['title_field'], $form->getRecordMetadata($data['record_id']), array(), false, 1, $data['default_category']);
                     if ($article_id) {
                         $db->setQuery("Update #__contentbuilder_articles Set `last_update`=" . $db->Quote($now) . " Where article_id = " . $db->Quote($article_id) . " And record_id = " . $db->Quote($data['record_id']) . " And form_id = " . $db->Quote($data['form_id']));
                         $db->query();
                     }
                 }
             }
         }
     }
 }
예제 #5
0
 if ($chunkIdx == $chunksLength - 1) {
     $contents = '';
     for ($i = 0; $i < $chunksLength; $i++) {
         $contents .= @JFile::read(JPATH_SITE . '/media/breezingforms/ajax_cache/ajaxsave_' . $i . '_' . $rndAdd . '.txt');
         @JFile::delete(JPATH_SITE . '/media/breezingforms/ajax_cache/ajaxsave_' . $i . '_' . $rndAdd . '.txt');
     }
     $formId = 0;
     @ob_end_clean();
     $formId = $quickMode->save($form, Zend_Json::decode(base64_decode($contents)));
     ob_start();
     // CONTENTBUILDER
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.folder');
     if (JFile::exists(JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'classes' . DS . 'contentbuilder.php')) {
         require_once JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'classes' . DS . 'contentbuilder.php';
         $cbForm = contentbuilder::getForm('com_breezingforms', $formId);
         $db = JFactory::getDBO();
         $db->setQuery("Select id From #__contentbuilder_forms Where `type` = 'com_breezingforms' And `reference_id` = " . intval($formId));
         jimport('joomla.version');
         $version = new JVersion();
         if (version_compare($version->getShortVersion(), '3.0', '>=')) {
             $cbForms = $db->loadColumn();
         } else {
             $cbForms = $db->loadResultArray();
         }
         if (is_object($cbForm) && count($cbForms)) {
             require_once JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'tables' . DS . 'elements.php';
             foreach ($cbForms as $dataId) {
                 contentbuilder::synchElements($dataId, $cbForm);
                 $elements_table = new TableElements($db);
                 $elements_table->reorder('form_id=' . $dataId);
예제 #6
0
 static function save($option, $pkg, $form, $page)
 {
     global $database;
     $database = JFactory::getDBO();
     $row = new facileFormsElements($database);
     // bind it to the table
     if (!$row->bind($_POST)) {
         echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n";
         exit;
     }
     // if
     if ($row->script1flag1 == null) {
         $row->script1flag1 = 0;
     }
     if ($row->script1flag2 == null) {
         $row->script1flag2 = 0;
     }
     if ($row->script2flag1 == null) {
         $row->script2flag1 = 0;
     }
     if ($row->script2flag2 == null) {
         $row->script2flag2 = 0;
     }
     if ($row->script2flag3 == null) {
         $row->script2flag3 = 0;
     }
     if ($row->script2flag4 == null) {
         $row->script2flag4 = 0;
     }
     if ($row->script2flag5 == null) {
         $row->script2flag5 = 0;
     }
     // store it in the db
     if (!$row->store()) {
         echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n";
         exit;
     }
     // if
     $row->reorder("form={$form} and page={$page}");
     // CONTENTBUILDER
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.folder');
     if (JFile::exists(JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'classes' . DS . 'contentbuilder.php')) {
         $formId = $form;
         require_once JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'classes' . DS . 'contentbuilder.php';
         $cbForm = contentbuilder::getForm('com_breezingforms', $formId);
         $db = JFactory::getDBO();
         $db->setQuery("Select id From #__contentbuilder_forms Where `type` = 'com_breezingforms' And `reference_id` = " . intval($formId));
         jimport('joomla.version');
         $version = new JVersion();
         if (version_compare($version->getShortVersion(), '3.0', '>=')) {
             $cbForms = $db->loadColumn();
         } else {
             $cbForms = $db->loadResultArray();
         }
         if (is_object($cbForm) && count($cbForms)) {
             require_once JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'tables' . DS . 'elements.php';
             foreach ($cbForms as $dataId) {
                 contentbuilder::synchElements($dataId, $cbForm);
                 $elements_table = new TableElements($db);
                 $elements_table->reorder('form_id=' . $dataId);
             }
         }
     }
     // CONTENTBUILDER END
     JFactory::getApplication()->redirect("index.php?option={$option}&act=editpage&form={$form}&page={$page}&pkg={$pkg}", BFText::_('COM_BREEZINGFORMS_ELEMENTS_SAVED'));
 }
예제 #7
0
 function getGroupDefinition()
 {
     $this->_db->setQuery("Select `type`, `reference_id` From #__contentbuilder_forms Where id = " . intval($this->_id));
     $form = $this->_db->loadAssoc();
     $form = contentbuilder::getForm($form['type'], $form['reference_id']);
     if ($form->isGroup($this->_data->reference_id)) {
         return $form->getGroupDefinition($this->_data->reference_id);
     }
     return array();
 }
예제 #8
0
 function getForm()
 {
     $query = ' Select * From #__contentbuilder_forms ' . '  Where id = ' . $this->_id;
     $this->_db->setQuery($query);
     $data = $this->_db->loadObject();
     if (!$data) {
         $data = new stdClass();
         $data->id = 0;
         $data->type = null;
         $data->reference_id = null;
         $data->name = null;
         $data->tag = null;
         $data->details_template = null;
         $data->details_prepare = null;
         $data->intro_text = null;
         $data->title = null;
         $data->created = null;
         $data->modified = null;
         $data->metadata = true;
         $data->export_xls = null;
         $data->print_button = true;
         $data->created_by = null;
         $data->modified_by = null;
         $data->published = null;
         $data->display_in = null;
         $data->published_only = null;
         $data->show_id_column = true;
         $data->select_column = false;
         $data->edit_button = false;
         $data->list_states = false;
         $data->config = null;
         $data->editable_prepare = null;
         $data->editable_template = null;
         $data->use_view_name_as_title = false;
         $data->list_states = $this->_default_list_states;
         $data->own_only = false;
         $data->own_only_fe = false;
         $data->list_state = false;
         $data->list_publish = false;
         $data->initial_sort_order = -1;
         $data->initial_sort_order2 = -1;
         $data->initial_sort_order3 = -1;
         $data->initial_order_dir = 'desc';
         $data->default_section = 0;
         $data->default_category = 0;
         $data->create_articles = 1;
         $data->title_field = 0;
         $data->delete_articles = 1;
         $data->edit_by_type = 0;
         $data->email_notifications = 1;
         $data->email_update_notifications = 0;
         $data->limited_article_options = 1;
         $data->limited_article_options_fe = 1;
         $data->upload_directory = JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'upload';
         $data->protect_upload_directory = 1;
         $data->limit_add = 0;
         $data->limit_edit = 0;
         $data->verification_required_view = 0;
         $data->verification_days_view = 0;
         $data->verification_required_new = 0;
         $data->verification_days_new = 0;
         $data->verification_required_edit = 0;
         $data->verification_days_edit = 0;
         $data->verification_url_new = '';
         $data->verification_url_view = '';
         $data->verification_url_edit = '';
         $data->default_lang_code = '*';
         $data->default_lang_code_ignore = 0;
         $data->show_all_languages_fe = 1;
         $data->list_language = 0;
         $data->default_publish_up_days = 0;
         $data->default_publish_down_days = 0;
         $data->default_access = 0;
         $data->default_featured = 0;
         $data->list_article = 0;
         $data->list_author = 0;
         $data->list_rating = 0;
         $data->email_template = '';
         $data->email_subject = '';
         $data->email_alternative_from = '';
         $data->email_alternative_fromname = '';
         $data->email_recipients = '';
         $data->email_recipients_attach_uploads = '';
         $data->email_html = '';
         $data->email_admin_template = '';
         $data->email_admin_subject = '';
         $data->email_admin_alternative_from = '';
         $data->email_admin_alternative_fromname = '';
         $data->email_admin_recipients = '';
         $data->email_admin_recipients_attach_uploads = '';
         $data->email_admin_html = '';
         $data->act_as_registration = 0;
         $data->registration_username_field = '';
         $data->registration_password_field = '';
         $data->registration_password_repeat_field = '';
         $data->registration_email_field = '';
         $data->registration_email_repeat_field = '';
         $data->registration_name_field = '';
         $data->auto_publish = 0;
         $data->force_login = 0;
         $data->force_url = '';
         $data->registration_bypass_plugin = '';
         $data->registration_bypass_plugin_params = '';
         $data->registration_bypass_verification_name = '';
         $data->registration_bypass_verify_view = '';
         $data->theme_plugin = '';
         $data->rating_slots = 5;
         $data->rand_date_update = '0000-00-00 00:00:00';
         $data->rand_update = '86400';
         $data->article_record_impact_publish = 0;
         $data->article_record_impact_language = 0;
         $data->allow_external_filter = 0;
         $data->show_filter = 1;
         $data->show_records_per_page = 1;
         $data->initial_list_limit = 20;
         $data->save_button_title = '';
         $data->apply_button_title = '';
         $data->filter_exact_match = 0;
         $data->ordering = 0;
     }
     $data->forms = array();
     $data->types = contentbuilder::getTypes();
     if ($data->type) {
         $data->forms = contentbuilder::getForms($data->type);
     }
     $data->form = null;
     if ($data->type && $data->reference_id) {
         $data->form = contentbuilder::getForm($data->type, $data->reference_id);
         if (!$data->form->exists) {
             JFactory::getApplication()->redirect('index.php?option=com_contentbuilder&controller=forms&limitstart=' . $this->getState('limitstart', 0), JText::_('COM_CONTENTBUILDER_FORM_NOT_FOUND'), 'error');
         }
         if (isset($data->form->properties) && isset($data->form->properties->name)) {
             $data->type_name = $data->form->properties->name;
         } else {
             $data->type_name = '';
         }
         $data->title = $data->form->getPageTitle();
         if (is_object($data->form)) {
             contentbuilder::synchElements($data->id, $data->form);
             $elements_table = $this->getTable('elements');
             $elements_table->reorder('form_id=' . $data->id);
         }
     }
     $db = JFactory::getDBO();
     $db->setQuery("Select * From #__contentbuilder_list_states Where form_id = " . $this->_id . " Order By id");
     $list_states = $db->loadAssocList();
     if (count($list_states)) {
         $data->list_states = $list_states;
     } else {
         $data->list_states = $this->_default_list_states;
     }
     $data->language_codes = contentbuilder::getLanguageCodes();
     $version = new JVersion();
     if (version_compare($version->getShortVersion(), '1.6', '>=')) {
         $data->sectioncategories = $this->getOptions();
         $data->accesslevels = array();
     } else {
         $db->setQuery("Select * From #__groups");
         $data->accesslevels = $db->loadAssocList();
         // Joomla 1.5 begin
         // get sections and categories
         $db->setQuery("Select `title`, `id` From #__sections Where published = 1 Order By ordering");
         $sections = $db->loadAssocList();
         $i = 0;
         foreach ($sections as $section) {
             if (!isset($sections['categories'])) {
                 $sections[$i]['categories'] = array();
             }
             $db->setQuery("Select `title`, `id` From #__categories Where section = {$section['id']} And published = 1 Order By ordering");
             $cats = $db->loadAssocList();
             foreach ($cats as $cat) {
                 if ($cat) {
                     $sections[$i]['categories'][] = $cat;
                 }
             }
             if (!count($cats)) {
                 unset($sections[$i]);
             }
             $i++;
         }
         $sections = array_merge(array(), $sections);
         $data->sectioncategories = $sections;
         // Joomla 1.5 end
     }
     $this->_form_data = $data;
     return $data;
 }
 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;">&nbsp;</div>';
                                                             }
                                                             $align_ = '';
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                         $time_passed = $this->measureTime();
                                         if ($time_passed - $start_time > $max_time) {
                                             break;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 if (trim($out) == '' && JFile::exists(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins' . DS . 'image_scale' . DS . basename($default_image))) {
                     $out = '<img width="' . $default_image_width . '" height="' . $default_image_height . '" alt="" src="' . JURI::root(true) . '/media/contentbuilder/plugins/image_scale/' . basename($default_image) . '"/>';
                 }
                 if ($is_series && $align && (strtolower($align) == 'left' || strtolower($align) == 'right')) {
                     $out .= '<div style="clear:' . strtolower($align) . ';"></div>';
                 }
                 $article->text = str_replace($matches[0][$i], $out, $article->text);
                 $i++;
             }
         }
     }
     return true;
 }
예제 #11
0
 function delete()
 {
     $items = JRequest::getVar('cid', array(), 'request', 'array');
     if (empty($this->_data)) {
         $query = $this->_buildQuery();
         $this->_data = $this->_getList($query, 0, 1);
         if (!count($this->_data)) {
             JError::raiseError(404, JText::_('COM_CONTENTBUILDER_FORM_NOT_FOUND'));
         }
         foreach ($this->_data as $data) {
             if (!$this->frontend && $data->display_in == 0) {
                 JError::raiseError(404, JText::_('COM_CONTENTBUILDER_RECORD_NOT_FOUND'));
             } else {
                 if ($this->frontend && $data->display_in == 1) {
                     JError::raiseError(404, JText::_('COM_CONTENTBUILDER_RECORD_NOT_FOUND'));
                 }
             }
             $data->form_id = $this->_id;
             if ($data->type && $data->reference_id) {
                 $data->form = contentbuilder::getForm($data->type, $data->reference_id);
                 $res = $data->form->delete($items, $data->form_id);
                 $cnt = count($items);
                 $new_items = array();
                 if ($res && $cnt) {
                     for ($i = 0; $i < $cnt; $i++) {
                         $new_items[] = $this->_db->Quote($items[$i]);
                     }
                     $new_items = implode(',', $new_items);
                     $this->_db->setQuery("Delete From #__contentbuilder_list_records Where form_id = " . intval($this->_id) . " And record_id In ({$new_items})");
                     $this->_db->query();
                     $this->_db->setQuery("Delete From #__contentbuilder_records Where `type` = " . $this->_db->Quote($data->type) . " And  `reference_id` = " . $this->_db->Quote($data->form->getReferenceId()) . " And record_id In ({$new_items})");
                     $this->_db->query();
                     if ($data->delete_articles) {
                         $this->_db->setQuery("Select article_id From #__contentbuilder_articles Where `type` = " . $this->_db->Quote($data->type) . " And reference_id = " . $this->_db->Quote($data->form->getReferenceId()) . " And record_id In ({$new_items})");
                         jimport('joomla.version');
                         $version = new JVersion();
                         if (version_compare($version->getShortVersion(), '3.0', '>=')) {
                             $articles = $this->_db->loadColumn();
                         } else {
                             $articles = $this->_db->loadResultArray();
                         }
                         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 (!$this->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 (!$this->is15) {
                                     $dispatcher->trigger('onContentAfterDelete', array('com_content.article', $table));
                                 }
                             }
                             if (!$this->is15) {
                                 $this->_db->setQuery("Delete From #__assets Where `name` In (" . implode(',', $article_items) . ")");
                                 $this->_db->query();
                             }
                         }
                     }
                     $this->_db->setQuery("Delete From #__contentbuilder_articles Where `type` = " . $this->_db->Quote($data->type) . " And reference_id = " . $this->_db->Quote($data->form->getReferenceId()) . " And record_id In ({$new_items})");
                     $this->_db->query();
                 }
             }
         }
     }
     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();
     }
 }
예제 #12
0
 /**
  * Gets the currencies
  * @return array List of products
  */
 function getData()
 {
     $mainframe = JFactory::getApplication();
     $option = 'com_contentbuilder';
     // Lets load the data if it doesn't already exist
     if (empty($this->_data)) {
         $query = $this->_buildQuery();
         $this->_data = $this->_getList($query, 0, 1);
         if (!count($this->_data)) {
             JError::raiseError(404, JText::_('COM_CONTENTBUILDER_FORM_NOT_FOUND'));
         }
         foreach ($this->_data as $data) {
             if (!$this->frontend && $data->display_in == 0) {
                 JError::raiseError(404, JText::_('COM_CONTENTBUILDER_FORM_NOT_FOUND'));
             } else {
                 if ($this->frontend && $data->display_in == 1) {
                     JError::raiseError(404, JText::_('COM_CONTENTBUILDER_FORM_NOT_FOUND'));
                 }
             }
             // filter by category if requested by menu item
             if (JRequest::getVar('cb_category_menu_filter', null) !== null && JRequest::getVar('cb_category_menu_filter', 0) == 1 && JRequest::getVar('cb_category_id', null) !== null) {
                 if (JRequest::getInt('cb_category_id', -1) > -2) {
                     $this->setState('article_category_filter', JRequest::getInt('cb_category_id', -1));
                 } else {
                     $this->setState('article_category_filter', $data->default_category);
                 }
             }
             $data->show_page_heading = $this->_show_page_heading;
             $data->page_class = $this->_page_class;
             $data->form_id = $this->_id;
             if ($data->type && $data->reference_id) {
                 $data->form = contentbuilder::getForm($data->type, $data->reference_id);
                 if (!$data->form->exists) {
                     JError::raiseError(404, JText::_('COM_CONTENTBUILDER_FORM_NOT_FOUND'));
                 }
                 $data->page_title = '';
                 if (JRequest::getInt('cb_prefix_in_title', 1)) {
                     if (!$this->_menu_item) {
                         $data->page_title = $data->use_view_name_as_title ? $data->name : $data->form->getPageTitle();
                     } else {
                         $data->page_title = $data->use_view_name_as_title ? $data->name : JFactory::getDocument()->getTitle();
                     }
                 }
                 // enables the record randomizer
                 $now = JFactory::getDate();
                 $data->rand_update = intval($data->rand_update);
                 if ($data->rand_update < 1) {
                     $data->rand_update = 86400;
                 }
                 jimport('joomla.version');
                 $version = new JVersion();
                 if (version_compare($version->getShortVersion(), '3.0', '>=')) {
                     $___now = $now->toSql();
                 } else {
                     $___now = $now->toMySQL();
                 }
                 if ($data->initial_sort_order == 'Rand' && ($data->rand_date_update == '0000-00-00 00:00:00' || $now->toUnix() - strtotime($data->rand_date_update) >= $data->rand_update)) {
                     $this->_db->setQuery("UPDATE #__contentbuilder_records SET rand_date = '" . $___now . "' + interval rand()*10000 day Where `type` = " . $this->_db->Quote($data->type) . " And reference_id = " . $this->_db->Quote($data->reference_id));
                     $this->_db->query();
                     $this->_db->setQuery("Update #__contentbuilder_forms Set rand_date_update = '" . $___now . "'");
                     $this->_db->query();
                 }
                 $data->labels = $data->form->getElementLabels();
                 if (JRequest::getBool('filter_reset', false)) {
                     JFactory::getSession()->clear('com_contentbuilder.filter_signal.' . $this->_id);
                     JFactory::getSession()->clear('com_contentbuilder.filter.' . $this->_id);
                     JFactory::getSession()->clear('com_contentbuilder.calendar_filter_from.' . $this->_id);
                     JFactory::getSession()->clear('com_contentbuilder.calendar_filter_to.' . $this->_id);
                     JFactory::getSession()->clear('com_contentbuilder.calendar_formats.' . $this->_id);
                     JFactory::getSession()->clear('com_contentbuilder.filter_keywords.' . $this->_id);
                     JFactory::getSession()->clear('com_contentbuilder.filter_article_categories.' . $this->_id);
                 } else {
                     if ((JFactory::getSession()->get('com_contentbuilder.filter_signal.' . $this->_id, false) || JRequest::getBool('contentbuilder_filter_signal', false)) && $data->allow_external_filter) {
                         $orders = array();
                         $filters = array();
                         $filters_from = array();
                         $filters_to = array();
                         $calendar_formats = array();
                         // renew on request
                         if (JRequest::getBool('contentbuilder_filter_signal', false)) {
                             if (JRequest::getVar('cbListFilterKeywords', '')) {
                                 $this->setState('formsd_filter', JRequest::getVar('cbListFilterKeywords', ''));
                             }
                             if (JRequest::getVar('cbListFilterArticleCategories', -1) > -1) {
                                 $this->setState('article_category_filter', JRequest::getInt('cbListFilterArticleCategories', -1));
                             }
                             $filters = JRequest::getVar('cb_filter', array(), 'POST', 'array');
                             $filters_from = JRequest::getVar('cbListFilterCalendarFrom', array(), 'POST', 'array');
                             $filters_to = JRequest::getVar('cbListFilterCalendarTo', array(), 'POST', 'array');
                             $calendar_formats = JRequest::getVar('cb_filter_calendar_format', array(), 'POST', 'array');
                             JFactory::getSession()->set('com_contentbuilder.filter_signal.' . $this->_id, true);
                             JFactory::getSession()->set('com_contentbuilder.filter.' . $this->_id, $filters);
                             JFactory::getSession()->set('com_contentbuilder.filter_keywords.' . $this->_id, JRequest::getVar('cbListFilterKeywords', ''));
                             JFactory::getSession()->set('com_contentbuilder.filter_article_categories.' . $this->_id, JRequest::getInt('cbListFilterArticleCategories', -1));
                             JFactory::getSession()->set('com_contentbuilder.calendar_filter_from.' . $this->_id, $filters_from);
                             JFactory::getSession()->set('com_contentbuilder.calendar_filter_to.' . $this->_id, $filters_to);
                             JFactory::getSession()->set('com_contentbuilder.calendar_formats.' . $this->_id, $calendar_formats);
                             // else pick from session
                         } else {
                             if (JFactory::getSession()->get('com_contentbuilder.filter_signal.' . $this->_id, false)) {
                                 $filters = JFactory::getSession()->get('com_contentbuilder.filter.' . $this->_id, array());
                                 $filters_from = JFactory::getSession()->get('com_contentbuilder.calendar_filter_from.' . $this->_id, array());
                                 $filters_to = JFactory::getSession()->get('com_contentbuilder.calendar_filter_to.' . $this->_id, array());
                                 $calendar_formats = JFactory::getSession()->get('com_contentbuilder.calendar_formats.' . $this->_id, array());
                                 $filter_keywords = JFactory::getSession()->get('com_contentbuilder.filter_keywords.' . $this->_id, '');
                                 $filter_cats = JFactory::getSession()->get('com_contentbuilder.filter_article_categories.' . $this->_id, -1);
                                 if ($filter_keywords != '') {
                                     $this->setState('formsd_filter', $filter_keywords);
                                 }
                                 if ($filter_cats != -1) {
                                     $this->setState('article_category_filter', $filter_cats);
                                 }
                             }
                         }
                         foreach ($calendar_formats as $col => $calendar_format) {
                             if (isset($filters[$col])) {
                                 $filter_exploded = explode('/', $filters[$col]);
                                 if (isset($filter_exploded[2])) {
                                     $to_exploded = explode('to', $filter_exploded[2]);
                                     switch (count($to_exploded)) {
                                         case 2:
                                             if ($to_exploded[0] != '') {
                                                 $filters[$col] = '@range/date/' . contentbuilder_convert_date(trim($to_exploded[0]), $calendar_format) . ' to ' . contentbuilder_convert_date(trim($to_exploded[1]), $calendar_format);
                                             } else {
                                                 $filters[$col] = '@range/date/to ' . contentbuilder_convert_date(trim($to_exploded[1]), $calendar_format);
                                             }
                                             break;
                                         case 1:
                                             $filters[$col] = '@range/date/' . contentbuilder_convert_date(trim($to_exploded[0]), $calendar_format);
                                             break;
                                     }
                                     if (isset($to_exploded[0]) && isset($to_exploded[1]) && trim($to_exploded[0]) == '' && trim($to_exploded[1]) == '') {
                                         $filters[$col] = '';
                                     }
                                     if (isset($to_exploded[0]) && !isset($to_exploded[1]) && trim($to_exploded[0]) == '') {
                                         $filters[$col] = '';
                                     }
                                 }
                             }
                         }
                         $new_filters = array();
                         $i = 1;
                         foreach ($filters as $filter_key => $filter) {
                             if ($filter != '') {
                                 $orders[$filter_key] = $i;
                                 $new_filters[$filter_key] = explode('|', $filter);
                             }
                             $i++;
                         }
                         $this->_menu_filter = $new_filters;
                         $this->_menu_filter_order = $orders;
                     }
                 }
                 $ordered_extra_title = '';
                 foreach ($this->_menu_filter_order as $order_key => $order) {
                     if (isset($this->_menu_filter[$order_key])) {
                         // range test
                         $is_range = strstr(strtolower(implode(',', $this->_menu_filter[$order_key])), '@range') !== false;
                         $is_match = strstr(strtolower(implode(',', $this->_menu_filter[$order_key])), '@match') !== false;
                         if ($is_range) {
                             $ex = explode('/', implode(', ', $this->_menu_filter[$order_key]));
                             if (count($ex) == 3) {
                                 $ex2 = explode('to', trim($ex[2]));
                                 $out = '';
                                 $val = $ex2[0];
                                 $val2 = '';
                                 if (isset($ex2[1])) {
                                     $val2 = $ex2[1];
                                 }
                                 if (strtolower(trim($ex[1])) == 'date') {
                                     $val = JHTML::_('date', $ex2[0], JText::_('DATE_FORMAT_LC3'));
                                     if (isset($ex2[1])) {
                                         $val2 = JHTML::_('date', $ex2[1], JText::_('DATE_FORMAT_LC3'));
                                     }
                                 }
                                 if (count($ex2) == 2) {
                                     $out = (trim($ex2[0]) ? JText::_('COM_CONTENTBUILDER_FROM') . ' ' . trim($val) : '') . ' ' . JText::_('COM_CONTENTBUILDER_TO') . ' ' . trim($val2);
                                 } else {
                                     if (count($ex2) > 0) {
                                         $out = JText::_('COM_CONTENTBUILDER_FROM2') . ' ' . trim($val);
                                     }
                                 }
                                 if ($out) {
                                     $this->_menu_filter[$order_key] = $ex;
                                     $ordered_extra_title .= ' &raquo; ' . htmlentities($data->labels[$order_key], ENT_QUOTES, 'UTF-8') . ': ' . htmlentities($out, ENT_QUOTES, 'UTF-8');
                                 }
                             }
                         } else {
                             if ($is_match) {
                                 $ex = explode('/', implode(', ', $this->_menu_filter[$order_key]));
                                 if (count($ex) == 2) {
                                     $ex2 = explode(';', trim($ex[1]));
                                     $out = '';
                                     $size = count($ex2);
                                     $i = 0;
                                     foreach ($ex2 as $val) {
                                         if ($i + 1 < $size) {
                                             $out .= trim($val) . ' ' . JText::_('COM_CONTENTBUILDER_AND') . ' ';
                                         } else {
                                             $out .= trim($val);
                                         }
                                         $i++;
                                     }
                                     if ($out) {
                                         $this->_menu_filter[$order_key] = $ex;
                                         $ordered_extra_title .= ' &raquo; ' . htmlentities($data->labels[$order_key], ENT_QUOTES, 'UTF-8') . ': ' . htmlentities($out, ENT_QUOTES, 'UTF-8');
                                     }
                                 }
                             } else {
                                 $ordered_extra_title .= ' &raquo; ' . htmlentities($data->labels[$order_key], ENT_QUOTES, 'UTF-8') . ': ' . htmlentities(implode(', ', $this->_menu_filter[$order_key]), ENT_QUOTES, 'UTF-8');
                             }
                         }
                     }
                 }
                 $data->slug = $data->page_title;
                 $data->slug2 = '';
                 // "buddy quaid hack", should be an option in future versions
                 jimport('joomla.version');
                 $version = new JVersion();
                 if (version_compare($version->getShortVersion(), '1.6', '>=')) {
                     if ($this->_show_page_heading && $this->_page_title != '' && $this->_page_heading != '' && $this->_page_title == $this->_page_heading) {
                         $data->page_title = $this->_page_title;
                     } else {
                         if (JRequest::getInt('cb_filter_in_title', 1)) {
                             $data->slug2 = str_replace(' &raquo; ', '', $ordered_extra_title);
                             $data->page_title .= $ordered_extra_title;
                         }
                     }
                 } else {
                     if ($this->_show_page_heading && $this->_page_title != '' && !JRequest::getInt('cb_prefix_in_title', 1)) {
                         $data->page_title = $this->_page_title;
                     } else {
                         if (JRequest::getInt('cb_filter_in_title', 1)) {
                             $data->slug2 = str_replace(' &raquo; ', '', $ordered_extra_title);
                             $data->page_title .= $ordered_extra_title;
                         }
                     }
                 }
                 if ($this->frontend) {
                     $document = JFactory::getDocument();
                     $document->setTitle(html_entity_decode($data->page_title, ENT_QUOTES, 'UTF-8'));
                 }
                 $ids = array();
                 foreach ($data->labels as $reference_id => $label) {
                     $ids[] = $this->_db->Quote($reference_id);
                 }
                 $searchable_elements = contentbuilder::getListSearchableElements($this->_id);
                 $data->display_filter = count($searchable_elements) && $data->show_filter;
                 $data->linkable_elements = contentbuilder::getListLinkableElements($this->_id);
                 $data->labels = array();
                 $order_types = array();
                 if (count($ids)) {
                     $this->_db->setQuery("Select Distinct `id`,`label`, reference_id, `order_type` From #__contentbuilder_elements Where form_id = " . intval($this->_id) . " And reference_id In (" . implode(',', $ids) . ") And published = 1 And list_include = 1 Order By ordering");
                     $rows = $this->_db->loadAssocList();
                     $ids = array();
                     foreach ($rows as $row) {
                         // cleaned up, in desired order
                         $data->labels[$row['reference_id']] = $row['label'];
                         $ids[] = $row['reference_id'];
                         $order_types['col' . $row['reference_id']] = $row['order_type'];
                     }
                 }
                 $act_as_registration = array();
                 if ($data->act_as_registration && $data->registration_username_field && $data->registration_name_field && $data->registration_email_field && $data->registration_email_repeat_field && $data->registration_password_field && $data->registration_password_repeat_field) {
                     $act_as_registration[$data->registration_username_field] = 'registration_username_field';
                     $act_as_registration[$data->registration_name_field] = 'registration_name_field';
                     $act_as_registration[$data->registration_email_field] = 'registration_email_field';
                 }
                 $data->items = $data->form->getListRecords($ids, $this->getState('formsd_filter'), $searchable_elements, $this->getState('limitstart'), $this->getState('limit'), $this->getState('formsd_filter_order'), $order_types, $this->getState('formsd_filter_order_Dir') ? $this->getState('formsd_filter_order_Dir') : $data->initial_order_dir, 0, $data->published_only, $this->frontend ? $data->own_only_fe ? JFactory::getUser()->get('id', 0) : -1 : ($data->own_only ? JFactory::getUser()->get('id', 0) : -1), $this->getState('formsd_filter_state'), $this->getState('formsd_filter_publish'), $data->initial_sort_order == -1 ? -1 : 'col' . $data->initial_sort_order, $data->initial_sort_order2 == -1 ? -1 : 'col' . $data->initial_sort_order2, $data->initial_sort_order3 == -1 ? -1 : 'col' . $data->initial_sort_order3, $this->_menu_filter, $this->frontend ? $data->show_all_languages_fe : true, $this->getState('formsd_filter_language'), $act_as_registration, $data, $this->getState('article_category_filter'));
                 if ($data->items === null) {
                     $mainframe->setUserState($option . 'formsd_filter_order', '');
                     JError::raiseError(500, JText::_('Stale list setup detected. Please reload view.'));
                 }
                 $data->items = contentbuilder::applyItemWrappers($this->_id, $data->items, $data);
                 $this->_total = $data->form->getListRecordsTotal($ids, $this->getState('formsd_filter'), $searchable_elements);
                 $data->visible_cols = $ids;
                 $data->states = array();
                 $data->state_colors = array();
                 $data->state_titles = array();
                 $data->published_items = array();
                 $data->states = contentbuilder::getListStates($this->_id);
                 if ($data->list_state) {
                     $data->state_colors = contentbuilder::getStateColors($data->items, $this->_id);
                     $data->state_titles = contentbuilder::getStateTitles($data->items, $this->_id);
                 }
                 if ($data->list_publish) {
                     $data->published_items = contentbuilder::getRecordsPublishInfo($data->items, $data->type, $data->reference_id);
                 }
                 $data->lang_codes = array();
                 if ($data->list_language) {
                     $data->lang_codes = contentbuilder::getRecordsLanguage($data->items, $data->type, $data->reference_id);
                 }
                 $data->languages = contentbuilder::getLanguageCodes();
                 // Search for the {readmore} tag and split the text up accordingly.
                 $pattern = '#<hr\\s+id=("|\')system-readmore("|\')\\s*\\/*>#i';
                 $tagPos = preg_match($pattern, $data->intro_text);
                 $fulltext = '';
                 if ($tagPos == 0) {
                     $introtext = $data->intro_text;
                 } else {
                     list($introtext, $fulltext) = preg_split($pattern, $data->intro_text, 2);
                 }
                 $data->intro_text = $introtext . ($fulltext ? '<br/><br/>' . $fulltext : '');
             }
             return $data;
         }
     }
     return null;
 }
예제 #13
0
 function __construct($config)
 {
     parent::__construct($config);
     $this->frontend = JFactory::getApplication()->isSite();
     $mainframe = JFactory::getApplication();
     $option = 'com_contentbuilder';
     $plugin = JRequest::getVar('plugin', '');
     $verification_name = JRequest::getVar('verification_name', '');
     $verification_id = JRequest::getVar('verification_id', '');
     $setup = '';
     $user_id = 0;
     if (!$verification_id) {
         $user_id = JFactory::getUser()->get('id', 0);
         $setup = JFactory::getSession()->get($plugin . $verification_name, '', 'com_contentbuilder.verify.' . $plugin . $verification_name);
     } else {
         $this->_db->setQuery("Select `setup`,`user_id` From #__contentbuilder_verifications Where `verification_hash` = " . $this->_db->Quote($verification_id));
         $setup = $this->_db->loadAssoc();
         if (is_array($setup)) {
             $user_id = $setup['user_id'];
             $setup = $setup['setup'];
         }
     }
     $out = array();
     if ($setup) {
         parse_str($setup, $out);
     }
     if (isset($out['plugin']) && $out['plugin'] && isset($out['verification_name']) && $out['verification_name'] && isset($out['verify_view']) && $out['verify_view']) {
         // alright
     } else {
         JFactory::getApplication()->redirect('index.php', 'Spoofed data or invalid verification id', 'error');
     }
     if (isset($out['plugin_options'])) {
         $options = base64_decode($out['plugin_options']);
         parse_str($options, $opts);
         $out['plugin_options'] = $opts;
         if (!count($out['plugin_options'])) {
             $out['plugin_options'] = array();
         }
     } else {
         $out['plugin_options'] = array();
     }
     $_now = JFactory::getDate();
     //$this->_db->setQuery("Select count(id) From #__contentbuilder_verifications Where Timestampdiff(Second, `start_date`, '".strtotime($_now->toMySQL())."') < 1 And ip = " . $this->_db->Quote($_SERVER['REMOTE_ADDR']));
     //$ver = $this->_db->loadResult();
     //if($ver >= 5){
     //    $this->_db->setQuery("Delete From #__contentbuilder_verifications Where `verification_date` = '0000-00-00 00:00:00' And ip = " . $this->_db->Quote($_SERVER['REMOTE_ADDR']));
     //    $this->_db->query();
     //    JError::raiseError(500, 'Penetration Denied');
     //}
     //$this->_db->setQuery("Delete From #__contentbuilder_verifications Where Timestampdiff(Second, `start_date`, '".strtotime($_now->toMySQL())."') > 86400 And `verification_date` = '0000-00-00 00:00:00'");
     //$this->_db->query();
     $rec = null;
     $redirect_view = '';
     if (isset($out['require_view']) && is_numeric($out['require_view']) && intval($out['require_view']) > 0) {
         if (JFactory::getSession()->get('cb_last_record_user_id', 0, 'com_contentbuilder')) {
             $user_id = JFactory::getSession()->get('cb_last_record_user_id', 0, 'com_contentbuilder');
             JFactory::getSession()->clear('cb_last_record_user_id', 'com_contentbuilder');
         }
         $id = intval($out['require_view']);
         $this->_db->setQuery("Select `type`, `reference_id`, `show_all_languages_fe` From #__contentbuilder_forms Where published = 1 And id = " . $id);
         $formsettings = $this->_db->loadAssoc();
         if (!is_array($formsettings)) {
             JError::raiseError(500, 'Verification Setup failed. Reason: View id ' . $out['require_view'] . ' has been requested but is not available (not existent or unpublished). Please update your content template or publish the view.');
         }
         $form = contentbuilder::getForm($formsettings['type'], $formsettings['reference_id']);
         $labels = $form->getElementLabels();
         $ids = array();
         foreach ($labels as $reference_id => $label) {
             $ids[] = $reference_id;
         }
         if (intval($user_id) == 0) {
             JFactory::getApplication()->redirect('index.php?option=com_contentbuilder&lang=' . JRequest::getCmd('lang', '') . '&return=' . base64_encode(JURI::getInstance()->toString()) . '&controller=edit&record_id=&id=' . $id . '&rand=' . rand(0, getrandmax()));
         }
         $rec = $form->getListRecords($ids, '', array(), 0, 1, '', array(), 'desc', 0, false, $user_id, 0, -1, -1, -1, -1, array(), true, null);
         if (count($rec) > 0) {
             $rec = $rec[0];
             $rec = $form->getRecord($rec->colRecord, false, -1, true);
         }
         if (!$form->getListRecordsTotal($ids)) {
             JFactory::getApplication()->redirect('index.php?option=com_contentbuilder&lang=' . JRequest::getCmd('lang', '') . '&return=' . base64_encode(JURI::getInstance()->toString()) . '&controller=edit&record_id=&id=' . $id . '&rand=' . rand(0, getrandmax()));
         }
     }
     // clearing session after possible required view to make re-visits possible
     JFactory::getSession()->clear($plugin . $verification_name, 'com_contentbuilder.verify.' . $plugin . $verification_name);
     $verification_data = '';
     if (is_array($rec) && count($rec)) {
         foreach ($rec as $value) {
             $verification_data .= urlencode(str_replace(array("\r", "\n"), '', $value->recTitle)) . "=" . urlencode(str_replace(array("\r", "\n"), '', $value->recValue)) . "&";
         }
         $verification_data = rtrim($verification_data, '&');
     }
     if (!JRequest::getBool('verify', 0) && !JRequest::getVar('token', '')) {
         jimport('joomla.version');
         $version = new JVersion();
         if (version_compare($version->getShortVersion(), '3.0', '>=')) {
             $___now = $_now->toSql();
         } else {
             $___now = $_now->toMySQL();
         }
         $verification_id = md5(uniqid(null, true) . mt_rand(0, mt_getrandmax()) . $user_id);
         $this->_db->setQuery("\n                    Insert Into #__contentbuilder_verifications\n                    (\n                    `verification_hash`,\n                    `start_date`,\n                    `verification_data`,\n                    `user_id`,\n                    `plugin`,\n                    `ip`,\n                    `setup`,\n                    `client`\n                    )\n                    Values\n                    (\n                    " . $this->_db->Quote($verification_id) . ",\n                    " . $this->_db->Quote($___now) . ",\n                    " . $this->_db->Quote('type=normal&' . $verification_data) . ",\n                    " . $user_id . ",\n                    " . $this->_db->Quote($plugin) . ",\n                    " . $this->_db->Quote($_SERVER['REMOTE_ADDR']) . ",\n                    " . $this->_db->Quote($setup) . ",\n                    " . intval($out['client']) . "\n                    )\n            ");
         $this->_db->query();
     }
     /*
     if(intval($out['client']) && !JFactory::getApplication()->isAdmin()){
        parse_str(JURI::getInstance()->getQuery(), $data1);
        $this_page = JURI::getInstance()->base() . 'administrator/index.php?'.http_build_query($data1, '', '&');
             }else{
        parse_str(JURI::getInstance()->getQuery(), $data1);
        $urlex = explode('?', JURI::getInstance()->toString());
        $this_page = $urlex[0] . '?' . http_build_query($data1, '', '&');
             }
     */
     if (intval($out['client']) && !JFactory::getApplication()->isAdmin()) {
         $this_page = JURI::getInstance()->base() . 'administrator/index.php?' . JURI::getInstance()->getQuery();
     } else {
         $this_page = JURI::getInstance()->toString();
     }
     JPluginHelper::importPlugin('contentbuilder_verify', $plugin);
     $dispatcher = JDispatcher::getInstance();
     $setup_result = $dispatcher->trigger('onSetup', array($this_page, $out));
     if (!implode('', $setup_result)) {
         if (!JRequest::getBool('verify', 0)) {
             if (JFactory::getApplication()->isAdmin()) {
                 $local = explode('/', JURI::getInstance()->base());
                 unset($local[count($local) - 1]);
                 unset($local[count($local) - 1]);
                 parse_str(JURI::getInstance()->getQuery(), $data);
                 $this_page = implode('/', $local) . '/index.php?' . http_build_query($data, '', '&') . '&verify=1&verification_id=' . $verification_id;
             } else {
                 parse_str(JURI::getInstance()->getQuery(), $data);
                 $urlex = explode('?', JURI::getInstance()->toString());
                 $this_page = $urlex[0] . '?' . http_build_query($data, '', '&') . '&verify=1&verification_id=' . $verification_id;
             }
             $forward_result = $dispatcher->trigger('onForward', array($this_page, $out));
             $forward = implode('', $forward_result);
             if ($forward) {
                 JFactory::getApplication()->redirect($forward);
             }
         } else {
             if ($verification_id) {
                 $msg = '';
                 $verify_result = $dispatcher->trigger('onVerify', array($this_page, $out));
                 if (count($verify_result)) {
                     if ($verify_result[0] === false) {
                         $msg = JText::_('COM_CONTENTBUILDER_VERIFICATION_FAILED');
                     } else {
                         if (isset($verify_result[0]['msg']) && $verify_result[0]['msg']) {
                             $msg = $verify_result[0]['msg'];
                         } else {
                             if (isset($out['verification_msg']) && $out['verification_msg']) {
                                 $msg = urldecode($out['verification_msg']);
                             } else {
                                 $msg = JText::_('COM_CONTENTBUILDER_VERIFICATION_SUCCESS');
                             }
                         }
                         if (!$out['client'] && (!isset($out['return-site']) || !$out['return-site']) || $out['client'] && (!isset($out['return-admin']) || !$out['return-admin'])) {
                             if (intval($out['client']) && !JFactory::getApplication()->isAdmin()) {
                                 $redirect_view = JURI::getInstance()->base() . 'administrator/index.php?option=com_contentbuilder&controller=list&lang=' . JRequest::getCmd('lang', '') . '&id=' . $out['verify_view'];
                             } else {
                                 $redirect_view = 'index.php?option=com_contentbuilder&controller=list&lang=' . JRequest::getCmd('lang', '') . '&id=' . $out['verify_view'];
                             }
                         }
                         $this->_db->setQuery("Select id From #__contentbuilder_users Where userid = " . $this->_db->Quote($user_id) . " And form_id = " . intval($out['verify_view']));
                         $usertableid = $this->_db->loadResult();
                         $levels = explode(',', $out['verify_levels']);
                         jimport('joomla.version');
                         $version = new JVersion();
                         if (version_compare($version->getShortVersion(), '3.0', '>=')) {
                             $___now = $_now->toSql();
                         } else {
                             $___now = $_now->toMySQL();
                         }
                         if ($usertableid) {
                             $this->_db->setQuery("Update #__contentbuilder_users\n                                Set\n                                " . (in_array('view', $levels) ? ' verified_view=1, verification_date_view=' . $this->_db->Quote($___now) . ", " : '') . "\n                                " . (in_array('new', $levels) ? ' verified_new=1, verification_date_new=' . $this->_db->Quote($___now) . ", " : '') . "\n                                " . (in_array('edit', $levels) ? ' verified_edit=1, verification_date_edit=' . $this->_db->Quote($___now) . ", " : '') . "\n                                published = 1\n                                Where id = {$usertableid}\n                                ");
                             $this->_db->query();
                         } else {
                             $this->_db->setQuery("\n                                Insert Into #__contentbuilder_users\n                                (\n                                " . (in_array('view', $levels) ? 'verified_view, verification_date_view,' : '') . "\n                                " . (in_array('new', $levels) ? 'verified_new, verification_date_new,' : '') . "\n                                " . (in_array('edit', $levels) ? 'verified_edit, verification_date_edit,' : '') . "\n                                published,\n                                userid,\n                                form_id\n                                )\n                                Values\n                                (\n                                " . (in_array('view', $levels) ? '1, ' . $this->_db->Quote($___now) . ',' : '') . "\n                                " . (in_array('new', $levels) ? '1, ' . $this->_db->Quote($___now) . ',' : '') . "\n                                " . (in_array('edit', $levels) ? '1, ' . $this->_db->Quote($___now) . ',' : '') . "\n                                1,\n                                " . $this->_db->Quote($user_id) . ",\n                                " . intval($out['verify_view']) . "\n                                )\n                                ");
                             $this->_db->query();
                         }
                         $verification_data = ($verification_data ? '&' : '') . '';
                         if (isset($verify_result[0]['data']) && is_array($verify_result[0]['data']) && count($verify_result[0]['data'])) {
                             foreach ($verify_result[0]['data'] as $key => $value) {
                                 $verification_data .= urlencode(str_replace(array("\r", "\n"), '', $key)) . "=" . urlencode(str_replace(array("\r", "\n"), '', $value)) . "&";
                             }
                             $verification_data = rtrim($verification_data, '&');
                         }
                         $this->_db->setQuery("\n                                Update #__contentbuilder_verifications\n                                Set\n                                `verification_hash` = '',\n                                `is_test` = " . (isset($verify_result[0]['is_test']) ? intval(isset($verify_result[0]['is_test'])) : 0) . ",\n                                `verification_date` = " . $this->_db->Quote($___now) . " \n                                " . ($verification_data ? ',verification_data = concat(verification_data, ' . $this->_db->Quote($verification_data) . ') ' : '') . "\n                                Where\n                                verification_hash = " . $this->_db->Quote($verification_id) . "\n                                And\n                                verification_hash <> ''\n                                And\n                                `verification_date` = '0000-00-00 00:00:00'\n                                \n                            ");
                         $this->_db->query();
                         // token check if given
                         if (JRequest::getVar('token', '')) {
                             jimport('joomla.version');
                             $version = new JVersion();
                             if (version_compare($version->getShortVersion(), '1.6', '>=')) {
                                 $this->activate(JRequest::getVar('token', ''));
                             } else {
                                 $this->activate15(JRequest::getVar('token', ''));
                             }
                         }
                         // exit if requested
                         if (count($verify_result) && isset($verify_result[0]['exit']) && $verify_result[0]['exit']) {
                             @ob_end_clean();
                             if (isset($verify_result[0]['header']) && $verify_result[0]['header']) {
                                 header($verify_result[0]['header']);
                             }
                             exit;
                         }
                     }
                 }
             } else {
                 $msg = JText::_('COM_CONTENTBUILDER_VERIFICATION_NOT_EXECUTED');
             }
             if (!$out['client']) {
                 JFactory::getApplication()->redirect($redirect_view ? $redirect_view : (!$out['client'] && isset($out['return-site']) && $out['return-site'] ? base64_decode($out['return-site']) : 'index.php'), $msg);
             } else {
                 JFactory::getApplication()->redirect($redirect_view ? $redirect_view : ($out['client'] && isset($out['return-admin']) && $out['return-admin'] ? base64_decode($out['return-admin']) : 'index.php'), $msg);
             }
         }
     } else {
         JError::raiseError(500, 'Verification Setup failed. Reason: ' . implode('', $setup_result));
     }
 }
 function onContentPrepare($context, &$article, &$params, $limitstart = 0, $is_list = false, $form = null, $item = null)
 {
     $protect = false;
     $plugin = JPluginHelper::getPlugin('content', 'contentbuilder_download');
     jimport('joomla.html.parameter');
     $pluginParams = CBCompat::getParams($plugin->params);
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.folder');
     if (!JFile::exists(JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'classes' . DS . 'contentbuilder.php')) {
         return true;
     }
     $lang = JFactory::getLanguage();
     $lang->load('plg_content_contentbuilder_download', JPATH_ADMINISTRATOR);
     /*
      * As of Joomla! 1.6 there is just the text passed if the article data is not passed in article context.
      * (for instance with categories).
      * But we need the article id, so we use the article id flag from content generation.
      */
     if (is_object($article) && !isset($article->id) && !isset($article->cbrecord) && isset($article->text) && $article->text) {
         preg_match_all("/<!--\\(cbArticleId:(\\d{1,})\\)-->/si", $article->text, $matched_id);
         if (isset($matched_id[1]) && isset($matched_id[1][0])) {
             $article->id = intval($matched_id[1][0]);
         }
     }
     // if this content plugin has been called from within list context
     if ($is_list) {
         if (!trim($article->text)) {
             return true;
         }
         $article->cbrecord = $form;
         $article->cbrecord->items = array();
         $article->cbrecord->items[0] = $item;
         $article->cbrecord->record_id = $item->colRecord;
     }
     if (!JFolder::exists(JPATH_SITE . DS . 'media' . DS . 'contentbuilder')) {
         JFolder::create(JPATH_SITE . DS . 'media' . DS . 'contentbuilder');
     }
     if (!JFile::exists(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'index.html')) {
         JFile::write(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'index.html', $def = '');
     }
     if (!JFolder::exists(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins')) {
         JFolder::create(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins');
     }
     if (!JFile::exists(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins' . DS . 'index.html')) {
         JFile::write(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins' . DS . 'index.html', $def = '');
     }
     if (!JFolder::exists(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins' . DS . 'download')) {
         JFolder::create(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins' . DS . 'download');
     }
     if (!JFile::exists(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins' . DS . 'download' . DS . 'index.html')) {
         JFile::write(JPATH_SITE . DS . 'media' . DS . 'contentbuilder' . DS . 'plugins' . DS . 'image_scale' . DS . 'index.html', $def = '');
     }
     if (isset($article->id) || isset($article->cbrecord)) {
         $db = JFactory::getDBO();
         $matches = array();
         preg_match_all("/\\{CBDownload([^}]*)\\}/i", $article->text, $matches);
         if (isset($matches[0]) && is_array($matches[0]) && isset($matches[1]) && is_array($matches[1])) {
             $record = null;
             $default_title = '';
             $protect = 0;
             $form_id = 0;
             $record_id = 0;
             $type = '';
             $frontend = true;
             if (JFactory::getApplication()->isAdmin()) {
                 $frontend = false;
             }
             if (isset($article->id) && $article->id && !isset($article->cbrecord)) {
                 // try to obtain the record id if if this is just an article
                 $db->setQuery("Select form.`title_field`,form.`protect_upload_directory`,form.`reference_id`,article.`record_id`,article.`form_id`,form.`type`,form.`published_only`,form.`own_only`,form.`own_only_fe` From #__contentbuilder_articles As article, #__contentbuilder_forms As form Where form.`published` = 1 And form.id = article.`form_id` And article.`article_id` = " . $article->id);
                 $data = $db->loadAssoc();
                 require_once JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'classes' . DS . 'contentbuilder.php';
                 $form = contentbuilder::getForm($data['type'], $data['reference_id']);
                 if (!$form || !$form->exists) {
                     return true;
                 }
                 if ($form) {
                     $protect = $data['protect_upload_directory'];
                     $record = $form->getRecord($data['record_id'], $data['published_only'], $frontend ? $data['own_only_fe'] ? JFactory::getUser()->get('id', 0) : -1 : ($data['own_only'] ? JFactory::getUser()->get('id', 0) : -1), true);
                     $default_title = $data['title_field'];
                     $form_id = $data['form_id'];
                     $record_id = $data['record_id'];
                     $type = $data['type'];
                 }
             } else {
                 if (isset($article->cbrecord) && isset($article->cbrecord->id) && $article->cbrecord->id) {
                     $protect = $article->cbrecord->protect_upload_directory;
                     $record = $article->cbrecord->items;
                     $default_title = $article->cbrecord->title_field;
                     $form_id = $article->cbrecord->id;
                     $record_id = $article->cbrecord->record_id;
                     $type = $article->cbrecord->type;
                 }
             }
             if (!$is_list) {
                 contentbuilder::setPermissions($form_id, $record_id, $frontend ? '_fe' : '');
                 if ($frontend) {
                     if (!contentbuilder::authorizeFe('view')) {
                         if (JRequest::getVar('contentbuilder_download_file', '', 'GET', 'STRING', JREQUEST_ALLOWRAW)) {
                             ob_end_clean();
                             die('No Access');
                         } else {
                             return true;
                         }
                     }
                 } else {
                     if (!contentbuilder::authorize('view')) {
                         if (JRequest::getVar('contentbuilder_download_file', '', 'GET', 'STRING', JREQUEST_ALLOWRAW)) {
                             ob_end_clean();
                             die('No Access');
                         } else {
                             return true;
                         }
                     }
                 }
             }
             if (!trim($default_title)) {
                 $default_title = strtotime('now');
             }
             $i = 0;
             foreach ($matches[1] as $match) {
                 $out = '';
                 $field = $is_list ? $article->cbrecord->items[0]->recName : '';
                 $box_style = 'border-width:thin::border-color:#000000::border-style:dashed::padding:5px::';
                 $info_style = '';
                 $align = '';
                 $info = true;
                 $hide_filename = false;
                 $hide_mime = false;
                 $hide_size = false;
                 $hide_downloads = false;
                 $options = explode(';', trim($match));
                 foreach ($options as $option) {
                     $keyval = explode(':', trim($option), 2);
                     if (count($keyval) == 2) {
                         $value = trim($keyval[1]);
                         switch (strtolower(trim($keyval[0]))) {
                             case 'field':
                                 $field = $value;
                                 break;
                             case 'info-style':
                                 $info_style = $value;
                                 break;
                             case 'box-style':
                                 $box_style = $value;
                                 break;
                             case 'align':
                                 $align = $value;
                                 break;
                             case 'info':
                                 $info = $value == 'true' ? true : false;
                                 break;
                             case 'hide-filename':
                                 $hide_filename = $value == 'true' ? true : false;
                                 break;
                             case 'hide-mime':
                                 $hide_mime = $value == 'true' ? true : false;
                                 break;
                             case 'hide-size':
                                 $hide_size = $value == 'true' ? true : false;
                                 break;
                             case 'hide-downloads':
                                 $hide_downloads = $value == 'true' ? true : false;
                                 break;
                         }
                     }
                 }
                 $is_series = false;
                 if ($field && isset($record) && $record !== null && is_array($record)) {
                     foreach ($record as $item) {
                         if ($default_title == $item->recElementId) {
                             $default_title = $item->recValue;
                             break;
                         }
                     }
                     foreach ($record as $item) {
                         if ($item->recName == $field) {
                             $the_files = explode("\n", str_replace("\r", '', $item->recValue));
                             $the_files_size = count($the_files);
                             if ($the_files_size > 0) {
                                 $is_series = true;
                             }
                             for ($fcnt = 0; $fcnt < $the_files_size; $fcnt++) {
                                 $the_value = str_replace(array('{CBSite}', '{cbsite}'), JPATH_SITE, trim($the_files[$fcnt]));
                                 if ($the_value) {
                                     $exists = JFile::exists($the_value);
                                     if ($exists) {
                                         $phpversion = explode('-', phpversion());
                                         $phpversion = $phpversion[0];
                                         // because of mime_content_type deprecation
                                         if (version_compare($phpversion, '5.3', '<')) {
                                             if (function_exists('mime_content_type')) {
                                                 $mime = mime_content_type($the_value);
                                             } else {
                                                 // fallback if not even that one exists
                                                 $mime = $this->mime_content_type($the_value);
                                             }
                                         } else {
                                             if (function_exists('finfo_open')) {
                                                 $finfo = finfo_open(FILEINFO_MIME_TYPE);
                                                 $mime = finfo_file($finfo, $the_value);
                                                 finfo_close($finfo);
                                             } else {
                                                 $mime = $this->mime_content_type($the_value);
                                             }
                                         }
                                         if (JRequest::getVar('contentbuilder_download_file', '', 'GET', 'STRING', JREQUEST_ALLOWRAW) == sha1($field . $the_value)) {
                                             $download_name = basename(JFilterOutput::stringURLSafe($default_title) . '_' . $the_value);
                                             $file_id = md5($type . $item->recElementId . $the_value);
                                             if (!JFactory::getSession()->get('downloaded' . $type . $item->recElementId . $file_id, false, 'com_contentbuilder.plugin.download')) {
                                                 $db->setQuery("Select hits From #__contentbuilder_resource_access Where `type` = " . $db->Quote($type) . " And resource_id = '" . $file_id . "' And element_id = " . $db->Quote($item->recElementId));
                                                 if ($db->loadResult() === null) {
                                                     $db->setQuery("Insert Into #__contentbuilder_resource_access (`type`, form_id, element_id, resource_id, hits) values (" . $db->Quote($type) . "," . intval($form_id) . ", " . $db->Quote($item->recElementId) . ", '" . $file_id . "',1)");
                                                 } else {
                                                     $db->setQuery("Update #__contentbuilder_resource_access Set `type` = " . $db->Quote($type) . ", resource_id = '" . $file_id . "', form_id = " . intval($form_id) . ", element_id = " . $db->Quote($item->recElementId) . ", hits = hits + 1 Where `type` = " . $db->Quote($type) . " And resource_id = '" . $file_id . "' And element_id = " . $db->Quote($item->recElementId));
                                                 }
                                                 $db->query();
                                             }
                                             JFactory::getSession()->set('downloaded' . $type . $item->recElementId . $file_id, true, 'com_contentbuilder.plugin.download');
                                             // clean up before displaying
                                             @ob_end_clean();
                                             header('Content-Type: application/octet-stream; name="' . $download_name . '"');
                                             header('Content-Disposition: inline; filename="' . $download_name . '"');
                                             header('Content-Length: ' . @filesize($the_value));
                                             // NOTE: if running IIS and CGI, raise the CGI timeout to serve large files
                                             @$this->readfile_chunked($the_value);
                                             exit;
                                         }
                                         $info_style_ = $info_style;
                                         $box_style_ = $box_style;
                                         $info_ = $info;
                                         $align_ = $align;
                                         $download_name = basename(JFilterOutput::stringURLSafe($default_title) . '_' . $the_value);
                                         $file_id = md5($type . $item->recElementId . $the_value);
                                         $db->setQuery("Select hits From #__contentbuilder_resource_access Where resource_id = '" . $file_id . "' And `type` = " . intval($type) . " And element_id = " . $db->Quote($item->recElementId));
                                         $hits = $db->loadResult();
                                         if (!$hits) {
                                             $hits = 0;
                                         }
                                         $size = @number_format(filesize($the_value) / (1024 * 1024), 2) . ' MB';
                                         if (!floatval($size)) {
                                             $size = @number_format(filesize($the_value) / 1024, 2) . ' kb';
                                         }
                                         $hide_filename_ = $hide_filename;
                                         $hide_mime_ = $hide_mime;
                                         $hide_size_ = $hide_size;
                                         $hide_downloads_ = $hide_downloads;
                                         $url = JURI::getInstance()->toString();
                                         $open_ = JRoute::_($url . (strstr($url, '?') !== false ? '&' : '?') . 'contentbuilder_download_file=' . sha1($field . $the_value));
                                         $out .= '<div style="' . ($align_ ? 'float: ' . $align_ . ';' : '') . str_replace('::', ';', $box_style_) . '">
                                                     <a href="' . $open_ . '">' . JText::_('COM_CONTENTBUILDER_PLUGIN_DOWNLOAD_DOWNLOAD') . '</a>' . ($info_ ? '<div style="' . str_replace('::', ';', $info_style_) . '">
                                                                 ' . ($hide_filename_ ? '' : '<span class="cbPluginDownloadFilename">' . JText::_('COM_CONTENTBUILDER_PLUGIN_DOWNLOAD_FILENAME') . ':</span> ' . $download_name . '<br/>') . '
                                                                 ' . ($hide_mime_ ? '' : '<span class="cbPluginDownloadMime">' . JText::_('COM_CONTENTBUILDER_PLUGIN_DOWNLOAD_MIME') . ':</span> ' . $mime . '<br/>') . '
                                                                 ' . ($hide_size_ ? '' : '<span ' . ($hide_size_ ? ' style="display:none;" ' : '') . 'class="cbPluginDownloadSize">' . JText::_('COM_CONTENTBUILDER_PLUGIN_DOWNLOAD_SIZE') . ':</span> ' . $size . '<br/>') . '
                                                                 ' . ($hide_downloads_ ? '' : '<span ' . ($hide_downloads_ ? ' style="display:none;" ' : '') . 'class="cbPluginDownloadDownloads">' . JText::_('COM_CONTENTBUILDER_PLUGIN_DOWNLOAD_DOWNLOADS') . ':</span> ' . $hits . '<br/>') . '
                                                              </div>' : '') . '</div>';
                                         if ($is_series && $align_ && (strtolower($align_) == 'left' || strtolower($align_) == 'right')) {
                                             $out .= '<div style="float:' . strtolower($align_) . ';width: 5px;">&nbsp;</div>';
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 if ($is_series && $align && (strtolower($align) == 'left' || strtolower($align) == 'right')) {
                     $out .= '<div style="clear:' . strtolower($align) . ';"></div>';
                 }
                 $article->text = str_replace($matches[0][$i], $out, $article->text);
                 $i++;
             }
         }
     }
     return true;
 }
예제 #15
0
 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){
                 //    $this->_show_page_heading = $item->params->get('show_page_heading', null);
                 //}
             }
         } else {
             $params = JComponentHelper::getParams($option);
             if ($params->get('record_id', null)) {
                 JRequest::setVar('record_id', $params->get('record_id', null));
                 $this->_show_back_button = $params->get('show_back_button', null);
             }
             //if($params->get('show_page_heading', null) !== null){
             //    $this->_show_page_heading = $params->get('show_page_heading', null);
             //}
         }
     }
     if (JRequest::getWord('view', '') == 'latest') {
         $db = JFactory::getDBO();
         $db->setQuery('Select `type`, `reference_id` From #__contentbuilder_forms Where id = ' . intval(JRequest::getInt('id', 0)) . ' And published = 1');
         $form = $db->loadAssoc();
         $form = contentbuilder::getForm($form['type'], $form['reference_id']);
         $labels = $form->getElementLabels();
         $ids = array();
         foreach ($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(JRequest::getInt('id', 0)) . " And reference_id In (" . implode(',', $ids) . ") And published = 1 Order By ordering");
             $rows = $db->loadAssocList();
             $ids = array();
             foreach ($rows as $row) {
                 $ids[] = $row['reference_id'];
             }
         }
         $rec = $form->getListRecords($ids, '', array(), 0, 1, '', array(), 'desc', 0, false, JFactory::getUser()->get('id', 0), 0, -1, -1, -1, -1, array(), true, null);
         if (count($rec) > 0) {
             $rec = $rec[0];
             $rec2 = $form->getRecord($rec->colRecord, false, -1, true);
             $record_id = $rec->colRecord;
             JRequest::setVar('record_id', $record_id);
         }
         if (!JRequest::getCmd('record_id', '')) {
             JRequest::setVar('cbIsNew', 1);
             contentbuilder::setPermissions(JRequest::getInt('id', 0), 0, class_exists('cbFeMarker') ? '_fe' : '');
             $auth = class_exists('cbFeMarker') ? contentbuilder::authorizeFe('new') : contentbuilder::authorize('new');
             if ($auth) {
                 JFactory::getApplication()->redirect(JRoute::_('index.php?option=com_contentbuilder&controller=edit&latest=1&backtolist=' . JRequest::getInt('backtolist', 0) . '&id=' . JRequest::getInt('id', 0) . (JRequest::getVar('tmpl', '') != '' ? '&tmpl=' . JRequest::getVar('tmpl', '') : '') . (JRequest::getVar('layout', '') != '' ? '&layout=' . JRequest::getVar('layout', '') : '') . '&record_id=&limitstart=' . JRequest::getInt('limitstart', 0) . '&filter_order=' . JRequest::getVar('filter_order', ''), false));
             } else {
                 JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTBUILDER_ADD_ENTRY_FIRST'));
                 JFactory::getApplication()->redirect('index.php', false);
             }
         }
     }
     contentbuilder::setPermissions(JRequest::getInt('id', 0), JRequest::getCmd('record_id', 0), class_exists('cbFeMarker') ? '_fe' : '');
     parent::__construct();
 }
예제 #16
0
 public static function createArticle($contentbuilder_form_id, $record_id, array $record, array $elements_allowed, $title_field = '', $metadata = null, $config = array(), $full = false, $limited_options = true, $menu_cat_id = null)
 {
     $tz = new DateTimeZone(JFactory::getApplication()->getCfg('offset'));
     if (isset($config['publish_up']) && $config['publish_up'] && $config['publish_up'] != '0000-00-00 00:00:00') {
         $config['publish_up'] = JFactory::getDate($config['publish_up'], $tz);
         $config['publish_up'] = $config['publish_up']->format('Y-m-d H:i:s');
     } else {
         $config['publish_up'] = '0000-00-00 00:00:00';
     }
     if (isset($config['created']) && $config['created'] && $config['created'] != '0000-00-00 00:00:00') {
         $config['created'] = JFactory::getDate($config['created'], $tz);
         $config['created'] = $config['created']->format('Y-m-d H:i:s');
     } else {
         $config['created'] = '0000-00-00 00:00:00';
     }
     if (isset($config['publish_down']) && $config['publish_down'] && $config['publish_down'] != '0000-00-00 00:00:00') {
         $config['publish_down'] = JFactory::getDate($config['publish_down'], $tz);
         $config['publish_down'] = $config['publish_down']->format('Y-m-d H:i:s');
     } else {
         $config['publish_down'] = '0000-00-00 00:00:00';
     }
     $is15 = true;
     $version = new JVersion();
     if (version_compare($version->getShortVersion(), '1.6', '>=')) {
         $is15 = false;
     }
     $tpl = self::getTemplate($contentbuilder_form_id, $record_id, $record, $elements_allowed, true);
     if (!$tpl) {
         return 0;
     }
     $db = JFactory::getDBO();
     $db->setQuery("Select * From #__contentbuilder_forms Where id = " . intval($contentbuilder_form_id) . " And published = 1");
     $form = $db->loadAssoc();
     if (!$form) {
         return 0;
     }
     if ($is15 && $menu_cat_id !== null) {
         if (intval($menu_cat_id) > -2) {
             $menu_cat_id = explode(':', $menu_cat_id);
             if (count($menu_cat_id) == 2) {
                 $form['default_category'] = $menu_cat_id[1];
                 $form['default_section'] = $menu_cat_id[0];
             }
         }
     } else {
         if ($menu_cat_id !== null && intval($menu_cat_id) > -2) {
             $form['default_category'] = $menu_cat_id;
         }
     }
     $user = null;
     if ($form['act_as_registration']) {
         if ($record_id) {
             $form_ = contentbuilder::getForm($form['type'], $form['reference_id']);
             $meta = $form_->getRecordMetadata($record_id);
             $db->setQuery("Select * From #__users Where id = " . $meta->created_id);
             $user = $db->loadObject();
         } else {
             if (JFactory::getUser()->get('id', 0)) {
                 $db->setQuery("Select * From #__users Where id = " . JFactory::getUser()->get('id', 0));
                 $user = $db->loadObject();
             }
         }
     }
     $label = '';
     foreach ($record as $rec) {
         if ($rec->recElementId == $title_field) {
             if ($form['act_as_registration'] && $user !== null) {
                 if ($form['registration_name_field'] == $rec->recElementId) {
                     $rec->recValue = $user->name;
                 } else {
                     if ($form['registration_username_field'] == $rec->recElementId) {
                         $rec->recValue = $user->username;
                     } else {
                         if ($form['registration_email_field'] == $rec->recElementId) {
                             $rec->recValue = $user->email;
                         } else {
                             if ($form['registration_email_repeat_field'] == $rec->recElementId) {
                                 $rec->recValue = $user->email;
                             }
                         }
                     }
                 }
             }
             $label = cbinternal($rec->recValue);
             break;
         }
     }
     // trying first element if no title field given
     if (!$label && !count($record)) {
         $label = 'Unnamed';
     } else {
         if (!$label && count($record)) {
             $label = cbinternal($record[0]->recValue);
         }
     }
     // Clean text for xhtml transitional compliance
     $introtext = '';
     $fulltext = '';
     $tpl = str_replace('<br>', '<br />', $tpl);
     // Search for the {readmore} tag and split the text up accordingly.
     $pattern = '#<hr\\s+id=("|\')system-readmore("|\')\\s*\\/*>#i';
     $tagPos = preg_match($pattern, $tpl);
     if ($tagPos == 0) {
         $introtext = $tpl;
     } else {
         list($introtext, $fulltext) = preg_split($pattern, $tpl, 2);
     }
     // retrieve the publish state from the list view
     $state = 1;
     $db->setQuery("Select published, is_future, publish_up, publish_down From #__contentbuilder_records Where `type` = " . $db->Quote($form['type']) . " And reference_id = " . $db->Quote($form['reference_id']) . " And record_id = " . $db->Quote($record_id));
     $state = $db->loadAssoc();
     $publish_up_record = $state['publish_up'];
     $publish_down_record = $state['publish_down'];
     $state = $state['is_future'] ? 1 : $state['published'];
     // save/update articles
     $alias = '';
     $db->setQuery("Select articles.`article_id`, content.`alias` From #__contentbuilder_articles As articles, #__content As content Where content.id = articles.article_id And (content.state = 1 Or content.state = 0) And articles.form_id = " . intval($contentbuilder_form_id) . " And articles.record_id = " . $db->Quote($record_id));
     $article = $db->loadAssoc();
     if (is_array($article)) {
         $alias = $article['alias'];
         $article = $article['article_id'];
     }
     // params
     $attribs = '';
     $meta = '';
     $rules = '';
     $metakey = '';
     $metadesc = '';
     $created_by = 0;
     $created_by_alias = '';
     $created_article = null;
     $_now = JFactory::getDate();
     $created_up = $publish_up_record;
     $created_down = $publish_down_record;
     if (is_array($article) && isset($article['article_id']) && intval($form['default_publish_up_days']) != 0) {
         // this will cause errors on 64bit systems, as strtotime's behavior is different for null dates
         // $date = JFactory::getDate(strtotime('now +'.intval($form['default_publish_up_days']).' days'));
         // fix as of forum post http://crosstec.de/forums/37-contentbuilder-general-forum-english/62084-64-bit-strtotime-bug.html#62084
         // thanks to user Fremmedkar
         $date = JFactory::getDate(strtotime(($created_up !== null && $created_up != '0000-00-00 00:00:00' ? $created_up : $_now) . ' +' . intval($form['default_publish_down_days']) . ' days'));
         if (version_compare($version->getShortVersion(), '3.0', '>=')) {
             $created_up = $date->toSql();
         } else {
             $created_up = $date->toMySQL();
         }
     }
     $publish_up = $created_up;
     if (is_array($article) && isset($article['article_id']) && intval($form['default_publish_down_days']) != 0) {
         //$date = JFactory::getDate(strtotime( ($created_up !== null ? $created_up : $_now).' +'.intval($form['default_publish_down_days']).' days'));
         $date = JFactory::getDate(strtotime(($created_up !== null && $created_up != '0000-00-00 00:00:00' ? $created_up : $_now) . ' +' . intval($form['default_publish_down_days']) . ' days'));
         if (version_compare($version->getShortVersion(), '3.0', '>=')) {
             $created_down = $date->toSql();
         } else {
             $created_down = $date->toMySQL();
         }
     }
     $publish_down = $created_down;
     $featured = $form['default_featured'];
     $ignore_lang_code = '*';
     if ($form['default_lang_code_ignore']) {
         if (!$is15) {
             $db->setQuery("Select lang_code From #__languages Where published = 1 And sef = " . $db->Quote(JRequest::getCmd('lang', '')));
             $ignore_lang_code = $db->loadResult();
             if (!$ignore_lang_code) {
                 $ignore_lang_code = '*';
             }
         } else {
             $ignore_lang_code = '';
             $codes = self::getLanguageCodes();
             foreach ($codes as $code) {
                 if (strstr(strtolower($code), strtolower(trim(JRequest::getCmd('lang', 'xxxxx')))) !== false) {
                     $ignore_lang_code = $code;
                     break;
                 }
             }
         }
     }
     $language = $form['default_lang_code_ignore'] ? $ignore_lang_code : $form['default_lang_code'];
     if ($is15) {
         // an exception regarding limited options for language
         if (!isset($config['params'])) {
             $registry = new JRegistry();
             $attr = array('language' => $language);
             $registry->loadArray($attr);
             $attribs = (string) $registry->toString();
         }
     }
     $access = $form['default_access'];
     $ordering = 0;
     if (!$is15 && $full) {
         //$state = isset($config['state']) ? $config['state'] : $state;
         // change the state in the CB records as well if coming from article settings
         //if(isset($config['state'])){
         //    $db->setQuery("Update #__contentbuilder_records Set `published` = ".( intval($config['state'])  == 1 ? 1 : 0 )." Where reference_id = ".$db->Quote($form['reference_id'])." And record_id = " . $db->Quote($record_id));
         //    $db->query();
         //}
         // limited
         $alias = isset($config['alias']) ? $config['alias'] : $alias;
         // limited
         $form['default_category'] = isset($config['catid']) ? $config['catid'] : $form['default_category'];
         // limited
         $access = isset($config['access']) ? $config['access'] : $access;
         // limited
         $featured = isset($config['featured']) ? $config['featured'] : 0;
         // limited
         $language = isset($config['language']) ? $config['language'] : $language;
         if ($form['article_record_impact_language'] && isset($config['language'])) {
             $db->setQuery("Select sef From #__languages Where published = 1 And lang_code = " . $db->Quote($config['language']));
             $sef = $db->loadResult();
             if ($sef === null) {
                 $sef = '';
             }
             $db->setQuery("Update #__contentbuilder_records Set sef = " . $db->Quote($sef) . ", lang_code = " . $db->Quote($config['language']) . " Where `type` = " . $db->Quote($form['type']) . " And reference_id = " . $db->Quote($form['reference_id']) . " And record_id = " . $db->Quote($record_id));
             $db->query();
         }
         // limited
         $created_by_alias = isset($config['created_by_alias']) ? $config['created_by_alias'] : '';
         if ($form['article_record_impact_publish'] && isset($config['publish_up']) && $config['publish_up'] != $publish_up) {
             // check in strtotime due to php's different behavior on 64bit machines
             if (version_compare($version->getShortVersion(), '3.0', '>=')) {
                 $___now = $_now->toSql();
             } else {
                 $___now = $_now->toMySQL();
             }
             $db->setQuery("Update #__contentbuilder_records Set " . (strtotime($config['publish_up'] == '0000-00-00 00:00:00' ? '1976-03-07 22:10:00' : $config['publish_up']) >= strtotime($___now) ? 'published = 0, is_future = 1, ' : '') . " publish_up = " . $db->Quote($config['publish_up']) . " Where `type` = " . $db->Quote($form['type']) . " And reference_id = " . $db->Quote($form['reference_id']) . " And record_id = " . $db->Quote($record_id));
             $db->query();
         }
         // limited
         $publish_up = isset($config['publish_up']) ? $config['publish_up'] : $publish_up;
         if ($form['article_record_impact_publish'] && isset($config['publish_down']) && $config['publish_down'] != $publish_down) {
             if (version_compare($version->getShortVersion(), '3.0', '>=')) {
                 $___now = $_now->toSql();
             } else {
                 $___now = $_now->toMySQL();
             }
             $db->setQuery("Update #__contentbuilder_records Set " . (strtotime($config['publish_down'] == '0000-00-00 00:00:00' ? '1976-03-07 22:10:00' : $config['publish_down']) <= strtotime($___now) ? 'published = 0,' : '') . "  publish_down = " . $db->Quote($config['publish_down']) . " Where `type` = " . $db->Quote($form['type']) . " And reference_id = " . $db->Quote($form['reference_id']) . " And record_id = " . $db->Quote($record_id));
             $db->query();
         }
         // limited
         $publish_down = isset($config['publish_down']) ? $config['publish_down'] : $publish_down;
         // limited
         $metakey = isset($config['metakey']) ? $config['metakey'] : '';
         // limited
         $metadesc = isset($config['metadesc']) ? $config['metadesc'] : '';
         $robots = '';
         $author = '';
         $rights = '';
         $xreference = '';
         if (!$limited_options) {
             // FULL
             $created_article = isset($config['created']) ? $config['created'] : null;
             // FULL
             if (JFactory::getApplication()->isAdmin()) {
                 $created_by = isset($config['created_by']) ? $config['created_by'] : 0;
             }
             // FULL
             if (isset($config['attribs']) && is_array($config['attribs'])) {
                 $registry = new JRegistry();
                 $registry->loadArray($config['attribs']);
                 $attribs = (string) $registry;
             }
             // FULL
             if (isset($config['metadata']) && is_array($config['metadata'])) {
                 if (isset($config['metadata']['robots'])) {
                     $robots = $config['metadata']['robots'];
                 }
                 if (isset($config['metadata']['author'])) {
                     $author = $config['metadata']['author'];
                 }
                 if (isset($config['metadata']['rights'])) {
                     $rights = $config['metadata']['rights'];
                 }
                 if (isset($config['metadata']['xreference'])) {
                     $xreference = $config['metadata']['xreference'];
                 }
                 $registry = new JRegistry();
                 $registry->loadArray($config['metadata']);
                 $meta = (string) $registry;
             }
         }
         $db->setQuery("Update #__contentbuilder_records Set robots = " . $db->Quote($robots) . ", author = " . $db->Quote($author) . ", rights = " . $db->Quote($rights) . ", xreference = " . $db->Quote($xreference) . ", metakey = " . $db->Quote($metakey) . ", metadesc = " . $db->Quote($metadesc) . " Where `type` = " . $db->Quote($form['type']) . " And reference_id = " . $db->Quote($form['reference_id']) . " And record_id = " . $db->Quote($record_id));
         $db->query();
         // Trigger the onContentBeforeSave event.
         $isNew = true;
         $dispatcher = JDispatcher::getInstance();
         $table = JTable::getInstance('content');
         if ($article > 0) {
             $table->load($article);
             $isNew = false;
         }
         $dispatcher->trigger('onContentBeforeSave', array('com_content.article', &$table, $isNew));
     } else {
         if ($full) {
             //$state = isset($config['state']) ? $config['state'] : $state;
             // change the state in the CB records as well if coming from article settings
             //if(isset($config['state'])){
             //    $db->setQuery("Update #__contentbuilder_records Set `published` = ".( intval($config['state'])  == 1 ? 1 : 0 )." Where reference_id = ".$db->Quote($form['reference_id'])." And record_id = " . $db->Quote($record_id));
             //    $db->query();
             //}
             // limited
             $alias = isset($config['alias']) ? $config['alias'] : $alias;
             // limited
             $form['default_category'] = isset($config['catid']) ? $config['catid'] : $form['default_category'];
             // limited
             $form['default_section'] = isset($config['sectionid']) ? $config['sectionid'] : $form['default_section'];
             // limited
             $access = isset($config['details']) && isset($config['details']['access']) ? $config['details']['access'] : $access;
             // limited
             $created_by_alias = isset($config['details']) && isset($config['details']['created_by_alias']) ? $config['details']['created_by_alias'] : '';
             // limited
             $ordering = isset($config['ordering']) && isset($config['ordering']) ? intval($config['ordering']) : 0;
             if ($form['article_record_impact_publish'] && isset($config['details']) && isset($config['details']['publish_up']) && $config['details']['publish_up'] != $publish_up) {
                 if (version_compare($version->getShortVersion(), '3.0', '>=')) {
                     $___now = $_now->toSql();
                 } else {
                     $___now = $_now->toMySQL();
                 }
                 $db->setQuery("Update #__contentbuilder_records Set " . (strtotime($config['details']['publish_up'] == '0000-00-00 00:00:00' ? '1976-03-07 22:10:00' : $config['details']['publish_up']) >= strtotime($___now) ? 'published = 0,' : '') . " publish_up = " . $db->Quote($config['details']['publish_up']) . ", is_future = 1 Where `type` = " . $db->Quote($form['type']) . " And reference_id = " . $db->Quote($form['reference_id']) . " And record_id = " . $db->Quote($record_id));
                 $db->query();
             }
             // limited
             $publish_up = isset($config['details']) && isset($config['details']['publish_up']) ? $config['details']['publish_up'] == JText::_('Never') ? '0000-00-00 00:00:00' : $config['details']['publish_up'] : $publish_up;
             if ($form['article_record_impact_publish'] && isset($config['details']) && isset($config['details']['publish_down']) && $config['details']['publish_down'] != $publish_down) {
                 if (version_compare($version->getShortVersion(), '3.0', '>=')) {
                     $___now = $_now->toSql();
                 } else {
                     $___now = $_now->toMySQL();
                 }
                 $db->setQuery("Update #__contentbuilder_records Set " . (strtotime($config['details']['publish_down'] == '0000-00-00 00:00:00' ? '1976-03-07 22:10:00' : $config['details']['publish_down']) <= strtotime($___now) ? 'published = 0,' : '') . " publish_down = " . $db->Quote($config['details']['publish_down']) . " Where `type` = " . $db->Quote($form['type']) . " And reference_id = " . $db->Quote($form['reference_id']) . " And record_id = " . $db->Quote($record_id));
                 $db->query();
             }
             // limited
             $publish_down = isset($config['details']) && isset($config['details']['publish_down']) ? $config['details']['publish_down'] == JText::_('Never') ? '0000-00-00 00:00:00' : $config['details']['publish_down'] : $publish_down;
             // limited
             $metakey = isset($config['meta']) && isset($config['meta']['keywords']) ? $config['meta']['keywords'] : '';
             // limited
             $metadesc = isset($config['meta']) && isset($config['meta']['description']) ? $config['meta']['description'] : '';
             $robots = '';
             $author = '';
             $rights = '';
             // an exception regarding limited options for language
             if (!isset($config['params'])) {
                 $ex = explode('-', $language);
                 $sef = '';
                 if (count($ex)) {
                     $sef = strtolower($ex[0]);
                 }
                 if ($form['article_record_impact_language']) {
                     $db->setQuery("Update #__contentbuilder_records Set sef = " . $db->Quote($sef) . ", lang_code = " . $db->Quote($language) . " Where `type` = " . $db->Quote($form['type']) . " And reference_id = " . $db->Quote($form['reference_id']) . " And record_id = " . $db->Quote($record_id));
                     $db->query();
                 }
                 $registry = new JRegistry();
                 $attr = array('language' => $language);
                 $registry->loadArray($attr);
                 $attribs = (string) $registry->toString();
             }
             if (!$limited_options) {
                 // FULL
                 $created_by = isset($config['details']) && isset($config['details']['created_by']) ? $config['details']['created_by'] : 0;
                 // FULL
                 $created_article = isset($config['details']) && isset($config['details']['created']) ? $config['details']['created'] == JText::_('Never') ? '0000-00-00 00:00:00' : $config['details']['created'] : null;
                 // FULL
                 if (isset($config['params']) && is_array($config['params'])) {
                     if (isset($config['params']['language'])) {
                         if ($form['article_record_impact_language'] && $config['params']['language'] != $language) {
                             $ex = explode('-', $config['params']['language']);
                             $sef = '';
                             if (count($ex)) {
                                 $sef = strtolower($ex[0]);
                             }
                             $db->setQuery("Update #__contentbuilder_records Set sef = " . $db->Quote($sef) . ", lang_code = " . $db->Quote($config['params']['language']) . " Where `type` = " . $db->Quote($form['type']) . " And reference_id = " . $db->Quote($form['reference_id']) . " And record_id = " . $db->Quote($record_id));
                             $db->query();
                         } else {
                             $config['params']['language'] = $language;
                         }
                     }
                     $registry = new JRegistry();
                     $registry->loadArray($config['params']);
                     $attribs = (string) $registry->toString();
                 }
                 // FULL
                 if (isset($config['meta']) && is_array($config['meta'])) {
                     if (isset($config['meta']['robots'])) {
                         $robots = $config['meta']['robots'];
                     }
                     if (isset($config['meta']['author'])) {
                         $author = $config['meta']['author'];
                     }
                     if (isset($config['meta']['rights'])) {
                         $rights = $config['meta']['rights'];
                     }
                     $registry = new JRegistry();
                     $registry->loadArray($config['meta']);
                     $meta = (string) $registry->toString();
                 }
             }
             $db->setQuery("Update #__contentbuilder_records Set robots = " . $db->Quote($robots) . ", author = " . $db->Quote($author) . ", rights = " . $db->Quote($rights) . ", xreference = '', metakey = " . $db->Quote($metakey) . ", metadesc = " . $db->Quote($metadesc) . " Where `type` = " . $db->Quote($form['type']) . " And reference_id = " . $db->Quote($form['reference_id']) . " And record_id = " . $db->Quote($record_id));
             $db->query();
             $dispatcher = JDispatcher::getInstance();
             $isNew = true;
             $dispatcher = JDispatcher::getInstance();
             $table = JTable::getInstance('content');
             $isNew = true;
             if ($article > 0) {
                 $table->load($article);
                 $isNew = false;
             }
             $dispatcher->trigger('onBeforeContentSave', array(&$table, $isNew));
         }
     }
     $created_by = $created_by ? $created_by : $metadata->created_id;
     $date = JFactory::getDate();
     if (version_compare($version->getShortVersion(), '3.0', '>=')) {
         $created = $date->toSql();
     } else {
         $created = $date->toMySQL();
     }
     $created = $created_article ? $created_article : ($metadata->created ? $metadata->created : $created);
     if ($created && strlen(trim($created)) <= 10) {
         $created .= ' 00:00:00';
     }
     if (!$publish_up || $publish_up == '0000-00-00 00:00:00') {
         $publish_up = $created;
     }
     if (!$publish_down && !$article) {
         $publish_down = '0000-00-00 00:00:00';
     }
     $alias = $alias ? self::stringURLUnicodeSlug($alias) : self::stringURLUnicodeSlug($label);
     if (trim(str_replace('-', '', $alias)) == '') {
         $datenow = JFactory::getDate();
         if (version_compare($version->getShortVersion(), '3.0', '>=')) {
             $alias = $datenow->format("%Y-%m-%d-%H-%M-%S");
         } else {
             $alias = $datenow->toFormat("%Y-%m-%d-%H-%M-%S");
         }
     }
     // not existing, create
     if (!$article) {
         $db->setQuery("Insert Into \n                    #__content \n                        (\n                         `title`,\n                         `alias`,\n                         `introtext`,\n                         `fulltext`,\n                         `state`,\n                         " . ($is15 ? "`sectionid`," : '') . "\n                         `catid`,\n                         `created`,\n                         `created_by`,\n                         `modified`,\n                         `modified_by`,\n                         `checked_out`,\n                         `checked_out_time`,\n                         `publish_up`,\n                         `publish_down`,\n                         `attribs`,\n                         `version`,\n                         `metakey`,\n                         `metadesc`,\n                         `metadata`,\n                         `access`,\n                         `created_by_alias`,\n                         `ordering`\n                         " . (!$is15 ? ',featured' : '') . "\n                         " . (!$is15 ? ',language' : '') . "\n                         " . (!$is15 ? ',xreference' : '') . "\n                        ) \n                    Values \n                        (\n                          " . $db->Quote($label) . ",\n                          " . $db->Quote($alias) . ",\n                          " . $db->Quote($introtext) . ",\n                          " . $db->Quote($fulltext) . ",\n                          " . $db->Quote($state) . ",\n                          " . ($is15 ? intval($form['default_section']) . "," : '') . "\n                          " . intval($form['default_category']) . ",\n                          " . $db->Quote($created) . ",\n                          " . $db->Quote($created_by ? $created_by : JFactory::getUser()->get('id', 0)) . ",\n                          '0000-00-00 00:00:00',\n                          '0',\n                          '0',\n                          '0000-00-00 00:00:00',\n                          " . $db->Quote($publish_up) . ",\n                          " . $db->Quote($publish_down) . ",\n                          " . $db->Quote($attribs) . ",\n                          '1',\n                          " . $db->Quote($metakey) . ",\n                          " . $db->Quote($metadesc) . ",\n                          " . $db->Quote($meta) . ",\n                          " . $db->Quote($access) . ",\n                          " . $db->Quote($created_by_alias) . ",\n                          " . $db->Quote($ordering) . "\n                          " . (!$is15 ? ',' . $db->Quote($featured) : '') . "\n                          " . (!$is15 ? ',' . $db->Quote($language) : '') . "\n                          " . (!$is15 ? ',' . $db->Quote(is_array($config) && isset($config['metadata']) && is_array($config['metadata']) && isset($config['metadata']['xreference']) ? $config['metadata']['xreference'] : '') : '') . "\n                        )\n            ");
         $db->query();
         $article = $db->insertid();
         $datenow = JFactory::getDate();
         if (version_compare($version->getShortVersion(), '3.0', '>=')) {
             $___datenow = $datenow->toSql();
         } else {
             $___datenow = $datenow->toMySQL();
         }
         $db->setQuery("Insert Into #__contentbuilder_articles (`type`,`reference_id`,`last_update`,`article_id`,`record_id`,`form_id`) Values (" . $db->Quote($form['type']) . "," . $db->Quote($form['reference_id']) . "," . $db->Quote($___datenow) . ",{$article}," . $db->Quote($record_id) . "," . intval($contentbuilder_form_id) . ")");
         $db->query();
         $db->setQuery("Update #__content Set introtext = concat('<div style=\\'display:none;\\'><!--(cbArticleId:{$article})--></div>', introtext) Where id = {$article}");
         $db->query();
         // existing, update
     } else {
         $datenow = JFactory::getDate();
         if (version_compare($version->getShortVersion(), '3.0', '>=')) {
             $___datenow = $datenow->toSql();
         } else {
             $___datenow = $datenow->toMySQL();
         }
         $modified = $metadata->modified ? $metadata->modified : $___datenow;
         $modified_by = $metadata->modified_id ? $metadata->modified_id : JFactory::getUser()->get('id', 0);
         if ($full) {
             $db->setQuery("Update \n                        #__content \n                            Set\n                             `title` = " . $db->Quote($label) . ",\n                             `alias` = " . $db->Quote($alias) . ",\n                             `introtext` = " . $db->Quote('<div style=\'display:none;\'><!--(cbArticleId:' . $article . ')--></div>' . $introtext) . ",\n                             `fulltext` = " . $db->Quote($fulltext . '<div style=\'display:none;\'><!--(cbArticleId:' . $article . ')--></div>') . ",\n                             `state` = " . $db->Quote($state) . ",\n                             " . ($is15 ? "`sectionid` = " . intval($form['default_section']) . "," : '') . "\n                             `catid` = " . intval($form['default_category']) . ",\n                             `modified` = " . $db->Quote($modified) . ",\n                             `modified_by` = " . $db->Quote($modified_by ? $modified_by : JFactory::getUser()->get('id', 0)) . ",\n                             `attribs` = " . $db->Quote($attribs) . ",\n                             `metakey` = " . $db->Quote($metakey) . ",\n                             `metadesc` = " . $db->Quote($metadesc) . ",\n                             `metadata` = " . $db->Quote($meta) . ",\n                             `version` = `version`+1,\n                             `created` = " . $db->Quote($created) . ",\n                             `created_by` = " . $db->Quote($created_by) . ",\n                             `created_by_alias` = " . $db->Quote($created_by_alias) . ",\n                             `publish_up` = " . $db->Quote($publish_up) . ",\n                             `publish_down` = " . $db->Quote($publish_down) . ",\n                             `access` = " . $db->Quote($access) . ",\n                             `ordering` = " . $db->Quote($ordering) . "\n                             " . (!$is15 ? ',featured=' . $db->Quote($featured) : '') . "\n                             " . (!$is15 ? ',language=' . $db->Quote($language) : '') . "\n                             " . (!$is15 ? ',xreference=' . $db->Quote(is_array($config) && isset($config['metadata']) && is_array($config['metadata']) && isset($config['metadata']['xreference']) ? $config['metadata']['xreference'] : '') : '') . "\n                        Where id = {$article}\n                ");
         } else {
             $db->setQuery("Update \n                        #__content \n                            Set\n                             `title` = " . $db->Quote($label) . ",\n                             `alias` = " . $db->Quote($alias) . ",\n                             `introtext` = " . $db->Quote('<div style=\'display:none;\'><!--(cbArticleId:' . $article . ')--></div>' . $introtext) . ",\n                             `fulltext` = " . $db->Quote($fulltext . '<div style=\'display:none;\'><!--(cbArticleId:' . $article . ')--></div>') . ",\n                             `state` = " . $db->Quote($state) . ",\n                             `modified` = " . $db->Quote($modified) . ",\n                             `modified_by` = " . $db->Quote($modified_by ? $modified_by : JFactory::getUser()->get('id', 0)) . ",\n                             `version` = `version`+1\n                             " . (!$is15 ? ',language=' . $db->Quote($language) : '') . "\n                        Where id = {$article}\n                ");
         }
         $db->query();
         // here we do not limit to the form_id, as this is a record change and all articles should be notified
         if (version_compare($version->getShortVersion(), '3.0', '>=')) {
             $___datenow = $datenow->toSql();
         } else {
             $___datenow = $datenow->toMySQL();
         }
         $db->setQuery("Update #__contentbuilder_articles Set `last_update` = " . $db->Quote($___datenow) . " Where `type` = " . $db->Quote($form['type']) . " And form_id = " . intval($contentbuilder_form_id) . " And reference_id = " . $db->Quote($form['reference_id']) . " And record_id = " . $db->Quote($record_id));
         $db->query();
     }
     // Bind the rules.
     /*
             if ($full && !$is15 && $article && isset($config['rules']) && is_array($config['rules'])) {
                 
                 // Cleaning the rules
                 $new = array();
                 foreach($config['rules'] As $key => $the_rules){
                     foreach($the_rules As $key2 => $the_rule){
                         if(!isset($new[$key])){
                             $new[$key] = array();
                         }
                         if(trim($the_rule) != ''){
                             $new[$key][$key2] = intval($the_rule);
                         }
                     }
                 }
                 $config['rules'] = $new;
                 
                 $registry = new JRegistry();
                 $registry->loadArray($config['rules']);
                 $json_rules = (string) $registry;
                 
                 $cat_asset = JTable::getInstance('Asset');
                 $cat_asset->loadByName('com_content.category.' . $form['default_category']);
     
                 $article_asset = JTable::getInstance('Asset');
                 $article_asset->loadByName('com_content.article.' . $article);
                 
                 if($cat_asset->id != $article_asset->parent_id){
                     $article_asset->setLocation($cat_asset->id, 'last-child');
                 }
                 
                 $article_asset->name = 'com_content.article.'.$article;
                 $article_asset->rules = $json_rules;
                 $article_asset->title = $label;
                 
                 $article_asset->store();
                 
                 $db->setQuery("Update #__content Set asset_id = " . $article_asset->id. " Where id = " . $article);
                 $db->query();
             }*/
     if ($article && $is15) {
         $row = JTable::getInstance('content');
         if ($row->load($article)) {
             $row->reorder('sectionid = ' . (int) $form['default_section'] . ' And catid = ' . (int) $form['default_category'] . ' AND state >= 0');
         }
     } else {
         if ($article) {
             $row = JTable::getInstance('content');
             if ($row->load($article)) {
                 $row->reorder('catid = ' . (int) $form['default_category'] . ' AND state >= 0');
             }
         }
     }
     if (!$is15) {
         // cleaning cache
         // Trigger the onContentCleanCache event.
         $conf = JFactory::getConfig();
         $options = array('defaultgroup' => 'com_content', 'cachebase' => $conf->get('cache_path', JPATH_SITE . DS . 'cache'));
         $cache = JFactory::getCache('com_content');
         $cache->clean();
         $cache = JFactory::getCache('com_contentbuilder');
         $cache->clean();
         $dispatcher = JDispatcher::getInstance();
         $dispatcher->trigger('onContentCleanCache', $options);
         //// trigger onContentAfterSave event
         $isNew = true;
         $dispatcher = JDispatcher::getInstance();
         $table = JTable::getInstance('content');
         if ($article > 0) {
             $table->load($article);
             $isNew = false;
         }
         $dispatcher->trigger('onContentAfterSave', array('com_content.article', &$table, $isNew));
     } else {
         //if($article && $full){
         $frontpage = isset($config['frontpage']) ? $config['frontpage'] : $featured;
         if ($frontpage !== null) {
             if (!$frontpage) {
                 $query = 'Delete From #__content_frontpage Where content_id = ' . (int) $article;
                 $db->setQuery($query);
                 $db->query();
             } else {
                 $query = 'Select content_id From #__content_frontpage Where content_id = ' . (int) $article;
                 $db->setQuery($query);
                 if (!$db->loadResult()) {
                     $query = 'Insert Into #__content_frontpage (content_id) Values (' . (int) $article . ')';
                     $db->setQuery($query);
                     $db->query();
                 }
             }
             JTable::addIncludePath(JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_frontpage' . DS . 'tables');
             $fp = JTable::getInstance('frontpage', 'Table');
             $fp->reorder();
         }
         //}
         $cache = JFactory::getCache('com_content');
         $cache->clean();
         $cache = JFactory::getCache('com_contentbuilder');
         $cache->clean();
         $isNew = true;
         $table = JTable::getInstance('content');
         if ($article > 0) {
             $table->load($article);
             $isNew = false;
         }
         $dispatcher = JDispatcher::getInstance();
         $dispatcher->trigger('onAfterContentSave', array(&$table, $isNew));
     }
     JPluginHelper::importPlugin('contentbuilder_listaction');
     $dispatcher = JDispatcher::getInstance();
     $result = $dispatcher->trigger('onAfterArticleCreation', array($contentbuilder_form_id, $record_id, $article));
     $msg = implode('', $result);
     if ($msg) {
         JFactory::getApplication()->enqueueMessage($msg);
     }
     return $article;
 }
예제 #17
0
 /**
  * Gets the currencies
  * @return array List of products
  */
 function getData()
 {
     // Lets load the data if it doesn't already exist
     if (empty($this->_data)) {
         $query = $this->_buildQuery();
         $this->_data = $this->_getList($query, 0, 1);
         if (!count($this->_data)) {
             JError::raiseError(404, JText::_('COM_CONTENTBUILDER_FORM_NOT_FOUND'));
         }
         foreach ($this->_data as $data) {
             if (!$this->frontend && $data->display_in == 0) {
                 JError::raiseError(404, JText::_('COM_CONTENTBUILDER_FORM_NOT_FOUND'));
             } else {
                 if ($this->frontend && $data->display_in == 1) {
                     JError::raiseError(404, JText::_('COM_CONTENTBUILDER_FORM_NOT_FOUND'));
                 }
             }
             if (!count($data->export_xls)) {
                 JError::raiseError(500, JText::_('Not exportable error'));
             }
             $data->form_id = $this->_id;
             if ($data->type && $data->reference_id) {
                 $data->form = contentbuilder::getForm($data->type, $data->reference_id);
                 if (!$data->form->exists) {
                     JError::raiseError(404, JText::_('COM_CONTENTBUILDER_FORM_NOT_FOUND'));
                 }
                 $searchable_elements = contentbuilder::getListSearchableElements($this->_id);
                 $data->labels = $data->form->getElementLabels();
                 if (JFactory::getSession()->get('com_contentbuilder.filter_signal.' . $this->_id, false) && $data->allow_external_filter) {
                     $orders = array();
                     $filters = array();
                     $filters_from = array();
                     $filters_to = array();
                     $calendar_formats = array();
                     $filters = JFactory::getSession()->get('com_contentbuilder.filter.' . $this->_id, array());
                     $filters_from = JFactory::getSession()->get('com_contentbuilder.calendar_filter_from.' . $this->_id, array());
                     $filters_to = JFactory::getSession()->get('com_contentbuilder.calendar_filter_to.' . $this->_id, array());
                     $calendar_formats = JFactory::getSession()->get('com_contentbuilder.calendar_formats.' . $this->_id, array());
                     $filter_keywords = JFactory::getSession()->get('com_contentbuilder.filter_keywords.' . $this->_id, '');
                     $filter_cats = JFactory::getSession()->get('com_contentbuilder.filter_article_categories.' . $this->_id, -1);
                     if ($filter_keywords != '') {
                         $this->setState('formsd_filter', $filter_keywords);
                     }
                     if ($filter_cats != -1) {
                         $this->setState('article_category_filter', $filter_cats);
                     }
                     foreach ($calendar_formats as $col => $calendar_format) {
                         if (isset($filters[$col])) {
                             $filter_exploded = explode('/', $filters[$col]);
                             if (isset($filter_exploded[2])) {
                                 $to_exploded = explode('to', $filter_exploded[2]);
                                 switch (count($to_exploded)) {
                                     case 2:
                                         if ($to_exploded[0] != '') {
                                             $filters[$col] = '@range/date/' . contentbuilder_convert_date(trim($to_exploded[0]), $calendar_format) . ' to ' . contentbuilder_convert_date(trim($to_exploded[1]), $calendar_format);
                                         } else {
                                             $filters[$col] = '@range/date/to ' . contentbuilder_convert_date(trim($to_exploded[1]), $calendar_format);
                                         }
                                         break;
                                     case 1:
                                         $filters[$col] = '@range/date/' . contentbuilder_convert_date(trim($to_exploded[0]), $calendar_format);
                                         break;
                                 }
                                 if (isset($to_exploded[0]) && isset($to_exploded[1]) && trim($to_exploded[0]) == '' && trim($to_exploded[1]) == '') {
                                     $filters[$col] = '';
                                 }
                                 if (isset($to_exploded[0]) && !isset($to_exploded[1]) && trim($to_exploded[0]) == '') {
                                     $filters[$col] = '';
                                 }
                             }
                         }
                     }
                     $new_filters = array();
                     $i = 1;
                     foreach ($filters as $filter_key => $filter) {
                         if ($filter != '') {
                             $orders[$filter_key] = $i;
                             $new_filters[$filter_key] = explode('|', $filter);
                         }
                         $i++;
                     }
                     $this->_menu_filter = $new_filters;
                     $this->_menu_filter_order = $orders;
                 }
                 $ordered_extra_title = '';
                 foreach ($this->_menu_filter_order as $order_key => $order) {
                     if (isset($this->_menu_filter[$order_key])) {
                         // range test
                         $is_range = strstr(strtolower(implode(',', $this->_menu_filter[$order_key])), '@range') !== false;
                         $is_match = strstr(strtolower(implode(',', $this->_menu_filter[$order_key])), '@match') !== false;
                         if ($is_range) {
                             $ex = explode('/', implode(', ', $this->_menu_filter[$order_key]));
                             if (count($ex) == 3) {
                                 $ex2 = explode('to', trim($ex[2]));
                                 $out = '';
                                 $val = $ex2[0];
                                 $val2 = '';
                                 if (isset($ex2[1])) {
                                     $val2 = $ex2[1];
                                 }
                                 if (strtolower(trim($ex[1])) == 'date') {
                                     $val = JHTML::_('date', $ex2[0], JText::_('DATE_FORMAT_LC3'));
                                     if (isset($ex2[1])) {
                                         $val2 = JHTML::_('date', $ex2[1], JText::_('DATE_FORMAT_LC3'));
                                     }
                                 }
                                 if (count($ex2) == 2) {
                                     $out = (trim($ex2[0]) ? JText::_('COM_CONTENTBUILDER_FROM') . ' ' . trim($val) : '') . ' ' . JText::_('COM_CONTENTBUILDER_TO') . ' ' . trim($val2);
                                 } else {
                                     if (count($ex2) > 0) {
                                         $out = JText::_('COM_CONTENTBUILDER_FROM2') . ' ' . trim($val);
                                     }
                                 }
                                 if ($out) {
                                     $this->_menu_filter[$order_key] = $ex;
                                     $ordered_extra_title .= ' &raquo; ' . htmlentities($data->labels[$order_key], ENT_QUOTES, 'UTF-8') . ': ' . htmlentities($out, ENT_QUOTES, 'UTF-8');
                                 }
                             }
                         } else {
                             if ($is_match) {
                                 $ex = explode('/', implode(', ', $this->_menu_filter[$order_key]));
                                 if (count($ex) == 2) {
                                     $ex2 = explode(';', trim($ex[1]));
                                     $out = '';
                                     $size = count($ex2);
                                     $i = 0;
                                     foreach ($ex2 as $val) {
                                         if ($i + 1 < $size) {
                                             $out .= trim($val) . ' ' . JText::_('COM_CONTENTBUILDER_AND') . ' ';
                                         } else {
                                             $out .= trim($val);
                                         }
                                         $i++;
                                     }
                                     if ($out) {
                                         $this->_menu_filter[$order_key] = $ex;
                                         $ordered_extra_title .= ' &raquo; ' . htmlentities($data->labels[$order_key], ENT_QUOTES, 'UTF-8') . ': ' . htmlentities($out, ENT_QUOTES, 'UTF-8');
                                     }
                                 }
                             } else {
                                 $ordered_extra_title .= ' &raquo; ' . htmlentities($data->labels[$order_key], ENT_QUOTES, 'UTF-8') . ': ' . htmlentities(implode(', ', $this->_menu_filter[$order_key]), ENT_QUOTES, 'UTF-8');
                             }
                         }
                     }
                 }
                 $order_types = array();
                 $ids = array();
                 foreach ($data->labels as $reference_id => $label) {
                     $ids[] = $this->_db->Quote($reference_id);
                 }
                 if (count($ids)) {
                     $this->_db->setQuery("Select Distinct `id`,`label`, reference_id, `order_type` From #__contentbuilder_elements Where form_id = " . intval($this->_id) . " And reference_id In (" . implode(',', $ids) . ") And published = 1 Order By ordering");
                     $rows = $this->_db->loadAssocList();
                     $ids = array();
                     foreach ($rows as $row) {
                         // cleaned up, in desired order
                         $ids[] = $row['reference_id'];
                         $labels[] = $row['label'];
                         $order_types['col' . $row['reference_id']] = $row['order_type'];
                     }
                 }
                 $data->visible_cols = $ids;
                 $data->visible_labels = $labels;
                 $act_as_registration = array();
                 if ($data->act_as_registration && $data->registration_username_field && $data->registration_name_field && $data->registration_email_field && $data->registration_email_repeat_field && $data->registration_password_field && $data->registration_password_repeat_field) {
                     $act_as_registration[$data->registration_username_field] = 'registration_username_field';
                     $act_as_registration[$data->registration_name_field] = 'registration_name_field';
                     $act_as_registration[$data->registration_email_field] = 'registration_email_field';
                 }
                 $data->items = $data->form->getListRecords($ids, $this->getState('formsd_filter'), $searchable_elements, 0, 0, $this->getState('formsd_filter_order'), $order_types, $this->getState('formsd_filter_order_Dir'), 0, $data->published_only, $this->frontend && $data->own_only_fe ? JFactory::getUser()->get('id', 0) : -1, $this->getState('formsd_filter_state'), $this->getState('formsd_filter_publish'), $data->initial_sort_order == -1 ? -1 : 'col' . $data->initial_sort_order, $data->initial_sort_order2 == -1 ? -1 : 'col' . $data->initial_sort_order2, $data->initial_sort_order3 == -1 ? -1 : 'col' . $data->initial_sort_order3, $this->_menu_filter, $this->frontend ? $data->show_all_languages_fe : true, $this->getState('formsd_filter_language'), $act_as_registration, $data, $this->getState('article_category_filter'));
             }
             return $data;
         }
     }
     return null;
 }
예제 #18
0
 function getData()
 {
     jimport('joomla.version');
     $version = new JVersion();
     switch ($this->_subject) {
         case 'get_unique_values':
             if ($this->frontend) {
                 if (!contentbuilder::authorizeFe('listaccess')) {
                     return Zend_Json::encode($a = array('code' => 1, 'msg' => JText::_('COM_CONTENTBUILDER_PERMISSIONS_VIEW_NOT_ALLOWED')));
                 }
             } else {
                 if (!contentbuilder::authorize('listaccess')) {
                     return Zend_Json::encode($a = array('code' => 1, 'msg' => JText::_('COM_CONTENTBUILDER_PERMISSIONS_VIEW_NOT_ALLOWED')));
                 }
             }
             $this->_db->setQuery("Select `type`, `reference_id`, `rating_slots` From #__contentbuilder_forms Where id = " . $this->_id);
             $result = $this->_db->loadAssoc();
             $form = contentbuilder::getForm($result['type'], $result['reference_id']);
             if (!$form || !$form->exists) {
                 return Zend_Json::encode($a = array('code' => 2, 'msg' => JText::_('COM_CONTENTBUILDER_FORM_ERROR')));
             }
             $values = $form->getUniqueValues(JRequest::getCmd('field_reference_id', ''), JRequest::getCmd('where_field', ''), JRequest::getVar('where', ''));
             return Zend_Json::encode($a = array('code' => 0, 'field_reference_id' => JRequest::getCmd('field_reference_id', ''), 'msg' => $values));
             break;
         case 'rating':
             if ($this->frontend) {
                 if (!contentbuilder::authorizeFe('rating')) {
                     return Zend_Json::encode($a = array('code' => 1, 'msg' => JText::_('COM_CONTENTBUILDER_RATING_NOT_ALLOWED')));
                 }
             } else {
                 if (!contentbuilder::authorize('rating')) {
                     return Zend_Json::encode($a = array('code' => 1, 'msg' => JText::_('COM_CONTENTBUILDER_RATING_NOT_ALLOWED')));
                 }
             }
             $this->_db->setQuery("Select `type`, `reference_id`, `rating_slots` From #__contentbuilder_forms Where id = " . $this->_id);
             $result = $this->_db->loadAssoc();
             $form = contentbuilder::getForm($result['type'], $result['reference_id']);
             if (!$form || !$form->exists) {
                 return Zend_Json::encode($a = array('code' => 2, 'msg' => JText::_('COM_CONTENTBUILDER_FORM_ERROR')));
             }
             $rating = 0;
             switch ($result['rating_slots']) {
                 case 1:
                     $rating = 1;
                     //$rating = 5;
                     break;
                 case 2:
                     $rating = JRequest::getInt('rate', 5);
                     if ($rating > 5) {
                         $rating = 5;
                     }
                     if ($rating < 4) {
                         $rating = 0;
                     }
                     //if($rating == 2) $rating = 5;
                     break;
                 case 3:
                     $rating = JRequest::getInt('rate', 3);
                     if ($rating > 3) {
                         $rating = 3;
                     }
                     if ($rating < 1) {
                         $rating = 1;
                     }
                     //if($rating == 2) $rating = 3;
                     //if($rating == 3) $rating = 5;
                     break;
                 case 4:
                     $rating = JRequest::getInt('rate', 4);
                     if ($rating > 4) {
                         $rating = 4;
                     }
                     if ($rating < 1) {
                         $rating = 1;
                     }
                     //if($rating == 3) $rating = 4;
                     //if($rating == 4) $rating = 5;
                     break;
                 case 5:
                     $rating = JRequest::getInt('rate', 5);
                     if ($rating > 5) {
                         $rating = 5;
                     }
                     if ($rating < 1) {
                         $rating = 1;
                     }
                     break;
             }
             if ($result['rating_slots'] == 2 || $rating) {
                 $_now = JFactory::getDate();
                 // clear rating cache
                 if (version_compare($version->getShortVersion(), '3.0', '<')) {
                     $___now = $_now->toMySQL();
                 } else {
                     $___now = $_now->toSql();
                 }
                 $this->_db->setQuery("Delete From #__contentbuilder_rating_cache Where Datediff('" . $___now . "', `date`) >= 1");
                 $this->_db->query();
                 // test if already voted
                 $this->_db->setQuery("Select `form_id` From #__contentbuilder_rating_cache Where `record_id` = " . $this->_db->Quote(JRequest::getCmd('record_id', '')) . " And `form_id` = " . $this->_id . " And `ip` = " . $this->_db->Quote($_SERVER['REMOTE_ADDR']));
                 $cached = $this->_db->loadResult();
                 $rated = JFactory::getSession()->get('rated' . $this->_id . JRequest::getCmd('record_id', ''), false, 'com_contentbuilder.rating');
                 if ($rated || $cached) {
                     return Zend_Json::encode($a = array('code' => 1, 'msg' => JText::_('COM_CONTENTBUILDER_RATED_ALREADY')));
                 } else {
                     JFactory::getSession()->set('rated' . $this->_id . JRequest::getCmd('record_id', ''), true, 'com_contentbuilder.rating');
                 }
                 // adding vote
                 $this->_db->setQuery("Update #__contentbuilder_records Set rating_count = rating_count + 1, rating_sum = rating_sum + " . $rating . ", lastip = " . $this->_db->Quote($_SERVER['REMOTE_ADDR']) . " Where `type` = " . $this->_db->Quote($result['type']) . " And `reference_id` = " . $this->_db->Quote($result['reference_id']) . " And `record_id` = " . $this->_db->Quote(JRequest::getCmd('record_id', '')));
                 $this->_db->query();
                 // adding vote to cache
                 if (version_compare($version->getShortVersion(), '3.0', '<')) {
                     $___now = $_now->toMySQL();
                 } else {
                     $___now = $_now->toSql();
                 }
                 $this->_db->setQuery("Insert Into #__contentbuilder_rating_cache (`record_id`,`form_id`,`ip`,`date`) Values (" . $this->_db->Quote(JRequest::getCmd('record_id', '')) . ", " . $this->_id . "," . $this->_db->Quote($_SERVER['REMOTE_ADDR']) . ",'" . $___now . "')");
                 $this->_db->query();
                 // updating article's votes if there is an article bound to the record & view
                 $this->_db->setQuery("Select a.article_id From #__contentbuilder_articles As a, #__content As c Where c.id = a.article_id And (c.state = 1 Or c.state = 0) And a.form_id = " . $this->_id . " And a.record_id = " . $this->_db->Quote(JRequest::getCmd('record_id', '')));
                 $article_id = $this->_db->loadResult();
                 if ($article_id) {
                     $this->_db->setQuery("Select content_id From #__content_rating Where content_id = " . $article_id);
                     $exists = $this->_db->loadResult();
                     if ($exists) {
                         $this->_db->setQuery("\n                                Update \n                                    #__content_rating As cr, \n                                    #__contentbuilder_records As cbr, \n                                    #__contentbuilder_articles As cba\n                                Set\n                                    cr.rating_count = cbr.rating_count,\n                                    cr.rating_sum = cbr.rating_sum,\n                                    cr.lastip = cbr.lastip\n                                Where\n                                    cbr.record_id = " . $this->_db->Quote(JRequest::getCmd('record_id', '')) . "\n                                And\n                                    cbr.record_id = cba.record_id\n                                And\n                                    cbr.reference_id = " . $this->_db->Quote($result['reference_id']) . "\n                                And\n                                    cbr.`type` = " . $this->_db->Quote($result['type']) . " \n                                And \n                                    cba.form_id = " . $this->_id . "\n                                And\n                                    cr.content_id = cba.article_id\n                            ");
                         $this->_db->query();
                     } else {
                         $this->_db->setQuery("\n                                Insert Into \n                                    #__content_rating \n                                (\n                                    content_id,\n                                    rating_sum,\n                                    rating_count,\n                                    lastip\n                                ) \n                                Values\n                                (\n                                    {$article_id},\n                                    {$rating},\n                                    1,\n                                    " . $this->_db->Quote($_SERVER['REMOTE_ADDR']) . "\n                                )");
                         $this->_db->query();
                     }
                 }
             }
             return Zend_Json::encode($a = array('code' => 0, 'msg' => JText::_('COM_CONTENTBUILDER_THANK_YOU_FOR_RATING')));
             break;
     }
     return null;
 }