Ejemplo n.º 1
0
 function display($tpl = null)
 {
     JHTML::_('behavior.tooltip');
     JRequest::setVar('hidemainmenu', 1);
     $model =& $this->getModel();
     $userGroup = $model->getData();
     JFilterOutput::objectHTMLSafe($userGroup);
     $this->assignRef('row', $userGroup);
     $form = new JParameter('', JPATH_COMPONENT . DS . 'models' . DS . 'userGroup.xml');
     $form->loadINI($userGroup->permissions);
     $this->assignRef('form', $form);
     $appliedCategories = $form->get('categories');
     $this->assignRef('categories', $appliedCategories);
     $lists = array();
     require_once JPATH_COMPONENT . DS . 'models' . DS . 'categories.php';
     $categoriesModel = new K2ModelCategories();
     $categories = $categoriesModel->categoriesTree(NULL, true);
     $categories_options = @array_merge($categories_option, $categories);
     $lists['categories'] = JHTML::_('select.genericlist', $categories, 'params[categories][]', 'multiple="multiple" style="width:90%;" size="15"', 'value', 'text', $appliedCategories);
     $lists['inheritance'] = JHTML::_('select.booleanlist', 'params[inheritance]', NULL, $form->get('inheritance'));
     $this->assignRef('lists', $lists);
     JRequest::getInt('cid') ? $title = JText::_('Edit user group') : ($title = JText::_('Add user group'));
     JToolBarHelper::title(JText::_($title));
     JToolBarHelper::save();
     JToolBarHelper::apply();
     JToolBarHelper::cancel();
     parent::display($tpl);
 }
Ejemplo n.º 2
0
 function display($tpl = null)
 {
     JRequest::setVar('hidemainmenu', 1);
     $model =& $this->getModel();
     $category = $model->getData();
     JFilterOutput::objectHTMLSafe($category);
     if (!$category->id) {
         $category->published = 1;
     }
     $this->assignRef('row', $category);
     $wysiwyg =& JFactory::getEditor();
     $editor = $wysiwyg->display('description', $category->description, '100%', '250', '40', '5', array('pagebreak', 'readmore'));
     $this->assignRef('editor', $editor);
     $lists = array();
     $lists['published'] = JHTML::_('select.booleanlist', 'published', 'class="inputbox"', $category->published);
     $lists['access'] = JHTML::_('list.accesslevel', $category);
     $query = 'SELECT ordering AS value, name AS text FROM #__k2_categories ORDER BY ordering';
     $lists['ordering'] = JHTML::_('list.specificordering', $category, $category->id, $query);
     $categories[] = JHTML::_('select.option', '0', JText::_('-- None --'));
     require_once JPATH_COMPONENT . DS . 'models' . DS . 'categories.php';
     $categoriesModel = new K2ModelCategories();
     $tree = $categoriesModel->categoriesTree($category);
     $categories = array_merge($categories, $tree);
     $lists['parent'] = JHTML::_('select.genericlist', $categories, 'parent', 'class="inputbox"', 'value', 'text', $category->parent);
     require_once JPATH_COMPONENT . DS . 'models' . DS . 'extrafields.php';
     $extraFieldsModel = new K2ModelExtraFields();
     $groups = $extraFieldsModel->getGroups();
     $group[] = JHTML::_('select.option', '0', JText::_('-- None --'), 'id', 'name');
     $group = array_merge($group, $groups);
     $lists['extraFieldsGroup'] = JHTML::_('select.genericlist', $group, 'extraFieldsGroup', 'class="inputbox" size="1" ', 'id', 'name', $category->extraFieldsGroup);
     JPluginHelper::importPlugin('k2');
     $dispatcher =& JDispatcher::getInstance();
     $K2Plugins = $dispatcher->trigger('onRenderAdminForm', array(&$category, 'category'));
     $this->assignRef('K2Plugins', $K2Plugins);
     $params =& JComponentHelper::getParams('com_k2');
     $this->assignRef('params', $params);
     $form = new JParameter('', JPATH_COMPONENT . DS . 'models' . DS . 'category.xml');
     $form->loadINI($category->params);
     $this->assignRef('form', $form);
     $categories[0] = JHTML::_('select.option', '0', JText::_('-- None --'));
     $lists['inheritFrom'] = JHTML::_('select.genericlist', $categories, 'params[inheritFrom]', 'class="inputbox"', 'value', 'text', $form->get('inheritFrom'));
     $this->assignRef('lists', $lists);
     JRequest::getInt('cid') ? $title = JText::_('Edit Category') : ($title = JText::_('Add Category'));
     JToolBarHelper::title($title, 'k2.png');
     JToolBarHelper::save();
     JToolBarHelper::custom('saveAndNew', 'save.png', 'save_f2.png', 'Save & New', false);
     JToolBarHelper::apply();
     JToolBarHelper::cancel();
     parent::display($tpl);
 }
Ejemplo n.º 3
0
 function display($tpl = null)
 {
     $app = JFactory::getApplication();
     $user = JFactory::getUser();
     JHTML::_('behavior.tooltip');
     //get vars
     $cid = JRequest::getVar('cid');
     $field_type = JRequest::getVar('field_type', 0);
     //Get data from the model
     $model = $this->getModel();
     if (FLEXI_J16GE) {
         $form = $this->get('Form');
     } else {
         $row =& $this->get('Field');
         //Import File system
         jimport('joomla.filesystem.file');
         // Create the form
         $pluginpath = JPATH_PLUGINS . DS . 'flexicontent_fields' . DS . $field_type . '.xml';
         if (JFile::exists($pluginpath)) {
             $form = new JParameter('', $pluginpath);
         } else {
             $form = new JParameter('', JPATH_PLUGINS . DS . 'flexicontent_fields' . DS . 'core.xml');
         }
         $form->loadINI($row->attribs);
     }
     $isnew = FLEXI_J16GE ? !$form->getValue('id') : !$row->id;
     // fail if checked out not by 'me'
     if (!$isnew) {
         if ($model->isCheckedOut($user->get('id'))) {
             JError::raiseWarning('SOME_ERROR_CODE', $row->name . ' ' . JText::_('FLEXI_EDITED_BY_ANOTHER_ADMIN'));
             $app->redirect('index.php?option=com_flexicontent&view=fields');
         }
     }
     if ($field_type) {
         if (!FLEXI_J16GE) {
             echo $form->render('params', 'group-' . $field_type);
         } else {
             foreach ($form->getFieldset('group-' . $field_type) as $field) {
                 echo '<fieldset class="panelform">' . $field->label . $field->input . '</fieldset>' . "\n";
             }
         }
     } else {
         echo "<br /><span style=\"padding-left:25px;\"'>" . JText::_('FLEXI_APPLY_TO_SEE_THE_PARAMETERS') . "</span><br /><br />";
     }
     //parent::display($tpl);
 }
Ejemplo n.º 4
0
 function display($tpl = null)
 {
     JHTML::_('behavior.tooltip');
     JRequest::setVar('hidemainmenu', 1);
     $model = $this->getModel();
     $userGroup = $model->getData();
     if (K2_JVERSION == '15') {
         JFilterOutput::objectHTMLSafe($userGroup);
     } else {
         JFilterOutput::objectHTMLSafe($userGroup, ENT_QUOTES, 'permissions');
     }
     $this->assignRef('row', $userGroup);
     if (K2_JVERSION == '15') {
         $form = new JParameter('', JPATH_COMPONENT . DS . 'models' . DS . 'usergroup.xml');
         $form->loadINI($userGroup->permissions);
         $appliedCategories = $form->get('categories');
         $inheritance = $form->get('inheritance');
     } else {
         jimport('joomla.form.form');
         $form = JForm::getInstance('permissions', JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'usergroup.xml');
         $values = array('params' => json_decode($userGroup->permissions));
         $form->bind($values);
         $inheritance = isset($values['params']->inheritance) ? $values['params']->inheritance : 0;
         $appliedCategories = isset($values['params']->categories) ? $values['params']->categories : '';
     }
     $this->assignRef('form', $form);
     $this->assignRef('categories', $appliedCategories);
     $lists = array();
     require_once JPATH_ADMINISTRATOR . '/components/com_k2/models/categories.php';
     $categoriesModel = K2Model::getInstance('Categories', 'K2Model');
     $categories = $categoriesModel->categoriesTree(NULL, true);
     $categories_options = @array_merge($categories_option, $categories);
     $lists['categories'] = JHTML::_('select.genericlist', $categories, 'params[categories][]', 'multiple="multiple" size="15"', 'value', 'text', $appliedCategories);
     $lists['inheritance'] = JHTML::_('select.booleanlist', 'params[inheritance]', NULL, $inheritance);
     $this->assignRef('lists', $lists);
     JRequest::getInt('cid') ? $title = JText::_('K2_EDIT_USER_GROUP') : ($title = JText::_('K2_ADD_USER_GROUP'));
     JToolBarHelper::title($title, 'k2.png');
     JToolBarHelper::save();
     JToolBarHelper::apply();
     JToolBarHelper::cancel();
     parent::display($tpl);
 }
Ejemplo n.º 5
0
 /**
  * Renders a form using an xml path
  *
  * @param  array $config
  * @return void
  */
 public function getParameters($config = array())
 {
     $config = new KConfig($config);
     $config->append(array('data' => array(), 'element_paths' => array(dirname(__FILE__) . '/forms')));
     $content = file_exists($config->path) ? file_get_contents($config->path) : '';
     $paths = array();
     //replace all the addpath="{KServiceIdentifier}" with real path
     if (preg_match_all('/addpath="([^"]+)"/', $content, $paths)) {
         $replaces = array();
         foreach ($paths[1] as $path) {
             if (strpos($path, '.')) {
                 $replaces[] = str_replace(JPATH_ROOT . '/', '', dirname(KLoader::path($path . '.dummy')));
             } else {
                 $replaces[] = $path;
             }
         }
         $content = str_replace($paths[1], $replaces, $content);
     }
     $xml =& JFactory::getXMLParser('Simple');
     $parameter = new JParameter('');
     $data = KConfig::unbox($config->data);
     if ($data instanceof JParameter) {
         $data = $data->toArray();
     }
     if (is_array($data)) {
         $parameter->loadArray($data);
     } else {
         $parameter->loadINI($data);
     }
     $parameter->template_data = $config->template_data;
     foreach ($config->element_paths as $path) {
         $parameter->addElementPath($path);
     }
     if ($xml->loadString($content)) {
         if ($params =& $xml->document->params) {
             foreach ($params as $param) {
                 $parameter->setXML($param);
             }
         }
     }
     return $parameter;
 }
Ejemplo n.º 6
0
 /**
  * Edit a connection
  */
 function edit()
 {
     $user =& JFactory::getUser();
     $db =& JFactory::getDBO();
     $row =& JTable::getInstance('Group', 'FabrikTable');
     if ($this->_task == 'edit') {
         $cid = JRequest::getVar('cid', array(0), 'method', 'array');
         $cid = array((int) $cid[0]);
     } else {
         $cid = array(0);
     }
     $row->load($cid[0]);
     if ($cid) {
         $row->checkout($user->get('id'));
     }
     $model =& $this->getModel('Group');
     // Create the form
     $form = new JParameter('', JPATH_COMPONENT . DS . 'models' . DS . 'group.xml');
     $form->loadINI($row->attribs);
     require_once JPATH_COMPONENT . DS . 'views' . DS . 'group.php';
     FabrikViewGroup::edit($row, $form);
 }
Ejemplo n.º 7
0
 function display($tpl = null)
 {
     $mainframe = JFactory::getApplication();
     $db = JFactory::getDBO();
     $view = JRequest::getCmd('view');
     jimport('joomla.filesystem.file');
     jimport('joomla.html.pane');
     JHTML::_('behavior.keepalive');
     JHTML::_('behavior.modal');
     JRequest::setVar('hidemainmenu', 1);
     $document = JFactory::getDocument();
     $document->addScript(JURI::root(true) . '/media/k2/assets/js/nicEdit.js?v=2.6.8');
     //var K2SitePath = '".JURI::root(true)."/';
     $js = "\n\t\t\t\t\tvar K2BasePath = '" . JURI::base(true) . "/';\n\t\t\t\t\tvar K2Language = [\n\t\t\t\t\t\t'" . JText::_('K2_REMOVE', true) . "',\n\t\t\t\t\t\t'" . JText::_('K2_LINK_TITLE_OPTIONAL', true) . "',\n\t\t\t\t\t\t'" . JText::_('K2_LINK_TITLE_ATTRIBUTE_OPTIONAL', true) . "',\n\t\t\t\t\t\t'" . JText::_('K2_ARE_YOU_SURE', true) . "',\n\t\t\t\t\t\t'" . JText::_('K2_YOU_ARE_NOT_ALLOWED_TO_POST_TO_THIS_CATEGORY', true) . "',\n\t\t\t\t\t\t'" . JText::_('K2_OR_SELECT_A_FILE_ON_THE_SERVER', true) . "'\n\t\t\t\t\t]\n\t\t\t\t";
     $document->addScriptDeclaration($js);
     K2Model::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'models');
     $model = K2Model::getInstance('Item', 'K2Model', array('table_path' => JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables'));
     $item = $model->getData();
     JFilterOutput::objectHTMLSafe($item, ENT_QUOTES, array('video', 'params', 'plugins'));
     $user = JFactory::getUser();
     // Permissions check on frontend
     if ($mainframe->isSite()) {
         JLoader::register('K2HelperPermissions', JPATH_COMPONENT . DS . 'helpers' . DS . 'permissions.php');
         $task = JRequest::getCmd('task');
         if ($task == 'edit' && !K2HelperPermissions::canEditItem($item->created_by, $item->catid)) {
             JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
         }
         if ($task == 'add' && !K2HelperPermissions::canAddItem()) {
             JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
         }
         // Get permissions
         $K2Permissions = K2Permissions::getInstance();
         $this->assignRef('permissions', $K2Permissions->permissions);
         // Build permissions message
         $permissionsLabels = array();
         if ($this->permissions->get('add')) {
             $permissionsLabels[] = JText::_('K2_ADD_ITEMS');
         }
         if ($this->permissions->get('editOwn')) {
             $permissionsLabels[] = JText::_('K2_EDIT_OWN_ITEMS');
         }
         if ($this->permissions->get('editAll')) {
             $permissionsLabels[] = JText::_('K2_EDIT_ANY_ITEM');
         }
         if ($this->permissions->get('publish')) {
             $permissionsLabels[] = JText::_('K2_PUBLISH_ITEMS');
         }
         if ($this->permissions->get('editPublished')) {
             $permissionsLabels[] = JText::_('K2_ALLOW_EDITING_OF_ALREADY_PUBLISHED_ITEMS');
         }
         $permissionsMessage = JText::_('K2_YOU_ARE_ALLOWED_TO') . ' ' . implode(', ', $permissionsLabels);
         $this->assignRef('permissionsMessage', $permissionsMessage);
     }
     if ($item->isCheckedOut($user->get('id'), $item->checked_out)) {
         $message = JText::_('K2_THE_ITEM') . ': ' . $item->title . ' ' . JText::_('K2_IS_CURRENTLY_BEING_EDITED_BY_ANOTHER_ADMINISTRATOR');
         $url = $mainframe->isSite() ? 'index.php?option=com_k2&view=item&id=' . $item->id . '&tmpl=component' : 'index.php?option=com_k2';
         $mainframe->enqueueMessage($message);
         $mainframe->redirect($url);
     }
     if ($item->id) {
         $item->checkout($user->get('id'));
     } else {
         $item->published = 1;
         $item->publish_down = $db->getNullDate();
         $item->modified = $db->getNullDate();
         $date = JFactory::getDate();
         $now = K2_JVERSION == '15' ? $date->toMySQL() : $date->toSql();
         $item->created = $now;
         $item->publish_up = $item->created;
     }
     $lists = array();
     if (version_compare(JVERSION, '1.6.0', 'ge')) {
         $dateFormat = 'Y-m-d H:i:s';
     } else {
         $dateFormat = '%Y-%m-%d %H:%M:%S';
     }
     $created = $item->created;
     $publishUp = $item->publish_up;
     $publishDown = $item->publish_down;
     $created = JHTML::_('date', $item->created, $dateFormat);
     $publishUp = JHTML::_('date', $item->publish_up, $dateFormat);
     if ((int) $item->publish_down) {
         $publishDown = JHTML::_('date', $item->publish_down, $dateFormat);
     } else {
         $publishDown = '';
     }
     // Set up calendars
     $lists['createdCalendar'] = JHTML::_('calendar', $created, 'created', 'created');
     $lists['publish_up'] = JHTML::_('calendar', $publishUp, 'publish_up', 'publish_up');
     $lists['publish_down'] = JHTML::_('calendar', $publishDown, 'publish_down', 'publish_down');
     if ($item->id) {
         $lists['created'] = JHTML::_('date', $item->created, JText::_('DATE_FORMAT_LC2'));
     } else {
         $lists['created'] = JText::_('K2_NEW_DOCUMENT');
     }
     if ($item->modified == $db->getNullDate() || !$item->id) {
         $lists['modified'] = JText::_('K2_NEVER');
     } else {
         $lists['modified'] = JHTML::_('date', $item->modified, JText::_('DATE_FORMAT_LC2'));
     }
     $params = JComponentHelper::getParams('com_k2');
     $wysiwyg = JFactory::getEditor();
     $onSave = '';
     if ($params->get("mergeEditors")) {
         if (JString::strlen($item->fulltext) > 1) {
             $textValue = $item->introtext . "<hr id=\"system-readmore\" />" . $item->fulltext;
         } else {
             $textValue = $item->introtext;
         }
         $text = $wysiwyg->display('text', $textValue, '100%', '400px', '', '');
         $this->assignRef('text', $text);
         if (K2_JVERSION == '30') {
             $onSave = $wysiwyg->save('text');
         }
     } else {
         $introtext = $wysiwyg->display('introtext', $item->introtext, '100%', '400px', '', '', array('readmore'));
         $this->assignRef('introtext', $introtext);
         $fulltext = $wysiwyg->display('fulltext', $item->fulltext, '100%', '400px', '', '', array('readmore'));
         $this->assignRef('fulltext', $fulltext);
         if (K2_JVERSION == '30') {
             $onSave = $wysiwyg->save('introtext');
             $onSave .= $wysiwyg->save('fulltext');
         }
     }
     $document->addScriptDeclaration("function onK2EditorSave(){ " . $onSave . " }");
     $lists['published'] = JHTML::_('select.booleanlist', 'published', 'class="inputbox"', $item->published);
     $lists['featured'] = JHTML::_('select.booleanlist', 'featured', 'class="inputbox"', $item->featured);
     $lists['access'] = version_compare(JVERSION, '3.0', 'ge') ? JHTML::_('access.level', 'access', $item->access) : JHTML::_('list.accesslevel', $item);
     $query = "SELECT ordering AS value, title AS text FROM #__k2_items WHERE catid={$item->catid}";
     $lists['ordering'] = version_compare(JVERSION, '3.0', 'ge') ? NUll : JHTML::_('list.specificordering', $item, $item->id, $query);
     if (!$item->id) {
         $item->catid = $mainframe->getUserStateFromRequest('com_k2itemsfilter_category', 'catid', 0, 'int');
     }
     require_once JPATH_ADMINISTRATOR . '/components/com_k2/models/categories.php';
     $categoriesModel = K2Model::getInstance('Categories', 'K2Model');
     $categories = $categoriesModel->categoriesTree();
     $lists['catid'] = JHTML::_('select.genericlist', $categories, 'catid', 'class="inputbox"', 'value', 'text', $item->catid);
     if (version_compare(JVERSION, '1.6.0', 'ge')) {
         $languages = JHTML::_('contentlanguage.existing', true, true);
         $lists['language'] = JHTML::_('select.genericlist', $languages, 'language', '', 'value', 'text', $item->language);
     }
     $lists['checkSIG'] = $model->checkSIG();
     $lists['checkAllVideos'] = $model->checkAllVideos();
     $remoteVideo = false;
     $providerVideo = false;
     $embedVideo = false;
     if (stristr($item->video, 'remote}') !== false) {
         $remoteVideo = true;
         $options['startOffset'] = 1;
     }
     $providers = $model->getVideoProviders();
     if (count($providers)) {
         foreach ($providers as $provider) {
             $providersOptions[] = JHTML::_('select.option', $provider, ucfirst($provider));
             if (stristr($item->video, "{{$provider}}") !== false) {
                 $providerVideo = true;
                 $options['startOffset'] = 2;
             }
         }
     }
     if (JString::substr($item->video, 0, 1) !== '{') {
         $embedVideo = true;
         $options['startOffset'] = 3;
     }
     $lists['uploadedVideo'] = !$remoteVideo && !$providerVideo && !$embedVideo ? true : false;
     if ($lists['uploadedVideo'] || $item->video == '') {
         $options['startOffset'] = 0;
     }
     $document->addScriptDeclaration("var K2ActiveVideoTab = " . $options['startOffset']);
     $lists['remoteVideo'] = $remoteVideo ? preg_replace('%\\{[a-z0-9-_]*\\}(.*)\\{/[a-z0-9-_]*\\}%i', '\\1', $item->video) : '';
     $lists['remoteVideoType'] = $remoteVideo ? preg_replace('%\\{([a-z0-9-_]*)\\}.*\\{/[a-z0-9-_]*\\}%i', '\\1', $item->video) : '';
     $lists['providerVideo'] = $providerVideo ? preg_replace('%\\{[a-z0-9-_]*\\}(.*)\\{/[a-z0-9-_]*\\}%i', '\\1', $item->video) : '';
     $lists['providerVideoType'] = $providerVideo ? preg_replace('%\\{([a-z0-9-_]*)\\}.*\\{/[a-z0-9-_]*\\}%i', '\\1', $item->video) : '';
     $lists['embedVideo'] = $embedVideo ? $item->video : '';
     if (isset($providersOptions)) {
         $lists['providers'] = JHTML::_('select.genericlist', $providersOptions, 'videoProvider', '', 'value', 'text', $lists['providerVideoType']);
     }
     JPluginHelper::importPlugin('content', 'jw_sigpro');
     JPluginHelper::importPlugin('content', 'jw_allvideos');
     $dispatcher = JDispatcher::getInstance();
     // Detect gallery type
     if (JString::strpos($item->gallery, 'http://')) {
         $item->galleryType = 'flickr';
         $item->galleryValue = JString::substr($item->gallery, 9);
         $item->galleryValue = JString::substr($item->galleryValue, 0, -10);
     } else {
         $item->galleryType = 'server';
         $item->galleryValue = '';
     }
     $params->set('galleries_rootfolder', 'media/k2/galleries');
     $item->text = $item->gallery;
     if (K2_JVERSION == '15') {
         $dispatcher->trigger('onPrepareContent', array(&$item, &$params, null));
     } else {
         $dispatcher->trigger('onContentPrepare', array('com_k2.' . $view, &$item, &$params, null));
     }
     $item->gallery = $item->text;
     if (!$embedVideo) {
         $params->set('vfolder', 'media/k2/videos');
         $params->set('afolder', 'media/k2/audio');
         if (JString::strpos($item->video, 'remote}')) {
             preg_match("#}(.*?){/#s", $item->video, $matches);
             if (JString::substr($matches[1], 0, 7) != 'http://') {
                 $item->video = str_replace($matches[1], JURI::root() . $matches[1], $item->video);
             }
         }
         $item->text = $item->video;
         if (K2_JVERSION == '15') {
             $dispatcher->trigger('onPrepareContent', array(&$item, &$params, null));
         } else {
             $dispatcher->trigger('onContentPrepare', array('com_k2.' . $view, &$item, &$params, null));
         }
         $item->video = $item->text;
     } else {
         // no nothing
     }
     if (isset($item->created_by)) {
         $author = JUser::getInstance($item->created_by);
         $item->author = $author->name;
     } else {
         $item->author = $user->name;
     }
     if (isset($item->modified_by)) {
         $moderator = JUser::getInstance($item->modified_by);
         $item->moderator = $moderator->name;
     }
     if ($item->id) {
         $active = $item->created_by;
     } else {
         $active = $user->id;
     }
     $lists['authors'] = JHTML::_('list.users', 'created_by', $active, false);
     $categories_option[] = JHTML::_('select.option', 0, JText::_('K2_SELECT_CATEGORY'));
     $categories = $categoriesModel->categoriesTree(NUll, true, false);
     if ($mainframe->isSite()) {
         JLoader::register('K2HelperPermissions', JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'helpers' . DS . 'permissions.php');
         if (($task == 'add' || $task == 'edit') && !K2HelperPermissions::canAddToAll()) {
             for ($i = 0; $i < sizeof($categories); $i++) {
                 if (!K2HelperPermissions::canAddItem($categories[$i]->value) && $task == 'add') {
                     $categories[$i]->disable = true;
                 }
                 if (!K2HelperPermissions::canEditItem($item->created_by, $categories[$i]->value) && $task == 'edit') {
                     $categories[$i]->disable = true;
                 }
             }
         }
     }
     $categories_options = @array_merge($categories_option, $categories);
     $lists['categories'] = JHTML::_('select.genericlist', $categories_options, 'catid', '', 'value', 'text', $item->catid);
     JTable::addIncludePath(JPATH_COMPONENT . DS . 'tables');
     $category = JTable::getInstance('K2Category', 'Table');
     $category->load($item->catid);
     $extraFieldModel = K2Model::getInstance('ExtraField', 'K2Model');
     if ($category->id) {
         $extraFields = $extraFieldModel->getExtraFieldsByGroup($category->extraFieldsGroup);
     } else {
         $extraFields = NULL;
     }
     for ($i = 0; $i < sizeof($extraFields); $i++) {
         $extraFields[$i]->element = $extraFieldModel->renderExtraField($extraFields[$i], $item->id);
     }
     if ($item->id) {
         $item->attachments = $model->getAttachments($item->id);
         $rating = $model->getRating();
         if (is_null($rating)) {
             $item->ratingSum = 0;
             $item->ratingCount = 0;
         } else {
             $item->ratingSum = (int) $rating->rating_sum;
             $item->ratingCount = (int) $rating->rating_count;
         }
     } else {
         $item->attachments = NULL;
         $item->ratingSum = 0;
         $item->ratingCount = 0;
     }
     if ($user->gid < 24 && $params->get('lockTags')) {
         $params->set('taggingSystem', 0);
     }
     $tags = $model->getAvailableTags($item->id);
     $lists['tags'] = JHTML::_('select.genericlist', $tags, 'tags', 'multiple="multiple" size="10" ', 'id', 'name');
     if (isset($item->id)) {
         $item->tags = $model->getCurrentTags($item->id);
         $lists['selectedTags'] = JHTML::_('select.genericlist', $item->tags, 'selectedTags[]', 'multiple="multiple" size="10" ', 'id', 'name');
     } else {
         $lists['selectedTags'] = '<select size="10" multiple="multiple" id="selectedTags" name="selectedTags[]"></select>';
     }
     $lists['metadata'] = class_exists('JParameter') ? new JParameter($item->metadata) : new JRegistry($item->metadata);
     $date = JFactory::getDate($item->modified);
     $timestamp = '?t=' . $date->toUnix();
     if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_L.jpg')) {
         $item->image = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $item->id) . '_L.jpg' . $timestamp;
     }
     if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_S.jpg')) {
         $item->thumb = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $item->id) . '_S.jpg' . $timestamp;
     }
     JPluginHelper::importPlugin('k2');
     $dispatcher = JDispatcher::getInstance();
     $K2PluginsItemContent = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'content'));
     $this->assignRef('K2PluginsItemContent', $K2PluginsItemContent);
     $K2PluginsItemImage = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'image'));
     $this->assignRef('K2PluginsItemImage', $K2PluginsItemImage);
     $K2PluginsItemGallery = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'gallery'));
     $this->assignRef('K2PluginsItemGallery', $K2PluginsItemGallery);
     $K2PluginsItemVideo = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'video'));
     $this->assignRef('K2PluginsItemVideo', $K2PluginsItemVideo);
     $K2PluginsItemExtraFields = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'extra-fields'));
     $this->assignRef('K2PluginsItemExtraFields', $K2PluginsItemExtraFields);
     $K2PluginsItemAttachments = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'attachments'));
     $this->assignRef('K2PluginsItemAttachments', $K2PluginsItemAttachments);
     $K2PluginsItemOther = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'other'));
     $this->assignRef('K2PluginsItemOther', $K2PluginsItemOther);
     if (version_compare(JVERSION, '1.6.0', 'ge')) {
         jimport('joomla.form.form');
         $form = JForm::getInstance('itemForm', JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'item.xml');
         $values = array('params' => json_decode($item->params));
         $form->bind($values);
     } else {
         $form = new JParameter('', JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'item.xml');
         $form->loadINI($item->params);
     }
     $this->assignRef('form', $form);
     $nullDate = $db->getNullDate();
     $this->assignRef('nullDate', $nullDate);
     $this->assignRef('extraFields', $extraFields);
     $this->assignRef('options', $options);
     $this->assignRef('row', $item);
     $this->assignRef('lists', $lists);
     $this->assignRef('params', $params);
     $this->assignRef('user', $user);
     JRequest::getInt('cid') ? $title = JText::_('K2_EDIT_ITEM') : ($title = JText::_('K2_ADD_ITEM'));
     $this->assignRef('title', $title);
     $this->assignRef('mainframe', $mainframe);
     if ($mainframe->isAdmin()) {
         $this->params->set('showImageTab', true);
         $this->params->set('showImageGalleryTab', true);
         $this->params->set('showVideoTab', true);
         $this->params->set('showExtraFieldsTab', true);
         $this->params->set('showAttachmentsTab', true);
         $this->params->set('showK2Plugins', true);
         JToolBarHelper::title($title, 'k2.png');
         JToolBarHelper::save();
         $saveNewIcon = version_compare(JVERSION, '2.5.0', 'ge') ? 'save-new.png' : 'save.png';
         JToolBarHelper::custom('saveAndNew', $saveNewIcon, 'save_f2.png', 'K2_SAVE_AND_NEW', false);
         JToolBarHelper::apply();
         JToolBarHelper::cancel();
     }
     // ACE ACL integration
     $definedConstants = get_defined_constants();
     if (!empty($definedConstants['ACEACL']) && AceaclApi::authorize('permissions', 'com_aceacl')) {
         $aceAclFlag = true;
     } else {
         $aceAclFlag = false;
     }
     $this->assignRef('aceAclFlag', $aceAclFlag);
     // SIG PRO v3 integration
     if (JPluginHelper::isEnabled('k2', 'jw_sigpro')) {
         $sigPro = true;
         $sigProFolder = $this->row->id ? $this->row->id : uniqid();
         $this->assignRef('sigProFolder', $sigProFolder);
     } else {
         $sigPro = false;
     }
     $this->assignRef('sigPro', $sigPro);
     parent::display($tpl);
 }
Ejemplo n.º 8
0
    /**
     * Logic to render an XML file as form parameters
     * NOTE: this does not work with Request Data validation in J2.5+. The validation
     *       must be skipped or the parameters must be re-added after the validation
     *
     * @access public
     * @return void
     * @since 1.5
     */
    function getlayoutparams()
    {
        jimport('joomla.filesystem.file');
        $app = JFactory::getApplication();
        $user = JFactory::getUser();
        //get vars
        $ext_option = JRequest::getVar('ext_option', '');
        $ext_view = JRequest::getVar('ext_view', '');
        $ext_id = JRequest::getInt('ext_id', 0);
        $layout_name = JRequest::getVar('layout_name', 0);
        $directory = JRequest::getVar('directory', 0);
        $path = (!is_dir($directory) ? JPATH_ROOT : '') . $directory;
        $db = JFactory::getDBO();
        if ($ext_view == 'module') {
            $query = 'SELECT params FROM #__modules WHERE id = ' . $ext_id;
            // load english language file for 'mod_flexicontent' module then override with current language file
            $module_name = basename(dirname($directory));
            JFactory::getLanguage()->load($module_name, JPATH_SITE, 'en-GB', true);
            JFactory::getLanguage()->load($module_name, JPATH_SITE, null, true);
        } else {
            if ($ext_view == 'field') {
                $query = 'SELECT attribs FROM #__flexicontent_fields WHERE id = ' . $ext_id;
            } else {
                echo "not supported extension/view: " . $ext_view;
                return;
            }
        }
        if ($ext_option != 'com_flexicontent' && $ext_option != 'com_modules' && $ext_option != 'com_advancedmodules' && $ext_option != 'com_menus') {
            echo '<div class="alert fcpadded fcinlineblock" style="">You are editing module via extension: <span class="label label-warning">' . $ext_option . '</span><br/> - If extension does not call Joomla event <span class="label label-warning">onExtensionBeforeSave</span> then custom layout parameters may not be saved</div>';
        }
        $db->setQuery($query);
        $ext_params_str = $db->loadResult();
        $layout_names = explode(':', $layout_name);
        if (count($layout_names) > 1) {
            $layout_name = $layout_names[1];
            $layoutpath = JPATH_ROOT . DS . 'templates' . DS . $layout_names[0] . DS . 'html' . DS . 'mod_flexicontent/' . $layout_name . '.xml';
        } else {
            $layoutpath = $path . DS . $layout_name . '.xml';
        }
        if (!file_exists($layoutpath)) {
            if (file_exists($path . DS . '_fallback' . DS . '_fallback.xml')) {
                $layoutpath = $path . DS . '_fallback' . DS . '_fallback.xml';
                echo '<div class="alert fcpadded fcinlineblock">Currently selected layout: <b>"' . $layout_name . '"</b> does not have a parameters XML file, using general defaults. if this is an old template then these parameters will allow to continue using it, but we recommend that you create parameter file: ' . $layout_name . '.xml</div><div class="clear"></div>';
            } else {
                echo !FLEXI_J16GE ? '<div style="font-size: 11px; color: gray; background-color: lightyellow; border: 1px solid lightgray; width: auto; padding: 4px 2%; margin: 1px 8px; height: auto;">' : '<p class="tip">';
                echo ' Currently selected layout: <b>"' . $layout_name . '"</b> does not have layout specific parameters';
                echo !FLEXI_J16GE ? '</div>' : '</p>';
                exit;
            }
        }
        //Get data from the model
        if (FLEXI_J16GE) {
            // Load XML file
            if (FLEXI_J30GE) {
                $xml = simplexml_load_file($layoutpath);
                $xmldoc =& $xml;
            } else {
                $xml = JFactory::getXMLParser('Simple');
                $xml->loadFile($layoutpath);
                $xmldoc =& $xml->document;
            }
            // Create form object, (form name seems not to cause any problem)
            $jform = new JForm('com_flexicontent.template.item', array('control' => 'jform', 'load_data' => true));
            $tmpl_params = FLEXI_J30GE ? $xmldoc->asXML() : $xmldoc->toString();
            $jform->load($tmpl_params);
            // Load existing layout values into the object (that we got from DB)
            $ext_params = new JRegistry($ext_params_str);
            // and for J1.5:  new JParameter($ext_params_str);
            $grpname = 'params';
            // this is the name of <fields> container
            foreach ($jform->getGroup($grpname) as $field) {
                $fieldname = $field->__get('fieldname');
                $value = $ext_params->get($fieldname);
                if (strlen($value)) {
                    $jform->setValue($fieldname, $grpname, $value);
                }
            }
        } else {
            // Create a parameters object
            $form = new JParameter('', $layoutpath);
            // Load existing layout values into the object (that we got from DB)
            $form->loadINI($ext_params_str);
        }
        if ($layout_name) {
            if (!FLEXI_J16GE) {
                echo $form->render('params', 'layout');
            } else {
                ?>
				<fieldset class="panelform"><ul class="adminformlist">
					<?php 
                $grpname = 'params';
                // this is the name of <fields> container
                foreach ($jform->getGroup($grpname) as $field) {
                    echo '<li>' . $field->label . $field->input . '</li>';
                }
                ?>
				</ul></fieldset>
				<?php 
            }
        } else {
            echo "<br /><span style=\"padding-left:25px;\"'>" . JText::_('FLEXI_APPLY_TO_SEE_THE_PARAMETERS') . "</span><br /><br />";
        }
        //parent::display($tpl);
    }
Ejemplo n.º 9
0
function editlink($link_id, $cat_id, $for_approval = false, $option)
{
    global $mainframe, $mtconf;
    $database =& JFactory::getDBO();
    $my =& JFactory::getUser();
    $row = new mtLinks($database);
    $row->load($link_id);
    if ($row->link_id == 0) {
        $createdate =& JFactory::getDate();
        $row->cat_id = $cat_id;
        $row->alias = '';
        $row->link_hits = 0;
        $row->link_visited = 0;
        $row->link_votes = 0;
        $row->link_rating = 0.0;
        $row->link_featured = 0;
        $row->link_created = $createdate->toUnix();
        $row->publish_up = $createdate->toUnix();
        $row->publish_down = JText::_('Never');
        $row->link_published = 1;
        $row->link_approved = 1;
        $row->user_id = $my->id;
        $row->owner = $my->username;
    } else {
        if ($row->user_id > 0) {
            $database->setQuery('SELECT username FROM #__users WHERE id =' . $database->quote($row->user_id));
            $row->owner = $database->loadResult();
        } else {
            $row->owner = $my->username;
        }
    }
    if ($cat_id == 0 && $row->cat_id > 0) {
        $cat_id = $row->cat_id;
    }
    # Load images
    $database->setQuery('SELECT img_id, filename FROM #__mt_images WHERE link_id = ' . $database->quote($row->link_id) . ' ORDER BY ordering ASC');
    $images = $database->loadObjectList();
    $lists = array();
    # Load all published CORE & custom fields
    $sql = "SELECT cf.*, " . ($row->link_id ? $row->link_id : 0) . " AS link_id, cfv.value, cfv.attachment, cfv.counter, ft.ft_class FROM #__mt_customfields AS cf " . "\nLEFT JOIN #__mt_cfvalues AS cfv ON cf.cf_id=cfv.cf_id AND cfv.link_id = " . $database->quote($link_id) . "\nLEFT JOIN #__mt_fieldtypes AS ft ON ft.field_type=cf.field_type" . "\nWHERE cf.published='1' ORDER BY ordering ASC";
    $database->setQuery($sql);
    $fields = new mFields();
    $fields->setCoresValue($row->link_name, $row->link_desc, $row->address, $row->city, $row->state, $row->country, $row->postcode, $row->telephone, $row->fax, $row->email, $row->website, $row->price, $row->link_hits, $row->link_votes, $row->link_rating, $row->link_featured, $row->link_created, $row->link_modified, $row->link_visited, $row->publish_up, $row->publish_down, $row->metakey, $row->metadesc, $row->user_id, $row->owner);
    $fields->loadFields($database->loadObjectList());
    # Get other categories
    $database->setQuery('SELECT cl.cat_id FROM #__mt_cl AS cl WHERE cl.link_id = ' . $database->quote($link_id) . ' AND cl.main = 0');
    $other_cats = $database->loadResultArray();
    # Get Pathway
    $pathWay = new mtPathWay($cat_id);
    # Is this approval for modification?
    if ($row->link_approved < 0) {
        $row->original_link_id = -1 * $row->link_approved;
    } else {
        $row->original_link_id = '';
    }
    # Compile list of categories
    if ($cat_id > 0) {
        $database->setQuery('SELECT cat_parent FROM #__mt_cats WHERE cat_id = ' . $database->quote($cat_id));
        $browse_cat_parent = $database->loadResult();
    }
    $categories = array();
    if ($cat_id > 0) {
        $categories[] = JHTML::_('select.option', $browse_cat_parent, JText::_('Arrow back'));
    }
    $database->setQuery('SELECT cat_id AS value, cat_name AS text FROM #__mt_cats' . "\nWHERE cat_parent = " . $database->quote($cat_id) . " AND cat_approved = '1' AND cat_published = '1' ORDER BY cat_name ASC");
    $categories = array_merge($categories, $database->loadObjectList());
    $lists['cat_id'] = JHTML::_('select.genericlist', $categories, 'new_cat_id', 'size="8" class="text_area" style="display:block;width:50%;margin-top:6px;"', 'value', 'text', $row->getCatID(), 'browsecat');
    # Get Return task - Used by listpending_links
    $returntask = JRequest::getCmd('returntask', '', 'post');
    # Get params definitions
    $form = new JParameter($row->attribs, JPATH_COMPONENT . DS . 'models' . DS . 'listing.xml');
    $form->set('owner', $row->owner);
    $form->set('alias', $row->alias);
    $form->set('link_approved', $row->link_approved);
    $form->set('link_published', $row->link_published);
    $form->set('link_featured', $row->link_featured);
    $form->set('link_created', JHTML::_('date', $row->link_created, '%Y-%m-%d %H:%M:%S'));
    $form->set('publish_up', JHTML::_('date', $row->publish_up, '%Y-%m-%d %H:%M:%S'));
    if (JHTML::_('date', $row->publish_down, '%Y') <= 1969 || $row->publish_down == $database->getNullDate()) {
        $form->set('publish_down', JText::_('Never'));
    } else {
        $form->set('publish_down', JHTML::_('date', $row->publish_down, '%Y-%m-%d %H:%M:%S'));
    }
    $form->set('link_template', $row->link_template);
    $form->set('metakey', $row->metakey);
    $form->set('metadesc', $row->metadesc);
    $form->set('link_rating', $row->link_rating);
    $form->set('link_votes', $row->link_votes);
    $form->set('link_hits', $row->link_hits);
    $form->set('link_visited', $row->link_visited);
    $form->set('internal_notes', $row->internal_notes);
    $form->loadINI($row->attribs);
    if ($row->link_approved <= 0) {
        $database->setQuery('SELECT link_id FROM #__mt_links WHERE link_approved <= 0 ORDER BY link_created ASC, link_modified DESC');
        $links = $database->loadResultArray();
        $number_of_prev = array_search($row->link_id, $links);
        $number_of_next = count($links) - 1 - $number_of_prev;
    } else {
        $number_of_prev = 0;
        $number_of_next = 0;
    }
    HTML_mtree::editlink($row, $fields, $images, $cat_id, $other_cats, $lists, $number_of_prev, $number_of_next, $pathWay, $returntask, $form, $option);
}
Ejemplo n.º 10
0
    function display($tpl = null)
    {
        //initialise variables
        $app = JFactory::getApplication();
        $option = JRequest::getVar('option');
        $document = JFactory::getDocument();
        $cparams = JComponentHelper::getParams('com_flexicontent');
        $user = JFactory::getUser();
        //add css to document
        $document->addStyleSheetVersion(JURI::base(true) . '/components/com_flexicontent/assets/css/flexicontentbackend.css', FLEXI_VHASH);
        $document->addStyleSheetVersion(JURI::base(true) . '/components/com_flexicontent/assets/css/j3x.css', FLEXI_VHASH);
        // Add JS frameworks
        flexicontent_html::loadFramework('select2');
        // Add js function to overload the joomla submitform validation
        JHTML::_('behavior.formvalidation');
        // load default validation JS to make sure it is overriden
        $document->addScriptVersion(JURI::root(true) . '/components/com_flexicontent/assets/js/admin.js', FLEXI_VHASH);
        $document->addScriptVersion(JURI::root(true) . '/components/com_flexicontent/assets/js/validate.js', FLEXI_VHASH);
        //Load pane behavior
        jimport('joomla.html.pane');
        //Import File system
        jimport('joomla.filesystem.file');
        //Get data from the model
        $model = $this->getModel();
        $row = $this->get('Field');
        $form = $this->get('Form');
        $types = $this->get('Typeslist');
        $typesselected = $this->get('Typesselected');
        //create the toolbar
        if ($row->id) {
            JToolBarHelper::title(JText::_('FLEXI_EDIT_FIELD'), 'fieldedit');
        } else {
            JToolBarHelper::title(JText::_('FLEXI_ADD_FIELD'), 'fieldadd');
        }
        $ctrl = FLEXI_J16GE ? 'fields.' : '';
        JToolBarHelper::apply($ctrl . 'apply');
        JToolBarHelper::save($ctrl . 'save');
        JToolBarHelper::custom($ctrl . 'saveandnew', 'savenew.png', 'savenew.png', 'FLEXI_SAVE_AND_NEW', false);
        JToolBarHelper::cancel($ctrl . 'cancel');
        // Import Joomla plugin that implements the type of current flexi field
        $extfolder = 'flexicontent_fields';
        $extname = $row->iscore ? 'core' : $row->field_type;
        JPluginHelper::importPlugin('flexicontent_fields', $row->iscore ? 'core' : $row->field_type);
        // Create class name of the plugin and then create a plugin instance
        $classname = 'plg' . ucfirst($extfolder) . $extname;
        // Check max allowed version
        if (property_exists($classname, 'prior_to_version')) {
            // Set a system message with warning of failed PHP limits
            $prior_to_version = $app->getUserStateFromRequest($option . '.flexicontent.prior_to_version_' . $row->field_type, 'prior_to_version_' . $row->field_type, 0, 'int');
            $app->setUserState($option . '.flexicontent.prior_to_version_' . $row->field_type, $prior_to_version + 1);
            if ($prior_to_version < 2) {
                $close_btn = FLEXI_J30GE ? '<a class="close" data-dismiss="alert">&#215;</a>' : '<a class="fc-close" onclick="this.parentNode.parentNode.removeChild(this.parentNode);">&#215;</a>';
                $manifest_path = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_flexicontent' . DS . 'manifest.xml';
                $com_xml = JApplicationHelper::parseXMLInstallFile($manifest_path);
                $ver_exceeded = version_compare(str_replace(' ', '.', $com_xml['version']), str_replace(' ', '.', $classname::$prior_to_version), '>=');
                if ($ver_exceeded) {
                    echo '
					<span class="fc-note fc-mssg-inline">
						' . $close_btn . '
						Warning: installed version of Field: \'<b>' . $extname . '</b>\' was given to be free for FLEXIcontent versions prior to: v' . $classname::$prior_to_version . ' <br/> It may or may not work properly in later versions
					</span>';
                } else {
                    echo '
					<span class="fc-info fc-mssg-inline">
						' . $close_btn . '
						Note: installed version of Field: \'<b>' . $extname . '</b>\' is given free for FLEXIcontent versions prior to: v' . $classname::$prior_to_version . ', &nbsp; &nbsp; nevertheless it will continue to function after FLEXIcontent is upgraded.
					</span>';
                }
            }
        }
        // load plugin's english language file then override with current language file
        $extension_name = 'plg_flexicontent_fields_' . ($row->iscore ? 'core' : $row->field_type);
        JFactory::getLanguage()->load($extension_name, JPATH_ADMINISTRATOR, 'en-GB', true);
        JFactory::getLanguage()->load($extension_name, JPATH_ADMINISTRATOR, null, true);
        //check which properties are supported by current field
        $ft_support = FlexicontentFields::getPropertySupport($row->field_type, $row->iscore);
        $supportsearch = $ft_support->supportsearch;
        $supportadvsearch = $ft_support->supportadvsearch;
        $supportfilter = $ft_support->supportfilter;
        $supportadvfilter = $ft_support->supportadvfilter;
        $supportuntranslatable = $ft_support->supportuntranslatable;
        $supportvalueseditable = $ft_support->supportvalueseditable;
        $supportformhidden = $ft_support->supportformhidden;
        $supportedithelp = $ft_support->supportedithelp;
        //build selectlists, (for J1.6+ most of these are defined via XML file and custom form field classes)
        $lists = array();
        //build field_type list
        if (!$row->field_type) {
            $row->field_type = 'text';
        }
        $_attribs = ' class="use_select2_lib fc_skip_highlight" ';
        if ($row->iscore == 1) {
            $_attribs .= ' disabled="disabled" ';
        } else {
            $_field_id = 'jform_field_type';
            $_row_id = $form->getValue("id");
            $_ctrl_task = 'task=fields.getfieldspecificproperties';
            $document->addScriptDeclaration("\n\t\t\t\tjQuery(document).ready(function() {\n\t\t\t\t\tjQuery('#" . $_field_id . "').on('change', function() {\n\t\t\t\t\t\tjQuery('#fieldspecificproperties').html('<p class=\"centerimg\"><img src=\"components/com_flexicontent/assets/images/ajax-loader.gif\" align=\"center\"></p>');\n\t\t\t\t\t\tjQuery.ajax({\n\t\t\t\t\t\t\ttype: \"GET\",\n\t\t\t\t\t\t\turl: 'index.php?option=com_flexicontent&" . $_ctrl_task . "&cid=" . $_row_id . "&field_type='+this.value+'&format=raw',\n\t\t\t\t\t\t\tsuccess: function(str) {\n\t\t\t\t\t\t\t\tjQuery('#fieldspecificproperties').html(str);\n\t\t\t\t\t\t\t\t" . (FLEXI_J30GE ? "\n\t\t\t\t\t\t\t\t\tjQuery('.hasTooltip').tooltip({'html': true,'container': jQuery('#fieldspecificproperties')});\n\t\t\t\t\t\t\t\t" : "\n\t\t\t\t\t\t\t\tvar tipped_elements = jQuery('#fieldspecificproperties .hasTip');\n\t\t\t\t\t\t\t\ttipped_elements.each(function() {\n\t\t\t\t\t\t\t\t\tvar title = this.get('title');\n\t\t\t\t\t\t\t\t\tif (title) {\n\t\t\t\t\t\t\t\t\t\tvar parts = title.split('::', 2);\n\t\t\t\t\t\t\t\t\t\tthis.store('tip:title', parts[0]);\n\t\t\t\t\t\t\t\t\t\tthis.store('tip:text', parts[1]);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\tvar ajax_JTooltips = new Tips(\$('fieldspecificproperties').getElements('.hasTip'), { maxTitleChars: 50, fixed: false});\n\t\t\t\t\t\t\t\t") . "\n\t\t\t\t\t\t\t\ttabberAutomatic(tabberOptions, 'fieldspecificproperties');\n\t\t\t\t\t\t\t\tfc_bindFormDependencies('#fieldspecificproperties', 0, '');\n\t\t\t\t\t\t\t\tjQuery('#field_typename').html(jQuery('#" . $_field_id . "').val());\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t");
        }
        //build field select list
        $fieldtypes = flexicontent_db::getFieldTypes($_grouped = true, $_usage = false, $_published = true);
        $fftypes = array();
        foreach ($fieldtypes as $field_group => $ft_types) {
            $fftypes[] = $field_group;
            foreach ($ft_types as $field_type => $ftdata) {
                $fftypes[] = array('value' => $ftdata->field_type, 'text' => $ftdata->friendly);
            }
            $fftypes[] = '';
        }
        $lists['field_type'] = flexicontent_html::buildfieldtypeslist($fftypes, 'jform[field_type]', $row->field_type, $_grouped ? 1 : 0, $_attribs);
        //build type select list
        $attribs = 'class="use_select2_lib" multiple="multiple" size="6"';
        $attribs .= $row->iscore ? ' disabled="disabled"' : '';
        $types_fieldname = FLEXI_J16GE ? 'jform[tid][]' : 'tid[]';
        $lists['tid'] = flexicontent_html::buildtypesselect($types, $types_fieldname, $typesselected, false, $attribs);
        // **************************************************************************
        // Create fields for J1.5 (J2.5+ uses JForm XML file for most of form fields)
        // **************************************************************************
        if (!FLEXI_J16GE) {
            //build formhidden selector
            $formhidden[] = JHTML::_('select.option', 0, JText::_('FLEXI_NO'));
            $formhidden[] = JHTML::_('select.option', 1, JText::_('FLEXI_FRONTEND'));
            $formhidden[] = JHTML::_('select.option', 2, JText::_('FLEXI_BACKEND'));
            $formhidden[] = JHTML::_('select.option', 3, JText::_('FLEXI_BOTH'));
            $formhidden_fieldname = FLEXI_J16GE ? 'jform[formhidden]' : 'formhidden';
            $lists['formhidden'] = JHTML::_('select.radiolist', $formhidden, $formhidden_fieldname, '', 'value', 'text', $row->formhidden);
            if (FLEXI_ACCESS) {
                $valueseditable[] = JHTML::_('select.option', 0, JText::_('FLEXI_ANY_EDITOR'));
                $valueseditable[] = JHTML::_('select.option', 1, JText::_('FLEXI_USE_ACL_PERMISSION'));
                $valueseditable_fieldname = FLEXI_J16GE ? 'jform[valueseditable]' : 'valueseditable';
                $lists['valueseditable'] = JHTML::_('select.radiolist', $valueseditable, $valueseditable_fieldname, '', 'value', 'text', $row->valueseditable);
            }
            $edithelp[] = JHTML::_('select.option', 0, JText::_('FLEXI_EDIT_HELP_NONE'));
            $edithelp[] = JHTML::_('select.option', 1, JText::_('FLEXI_EDIT_HELP_LABEL_TOOLTIP'));
            $edithelp[] = JHTML::_('select.option', 2, JText::_('FLEXI_EDIT_HELP_LABEL_TOOLTIP_WICON'));
            $edithelp[] = JHTML::_('select.option', 3, JText::_('FLEXI_EDIT_HELP_INLINE'));
            $edithelp_fieldname = FLEXI_J16GE ? 'jform[edithelp]' : 'edithelp';
            $lists['edithelp'] = JHTML::_('select.radiolist', $edithelp, $edithelp_fieldname, '', 'value', 'text', $row->edithelp);
            // build the html select list for ordering
            $query = 'SELECT ordering AS value, label AS text' . ' FROM #__flexicontent_fields' . ' WHERE published >= 0' . ' ORDER BY ordering';
            $row->ordering = @$row->ordering;
            $lists['ordering'] = $row->id ? JHTML::_('list.specificordering', $row, $row->id, $query) : JHTML::_('list.specificordering', $row, '', $query);
            //build access level list
            if (FLEXI_ACCESS) {
                $lang = JFactory::getLanguage();
                $lang->_strings['FLEXIACCESS_PADD'] = 'Edit-Value';
                $lists['access'] = FAccess::TabGmaccess($row, 'field', 1, 1, 0, 1, 0, 1, 0, 1, 1);
            } else {
                $lists['access'] = JHTML::_('list.accesslevel', $row);
            }
        }
        if (!FLEXI_J16GE) {
            // Create the parameter 's form object parsing the file XML
            $pluginpath = JPATH_PLUGINS . DS . 'flexicontent_fields' . DS . $row->field_type . '.xml';
            if (JFile::exists($pluginpath)) {
                $form = new JParameter('', $pluginpath);
            } else {
                $form = new JParameter('', JPATH_PLUGINS . DS . 'flexicontent_fields' . DS . 'core.xml');
            }
            // Special and Core Groups
            $form->loadINI($row->attribs);
        }
        // fail if checked out not by 'me'
        if ($row->id) {
            if ($model->isCheckedOut($user->get('id'))) {
                JError::raiseWarning('SOME_ERROR_CODE', $row->name . ' ' . JText::_('FLEXI_EDITED_BY_ANOTHER_ADMIN'));
                $app->redirect('index.php?option=com_flexicontent&view=fields');
            }
        }
        //clean data
        JFilterOutput::objectHTMLSafe($row, ENT_QUOTES);
        // assign permissions for J2.5
        $permission = FlexicontentHelperPerm::getPerm();
        $this->assignRef('permission', $permission);
        //assign data to template
        $this->assignRef('document', $document);
        $this->assignRef('row', $row);
        $this->assignRef('lists', $lists);
        $this->assignRef('form', $form);
        $this->assignRef('typesselected', $typesselected);
        $this->assignRef('supportsearch', $supportsearch);
        $this->assignRef('supportadvsearch', $supportadvsearch);
        $this->assignRef('supportfilter', $supportfilter);
        $this->assignRef('supportadvfilter', $supportadvfilter);
        $this->assignRef('supportuntranslatable', $supportuntranslatable);
        $this->assignRef('supportvalueseditable', $supportvalueseditable);
        $this->assignRef('supportformhidden', $supportformhidden);
        $this->assignRef('supportedithelp', $supportedithelp);
        parent::display($tpl);
    }
Ejemplo n.º 11
0
    /**
     * Creates the item page
     *
     * @since 1.0
     */
    function display($tpl = null)
    {
        // ********************************
        // Initialize variables, flags, etc
        // ********************************
        global $globalcats;
        $categories = $globalcats;
        $app = JFactory::getApplication();
        $dispatcher = JDispatcher::getInstance();
        $document = JFactory::getDocument();
        $config = JFactory::getConfig();
        $session = JFactory::getSession();
        $user = JFactory::getUser();
        $db = JFactory::getDBO();
        $option = JRequest::getVar('option');
        $nullDate = $db->getNullDate();
        // Get the COMPONENT only parameters
        // Get component parameters
        $params = new JRegistry();
        $cparams = JComponentHelper::getParams('com_flexicontent');
        $params->merge($cparams);
        $params = clone JComponentHelper::getParams('com_flexicontent');
        // Some flags
        $enable_translation_groups = flexicontent_db::useAssociations();
        //$params->get("enable_translation_groups");
        $print_logging_info = $params->get('print_logging_info');
        if ($print_logging_info) {
            global $fc_run_times;
        }
        // *****************
        // Load JS/CSS files
        // *****************
        // Add css to document
        $document->addStyleSheet(JURI::base(true) . '/components/com_flexicontent/assets/css/flexicontentbackend.css');
        FLEXI_J30GE ? $document->addStyleSheet(JURI::base(true) . '/components/com_flexicontent/assets/css/j3x.css') : $document->addStyleSheet(JURI::base(true) . '/components/com_flexicontent/assets/css/j25.css');
        // Fields common CSS
        $document->addStyleSheet(JURI::root(true) . '/components/com_flexicontent/assets/css/flexi_form_fields.css');
        // Add JS frameworks
        flexicontent_html::loadFramework('select2');
        $prettycheckable_added = flexicontent_html::loadFramework('prettyCheckable');
        flexicontent_html::loadFramework('flexi-lib');
        // Add js function to overload the joomla submitform validation
        JHTML::_('behavior.formvalidation');
        // load default validation JS to make sure it is overriden
        $document->addScript(JURI::root(true) . '/components/com_flexicontent/assets/js/admin.js');
        $document->addScript(JURI::root(true) . '/components/com_flexicontent/assets/js/validate.js');
        // Add js function for custom code used by FLEXIcontent item form
        $document->addScript(JURI::root(true) . '/components/com_flexicontent/assets/js/itemscreen.js');
        // ***********************
        // Get data from the model
        // ***********************
        if ($print_logging_info) {
            $start_microtime = microtime(true);
        }
        $model = $this->getModel();
        $item = $model->getItem();
        $form = $this->get('Form');
        if ($print_logging_info) {
            $fc_run_times['get_item_data'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10;
        }
        // ***************************
        // Get Associated Translations
        // ***************************
        if ($enable_translation_groups) {
            $langAssocs = $this->get('LangAssocs');
        }
        $langs = FLEXIUtilities::getLanguages('code');
        // Get item id and new flag
        $cid = $model->getId();
        $isnew = !$cid;
        // Create and set a unique item id for plugins that needed it
        if ($cid) {
            $unique_tmp_itemid = $cid;
        } else {
            $unique_tmp_itemid = $app->getUserState('com_flexicontent.edit.item.unique_tmp_itemid');
            $unique_tmp_itemid = $unique_tmp_itemid ? $unique_tmp_itemid : date('_Y_m_d_h_i_s_', time()) . uniqid(true);
        }
        //print_r($unique_tmp_itemid);
        JRequest::setVar('unique_tmp_itemid', $unique_tmp_itemid);
        // Get number of subscribers
        $subscribers = $model->getSubscribersCount();
        // ******************
        // Version Panel data
        // ******************
        // Get / calculate some version related variables
        $versioncount = $model->getVersionCount();
        $versionsperpage = $params->get('versionsperpage', 10);
        $pagecount = (int) ceil($versioncount / $versionsperpage);
        // Data need by version panel: (a) current version page, (b) currently active version
        $current_page = 1;
        $k = 1;
        $allversions = $model->getVersionList();
        foreach ($allversions as $v) {
            if ($k > 1 && ($k - 1) % $versionsperpage == 0) {
                $current_page++;
            }
            if ($v->nr == $item->version) {
                break;
            }
            $k++;
        }
        // Finally fetch the version data for versions in current page
        $versions = $model->getVersionList(($current_page - 1) * $versionsperpage, $versionsperpage);
        // *****************
        // Type related data
        // *****************
        // Get available types and the currently selected/requested type
        $types = $model->getTypeslist();
        $typesselected = $model->getTypesselected();
        // Get and merge type parameters
        $tparams = $this->get('Typeparams');
        $tparams = new JRegistry($tparams);
        $params->merge($tparams);
        // Apply type configuration if it type is set
        // Get user allowed permissions on the item ... to be used by the form rendering
        // Also hide parameters panel if user can not edit parameters
        $perms = $this->_getItemPerms($item);
        if (!$perms['canparams']) {
            $document->addStyleDeclaration('#details-options {display:none;}');
        }
        // ******************
        // Create the toolbar
        // ******************
        $toolbar = JToolBar::getInstance('toolbar');
        $tip_class = FLEXI_J30GE ? ' hasTooltip' : ' hasTip';
        // SET toolbar title
        if ($cid) {
            JToolBarHelper::title(JText::_('FLEXI_EDIT_ITEM'), 'itemedit');
            // Editing existing item
        } else {
            JToolBarHelper::title(JText::_('FLEXI_NEW_ITEM'), 'itemadd');
            // Creating new item
        }
        // **************
        // Common Buttons
        // **************
        // Applying new item type is a special case that has not loaded custom fieds yet
        JToolBarHelper::apply($item->type_id ? 'items.apply' : 'items.apply_type', !$isnew ? 'FLEXI_APPLY' : ($typesselected->id ? 'FLEXI_ADD' : 'FLEXI_APPLY_TYPE'), false);
        /*if (!$isnew || $item->version) flexicontent_html::addToolBarButton(
        		'FLEXI_FAST_APPLY', $btn_name='apply_ajax', $full_js="Joomla.submitbutton('items.apply_ajax')", $msg_alert='', $msg_confirm='',
        		$btn_task='items.apply_ajax', $extra_js='', $btn_list=false, $btn_menu=true, $btn_confirm=false, $btn_class="".$tip_class, $btn_icon="icon-loop",
        		'data-placement="bottom" title="Fast saving, without reloading the form. <br/><br/>Note: new files will not be uploaded, <br/>- in such a case please use \'Apply\'"');*/
        if (!$isnew || $item->version) {
            JToolBarHelper::save('items.save');
        }
        if (!$isnew || $item->version) {
            JToolBarHelper::custom('items.saveandnew', 'savenew.png', 'savenew.png', 'FLEXI_SAVE_AND_NEW', false);
        }
        JToolBarHelper::cancel('items.cancel');
        // ***********************
        // Add a preview button(s)
        // ***********************
        //$_sh404sef = JPluginHelper::isEnabled('system', 'sh404sef') && $config->get('sef');
        $_sh404sef = defined('SH404SEF_IS_RUNNING') && $config->get('sef');
        if ($cid) {
            // Domain URL and autologin vars
            $server = JURI::getInstance()->toString(array('scheme', 'host', 'port'));
            $autologin = '';
            //$params->get('autoflogin', 1) ? '&fcu='.$user->username . '&fcp='.$user->password : '';
            // Check if we are in the backend, in the back end we need to set the application to the site app instead
            // we do not remove 'isAdmin' check so that we can copy later without change, e.g. to a plugin
            $isAdmin = JFactory::getApplication()->isAdmin();
            if ($isAdmin && !$_sh404sef) {
                JFactory::$application = JApplication::getInstance('site');
            }
            // Create the URL
            $item_url = FlexicontentHelperRoute::getItemRoute($item->id . ':' . $item->alias, $categories[$item->catid]->slug);
            $item_url = $_sh404sef ? Sh404sefHelperGeneral::getSefFromNonSef($item_url, $fullyQualified = true, $xhtml = false, $ssl = null) : JRoute::_($item_url);
            // Check if we are in the backend again
            // In backend we need to remove administrator from URL as it is added even though we've set the application to the site app
            if ($isAdmin && !$_sh404sef) {
                $admin_folder = str_replace(JURI::root(true), '', JURI::base(true));
                $item_url = str_replace($admin_folder . '/', '/', $item_url);
                // Restore application
                JFactory::$application = JApplication::getInstance('administrator');
            }
            $previewlink = $item_url . (strstr($item_url, '?') ? '&' : '?') . 'preview=1' . $autologin;
            //$previewlink     = str_replace('&amp;', '&', $previewlink);
            //$previewlink = JRoute::_(JURI::root() . FlexicontentHelperRoute::getItemRoute($item->id.':'.$item->alias, $categories[$item->catid]->slug)) .$autologin;
            // PREVIEW for latest version
            if (!$params->get('use_versioning', 1) || $item->version == $item->current_version && $item->version == $item->last_version) {
                $toolbar->appendButton('Custom', '<button class="preview btn btn-small btn-info spaced-btn" onClick="window.open(\'' . $previewlink . '\');" target="_blank"><span title="' . JText::_('Preview') . '" class="icon-screen"></span>' . JText::_('Preview') . '</button>', 'preview');
            } else {
                // Add a preview button for (currently) LOADED version of the item
                $previewlink_loaded_ver = $previewlink . '&version=' . $item->version;
                $toolbar->appendButton('Custom', '<button class="preview btn btn-small" onClick="window.open(\'' . $previewlink_loaded_ver . '\');" target="_blank"><span title="' . JText::_('Preview') . '" class="icon-screen"></span>' . JText::_('FLEXI_PREVIEW_FORM_LOADED_VERSION') . ' [' . $item->version . ']</button>', 'preview');
                // Add a preview button for currently ACTIVE version of the item
                $previewlink_active_ver = $previewlink . '&version=' . $item->current_version;
                $toolbar->appendButton('Custom', '<button class="preview btn btn-small" onClick="window.open(\'' . $previewlink_active_ver . '\');" target="_blank"><span title="' . JText::_('Preview') . '" class="icon-screen"></span>' . JText::_('FLEXI_PREVIEW_FRONTEND_ACTIVE_VERSION') . ' [' . $item->current_version . ']</button>', 'preview');
                // Add a preview button for currently LATEST version of the item
                $previewlink_last_ver = $previewlink;
                //'&version='.$item->last_version;
                $toolbar->appendButton('Custom', '<button class="preview btn btn-small" onClick="window.open(\'' . $previewlink_last_ver . '\');" target="_blank"><span title="' . JText::_('Preview') . '" class="icon-screen"></span>' . JText::_('FLEXI_PREVIEW_LATEST_SAVED_VERSION') . ' [' . $item->last_version . ']</button>', 'preview');
            }
            JToolBarHelper::spacer();
            JToolBarHelper::divider();
            JToolBarHelper::spacer();
        }
        // ************************
        // Add modal layout editing
        // ************************
        if ($perms['cantemplates']) {
            JToolBarHelper::divider();
            if (!$isnew || $item->version) {
                flexicontent_html::addToolBarButton('FLEXI_EDIT_LAYOUT', $btn_name = 'apply_ajax', $full_js = "var url = jQuery(this).attr('data-href'); fc_showDialog(url, 'fc_modal_popup_container'); return false;", $msg_alert = '', $msg_confirm = '', $btn_task = 'items.apply_ajax', $extra_js = '', $btn_list = false, $btn_menu = true, $btn_confirm = false, $btn_class = "btn-info" . $tip_class, $btn_icon = "icon-pencil", 'data-placement="bottom" data-href="index.php?option=com_flexicontent&amp;view=template&amp;type=items&amp;tmpl=component&amp;ismodal=1&amp;folder=' . $item->itemparams->get('ilayout', $tparams->get('ilayout', 'default')) . '" title="Edit the display layout of this item. <br/><br/>Note: this layout maybe assigned to content types or other items, thus changing it will effect them too"');
            }
        }
        // Check if saving an item that translates an original content in site's default language
        $site_default = substr(flexicontent_html::getSiteDefaultLang(), 0, 2);
        $is_content_default_lang = $site_default == substr($item->language, 0, 2);
        //$modify_untraslatable_values = $enable_translation_groups && !$is_content_default_lang; // && $item->lang_parent_id && $item->lang_parent_id!=$item->id;
        // *****************************************************************************
        // Get (CORE & CUSTOM) fields and their VERSIONED values and then
        // (a) Apply Content Type Customization to CORE fields (label, description, etc)
        // (b) Create the edit html of the CUSTOM fields by triggering 'onDisplayField'
        // *****************************************************************************
        if ($print_logging_info) {
            $start_microtime = microtime(true);
        }
        $fields = $this->get('Extrafields');
        $item->fields =& $fields;
        if ($print_logging_info) {
            $fc_run_times['get_field_vals'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10;
        }
        if ($print_logging_info) {
            $start_microtime = microtime(true);
        }
        $jcustom = $app->getUserState('com_flexicontent.edit.item.custom');
        //print_r($jcustom);
        foreach ($fields as $field) {
            // a. Apply CONTENT TYPE customizations to CORE FIELDS, e.g a type specific label & description
            // NOTE: the field parameters are already created so there is not need to call this for CUSTOM fields, which do not have CONTENT TYPE customizations
            if ($field->iscore) {
                FlexicontentFields::loadFieldConfig($field, $item);
            }
            // b. Create field 's editing HTML (the form field)
            // NOTE: this is DONE only for CUSTOM fields, since form field html is created by the form for all CORE fields, EXCEPTION is the 'text' field (see bellow)
            if (!$field->iscore) {
                if (isset($jcustom[$field->name])) {
                    $field->value = array();
                    foreach ($jcustom[$field->name] as $i => $_val) {
                        $field->value[$i] = $_val;
                    }
                }
                $is_editable = !$field->valueseditable || $user->authorise('flexicontent.editfieldvalues', 'com_flexicontent.field.' . $field->id);
                if ($is_editable) {
                    FLEXIUtilities::call_FC_Field_Func($field->field_type, 'onDisplayField', array(&$field, &$item));
                    if ($field->untranslatable) {
                        $field->html = '<div class="alert alert-info fc-small fc-iblock">' . JText::_('FLEXI_FIELD_VALUE_IS_NON_TRANSLATABLE') . '</div>' . "\n" . $field->html;
                    }
                } else {
                    if ($field->valueseditable == 1) {
                        $field->html = '<div class="fc-mssg fc-note">' . JText::_($field->parameters->get('no_acc_msg_form') ? $field->parameters->get('no_acc_msg_form') : 'FLEXI_NO_ACCESS_LEVEL_TO_EDIT_FIELD') . '</div>';
                    } else {
                        if ($field->valueseditable == 2) {
                            FLEXIUtilities::call_FC_Field_Func($field->field_type, 'onDisplayFieldValue', array(&$field, $item));
                            $field->html = '<div class="fc-mssg fc-note">' . JText::_($field->parameters->get('no_acc_msg_form') ? $field->parameters->get('no_acc_msg_form') : 'FLEXI_NO_ACCESS_LEVEL_TO_EDIT_FIELD') . '</div>' . "\n" . $field->display;
                        } else {
                            if ($field->valueseditable == 3) {
                                FLEXIUtilities::call_FC_Field_Func($field->field_type, 'onDisplayFieldValue', array(&$field, $item));
                                $field->html = $field->display;
                            } else {
                                if ($field->valueseditable == 4) {
                                    $field->html = '';
                                    $field->formhidden = 4;
                                }
                            }
                        }
                    }
                }
            }
            // c. Create main text field, via calling the display function of the textarea field (will also check for tabs)
            if ($field->field_type == 'maintext') {
                if (isset($item->item_translations)) {
                    $shortcode = substr($item->language, 0, 2);
                    foreach ($item->item_translations as $lang_id => $t) {
                        if ($shortcode == $t->shortcode) {
                            continue;
                        }
                        $field->name = array('jfdata', $t->shortcode, 'text');
                        $field->value[0] = html_entity_decode($t->fields->text->value, ENT_QUOTES, 'UTF-8');
                        FLEXIUtilities::call_FC_Field_Func('textarea', 'onDisplayField', array(&$field, &$item));
                        $t->fields->text->tab_labels = $field->tab_labels;
                        $t->fields->text->html = $field->html;
                        unset($field->tab_labels);
                        unset($field->html);
                    }
                }
                $field->name = 'text';
                // NOTE: We use the text created by the model and not the text retrieved by the CORE plugin code, which maybe overwritten with JoomFish/Falang data
                $field->value[0] = $item->text;
                // do not decode special characters this was handled during saving !
                // Render the field's (form) HTML
                FLEXIUtilities::call_FC_Field_Func('textarea', 'onDisplayField', array(&$field, &$item));
            }
        }
        if ($print_logging_info) {
            $fc_run_times['render_field_html'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10;
        }
        // *************************
        // Get tags used by the item
        // *************************
        $usedtagsIds = $this->get('UsedtagsIds');
        // NOTE: This will normally return the already set versioned value of tags ($item->tags)
        $usedtags = $model->getUsedtagsData($usedtagsIds);
        // *******************************
        // Get categories used by the item
        // *******************************
        if ($isnew) {
            // Case for preselected main category for new items
            $maincat = $item->catid ? $item->catid : JRequest::getInt('maincat', 0);
            if (!$maincat) {
                $maincat = $app->getUserStateFromRequest($option . '.items.filter_cats', 'filter_cats', '', 'int');
            }
            if ($maincat) {
                $selectedcats = array($maincat);
                $item->catid = $maincat;
            } else {
                $selectedcats = array();
            }
            if ($tparams->get('cid_default')) {
                $selectedcats = $tparams->get('cid_default');
            }
            if ($tparams->get('catid_default')) {
                $item->catid = $tparams->get('catid_default');
            }
        } else {
            // NOTE: This will normally return the already set versioned value of categories ($item->categories)
            $selectedcats = $this->get('Catsselected');
        }
        //$selectedcats 	= $isnew ? array() : $fields['categories']->value;
        //echo "<br/>row->tags: "; print_r($item->tags);
        //echo "<br/>usedtagsIds: "; print_r($usedtagsIds);
        //echo "<br/>usedtags (data): "; print_r($usedtags);
        //echo "<br/>row->categories: "; print_r($item->categories);
        //echo "<br/>selectedcats: "; print_r($selectedcats);
        // *********************************************************************************************
        // Build select lists for the form field. Only few of them are used in J1.6+, since we will use:
        // (a) form XML file to declare them and then (b) getInput() method form field to create them
        // *********************************************************************************************
        // First clean form data, we do this after creating the description field which may contain HTML
        JFilterOutput::objectHTMLSafe($item, ENT_QUOTES);
        $lists = array();
        // build state list
        $non_publishers_stategrp = $perms['isSuperAdmin'] || $item->state == -3 || $item->state == -4;
        $special_privelege_stategrp = $item->state == 2 || $perms['canarchive'] || ($item->state == -2 || $perms['candelete']);
        $state = array();
        // Using <select> groups
        if ($non_publishers_stategrp || $special_privelege_stategrp) {
            $state[] = JHTML::_('select.optgroup', JText::_('FLEXI_PUBLISHERS_WORKFLOW_STATES'));
        }
        $state[] = JHTML::_('select.option', 1, JText::_('FLEXI_PUBLISHED'));
        $state[] = JHTML::_('select.option', 0, JText::_('FLEXI_UNPUBLISHED'));
        $state[] = JHTML::_('select.option', -5, JText::_('FLEXI_IN_PROGRESS'));
        // States reserved for workflow
        if ($non_publishers_stategrp) {
            $state[] = JHTML::_('select.optgroup', '');
            $state[] = JHTML::_('select.optgroup', JText::_('FLEXI_NON_PUBLISHERS_WORKFLOW_STATES'));
        }
        if ($item->state == -3 || $perms['isSuperAdmin']) {
            $state[] = JHTML::_('select.option', -3, JText::_('FLEXI_PENDING'));
        }
        if ($item->state == -4 || $perms['isSuperAdmin']) {
            $state[] = JHTML::_('select.option', -4, JText::_('FLEXI_TO_WRITE'));
        }
        // Special access states
        if ($special_privelege_stategrp) {
            $state[] = JHTML::_('select.optgroup', '');
            $state[] = JHTML::_('select.optgroup', JText::_('FLEXI_SPECIAL_ACTION_STATES'));
        }
        if ($item->state == 2 || $perms['canarchive']) {
            $state[] = JHTML::_('select.option', 2, JText::_('FLEXI_ARCHIVED'));
        }
        if ($item->state == -2 || $perms['candelete']) {
            $state[] = JHTML::_('select.option', -2, JText::_('FLEXI_TRASHED'));
        }
        // Close last <select> group
        if ($non_publishers_stategrp || $special_privelege_stategrp) {
            $state[] = JHTML::_('select.optgroup', '');
        }
        $fieldname = 'jform[state]';
        $elementid = 'jform_state';
        $class = 'use_select2_lib';
        $attribs = 'class="' . $class . '"';
        $lists['state'] = JHTML::_('select.genericlist', $state, $fieldname, $attribs, 'value', 'text', $item->state, $elementid);
        if (!FLEXI_J16GE) {
            $lists['state'] = str_replace('<optgroup label="">', '</optgroup>', $lists['state']);
        }
        // *** BOF: J2.5 SPECIFIC SELECT LISTS
        if (FLEXI_J16GE) {
            // build featured flag
            $fieldname = 'jform[featured]';
            $elementid = 'jform_featured';
            /*
            $options = array();
            $options[] = JHTML::_('select.option',  0, JText::_( 'FLEXI_NO' ) );
            $options[] = JHTML::_('select.option',  1, JText::_( 'FLEXI_YES' ) );
            $attribs = FLEXI_J16GE ? ' style ="float:none!important;" '  :  '';   // this is not right for J1.5' style ="float:left!important;" ';
            $lists['featured'] = JHTML::_('select.radiolist', $options, $fieldname, $attribs, 'value', 'text', $item->featured, $elementid);
            */
            $classes = !$prettycheckable_added ? '' : ' use_prettycheckable ';
            $attribs = ' class="' . $classes . '" ';
            $i = 1;
            $options = array(0 => JText::_('FLEXI_NO'), 1 => JText::_('FLEXI_YES'));
            $lists['featured'] = '';
            foreach ($options as $option_id => $option_label) {
                $checked = $option_id == $item->featured ? ' checked="checked"' : '';
                $elementid_no = $elementid . '_' . $i;
                if (!$prettycheckable_added) {
                    $lists['featured'] .= '<label class="fccheckradio_lbl" for="' . $elementid_no . '">';
                }
                $extra_params = !$prettycheckable_added ? '' : ' data-labeltext="' . JText::_($option_label) . '" data-labelPosition="right" data-customClass="fcradiocheck"';
                $lists['featured'] .= ' <input type="radio" id="' . $elementid_no . '" data-element-grpid="' . $elementid . '" name="' . $fieldname . '" ' . $attribs . ' value="' . $option_id . '" ' . $checked . $extra_params . ' />';
                if (!$prettycheckable_added) {
                    $lists['featured'] .= '&nbsp;' . JText::_($option_label) . '</label>';
                }
                $i++;
            }
        }
        // *** EOF: J1.5 SPECIFIC SELECT LISTS
        // build version approval list
        $fieldname = 'jform[vstate]';
        $elementid = 'jform_vstate';
        /*
        $options = array();
        $options[] = JHTML::_('select.option',  1, JText::_( 'FLEXI_NO' ) );
        $options[] = JHTML::_('select.option',  2, JText::_( 'FLEXI_YES' ) );
        $attribs = FLEXI_J16GE ? ' style ="float:left!important;" '  :  '';   // this is not right for J1.5' style ="float:left!important;" ';
        $lists['vstate'] = JHTML::_('select.radiolist', $options, $fieldname, $attribs, 'value', 'text', 2, $elementid);
        */
        $classes = !$prettycheckable_added ? '' : ' use_prettycheckable ';
        $attribs = ' class="' . $classes . '" ';
        $i = 1;
        $options = array(1 => JText::_('FLEXI_NO'), 2 => JText::_('FLEXI_YES'));
        $lists['vstate'] = '';
        foreach ($options as $option_id => $option_label) {
            $checked = $option_id == 2 ? ' checked="checked"' : '';
            $elementid_no = $elementid . '_' . $i;
            if (!$prettycheckable_added) {
                $lists['vstate'] .= '<label class="fccheckradio_lbl" for="' . $elementid_no . '">';
            }
            $extra_params = !$prettycheckable_added ? '' : ' data-labeltext="' . JText::_($option_label) . '" data-labelPosition="right" data-customClass="fcradiocheck"';
            $lists['vstate'] .= ' <input type="radio" id="' . $elementid_no . '" data-element-grpid="' . $elementid . '" name="' . $fieldname . '" ' . $attribs . ' value="' . $option_id . '" ' . $checked . $extra_params . ' />';
            if (!$prettycheckable_added) {
                $lists['vstate'] .= '&nbsp;' . JText::_($option_label) . '</label>';
            }
            $i++;
        }
        // build field for notifying subscribers
        if (!$subscribers) {
            $lists['notify'] = !$isnew ? JText::_('FLEXI_NO_SUBSCRIBERS_EXIST') : '';
        } else {
            // b. Check if notification emails to subscribers , were already sent during current session
            $subscribers_notified = $session->get('subscribers_notified', array(), 'flexicontent');
            if (!empty($subscribers_notified[$item->id])) {
                $lists['notify'] = JText::_('FLEXI_SUBSCRIBERS_ALREADY_NOTIFIED');
            } else {
                // build favs notify field
                $fieldname = 'jform[notify]';
                $elementid = 'jform_notify';
                /*
                $attribs = FLEXI_J16GE ? ' style ="float:none!important;" '  :  '';   // this is not right for J1.5' style ="float:left!important;" ';
                $lists['notify'] = '<input type="checkbox" name="jform[notify]" id="jform_notify" '.$attribs.' /> '. $lbltxt;
                */
                $classes = !$prettycheckable_added ? '' : ' use_prettycheckable ';
                $attribs = ' class="' . $classes . '" ';
                $lbltxt = $subscribers . ' ' . JText::_($subscribers > 1 ? 'FLEXI_SUBSCRIBERS' : 'FLEXI_SUBSCRIBER');
                if (!$prettycheckable_added) {
                    $lists['notify'] .= '<label class="fccheckradio_lbl" for="' . $elementid . '">';
                }
                $extra_params = !$prettycheckable_added ? '' : ' data-labeltext="' . $lbltxt . '" data-labelPosition="right" data-customClass="fcradiocheck"';
                $lists['notify'] = ' <input type="checkbox" id="' . $elementid . '" data-element-grpid="' . $elementid . '" name="' . $fieldname . '" ' . $attribs . ' value="1" ' . $extra_params . ' checked="checked" />';
                if (!$prettycheckable_added) {
                    $lists['notify'] .= '&nbsp;' . $lbltxt . '</label>';
                }
            }
        }
        // Retrieve author configuration
        $authorparams = flexicontent_db::getUserConfig($user->id);
        // Get author's maximum allowed categories per item and set js limitation
        $max_cat_assign = intval($authorparams->get('max_cat_assign', 0));
        $document->addScriptDeclaration('
			max_cat_assign_fc = ' . $max_cat_assign . ';
			existing_cats_fc  = ["' . implode('","', $selectedcats) . '"];
			max_cat_overlimit_msg_fc = "' . JText::_('FLEXI_TOO_MANY_ITEM_CATEGORIES', true) . '";
		');
        // Creating categorories tree for item assignment, we use the 'create' privelege
        $actions_allowed = array('core.create');
        // Featured categories form field
        $featured_cats_parent = $params->get('featured_cats_parent', 0);
        $featured_cats = array();
        $enable_featured_cid_selector = $perms['multicat'] && $perms['canchange_featcat'];
        if ($featured_cats_parent) {
            $featured_tree = flexicontent_cats::getCategoriesTree($published_only = 1, $parent_id = $featured_cats_parent, $depth_limit = 0);
            $disabled_cats = $params->get('featured_cats_parent_disable', 1) ? array($featured_cats_parent) : array();
            $featured_sel = array();
            foreach ($selectedcats as $item_cat) {
                if (isset($featured_tree[$item_cat])) {
                    $featured_sel[] = $item_cat;
                }
            }
            $class = "use_select2_lib select2_list_selected";
            $attribs = 'class="' . $class . '" multiple="multiple" size="8"';
            $attribs .= $enable_featured_cid_selector ? '' : ' disabled="disabled"';
            $fieldname = 'jform[featured_cid][]';
            $lists['featured_cid'] = ($enable_featured_cid_selector ? '' : '<label class="label" style="float:none; margin:0 6px 0 0 !important;">locked</label>') . flexicontent_cats::buildcatselect($featured_tree, $fieldname, $featured_sel, 3, $attribs, true, true, $actions_allowed, $require_all = true, $skip_subtrees = array(), $disable_subtrees = array(), $custom_options = array(), $disabled_cats);
        } else {
            // Do not display, if not configured or not allowed to the user
            $lists['featured_cid'] = false;
        }
        // Multi-category form field, for user allowed to use multiple categories
        $lists['cid'] = '';
        $enable_cid_selector = $perms['multicat'] && $perms['canchange_seccat'];
        if (1) {
            if ($tparams->get('cid_allowed_parent')) {
                $cid_tree = flexicontent_cats::getCategoriesTree($published_only = 1, $parent_id = $tparams->get('cid_allowed_parent'), $depth_limit = 0);
                $disabled_cats = $tparams->get('cid_allowed_parent_disable', 1) ? array($tparams->get('cid_allowed_parent')) : array();
            } else {
                $cid_tree =& $categories;
                $disabled_cats = array();
            }
            // Get author's maximum allowed categories per item and set js limitation
            $max_cat_assign = !$authorparams ? 0 : intval($authorparams->get('max_cat_assign', 0));
            $document->addScriptDeclaration('
				max_cat_assign_fc = ' . $max_cat_assign . ';
				existing_cats_fc  = ["' . implode('","', $selectedcats) . '"];
				max_cat_overlimit_msg_fc = "' . JText::_('FLEXI_TOO_MANY_ITEM_CATEGORIES', true) . '";
			');
            $class = "mcat use_select2_lib select2_list_selected";
            $class .= $max_cat_assign ? " validate-fccats" : " validate";
            $attribs = 'class="' . $class . '" multiple="multiple" size="20"';
            $attribs .= $enable_cid_selector ? '' : ' disabled="disabled"';
            $fieldname = 'jform[cid][]';
            $skip_subtrees = $featured_cats_parent ? array($featured_cats_parent) : array();
            $lists['cid'] = ($enable_cid_selector ? '' : '<label class="label" style="float:none; margin:0 6px 0 0 !important;">locked</label>') . flexicontent_cats::buildcatselect($cid_tree, $fieldname, $selectedcats, false, $attribs, true, true, $actions_allowed, $require_all = true, $skip_subtrees, $disable_subtrees = array(), $custom_options = array(), $disabled_cats);
        } else {
            if (count($selectedcats) > 1) {
                foreach ($selectedcats as $catid) {
                    $cat_titles[$catid] = $globalcats[$catid]->title;
                }
                $lists['cid'] .= implode(', ', $cat_titles);
            } else {
                $lists['cid'] = false;
            }
        }
        // Main category form field
        $class = 'scat use_select2_lib';
        if ($perms['multicat']) {
            $class .= ' validate-catid';
        } else {
            $class .= ' required';
        }
        $attribs = 'class="' . $class . '"';
        $fieldname = 'jform[catid]';
        $enable_catid_selector = $isnew && !$tparams->get('catid_default') || !$isnew && empty($item->catid) || $perms['canchange_cat'];
        if ($tparams->get('catid_allowed_parent')) {
            $catid_tree = flexicontent_cats::getCategoriesTree($published_only = 1, $parent_id = $tparams->get('catid_allowed_parent'), $depth_limit = 0);
            $disabled_cats = $tparams->get('catid_allowed_parent_disable', 1) ? array($tparams->get('catid_allowed_parent')) : array();
        } else {
            $catid_tree =& $categories;
            $disabled_cats = array();
        }
        $lists['catid'] = false;
        if (!empty($catid_tree)) {
            $disabled = $enable_catid_selector ? '' : ' disabled="disabled"';
            $attribs .= $disabled;
            $lists['catid'] = ($enable_catid_selector ? '' : '<label class="label" style="float:none; margin:0 6px 0 0 !important;">locked</label>') . flexicontent_cats::buildcatselect($catid_tree, $fieldname, $item->catid, 2, $attribs, true, true, $actions_allowed, $require_all = true, $skip_subtrees = array(), $disable_subtrees = array(), $custom_options = array(), $disabled_cats);
        } else {
            if (!$isnew && $item->catid) {
                $lists['catid'] = $globalcats[$item->catid]->title;
            }
        }
        //buid types selectlist
        $class = 'required use_select2_lib';
        $attribs = 'class="' . $class . '"';
        $fieldname = 'jform[type_id]';
        $elementid = 'jform_type_id';
        $lists['type'] = flexicontent_html::buildtypesselect($types, $fieldname, $typesselected->id, 1, $attribs, $elementid, $check_perms = true);
        //build languages list
        $allowed_langs = !$authorparams ? null : $authorparams->get('langs_allowed', null);
        $allowed_langs = !$allowed_langs ? null : FLEXIUtilities::paramToArray($allowed_langs);
        if (!$isnew && $allowed_langs) {
            $allowed_langs[] = $item->language;
        }
        // We will not use the default getInput() function of J1.6+ since we want to create a radio selection field with flags
        // we could also create a new class and override getInput() method but maybe this is an overkill, we may do it in the future
        $lists['languages'] = flexicontent_html::buildlanguageslist('jform[language]', 'class="use_select2_lib"', $item->language, 2, $allowed_langs);
        // Label for current item state: published, unpublished, archived etc
        switch ($item->state) {
            case 0:
                $published = JText::_('FLEXI_UNPUBLISHED');
                break;
            case 1:
                $published = JText::_('FLEXI_PUBLISHED');
                break;
            case -1:
                $published = JText::_('FLEXI_ARCHIVED');
                break;
            case -3:
                $published = JText::_('FLEXI_PENDING');
                break;
            case -5:
                $published = JText::_('FLEXI_IN_PROGRESS');
                break;
            case -4:
            default:
                $published = JText::_('FLEXI_TO_WRITE');
                break;
        }
        // **************************************************************
        // Handle Item Parameters Creation and Load their values for J1.5
        // In J1.6+ we declare them in the item form XML file
        // **************************************************************
        if (!FLEXI_J16GE) {
            // Create the form parameters object
            if (FLEXI_ACCESS) {
                $formparams = new JParameter('', JPATH_COMPONENT . DS . 'models' . DS . 'item2.xml');
            } else {
                $formparams = new JParameter('', JPATH_COMPONENT . DS . 'models' . DS . 'item.xml');
            }
            // Details Group
            $active = intval($item->created_by) ? intval($item->created_by) : $user->get('id');
            if (!FLEXI_ACCESS) {
                $formparams->set('access', $item->access);
            }
            $formparams->set('created_by', $active);
            $formparams->set('created_by_alias', $item->created_by_alias);
            $formparams->set('created', JHTML::_('date', $item->created, '%Y-%m-%d %H:%M:%S'));
            $formparams->set('publish_up', JHTML::_('date', $item->publish_up, '%Y-%m-%d %H:%M:%S'));
            if (JHTML::_('date', $item->publish_down, '%Y') <= 1969 || $item->publish_down == $db->getNullDate() || empty($item->publish_down)) {
                $formparams->set('publish_down', JText::_('FLEXI_NEVER'));
            } else {
                $formparams->set('publish_down', JHTML::_('date', $item->publish_down, '%Y-%m-%d %H:%M:%S'));
            }
            // Advanced Group
            $formparams->loadINI($item->attribs);
            //echo "<pre>"; print_r($formparams->_xml['themes']->_children[0]);  echo "<pre>"; print_r($formparams->_xml['themes']->param[0]); exit;
            foreach ($formparams->_xml['themes']->_children as $i => $child) {
                if (isset($child->_attributes['enableparam']) && !$params->get($child->_attributes['enableparam'])) {
                    unset($formparams->_xml['themes']->_children[$i]);
                    unset($formparams->_xml['themes']->param[$i]);
                }
            }
            // Metadata Group
            $formparams->set('description', $item->metadesc);
            $formparams->set('keywords', $item->metakey);
            $formparams->loadINI($item->metadata);
        } else {
            if (JHTML::_('date', $item->publish_down, 'Y') <= 1969 || $item->publish_down == $db->getNullDate() || empty($item->publish_down)) {
                $form->setValue('publish_down', null, JText::_('FLEXI_NEVER'));
            }
        }
        // ****************************
        // Handle Template related work
        // ****************************
        // (a) Get the templates structures used to create form fields for template parameters
        $themes = flexicontent_tmpl::getTemplates();
        $tmpls_all = $themes->items;
        // (b) Get Content Type allowed templates
        $allowed_tmpls = $tparams->get('allowed_ilayouts');
        $type_default_layout = $tparams->get('ilayout', 'default');
        if (empty($allowed_tmpls)) {
            $allowed_tmpls = array();
        } else {
            if (!is_array($allowed_tmpls)) {
                $allowed_tmpls = explode("|", $allowed_tmpls);
            }
        }
        // (c) Add default layout, unless all templates allowed (=array is empty)
        if (count($allowed_tmpls) && !in_array($type_default_layout, $allowed_tmpls)) {
            $allowed_tmpls[] = $type_default_layout;
        }
        // (d) Create array of template data according to the allowed templates for current content type
        if (count($allowed_tmpls)) {
            foreach ($tmpls_all as $tmpl) {
                if (in_array($tmpl->name, $allowed_tmpls)) {
                    $tmpls[] = $tmpl;
                }
            }
        } else {
            $tmpls = $tmpls_all;
        }
        // (e) Apply Template Parameters values into the form fields structures
        foreach ($tmpls as $tmpl) {
            $jform = new JForm('com_flexicontent.template.item', array('control' => 'jform', 'load_data' => true));
            $jform->load($tmpl->params);
            $tmpl->params = $jform;
            foreach ($tmpl->params->getGroup('attribs') as $field) {
                $fieldname = $field->__get('fieldname');
                $value = $item->itemparams->get($fieldname);
                if (strlen($value)) {
                    $tmpl->params->setValue($fieldname, 'attribs', $value);
                }
            }
        }
        // ******************************
        // Assign data to VIEW's template
        // ******************************
        $this->assignRef('document', $document);
        $this->assignRef('lists', $lists);
        $this->assignRef('row', $item);
        if (FLEXI_J16GE) {
            $this->assignRef('form', $form);
        } else {
            $this->assignRef('editor', $editor);
            $this->assignRef('pane', $pane);
            $this->assignRef('formparams', $formparams);
        }
        if ($enable_translation_groups) {
            $this->assignRef('lang_assocs', $langAssocs);
        }
        if (FLEXI_FISH || FLEXI_J16GE) {
            $this->assignRef('langs', $langs);
        }
        $this->assignRef('typesselected', $typesselected);
        $this->assignRef('published', $published);
        $this->assignRef('nullDate', $nullDate);
        $this->assignRef('subscribers', $subscribers);
        $this->assignRef('fields', $fields);
        $this->assignRef('versions', $versions);
        $this->assignRef('pagecount', $pagecount);
        $this->assignRef('params', $params);
        $this->assignRef('tparams', $tparams);
        $this->assignRef('tmpls', $tmpls);
        $this->assignRef('usedtags', $usedtags);
        $this->assignRef('perms', $perms);
        $this->assignRef('current_page', $current_page);
        // Clear custom form data from session
        $app->setUserState($form->option . '.edit.' . $form->context . '.custom', false);
        $app->setUserState($form->option . '.edit.' . $form->context . '.jfdata', false);
        $app->setUserState($form->option . '.edit.' . $form->context . '.unique_tmp_itemid', false);
        if ($print_logging_info) {
            $start_microtime = microtime(true);
        }
        parent::display($tpl);
        if ($print_logging_info) {
            $fc_run_times['form_rendering'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10;
        }
    }
Ejemplo n.º 12
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->show_page_heading = $this->_show_page_heading;
                $data->limited_options = $this->frontend ? $data->limited_article_options_fe : $data->limited_article_options;
                $data->form_id = $this->_id;
                $data->record_id = $this->_record_id;
                if ($data->type && $data->reference_id) {
                    // article options
                    $this->_db->setQuery("Select content.id, content.modified_by, content.version, content.hits, content.catid From #__contentbuilder_articles As articles, #__content As content Where (content.state = 1 Or content.state = 0) And content.id = articles.article_id And articles.form_id = " . $this->_id . " And articles.record_id = " . $this->_db->Quote($this->_record_id));
                    $article = $this->_db->loadAssoc();
                    if ($data->create_articles) {
                        if (!$this->is15) {
                            // JOOMLA 1.6 params retrieval
                            jimport('joomla.form.form');
                            JForm::addFormPath(JPATH_SITE . '/administrator/components/com_contentbuilder/models/forms');
                            JForm::addFieldPath(JPATH_SITE . '/administrator/components/com_content/models/fields');
                            $form = JForm::getInstance('com_content.article', 'article', array('control' => 'jform', 'load_data' => true));
                            if (is_array($article)) {
                                $table = JTable::getInstance('content');
                                $loaded = $table->load($article['id']);
                                if ($loaded) {
                                    // Convert to the JObject before adding other data.
                                    $properties = $table->getProperties(1);
                                    $item = JArrayHelper::toObject($properties, 'JObject');
                                    if (property_exists($item, 'params')) {
                                        $registry = new JRegistry();
                                        if (!$this->is30) {
                                            $registry->loadJSON($item->params);
                                        } else {
                                            $registry->loadString($item->params);
                                        }
                                        $item->params = $registry->toArray();
                                    }
                                    // Convert the params field to an array.
                                    $registry = new JRegistry();
                                    if (!$this->is30) {
                                        $registry->loadJSON($item->attribs);
                                    } else {
                                        $registry->loadString($item->attribs);
                                    }
                                    $item->attribs = $registry->toArray();
                                    // Convert the params field to an array.
                                    $registry = new JRegistry();
                                    if (!$this->is30) {
                                        $registry->loadJSON($item->metadata);
                                    } else {
                                        $registry->loadString($item->metadata);
                                    }
                                    $item->metadata = $registry->toArray();
                                    $item->articletext = trim($item->fulltext) != '' ? $item->introtext . "<hr id=\"system-readmore\" />" . $item->fulltext : $item->introtext;
                                    // Import the approriate plugin group.
                                    JPluginHelper::importPlugin('content');
                                    // Get the dispatcher.
                                    $dispatcher = JDispatcher::getInstance();
                                    // Trigger the form preparation event.
                                    $results = $dispatcher->trigger('onContentPrepareForm', array($form, $item));
                                    // Check for errors encountered while preparing the form.
                                    if (count($results) && in_array(false, $results, true)) {
                                        // Get the last error.
                                        $error = $dispatcher->getError();
                                        // Convert to a JException if necessary.
                                        if (!JError::isError($error)) {
                                            throw new Exception($error);
                                        }
                                    }
                                    $form->bind($item);
                                    $data->sectioncategories = array();
                                    $data->row = $item;
                                    $data->lists = array();
                                } else {
                                    $data->sectioncategories = array();
                                    $data->row = new stdClass();
                                    $data->row->title = '';
                                    $data->row->alias = '';
                                    // special for 1.5
                                    $data->lists = array('state' => '', 'frontpage' => '', 'sectionid' => '', 'catid' => '');
                                    // special for 1.5
                                }
                                $data->article_settings = new stdClass();
                                $data->article_settings->modified_by = $article['modified_by'];
                                $data->article_settings->version = $article['version'];
                                $data->article_settings->hits = $article['hits'];
                                $data->article_settings->catid = $article['catid'];
                            } else {
                                $data->article_settings = new stdClass();
                                $data->article_settings->modified_by = 0;
                                $data->article_settings->version = 0;
                                $data->article_settings->hits = 0;
                                $data->article_settings->catid = 0;
                            }
                            $data->article_options = $form;
                            // article options end
                            // Joomla 1.6 params retrieval end
                        } else {
                            // Joomla 1.5 params retrieval
                            if (!$data->limited_options) {
                                $form = new JParameter('', JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_content' . DS . 'models' . DS . 'article.xml');
                            } else {
                                $form = new JParameter('', JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'assets' . DS . 'article.xml');
                            }
                            $table = JTable::getInstance('content');
                            // sections
                            $javascript = "onchange=\"changeDynaList( 'catid', sectioncategories, document.adminForm.sectionid.options[document.adminForm.sectionid.selectedIndex].value, 0, 0);\"";
                            $query = 'SELECT s.id, s.title' . ' FROM #__sections AS s' . ' ORDER BY s.ordering';
                            $this->_db->setQuery($query);
                            $seections = array();
                            $sections[] = JHTML::_('select.option', '-1', '- ' . JText::_('Select Section') . ' -', 'id', 'title');
                            $sections[] = JHTML::_('select.option', '0', JText::_('Uncategorized'), 'id', 'title');
                            $sections = array_merge($sections, $this->_db->loadObjectList());
                            // categories
                            foreach ($sections as $section) {
                                $section_list[] = (int) $section->id;
                            }
                            $sectioncategories = array();
                            $sectioncategories[-1] = array();
                            $sectioncategories[-1][] = JHTML::_('select.option', '-1', JText::_('Select Category'), 'id', 'title');
                            $section_list = implode('\', \'', $section_list);
                            $query = 'SELECT id, title, section' . ' FROM #__categories' . ' WHERE section IN ( \'' . $section_list . '\' )' . ' ORDER BY ordering';
                            $this->_db->setQuery($query);
                            $cat_list = $this->_db->loadObjectList();
                            // Uncategorized category mapped to uncategorized section
                            $uncat = new stdClass();
                            $uncat->id = 0;
                            $uncat->title = JText::_('Uncategorized');
                            $uncat->section = 0;
                            $cat_list[] = $uncat;
                            foreach ($sections as $section) {
                                $sectioncategories[$section->id] = array();
                                $rows2 = array();
                                foreach ($cat_list as $cat) {
                                    if ($cat->section == $section->id) {
                                        $rows2[] = $cat;
                                    }
                                }
                                foreach ($rows2 as $row2) {
                                    $sectioncategories[$section->id][] = JHTML::_('select.option', $row2->id, $row2->title, 'id', 'title');
                                }
                            }
                            $sectioncategories['-1'][] = JHTML::_('select.option', '-1', JText::_('Select Category'), 'id', 'title');
                            $categories = array();
                            foreach ($cat_list as $cat) {
                                $categories[] = $cat;
                            }
                            $categories[] = JHTML::_('select.option', '-1', JText::_('Select Category'), 'id', 'title');
                            if (is_array($article)) {
                                $loaded = $table->load($article['id']);
                                if ($loaded) {
                                    // Convert to the JObject before adding other data.
                                    $properties = $table->getProperties(1);
                                    $item = JArrayHelper::toObject($properties, 'JObject');
                                    $form->set('created_by', $item->created_by);
                                    $form->set('access', $item->access);
                                    $form->set('created_by_alias', $item->created_by_alias);
                                    $form->set('created', JHTML::_('date', $item->created, '%Y-%m-%d %H:%M:%S'));
                                    $form->set('publish_up', JHTML::_('date', $item->publish_up, '%Y-%m-%d %H:%M:%S'));
                                    if (JHTML::_('date', $item->publish_down, '%Y') <= 1969 || $item->publish_down == $this->_db->getNullDate()) {
                                        $form->set('publish_down', JText::_('Never'));
                                    } else {
                                        $form->set('publish_down', JHTML::_('date', $item->publish_down, '%Y-%m-%d %H:%M:%S'));
                                    }
                                    // Advanced Group
                                    $form->loadINI($item->attribs);
                                    // Metadata Group
                                    $form->set('description', $item->metadesc);
                                    $form->set('keywords', $item->metakey);
                                    $form->loadINI($item->metadata);
                                    $lists['state'] = JHTML::_('select.booleanlist', 'state', '', $item->state);
                                    $query = 'SELECT COUNT(content_id)' . ' FROM #__content_frontpage' . ' WHERE content_id = ' . (int) $item->id;
                                    $this->_db->setQuery($query);
                                    $item->frontpage = $this->_db->loadResult();
                                    if (!$item->frontpage) {
                                        $item->frontpage = 0;
                                    }
                                    $lists['frontpage'] = JHTML::_('select.booleanlist', 'frontpage', '', $item->frontpage);
                                    $lists['sectionid'] = JHTML::_('select.genericlist', $sections, 'sectionid', 'class="inputbox" size="1" ' . $javascript, 'id', 'title', intval($item->sectionid));
                                    $lists['catid'] = JHTML::_('select.genericlist', $categories, 'catid', 'class="inputbox" size="1"', 'id', 'title', intval($item->catid));
                                    $query = 'SELECT ordering AS value, title AS text FROM #__content WHERE catid = ' . (int) $data->default_category . ' AND state > ' . (int) "-1" . ' ORDER BY ordering';
                                    $lists['ordering'] = JHTML::_('list.specificordering', $table, $article['id'], $query, 1);
                                    $data->sectioncategories = $sectioncategories;
                                    $data->row = $item;
                                    // special for 1.5
                                    $data->lists = $lists;
                                } else {
                                    $data->sectioncategories = $sectioncategories;
                                    $data->row = $table;
                                    // special for 1.5
                                    $fplist = JHTML::_('select.booleanlist', 'frontpage', '', 0);
                                    $sectionid = JHTML::_('select.genericlist', $sections, 'sectionid', 'class="inputbox" size="1" ' . $javascript, 'id', 'title', intval($item->sectionid));
                                    $catid = JHTML::_('select.genericlist', $categories, 'catid', 'class="inputbox" size="1"', 'id', 'title', 0);
                                    // Select List: Category Ordering
                                    $query = 'SELECT ordering AS value, title AS text FROM #__content WHERE catid = ' . (int) $data->default_category . ' AND state > ' . (int) "-1" . ' ORDER BY ordering';
                                    $olist = JHTML::_('list.specificordering', $table, 0, $query, 1);
                                    $data->lists = array('ordering' => $olist, 'state' => '', 'frontpage' => $fplist, 'sectionid' => $sectionid, 'catid' => $catid);
                                    // special for 1.5
                                }
                                $data->article_settings = new stdClass();
                                $data->article_settings->modified_by = $article['modified_by'];
                                $data->article_settings->version = $article['version'];
                                $data->article_settings->hits = $article['hits'];
                                $data->article_settings->catid = $article['catid'];
                            } else {
                                $data->sectioncategories = $sectioncategories;
                                $data->row = $table;
                                // special for 1.5
                                $fplist = JHTML::_('select.booleanlist', 'frontpage', '', 0);
                                $sectionid = JHTML::_('select.genericlist', $sections, 'sectionid', 'class="inputbox" size="1" ' . $javascript, 'id', 'title', 0);
                                $catid = JHTML::_('select.genericlist', $categories, 'catid', 'class="inputbox" size="1"', 'id', 'title', 0);
                                // Select List: Category Ordering
                                $query = 'SELECT ordering AS value, title AS text FROM #__content WHERE catid = ' . (int) $data->default_category . ' AND state > ' . (int) "-1" . ' ORDER BY ordering';
                                $olist = JHTML::_('list.specificordering', $table, 0, $query, 1);
                                $data->lists = array('ordering' => $olist, 'state' => '', 'frontpage' => $fplist, 'sectionid' => $sectionid, 'catid' => $catid);
                                // special for 1.5
                                $data->article_settings = new stdClass();
                                $data->article_settings->modified_by = 0;
                                $data->article_settings->version = 0;
                                $data->article_settings->hits = 0;
                                $data->article_settings->catid = 0;
                            }
                            $data->article_options = $form;
                            // Joomla 1.5 params retrieval end
                        }
                    }
                    $data->back_button = JRequest::getBool('latest', 0) && !JRequest::getCmd('record_id', '') ? false : $this->_show_back_button;
                    $data->latest = $this->_latest;
                    $data->is15 = $this->is15;
                    $data->frontend = $this->frontend;
                    $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();
                        }
                    }
                    $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'];
                        }
                    }
                    $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;
                            }
                        }
                        // 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 ? '' : ': ') . $label : '';
                            }
                        } 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 ? '' : ': ') . $label : '';
                            }
                        }
                        if ($this->frontend) {
                            $document = JFactory::getDocument();
                            $document->setTitle(html_entity_decode($data->page_title, ENT_QUOTES, 'UTF-8'));
                        }
                    }
                    //if(!$data->edit_by_type){
                    $i = 0;
                    $api_items = '';
                    $api_names = $data->form->getElementNames();
                    $cntItems = count($api_names);
                    foreach ($api_names as $reference_id => $api_name) {
                        $api_items .= '"' . addslashes($api_name) . '": "' . addslashes($reference_id) . '"' . ($i + 1 < $cntItems ? ',' : '');
                        $i++;
                    }
                    $items = $api_items;
                    JFactory::getDocument()->addScriptDeclaration('
<!--
var contentbuilder = new function(){

   this.items = {' . $items . '};
   var items = this.items;

   this._ = function(name){
     var els = document.getElementsByName("cb_"+items[name]);
     if(els.length == 0){
        els = document.getElementsByName("cb_"+items[name]+"[]");
     }
     return els.length == 1 ? els[0] : els;
   };
   
   var _ = this._;

   this.urldecode = function (str) {
       return decodeURIComponent((str+\'\').replace(/\\+/g, \'%20\'));
   };

   this.getQuery = function ( name ){
       name = name.replace(/[\\[]/,"\\\\[").replace(/[\\]]/,"\\\\]");  
       var regexS = "[\\?&]"+name+"=([^&#]*)";  
       var regex = new RegExp( regexS );
       var results = regex.exec( window.location.href ); 
       if( results == null ){
           return null;
       } else {
           return this.urldecode(results[1]);
       }
   };

   this.onClick = function(name, func){
        if(typeof func != "function") return;
        var els = document.getElementsByName("cb_"+items[name]);
        if(els.length == 0){
            els = document.getElementsByName("cb_"+items[name]+"[]");
        }
        for(var i = 0; i < els.length; i++){
            els[i].onclick = func;
        }
   };
   this.onFocus = function(name, func){
        if(typeof func != "function") return;
        var els = document.getElementsByName("cb_"+items[name]);
        if(els.length == 0){
            els = document.getElementsByName("cb_"+items[name]+"[]");
        }
        for(var i = 0; i < els.length; i++){
            els[i].onfocus = func;
        }
   };
   this.onBlur = function(name, func){
        if(typeof func != "function") return;
        var els = document.getElementsByName("cb_"+items[name]);
        if(els.length == 0){
            els = document.getElementsByName("cb_"+items[name]+"[]");
        }
        for(var i = 0; i < els.length; i++){
            els[i].onblur = func;
        }
   };
   this.onChange = function(name, func){
        if(typeof func != "function") return;
        var els = document.getElementsByName("cb_"+items[name]);
        if(els.length == 0){
            els = document.getElementsByName("cb_"+items[name]+"[]");
        }
        for(var i = 0; i < els.length; i++){
            els[i].onchange = func;
        }
   };
   this.onSelect = function(name, func){
        if(typeof func != "function") return;
        var els = document.getElementsByName("cb_"+items[name]);
        if(els.length == 0){
            els = document.getElementsByName("cb_"+items[name]+"[]");
        }
        for(var i = 0; i < els.length; i++){
            els[i].onselect = func;
        }
   };
   
   this.submitReady = function(){ return true; };
   var _submitReady = this.submitReady;
   this.onSubmit = function(){ if(arguments.length > 0 && typeof arguments[0] == "function") { _submitReady = arguments[0]; return; } if(typeof _submitReady == "function" && _submitReady()) { document.adminForm.submit(); } };
}
//-->
');
                    //}
                    $data->template = contentbuilder::getEditableTemplate($this->_id, $this->_record_id, $data->items, $ids, !$data->edit_by_type);
                    $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 : '';
                    } else {
                        $data->created = '';
                        $data->created_by = '';
                        $data->modified = '';
                        $data->modified_by = '';
                    }
                }
                return $data;
            }
        }
        return null;
    }
Ejemplo n.º 13
0
 function display($tpl = null)
 {
     //initialise variables
     $app = JFactory::getApplication();
     $document = JFactory::getDocument();
     $cparams = JComponentHelper::getParams('com_flexicontent');
     $user = JFactory::getUser();
     //add css to document
     $document->addStyleSheet(JURI::base() . 'components/com_flexicontent/assets/css/flexicontentbackend.css');
     if (FLEXI_J30GE) {
         $document->addStyleSheet(JURI::base() . 'components/com_flexicontent/assets/css/j3x.css');
     } else {
         if (FLEXI_J16GE) {
             $document->addStyleSheet(JURI::base() . 'components/com_flexicontent/assets/css/j25.css');
         } else {
             $document->addStyleSheet(JURI::base() . 'components/com_flexicontent/assets/css/j15.css');
         }
     }
     //add js function to overload the joomla submitform
     FLEXI_J30GE ? JHtml::_('behavior.framework', true) : JHTML::_('behavior.mootools');
     JHTML::_('behavior.tooltip');
     flexicontent_html::loadFramework('jQuery');
     flexicontent_html::loadFramework('select2');
     $document->addScript(JURI::root() . 'components/com_flexicontent/assets/js/admin.js');
     $document->addScript(JURI::root() . 'components/com_flexicontent/assets/js/validate.js');
     //Load pane behavior
     jimport('joomla.html.pane');
     //Import File system
     jimport('joomla.filesystem.file');
     //Get data from the model
     $model = $this->getModel();
     $row = $this->get('Field');
     if (FLEXI_J16GE) {
         $form = $this->get('Form');
     }
     $types = $this->get('Typeslist');
     $typesselected = $this->get('Typesselected');
     //create the toolbar
     if ($row->id) {
         JToolBarHelper::title(JText::_('FLEXI_EDIT_FIELD'), 'fieldedit');
     } else {
         JToolBarHelper::title(JText::_('FLEXI_ADD_FIELD'), 'fieldadd');
     }
     $ctrl = FLEXI_J16GE ? 'fields.' : '';
     JToolBarHelper::apply($ctrl . 'apply');
     JToolBarHelper::save($ctrl . 'save');
     JToolBarHelper::custom($ctrl . 'saveandnew', 'savenew.png', 'savenew.png', 'FLEXI_SAVE_AND_NEW', false);
     JToolBarHelper::cancel($ctrl . 'cancel');
     // Import Joomla plugin that implements the type of current flexi field
     JPluginHelper::importPlugin('flexicontent_fields', $row->iscore ? 'core' : $row->field_type);
     // load plugin's english language file then override with current language file
     $extension_name = 'plg_flexicontent_fields_' . ($row->iscore ? 'core' : $row->field_type);
     JFactory::getLanguage()->load($extension_name, JPATH_ADMINISTRATOR, 'en-GB', true);
     JFactory::getLanguage()->load($extension_name, JPATH_ADMINISTRATOR, null, true);
     //check which properties are supported by current field
     $ft_support = FlexicontentFields::getPropertySupport($row->field_type, $row->iscore);
     $supportsearch = $ft_support->supportsearch;
     $supportadvsearch = $ft_support->supportadvsearch;
     $supportfilter = $ft_support->supportfilter;
     $supportadvfilter = $ft_support->supportadvfilter;
     $supportuntranslatable = $ft_support->supportuntranslatable;
     $supportvalueseditable = $ft_support->supportvalueseditable;
     $supportformhidden = $ft_support->supportformhidden;
     $supportedithelp = $ft_support->supportedithelp;
     //build selectlists, (for J1.6+ most of these are defined via XML file and custom form field classes)
     $lists = array();
     //build field_type list
     if (!$row->field_type) {
         $row->field_type = 'text';
     }
     if ($row->iscore == 1) {
         $class = 'disabled="disabled"';
     } else {
         $class = '';
         $_field_id = '#' . (FLEXI_J16GE ? 'jform_' : '') . 'field_type';
         $_row_id = FLEXI_J16GE ? $form->getValue("id") : $row->id;
         $_ctrl_task = FLEXI_J16GE ? 'task=fields.getfieldspecificproperties' : 'controller=fields&task=getfieldspecificproperties';
         $document->addScriptDeclaration("\n\t\t\t\tjQuery(document).ready(function() {\n\t\t\t\t\tjQuery('" . $_field_id . "').on('change', function() {\n\t\t\t\t\t\tjQuery('#fieldspecificproperties').html('<p class=\"centerimg\"><img src=\"components/com_flexicontent/assets/images/ajax-loader.gif\" align=\"center\"></p>');\n\t\t\t\t\t\tjQuery.ajax({\n\t\t\t\t\t\t\ttype: \"GET\",\n\t\t\t\t\t\t\turl: 'index.php?option=com_flexicontent&" . $_ctrl_task . "&cid=" . $_row_id . "&field_type='+this.value+'&format=raw',\n\t\t\t\t\t\t\tsuccess: function(str) {\n\t\t\t\t\t\t\t\tjQuery('#fieldspecificproperties').html(str);\n\t\t\t\t\t\t\t\tvar JTooltips = new Tips(jQuery('#fieldspecificproperties .hasTip'), { maxTitleChars: 50, fixed: false});\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tjQuery('#field_typename').html(jQuery('" . $_field_id . "').val());\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t");
     }
     //build field select list
     $lists['field_type'] = flexicontent_html::buildfieldtypeslist('field_type', $class, $row->field_type, $group = true);
     //build type select list
     $attribs = 'class="use_select2_lib" multiple="multiple" size="6"';
     $attribs .= $row->iscore ? ' disabled="disabled"' : '';
     $types_fieldname = FLEXI_J16GE ? 'jform[tid][]' : 'tid[]';
     $lists['tid'] = flexicontent_html::buildtypesselect($types, $types_fieldname, $typesselected, false, $attribs);
     // **************************************************************************
     // Create fields for J1.5 (J2.5+ uses JForm XML file for most of form fields)
     // **************************************************************************
     if (!FLEXI_J16GE) {
         //build formhidden selector
         $formhidden[] = JHTML::_('select.option', 0, JText::_('FLEXI_NO'));
         $formhidden[] = JHTML::_('select.option', 1, JText::_('FLEXI_FRONTEND'));
         $formhidden[] = JHTML::_('select.option', 2, JText::_('FLEXI_BACKEND'));
         $formhidden[] = JHTML::_('select.option', 3, JText::_('FLEXI_BOTH'));
         $formhidden_fieldname = FLEXI_J16GE ? 'jform[formhidden]' : 'formhidden';
         $lists['formhidden'] = JHTML::_('select.radiolist', $formhidden, $formhidden_fieldname, '', 'value', 'text', $row->formhidden);
         if (FLEXI_ACCESS) {
             $valueseditable[] = JHTML::_('select.option', 0, JText::_('FLEXI_ANY_EDITOR'));
             $valueseditable[] = JHTML::_('select.option', 1, JText::_('FLEXI_USE_ACL_PERMISSION'));
             $valueseditable_fieldname = FLEXI_J16GE ? 'jform[valueseditable]' : 'valueseditable';
             $lists['valueseditable'] = JHTML::_('select.radiolist', $valueseditable, $valueseditable_fieldname, '', 'value', 'text', $row->valueseditable);
         }
         $edithelp[] = JHTML::_('select.option', 0, JText::_('FLEXI_EDIT_HELP_NONE'));
         $edithelp[] = JHTML::_('select.option', 1, JText::_('FLEXI_EDIT_HELP_LABEL_TOOLTIP'));
         $edithelp[] = JHTML::_('select.option', 2, JText::_('FLEXI_EDIT_HELP_LABEL_TOOLTIP_WICON'));
         $edithelp[] = JHTML::_('select.option', 3, JText::_('FLEXI_EDIT_HELP_INLINE'));
         $edithelp_fieldname = FLEXI_J16GE ? 'jform[edithelp]' : 'edithelp';
         $lists['edithelp'] = JHTML::_('select.radiolist', $edithelp, $edithelp_fieldname, '', 'value', 'text', $row->edithelp);
         // build the html select list for ordering
         $query = 'SELECT ordering AS value, label AS text' . ' FROM #__flexicontent_fields' . ' WHERE published >= 0' . ' ORDER BY ordering';
         $row->ordering = @$row->ordering;
         $lists['ordering'] = $row->id ? JHTML::_('list.specificordering', $row, $row->id, $query) : JHTML::_('list.specificordering', $row, '', $query);
         //build access level list
         if (FLEXI_ACCESS) {
             $lang = JFactory::getLanguage();
             $lang->_strings['FLEXIACCESS_PADD'] = 'Edit-Value';
             $lists['access'] = FAccess::TabGmaccess($row, 'field', 1, 1, 0, 1, 0, 1, 0, 1, 1);
         } else {
             $lists['access'] = JHTML::_('list.accesslevel', $row);
         }
     }
     if (!FLEXI_J16GE) {
         // Create the parameter 's form object parsing the file XML
         $pluginpath = JPATH_PLUGINS . DS . 'flexicontent_fields' . DS . $row->field_type . '.xml';
         if (JFile::exists($pluginpath)) {
             $form = new JParameter('', $pluginpath);
         } else {
             $form = new JParameter('', JPATH_PLUGINS . DS . 'flexicontent_fields' . DS . 'core.xml');
         }
         // Special and Core Groups
         $form->loadINI($row->attribs);
     }
     // fail if checked out not by 'me'
     if ($row->id) {
         if ($model->isCheckedOut($user->get('id'))) {
             JError::raiseWarning('SOME_ERROR_CODE', $row->name . ' ' . JText::_('FLEXI_EDITED_BY_ANOTHER_ADMIN'));
             $app->redirect('index.php?option=com_flexicontent&view=fields');
         }
     }
     //clean data
     JFilterOutput::objectHTMLSafe($row, ENT_QUOTES);
     // assign permissions for J2.5
     if (FLEXI_J16GE) {
         $permission = FlexicontentHelperPerm::getPerm();
         $this->assignRef('permission', $permission);
     }
     //assign data to template
     $this->assignRef('document', $document);
     $this->assignRef('row', $row);
     $this->assignRef('lists', $lists);
     $this->assignRef('form', $form);
     $this->assignRef('typesselected', $typesselected);
     $this->assignRef('supportsearch', $supportsearch);
     $this->assignRef('supportadvsearch', $supportadvsearch);
     $this->assignRef('supportfilter', $supportfilter);
     $this->assignRef('supportadvfilter', $supportadvfilter);
     $this->assignRef('supportuntranslatable', $supportuntranslatable);
     $this->assignRef('supportvalueseditable', $supportvalueseditable);
     $this->assignRef('supportformhidden', $supportformhidden);
     $this->assignRef('supportedithelp', $supportedithelp);
     parent::display($tpl);
 }
Ejemplo n.º 14
0
    function edit()
    {
        $mainframe =& JFactory::getApplication();
        jimport('joomla.filesystem.file');
        jimport('joomla.html.pane');
        $db =& JFactory::getDBO();
        JHTML::_('behavior.mootools');
        $document =& JFactory::getDocument();
        $document->addScript(JURI::root() . 'administrator/components/com_k2/lib/Autocompleter.js');
        $document->addScript(JURI::root() . 'administrator/components/com_k2/lib/observer.js');
        $document->addScript(JURI::root() . 'administrator/components/com_k2/lib/simpletabs_1.3.js');
        //$document->addScript(JURI::root().'administrator/components/com_k2/js/k2.js'); // Core JS
        $document->addScript(JURI::root() . 'administrator/components/com_k2/js/k2.mootools.js');
        // Mootools based JS
        $document->addCustomTag('
        
<!-- K2 by JoomlaWorks (start) -->
		
	<!-- Load Khepri styling -->
	<link rel="stylesheet" href="' . JURI::root() . 'administrator/templates/system/css/system.css" type="text/css" />
	<link href="' . JURI::root() . 'administrator/templates/khepri/css/template.css" rel="stylesheet" type="text/css" />
	<!--[if IE 7]>
	<link href="' . JURI::root() . 'administrator/templates/khepri/css/ie7.css" rel="stylesheet" type="text/css" />
	<![endif]-->
	<!--[if lte IE 6]>
	<link href="' . JURI::root() . 'administrator/templates/khepri/css/ie6.css" rel="stylesheet" type="text/css" />
	<![endif]-->
	<link rel="stylesheet" type="text/css" href="' . JURI::root() . 'administrator/templates/khepri/css/rounded.css" />
	
	<!-- Load K2 styling -->
	<link href="' . JURI::root() . 'administrator/components/com_k2/css/k2.css" rel="stylesheet" type="text/css" />
	<!--[if IE 7]>
	<link href="' . JURI::root() . 'administrator/components/com_k2/css/k2_ie7.css" rel="stylesheet" type="text/css" />
	<![endif]-->
	<!--[if lte IE 6]>
	<link href="' . JURI::root() . 'administrator/components/com_k2/css/k2_ie6.css" rel="stylesheet" type="text/css" />
	<![endif]-->
		
<!-- K2 by JoomlaWorks (end) -->

		');
        JRequest::setVar('tmpl', 'component');
        require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'item.php';
        $model = new K2ModelItem();
        $task = JRequest::getCmd('task');
        $user =& JFactory::getUser();
        if ($task == 'edit') {
            $item = $model->getData();
            JFilterOutput::objectHTMLSafe($item, ENT_QUOTES, 'video');
            if (!K2HelperPermissions::canEditItem($item->created_by, $item->catid)) {
                JError::raiseError(403, JText::_("ALERTNOTAUTH"));
            }
            if (JTable::isCheckedOut($user->get('id'), $item->checked_out)) {
                $msg = JText::sprintf('DESCBEINGEDITTED', JText::_('The item'), $item->title);
                $mainframe->redirect('index.php?option=com_k2&view=item&id=' . $item->id . '&tmpl=component', $msg);
            }
        } elseif ($task == 'add') {
            if (!K2HelperPermissions::canAddItem()) {
                JError::raiseError(403, JText::_("ALERTNOTAUTH"));
            }
            JTable::addIncludePath(JPATH_COMPONENT . DS . 'tables');
            $item =& JTable::getInstance('K2Item', 'Table');
            $createdate =& JFactory::getDate();
            $item->published = 1;
            $item->publish_up = $createdate->toUnix();
            $item->publish_down = JText::_('Never');
            $item->created = $createdate->toUnix();
            $item->modified = $db->getNullDate();
        }
        if ($item->id) {
            $item->checkout($user->get('id'));
        }
        $item->created = JHTML::_('date', $item->created, '%Y-%m-%d %H:%M:%S');
        $item->publish_up = JHTML::_('date', $item->publish_up, '%Y-%m-%d %H:%M:%S');
        if (JHTML::_('date', $item->publish_down, '%Y') <= 1969 || $item->publish_down == $db->getNullDate()) {
            $item->publish_down = JText::_('Never');
        } else {
            $item->publish_down = JHTML::_('date', $item->publish_down, '%Y-%m-%d %H:%M:%S');
        }
        $params =& JComponentHelper::getParams('com_k2');
        $wysiwyg =& JFactory::getEditor();
        if ($params->get("mergeEditors")) {
            if (JString::strlen($item->fulltext) > 1) {
                $textValue = $item->introtext . "<hr id=\"system-readmore\" />" . $item->fulltext;
            } else {
                $textValue = $item->introtext;
            }
            $text = $wysiwyg->display('text', $textValue, '100%', '400', '40', '5', array('pagebreak'));
            $this->assignRef('text', $text);
        } else {
            $introtext = $wysiwyg->display('introtext', $item->introtext, '100%', '400', '40', '5', array('pagebreak', 'readmore'));
            $this->assignRef('introtext', $introtext);
            $fulltext = $wysiwyg->display('fulltext', $item->fulltext, '100%', '400', '40', '5', array('pagebreak', 'readmore'));
            $this->assignRef('fulltext', $fulltext);
        }
        $lists = array();
        $lists['published'] = JHTML::_('select.booleanlist', 'published', 'class="inputbox"', $item->published);
        $lists['access'] = JHTML::_('list.accesslevel', $item);
        $query = "SELECT ordering AS value, title AS text FROM #__k2_items WHERE catid={$item->catid}";
        $lists['ordering'] = JHTML::_('list.specificordering', $item, $item->id, $query);
        require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'categories.php';
        $categoriesModel = new K2ModelCategories();
        $categories = $categoriesModel->categoriesTree();
        $lists['catid'] = JHTML::_('select.genericlist', $categories, 'catid', 'class="inputbox"', 'value', 'text', $item->catid);
        $lists['checkSIG'] = $model->checkSIG();
        $lists['checkAllVideos'] = $model->checkAllVideos();
        $remoteVideo = false;
        $providerVideo = false;
        $embedVideo = false;
        $options['startOffset'] = 0;
        if (stristr($item->video, 'remote}') !== false) {
            $remoteVideo = true;
            $options['startOffset'] = 1;
        }
        $providers = $model->getVideoProviders();
        if (count($providers)) {
            foreach ($providers as $provider) {
                $providersOptions[] = JHTML::_('select.option', $provider, $provider);
                if (stristr($item->video, "{{$provider}}") !== false) {
                    $providerVideo = true;
                    $options['startOffset'] = 2;
                }
            }
        }
        if (JString::substr($item->video, 0, 1) !== '{') {
            $embedVideo = true;
            $options['startOffset'] = 3;
        }
        $lists['uploadedVideo'] = !$remoteVideo && !$providerVideo && !$embedVideo ? true : false;
        if ($lists['uploadedVideo']) {
            $options['startOffset'] = 0;
        }
        $lists['remoteVideo'] = $remoteVideo ? preg_replace('%\\{[a-z0-9-_]*\\}(.*)\\{/[a-z0-9-_]*\\}%i', '\\1', $item->video) : '';
        $lists['remoteVideoType'] = $remoteVideo ? preg_replace('%\\{([a-z0-9-_]*)\\}.*\\{/[a-z0-9-_]*\\}%i', '\\1', $item->video) : '';
        $lists['providerVideo'] = $providerVideo ? preg_replace('%\\{[a-z0-9-_]*\\}(.*)\\{/[a-z0-9-_]*\\}%i', '\\1', $item->video) : '';
        $lists['providerVideoType'] = $providerVideo ? preg_replace('%\\{([a-z0-9-_]*)\\}.*\\{/[a-z0-9-_]*\\}%i', '\\1', $item->video) : '';
        $lists['embedVideo'] = $embedVideo ? $item->video : '';
        if (count($providers)) {
            $lists['providers'] = JHTML::_('select.genericlist', $providersOptions, 'videoProvider', '', 'value', 'text', $lists['providerVideoType']);
        }
        JPluginHelper::importPlugin('content', 'jw_sigpro');
        JPluginHelper::importPlugin('content', 'jw_sig');
        JPluginHelper::importPlugin('content', 'jw_allvideos');
        $dispatcher =& JDispatcher::getInstance();
        $params->set('galleries_rootfolder', 'media/k2/galleries');
        $params->set('thb_width', '150');
        $params->set('thb_height', '120');
        $params->set('popup_engine', 'mootools_slimbox');
        $params->set('enabledownload', '0');
        $item->text = $item->gallery;
        $dispatcher->trigger('onPrepareContent', array(&$item, &$params, null));
        $item->gallery = $item->text;
        if (!$embedVideo) {
            $params->set('vfolder', 'media/k2/videos');
            $item->text = $item->video;
            $dispatcher->trigger('onPrepareContent', array(&$item, &$params, null));
            $item->video = $item->text;
        } else {
            $item->video = '<div>' . $item->video . '</div>';
        }
        if (isset($item->created_by)) {
            $author =& JUser::getInstance($item->created_by);
            $item->author = $author->name;
        }
        if (isset($item->modified_by)) {
            $moderator =& JUser::getInstance($item->modified_by);
            $item->moderator = $moderator->name;
        }
        if ($task == 'edit') {
            $item->editor = $item->author;
        } else {
            $item->editor = $user->name;
        }
        require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'categories.php';
        $categoriesModel = new K2ModelCategories();
        $categories_option[] = JHTML::_('select.option', 0, JText::_('- Select category -'));
        $categories = $categoriesModel->categoriesTree();
        if (($task == 'add' || $task == 'edit') && !$user->authorize('com_k2', 'add', 'category', 'all')) {
            for ($i = 0; $i < sizeof($categories); $i++) {
                if (!$user->authorize('com_k2', 'add', 'category', $categories[$i]->value)) {
                    $categories[$i]->disable = true;
                }
            }
        }
        $categories_options = @array_merge($categories_option, $categories);
        $lists['categories'] = JHTML::_('select.genericlist', $categories_options, 'catid', '', 'value', 'text', $item->catid);
        JTable::addIncludePath(JPATH_COMPONENT . DS . 'tables');
        $category =& JTable::getInstance('K2Category', 'Table');
        $category->load($item->catid);
        require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'extrafield.php';
        $extraFieldModel = new K2ModelExtraField();
        if ($category->extraFieldsGroup) {
            $extraFields = $extraFieldModel->getExtraFieldsByGroup($category->extraFieldsGroup);
        } else {
            $extraFields = NULL;
        }
        for ($i = 0; $i < sizeof($extraFields); $i++) {
            $extraFields[$i]->element = $extraFieldModel->renderExtraField($extraFields[$i], $item->id);
        }
        if ($item->id) {
            $item->attachments = $model->getAttachments($item->id);
        } else {
            $item->attachments = NULL;
        }
        $tags = $model->getAvailableTags($item->id);
        $lists['tags'] = JHTML::_('select.genericlist', $tags, 'tags', 'multiple="multiple" size="10" ', 'id', 'name');
        if (isset($item->id)) {
            $item->tags = $model->getCurrentTags($item->id);
            $lists['selectedTags'] = JHTML::_('select.genericlist', $item->tags, 'selectedTags[]', 'multiple="multiple" size="10" ', 'id', 'name');
        } else {
            $lists['selectedTags'] = '<select size="10" multiple="multiple" id="selectedTags" name="selectedTags[]"></select>';
        }
        if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_L.jpg')) {
            $item->image = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $item->id) . '_L.jpg';
        }
        if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_S.jpg')) {
            $item->thumb = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $item->id) . '_S.jpg';
        }
        $lists['metadata'] = new JParameter($item->metadata);
        JPluginHelper::importPlugin('k2');
        $dispatcher =& JDispatcher::getInstance();
        $K2PluginsItemContent = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'content'));
        $this->assignRef('K2PluginsItemContent', $K2PluginsItemContent);
        $K2PluginsItemImage = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'image'));
        $this->assignRef('K2PluginsItemImage', $K2PluginsItemImage);
        $K2PluginsItemGallery = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'gallery'));
        $this->assignRef('K2PluginsItemGallery', $K2PluginsItemGallery);
        $K2PluginsItemVideo = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'video'));
        $this->assignRef('K2PluginsItemVideo', $K2PluginsItemVideo);
        $K2PluginsItemExtraFields = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'extra-fields'));
        $this->assignRef('K2PluginsItemExtraFields', $K2PluginsItemExtraFields);
        $K2PluginsItemAttachments = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'attachments'));
        $this->assignRef('K2PluginsItemAttachments', $K2PluginsItemAttachments);
        $K2PluginsItemOther = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'other'));
        $this->assignRef('K2PluginsItemOther', $K2PluginsItemOther);
        $form = new JParameter('', JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'item.xml');
        $form->loadINI($item->params);
        $this->assignRef('form', $form);
        $this->assignRef('extraFields', $extraFields);
        $this->assignRef('options', $options);
        $this->assignRef('row', $item);
        $this->assignRef('lists', $lists);
        $this->assignRef('params', $params);
        parent::display();
    }
Ejemplo n.º 15
0
 function displayDefault()
 {
     global $mainframe, $hgconf;
     //Load pane behavior
     jimport('joomla.html.pane');
     JHTML::_('behavior.tooltip');
     //initialise variables
     $editor =& JFactory::getEditor();
     $document =& JFactory::getDocument();
     $user =& JFactory::getUser();
     $db =& JFactory::getDBO();
     $lang =& JFactory::getLanguage();
     $tabs =& JPane::getInstance('tabs');
     $pane =& JPane::getInstance('sliders');
     $nullDate = $db->getNullDate();
     $cid = JRequest::getVar('cid');
     $document->addScript(JURI::base() . 'components/com_hotelguide/assets/js/itemscreen.js');
     //create the toolbar
     if ($cid) {
         JToolBarHelper::title(JText::_('HG_EDIT_ACCOMMODATION'), 'hotelguide');
     } else {
         JToolBarHelper::title(JText::_('HG_NEW_ACCOMMODATION'), 'hotelguide');
     }
     JToolBarHelper::apply();
     JToolBarHelper::save();
     JToolBarHelper::custom('saveandnew', 'savenew.png', 'savenew.png', 'HG_SAVE_AND_NEW', false);
     JToolBarHelper::cancel();
     //Get data from the model
     $model =& $this->getModel();
     $row =& $this->get('Item');
     $images =& $this->get('Gallery');
     $rooms =& $this->get('Rooms');
     $promotions =& $this->get('Promotions');
     $restaurants =& $this->get('Restaurants');
     $spas =& $this->get('Spas');
     // fail if checked out not by 'me'
     if ($row->id) {
         if ($model->isCheckedOut($user->get('id'))) {
             JError::raiseWarning('SOME_ERROR_CODE', $row->title . ' ' . JText::_('HG_EDITED_BY_ANOTHER_ADMIN'));
             $mainframe->redirect('index.php?option=com_hotelguide&view=hotelguide');
         }
     }
     //clean data
     JFilterOutput::objectHTMLSafe($row, ENT_QUOTES);
     //build selectlists
     $lists = array();
     // Create the form
     $form = new JParameter('', HOTELGUIDE_MODELS . DS . 'hotelitem.xml');
     // Details Group
     $active = intval($row->created_by) ? intval($row->created_by) : $user->get('id');
     $form->set('created_by', $active);
     $form->set('user_id_hotel', $row->user_id_hotel);
     $form->set('created_by_alias', $row->created_by_alias);
     $form->set('created', JHTML::_('date', $row->created, '%Y-%m-%d %H:%M:%S'));
     // Metadata Group
     if (!$row->meta_description && $row->id > 0) {
         $form->set('description', $row->title);
     } else {
         $form->set('description', $row->meta_description);
     }
     if (!$row->meta_keywords && $row->id > 0) {
         $form->set('keywords', $row->title);
     } else {
         $form->set('keywords', $row->meta_keywords);
     }
     $form->loadINI($row->metadata);
     //build state list
     $published[] = JHTML::_('select.option', 1, JText::_('HG_PUBLISHED'));
     $published[] = JHTML::_('select.option', 0, JText::_('HG_UNPUBLISHED'));
     $lists['published'] = JHTML::_('select.genericlist', $published, 'published', '', 'value', 'text', $row->published);
     //build stear rate list
     $starrate[] = JHTML::_('select.option', 0, JText::_('HG_NONE'));
     $starrate[] = JHTML::_('select.option', 1, JText::_('HG_1STAR'));
     $starrate[] = JHTML::_('select.option', 2, JText::_('HG_2STARS'));
     $starrate[] = JHTML::_('select.option', 3, JText::_('HG_3STARS'));
     $starrate[] = JHTML::_('select.option', 4, JText::_('HG_4STARS'));
     $starrate[] = JHTML::_('select.option', 5, JText::_('HG_5STARS'));
     $lists['starrate'] = JHTML::_('select.genericlist', $starrate, 'starrate', '', 'value', 'text', $row->starrate);
     //assign data to template
     $this->assignRef('hgconf', $hgconf);
     $this->assignRef('lists', $lists);
     $this->assignRef('row', $row);
     $this->assignRef('tabs', $tabs);
     $this->assignRef('pane', $pane);
     $this->assignRef('nullDate', $nullDate);
     $this->assignRef('form', $form);
     $this->assignRef('images', $images);
     $this->assignRef('rooms', $rooms);
     $this->assignRef('promotions', $promotions);
     $this->assignRef('restaurants', $restaurants);
     $this->assignRef('spas', $spas);
     /*
     		echo "<pre>";
     		echo "view=";
     		print_r($row);
     		echo "</pre>"; 
     */
 }
Ejemplo n.º 16
0
 function display($tpl = null)
 {
     $mainframe =& JFactory::getApplication();
     $db =& JFactory::getDBO();
     jimport('joomla.filesystem.file');
     jimport('joomla.html.pane');
     JHTML::_('behavior.keepalive');
     JRequest::setVar('hidemainmenu', 1);
     $document =& JFactory::getDocument();
     $document->addScript(JURI::root() . 'administrator/components/com_k2/lib/Autocompleter.js');
     $document->addScript(JURI::root() . 'administrator/components/com_k2/lib/observer.js');
     $document->addScript(JURI::root() . 'administrator/components/com_k2/lib/nicEdit.js');
     $js = "function initExtraFieldsEditor(){\n\t\t\t\$\$('.k2ExtraFieldEditor').each(function(element) {\n\t\t\t\tvar id = element.id;\n\t\t\t\tif (typeof JContentEditor != 'undefined') {\n\t\t\t\t\tif (tinyMCE.get(id)) {\n\t\t\t\t\t\ttinymce.EditorManager.remove(tinyMCE.get(id));\n\t\t\t\t\t}\n\t\t\t\t\ttinyMCE.execCommand('mceAddControl', false, id);\n\t\t\t\t} else {\n\t\t\t\t\tnew nicEditor({fullPanel: true, maxHeight: 180, iconsPath: '" . JURI::root() . "administrator/components/com_k2/images/system/nicEditorIcons.gif'}).panelInstance(element.getProperty('id'));\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t\tfunction syncExtraFieldsEditor(){\n\t\t\t\$\$('.k2ExtraFieldEditor').each(function(element){\n\t\t\t\teditor = nicEditors.findEditor(element.getProperty('id'));\n\t\t\t\tif(typeof editor != 'undefined'){\n\t\t\t\t\teditor.saveContent();\n\t\t\t\t}\n    \t\t});\n\t\t}\n\t\t";
     $document->addScriptDeclaration($js);
     $model =& $this->getModel();
     $item = $model->getData();
     JFilterOutput::objectHTMLSafe($item, ENT_QUOTES, 'video');
     $user =& JFactory::getUser();
     if (JTable::isCheckedOut($user->get('id'), $item->checked_out)) {
         $msg = JText::sprintf('DESCBEINGEDITTED', JText::_('The item'), $item->title);
         $mainframe->redirect('index.php?option=com_k2', $msg);
     }
     if ($item->id) {
         $item->checkout($user->get('id'));
     } else {
         $createdate =& JFactory::getDate();
         $item->published = 1;
         $item->publish_up = $createdate->toUnix();
         $item->publish_down = JText::_('Never');
         $item->created = $createdate->toUnix();
         $item->modified = $db->getNullDate();
     }
     $item->created = JHTML::_('date', $item->created, '%Y-%m-%d %H:%M:%S');
     $item->publish_up = JHTML::_('date', $item->publish_up, '%Y-%m-%d %H:%M:%S');
     if (JHTML::_('date', $item->publish_down, '%Y') <= 1969 || $item->publish_down == $db->getNullDate()) {
         $item->publish_down = JText::_('Never');
     } else {
         $item->publish_down = JHTML::_('date', $item->publish_down, '%Y-%m-%d %H:%M:%S');
     }
     $params =& JComponentHelper::getParams('com_k2');
     $wysiwyg =& JFactory::getEditor();
     if ($params->get("mergeEditors")) {
         if (JString::strlen($item->fulltext) > 1) {
             $textValue = $item->introtext . "<hr id=\"system-readmore\" />" . $item->fulltext;
         } else {
             $textValue = $item->introtext;
         }
         $text = $wysiwyg->display('text', $textValue, '100%', '400', '40', '5');
         $this->assignRef('text', $text);
     } else {
         $introtext = $wysiwyg->display('introtext', $item->introtext, '100%', '400', '40', '5', array('readmore'));
         $this->assignRef('introtext', $introtext);
         $fulltext = $wysiwyg->display('fulltext', $item->fulltext, '100%', '400', '40', '5', array('readmore'));
         $this->assignRef('fulltext', $fulltext);
     }
     $lists = array();
     $lists['published'] = JHTML::_('select.booleanlist', 'published', 'class="inputbox"', $item->published);
     $lists['access'] = JHTML::_('list.accesslevel', $item);
     $query = "SELECT ordering AS value, title AS text FROM #__k2_items WHERE catid={$item->catid}";
     $lists['ordering'] = JHTML::_('list.specificordering', $item, $item->id, $query);
     if (!$item->id) {
         $item->catid = $mainframe->getUserStateFromRequest('com_k2itemsfilter_category', 'catid', 0, 'int');
     }
     require_once JPATH_COMPONENT . DS . 'models' . DS . 'categories.php';
     $categoriesModel = new K2ModelCategories();
     $categories = $categoriesModel->categoriesTree();
     $lists['catid'] = JHTML::_('select.genericlist', $categories, 'catid', 'class="inputbox"', 'value', 'text', $item->catid);
     $lists['checkSIG'] = $model->checkSIG();
     $lists['checkAllVideos'] = $model->checkAllVideos();
     $remoteVideo = false;
     $providerVideo = false;
     $embedVideo = false;
     if (stristr($item->video, 'remote}') !== false) {
         $remoteVideo = true;
         $options['startOffset'] = 1;
     }
     $providers = $model->getVideoProviders();
     if (count($providers)) {
         foreach ($providers as $provider) {
             $providersOptions[] = JHTML::_('select.option', $provider, $provider);
             if (stristr($item->video, "{{$provider}}") !== false) {
                 $providerVideo = true;
                 $options['startOffset'] = 2;
             }
         }
     }
     if (JString::substr($item->video, 0, 1) !== '{') {
         $embedVideo = true;
         $options['startOffset'] = 3;
     }
     $lists['uploadedVideo'] = !$remoteVideo && !$providerVideo && !$embedVideo ? true : false;
     if ($lists['uploadedVideo'] || $item->video == '') {
         $options['startOffset'] = 0;
     }
     $lists['remoteVideo'] = $remoteVideo ? preg_replace('%\\{[a-z0-9-_]*\\}(.*)\\{/[a-z0-9-_]*\\}%i', '\\1', $item->video) : '';
     $lists['remoteVideoType'] = $remoteVideo ? preg_replace('%\\{([a-z0-9-_]*)\\}.*\\{/[a-z0-9-_]*\\}%i', '\\1', $item->video) : '';
     $lists['providerVideo'] = $providerVideo ? preg_replace('%\\{[a-z0-9-_]*\\}(.*)\\{/[a-z0-9-_]*\\}%i', '\\1', $item->video) : '';
     $lists['providerVideoType'] = $providerVideo ? preg_replace('%\\{([a-z0-9-_]*)\\}.*\\{/[a-z0-9-_]*\\}%i', '\\1', $item->video) : '';
     $lists['embedVideo'] = $embedVideo ? $item->video : '';
     if (isset($providersOptions)) {
         $lists['providers'] = JHTML::_('select.genericlist', $providersOptions, 'videoProvider', '', 'value', 'text', $lists['providerVideoType']);
     }
     JPluginHelper::importPlugin('content', 'jw_sigpro');
     JPluginHelper::importPlugin('content', 'jw_allvideos');
     $dispatcher =& JDispatcher::getInstance();
     $params->set('galleries_rootfolder', 'media/k2/galleries');
     $params->set('thb_width', '150');
     $params->set('thb_height', '120');
     $params->set('popup_engine', 'mootools_slimbox');
     $params->set('enabledownload', '0');
     $item->text = $item->gallery;
     $dispatcher->trigger('onPrepareContent', array(&$item, &$params, null));
     $item->gallery = $item->text;
     if (!$embedVideo) {
         $params->set('vfolder', 'media/k2/videos');
         if (JString::strpos($item->video, 'remote}')) {
             preg_match("#}(.*?){/#s", $item->video, $matches);
             if (JString::substr($matches[1], 0, 7) != 'http://') {
                 $item->video = JString::str_ireplace($matches[1], JURI::root() . $matches[1], $item->video);
             }
         }
         $item->text = $item->video;
         $dispatcher->trigger('onPrepareContent', array(&$item, &$params, null));
         $item->video = $item->text;
     } else {
         // no nothing
     }
     if (isset($item->created_by)) {
         $author =& JUser::getInstance($item->created_by);
         $item->author = $author->name;
     }
     if (isset($item->modified_by)) {
         $moderator =& JUser::getInstance($item->modified_by);
         $item->moderator = $moderator->name;
     }
     if ($item->id) {
         $active = $item->created_by;
     } else {
         $active = $user->id;
     }
     $lists['authors'] = JHTML::_('list.users', 'created_by', $active, false);
     require_once JPATH_COMPONENT . DS . 'models' . DS . 'categories.php';
     $categoriesModel = new K2ModelCategories();
     $categories_option[] = JHTML::_('select.option', 0, JText::_('- Select category -'));
     $categories = $categoriesModel->categoriesTree(NUll, true, false);
     $categories_options = @array_merge($categories_option, $categories);
     $lists['categories'] = JHTML::_('select.genericlist', $categories_options, 'catid', '', 'value', 'text', $item->catid);
     JTable::addIncludePath(JPATH_COMPONENT . DS . 'tables');
     $category =& JTable::getInstance('K2Category', 'Table');
     $category->load($item->catid);
     require_once JPATH_COMPONENT . DS . 'models' . DS . 'extrafield.php';
     $extraFieldModel = new K2ModelExtraField();
     if ($item->id) {
         $extraFields = $extraFieldModel->getExtraFieldsByGroup($category->extraFieldsGroup);
     } else {
         $extraFields = NULL;
     }
     for ($i = 0; $i < sizeof($extraFields); $i++) {
         $extraFields[$i]->element = $extraFieldModel->renderExtraField($extraFields[$i], $item->id);
     }
     if ($item->id) {
         $item->attachments = $model->getAttachments($item->id);
         $rating = $model->getRating();
         if (is_null($rating)) {
             $item->ratingSum = 0;
             $item->ratingCount = 0;
         } else {
             $item->ratingSum = (int) $rating->rating_sum;
             $item->ratingCount = (int) $rating->rating_count;
         }
     } else {
         $item->attachments = NULL;
         $item->ratingSum = 0;
         $item->ratingCount = 0;
     }
     if ($user->gid < 24 && $params->get('lockTags')) {
         $params->set('taggingSystem', 0);
     }
     $tags = $model->getAvailableTags($item->id);
     $lists['tags'] = JHTML::_('select.genericlist', $tags, 'tags', 'multiple="multiple" size="10" ', 'id', 'name');
     if (isset($item->id)) {
         $item->tags = $model->getCurrentTags($item->id);
         $lists['selectedTags'] = JHTML::_('select.genericlist', $item->tags, 'selectedTags[]', 'multiple="multiple" size="10" ', 'id', 'name');
     } else {
         $lists['selectedTags'] = '<select size="10" multiple="multiple" id="selectedTags" name="selectedTags[]"></select>';
     }
     $lists['metadata'] = new JParameter($item->metadata);
     if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_L.jpg')) {
         $item->image = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $item->id) . '_L.jpg';
     }
     if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_S.jpg')) {
         $item->thumb = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $item->id) . '_S.jpg';
     }
     JPluginHelper::importPlugin('k2');
     $dispatcher =& JDispatcher::getInstance();
     $K2PluginsItemContent = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'content'));
     $this->assignRef('K2PluginsItemContent', $K2PluginsItemContent);
     $K2PluginsItemImage = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'image'));
     $this->assignRef('K2PluginsItemImage', $K2PluginsItemImage);
     $K2PluginsItemGallery = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'gallery'));
     $this->assignRef('K2PluginsItemGallery', $K2PluginsItemGallery);
     $K2PluginsItemVideo = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'video'));
     $this->assignRef('K2PluginsItemVideo', $K2PluginsItemVideo);
     $K2PluginsItemExtraFields = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'extra-fields'));
     $this->assignRef('K2PluginsItemExtraFields', $K2PluginsItemExtraFields);
     $K2PluginsItemAttachments = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'attachments'));
     $this->assignRef('K2PluginsItemAttachments', $K2PluginsItemAttachments);
     $K2PluginsItemOther = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'other'));
     $this->assignRef('K2PluginsItemOther', $K2PluginsItemOther);
     $form = new JParameter('', JPATH_COMPONENT . DS . 'models' . DS . 'item.xml');
     $form->loadINI($item->params);
     $this->assignRef('form', $form);
     $this->assignRef('extraFields', $extraFields);
     $this->assignRef('options', $options);
     $this->assignRef('row', $item);
     $this->assignRef('lists', $lists);
     $this->assignRef('params', $params);
     $this->assignRef('user', $user);
     JRequest::getInt('cid') ? $title = JText::_('Edit Item') : ($title = JText::_('Add Item'));
     JToolBarHelper::title($title, 'k2.png');
     JToolBarHelper::save();
     JToolBarHelper::custom('saveAndNew', 'save.png', 'save_f2.png', 'Save &amp; New', false);
     JToolBarHelper::apply();
     JToolBarHelper::cancel();
     parent::display($tpl);
 }
Ejemplo n.º 17
0
 function removeOnePhotoActivity($app, $uniqueId, $datetime, $photoId, $thumbnail)
 {
     $db = JFactory::getDBO();
     $query = 'SELECT * FROM ' . $db->nameQuote('#__community_activities') . ' ' . 'WHERE ' . $db->nameQuote('app') . '=' . $db->Quote($app) . ' ' . 'AND ' . $db->nameQuote('cid') . '=' . $db->Quote($uniqueId) . ' ' . 'AND ( ' . $db->nameQuote('created') . ' BETWEEN ' . $db->Quote($datetime) . ' ' . 'AND ( ADDTIME(' . $db->Quote($datetime) . ', ' . $db->Quote('00:00:05') . ' ) ) ) ';
     $db->setQuery($query);
     $result = $db->loadObjectList();
     if ($db->getErrorNum()) {
         JError::raiseError(500, $db->stderr());
     }
     $activityId = null;
     $handler = new JParameter(null);
     // the activity data contains photoid and the photo thumbnail
     // which can be useful for us to find the correct activity id
     foreach ($result as $activity) {
         $handler->loadINI($activity->params);
         if ($handler->getValue('photoid') == $photoId) {
             $activityId = $activity->id;
             break;
         }
         if (JString::strpos($activity->content, $thumbnail) !== false) {
             $activityId = $activity->id;
             break;
         }
     }
     if (is_null($activityId)) {
         return $this->removeOneActivity($app, $uniqueId);
     }
     $query = 'DELETE FROM ' . $db->nameQuote('#__community_activities') . ' ' . 'WHERE ' . $db->nameQuote('id') . '=' . $db->Quote($activityId) . ' ' . 'LIMIT 1 ';
     $db->setQuery($query);
     $status = $db->query();
     if ($db->getErrorNum()) {
         JError::raiseError(500, $db->stderr());
     }
     return $status;
 }
Ejemplo n.º 18
0
 /**
  * Edit a table
  */
 function edit()
 {
     $app =& JFactory::getApplication();
     $session =& JFactory::getSession();
     $session->clear('com_fabrik.admin.table.edit.model');
     require_once JPATH_COMPONENT . DS . 'views' . DS . 'table.php';
     $user =& JFactory::getUser();
     $db =& JFactory::getDBO();
     $row =& JTable::getInstance('table', 'Table');
     $acl =& JFactory::getACL();
     $config =& JFactory::getConfig();
     if ($this->_task == 'edit') {
         $cid = JRequest::getVar('cid', array(0), 'method', 'array');
         $cid = array((int) $cid[0]);
     } else {
         $cid = array(0);
     }
     $connectionTables = array();
     //  this only appears if you are automatically creating the table from an existing form - which has no table associated with it
     $fabrikid = JRequest::getVar('fabrikid', '', 'get');
     $row->load($cid[0]);
     $params = new fabrikParams($row->attribs, JPATH_COMPONENT . DS . 'model' . DS . 'table.xml');
     $lists['tablejoin'] = "";
     //$lists['defaultJoinTables'] = '[]';
     $lists['defaultJoinTables'] = array();
     $lists['linkedtables'] = array();
     $connModel =& JModel::getInstance('Connection', 'FabrikModel');
     $model =& JModel::getInstance('Table', 'FabrikModel');
     $model->setId($cid[0]);
     $model->_table =& $row;
     $formModel =& $model->getForm();
     $aJoinObjs = array();
     if ($this->_task != 'edit') {
         $row->template = 'default';
         $realCnns = $connModel->getConnections();
         $defaultCid = '';
         foreach ($realCnns as $realCnn) {
             if ($realCnn->default == 1) {
                 $defaultCid = $realCnn->id;
             }
         }
         $javascript = "onchange=\"changeDynaList('db_table_name', connectiontables, document.adminForm.connection_id.options[document.adminForm.connection_id.selectedIndex].value, 0, 0);\"";
         $lists['connections'] = $connModel->getConnectionsDd($realCnns, $javascript, 'connection_id', $defaultCid);
         $connectionTables = $connModel->getConnectionTables($realCnns);
         $javascript = '';
         $lists['tablename'] = '<select name="db_table_name" id="tablename" class="inputbox" size="1" >';
         if ($defaultCid == '') {
             $lists['tablename'] .= '<option value="" selected="selected">' . JText::_('CHOOSE A CONNECTION FIRST') . '</option>';
         } else {
             foreach ($connectionTables[$defaultCid] as $t) {
                 $lists['tablename'] .= '<option value="' . $t->value . '">' . $t->text . '</option>';
             }
         }
         $lists['tablename'] .= '</select>';
         $lists['order_by'][] = JText::_('AVAILABLE AFTER TABLE SAVED');
         $lists['group_by'] = JText::_('AVAILABLE AFTER TABLE SAVED');
         $lists['filter-fields'] = JText::_('AVAILABLE AFTER TABLE SAVED');
         $lists['db_primary_key'] = JText::_('AVAILABLE AFTER TABLE SAVED');
     } else {
         //if record already exists then you can't change the form or table it points to
         // fail if checked out not by 'me'
         if ($row->checked_out && $row->checked_out != $user->get('id')) {
             $app->redirect('index.php?option=com_fabrik', 'The connection ' . $row->description . ' is currently being edited by another administrator');
         }
         $row->checkout($user->get('id'));
         if ($row->connection_id != "-1") {
             $sql = "SELECT description FROM #__fabrik_connections WHERE id = " . (int) $row->connection_id;
             $db->setQuery($sql);
             $lists['connections'] = $db->loadResult();
             $lists['tablename'] = "<input type='hidden' name='db_table_name' value='{$row->db_table_name}' />{$row->db_table_name}";
         } else {
             $lists['connections'] = "no database";
             $lists['tablename'] = "no table";
         }
         $lists['connections'] .= "<input type=\"hidden\" value=\"{$row->connection_id}\" id=\"connection_id\" name=\"connection_id\" />";
         $formModel->setId($row->form_id);
         $formTable =& $formModel->getForm();
         $formModel->getGroupsHiarachy();
         //table join info
         $sql = "SELECT * FROM #__fabrik_joins WHERE table_id = " . (int) $row->id . " AND element_id = 0";
         $db->setQuery($sql);
         $aJoinObjs = $db->loadObjectList();
         $lists['joins'] =& $aJoinObjs;
         $lists['order_by'] = array();
         $orderbys = explode(GROUPSPLITTER2, $row->order_by);
         foreach ($orderbys as $orderby) {
             $lists['order_by'][] = $formModel->getElementList('order_by[]', $orderby, true, false, true);
         }
         $lists['group_by'] = $formModel->getElementList('group_by', $row->group_by, true, false, true);
         //needs to be table.element format for where statement to work
         $formModel->_addDbQuote = true;
         $lists['filter-fields'] = $formModel->getElementList('params[filter-fields][]', '', false, false, true);
         $lists['db_primary_key'] = $formModel->getElementList('db_primary_key', $row->db_primary_key);
         $formModel->_addDbQuote = false;
         //but you can now add table joins
         $connModel->setId($row->connection_id);
         $connModel->getConnection($row->connection_id);
         ///load in current connection
         $joinFromTables[] = JHTML::_('select.option', '', '-');
         $joinFromTables[] = JHTML::_('select.option', $row->db_table_name, $row->db_table_name);
         $lists['defaultjoin'] = $connModel->getTableDdForThisConnection('', 'table_join[]', '', 'inputbox table_key');
         $lists['tablejoin'] = $connModel->getTableDdForThisConnection('', 'table_join[]', '', 'inputbox table_join_key');
         //make a drop down validation type for each validation
         $aActiveJoinTypes = array();
         if (is_array($aJoinObjs)) {
             for ($ff = 0; $ff < count($aJoinObjs); $ff++) {
                 $oJoin = $aJoinObjs[$ff];
                 $fields = array();
                 $aFields = $model->getDBFields($oJoin->join_from_table);
                 foreach ($aFields as $o) {
                     if (is_array($o)) {
                         foreach ($o as $f) {
                             $fields[] = $f->Field;
                         }
                     } else {
                         $fields[] = $o->Field;
                     }
                 }
                 $aJoinObjs[$ff]->joinFormFields = $fields;
                 $aFields = $model->getDBFields($oJoin->table_join);
                 $fields = array();
                 foreach ($aFields as $o) {
                     if (is_array($o)) {
                         foreach ($o as $f) {
                             $fields[] = $f->Field;
                         }
                     } else {
                         $fields[] = $o->Field;
                     }
                 }
                 $aJoinObjs[$ff]->joinToFields = $fields;
             }
             $lists['defaultJoinTables'] = $connModel->getThisTables(true);
         }
     }
     if ($row->id != '') {
         //only existing tables can have a menu linked to them
         $and = "\n AND link LIKE '%index.php?option=com_fabrik%' AND link LIKE '%view=table%'";
         $and .= " AND params LIKE '%tableid=" . $row->id . "'";
         $menus = FabrikHelperMenu::Links2Menu('component', $and);
     } else {
         $menus = null;
     }
     $lists['filter-access'] = $this->getFilterACLList($row);
     $lists['menuselect'] = FabrikHelperMenu::MenuSelect();
     $lists['tableTemplates'] = FabrikHelperAdminHTML::templateList('table', 'template', $row->template);
     // make the filter action drop down
     $filterActions[] = JHTML::_('select.option', 'onchange', JText::_('ON CHANGE'));
     $filterActions[] = JHTML::_('select.option', 'submitform', JText::_('SUBMIT FORM'));
     $lists['filter_action'] = JHTML::_('select.genericlist', $filterActions, 'filter_action', 'class="inputbox" size="1" ', 'value', 'text', $row->filter_action);
     //make the order direction drop down
     $orderDir[] = JHTML::_('select.option', 'ASC', JText::_('ASCENDING'));
     $orderDir[] = JHTML::_('select.option', 'DESC', JText::_('DESCENDING'));
     $orderdirs = explode(GROUPSPLITTER2, $row->order_dir);
     $lists['order_dir'] = array();
     foreach ($orderdirs as $orderdir) {
         $lists['order_dir'][] = JHTML::_('select.genericlist', $orderDir, 'order_dir[]', 'class="inputbox" size="1" ', 'value', 'text', $orderdir);
     }
     $linkedTables = $model->getJoinsToThisKey();
     $aExisitngLinkedTables = $params->get('linkedtable', '', '_default', 'array');
     $aExisitngLinkedForms = $params->get('linkedform', '', '_default', 'array');
     $aExistingTableHeaders = $params->get('linkedtableheader', '', '_default', 'array');
     $aExistingFormHeaders = $params->get('linkedformheader', '', '_default', 'array');
     $linkedform_linktype = $params->get('linkedform_linktype', '', '_default', 'array');
     $linkedtable_linktype = $params->get('linkedtable_linktype', '', '_default', 'array');
     $tableLinkTexts = $params->get('linkedtabletext', '', '_default', 'array');
     $formLinkTexts = $params->get('linkedformtext', '', '_default', 'array');
     $lists['linkedtables'] = array();
     $f = 0;
     $used = array();
     foreach ($linkedTables as $linkedTable) {
         $key = $linkedTable->table_id . '-' . $linkedTable->form_id . '-' . $linkedTable->element_id;
         if (!array_key_exists($f, $aExisitngLinkedTables)) {
             $aExisitngLinkedTables[$f] = '0';
         }
         if (!array_key_exists($f, $linkedtable_linktype)) {
             $linkedtable_linktype[$f] = '0';
         }
         //fiddle ordering
         $index = array_search($key, $aExisitngLinkedTables);
         $index = $index === false ? $f : $index;
         if (!array_search($key, $aExisitngLinkedTables)) {
             for ($fcounter = 0; $fcounter <= count($linkedTables); $fcounter++) {
                 if (!in_array($fcounter, $used)) {
                     $index = $fcounter;
                     break;
                 }
             }
         }
         $used[] = $index;
         $yeschecked = in_array($linkedTable->db_table_name, $aExisitngLinkedTables) || JArrayHelper::getValue($aExisitngLinkedTables, $index, 0) != '0' ? 'checked="checked"' : ($checked = '');
         $nochecked = $yeschecked == '' ? 'checked="checked"' : ($checked = '');
         $el = '<label><input name="params[linkedtable][' . $key . ']" value="0" ' . $nochecked . ' type="radio">' . JText::_('NO') . '</label>';
         $el .= '<label><input name="params[linkedtable][' . $key . ']" value="' . $key . '" ' . $yeschecked . ' type="radio">' . JText::_('YES') . '</label>';
         $yeschecked = in_array($linkedTable->db_table_name, $linkedtable_linktype) || JArrayHelper::getValue($linkedtable_linktype, $index, 0) != '0' ? 'checked="checked"' : ($checked = '');
         $nochecked = $yeschecked == '' ? 'checked="checked"' : ($checked = '');
         $linkType1 = '<label><input name="params[linkedtable_linktype][' . $key . ']" value="0" ' . $nochecked . ' type="radio">' . JText::_('NO') . '</label>';
         $linkType1 .= '<label><input name="params[linkedtable_linktype][' . $key . ']" value="' . $key . '" ' . $yeschecked . ' type="radio">' . JText::_('YES') . '</label>';
         $tableHeader = '<input name="params[linkedtableheader][' . $key . ']" value="' . @$aExistingTableHeaders[$index] . '" size="16" >';
         $label = str_replace(array("\n", "\r", "<br>", "</br>"), '', $linkedTable->tablelabel);
         $hover = JText::_('ELEMENT') . ': ' . $linkedTable->element_label . " [{$linkedTable->plugin}]. {tmpl key =" . $linkedTable->element_id . "_table_heading}";
         $tableLinkText = '<input name="params[linkedtabletext][' . $key . ']" value="' . @$tableLinkTexts[$index] . '" size="16" >';
         $linkedArray = array($label, $hover, $el, $tableHeader, $linkType1, $tableLinkText);
         $lists['linkedtables'][$index] = $linkedArray;
     }
     ksort($lists['linkedtables']);
     $lists['linkedforms'] = array();
     $f = 0;
     $used = array();
     /***/
     foreach ($linkedTables as $linkedTable) {
         $key = $linkedTable->table_id . '-' . $linkedTable->form_id . '-' . $linkedTable->element_id;
         if (!array_key_exists($f, $aExisitngLinkedForms)) {
             $aExisitngLinkedForms[$f] = '0';
         }
         if (!array_key_exists($f, $linkedform_linktype)) {
             $linkedform_linktype[$f] = '0';
         }
         //fiddle ordering
         $index = array_search($key, $aExisitngLinkedForms);
         $index = $index === false ? $f : $index;
         if (!array_search($key, $aExisitngLinkedForms)) {
             for ($fcounter = 0; $fcounter <= count($linkedTables); $fcounter++) {
                 if (!in_array($fcounter, $used)) {
                     $index = $fcounter;
                     break;
                 }
             }
         }
         $used[] = $index;
         $yeschecked = in_array($linkedTable->db_table_name, $aExisitngLinkedForms) || JArrayHelper::getValue($aExisitngLinkedForms, $index, 0) != '0' ? 'checked="checked"' : ($checked = '');
         $nochecked = $yeschecked == '' ? 'checked="checked"' : ($checked = '');
         $el2 = '<label><input name="params[linkedform][' . $key . ']" value="0" ' . $nochecked . ' type="radio">' . JText::_('NO') . '</label>';
         $el2 .= '<label><input name="params[linkedform][' . $key . ']" value="' . $key . '" ' . $yeschecked . ' type="radio">' . JText::_('YES') . '</label>';
         $yeschecked = in_array($linkedTable->db_table_name, $linkedform_linktype) || JArrayHelper::getValue($linkedform_linktype, $index, 0) != '0' ? 'checked="checked"' : ($checked = '');
         $nochecked = $yeschecked == '' ? 'checked="checked"' : ($checked = '');
         $linkType2 = '<label><input name="params[linkedform_linktype][' . $key . ']" value="0" ' . $nochecked . ' type="radio">' . JText::_('NO') . '</label>';
         $linkType2 .= '<label><input name="params[linkedform_linktype][' . $key . ']" value="' . $key . '" ' . $yeschecked . ' type="radio">' . JText::_('YES') . '</label>';
         $formHeader = '<input name="params[linkedformheader][' . $key . ']" value="' . @$aExistingFormHeaders[$index] . '" size="16" >';
         $label = str_replace(array("\n", "\r", "<br>", "</br>"), '', $linkedTable->tablelabel);
         $formLinkText = '<input name="params[linkedformtext][' . $key . ']" value="' . @$formLinkTexts[$index] . '" size="16" >';
         $linkedArray = array($label, $el2, $formHeader, $linkType2, $formLinkText);
         $linkedArray['formhover'] = JText::_('ELEMENT') . ': ' . $linkedTable->element_label . " [{$linkedTable->plugin}]. {tmpl key =" . $linkedTable->element_id . "_form_heading}";
         $lists['linkedforms'][$index] = $linkedArray;
     }
     ksort($lists['linkedforms']);
     /*****/
     $pluginManager = JModel::getInstance('Pluginmanager', 'FabrikModel');
     $pluginManager->getPlugInGroup('table');
     // Create the form (publish dates should be stored as UTC)
     $form = new JParameter('', JPATH_COMPONENT . DS . 'models' . DS . 'table.xml');
     $form->bind($row);
     $form->set('created', JHTML::_('date', $row->created, '%Y-%m-%d %H:%M:%S'));
     $form->set('publish_up', JHTML::_('date', $row->publish_up, '%Y-%m-%d %H:%M:%S'));
     if ($cid[0] == 0 || $form->get('publish_down') == '' || $form->get('publish_down') == $db->getNullDate()) {
         $form->set('publish_down', JText::_('NEVER'));
     } else {
         $form->set('publish_down', JHTML::_('date', $row->publish_down, '%Y-%m-%d %H:%M:%S'));
     }
     $form->loadINI($row->attribs);
     $session->set('com_fabrik.admin.table.edit.model', $model);
     FabrikViewTable::edit($row, $lists, $connectionTables, $menus, $fabrikid, $params, $pluginManager, $model, $form);
 }
Ejemplo n.º 19
0
 public function loadINI($data, $namespace = null, $options = array())
 {
     //for 1.5 no change in behavior
     if (XIPT_JOOMLA_15) {
         return parent::loadINI($data, $namespace, $options);
     }
     //for 1.6+ we will use our own writer
     return $this->loadString($data, 'XiptINI', $options);
 }
Ejemplo n.º 20
0
 /**
  * Edit a cron job
  */
 function edit()
 {
     $user =& JFactory::getUser();
     $db =& JFactory::getDBO();
     $row =& JTable::getInstance('Cron', 'Table');
     if ($this->_task == 'edit') {
         $cid = JRequest::getVar('cid', array(0), 'method', 'array');
         $cid = array((int) $cid[0]);
     } else {
         $cid = array(0);
     }
     $row->load($cid[0]);
     if ($cid) {
         $row->checkout($user->get('id'));
     }
     $model =& $this->getModel('Cron');
     // get params definitions
     $lists = array();
     $units = array(JHTML::_('select.option', 'second', JText::_('SECOND')), JHTML::_('select.option', 'minute', JText::_('MINUTE')), JHTML::_('select.option', 'hour', JText::_('HOUR')), JHTML::_('select.option', 'day', JText::_('DAY')), JHTML::_('select.option', 'week', JText::_('WEEK')), JHTML::_('select.option', 'month', JText::_('MONTH')), JHTML::_('select.option', 'year', JText::_('YEAR')));
     $lists['unit'] = JHTML::_('select.genericlist', $units, 'unit', 'class="inputbox"', 'value', 'text', $row->unit);
     //build list of visualization plugins
     $pluginManager =& JModel::getInstance('Pluginmanager', 'FabrikModel');
     $pluginManager->getPlugInGroup('cron');
     $lists['plugins'] = $pluginManager->getElementTypeDd($row->plugin, 'plugin', 'class="inputbox"');
     // Create the form
     $form = new JParameter('', JPATH_COMPONENT . DS . 'models' . DS . 'cron.xml');
     $form->loadINI($row->attribs);
     require_once JPATH_COMPONENT . DS . 'views' . DS . 'cron.php';
     FabrikViewCron::edit($row, $form, $lists, $pluginManager);
 }
 /**
  * Compiles information to add or edit the record
  *
  * @param database A database connector object
  * @param integer The unique id of the record to edit (0 if new)
  * @param integer The id of the content section
  */
 function editContent($edit)
 {
     global $mainframe;
     // Initialize variables
     $db =& JFactory::getDBO();
     $user =& JFactory::getUser();
     $cid = JRequest::getVar('cid', array(0), '', 'array');
     JArrayHelper::toInteger($cid, array(0));
     $id = JRequest::getVar('id', $cid[0], '', 'int');
     $option = JRequest::getCmd('option');
     $nullDate = $db->getNullDate();
     $contentSection = '';
     $sectionid = 0;
     // Create and load the content table row
     $row =& JTable::getInstance('content');
     if ($edit) {
         $row->load($id);
     }
     if ($id) {
         $sectionid = $row->sectionid;
         if ($row->state < 0) {
             $mainframe->redirect('index.php?option=com_content', JText::_('You cannot edit an archived item'));
         }
     }
     // A sectionid of zero means grab from all sections
     if ($sectionid == 0) {
         $where = ' WHERE section NOT LIKE "%com_%"';
     } else {
         // Grab from the specific section
         $where = ' WHERE section = ' . $db->Quote($sectionid);
     }
     /*
      * If the item is checked out we cannot edit it... unless it was checked
      * out by the current user.
      */
     if (JTable::isCheckedOut($user->get('id'), $row->checked_out)) {
         $msg = JText::sprintf('DESCBEINGEDITTED', JText::_('The item'), $row->title);
         $mainframe->redirect('index.php?option=com_content', $msg);
     }
     if ($id) {
         $row->checkout($user->get('id'));
         if (trim($row->images)) {
             $row->images = explode("\n", $row->images);
         } else {
             $row->images = array();
         }
         $query = 'SELECT name' . ' FROM #__users' . ' WHERE id = ' . (int) $row->created_by;
         $db->setQuery($query);
         $row->creator = $db->loadResult();
         // test to reduce unneeded query
         if ($row->created_by == $row->modified_by) {
             $row->modifier = $row->creator;
         } else {
             $query = 'SELECT name' . ' FROM #__users' . ' WHERE id = ' . (int) $row->modified_by;
             $db->setQuery($query);
             $row->modifier = $db->loadResult();
         }
         $query = 'SELECT COUNT(content_id)' . ' FROM #__content_frontpage' . ' WHERE content_id = ' . (int) $row->id;
         $db->setQuery($query);
         $row->frontpage = $db->loadResult();
         if (!$row->frontpage) {
             $row->frontpage = 0;
         }
     } else {
         if (!$sectionid && JRequest::getInt('filter_sectionid')) {
             $sectionid = JRequest::getInt('filter_sectionid');
         }
         if (JRequest::getInt('catid')) {
             $row->catid = JRequest::getInt('catid');
             $category =& JTable::getInstance('category');
             $category->load($row->catid);
             $sectionid = $category->section;
         } else {
             $row->catid = NULL;
         }
         $createdate =& JFactory::getDate();
         $row->sectionid = $sectionid;
         $row->version = 0;
         $row->state = 1;
         $row->ordering = 0;
         $row->images = array();
         $row->publish_up = $createdate->toUnix();
         $row->publish_down = JText::_('Never');
         $row->creator = '';
         $row->created = $createdate->toUnix();
         $row->modified = $nullDate;
         $row->modifier = '';
         $row->frontpage = 0;
     }
     $javascript = "onchange=\"changeDynaList( 'catid', sectioncategories, document.adminForm.sectionid.options[document.adminForm.sectionid.selectedIndex].value, 0, 0);\"";
     $query = 'SELECT s.id, s.title' . ' FROM #__sections AS s' . ' ORDER BY s.ordering';
     $db->setQuery($query);
     $sections[] = JHTML::_('select.option', '-1', '- ' . JText::_('Select Section') . ' -', 'id', 'title');
     $sections[] = JHTML::_('select.option', '0', JText::_('Uncategorized'), 'id', 'title');
     $sections = array_merge($sections, $db->loadObjectList());
     $lists['sectionid'] = JHTML::_('select.genericlist', $sections, 'sectionid', 'class="inputbox" size="1" ' . $javascript, 'id', 'title', intval($row->sectionid));
     foreach ($sections as $section) {
         $section_list[] = (int) $section->id;
         // get the type name - which is a special category
         if ($row->sectionid) {
             if ($section->id == $row->sectionid) {
                 $contentSection = $section->title;
             }
         } else {
             if ($section->id == $sectionid) {
                 $contentSection = $section->title;
             }
         }
     }
     $sectioncategories = array();
     $sectioncategories[-1] = array();
     $sectioncategories[-1][] = JHTML::_('select.option', '-1', JText::_('Select Category'), 'id', 'title');
     $section_list = implode('\', \'', $section_list);
     $query = 'SELECT id, title, section' . ' FROM #__categories' . ' WHERE section IN ( \'' . $section_list . '\' )' . ' ORDER BY ordering';
     $db->setQuery($query);
     $cat_list = $db->loadObjectList();
     // Uncategorized category mapped to uncategorized section
     $uncat = new stdClass();
     $uncat->id = 0;
     $uncat->title = JText::_('Uncategorized');
     $uncat->section = 0;
     $cat_list[] = $uncat;
     foreach ($sections as $section) {
         $sectioncategories[$section->id] = array();
         $rows2 = array();
         foreach ($cat_list as $cat) {
             if ($cat->section == $section->id) {
                 $rows2[] = $cat;
             }
         }
         foreach ($rows2 as $row2) {
             $sectioncategories[$section->id][] = JHTML::_('select.option', $row2->id, $row2->title, 'id', 'title');
         }
     }
     $sectioncategories['-1'][] = JHTML::_('select.option', '-1', JText::_('Select Category'), 'id', 'title');
     $categories = array();
     foreach ($cat_list as $cat) {
         if ($cat->section == $row->sectionid) {
             $categories[] = $cat;
         }
     }
     $categories[] = JHTML::_('select.option', '-1', JText::_('Select Category'), 'id', 'title');
     $lists['catid'] = JHTML::_('select.genericlist', $categories, 'catid', 'class="inputbox" size="1"', 'id', 'title', intval($row->catid));
     // build the html select list for ordering
     $query = 'SELECT ordering AS value, title AS text' . ' FROM #__content' . ' WHERE catid = ' . (int) $row->catid . ' AND state >= 0' . ' ORDER BY ordering';
     if ($edit) {
         $lists['ordering'] = JHTML::_('list.specificordering', $row, $id, $query, 1);
     } else {
         $lists['ordering'] = JHTML::_('list.specificordering', $row, '', $query, 1);
     }
     // build the html radio buttons for frontpage
     $lists['frontpage'] = JHTML::_('select.booleanlist', 'frontpage', '', $row->frontpage);
     // build the html radio buttons for published
     $lists['state'] = JHTML::_('select.booleanlist', 'state', '', $row->state);
     /*
      * We need to unify the introtext and fulltext fields and have the
      * fields separated by the {readmore} tag, so lets do that now.
      */
     if (JString::strlen($row->fulltext) > 1) {
         $row->text = $row->introtext . "<hr id=\"system-readmore\" />" . $row->fulltext;
     } else {
         $row->text = $row->introtext;
     }
     // Create the form
     $form = new JParameter('', JPATH_COMPONENT . DS . 'models' . DS . 'article.xml');
     // Details Group
     $active = intval($row->created_by) ? intval($row->created_by) : $user->get('id');
     $form->set('created_by', $active);
     $form->set('access', $row->access);
     $form->set('created_by_alias', $row->created_by_alias);
     $form->set('created', JHTML::_('date', $row->created, '%Y-%m-%d %H:%M:%S'));
     $form->set('publish_up', JHTML::_('date', $row->publish_up, '%Y-%m-%d %H:%M:%S'));
     if (JHTML::_('date', $row->publish_down, '%Y') <= 1969 || $row->publish_down == $db->getNullDate()) {
         $form->set('publish_down', JText::_('Never'));
     } else {
         $form->set('publish_down', JHTML::_('date', $row->publish_down, '%Y-%m-%d %H:%M:%S'));
     }
     // Advanced Group
     $form->loadINI($row->attribs);
     // Metadata Group
     $form->set('description', $row->metadesc);
     $form->set('keywords', $row->metakey);
     $form->loadINI($row->metadata);
     ContentView::editContent($row, $contentSection, $lists, $sectioncategories, $option, $form);
 }
Ejemplo n.º 22
0
    /**
     * Logic to render an XML file as form parameters
     * NOTE: this does not work with Request Data validation in J2.5+. The validation
     *       must be skipped or the parameters must be re-added after the validation
     *
     * @access public
     * @return void
     * @since 1.5
     */
    function getlayoutparams()
    {
        jimport('joomla.filesystem.file');
        $mainframe = JFactory::getApplication();
        $user = JFactory::getUser();
        //get vars
        $ext_view = JRequest::getVar('ext_view', '');
        $ext_id = JRequest::getInt('ext_id', 0);
        $layout_name = JRequest::getVar('layout_name', 0);
        $directory = JRequest::getVar('directory', 0);
        $path = (!is_dir($directory) ? JPATH_ROOT : '') . $directory;
        $db = JFactory::getDBO();
        if ($ext_view == 'module') {
            $query = 'SELECT params FROM #__modules WHERE id = ' . $ext_id;
        } else {
            if ($ext_view == 'field') {
                $query = 'SELECT attribs FROM #__flexicontent_fields WHERE id = ' . $ext_id;
            } else {
                echo "not supported extension/view: " . $ext_view;
                return;
            }
        }
        $db->setQuery($query);
        $ext_params_str = $db->loadResult();
        $layoutpath = $path . DS . $layout_name . '.xml';
        if (!file_exists($layoutpath)) {
            echo !FLEXI_J16GE ? '<div style="font-size: 11px; color: gray; background-color: lightyellow; border: 1px solid lightgray; width: auto; padding: 4px 2%; margin: 1px 8px; height: auto;">' : '<p class="tip">';
            echo ' Currently selected layout: <b>"' . $layout_name . '"</b> does not have layout specific parameters';
            echo !FLEXI_J16GE ? '</div>' : '</p>';
            exit;
        }
        //Get data from the model
        if (FLEXI_J16GE) {
            $grpname = 'params';
            // this name of <fields> container
            if (FLEXI_J30GE) {
                $xml = simplexml_load_file($layoutpath);
                $xmldoc =& $xml;
            } else {
                $xml = JFactory::getXMLParser('Simple');
                $xml->loadFile($layoutpath);
                $xmldoc =& $xml->document;
            }
            $tmpl_params = FLEXI_J30GE ? $xmldoc->asXML() : $xmldoc->toString();
            // Create form object, (form name seems not to cause any problem)
            $jform = new JForm('com_flexicontent.template.item', array('control' => 'jform', 'load_data' => true));
            $jform->load($tmpl_params);
            // Load existing layout values into the object (that we got from DB)
            $ext_params = new JRegistry($ext_params_str);
            // and for J1.5:  new JParameter($ext_params_str);
            foreach ($jform->getGroup($grpname) as $field) {
                $fieldname = $field->__get('fieldname');
                $value = $ext_params->get($fieldname);
                if (strlen($value)) {
                    $jform->setValue($fieldname, $grpname, $value);
                }
            }
        } else {
            // Create a parameters object
            $form = new JParameter('', $layoutpath);
            // Load existing layout values into the object (that we got from DB)
            $form->loadINI($ext_params_str);
        }
        if ($layout_name) {
            if (!FLEXI_J16GE) {
                echo $form->render('params', 'layout');
            } else {
                ?>
				<fieldset class="panelform"><ul class="adminformlist">
					<?php 
                foreach ($jform->getGroup($grpname) as $field) {
                    echo '<li>' . $field->label . $field->input . '</li>';
                }
                ?>
				</ul></fieldset>
				<?php 
            }
        } else {
            echo "<br /><span style=\"padding-left:25px;\"'>" . JText::_('FLEXI_APPLY_TO_SEE_THE_PARAMETERS') . "</span><br /><br />";
        }
        //parent::display($tpl);
    }
Ejemplo n.º 23
0
    function display($tpl = null)
    {
        //initialise variables
        $app = JFactory::getApplication();
        $user = JFactory::getUser();
        //JHTML::_('behavior.tooltip');
        //get vars
        $cid = JRequest::getVar('cid');
        $field_type = JRequest::getVar('field_type', 0);
        //Get data from the model
        $model = $this->getModel();
        $form = $this->get('Form');
        if (!FLEXI_J16GE) {
            $row =& $this->get('Field');
            //Import File system
            jimport('joomla.filesystem.file');
            // Create the form
            $pluginpath = JPATH_PLUGINS . DS . 'flexicontent_fields' . DS . $field_type . '.xml';
            if (JFile::exists($pluginpath)) {
                $form = new JParameter('', $pluginpath);
            } else {
                $form = new JParameter('', JPATH_PLUGINS . DS . 'flexicontent_fields' . DS . 'core.xml');
            }
            $form->loadINI($row->attribs);
        }
        $isnew = FLEXI_J16GE ? !$form->getValue('id') : !$row->id;
        // fail if checked out not by 'me'
        if (!$isnew) {
            if ($model->isCheckedOut($user->get('id'))) {
                JError::raiseWarning('SOME_ERROR_CODE', $row->name . ' ' . JText::_('FLEXI_EDITED_BY_ANOTHER_ADMIN'));
                $app->redirect('index.php?option=com_flexicontent&view=fields');
            }
        }
        /*if ($field_type)
        		{
        			if (!FLEXI_J16GE) {
        				echo $form->render('params', 'group-' . $field_type );
        			} else {
        				foreach ($form->getFieldset('group-' . $field_type) as $field) {
        					echo '<fieldset class="panelform">' . $field->label . $field->input . '</fieldset>' . "\n";
        				}
        			}
        		} else {
        			echo "<br /><span style=\"padding-left:25px;\"'>" . JText::_( 'FLEXI_APPLY_TO_SEE_THE_PARAMETERS' ) . "</span><br /><br />";
        		}*/
        ?>
			<div class="fctabber fields_tabset" id="field_specific_props_tabset">
			<?php 
        $fieldSets = $form->getFieldsets('attribs');
        $prefix_len = strlen('group-' . $field_type . '-');
        foreach ($fieldSets as $name => $fieldSet) {
            if ($name != 'basic' && $name != 'standard' && (substr($name, 0, $prefix_len) != 'group-' . $field_type . '-' || $name === 'group-' . $field_type)) {
                continue;
            }
            if ($fieldSet->label) {
                $label = JText::_($fieldSet->label);
            } else {
                $label = $name == 'basic' || $name == 'standard' ? JText::_('FLEXI_BASIC') : ucfirst(str_replace("group-", "", $name));
            }
            if (@$fieldSet->label_prefix) {
                $label = JText::_($fieldSet->label_prefix) . ' - ' . $label;
            }
            $icon = @$fieldSet->icon_class ? 'data-icon-class="' . $fieldSet->icon_class . '"' : '';
            $prepend = @$fieldSet->prepend_text ? 'data-prefix-text="' . JText::_($fieldSet->prepend_text) . '"' : '';
            $description = $fieldSet->description ? JText::_($fieldSet->description) : '';
            ?>
				<div class="tabbertab" id="fcform_tabset_<?php 
            echo $name;
            ?>
_tab" <?php 
            echo $icon;
            ?>
 <?php 
            echo $prepend;
            ?>
>
					<h3 class="tabberheading hasTooltip" title="<?php 
            echo $description;
            ?>
"><?php 
            echo $label;
            ?>
 </h3>
					<?php 
            $i = 0;
            ?>
					<?php 
            foreach ($form->getFieldset($name) as $field) {
                $_depends = FLEXI_J30GE ? $field->getAttribute('depend_class') : $form->getFieldAttribute($field->__get('fieldname'), 'depend_class', '', 'attribs');
                echo '
						<fieldset class="panelform' . ($i ? '' : ' fc-nomargin') . ' ' . ($_depends ? ' ' . $_depends : '') . '" id="' . $field->id . '-container">
							' . ($field->label ? '
								<span class="label-fcouter">' . str_replace('class="', 'class="label label-fcinner ', $field->label) . '</span>
								<div class="container_fcfield">' . $field->input . '</div>
							' : $field->input) . '
						</fieldset>
						';
                $i++;
            }
            ?>
				</div>
		<?php 
        }
        ?>
		</div>
		
		<?php 
        //parent::display($tpl);
    }
Ejemplo n.º 24
0
    /**
     * Creates the item submit form
     *
     * @since 1.0
     */
    function _displayForm($tpl)
    {
        jimport('joomla.html.parameter');
        // ... we use some strings from administrator part
        // load english language file for 'com_content' component then override with current language file
        JFactory::getLanguage()->load('com_content', JPATH_ADMINISTRATOR, 'en-GB', true);
        JFactory::getLanguage()->load('com_content', JPATH_ADMINISTRATOR, null, true);
        // load english language file for 'com_flexicontent' component then override with current language file
        JFactory::getLanguage()->load('com_flexicontent', JPATH_ADMINISTRATOR, 'en-GB', true);
        JFactory::getLanguage()->load('com_flexicontent', JPATH_ADMINISTRATOR, null, true);
        // ********************************
        // Initialize variables, flags, etc
        // ********************************
        $app = JFactory::getApplication();
        $dispatcher = JDispatcher::getInstance();
        $document = JFactory::getDocument();
        $session = JFactory::getSession();
        $user = JFactory::getUser();
        $db = JFactory::getDBO();
        $uri = JFactory::getURI();
        $nullDate = $db->getNullDate();
        $menu = $app->getMenu()->getActive();
        // Get the COMPONENT only parameters, then merge the menu parameters
        $comp_params = JComponentHelper::getComponent('com_flexicontent')->params;
        $params = FLEXI_J16GE ? clone $comp_params : new JParameter($comp_params);
        // clone( JComponentHelper::getParams('com_flexicontent') );
        if ($menu) {
            $menu_params = FLEXI_J16GE ? $menu->params : new JParameter($menu->params);
            $params->merge($menu_params);
        }
        // Some flags
        $enable_translation_groups = $params->get("enable_translation_groups") && (FLEXI_J16GE || FLEXI_FISH);
        $print_logging_info = $params->get('print_logging_info');
        if ($print_logging_info) {
            global $fc_run_times;
        }
        // *****************
        // Load JS/CSS files
        // *****************
        FLEXI_J30GE ? JHtml::_('behavior.framework', true) : JHTML::_('behavior.mootools');
        flexicontent_html::loadFramework('jQuery');
        flexicontent_html::loadFramework('select2');
        // Load custom behaviours: form validation, popup tooltips
        //JHTML::_('behavior.formvalidation');
        JHTML::_('behavior.tooltip');
        if (FLEXI_J30GE) {
            JHtml::_('bootstrap.tooltip');
        }
        //JHTML::_('script', 'joomla.javascript.js', 'includes/js/');
        // Add css files to the document <head> section (also load CSS joomla template override)
        $document->addStyleSheet(JURI::base(true) . '/components/com_flexicontent/assets/css/flexicontent.css');
        if (file_exists(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'css' . DS . 'flexicontent.css')) {
            $document->addStyleSheet(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'css' . DS . 'flexicontent.css');
        }
        if (!FLEXI_J16GE) {
            $document->addStyleSheet($this->baseurl . '/administrator/templates/khepri/css/general.css');
        }
        //$document->addCustomTag('<!--[if IE]><style type="text/css">.floattext{zoom:1;}, * html #flexicontent dd { height: 1%; }</style><![endif]-->');
        // Load backend / frontend shared and Joomla version specific CSS (different for frontend / backend)
        $document->addStyleSheet(JURI::base(true) . '/components/com_flexicontent/assets/css/flexi_shared.css');
        // NOTE: this is imported by main Frontend CSS file
        if (FLEXI_J30GE) {
            $document->addStyleSheet(JURI::base(true) . '/components/com_flexicontent/assets/css/j3x.css');
        } else {
            if (FLEXI_J16GE) {
                $document->addStyleSheet(JURI::base(true) . '/components/com_flexicontent/assets/css/j25.css');
            } else {
                $document->addStyleSheet(JURI::base(true) . '/components/com_flexicontent/assets/css/j15.css');
            }
        }
        // Add js function to overload the joomla submitform
        $document->addScript(JURI::base(true) . '/components/com_flexicontent/assets/js/admin.js');
        $document->addScript(JURI::base(true) . '/components/com_flexicontent/assets/js/validate.js');
        // Add js function for custom code used by FLEXIcontent item form
        $document->addScript(JURI::base(true) . '/components/com_flexicontent/assets/js/itemscreen.js');
        // ***********************************************
        // Get item and create form (that loads item data)
        // ***********************************************
        if ($print_logging_info) {
            $start_microtime = microtime(true);
        }
        $model = $this->getModel();
        // ** WE NEED TO get OR decide the Content Type, before we call the getItem
        // ** We rely on typeid Request variable to decide type for new items so make sure this is set,
        // ZERO means allow user to select type, but if user is only allowed a single type, then autoselect it!
        if ($menu && isset($menu->query['typeid'])) {
            JRequest::setVar('typeid', (int) $menu->query['typeid']);
            // This also forces zero if value not set
        }
        $new_typeid = JRequest::getVar('typeid', 0, '', 'int');
        if (!$new_typeid) {
            $types = $model->getTypeslist($type_ids_arr = false, $check_perms = true);
            if ($types && count($types) == 1) {
                $new_typeid = $types[0]->id;
            }
            JRequest::setVar('typeid', $new_typeid);
            $canCreateType = true;
        }
        $item = $this->get('Item');
        if (FLEXI_J16GE) {
            $form = $this->get('Form');
        }
        if ($print_logging_info) {
            $fc_run_times['get_item_data'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10;
        }
        // *********************************************************************************************************
        // Get language stuff, and also load Template-Specific language file to override or add new language strings
        // *********************************************************************************************************
        if ($enable_translation_groups) {
            $langAssocs = $this->get('LangAssocs');
        }
        if (FLEXI_FISH || FLEXI_J16GE) {
            $langs = FLEXIUtilities::getLanguages('code');
        }
        if (FLEXI_FISH || FLEXI_J16GE) {
            FLEXIUtilities::loadTemplateLanguageFile($item->parameters->get('ilayout', 'default'));
        }
        // ****************************************************************************************
        // CHECK EDIT / CREATE PERMISSIONS (this is duplicate since it also done at the controller)
        // ****************************************************************************************
        // new item and ownership variables
        $isnew = !$item->id;
        $isOwner = $item->created_by == $user->get('id');
        // create and set (into HTTP request) a unique item id for plugins that needed it
        JRequest::setVar('unique_tmp_itemid', $item->id ? $item->id : date('_Y_m_d_h_i_s_', time()) . uniqid(true));
        // Component / Menu Item parameters
        $allowunauthorize = $params->get('allowunauthorize', 0);
        // allow unauthorised user to submit new content
        $unauthorized_page = $params->get('unauthorized_page', '');
        // page URL for unauthorized users (via global configuration)
        $notauth_itemid = $params->get('notauthurl', '');
        // menu itemid (to redirect) when user is not authorized to create content
        // Create captcha field or messages
        if (FLEXI_J16GE) {
            $use_captcha = $params->get('use_captcha', 1);
            // 1 for guests, 2 for any user
            $captcha_formop = $params->get('captcha_formop', 0);
            // 0 for submit, 1 for submit/edit (aka always)
            $display_captcha = $use_captcha >= 2 || $use_captcha == 1 && $user->guest;
            $display_captcha = $display_captcha && ($isnew || $captcha_formop);
            // Force using recaptcha
            if ($display_captcha) {
                // Try to force the use of recaptcha plugin
                JFactory::getConfig()->set('captcha', 'recaptcha');
                if (!$app->getCfg('captcha')) {
                    $captcha_errmsg = '-- Please select <b>CAPTCHA Type</b> at global Joomla parameters';
                } else {
                    if ($app->getCfg('captcha') != 'recaptcha') {
                        $captcha_errmsg = '-- Captcha Type: <b>' . $app->getCfg('captcha') . '</b> not supported';
                    } else {
                        if (!JPluginHelper::isEnabled('captcha', 'recaptcha')) {
                            $captcha_errmsg = '-- Please enable & configure the Joomla <b>ReCaptcha Plugin</b>';
                        } else {
                            $captcha_errmsg = '';
                            JPluginHelper::importPlugin('captcha');
                            $dispatcher->trigger('onInit', 'dynamic_recaptcha_1');
                            $field_description = JText::_('FLEXI_CAPTCHA_ENTER_CODE_DESC');
                            $label_tooltip = 'class="hasTip flexi_label" title="' . '::' . htmlspecialchars($field_description, ENT_COMPAT, 'UTF-8') . '"';
                            $captcha_field = '
						<label id="recaptcha_response_field-lbl" for="recaptcha_response_field" ' . $label_tooltip . ' >
						' . JText::_('FLEXI_CAPTCHA_ENTER_CODE') . '
						</label>
						<div class="container_fcfield container_fcfield_name_captcha">
							<div id="dynamic_recaptcha_1"></div>
						</div>
						';
                        }
                    }
                }
            }
        }
        // User Group / Author parameters
        $db->setQuery('SELECT author_basicparams FROM #__flexicontent_authors_ext WHERE user_id = ' . $user->id);
        $authorparams = $db->loadResult();
        $authorparams = FLEXI_J16GE ? new JRegistry($authorparams) : new JParameter($authorparams);
        $max_auth_limit = $authorparams->get('max_auth_limit', 0);
        // maximum number of content items the user can create
        if (!$isnew) {
            // EDIT action
            // Finally check if item is currently being checked-out (currently being edited)
            if ($model->isCheckedOut($user->get('id'))) {
                $msg = JText::sprintf('FLEXI_DESCBEINGEDITTED', $model->get('title'));
                $app->redirect(JRoute::_('index.php?view=' . FLEXI_ITEMVIEW . '&cid=' . $model->get('catid') . '&id=' . $model->get('id'), false), $msg);
            }
            //Checkout the item
            $model->checkout();
            if (FLEXI_J16GE) {
                $canEdit = $model->getItemAccess()->get('access-edit');
                // includes privileges edit and edit-own
                // ALTERNATIVE 1
                //$asset = 'com_content.article.' . $model->get('id');
                //$canEdit = $user->authorise('core.edit', $asset) || ($user->authorise('core.edit.own', $asset) && $model->get('created_by') == $user->get('id'));
                // ALTERNATIVE 2
                //$rights = FlexicontentHelperPerm::checkAllItemAccess($user->get('id'), 'item', $model->get('id'));
                //$canEdit = in_array('edit', $rights) || (in_array('edit.own', $rights) && $model->get('created_by') == $user->get('id')) ;
            } else {
                if ($user->gid >= 25) {
                    $canEdit = true;
                } else {
                    if (FLEXI_ACCESS) {
                        $rights = FAccess::checkAllItemAccess('com_content', 'users', $user->gmid, $model->get('id'), $model->get('catid'));
                        $canEdit = in_array('edit', $rights) || in_array('editown', $rights) && $model->get('created_by') == $user->get('id');
                    } else {
                        $canEdit = $user->authorize('com_content', 'edit', 'content', 'all') || $user->authorize('com_content', 'edit', 'content', 'own') && $model->get('created_by') == $user->get('id');
                        //$canEdit = ($user->gid >= 20);  // At least J1.5 Editor
                    }
                }
            }
            if (!$canEdit) {
                // No edit privilege, check if item is editable till logoff
                if ($session->has('rendered_uneditable', 'flexicontent')) {
                    $rendered_uneditable = $session->get('rendered_uneditable', array(), 'flexicontent');
                    $canEdit = isset($rendered_uneditable[$model->get('id')]) && $rendered_uneditable[$model->get('id')];
                }
            }
            if (!$canEdit) {
                if ($user->guest) {
                    $uri = JFactory::getURI();
                    $return = $uri->toString();
                    $fcreturn = serialize(array('id' => @$this->_item->id, 'cid' => $cid));
                    // a special url parameter, used by some SEF code
                    $com_users = FLEXI_J16GE ? 'com_users' : 'com_user';
                    $url = $params->get('login_page', 'index.php?option=' . $com_users . '&view=login');
                    $return = strtr(base64_encode($return), '+/=', '-_,');
                    $url .= '&return=' . $return;
                    //$url .= '&return='.urlencode(base64_encode($return));
                    $url .= '&fcreturn=' . base64_encode($fcreturn);
                    JError::raiseWarning(403, JText::sprintf("FLEXI_LOGIN_TO_ACCESS", $url));
                    $app->redirect($url);
                } else {
                    if ($unauthorized_page) {
                        //  unauthorized page via global configuration
                        JError::raiseNotice(403, JText::_('FLEXI_ALERTNOTAUTH_TASK'));
                        $app->redirect($unauthorized_page);
                    } else {
                        // user isn't authorize to edit this content
                        $msg = JText::_('FLEXI_ALERTNOTAUTH_TASK');
                        if (FLEXI_J16GE) {
                            throw new Exception($msg, 403);
                        } else {
                            JError::raiseError(403, $msg);
                        }
                    }
                }
            }
        } else {
            // CREATE action
            if (FLEXI_J16GE) {
                $canAdd = $model->getItemAccess()->get('access-create');
                // includes check of creating in at least one category
                $not_authorised = !$canAdd;
            } else {
                if ($user->gid >= 25) {
                    $not_authorised = 0;
                } else {
                    if (FLEXI_ACCESS) {
                        $canAdd = FAccess::checkUserElementsAccess($user->gmid, 'submit');
                        $not_authorised = !(@$canAdd['content'] || @$canAdd['category']);
                    } else {
                        $canAdd = $user->authorize('com_content', 'add', 'content', 'all');
                        //$canAdd = ($user->gid >= 19);  // At least J1.5 Author
                        $not_authorised = !$canAdd;
                    }
                }
            }
            // Check if Content Type can be created by current user
            if (empty($canCreateType)) {
                if ($new_typeid) {
                    $canCreateType = $model->canCreateType(array($new_typeid));
                    // Can create given Content Type
                } else {
                    $canCreateType = $model->canCreateType();
                    // Can create at least one Content Type
                }
            }
            $not_authorised = $not_authorised || !$canCreateType;
            // Allow item submission by unauthorized users, ... even guests ...
            if ($allowunauthorize == 2) {
                $allowunauthorize = !$user->guest;
            }
            if ($not_authorised && !$allowunauthorize) {
                if (!$canCreateType) {
                    $type_name = isset($types[$new_typeid]) ? '"' . JText::_($types[$new_typeid]->name) . '"' : JText::_('FLEXI_ANY');
                    $msg = JText::sprintf('FLEXI_NO_ACCESS_CREATE_CONTENT_OF_TYPE', $type_name);
                } else {
                    $msg = JText::_('FLEXI_ALERTNOTAUTH_CREATE');
                }
            } else {
                if ($max_auth_limit) {
                    $db->setQuery('SELECT COUNT(id) FROM #__content WHERE created_by = ' . $user->id);
                    $authored_count = $db->loadResult();
                    $content_is_limited = $authored_count >= $max_auth_limit;
                    $msg = $content_is_limited ? JText::sprintf('FLEXI_ALERTNOTAUTH_CREATE_MORE', $max_auth_limit) : '';
                }
            }
            if ($not_authorised && !$allowunauthorize || @$content_is_limited) {
                // User isn't authorize to add ANY content
                if ($notauth_menu = $app->getMenu()->getItem($notauth_itemid)) {
                    // a. custom unauthorized submission page via menu item
                    $internal_link_vars = @$notauth_menu->component ? '&Itemid=' . $notauth_itemid . '&option=' . $notauth_menu->component : '';
                    $notauthurl = JRoute::_($notauth_menu->link . $internal_link_vars, false);
                    JError::raiseNotice(403, $msg);
                    $app->redirect($notauthurl);
                } else {
                    if ($unauthorized_page) {
                        // b. General unauthorized page via global configuration
                        JError::raiseNotice(403, $msg);
                        $app->redirect($unauthorized_page);
                    } else {
                        // c. Finally fallback to raising a 403 Exception/Error that will redirect to site's default 403 unauthorized page
                        if (FLEXI_J16GE) {
                            throw new Exception($msg, 403);
                        } else {
                            JError::raiseError(403, $msg);
                        }
                    }
                }
            }
        }
        // *********************************************
        // Get more variables to push into the FORM view
        // *********************************************
        // Get available types and the currently selected/requested type
        $types = $model->getTypeslist();
        $typesselected = $model->getTypesselected();
        // Create the type parameters
        $tparams = $this->get('Typeparams');
        $tparams = FLEXI_J16GE ? new JRegistry($tparams) : new JParameter($tparams);
        // Merge item parameters, or type/menu parameters for new item
        if ($isnew) {
            if ($new_typeid) {
                $params->merge($tparams);
            }
            // Apply type configuration if it type is set
            if ($menu) {
                $params->merge($menu_params);
            }
            // Apply menu configuration if it menu is set, to override type configuration
        } else {
            $params = $item->parameters;
        }
        // Check if saving an item that translates an original content in site's default language
        $is_content_default_lang = substr(flexicontent_html::getSiteDefaultLang(), 0, 2) == substr($item->language, 0, 2);
        $modify_untraslatable_values = $enable_translation_groups && !$is_content_default_lang && $item->lang_parent_id && $item->lang_parent_id != $item->id;
        // *****************************************************************************
        // Get (CORE & CUSTOM) fields and their VERSIONED values and then
        // (a) Apply Content Type Customization to CORE fields (label, description, etc)
        // (b) Create the edit html of the CUSTOM fields by triggering 'onDisplayField'
        // *****************************************************************************
        if ($print_logging_info) {
            $start_microtime = microtime(true);
        }
        $fields = $this->get('Extrafields');
        if ($print_logging_info) {
            $fc_run_times['get_field_vals'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10;
        }
        if ($print_logging_info) {
            $start_microtime = microtime(true);
        }
        foreach ($fields as $field) {
            // a. Apply CONTENT TYPE customizations to CORE FIELDS, e.g a type specific label & description
            // NOTE: the field parameters are already created so there is not need to call this for CUSTOM fields, which do not have CONTENT TYPE customizations
            if ($field->iscore) {
                FlexicontentFields::loadFieldConfig($field, $item);
            }
            // b. Create field 's editing HTML (the form field)
            // NOTE: this is DONE only for CUSTOM fields, since form field html is created by the form for all CORE fields, EXCEPTION is the 'text' field (see bellow)
            if (!$field->iscore) {
                if (FLEXI_J16GE) {
                    $is_editable = !$field->valueseditable || $user->authorise('flexicontent.editfieldvalues', 'com_flexicontent.field.' . $field->id);
                } else {
                    if (FLEXI_ACCESS && $user->gid < 25) {
                        $is_editable = !$field->valueseditable || FAccess::checkAllContentAccess('com_content', 'submit', 'users', $user->gmid, 'field', $field->id);
                    } else {
                        $is_editable = 1;
                    }
                }
                if (!$is_editable) {
                    $field->html = '<div class="fc-mssg fc-warning">' . JText::_('FLEXI_NO_ACCESS_LEVEL_TO_EDIT_FIELD') . '</div>';
                } else {
                    if ($modify_untraslatable_values && $field->untranslatable) {
                        $field->html = '<div class="fc-mssg fc-note">' . JText::_('FLEXI_FIELD_VALUE_IS_UNTRANSLATABLE') . '</div>';
                    } else {
                        FLEXIUtilities::call_FC_Field_Func($field->field_type, 'onDisplayField', array(&$field, &$item));
                    }
                }
            }
            // c. Create main text field, via calling the display function of the textarea field (will also check for tabs)
            if ($field->field_type == 'maintext') {
                if (isset($item->item_translations)) {
                    $shortcode = substr($item->language, 0, 2);
                    foreach ($item->item_translations as $lang_id => $t) {
                        if ($shortcode == $t->shortcode) {
                            continue;
                        }
                        $field->name = array('jfdata', $t->shortcode, 'text');
                        $field->value[0] = html_entity_decode($t->fields->text->value, ENT_QUOTES, 'UTF-8');
                        FLEXIUtilities::call_FC_Field_Func('textarea', 'onDisplayField', array(&$field, &$item));
                        $t->fields->text->tab_labels = $field->tab_labels;
                        $t->fields->text->html = $field->html;
                        unset($field->tab_labels);
                        unset($field->html);
                    }
                }
                $field->name = 'text';
                // NOTE: We use the text created by the model and not the text retrieved by the CORE plugin code, which maybe overwritten with JoomFish/Falang data
                $field->value[0] = $item->text;
                // do not decode special characters this was handled during saving !
                // Render the field's (form) HTML
                FLEXIUtilities::call_FC_Field_Func('textarea', 'onDisplayField', array(&$field, &$item));
            }
        }
        if ($print_logging_info) {
            $fc_run_times['render_field_html'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10;
        }
        // Tags used by the item
        $usedtagsids = $this->get('UsedtagsIds');
        // NOTE: This will normally return the already set versioned value of tags ($item->tags)
        //$usedtagsIds 	= $isnew ? array() : $fields['tags']->value;
        $usedtagsdata = $model->getUsedtagsData($usedtagsids);
        //echo "<br/>usedtagsIds: "; print_r($usedtagsids);
        //echo "<br/>usedtags (data): "; print_r($usedtagsdata);
        // Compatibility for old overriden templates ...
        if (!FLEXI_J16GE) {
            $tags = $this->get('Alltags');
            $usedtags = $this->get('UsedtagsIds');
        }
        // Load permissions (used by form template)
        $perms = $this->_getItemPerms($item, $typesselected);
        // Get the edit lists
        $lists = $this->_buildEditLists($perms, $params, $authorparams, $typesselected, $tparams);
        // Get number of subscribers
        $subscribers = $this->get('SubscribersCount');
        // Get menu overridden categories/main category fields
        $menuCats = $this->_getMenuCats($item, $perms, $params);
        // Create submit configuration (for new items) into the session
        $submitConf = $this->_createSubmitConf($item, $perms, $params);
        // Create placement configuration for CORE properties
        $placementConf = $this->_createPlacementConf($fields, $params, $item);
        // Item language related vars
        if (FLEXI_FISH || FLEXI_J16GE) {
            $languages = FLEXIUtilities::getLanguages();
            $itemlang = new stdClass();
            $itemlang->shortcode = substr($item->language, 0, 2);
            $itemlang->name = $languages->{$item->language}->name;
            $itemlang->image = '<img src="' . @$languages->{$item->language}->imgsrc . '" alt="' . $languages->{$item->language}->name . '" />';
        }
        //Load the JEditor object
        $editor = JFactory::getEditor();
        // **********************************************************
        // Calculate a (browser window) page title and a page heading
        // **********************************************************
        // Verify menu item points to current FLEXIcontent object
        if ($menu) {
            $menu_matches = false;
            $view_ok = FLEXI_ITEMVIEW == @$menu->query['view'] || 'article' == @$menu->query['view'];
            $menu_matches = $view_ok;
            //$menu_params = FLEXI_J16GE ? $menu->params : new JParameter($menu->params);  // Get active menu item parameters
        } else {
            $menu_matches = false;
        }
        // MENU ITEM matched, use its page heading (but use menu title if the former is not set)
        if ($menu_matches) {
            $default_heading = FLEXI_J16GE ? $menu->title : $menu->name;
            // Cross set (show_) page_heading / page_title for compatibility of J2.5+ with J1.5 template (and for J1.5 with J2.5 template)
            $params->def('page_heading', $params->get('page_title', $default_heading));
            $params->def('page_title', $params->get('page_heading', $default_heading));
            $params->def('show_page_heading', $params->get('show_page_title', 0));
            $params->def('show_page_title', $params->get('show_page_heading', 0));
        } else {
            // Calculate default page heading (=called page title in J1.5), which in turn will be document title below !! ...
            $default_heading = !$isnew ? JText::_('FLEXI_EDIT') : JText::_('FLEXI_NEW');
            // Decide to show page heading (=J1.5 page title), there is no need for this in item view
            $show_default_heading = 0;
            // Set both (show_) page_heading / page_title for compatibility of J2.5+ with J1.5 template (and for J1.5 with J2.5 template)
            $params->set('page_title', $default_heading);
            $params->set('page_heading', $default_heading);
            $params->set('show_page_heading', $show_default_heading);
            $params->set('show_page_title', $show_default_heading);
        }
        // ************************************************************
        // Create the document title, by from page title and other data
        // ************************************************************
        // Use the page heading as document title, (already calculated above via 'appropriate' logic ...)
        $doc_title = $params->get('page_title');
        // Check and prepend or append site name
        if (FLEXI_J16GE) {
            // Not available in J1.5
            // Add Site Name to page title
            if ($app->getCfg('sitename_pagetitles', 0) == 1) {
                $doc_title = $app->getCfg('sitename') . " - " . $doc_title;
            } elseif ($app->getCfg('sitename_pagetitles', 0) == 2) {
                $doc_title = $doc_title . " - " . $app->getCfg('sitename');
            }
        }
        // Finally, set document title
        $document->setTitle($doc_title);
        // Add title to pathway
        $pathway = $app->getPathWay();
        $pathway->addItem($doc_title, '');
        // Get pageclass suffix
        $pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx'));
        // Ensure the row data is safe html
        // @TODO: check if this is really required as it conflicts with the escape function in the tmpl
        //JFilterOutput::objectHTMLSafe( $item );
        $this->assign('action', $uri->toString());
        $this->assignRef('item', $item);
        if (FLEXI_J16GE) {
            // most core field are created via calling methods of the form (J2.5)
            $this->assignRef('form', $form);
        }
        if ($enable_translation_groups) {
            $this->assignRef('lang_assocs', $langAssocs);
        }
        if (FLEXI_FISH || FLEXI_J16GE) {
            $this->assignRef('langs', $langs);
        }
        $this->assignRef('params', $params);
        $this->assignRef('lists', $lists);
        $this->assignRef('subscribers', $subscribers);
        $this->assignRef('editor', $editor);
        $this->assignRef('user', $user);
        if (!FLEXI_J16GE) {
            // compatibility old templates
            $this->assignRef('tags', $tags);
            $this->assignRef('usedtags', $usedtags);
        }
        $this->assignRef('usedtagsdata', $usedtagsdata);
        $this->assignRef('fields', $fields);
        $this->assignRef('tparams', $tparams);
        $this->assignRef('perms', $perms);
        $this->assignRef('document', $document);
        $this->assignRef('nullDate', $nullDate);
        $this->assignRef('menuCats', $menuCats);
        $this->assignRef('submitConf', $submitConf);
        $this->assignRef('placementConf', $placementConf);
        $this->assignRef('itemlang', $itemlang);
        $this->assignRef('pageclass_sfx', $pageclass_sfx);
        $this->assign('captcha_errmsg', @$captcha_errmsg);
        $this->assign('captcha_field', @$captcha_field);
        // **************************************************************************************
        // Load a different template file for parameters depending on whether we use FLEXI_ACCESS
        // **************************************************************************************
        if (!FLEXI_J16GE) {
            if (FLEXI_ACCESS) {
                $formparams = new JParameter('', JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_flexicontent' . DS . 'models' . DS . 'item2.xml');
            } else {
                $formparams = new JParameter('', JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_flexicontent' . DS . 'models' . DS . 'item.xml');
            }
        }
        // ****************************************************************
        // SET INTO THE FORM, parameter values for various parameter groups
        // ****************************************************************
        if (!FLEXI_J16GE) {
            // Permissions (Access) Group
            if (!FLEXI_ACCESS) {
                $formparams->set('access', $item->access);
            }
            // Set: (Publication) Details Group
            $created_by = intval($item->created_by) ? intval($item->created_by) : $user->get('id');
            $formparams->set('created_by', $created_by);
            $formparams->set('created_by_alias', $item->created_by_alias);
            $formparams->set('created', JHTML::_('date', $item->created, '%Y-%m-%d %H:%M:%S'));
            $formparams->set('publish_up', JHTML::_('date', $item->publish_up, '%Y-%m-%d %H:%M:%S'));
            if (JHTML::_('date', $item->publish_down, '%Y') <= 1969 || $item->publish_down == $nullDate || empty($item->publish_down)) {
                $formparams->set('publish_down', JText::_('FLEXI_NEVER'));
            } else {
                $formparams->set('publish_down', JHTML::_('date', $item->publish_down, '%Y-%m-%d %H:%M:%S'));
            }
            // Set:  Attributes (parameters) Group, (these are retrieved from the item table column 'attribs')
            // (also contains templates parameters, but we will use these individual for every template ... see below)
            $formparams->loadINI($item->attribs);
            //echo "<pre>"; print_r($formparams->_xml['themes']->_children[0]);  echo "<pre>"; print_r($formparams->_xml['themes']->param[0]); exit;
            foreach ($formparams->_xml['themes']->_children as $i => $child) {
                if (isset($child->_attributes['enableparam']) && !$params->get($child->_attributes['enableparam'])) {
                    unset($formparams->_xml['themes']->_children[$i]);
                    unset($formparams->_xml['themes']->param[$i]);
                }
            }
            // Set: Metadata (parameters) Group
            // NOTE: (2 params from 2 item table columns, and then multiple params from item table column 'metadata')
            $formparams->set('description', $item->metadesc);
            $formparams->set('keywords', $item->metakey);
            if (!empty($item->metadata)) {
                $formparams->loadINI($item->metadata->toString());
            }
            // Now create the sliders object,
            // And also push the Form Parameters object into the template (Template Parameters object is seperate)
            jimport('joomla.html.pane');
            $pane = JPane::getInstance('Sliders');
            //$tabs_pane = JPane::getInstance('Tabs');
            $this->assignRef('pane', $pane);
            //$this->assignRef('tabs_pane'	, $tabs_pane);
            $this->assignRef('formparams', $formparams);
        } else {
            if (JHTML::_('date', $item->publish_down, 'Y') <= 1969 || $item->publish_down == $nullDate) {
                $item->publish_down = JText::_('FLEXI_NEVER');
            }
        }
        // ****************************
        // Handle Template related work
        // ****************************
        // (a) Get the templates structures used to create form fields for template parameters
        $themes = flexicontent_tmpl::getTemplates();
        $tmpls_all = $themes->items;
        // (b) Get Content Type allowed templates
        $allowed_tmpls = $tparams->get('allowed_ilayouts');
        $type_default_layout = $tparams->get('ilayout', 'default');
        if (empty($allowed_tmpls)) {
            $allowed_tmpls = array();
        } else {
            if (!is_array($allowed_tmpls)) {
                $allowed_tmpls = !FLEXI_J16GE ? array($allowed_tmpls) : explode("|", $allowed_tmpls);
            }
        }
        // (c) Add default layout, unless all templates allowed (=array is empty)
        if (count($allowed_tmpls) && !in_array($type_default_layout, $allowed_tmpls)) {
            $allowed_tmpls[] = $type_default_layout;
        }
        // (d) Create array of template data according to the allowed templates for current content type
        if (count($allowed_tmpls)) {
            foreach ($tmpls_all as $tmpl) {
                if (in_array($tmpl->name, $allowed_tmpls)) {
                    $tmpls[] = $tmpl;
                }
            }
        } else {
            $tmpls = $tmpls_all;
        }
        // (e) Apply Template Parameters values into the form fields structures
        foreach ($tmpls as $tmpl) {
            if (FLEXI_J16GE) {
                $jform = new JForm('com_flexicontent.template.item', array('control' => 'jform', 'load_data' => true));
                $jform->load($tmpl->params);
                $tmpl->params = $jform;
                foreach ($tmpl->params->getGroup('attribs') as $field) {
                    $fieldname = $field->__get('fieldname');
                    $value = $item->itemparams->get($fieldname);
                    if (strlen($value)) {
                        $tmpl->params->setValue($fieldname, 'attribs', $value);
                    }
                }
            } else {
                $tmpl->params->loadINI($item->attribs);
            }
        }
        $this->assignRef('tmpls', $tmpls);
        if ($print_logging_info) {
            $start_microtime = microtime(true);
        }
        parent::display($tpl);
        if ($print_logging_info) {
            $fc_run_times['form_rendering'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10;
        }
    }
Ejemplo n.º 25
0
 function display($tpl = null)
 {
     JRequest::setVar('hidemainmenu', 1);
     $model = $this->getModel();
     $category = $model->getData();
     if (K2_JVERSION == '15') {
         JFilterOutput::objectHTMLSafe($category);
     } else {
         JFilterOutput::objectHTMLSafe($category, ENT_QUOTES, array('params', 'plugins'));
     }
     if (!$category->id) {
         $category->published = 1;
     }
     $this->assignRef('row', $category);
     $wysiwyg = JFactory::getEditor();
     $editor = $wysiwyg->display('description', $category->description, '100%', '250px', '', '', array('pagebreak', 'readmore'));
     $this->assignRef('editor', $editor);
     $document = JFactory::getDocument();
     $js = "\n\t\tvar K2SitePath = '" . JURI::root(true) . "/';\n\t\tvar K2BasePath = '" . JURI::base(true) . "/';\n\t\t";
     $document->addScriptDeclaration($js);
     $lists = array();
     $lists['published'] = JHTML::_('select.booleanlist', 'published', 'class="inputbox"', $category->published);
     $lists['access'] = version_compare(JVERSION, '3.0', 'ge') ? JHTML::_('access.level', 'access', $category->access) : JHTML::_('list.accesslevel', $category);
     $query = 'SELECT ordering AS value, name AS text FROM #__k2_categories ORDER BY ordering';
     $lists['ordering'] = version_compare(JVERSION, '3.0', 'ge') ? NUll : JHTML::_('list.specificordering', $category, $category->id, $query);
     $categories[] = JHTML::_('select.option', '0', JText::_('K2_NONE_ONSELECTLISTS'));
     $categoriesModel = K2Model::getInstance('Categories', 'K2Model');
     $tree = $categoriesModel->categoriesTree($category, true, false);
     $categories = array_merge($categories, $tree);
     $lists['parent'] = JHTML::_('select.genericlist', $categories, 'parent', 'class="inputbox"', 'value', 'text', $category->parent);
     $extraFieldsModel = K2Model::getInstance('ExtraFields', 'K2Model');
     $groups = $extraFieldsModel->getGroups();
     $group[] = JHTML::_('select.option', '0', JText::_('K2_NONE_ONSELECTLISTS'), 'id', 'name');
     $group = array_merge($group, $groups);
     $lists['extraFieldsGroup'] = JHTML::_('select.genericlist', $group, 'extraFieldsGroup', 'class="inputbox" size="1" ', 'id', 'name', $category->extraFieldsGroup);
     if (version_compare(JVERSION, '1.6.0', 'ge')) {
         $languages = JHTML::_('contentlanguage.existing', true, true);
         $lists['language'] = JHTML::_('select.genericlist', $languages, 'language', '', 'value', 'text', $category->language);
     }
     JPluginHelper::importPlugin('k2');
     $dispatcher = JDispatcher::getInstance();
     $K2Plugins = $dispatcher->trigger('onRenderAdminForm', array(&$category, 'category'));
     $this->assignRef('K2Plugins', $K2Plugins);
     $params = JComponentHelper::getParams('com_k2');
     $this->assignRef('params', $params);
     if (version_compare(JVERSION, '1.6.0', 'ge')) {
         jimport('joomla.form.form');
         $form = JForm::getInstance('categoryForm', JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'category.xml');
         $values = array('params' => json_decode($category->params));
         $form->bind($values);
         $inheritFrom = isset($values['params']->inheritFrom) ? $values['params']->inheritFrom : 0;
     } else {
         $form = new JParameter('', JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'category.xml');
         $form->loadINI($category->params);
         $inheritFrom = $form->get('inheritFrom');
     }
     $this->assignRef('form', $form);
     $categories[0] = JHTML::_('select.option', '0', JText::_('K2_NONE_ONSELECTLISTS'));
     $lists['inheritFrom'] = JHTML::_('select.genericlist', $categories, 'params[inheritFrom]', 'class="inputbox"', 'value', 'text', $inheritFrom);
     $this->assignRef('lists', $lists);
     JRequest::getInt('cid') ? $title = JText::_('K2_EDIT_CATEGORY') : ($title = JText::_('K2_ADD_CATEGORY'));
     JToolBarHelper::title($title, 'k2.png');
     JToolBarHelper::save();
     JToolBarHelper::custom('saveAndNew', 'save.png', 'save_f2.png', 'K2_SAVE_AND_NEW', false);
     JToolBarHelper::apply();
     JToolBarHelper::cancel();
     // ACE ACL integration
     $definedConstants = get_defined_constants();
     if (!empty($definedConstants['ACEACL']) && AceaclApi::authorize('permissions', 'com_aceacl')) {
         $aceAclFlag = true;
     } else {
         $aceAclFlag = false;
     }
     $this->assignRef('aceAclFlag', $aceAclFlag);
     parent::display($tpl);
 }
Ejemplo n.º 26
0
 /**
  * Edit a form
  */
 function edit()
 {
     $user =& JFactory::getUser();
     $session =& JFactory::getSession();
     $db =& JFactory::getDBO();
     $lists = array();
     $row =& JTable::getInstance('form', 'Table');
     if ($this->_task == 'edit') {
         $cid = JRequest::getVar('cid', array(0), 'method', 'array');
         $cid = array((int) $cid[0]);
     } else {
         $cid = array(0);
     }
     $row->load($cid[0]);
     if ($cid) {
         $row->checkout($user->get('id'));
     }
     $model = JModel::getInstance('Form', 'FabrikModel');
     $model->setId($cid[0]);
     $model->getTable();
     $groupModels =& $model->getGroupsHiarachy();
     $possible_email_receipt_fields[] = JHTML::_('select.option', '', 'n/a');
     foreach ($groupModels as $groupModel) {
         $groupModel->_form =& $model;
         $elementModels =& $groupModel->getMyElements();
         foreach ($elementModels as $elementModel) {
             if ($elementModel->isReceiptElement()) {
                 $element =& $elementModel->getElement();
                 $possible_email_receipt_fields[] = JHTML::_('select.option', $element->name, $element->label);
             }
         }
     }
     // get params definitions
     $params = new fabrikParams($row->attribs, JPATH_COMPONENT . DS . 'xml' . DS . 'form.xml');
     require_once JPATH_COMPONENT . DS . 'views' . DS . 'form.php';
     // get a list of used groups
     $sql = "SELECT  #__fabrik_formgroup.group_id AS value,\n\t\t\t#__fabrik_groups.name AS text\n\t\t\tFROM #__fabrik_formgroup\n\t\t\tLEFT JOIN #__fabrik_groups\n\t\t\tON #__fabrik_formgroup.group_id = #__fabrik_groups.id\n\t\t\tWHERE  #__fabrik_formgroup.form_id = '" . $cid[0] . "'\n\t\t\tAND #__fabrik_groups.name <> ''\n\t\t\tORDER BY  #__fabrik_formgroup.ordering";
     $db->setQuery($sql);
     $current_groups = $db->loadObjectList();
     $lists['current_groups'] = $current_groups;
     $lists['current_grouplist'] = JHTML::_('select.genericlist', $current_groups, 'current_groups', "class=\"inputbox\" style=\"width:100%;\" size=\"10\" ", 'value', 'text', '/');
     // get a list of available groups - need to make the sql only return groups not already listed in mos_fabrik_fromgroup for $id
     //$$$ only unused groups can be assigned now - simplifies a load of stuff for us!
     $db->setQuery("SELECT DISTINCT(group_id) FROM #__fabrik_formgroup");
     $usedgroups = $db->loadResultArray();
     if (!empty($usedgroups)) {
         $db->setQuery("SELECT id AS value, name AS text FROM #__fabrik_groups WHERE id NOT IN(" . implode(",", $usedgroups) . ") ORDER BY `text`");
         $groups = $db->loadObjectList();
     } else {
         $groups = array();
     }
     $lists['groups'] = $groups;
     $lists['grouplist'] = JHTML::_('select.genericlist', $groups, 'groups', "class=\"inputbox\" size=\"10\" style=\"width:100%;\" ", 'value', 'text', null);
     if ($cid[0] != 0) {
         $row->_database_name = $model->getTableName();
         $row->_connection_id = $model->getListModel()->getTable()->connection_id;
     } else {
         //this is a new form so fill in some default values
         $row->error = JText::_('SOME OF THE FORM DATA IS MISSING');
         $row->submit_button_label = JText::_('SUBMIT');
         $row->_database_name = '';
         $row->_connection_id = '';
         $menus = array();
     }
     //get the view only templates
     $viewTemplate = $row->view_only_template == '' ? "default" : $row->view_only_template;
     $lists['viewOnlyTemplates'] = FabrikHelperAdminHTML::templateList('form', 'view_only_template', $viewTemplate);
     //get the form templates
     $formTemplate = $row->form_template == '' ? "default" : $row->form_template;
     $lists['formTemplates'] = FabrikHelperAdminHTML::templateList('form', 'form_template', $formTemplate);
     $pluginManager = JModel::getInstance('Pluginmanager', 'FabrikModel');
     $pluginManager->getPlugInGroup('form');
     // Create the form
     $form = new JParameter('', JPATH_COMPONENT . DS . 'models' . DS . 'form.xml');
     $form->bind($row);
     if ($cid[0] == 0 || $form->get('publish_down') == '' || $form->get('publish_down') == $db->getNullDate()) {
         $form->set('publish_down', JText::_('Never'));
     } else {
         $form->set('publish_down', JHTML::_('date', $row->publish_down, '%Y-%m-%d %H:%M:%S'));
     }
     $form->set('created', JHTML::_('date', $row->created, '%Y-%m-%d %H:%M:%S'));
     $form->set('publish_up', JHTML::_('date', $row->publish_up, '%Y-%m-%d %H:%M:%S'));
     $form->loadINI($row->attribs);
     $session->set('com_fabrik.admin.form.edit.model', $model);
     FabrikViewForm::edit($row, $pluginManager, $lists, $params, $form);
 }