function display($tpl = null) { $user = JFactory::getUser(); $dispatcher = JDispatcher::getInstance(); // Initialize some variables $item =& $this->get('Item'); $params =& $item->parameters; $fields =& $this->get('Extrafields'); $tags =& $item->tags; $categories =& $item->categories; $favourites = $item->favourites; $favoured = $item->favoured; // process the new plugins JPluginHelper::importPlugin('content', 'image'); if (!FLEXI_J16GE) { $dispatcher->trigger('onPrepareContent', array(&$item, &$params, 0)); } else { $dispatcher->trigger('onContentPrepare', array('com_content.article', &$item, &$params, 0)); } $document = JFactory::getDocument(); // set document information $document->setTitle($item->title); $document->setName($item->alias); $document->setDescription($item->metadesc); $document->setMetaData('keywords', $item->metakey); // prepare header lines $document->setHeader($this->_getHeaderText($item, $params)); $pdf_format_fields = trim($params->get("pdf_format_fields")); $pdf_format_fields = !$pdf_format_fields ? array() : preg_split("/[\\s]*,[\\s]*/", $pdf_format_fields); $methodnames = array(); foreach ($pdf_format_fields as $pdf_format_field) { @(list($fieldname, $methodname) = preg_split("/[\\s]*:[\\s]*/", $pdf_format_field)); $methodnames[$fieldname] = empty($methodname) ? 'display' : $methodname; } // IF no fields set then just print the item's description text if (!count($pdf_format_fields)) { echo $item->text; return; } foreach ($fields as $field) { if (!isset($methodnames[$field->name])) { continue; } if ($field->iscore) { FlexicontentFields::loadFieldConfig($field, $item); //$results = $dispatcher->trigger('onDisplayCoreFieldValue', array( &$field, $item, &$params, $tags, $categories, $favourites, $favoured )); FLEXIUtilities::call_FC_Field_Func('core', 'onDisplayCoreFieldValue', array(&$field, $item, &$params, $tags, $categories, $favourites, $favoured)); } else { //$results = $dispatcher->trigger('onDisplayFieldValue', array( &$field, $item )); FLEXIUtilities::call_FC_Field_Func($field->field_type, 'onDisplayFieldValue', array(&$field, $item)); } if (@$field->display) { echo '<b>' . $field->label . '</b>: '; echo $field->display . '<br /><br />'; } } }
static function replaceFieldValue(&$field, &$item, $variable, $varname, &$cacheable = false) { static $parsed = array(); static $d; static $c; // Parse field variable if not already parsed if (!isset($parsed[$field->id][$varname])) { $parsed[$field->id][$varname] = true; $result = preg_match_all("/\\{\\{([a-zA-Z_0-9]+)(##)?([0-9]+)?(##)?([a-zA-Z_0-9]+)?\\}\\}/", $variable, $field_matches); if ($result) { $d[$field->id][$varname]['fulltxt'] = $field_matches[0]; $d[$field->id][$varname]['fieldname'] = $field_matches[1]; $d[$field->id][$varname]['valueno'] = $field_matches[3]; $d[$field->id][$varname]['propname'] = $field_matches[5]; } else { $d[$field->id][$varname]['fulltxt'] = array(); $d[$field->id][$varname]['valueno'] = false; } $result = preg_match_all("/\\{\\{(item->)([a-zA-Z_0-9]+)\\}\\}/", $variable, $field_matches); if ($result) { $c[$field->id][$varname]['fulltxt'] = $field_matches[0]; $c[$field->id][$varname]['propname'] = $field_matches[2]; } else { $c[$field->id][$varname]['fulltxt'] = array(); } if (!count($d[$field->id][$varname]['fulltxt']) && !count($c[$field->id][$varname]['fulltxt'])) { $cacheable = true; } } // Replace variable foreach ($d[$field->id][$varname]['fulltxt'] as $i => $fulltxt) { $fieldname = $d[$field->id][$varname]['fieldname'][$i]; $valueno = $d[$field->id][$varname]['valueno'][$i] ? (int) $d[$field->id][$varname]['valueno'][$i] : 0; $propname = $d[$field->id][$varname]['propname'][$i] ? $d[$field->id][$varname]['propname'][$i] : ''; $fieldid = @$item->fields[$fieldname]->id; $value = @$item->fieldvalues[$fieldid][$valueno]; if (!$fieldid) { $value = 'Field with name: ' . $fieldname . ' not found'; $variable = str_replace($fulltxt, $value, $variable); continue; } $is_indexable = $propname && preg_match("/^_([a-zA-Z_0-9]+)_\$/", $propname, $prop_matches) && ($propname = $prop_matches[1]); if ($fieldid <= 14) { if ($fieldid == 13) { $value = @$item->categories[$valueno]->{$propname}; } else { if ($fieldid == 14) { $value = @$item->tags[$valueno]->{$propname}; } } } else { if ($is_indexable) { if ($propname != 'value') { $extra_props = $propname != 'text' ? array($propname) : array(); // this will work only if field has a single extra property $extra_props = array(); if (!isset($item->fields[$fieldname]->parameters)) { FlexicontentFields::loadFieldConfig($item->fields[$fieldname], $item); } $elements = FlexicontentFields::indexedField_getElements($item->fields[$fieldname], $item, $extra_props); $value = @$elements[$value]->{$propname}; } } else { if ($propname) { $value = @unserialize($value); $value = @$value[$propname]; } } } $variable = str_replace($fulltxt, $value, $variable); //echo "<pre>"; print_r($item->fieldvalues[$fieldid]); echo "</pre>"; echo "Replaced $fulltxt with ITEM field VALUE: $value <br>"; } // Replace variable foreach ($c[$field->id][$varname]['fulltxt'] as $i => $fulltxt) { $propname = $c[$field->id][$varname]['propname'][$i]; if (!isset($item->{$propname})) { $value = 'Item property with name: ' . $propname . ' not found'; $variable = str_replace($fulltxt, $value, $variable); continue; } $value = $item->{$propname}; $variable = str_replace($fulltxt, $value, $variable); //echo "<pre>"; echo "</pre>"; echo "Replaced $fulltxt with ITEM property VALUE: $value <br>"; } // Return variable after all replacements return $variable; }
function getCascadedField() { $field_id = JRequest::getInt('field_id', 0); $item_id = JRequest::getInt('item_id', 0); $valgrps = JRequest::getVar('valgrps', ''); $valindex = JRequest::getVar('valindex', 0); // Load field $_fields = FlexicontentFields::getFieldsByIds(array($field_id), array($item_id)); $field = $_fields[$field_id]; $field->item_id = $item_id; $field->valgrps = $valgrps; $field->valindex = $valindex; // Load item $item = JTable::getInstance($_type = 'flexicontent_items', $_prefix = '', $_config = array()); $item->load($item_id); // Get field configuration FlexicontentFields::loadFieldConfig($field, $item); // Get field values //$_fieldvalues = FlexicontentFields::getFieldValsById(array($field_id), array($item_id)); $field->value = null; //isset($_fieldvalues[$item_id][$field_id]) ? $_fieldvalues[$item_id][$field_id] : array(); // Render field $field->isAjax = 1; $this->onDisplayField($field, $item); // Output the field echo $field->html; exit; }
function getRatingResolution() { if ($this->_rating_resolution) { return $this->_rating_resolution; } $this->_db->setQuery('SELECT * FROM #__flexicontent_fields WHERE field_type="voting"'); $field = $this->_db->loadObject(); $item = JTable::getInstance($type = 'flexicontent_items', $prefix = '', $config = array()); //$item->load( $id ); FlexicontentFields::loadFieldConfig($field, $item); $rating_resolution = (int) $field->parameters->get('rating_resolution', 5); $rating_resolution = $rating_resolution >= 5 ? $rating_resolution : 5; $rating_resolution = $rating_resolution <= 100 ? $rating_resolution : 100; $this->_rating_resolution = $rating_resolution; }
/** * 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(); // We do not have item parameters yet, but we need to do some work before creating the item // Get the COMPONENT only parameter $params = new JRegistry(); $cparams = JComponentHelper::getParams('com_flexicontent'); $params->merge($cparams); // Merge the active menu parameters if ($menu) { $params->merge($menu->params); } // 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 // ***************** FLEXI_J30GE ? JHtml::_('behavior.framework', true) : JHTML::_('behavior.mootools'); flexicontent_html::loadFramework('jQuery'); flexicontent_html::loadFramework('select2'); flexicontent_html::loadFramework('flexi-lib'); // Load custom behaviours: form validation, popup tooltips JHTML::_('behavior.formvalidation'); // load default validation JS to make sure it is overriden 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($this->baseurl . '/templates/' . $app->getTemplate() . '/css/flexicontent.css'); } // Fields common CSS $document->addStyleSheet($this->baseurl . '/components/com_flexicontent/assets/css/flexi_form_fields.css'); // Load backend / frontend shared and Joomla version specific CSS (different for frontend / backend) 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'); // 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 data and create item 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! // Try type from session $jdata = $app->getUserState('com_flexicontent.edit.item.data'); //print_r($jdata); if (!empty($jdata['type_id'])) { JRequest::setVar('typeid', (int) $jdata['type_id']); // This also forces zero if value not set } else { 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'); // Verify type is allowed to the user if (!$new_typeid) { $types = $model->getTypeslist($type_ids_arr = false, $check_perms = true, $_published = true); if ($types && count($types) == 1) { $new_typeid = $types[0]->id; } JRequest::setVar('typeid', $new_typeid); $canCreateType = true; } // FORCE model to load versioned data (URL specified version or latest version (last saved)) $version = JRequest::getVar('version', 0, 'request', 'int'); // Load specific item version (non-zero), 0 version: is unversioned data, -1 version: is latest version (=default for edit form) $item = $model->getItem(null, $check_view_access = false, $no_cache = true, $force_version = $version != 0 ? $version : -1); // -1 version means latest // Replace component/menu 'params' with thee merged component/category/type/item/menu ETC ... parameters $params =& $item->parameters; if ($print_logging_info) { $fc_run_times['get_item_data'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10; } // Load permissions (used by form template) $perms = $this->_getItemPerms($item); // Create submit configuration (for new items) into the session, this is needed before creating the item form $submitConf = $this->_createSubmitConf($item, $perms); // Most core field are created via calling methods of the form (J2.5) $form = $this->get('Form'); // is new item and ownership Flags $isnew = !$item->id; $isOwner = $item->created_by == $user->get('id'); // Get available types and the currently selected/requested type $types = $model->getTypeslist(); $typesselected = $model->getTypesselected(); // Get type parameters, these are needed besides the 'merged' item parameters, e.g. to get Type's default layout $tparams = $this->get('Typeparams'); $tparams = new JRegistry($tparams); // ********************************************************************************************************* // Get language stuff, and also load Template-Specific language file to override or add new language strings // ********************************************************************************************************* if ($enable_translation_groups) { $langAssocs = $params->get('uselang_fe') == 1 ? $this->get('LangAssocs') : false; } $langs = FLEXIUtilities::getLanguages('code'); FLEXIUtilities::loadTemplateLanguageFile($params->get('ilayout', 'default')); // ************************************* // Create captcha field via custom logic // ************************************* // create and set (into HTTP request) a unique item id for plugins that needed it if ($item->id) { $unique_tmp_itemid = $item->id; } 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); // 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 // Maybe some code can be removed by using Joomla's built-in form element (in XML file), instead of calling the captcha plugin ourselves $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); // Trigger the configured captcha plugin if ($display_captcha) { // Get configured captcha plugin $c_plugin = $params->get('captcha', $app->getCfg('captcha')); // TODO add param to override default if ($c_plugin) { $c_name = 'captcha_response_field'; $c_id = $c_plugin == 'recaptcha' ? 'dynamic_recaptcha_1' : 'fc_dynamic_captcha'; $c_class = ' required'; $c_namespace = 'fc_item_form'; // Try to load the configured captcha plugin, (check if disabled or uninstalled), Joomla will enqueue an error message if needed $captcha_obj = JCaptcha::getInstance($c_plugin, array('namespace' => $c_namespace)); if ($captcha_obj) { $captcha_field = $captcha_obj->display($c_name, $c_id, $c_class); $label_class = 'flexi_label'; $label_class .= FLEXI_J30GE ? ' hasTooltip' : ' hasTip'; $label_tooltip = flexicontent_html::getToolTip(null, 'FLEXI_CAPTCHA_ENTER_CODE_DESC', 1, 1); $captcha_field = ' <label id="' . $c_name . '-lbl" for="' . $c_name . '" class="' . $label_class . '" title="' . $label_tooltip . '" > ' . JText::_('FLEXI_CAPTCHA_ENTER_CODE') . ' </label> <div id="container_fcfield_' . $c_plugin . '" class="container_fcfield container_fcfield_name_' . $c_plugin . '"> <div class="fcfieldval_container valuebox fcfieldval_container_' . $c_plugin . '"> ' . $captcha_field . ' </div> </div>'; } } } // ******************************* // CHECK EDIT / CREATE PERMISSIONS // ******************************* // User Group / Author parameters $authorparams = flexicontent_db::getUserConfig($user->id); $max_auth_limit = intval($authorparams->get('max_auth_limit', 0)); // maximum number of content items the user can create $hasTmpEdit = false; $hasCoupon = false; // Check session if ($session->has('rendered_uneditable', 'flexicontent')) { $rendered_uneditable = $session->get('rendered_uneditable', array(), 'flexicontent'); $hasTmpEdit = !empty($rendered_uneditable[$model->get('id')]); $hasCoupon = !empty($rendered_uneditable[$model->get('id')]) && $rendered_uneditable[$model->get('id')] == 2; // editable via coupon } 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(); // Get edit access, this includes privileges edit and edit-own and the temporary EDIT flag ('rendered_uneditable') $canEdit = $model->getItemAccess()->get('access-edit'); // If no edit privilege, check if edit COUPON was provided if (!$canEdit) { $edittok = JRequest::getCmd('edittok', false); if ($edittok) { $query = 'SHOW TABLES LIKE "' . $app->getCfg('dbprefix') . 'flexicontent_edit_coupons"'; $db->setQuery($query); $tbl_exists = (bool) count($db->loadObjectList()); if ($tbl_exists) { $query = 'SELECT * FROM #__flexicontent_edit_coupons ' . ' WHERE token = ' . $db->Quote($edittok) . ' AND id = ' . $model->get('id'); $db->setQuery($query); $tokdata = $db->loadObject(); if ($tokdata) { $hasCoupon = true; $rendered_uneditable = $session->get('rendered_uneditable', array(), 'flexicontent'); $rendered_uneditable[$model->get('id')] = 2; // 2: indicates, that has edit via EDIT Coupon $session->set('rendered_uneditable', $rendered_uneditable, 'flexicontent'); $canEdit = 1; } else { JError::raiseNotice(403, JText::_('EDIT_TOKEN_IS_INVALID') . ' : ' . $edittok); } } } } // Edit check finished, throw error if needed 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 // Get create access, this includes check of creating in at least one category, and type's "create items" $canAdd = $model->getItemAccess()->get('access-create'); $not_authorised = !$canAdd; // Check if Content Type can be created by current user if (empty($canCreateType)) { if ($new_typeid) { // not needed, already done be model when type_id is set, check and remove $canCreateType = $model->canCreateType(array($new_typeid)); // Can create given Content Type } else { // needed not done be model yet $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 (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' // ***************************************************************************** // 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; 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; } // Tags used by the item $usedtagsids = $this->get('UsedtagsIds'); // NOTE: This will normally return the already set versioned value of tags ($item->tags) $usedtagsdata = $model->getUsedtagsData($usedtagsids); // Get the edit lists $lists = $this->_buildEditLists($perms, $params, $authorparams); // Get number of subscribers $subscribers = $this->get('SubscribersCount'); // Get menu overridden categories/main category fields $menuCats = $this->_getMenuCats($item, $perms); // Create placement configuration for CORE properties $placementConf = $this->_createPlacementConf($item, $fields); // Item language related vars $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 = $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 // 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); $this->assignRef('form', $form); // most core field are created via calling methods of the form (J2.5) if ($enable_translation_groups) { $this->assignRef('lang_assocs', $langAssocs); } $this->assignRef('langs', $langs); $this->assignRef('params', $params); $this->assignRef('lists', $lists); $this->assignRef('subscribers', $subscribers); $this->assignRef('editor', $editor); $this->assignRef('user', $user); $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); // **************************************************************** // SET INTO THE FORM, parameter values for various parameter groups // **************************************************************** 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(); } 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) { 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); // 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; } }
/** * 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->addStyleSheetVersion(JURI::base(true) . '/components/com_flexicontent/assets/css/flexicontentbackend.css', FLEXI_VERSION); $document->addStyleSheetVersion(JURI::base(true) . '/components/com_flexicontent/assets/css/j3x.css', FLEXI_VERSION); // Fields common CSS $document->addStyleSheetVersion(JURI::root(true) . '/components/com_flexicontent/assets/css/flexi_form_fields.css', FLEXI_VERSION); // 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->addScriptVersion(JURI::root(true) . '/components/com_flexicontent/assets/js/admin.js', FLEXI_VERSION); $document->addScriptVersion(JURI::root(true) . '/components/com_flexicontent/assets/js/validate.js', FLEXI_VERSION); // Add js function for custom code used by FLEXIcontent item form $document->addScriptVersion(JURI::root(true) . '/components/com_flexicontent/assets/js/itemscreen.js', FLEXI_VERSION); // *********************** // 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); // Create display of average rating $ratings = $model->getRatingDisplay(); // ***************** // 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->language != '*' ? '&lang=' . substr($item->language, 0, 2) : ''); $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('&', '&', $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 . '\');"><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&view=template&type=items&tmpl=component&ismodal=1&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); // ***************************************************************************** // 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 = (!isset($field->html) ? '<div class="fc-mssg-inline fc-warning" style="margin:0 4px 6px 4px; max-width: unset;">' . JText::_('FLEXI_PLEASE_PUBLISH_THIS_PLUGIN') . '</div><div class="clear"></div>' : '') . '<div class="alert alert-info fc-small fc-iblock" style="margin:0 4px 6px 4px; max-width: unset;">' . JText::_('FLEXI_FIELD_VALUE_IS_NON_TRANSLATABLE') . '</div>' . "\n" . (isset($field->html) ? '<div class="clear"></div>' . $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'] .= ' ' . 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'] .= ' ' . 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'] .= ' ' . $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) . '"]; '); JText::script('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) . '"]; '); $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 (JHTML::_('date', $item->publish_down, 'Y') <= 1969 || $item->publish_down == $db->getNullDate() || empty($item->publish_down)) { $form->setValue('publish_down', null, ''); // Setting to text will break form date element } // **************************** // 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('ratings', $ratings); $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; } }
/** * Method to fetch the votes * * @since 1.5 */ function getvotes() { $id = JRequest::getInt('id', 0); $model = $this->getModel('item'); $votes = $model->getvotes($id); $db = JFactory::getDBO(); $db->setQuery('SELECT * FROM #__flexicontent_fields WHERE field_type="voting"'); $field = $db->loadObject(); $item = JTable::getInstance($type = 'flexicontent_items', $prefix = '', $config = array()); $item->load($id); FlexicontentFields::loadFieldConfig($field, $item); $rating_resolution = (int) $field->parameters->get('rating_resolution', 5); $rating_resolution = $rating_resolution >= 5 ? $rating_resolution : 5; $rating_resolution = $rating_resolution <= 100 ? $rating_resolution : 100; @ob_end_clean(); if ($votes) { $score = round((int) $votes[0]->rating_sum / (int) $votes[0]->rating_count * (100 / $rating_resolution), 2); $vote = (int) $votes[0]->rating_count > 1 ? (int) $votes[0]->rating_count . ' ' . JText::_('FLEXI_VOTES') : (int) $votes[0]->rating_count . ' ' . JText::_('FLEXI_VOTE'); echo $score . '% | ' . $vote; } else { echo JText::_('FLEXI_NOT_RATED_YET'); } exit; }
public static function getList(&$params) { global $modfc_jprof, $mod_fc_run_times; $forced_itemid = $params->get('forced_itemid'); $db = JFactory::getDBO(); $user = JFactory::getUser(); // Get IDs of user's access view levels if (!FLEXI_J16GE) { $aid = (int) $user->get('aid'); } else { $aid_arr = JAccess::getAuthorisedViewLevels($user->id); } // get the component parameters $flexiparams = JComponentHelper::getParams('com_flexicontent'); // get module ordering parameters $ordering = $params->get('ordering', array()); $count = (int) $params->get('count', 5); $featured = (int) $params->get('count_feat', 1); // Default ordering is 'added' if none ordering is set. Also make sure $ordering is an array (of ordering groups) if (empty($ordering)) { $ordering = array('added'); } if (!is_array($ordering)) { $ordering = explode(',', $ordering); } // get other module parameters $method_curlang = (int) $params->get('method_curlang', 0); // standard $display_title = $params->get('display_title'); $link_title = $params->get('link_title'); $cuttitle = $params->get('cuttitle'); $display_date = $params->get('display_date'); $display_text = $params->get('display_text'); $display_hits = $params->get('display_hits'); $display_voting = $params->get('display_voting'); $display_comments = $params->get('display_comments'); $mod_readmore = $params->get('mod_readmore'); $mod_cut_text = $params->get('mod_cut_text'); $mod_do_stripcat = $params->get('mod_do_stripcat', 1); $mod_use_image = $params->get('mod_use_image'); $mod_image = $params->get('mod_image'); $mod_link_image = $params->get('mod_link_image'); $mod_default_img_show = $params->get('mod_default_img_show', 1); $mod_default_img_path = $params->get('mod_default_img_path', 'components/com_flexicontent/assets/images/image.png'); $mod_width = (int) $params->get('mod_width', 80); $mod_height = (int) $params->get('mod_height', 80); $mod_method = (int) $params->get('mod_method', 1); // featured $display_title_feat = $params->get('display_title_feat'); $link_title_feat = $params->get('link_title_feat'); $cuttitle_feat = $params->get('cuttitle_feat'); $display_date_feat = $params->get('display_date_feat'); $display_text_feat = $params->get('display_text'); $display_hits_feat = $params->get('display_hits_feat'); $display_voting_feat = $params->get('display_voting_feat'); $display_comments_feat = $params->get('display_comments_feat'); $mod_readmore_feat = $params->get('mod_readmore_feat'); $mod_cut_text_feat = $params->get('mod_cut_text_feat'); $mod_do_stripcat_feat = $params->get('mod_do_stripcat_feat', 1); $mod_use_image_feat = $params->get('mod_use_image_feat'); $mod_link_image_feat = $params->get('mod_link_image_feat'); $mod_width_feat = (int) $params->get('mod_width_feat', 140); $mod_height_feat = (int) $params->get('mod_height_feat', 140); $mod_method_feat = (int) $params->get('mod_method_feat', 1); // Common for image of standard/feature image $mod_image_custom_display = $params->get('mod_image_custom_display'); $mod_image_custom_url = $params->get('mod_image_custom_url'); $mod_image_fallback_img = $params->get('mod_image_fallback_img'); // Retrieve default image for the image field and also create field parameters so that they can be used if ($mod_image) { $query = 'SELECT attribs, name FROM #__flexicontent_fields WHERE id = ' . (int) $mod_image; $db->setQuery($query); $mod_image_dbdata = $db->loadObject(); $mod_image_name = $mod_image_dbdata->name; //$img_fieldparams = new JRegistry($mod_image_dbdata->attribs); } if ($mod_default_img_show) { $src = $mod_default_img_path; // Default image featured $h = '&h=' . $mod_height; $w = '&w=' . $mod_width; $aoe = '&aoe=1'; $q = '&q=95'; $zc = $mod_method ? '&zc=' . $mod_method : ''; $ext = strtolower(pathinfo($src, PATHINFO_EXTENSION)); $f = in_array($ext, array('png', 'ico', 'gif')) ? '&f=' . $ext : ''; $conf = $w . $h . $aoe . $q . $zc . $f; $base_url = !preg_match("#^http|^https|^ftp|^/#i", $src) ? JURI::base(true) . '/' : ''; $thumb_default = JURI::base() . 'components/com_flexicontent/librairies/phpthumb/phpThumb.php?src=' . $base_url . $src . $conf; // Default image standard $h = '&h=' . $mod_height_feat; $w = '&w=' . $mod_width_feat; $aoe = '&aoe=1'; $q = '&q=95'; $zc = $mod_method_feat ? '&zc=' . $mod_method_feat : ''; $ext = strtolower(pathinfo($src, PATHINFO_EXTENSION)); $f = in_array($ext, array('png', 'ico', 'gif')) ? '&f=' . $ext : ''; $conf = $w . $h . $aoe . $q . $zc . $f; $base_url = !preg_match("#^http|^https|^ftp|^/#i", $src) ? JURI::base(true) . '/' : ''; $thumb_default_feat = JURI::base() . 'components/com_flexicontent/librairies/phpthumb/phpThumb.php?src=' . $base_url . $src . $conf; } // Retrieve custom displayed field data (including their parameters and access): hits/voting/etc if ($display_hits || $display_hits_feat || $display_voting || $display_voting_feat) { $query = 'SELECT * FROM #__flexicontent_fields'; $disp_field_where = array(); if ($display_hits || $display_hits_feat) { $disp_field_where[] = 'field_type="hits"'; } if ($display_voting || $display_voting_feat) { $disp_field_where[] = 'field_type="voting"'; } $query .= ' WHERE ' . implode($disp_field_where, ' OR '); $db->setQuery($query); $disp_fields_data = $db->loadObjectList('field_type'); if ($display_hits || $display_hits_feat) { $hitsfield = $disp_fields_data['hits']; $hitsfield->parameters = new JRegistry($hitsfield->attribs); $has_access_hits = in_array($hitsfield->access, $aid_arr); } if ($display_voting || $display_voting_feat) { $votingfield = $disp_fields_data['voting']; $votingfield->parameters = new JRegistry($votingfield->attribs); $has_access_voting = in_array($votingfield->access, $aid_arr); } } // get module fields parameters $use_fields = $params->get('use_fields', 1); $display_label = $params->get('display_label'); $fields = array_map('trim', explode(',', $params->get('fields'))); if ($fields[0] == '') { $fields = array(); } // get fields that when empty cause an item to be skipped $skip_items = (int) $params->get('skip_items', 0); $skiponempty_fields = array_map('trim', explode(',', $params->get('skiponempty_fields'))); if ($skiponempty_fields[0] == '') { $skiponempty_fields = array(); } if ($params->get('maxskipcount', 50) > 100) { $params->set('maxskipcount', 100); } $striptags_onempty_fields = $params->get('striptags_onempty_fields'); $onempty_fields_combination = $params->get('onempty_fields_combination'); // featured $use_fields_feat = $params->get('use_fields_feat', 1); $display_label_feat = $params->get('display_label_feat'); $fields_feat = array_map('trim', explode(',', $params->get('fields_feat'))); if ($fields_feat[0] == '') { $fields_feat = array(); } //$mod_fc_run_times['query_items']= $modfc_jprof->getmicrotime(); $cat_items_arr = array(); if (!is_array($ordering)) { $ordering = explode(',', $ordering); } foreach ($ordering as $ord) { $items_arr = modFlexicontentHelper::getItems($params, $ord); if (empty($items_arr)) { continue; } foreach ($items_arr as $catid => $items) { if (!isset($cat_items_arr[$catid])) { $cat_items_arr[$catid] = array(); } for ($i = 0; $i < count($items); $i++) { $items[$i]->featured = $i < $featured ? 1 : 0; $items[$i]->fetching = $ord; $cat_items_arr[$catid][] = $items[$i]; } } } //$mod_fc_run_times['query_items'] = $modfc_jprof->getmicrotime() - $mod_fc_run_times['query_items']; // Impementation of Empty Field Filter. // The cost of the following code is minimal. // The big time cost goes into rendering the fields ... // We need to create the display of the fields before examining if they are empty. // The hardcoded limit of max items skipped is 100. if ($skip_items && count($skiponempty_fields)) { $mod_fc_run_times['empty_fields_filter'] = $modfc_jprof->getmicrotime(); // 0. Add ONLY skipfields to the list of fields to be rendered $fields_list = implode(',', $skiponempty_fields); //$skip_params = new JRegistry(); //$skip_params->set('fields',$fields_list); foreach ($cat_items_arr as $catid => $cat_items) { // 1. The filtered rows $filtered_rows = array(); $order_count = array(); // 2. Get field values (we pass null parameters to only retrieve field values and not render (YET) the 'skip-onempty' fields FlexicontentFields::getFields($cat_items, 'module', $skip_params = null); // 3. Skip Items with empty fields (if this filter is enabled) foreach ($cat_items as $i => $item) { //echo "$i . {$item->title}<br/>"; // Check to initialize counter for this ordering if (!isset($order_count[$item->fetching])) { $order_count[$item->fetching] = 0; } // Check if enough encountered for this ordering if ($order_count[$item->fetching] >= $count) { continue; } // Initialize skip property ZERO for 'any' and ONE for 'all' $skip_curritem = $onempty_fields_combination == 'any' ? 0 : 1; // Now check for empty field display or empty field values, if so item must be skipped foreach ($skiponempty_fields as $skipfield_name) { if ($skip_items == 2) { // We will check field's display FlexicontentFields::getFieldDisplay($item, $skipfield_name, null, 'display', 'module'); $skipfield_data = @$item->fields[$skipfield_name]->display; } else { // We will check field's value $skipfield_iscore = $item->fields[$skipfield_name]->iscore; $skipfield_id = $item->fields[$skipfield_name]->id; $skipfield_data = $skipfield_iscore ? $item->{$skipfield_name} : @$item->fieldvalues[$skipfield_id]; } // Strip HTML Tags if ($striptags_onempty_fields) { $skipfield_data = strip_tags($skipfield_data); } // Decide if field is empty $skipfield_isempty = is_array($skipfield_data) ? !count($skipfield_data) : !strlen(trim($skipfield_data)); if ($skipfield_isempty) { if ($onempty_fields_combination == 'any') { $skip_curritem = 1; break; } } else { if ($onempty_fields_combination == 'all') { $skip_curritem = 0; break; } } } if ($skip_curritem) { //echo "Skip: $i . {$item->title}<br/>"; if (!isset($order_skipcount[$item->fetching])) { $order_skipcount[$item->fetching] = 0; } $order_skipcount[$item->fetching]++; continue; } // 4. Increment counter for item's ordering and Add item to list of displayed items $order_count[$item->fetching]++; $filtered_rows[] = $item; } $filtered_rows_arr[$catid] = $filtered_rows; } $mod_fc_run_times['empty_fields_filter'] = $modfc_jprof->getmicrotime() - $mod_fc_run_times['empty_fields_filter']; } else { $filtered_rows_arr =& $cat_items_arr; } $mod_fc_run_times['item_list_creation'] = $modfc_jprof->getmicrotime(); // *** OPTIMIZATION: we only render the fields after skipping unwanted items if ($use_fields && count($fields) || $use_fields_feat && count($fields_feat)) { $all_fields = array(); if ($use_fields && count($fields)) { $all_fields = array_merge($all_fields, $fields); } if ($use_fields_feat && count($fields_feat)) { $all_fields = array_merge($all_fields, $fields_feat); } $all_fields = array_unique($all_fields); $fields_list = implode(',', $all_fields); $params->set('fields', $fields_list); } // *** OPTIMIZATION: we should create some variables outside the loop ... TODO MORE if (($display_hits_feat || $display_hits) && $has_access_hits) { $hits_icon = FLEXI_J16GE ? JHTML::image('components/com_flexicontent/assets/images/' . 'user.png', JText::_('FLEXI_HITS_L')) : JHTML::_('image.site', 'user.png', 'components/com_flexicontent/assets/images/', NULL, NULL, JText::_('FLEXI_HITS_L')); } if ($display_comments_feat || $display_comments) { $comments_icon = FLEXI_J16GE ? JHTML::image('components/com_flexicontent/assets/images/' . 'comments.png', JText::_('FLEXI_COMMENTS_L')) : JHTML::_('image.site', 'comments.png', 'components/com_flexicontent/assets/images/', NULL, NULL, JText::_('FLEXI_COMMENTS_L')); } $option = JRequest::getVar('option'); $view = JRequest::getVar('view'); $isflexi_itemview = $option == 'com_flexicontent' && $view == FLEXI_ITEMVIEW; $active_item_id = JRequest::getInt('id', 0); $lists_arr = array(); foreach ($filtered_rows_arr as $catid => $filtered_rows) { if (empty($filtered_rows)) { $rows = array(); } else { if ($use_fields && count($fields) || $use_fields_feat && count($fields_feat)) { $rows = FlexicontentFields::getFields($filtered_rows, 'module', $params); } else { $rows =& $filtered_rows; } } // For Debuging /*foreach ($order_skipcount as $skipordering => $skipcount) { echo "SKIPS $skipordering ==> $skipcount<br>\n"; }*/ $lists = array(); foreach ($ordering as $ord) { $lists[$ord] = array(); } $ord = "__start__"; foreach ($rows as $row) { if ($ord != $row->fetching) { // Detect change of next ordering group $ord = $row->fetching; $i = 0; } if ($row->featured) { // image processing $thumb = ''; $thumb_rendered = ''; if ($mod_use_image_feat) { if ($mod_image_custom_display) { @(list($fieldname, $varname) = preg_split('/##/', $mod_image_custom_display)); $fieldname = trim($fieldname); $varname = trim($varname); $varname = $varname ? $varname : 'display'; $thumb_rendered = FlexicontentFields::getFieldDisplay($row, $fieldname, null, $varname, 'module'); $src = ''; } else { if ($mod_image_custom_url) { @(list($fieldname, $varname) = preg_split('/##/', $mod_image_custom_url)); $fieldname = trim($fieldname); $varname = trim($varname); $varname = $varname ? $varname : 'display'; $src = FlexicontentFields::getFieldDisplay($row, $fieldname, null, $varname, 'module'); } else { if ($mod_image) { FlexicontentFields::getFieldDisplay($row, $mod_image_name, null, 'display_large_src', 'module'); // just makes sure thumbs are created by requesting a '*_src' display $img_field =& $row->fields[$mod_image_name]; if ($mod_use_image_feat == 1) { $src = str_replace(JURI::root(), '', @$img_field->thumbs_src['large'][0]); } else { $src = ''; $thumb = @$img_field->thumbs_src[$mod_use_image_feat][0]; } if (!$src && $mod_image_fallback_img == 1 || $src && $mod_image_fallback_img == 2 && $img_field->using_default_value) { $src = flexicontent_html::extractimagesrc($row); } } else { $src = flexicontent_html::extractimagesrc($row); } } } if (!$thumb && !$src && $mod_default_img_show) { $thumb = $thumb_default_feat; } if ($src) { $h = '&h=' . $mod_height_feat; $w = '&w=' . $mod_width_feat; $aoe = '&aoe=1'; $q = '&q=95'; $zc = $mod_method_feat ? '&zc=' . $mod_method_feat : ''; $ext = strtolower(pathinfo($src, PATHINFO_EXTENSION)); $f = in_array($ext, array('png', 'ico', 'gif')) ? '&f=' . $ext : ''; $conf = $w . $h . $aoe . $q . $zc . $f; $base_url = !preg_match("#^http|^https|^ftp|^/#i", $src) ? JURI::base(true) . '/' : ''; $thumb = JURI::base() . 'components/com_flexicontent/librairies/phpthumb/phpThumb.php?src=' . $base_url . $src . $conf; } } $lists[$ord]['featured'][$i] = new stdClass(); $lists[$ord]['featured'][$i]->_row = $row; $lists[$ord]['featured'][$i]->id = $row->id; $lists[$ord]['featured'][$i]->is_active_item = $isflexi_itemview && $row->id == $active_item_id; //date if ($display_date_feat == 1) { $dateformat = JText::_($params->get('date_format_feat', 'DATE_FORMAT_LC3')); if ($dateformat == JText::_('custom')) { $dateformat = $params->get('custom_date_format_feat', JText::_('DATE_FORMAT_LC3')); } $date_fields_feat = $params->get('date_fields_feat', array('created')); $date_fields_feat = !is_array($date_fields_feat) ? array($date_fields_feat) : $date_fields_feat; $lists[$ord]['featured'][$i]->date_created = ""; if (in_array('created', $date_fields_feat)) { // Created $lists[$ord]['featured'][$i]->date_created .= $params->get('date_label_feat', 1) ? '<span class="date_label_feat">' . JText::_('FLEXI_DATE_CREATED') . '</span> ' : ''; $lists[$ord]['featured'][$i]->date_created .= '<span class="date_value_feat">' . JHTML::_('date', $row->created, $dateformat) . '</span>'; } $lists[$ord]['featured'][$i]->date_modified = ""; if (in_array('modified', $date_fields_feat)) { // Modified $lists[$ord]['featured'][$i]->date_modified .= $params->get('date_label_feat', 1) ? '<span class="date_label_feat">' . JText::_('FLEXI_DATE_MODIFIED') . '</span> ' : ''; $modified_date = $row->modified != $db->getNullDate() ? JHTML::_('date', $row->modified, $dateformat) : JText::_('FLEXI_DATE_NEVER'); $lists[$ord]['featured'][$i]->date_modified .= '<span class="date_value_feat">' . $modified_date . '</span>'; } } $lists[$ord]['featured'][$i]->image_rendered = $thumb_rendered; $lists[$ord]['featured'][$i]->image = $thumb; $lists[$ord]['featured'][$i]->hits = $row->hits; $lists[$ord]['featured'][$i]->hits_rendered = ''; if ($display_hits_feat && $has_access_hits) { FlexicontentFields::loadFieldConfig($hitsfield, $row); $lists[$ord]['featured'][$i]->hits_rendered .= $params->get('hits_label_feat') ? '<span class="hits_label_feat">' . JText::_($hitsfield->label) . '</span> ' : ''; $lists[$ord]['featured'][$i]->hits_rendered .= $hits_icon; $lists[$ord]['featured'][$i]->hits_rendered .= ' (' . $row->hits . (!$params->get('hits_label_feat') ? ' ' . JTEXT::_('FLEXI_HITS_L') : '') . ')'; } $lists[$ord]['featured'][$i]->voting = ''; if ($display_voting_feat && $has_access_voting) { FlexicontentFields::loadFieldConfig($votingfield, $row); $lists[$ord]['featured'][$i]->voting .= $params->get('voting_label_feat') ? '<span class="voting_label_feat">' . JText::_($votingfield->label) . '</span> ' : ''; $lists[$ord]['featured'][$i]->voting .= '<div class="voting_value_feat">' . flexicontent_html::ItemVoteDisplay($votingfield, $row->id, $row->rating_sum, $row->rating_count, 'main', '', $params->get('vote_stars_feat', 1), $params->get('allow_vote_feat', 0), $params->get('vote_counter_feat', 1), !$params->get('voting_label_feat')) . '</div>'; } if ($display_comments_feat) { $lists[$ord]['featured'][$i]->comments = $row->comments_total; $lists[$ord]['featured'][$i]->comments_rendered = $params->get('comments_label_feat') ? '<span class="comments_label_feat">' . JText::_('FLEXI_COMMENTS') . '</span> ' : ''; $lists[$ord]['featured'][$i]->comments_rendered .= $comments_icon; $lists[$ord]['featured'][$i]->comments_rendered .= ' (' . $row->comments_total . (!$params->get('comments_label_feat') ? ' ' . JTEXT::_('FLEXI_COMMENTS_L') : '') . ')'; } $lists[$ord]['featured'][$i]->catid = $row->catid; $lists[$ord]['featured'][$i]->itemcats = explode(",", $row->itemcats); $lists[$ord]['featured'][$i]->link = JRoute::_(FlexicontentHelperRoute::getItemRoute($row->slug, $row->categoryslug, $forced_itemid, $row) . ($method_curlang == 1 ? "&lang=" . substr($row->language, 0, 2) : "")); $lists[$ord]['featured'][$i]->title = strlen($row->title) > $cuttitle_feat ? JString::substr($row->title, 0, $cuttitle_feat) . '...' : $row->title; $lists[$ord]['featured'][$i]->alias = $row->alias; $lists[$ord]['featured'][$i]->fulltitle = $row->title; $lists[$ord]['featured'][$i]->text = $mod_do_stripcat_feat ? flexicontent_html::striptagsandcut($row->introtext, $mod_cut_text_feat) : $row->introtext; $lists[$ord]['featured'][$i]->typename = $row->typename; $lists[$ord]['featured'][$i]->access = $row->access; $lists[$ord]['featured'][$i]->featured = 1; if ($use_fields_feat && @$row->fields && $fields_feat) { $lists[$ord]['featured'][$i]->fields = array(); foreach ($fields_feat as $field) { if (!isset($row->fields[$field])) { continue; } /*$lists[$ord]['featured'][$i]->fields[$field] = new stdClass(); $lists[$ord]['featured'][$i]->fields[$field]->display = @$row->fields[$field]->display ? $row->fields[$field]->display : ''; $lists[$ord]['featured'][$i]->fields[$field]->name = $row->fields[$field]->name; $lists[$ord]['featured'][$i]->fields[$field]->id = $row->fields[$field]->id;*/ // Expose field to the module template ... the template should NOT modify this ... if (!isset($row->fields[$field]->display)) { $row->fields[$field]->display = ''; } $lists[$ord]['featured'][$i]->fields[$field] = $row->fields[$field]; } } $i++; } else { // image processing $thumb = ''; $thumb_rendered = ''; if ($mod_use_image) { if ($mod_image_custom_display) { @(list($fieldname, $varname) = preg_split('/##/', $mod_image_custom_display)); $fieldname = trim($fieldname); $varname = trim($varname); $varname = $varname ? $varname : 'display'; $thumb_rendered = FlexicontentFields::getFieldDisplay($row, $fieldname, null, $varname, 'module'); $src = ''; // Clear src no rendering needed } else { if ($mod_image_custom_url) { @(list($fieldname, $varname) = preg_split('/##/', $mod_image_custom_url)); $fieldname = trim($fieldname); $varname = trim($varname); $varname = $varname ? $varname : 'display'; $src = FlexicontentFields::getFieldDisplay($row, $fieldname, null, $varname, 'module'); } else { if ($mod_image) { FlexicontentFields::getFieldDisplay($row, $mod_image_name, null, 'display_large_src', 'module'); // just makes sure thumbs are created by requesting a '*_src' display $img_field =& $row->fields[$mod_image_name]; if ($mod_use_image == 1) { $src = str_replace(JURI::root(), '', @$img_field->thumbs_src['large'][0]); } else { $src = ''; $thumb = @$img_field->thumbs_src[$mod_use_image][0]; } if (!$src && $mod_image_fallback_img == 1 || $src && $mod_image_fallback_img == 2 && $img_field->using_default_value) { $src = flexicontent_html::extractimagesrc($row); } } else { $src = flexicontent_html::extractimagesrc($row); } } } if (!$thumb && !$src && $mod_default_img_show) { $thumb = $thumb_default; } if ($src) { $h = '&h=' . $mod_height; $w = '&w=' . $mod_width; $aoe = '&aoe=1'; $q = '&q=95'; $zc = $mod_method ? '&zc=' . $mod_method : ''; $ext = strtolower(pathinfo($src, PATHINFO_EXTENSION)); $f = in_array($ext, array('png', 'ico', 'gif')) ? '&f=' . $ext : ''; $conf = $w . $h . $aoe . $q . $zc . $f; $base_url = !preg_match("#^http|^https|^ftp|^/#i", $src) ? JURI::base(true) . '/' : ''; $thumb = JURI::base() . 'components/com_flexicontent/librairies/phpthumb/phpThumb.php?src=' . $base_url . $src . $conf; } } // START population of item's custom properties $lists[$ord]['standard'][$i] = new stdClass(); $lists[$ord]['standard'][$i]->_row = $row; $lists[$ord]['standard'][$i]->id = $row->id; $lists[$ord]['standard'][$i]->is_active_item = $isflexi_itemview && $row->id == $active_item_id; //date if ($display_date == 1) { $dateformat = JText::_($params->get('date_format', 'DATE_FORMAT_LC3')); if ($dateformat == JText::_('custom')) { $dateformat = $params->get('custom_date_format', JText::_('DATE_FORMAT_LC3')); } $date_fields = $params->get('date_fields', array('created')); $date_fields = !is_array($date_fields) ? array($date_fields) : $date_fields; $lists[$ord]['standard'][$i]->date_created = ""; if (in_array('created', $date_fields)) { // Created $lists[$ord]['standard'][$i]->date_created .= $params->get('date_label', 1) ? '<span class="date_label">' . JText::_('FLEXI_DATE_CREATED') . '</span> ' : ''; $lists[$ord]['standard'][$i]->date_created .= '<span class="date_value">' . JHTML::_('date', $row->created, $dateformat) . '</span>'; } $lists[$ord]['standard'][$i]->date_modified = ""; if (in_array('modified', $date_fields)) { // Modified $lists[$ord]['standard'][$i]->date_modified .= $params->get('date_label', 1) ? '<span class="date_label">' . JText::_('FLEXI_DATE_MODIFIED') . '</span> ' : ''; $modified_date = $row->modified != $db->getNullDate() ? JHTML::_('date', $row->modified, $dateformat) : JText::_('FLEXI_DATE_NEVER'); $lists[$ord]['standard'][$i]->date_modified .= '<span class="date_value_feat">' . $modified_date . '</span>'; } } $lists[$ord]['standard'][$i]->image_rendered = $thumb_rendered; $lists[$ord]['standard'][$i]->image = $thumb; $lists[$ord]['standard'][$i]->hits = $row->hits; $lists[$ord]['standard'][$i]->hits_rendered = ''; if ($display_hits && $has_access_hits) { FlexicontentFields::loadFieldConfig($hitsfield, $row); $lists[$ord]['standard'][$i]->hits_rendered .= $params->get('hits_label') ? '<span class="hits_label">' . JText::_($hitsfield->label) . '</span> ' : ''; $lists[$ord]['standard'][$i]->hits_rendered .= $hits_icon; $lists[$ord]['standard'][$i]->hits_rendered .= ' (' . $row->hits . (!$params->get('hits_label') ? ' ' . JTEXT::_('FLEXI_HITS_L') : '') . ')'; } $lists[$ord]['standard'][$i]->voting = ''; if ($display_voting && $has_access_voting) { FlexicontentFields::loadFieldConfig($votingfield, $row); $lists[$ord]['standard'][$i]->voting .= $params->get('voting_label') ? '<span class="voting_label">' . JText::_($votingfield->label) . '</span> ' : ''; $lists[$ord]['standard'][$i]->voting .= '<div class="voting_value">' . flexicontent_html::ItemVoteDisplay($votingfield, $row->id, $row->rating_sum, $row->rating_count, 'main', '', $params->get('vote_stars', 1), $params->get('allow_vote', 0), $params->get('vote_counter', 1), !$params->get('voting_label')) . '</div>'; } if ($display_comments) { $lists[$ord]['standard'][$i]->comments = $row->comments_total; $lists[$ord]['standard'][$i]->comments_rendered = $params->get('comments_label') ? '<span class="comments_label">' . JText::_('FLEXI_COMMENTS') . '</span> ' : ''; $lists[$ord]['standard'][$i]->comments_rendered .= $comments_icon; $lists[$ord]['standard'][$i]->comments_rendered .= ' (' . $row->comments_total . (!$params->get('comments_label') ? ' ' . JTEXT::_('FLEXI_COMMENTS_L') : '') . ')'; } $lists[$ord]['standard'][$i]->catid = $row->catid; $lists[$ord]['standard'][$i]->itemcats = explode(",", $row->itemcats); $lists[$ord]['standard'][$i]->link = JRoute::_(FlexicontentHelperRoute::getItemRoute($row->slug, $row->categoryslug, $forced_itemid, $row) . ($method_curlang == 1 ? "&lang=" . substr($row->language, 0, 2) : "")); $lists[$ord]['standard'][$i]->title = strlen($row->title) > $cuttitle ? JString::substr($row->title, 0, $cuttitle) . '...' : $row->title; $lists[$ord]['standard'][$i]->alias = $row->alias; $lists[$ord]['standard'][$i]->fulltitle = $row->title; $lists[$ord]['standard'][$i]->text = $mod_do_stripcat ? flexicontent_html::striptagsandcut($row->introtext, $mod_cut_text) : $row->introtext; $lists[$ord]['standard'][$i]->typename = $row->typename; $lists[$ord]['standard'][$i]->access = $row->access; $lists[$ord]['standard'][$i]->featured = 0; if ($use_fields && @$row->fields && $fields) { $lists[$ord]['standard'][$i]->fields = array(); foreach ($fields as $field) { if (!isset($row->fields[$field])) { continue; } /*$lists[$ord]['standard'][$i]->fields[$field] = new stdClass(); $lists[$ord]['standard'][$i]->fields[$field]->display = @$row->fields[$field]->display ? $row->fields[$field]->display : ''; $lists[$ord]['standard'][$i]->fields[$field]->name = $row->fields[$field]->name; $lists[$ord]['standard'][$i]->fields[$field]->id = $row->fields[$field]->id;*/ // Expose field to the module template ... the template should NOT modify this ... if (!isset($row->fields[$field]->display)) { $row->fields[$field]->display = ''; } $lists[$ord]['standard'][$i]->fields[$field] = $row->fields[$field]; // Expose field to the module template ... but template may modify it ... } } $i++; } } $lists_arr[$catid] = $lists; } $mod_fc_run_times['item_list_creation'] = $modfc_jprof->getmicrotime() - $mod_fc_run_times['item_list_creation']; return $lists_arr; }
function translateFieldValues(&$fields, &$row, $lang_from, $lang_to) { // Translate 'text' TYPE fields $fieldnames_arr = array(); $fieldvalues_arr = array(); foreach ($fields as $field_index => $field) { if ($field->field_type != 'text') { continue; } $fieldnames_arr[] = 'field_value' . $field_index; $translatable_obj = new stdClass(); $translatable_obj->originalValue = $field->value; $translatable_obj->noTranslate = false; $fieldvalues_arr[] = $translatable_obj; } if (count($fieldvalues_arr)) { $result = autoTranslator::translateItem($fieldnames_arr, $fieldvalues_arr, $lang_from, $lang_to); if (intval($result)) { foreach ($fieldnames_arr as $index => $fieldname) { $field_index = str_replace('field_value', '', $fieldname); $fields[$field_index]->value = $fieldvalues_arr[$index]->translationValue; } } } // Translate 'textarea' TYPE fields $fieldnames_arr = array(); $fieldvalues_arr = array(); foreach ($fields as $field_index => $field) { if ($field->field_type != 'textarea' && $field->field_type != 'maintext') { continue; } if (!is_array($field->value)) { $field->value = array($field->value); } // Load field parameters FlexicontentFields::loadFieldConfig($field, $row); // Parse fulltext field into tabs to avoid destroying them during translation FLEXIUtilities::call_FC_Field_Func('textarea', 'parseTabs', array(&$field, &$row)); $dti =& $field->tab_info; if (!$field->tabs_detected) { $fieldnames_arr[] = $field->name; $translatable_obj = new stdClass(); $translatable_obj->originalValue = $field->value[0]; $translatable_obj->noTranslate = false; $fieldvalues_arr[] = $translatable_obj; } else { // BEFORE tabs $fieldnames_arr[] = 'beforetabs'; $translatable_obj = new stdClass(); $translatable_obj->originalValue = $dti->beforetabs; $translatable_obj->noTranslate = false; $fieldvalues_arr[] = $translatable_obj; // AFTER tabs $fieldnames_arr[] = 'aftertabs'; $translatable_obj = new stdClass(); $translatable_obj->originalValue = $dti->aftertabs; $translatable_obj->noTranslate = false; $fieldvalues_arr[] = $translatable_obj; // TAB titles foreach ($dti->tab_titles as $i => $tab_title) { $fieldnames_arr[] = 'tab_titles_' . $i; $translatable_obj = new stdClass(); $translatable_obj->originalValue = $tab_title; $translatable_obj->noTranslate = false; $fieldvalues_arr[] = $translatable_obj; } // TAB contents foreach ($dti->tab_contents as $i => $tab_content) { $fieldnames_arr[] = 'tab_contents_' . $i; $translatable_obj = new stdClass(); $translatable_obj->originalValue = $tab_content; $translatable_obj->noTranslate = false; $fieldvalues_arr[] = $translatable_obj; } } // Do Google Translation unset($translated_parts); if (count($fieldvalues_arr)) { $result = autoTranslator::translateItem($fieldnames_arr, $fieldvalues_arr, $lang_from, $lang_to); if (intval($result)) { $translated_parts = new stdClass(); foreach ($fieldnames_arr as $index => $fieldname) { $translated_parts->{$fieldname} = $fieldvalues_arr[$index]->translationValue; } } } //echo "<pre>"; print_r($translated_parts); // Reconstruct field value out of the translated tabs code and assign it back to the field if (isset($translated_parts)) { if (!$field->tabs_detected) { $fields[$field_index]->value = $translated_parts->{$field->name}; } else { $translated_value = $translated_parts->beforetabs; $translated_value .= $dti->tabs_start; foreach ($dti->tab_titles as $i => $tab_title) { $translated_value .= str_replace($tab_title, $translated_parts->{'tab_titles_' . $i}, $dti->tab_startings[$i]); $translated_value .= $translated_parts->{'tab_contents_' . $i}; $translated_value .= $dti->tab_endings[$i]; } $translated_value .= $dti->tabs_end; $translated_value .= $translated_parts->aftertabs; // Assign translated value back to the field $fields[$field_index]->value = $translated_value; } } else { // no translation performed, or translation unsuccessful $field->value = $field->value[0]; } } }
/** * Method for voting (ajax) * * @TODO move the query part to the item model * @access public * @since 1.5 */ public function ajaxvote() { $app = JFactory::getApplication(); $user = JFactory::getUser(); $db = JFactory::getDBO(); $session = JFactory::getSession(); $cparams = JComponentHelper::getParams('com_flexicontent'); $no_ajax = JRequest::getInt('no_ajax'); $user_rating = JRequest::getInt('user_rating'); $cid = JRequest::getInt('cid'); $xid = JRequest::getVar('xid'); // Compatibility in case the voting originates from joomla's voting plugin if ($no_ajax && !$cid) { $cid = JRequest::getInt('id'); // Joomla 's content plugin uses 'id' HTTP request variable } // ******************************************************************* // Check for invalid xid (according to voting field/type configuration // ******************************************************************* $xid = empty($xid) ? 'main' : $xid; $int_xid = (int) $xid; if ($xid != 'main' && !$int_xid) { // Rare/unreachable voting ERROR $error = "ajaxvote(): invalid xid '" . $xid . "' was given"; // Set responce if ($no_ajax) { $app->enqueueMessage($error, 'notice'); return; } else { $result = new stdClass(); $result->percentage = ''; $result->htmlrating = ''; $error = ' <div class="fc-mssg fc-warning fc-nobgimage"> <button type="button" class="close" data-dismiss="alert">×</button> ' . $error . ' </div>'; if ($int_xid) { $result->message = $error; } else { $result->message_main = $error; } echo json_encode($result); jexit(); } } // ****************************** // Get voting field configuration // ****************************** $db->setQuery('SELECT * FROM #__flexicontent_fields WHERE field_type="voting"'); $field = $db->loadObject(); $item = JTable::getInstance($type = 'flexicontent_items', $prefix = '', $config = array()); $item->load($cid); FlexicontentFields::loadFieldConfig($field, $item); $rating_resolution = (int) $field->parameters->get('rating_resolution', 5); $rating_resolution = $rating_resolution >= 5 ? $rating_resolution : 5; $rating_resolution = $rating_resolution <= 100 ? $rating_resolution : 100; $min_rating = 1; $max_rating = $rating_resolution; $main_counter = (int) $field->parameters->get('main_counter', 1); $extra_counter = (int) $field->parameters->get('extra_counter', 1); $main_counter_show_label = (int) $field->parameters->get('main_counter_show_label', 1); $extra_counter_show_label = (int) $field->parameters->get('extra_counter_show_label', 1); $main_counter_show_percentage = (int) $field->parameters->get('main_counter_show_percentage', 0); $extra_counter_show_percentage = (int) $field->parameters->get('extra_counter_show_percentage', 0); // ***************************************************** // Find if user has the ACCESS level required for voting // ***************************************************** $aid_arr = JAccess::getAuthorisedViewLevels($user->id); $acclvl = (int) $field->parameters->get('submit_acclvl', 1); $has_acclvl = in_array($acclvl, $aid_arr); // ********************************* // Create no access Redirect Message // ********************************* if (!$has_acclvl) { $logged_no_acc_msg = $field->parameters->get('logged_no_acc_msg', ''); $guest_no_acc_msg = $field->parameters->get('guest_no_acc_msg', ''); $no_acc_msg = $user->id ? $logged_no_acc_msg : $guest_no_acc_msg; $no_acc_msg = $no_acc_msg ? JText::_($no_acc_msg) : ''; // Message not set create a Default Message if (!$no_acc_msg) { // Find name of required Access Level $acclvl_name = ''; if ($acclvl) { $db->setQuery('SELECT title FROM #__viewlevels as level WHERE level.id=' . $acclvl); $acclvl_name = $db->loadResult(); if (!$acclvl_name) { $acclvl_name = "Access Level: " . $acclvl . " not found/was deleted"; } } $no_acc_msg = JText::sprintf('FLEXI_NO_ACCESS_TO_VOTE', $acclvl_name); } } // **************************************************** // NO voting Access OR rating is NOT within valid range // **************************************************** if (!$has_acclvl || $user_rating < $min_rating && $user_rating > $max_rating) { // Voting REJECTED, avoid setting BAR percentage and HTML rating text ... someone else may have voted for the item ... $error = !$has_acclvl ? $no_acc_msg : JText::sprintf('FLEXI_VOTE_OUT_OF_RANGE', $min_rating, $max_rating); // Set responce if ($no_ajax) { $app->enqueueMessage($error, 'notice'); return; } else { $result = new stdClass(); $result->percentage = ''; $result->htmlrating = ''; $error = ' <div class="fc-mssg fc-warning fc-nobgimage"> <button type="button" class="close" data-dismiss="alert">×</button> ' . $error . ' </div>'; if ($int_xid) { $result->message = $error; } else { $result->message_main = $error; } echo json_encode($result); jexit(); } } // ************************************************* // Check extra vote exists and get extra votes types // ************************************************* $xids = array(); $enable_extra_votes = $field->parameters->get('enable_extra_votes', ''); if ($enable_extra_votes) { // Retrieve and split-up extra vote types, (removing last one if empty) $extra_votes = $field->parameters->get('extra_votes', ''); $extra_votes = preg_split("/[\\s]*%%[\\s]*/", $field->parameters->get('extra_votes', '')); if (empty($extra_votes[count($extra_votes) - 1])) { unset($extra_votes[count($extra_votes) - 1]); } // Split extra voting ids (xid) and their titles foreach ($extra_votes as $extra_vote) { @(list($extra_id, $extra_title, $extra_desc) = explode("##", $extra_vote)); $xids[$extra_id] = 1; } } if (!$int_xid && count($xids)) { $error = JText::_('FLEXI_VOTE_AVERAGE_RATING_CALCULATED_AUTOMATICALLY'); } if ($int_xid && !isset($xids[$int_xid])) { // Rare/unreachable voting ERROR $error = !$enable_extra_votes ? JText::_('FLEXI_VOTE_COMPOSITE_VOTING_IS_DISABLED') : 'Voting characteristic with id: ' . $int_xid . ' was not found'; } if (isset($error)) { // Set responce if ($no_ajax) { $app->enqueueMessage($error, 'notice'); return; } else { $result = new stdClass(); $result->percentage = ''; $result->htmlrating = ''; $error = ' <div class="fc-mssg fc-warning fc-nobgimage"> <button type="button" class="close" data-dismiss="alert">×</button> ' . $error . ' </div>'; if ($int_xid) { $result->message = $error; } else { $result->message_main = $error; } echo json_encode($result); jexit(); } } // ******************************************************************************************** // Check: item id exists in our voting logging SESSION (array) variable, to avoid double voting // ******************************************************************************************** $vote_history = $session->get('vote_history', array(), 'flexicontent'); if (!isset($vote_history[$cid]) || !is_array($vote_history[$cid])) { $vote_history[$cid] = array(); } // Allow user to change his vote $old_rating = isset($vote_history[$cid][$xid]) ? (int) $vote_history[$cid][$xid] : 0; $old_main_rating = isset($vote_history[$cid]['main']) ? (int) $vote_history[$cid]['main'] : 0; // For the case that the browser was not close we can get rating from user's session and allow to change the vote $rating_diff = $user_rating - $old_rating; // Accept votes only if user has voted for all cases, but do not store session yet $main_rating = 0; if (!count($xids)) { $voteIsComplete = true; $main_rating = $user_rating; $vote_history[$cid]['main'] = $main_rating; } else { if (!$int_xid) { die('unreachable int_xid is zero'); } $voteIsComplete = true; $main_rating = 0; $rating_completed = 0; // Add current vote $vote_history[$cid][$int_xid] = $user_rating; foreach ($xids as $_xid => $i) { if (!isset($vote_history[$cid][$_xid])) { $voteIsComplete = false; continue; } $rating_completed++; $main_rating += (int) $vote_history[$cid][$_xid]; } if ($voteIsComplete) { $main_rating = (int) ($main_rating / count($xids)); $vote_history[$cid]['main'] = $main_rating; } } $main_rating_diff = $main_rating - $old_main_rating; // ************************************* // Retreive last vote for the given item // ************************************* $currip = $_SERVER['REMOTE_ADDR']; $currip_quoted = $db->Quote($currip); $result = new stdClass(); foreach ($vote_history[$cid] as $_xid => $_rating) { if (!$voteIsComplete && $_xid != $xid) { continue; } // nothing todo //echo $_xid."\n"; $dbtbl = !(int) $_xid ? '#__content_rating' : '#__flexicontent_items_extravote'; // Choose db table to store vote (normal or extra) $and_extra_id = (int) $_xid ? ' AND field_id = ' . (int) $_xid : ''; // second part is for defining the vote type in case of extra vote $query = ' SELECT *' . ' FROM ' . $dbtbl . ' AS a ' . ' WHERE content_id = ' . (int) $cid . ' ' . $and_extra_id; $db->setQuery($query); $db_itemratings = $db->loadObject(); // *********************************************************** // Voting access allowed and valid, but we will need to make // some more checks (IF voting record exists AND double voting) // *********************************************************** // Voting record does not exist for this item, accept user's vote and insert new voting record in the db if (!$db_itemratings) { if ($voteIsComplete) { $query = ' INSERT ' . $dbtbl . ' SET content_id = ' . (int) $cid . ', ' . ' lastip = ' . $currip_quoted . ', ' . ' rating_sum = ' . (int) $user_rating . ', ' . ' rating_count = 1 ' . ((int) $_xid ? ', field_id = ' . (int) $_xid : ''); $db->setQuery($query); $db->execute() or die($db->stderr()); } } else { if ((int) $_xid && !isset($xids[$_xid]) && $_xid != 'main') { continue; } // just in case there are some old records in session table 'vote_history' //echo $db_itemratings->rating_sum. " - ".$rating_diff. "\n"; // If item is not in the user's voting history (session), then we check if this IP has voted for this item recently and refuse to accept vote if ($_xid == $xid && !$old_rating && $currip == $db_itemratings->lastip) { // Voting REJECTED, avoid setting BAR percentage and HTML rating text ... someone else may have voted for the item ... //$result->percentage = ( $db_itemratings->rating_sum / $db_itemratings->rating_count ) * (100/$rating_resolution); //$result->htmlrating = $db_itemratings->rating_count .' '. JText::_( 'FLEXI_VOTES' ); $error = JText::_('FLEXI_YOU_HAVE_ALREADY_VOTED'); //.', IP: '.$db_itemratings->lastip; if ($int_xid) { $result->message = $error; } else { $result->message_main = $error; } if ($no_ajax) { $app->enqueueMessage($int_xid ? $result->html : $result->html_main, 'notice'); return; } else { $result = new stdClass(); $result->percentage = ''; $result->htmlrating = ''; $error = ' <div class="fc-mssg fc-warning fc-nobgimage"> <button type="button" class="close" data-dismiss="alert">×</button> ' . $error . ' </div>'; if ($int_xid) { $result->message = $error; } else { $result->message_main = $error; } echo json_encode($result); jexit(); } } // If voting is completed, add all rating into DB -OR- if user has updated existing vote (update in DB only the current sub-vote and the main vote) if ($voteIsComplete && (!$old_main_rating || $_xid == 'main' || (int) $_xid == $xid)) { // vote accepted update DB $query = " UPDATE " . $dbtbl . ' SET rating_count = rating_count + ' . ($old_rating ? 0 : 1) . ' , rating_sum = rating_sum + ' . ($_xid == 'main' ? $old_main_rating ? $main_rating_diff : $main_rating : ($_xid == $xid && $old_main_rating ? $rating_diff : $_rating)) . ' , lastip = ' . $currip_quoted . ' WHERE content_id = ' . (int) $cid . ' ' . $and_extra_id; $db->setQuery($query); $db->execute() or die($db->stderr()); } } if ($_xid == 'main') { $result->rating_sum_main = @(int) $db_itemratings->rating_sum + ($old_main_rating ? $main_rating_diff : $main_rating); $result->ratingcount_main = @(int) $db_itemratings->rating_count + ($old_main_rating ? 0 : 1); $result->percentage_main = !$result->ratingcount_main ? 0 : $result->rating_sum_main / $result->ratingcount_main * (100 / $rating_resolution); $result->htmlrating_main = ($main_counter ? $result->ratingcount_main . ($main_counter_show_label ? ' ' . JText::_(@$db_itemratings ? 'FLEXI_VOTES' : 'FLEXI_VOTE') : '') . ($main_counter_show_percentage ? ' - ' : '') : '') . ($main_counter_show_percentage ? (int) $result->percentage_main . '%' : ''); } else { if ($_xid == $xid) { $result->rating_sum = @(int) $db_itemratings->rating_sum + ($old_main_rating ? $rating_diff : $_rating); $result->ratingcount = @(int) $db_itemratings->rating_count + ($old_main_rating ? 0 : 1); $result->percentage = !$result->ratingcount ? 0 : $result->rating_sum / $result->ratingcount * (100 / $rating_resolution); $result->htmlrating = ($extra_counter ? $result->ratingcount . ($extra_counter_show_label ? ' ' . JText::_(@$db_itemratings ? 'FLEXI_VOTES' : 'FLEXI_VOTE') : '') . ($extra_counter_show_percentage ? ' - ' : '') : '') . ($extra_counter_show_percentage ? (int) $result->percentage . '%' : ''); } } } // Prepare responce $html = $old_rating ? '' . 100 * ($old_rating / $max_rating) . '% => ' . 100 * ($user_rating / $max_rating) . '%' : '' . 100 * ($user_rating / $max_rating) . '%'; if ($xid == 'main') { $result->html_main = $html; } else { $result->html = $html; } if ($int_xid) { $result->message = ' <div class="fc-mssg fc-warning fc-nobgimage"> <button type="button" class="close" data-dismiss="alert">×</button> ' . JText::_('FLEXI_VOTE_YOUR_RATING') . ': ' . 100 * ($user_rating / $max_rating) . '% </div>'; if (!$voteIsComplete) { $result->message_main = ' <div class="fc-mssg fc-warning fc-nobgimage"> <button type="button" class="close" data-dismiss="alert">×</button> ' . JText::sprintf('FLEXI_VOTE_PLEASE_COMPLETE_VOTING', $rating_completed, count($xids)) . ' </div>'; } else { $result->html_main = JText::_($old_main_rating ? 'FLEXI_VOTE_AVERAGE_RATING_UPDATED' : 'FLEXI_VOTE_AVERAGE_RATING_SUBMITTED'); $result->message_main = ' <div class="fc-mssg fc-success fc-nobgimage"> <button type="button" class="close" data-dismiss="alert">×</button> ' . JText::_($old_rating ? 'FLEXI_VOTE_YOUR_OLD_AVERAGE_RATING_WAS_UPDATED' : 'FLEXI_VOTE_YOUR_AVERAGE_RATING_STORED') . ': <b>' . ($old_main_rating ? 100 * ($old_main_rating / $max_rating) . '% => ' : '') . 100 * ($main_rating / $max_rating) . '%</b> </div>'; } } else { $result->message_main = ' <div class="fc-mssg fc-success fc-nobgimage"> <button type="button" class="close" data-dismiss="alert">×</button> ' . JText::_($old_rating ? 'FLEXI_VOTE_YOUR_OLD_RATING_WAS_CHANGED' : 'FLEXI_THANK_YOU_FOR_VOTING') . ' </div>'; } // Set the voting data, into SESSION $session->set('vote_history', $vote_history, 'flexicontent'); // Finally set responce if ($no_ajax) { $app->enqueueMessage($int_xid ? $result->message_main . '<br/>' . $result->message : $result->message_main, 'notice'); return; } else { echo json_encode($result); jexit(); } }
/** * Method for voting (ajax) * * @TODO move the query part to the item model * @access public * @since 1.5 */ public function ajaxvote() { $app = JFactory::getApplication(); $user = JFactory::getUser(); $db = JFactory::getDBO(); $session = JFactory::getSession(); $cparams = JComponentHelper::getParams( 'com_flexicontent' ); $no_ajax = JRequest::getInt('no_ajax'); $user_rating = JRequest::getInt('user_rating'); $cid = JRequest::getInt('cid'); $xid = JRequest::getVar('xid'); // Compatibility in case the voting originates from joomla's voting plugin if ($no_ajax) { // Joomla 's content plugin uses 'id' HTTP request variable $cid = JRequest::getInt('id'); } // ****************************** // Get voting field configuration // ****************************** $db->setQuery('SELECT * FROM #__flexicontent_fields WHERE field_type="voting"'); $field = $db->loadObject(); $item = JTable::getInstance( $type = 'flexicontent_items', $prefix = '', $config = array() ); $item->load( $cid ); FlexicontentFields::loadFieldConfig($field, $item); $rating_resolution = (int)$field->parameters->get('rating_resolution', 5); $rating_resolution = $rating_resolution >= 5 ? $rating_resolution : 5; $rating_resolution = $rating_resolution <= 100 ? $rating_resolution : 100; $min_rating = 1; $max_rating = $rating_resolution; // ***************************************************** // Find if user has the ACCESS level required for voting // ***************************************************** if (!FLEXI_J16GE) $aid = (int) $user->get('aid'); else $aid_arr = JAccess::getAuthorisedViewLevels($user->id); $acclvl = (int) $field->parameters->get('submit_acclvl', FLEXI_J16GE ? 1 : 0); $has_acclvl = FLEXI_J16GE ? in_array($acclvl, $aid_arr) : $acclvl <= $aid; // ********************************* // Create no access Redirect Message // ********************************* if ( !$has_acclvl ) { $logged_no_acc_msg = $field->parameters->get('logged_no_acc_msg', ''); $guest_no_acc_msg = $field->parameters->get('guest_no_acc_msg', ''); $no_acc_msg = $user->id ? $logged_no_acc_msg : $guest_no_acc_msg; $no_acc_msg = $no_acc_msg ? JText::_($no_acc_msg) : ''; // Message not set create a Default Message if ( !$no_acc_msg ) { // Find name of required Access Level if (FLEXI_J16GE) { $acclvl_name = ''; if ($acclvl) { $db->setQuery('SELECT title FROM #__viewlevels as level WHERE level.id='.$acclvl); $acclvl_name = $db->loadResult(); if ( !$acclvl_name ) $acclvl_name = "Access Level: ".$acclvl." not found/was deleted"; } } else { $acclvl_names = array(0=>'Public', 1=>'Registered', 2=>'Special'); $acclvl_name = $acclvl_names[$acclvl]; } $no_acc_msg = JText::sprintf( 'FLEXI_NO_ACCESS_TO_VOTE' , $acclvl_name); } } // **************************************************** // NO voting Access OR rating is NOT within valid range // **************************************************** if ( !$has_acclvl || ($user_rating < $min_rating && $user_rating > $max_rating) ) { // Voting REJECTED, avoid setting BAR percentage and HTML rating text ... someone else may have voted for the item ... $result = new stdClass(); $result->percentage = ''; $result->htmlrating = ''; $result->html = !$has_acclvl ? $no_acc_msg : JText::sprintf( 'FLEXI_VOTING_OUT_OF_RANGE', $min_rating, $max_rating); // Set responce if ($no_ajax) { $app->enqueueMessage( $result->html, 'notice' ); return; } else { echo json_encode($result); jexit(); } } // ************************************* // Retreive last vote for the given item // ************************************* $currip = ( phpversion() <= '4.2.1' ? @getenv( 'REMOTE_ADDR' ) : $_SERVER['REMOTE_ADDR'] ); $currip_quoted = $db->Quote( $currip ); $dbtbl = !(int)$xid ? '#__content_rating' : '#__flexicontent_items_extravote'; // Choose db table to store vote (normal or extra) $and_extra_id = (int)$xid ? ' AND field_id = '.(int)$xid : ''; // second part is for defining the vote type in case of extra vote $query = ' SELECT *' . ' FROM '.$dbtbl.' AS a ' . ' WHERE content_id = '.(int)$cid.' '.$and_extra_id; $db->setQuery( $query ); $votesdb = $db->loadObject(); // ******************************************************************************************** // Check: item id exists in our voting logging SESSION (array) variable, to avoid double voting // ******************************************************************************************** $votestamp = $session->get('votestamp', array(),'flexicontent'); if ( !isset($votestamp[$cid]) || !is_array($votestamp[$cid]) ) { $votestamp[$cid] = array(); } $votecheck = isset($votestamp[$cid][$xid]); // *********************************************************** // Voting access allowed and valid, but we will need to make // some more checks (IF voting record exists AND double voting) // *********************************************************** $result = new stdClass(); // Voting record does not exist for this item, accept user's vote and insert new voting record in the db if ( !$votesdb ) { $query = ' INSERT '.$dbtbl . ' SET content_id = '.(int)$cid.', ' . ' lastip = '.$currip_quoted.', ' . ' rating_sum = '.(int)$user_rating.', ' . ' rating_count = 1 ' . ( (int)$xid ? ', field_id = '.(int)$xid : '' ); $db->setQuery( $query ); $db->query() or die( $db->stderr() ); $result->ratingcount = 1; $result->htmlrating = '(' . $result->ratingcount .' '. JText::_( 'FLEXI_VOTE' ) . ')'; } // Voting record exists for this item, check if user has already voted else { // NOTE: it is not so good way to check using ip, since 2 users may have same IP, // but for compatibility with standard joomla and for stronger security we will do it if ( !$votecheck && $currip!=$votesdb->lastip ) { // vote accepted update DB $query = " UPDATE ".$dbtbl . ' SET rating_count = rating_count + 1, ' . ' rating_sum = rating_sum + '.(int)$user_rating.', ' . ' lastip = '.$currip_quoted . ' WHERE content_id = '.(int)$cid.' '.$and_extra_id; $db->setQuery( $query ); $db->query() or die( $db->stderr() ); $result->ratingcount = $votesdb->rating_count + 1; $result->htmlrating = '(' . $result->ratingcount .' '. JText::_( 'FLEXI_VOTES' ) . ')'; } else { // Voting REJECTED, avoid setting BAR percentage and HTML rating text ... someone else may have voted for the item ... //$result->percentage = ( $votesdb->rating_sum / $votesdb->rating_count ) * (100/$rating_resolution); //$result->htmlrating = '(' . $votesdb->rating_count .' '. JText::_( 'FLEXI_VOTES' ) . ')'; $result->html = JText::_( 'FLEXI_YOU_HAVE_ALREADY_VOTED' ); if ($no_ajax) { $app->enqueueMessage( $result->html, 'notice' ); return; } else { echo json_encode($result); jexit(); } } } // Set the current item id, in our voting logging SESSION (array) variable, to avoid future double voting $votestamp[$cid][$xid] = 1; $session->set('votestamp', $votestamp, 'flexicontent'); // Prepare responce $rating_sum = (@ $votesdb ? $votesdb->rating_sum : 0) + (int) $user_rating; $result->percentage = ($rating_sum / $result->ratingcount) * (100 / $rating_resolution); $result->html = JText::_( 'FLEXI_THANK_YOU_FOR_VOTING' ); // Finally set responce if ($no_ajax) { $app->enqueueMessage( $result->html, 'notice' ); return; } else { echo json_encode($result); jexit(); } }
function getVotingResolution($id = 0) { static $rating_resolution = array(); $id = $id ? $id : $this->_id; if (empty($rating_resolution[$id])) { $this->_db->setQuery('SELECT * FROM #__flexicontent_fields WHERE field_type="voting"'); $field = $this->_db->loadObject(); $item = JTable::getInstance($type = 'flexicontent_items', $prefix = '', $config = array()); $item->load($id); FlexicontentFields::loadFieldConfig($field, $item); $_rating_resolution = (int) $field->parameters->get('rating_resolution', 5); $_rating_resolution = $_rating_resolution >= 5 ? $_rating_resolution : 5; $_rating_resolution = $_rating_resolution <= 100 ? $_rating_resolution : 100; $rating_resolution[$id] = $_rating_resolution; } return $rating_resolution[$id]; }
/** * 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(); $session = JFactory::getSession(); $user = JFactory::getUser(); $db = JFactory::getDBO(); $option = JRequest::getVar('option'); $nullDate = $db->getNullDate(); // Get the COMPONENT only parameters $params = clone JComponentHelper::getParams('com_flexicontent'); if (!FLEXI_J16GE) { jimport('joomla.html.pane'); $pane = JPane::getInstance('sliders'); $editor = JFactory::getEditor(); } // 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'); $prettycheckable_added = flexicontent_html::loadFramework('prettyCheckable'); // Load custom behaviours: form validation, popup tooltips //JHTML::_('behavior.formvalidation'); JHTML::_('behavior.tooltip'); // 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 $document->addScript(JURI::root() . 'components/com_flexicontent/assets/js/admin.js'); $document->addScript(JURI::root() . 'components/com_flexicontent/assets/js/validate.js'); // Add js function for custom code used by FLEXIcontent item form $document->addScript(JURI::root() . 'components/com_flexicontent/assets/js/itemscreen.js'); // *********************** // Get data from the model // *********************** if ($print_logging_info) { $start_microtime = microtime(true); } $model = $this->getModel(); $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 Associated Translations // *************************** if ($enable_translation_groups) { $langAssocs = $this->get('LangAssocs'); } if (FLEXI_FISH || FLEXI_J16GE) { $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 JRequest::setVar('unique_tmp_itemid', $cid ? $cid : date('_Y_m_d_h_i_s_', time()) . uniqid(true)); // 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 = FLEXI_J16GE ? new JRegistry($tparams) : new JParameter($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, $typesselected); if (!$perms['canparams']) { $document->addStyleDeclaration((FLEXI_J16GE ? '#details-options' : '#det-pane') . '{display:none;}'); } // ****************** // Create the toolbar // ****************** $toolbar = JToolBar::getInstance('toolbar'); // 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 } // Add a preview button for LATEST version of the item 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 $isAdmin = JFactory::getApplication()->isAdmin(); if ($isAdmin && FLEXI_J16GE) { JFactory::$application = JApplication::getInstance('site'); } // Create the URL $item_url = JRoute::_(FlexicontentHelperRoute::getItemRoute($item->id . ':' . $item->alias, $categories[$item->catid]->slug) . $autologin); // 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) { if (FLEXI_J16GE) { $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'); } else { $item_url = JURI::root(true) . '/' . $item_url; } } $previewlink = $item_url . (strstr($item_url, '?') ? '&' : '?') . 'preview=1'; //$previewlink = str_replace('&', '&', $previewlink); //$previewlink = JRoute::_(JURI::root() . FlexicontentHelperRoute::getItemRoute($item->id.':'.$item->alias, $categories[$item->catid]->slug)) .$autologin; if (!$params->get('use_versioning', 1) || $item->version == $item->current_version && $item->version == $item->last_version) { $toolbar->appendButton('Custom', '<a class="preview btn btn-small" href="' . $previewlink . '" target="_blank"><span title="' . JText::_('Preview') . '" class="icon-32-preview"></span>' . JText::_('Preview') . '</a>', 'preview'); } else { // Add a preview button for (currently) LOADED version of the item $previewlink_loaded_ver = $previewlink . '&version=' . $item->version; $toolbar->appendButton('Custom', '<a class="preview btn btn-small" href="' . $previewlink_loaded_ver . '" target="_blank"><span title="' . JText::_('Preview') . '" class="icon-32-preview"></span>' . JText::_('FLEXI_PREVIEW_FORM_LOADED_VERSION') . ' [' . $item->version . ']</a>', 'preview'); // Add a preview button for currently ACTIVE version of the item $previewlink_active_ver = $previewlink . '&version=' . $item->current_version; $toolbar->appendButton('Custom', '<a class="preview btn btn-small" href="' . $previewlink_active_ver . '" target="_blank"><span title="' . JText::_('Preview') . '" class="icon-32-preview"></span>' . JText::_('FLEXI_PREVIEW_FRONTEND_ACTIVE_VERSION') . ' [' . $item->current_version . ']</a>', 'preview'); // Add a preview button for currently LATEST version of the item $previewlink_last_ver = $previewlink; //'&version='.$item->last_version; $toolbar->appendButton('Custom', '<a class="preview btn btn-small" href="' . $previewlink_last_ver . '" target="_blank"><span title="' . JText::_('Preview') . '" class="icon-32-preview"></span>' . JText::_('FLEXI_PREVIEW_LATEST_SAVED_VERSION') . ' [' . $item->last_version . ']</a>', 'preview'); } JToolBarHelper::spacer(); JToolBarHelper::divider(); JToolBarHelper::spacer(); } // Common Buttons if (FLEXI_J16GE) { JToolBarHelper::apply('items.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'); } else { JToolBarHelper::apply(); if (!$isnew || $item->version) { JToolBarHelper::save(); } if (!$isnew || $item->version) { JToolBarHelper::custom('saveandnew', 'savenew.png', 'savenew.png', 'FLEXI_SAVE_AND_NEW', false); } JToolBarHelper::cancel(); } // 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; } // ************************* // 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 granular access list if (!FLEXI_J16GE) { if (FLEXI_ACCESS) { if (isset($user->level)) { $lists['access'] = FAccess::TabGmaccess($item, 'item', 1, 0, 0, 1, 0, 1, 0, 1, 1); } else { $lists['access'] = JText::_('Your profile has been changed, please logout to access to the permissions'); } } else { $lists['access'] = JHTML::_('list.accesslevel', $item); // created but not used in J1.5 backend form } } // build state list $_arc_ = FLEXI_J16GE ? 2 : -1; $non_publishers_stategrp = $perms['isSuperAdmin'] || $item->state == -3 || $item->state == -4; $special_privelege_stategrp = $item->state == $_arc_ || $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 == $_arc_ || $perms['canarchive']) { $state[] = JHTML::_('select.option', $_arc_, 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 = FLEXI_J16GE ? 'jform[state]' : 'state'; $elementid = FLEXI_J16GE ? 'jform_state' : '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-label="' . JText::_($option_label) . '" data-labelPosition="right" data-customClass="fcradiocheck"'; $lists['featured'] .= ' <input type="radio" id="' . $elementid_no . '" element_group_id="' . $elementid . '" name="' . $fieldname . '" ' . $attribs . ' value="' . $option_id . '" ' . $checked . $extra_params . ' />'; if (!$prettycheckable_added) { $lists['featured'] .= ' ' . JText::_($option_label) . '</label>'; } $i++; } } // *** EOF: J1.5 SPECIFIC SELECT LISTS // build version approval list $fieldname = FLEXI_J16GE ? 'jform[vstate]' : 'vstate'; $elementid = FLEXI_J16GE ? 'jform_vstate' : '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-label="' . JText::_($option_label) . '" data-labelPosition="right" data-customClass="fcradiocheck"'; $lists['vstate'] .= ' <input type="radio" id="' . $elementid_no . '" element_group_id="' . $elementid . '" name="' . $fieldname . '" ' . $attribs . ' value="' . $option_id . '" ' . $checked . $extra_params . ' />'; if (!$prettycheckable_added) { $lists['vstate'] .= ' ' . 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 = FLEXI_J16GE ? 'jform[notify]' : 'notify'; $elementid = FLEXI_J16GE ? 'jform_notify' : '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-label="' . $lbltxt . '" data-labelPosition="right" data-customClass="fcradiocheck"'; $lists['notify'] = ' <input type="checkbox" id="' . $elementid . '" element_group_id="' . $elementid . '" name="' . $fieldname . '" ' . $attribs . ' value="1" ' . $extra_params . ' checked="checked" />'; if (!$prettycheckable_added) { $lists['notify'] .= ' ' . $lbltxt . '</label>'; } } } // Retrieve author configuration $db->setQuery('SELECT author_basicparams FROM #__flexicontent_authors_ext WHERE user_id = ' . $user->id); if ($authorparams = $db->loadResult()) { $authorparams = FLEXI_J16GE ? new JRegistry($authorparams) : new JParameter($authorparams); } // 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) . '"; '); // 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); $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 = FLEXI_J16GE ? 'jform[featured_cid][]' : '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); } 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); } else { $cid_tree =& $categories; } // 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 = FLEXI_J16GE ? 'jform[cid][]' : '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()); } 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 = FLEXI_J16GE ? 'jform[catid]' : '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); } else { $catid_tree =& $categories; } $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); } else { if (!$isnew && $item->catid) { $lists['catid'] = $globalcats[$item->catid]->title; } } //buid types selectlist $class = 'required use_select2_lib'; $attribs = 'class="' . $class . '"'; $fieldname = FLEXI_J16GE ? 'jform[type_id]' : 'type_id'; $elementid = FLEXI_J16GE ? 'jform_type_id' : '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 $language_fieldname = FLEXI_J16GE ? 'jform[language]' : 'language'; if (FLEXI_FISH || FLEXI_J16GE) { $lists['languages'] = flexicontent_html::buildlanguageslist($language_fieldname, '', $item->language, 3, $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 = !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); } } // ****************************** // 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); 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; } }
/** * 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; } }