Beispiel #1
0
    function onDisplayCoreFieldValue(&$_field, &$_item, &$params, $_tags = null, $_categories = null, $_favourites = null, $_favoured = null, $_vote = null, $values = null, $prop = 'display')
    {
        $view = JRequest::setVar('view', JRequest::getVar('view', FLEXI_ITEMVIEW));
        static $cat_links = array();
        static $tag_links = array();
        static $cparams = null;
        if ($cparams === null) {
            $cparams = JComponentHelper::getParams('com_flexicontent');
        }
        if (!is_array($_item)) {
            $items = array(&$_item);
        } else {
            $items =& $_item;
        }
        // Prefix - Suffix - Separator parameters
        // these parameters should be common so we will retrieve them from the first item instead of inside the loop
        $item = reset($items);
        if (is_object($_field)) {
            $field = $_field;
        } else {
            $field = $item->fields[$_field];
        }
        $remove_space = $field->parameters->get('remove_space', 0);
        $_pretext = $field->parameters->get('pretext', '');
        $_posttext = $field->parameters->get('posttext', '');
        $separatorf = $field->parameters->get('separatorf', 3);
        $_opentag = $field->parameters->get('opentag', '');
        $_closetag = $field->parameters->get('closetag', '');
        $pretext_cacheable = $posttext_cacheable = $opentag_cacheable = $closetag_cacheable = false;
        switch ($separatorf) {
            case 0:
                $separatorf = ' ';
                break;
            case 1:
                $separatorf = '<br />';
                break;
            case 2:
                $separatorf = ' | ';
                break;
            case 3:
                $separatorf = ', ';
                break;
            case 4:
                $separatorf = $closetag . $opentag;
                break;
            case 5:
                $separatorf = '';
                break;
            default:
                $separatorf = '&nbsp;';
                break;
        }
        foreach ($items as $item) {
            //if (!is_object($_field)) echo $item->id." - ".$_field ."<br/>";
            if (is_object($_field)) {
                $field = $_field;
            } else {
                $field = $item->fields[$_field];
            }
            if ($field->iscore != 1) {
                continue;
            }
            $field->item_id = $item->id;
            // Replace item properties or values of other fields
            if (!$pretext_cacheable) {
                $pretext = FlexicontentFields::replaceFieldValue($field, $item, $_pretext, 'pretext', $pretext_cacheable);
                if ($pretext && !$remove_space) {
                    $pretext = $pretext . ' ';
                }
            }
            if (!$posttext_cacheable) {
                $posttext = FlexicontentFields::replaceFieldValue($field, $item, $_posttext, 'posttext', $posttext_cacheable);
                if ($posttext && !$remove_space) {
                    $posttext = ' ' . $posttext;
                }
            }
            if (!$opentag_cacheable) {
                $opentag = FlexicontentFields::replaceFieldValue($field, $item, $_opentag, 'opentag', $opentag_cacheable);
            }
            // used by some fields
            if (!$closetag_cacheable) {
                $closetag = FlexicontentFields::replaceFieldValue($field, $item, $_closetag, 'closetag', $closetag_cacheable);
            }
            // used by some fields
            $field->value = array();
            switch ($field->field_type) {
                case 'created':
                    // created
                    $field->value = array($item->created);
                    // Get date format
                    $customdate = $field->parameters->get('custom_date', 'Y-m-d');
                    $dateformat = $field->parameters->get('date_format', '');
                    $dateformat = $dateformat ? JText::_($dateformat) : ($field->parameters->get('lang_filter_format', 0) ? JText::_($customdate) : $customdate);
                    // Add prefix / suffix
                    $field->{$prop} = $pretext . JHTML::_('date', $item->created, $dateformat) . $posttext;
                    // Add microdata property
                    $itemprop = $field->parameters->get('microdata_itemprop', 'dateCreated');
                    if ($itemprop) {
                        $field->{$prop} = '<div style="display:inline" itemprop="' . $itemprop . '" >' . $field->{$prop} . '</div>';
                    }
                    break;
                case 'createdby':
                    // created by
                    $field->value[] = $item->created_by;
                    $field->{$prop} = $pretext . ($field->parameters->get('name_username', 1) == 2 ? $item->cuname : $item->creator) . $posttext;
                    break;
                case 'modified':
                    // modified
                    $field->value = array($item->modified);
                    // Get date format
                    $customdate = $field->parameters->get('custom_date', 'Y-m-d');
                    $dateformat = $field->parameters->get('date_format', '');
                    $dateformat = $dateformat ? JText::_($dateformat) : ($field->parameters->get('lang_filter_format', 0) ? JText::_($customdate) : $customdate);
                    // Add prefix / suffix
                    $field->{$prop} = $pretext . JHTML::_('date', $item->modified, $dateformat) . $posttext;
                    // Add microdata property
                    $itemprop = $field->parameters->get('microdata_itemprop', 'dateModified');
                    if ($itemprop) {
                        $field->{$prop} = '<div style="display:inline" itemprop="' . $itemprop . '" >' . $field->{$prop} . '</div>';
                    }
                    break;
                case 'modifiedby':
                    // modified by
                    $field->value[] = $item->modified_by;
                    $field->{$prop} = $pretext . ($field->parameters->get('name_username', 1) == 2 ? $item->muname : $item->modifier) . $posttext;
                    break;
                case 'title':
                    // title
                    $field->value[] = $item->title;
                    $field->{$prop} = $pretext . $item->title . $posttext;
                    // Get ogp configuration
                    $useogp = $field->parameters->get('useogp', 1);
                    $ogpinview = $field->parameters->get('ogpinview', array());
                    $ogpinview = FLEXIUtilities::paramToArray($ogpinview);
                    $ogpmaxlen = $field->parameters->get('ogpmaxlen', 300);
                    if ($useogp && $field->{$prop}) {
                        if (in_array($view, $ogpinview)) {
                            $content_val = flexicontent_html::striptagsandcut($field->{$prop}, $ogpmaxlen);
                            JFactory::getDocument()->addCustomTag('<meta property="og:title" content="' . $content_val . '" />');
                        }
                    }
                    // Add microdata property (currently no parameter in XML for this field)
                    $itemprop = $field->parameters->get('microdata_itemprop', 'name');
                    if ($itemprop) {
                        $field->{$prop} = '<div style="display:inline" itemprop="' . $itemprop . '" >' . $field->{$prop} . '</div>';
                    }
                    break;
                case 'hits':
                    // hits
                    $field->value[] = $item->hits;
                    $field->{$prop} = $pretext . $item->hits . $posttext;
                    break;
                case 'type':
                    // document type
                    $field->value[] = $item->type_id;
                    $field->{$prop} = $pretext . JText::_($item->typename) . $posttext;
                    break;
                case 'version':
                    // version
                    $field->value[] = $item->version;
                    $field->{$prop} = $pretext . $item->version . $posttext;
                    break;
                case 'state':
                    // state
                    $field->value[] = $item->state;
                    $field->{$prop} = $pretext . flexicontent_html::stateicon($item->state, $field->parameters) . $posttext;
                    break;
                case 'voting':
                    // voting button
                    if ($_vote === false) {
                        $vote =& $item->vote;
                    } else {
                        $vote =& $_vote;
                    }
                    $field->value[] = 'button';
                    // dummy value to force display
                    $field->{$prop} = $pretext . flexicontent_html::ItemVote($field, 'all', $vote) . $posttext;
                    break;
                case 'favourites':
                    // favourites button
                    if ($_favourites === false) {
                        $favourites =& $item->favs;
                    } else {
                        $favourites =& $_favourites;
                    }
                    if ($_favoured === false) {
                        $favoured =& $item->fav;
                    } else {
                        $favoured =& $_favoured;
                    }
                    $field->value[] = 'button';
                    // dummy value to force display
                    $favs = flexicontent_html::favoured_userlist($field, $item, $favourites);
                    $field->{$prop} = $pretext . '
					<div class="fav-block">
						' . flexicontent_html::favicon($field, $favoured, $item) . '
						<div id="fcfav-reponse_item_' . $item->id . '" class="fcfav-reponse-tip">
							<div class="fc-mssg-inline fc-info fc-iblock fc-nobgimage ' . ($favoured ? 'fcfavs-is-subscriber' : 'fcfavs-isnot-subscriber') . '">
								' . JText::_($favoured ? 'FLEXI_FAVS_YOU_HAVE_SUBSCRIBED' : 'FLEXI_FAVS_CLICK_TO_SUBSCRIBE') . '
							</div>
							' . $favs . '
						</div>
					</div>
						' . $posttext;
                    break;
                case 'categories':
                    // assigned categories
                    $field->{$prop} = '';
                    if ($_categories === false) {
                        $categories =& $item->cats;
                    } else {
                        $categories =& $_categories;
                    }
                    if ($categories) {
                        // Get categories that should be excluded from linking
                        global $globalnoroute;
                        if (!is_array($globalnoroute)) {
                            $globalnoroute = array();
                        }
                        // Create list of category links, excluding the "noroute" categories
                        $field->{$prop} = array();
                        foreach ($categories as $category) {
                            $cat_id = $category->id;
                            if (in_array($cat_id, @$globalnoroute)) {
                                continue;
                            }
                            if (!isset($cat_links[$cat_id])) {
                                $cat_links[$cat_id] = JRoute::_(FlexicontentHelperRoute::getCategoryRoute($category->slug));
                            }
                            $cat_link =& $cat_links[$cat_id];
                            $display = '<a class="fc_categories fc_category_' . $cat_id . ' link_' . $field->name . '" href="' . $cat_link . '">' . $category->title . '</a>';
                            $field->{$prop}[] = $pretext . $display . $posttext;
                            $field->value[] = $category->title;
                        }
                        $field->{$prop} = implode($separatorf, $field->{$prop});
                        $field->{$prop} = $opentag . $field->{$prop} . $closetag;
                    }
                    break;
                case 'tags':
                    // assigned tags
                    $use_catlinks = $cparams->get('tags_using_catview', 0);
                    $field->{$prop} = '';
                    if ($_tags === false) {
                        $tags =& $item->tags;
                    } else {
                        $tags =& $_tags;
                    }
                    if ($tags) {
                        // Create list of tag links
                        $field->{$prop} = array();
                        foreach ($tags as $tag) {
                            $tag_id = $tag->id;
                            if (!isset($tag_links[$tag_id])) {
                                $tag_links[$tag_id] = $use_catlinks ? JRoute::_(FlexicontentHelperRoute::getCategoryRoute(0, 0, array('layout' => 'tags', 'tagid' => $tag->slug))) : JRoute::_(FlexicontentHelperRoute::getTagRoute($tag->slug));
                            }
                            $tag_link =& $tag_links[$tag_id];
                            $display = '<a class="fc_tags fc_tag_' . $tag->id . ' link_' . $field->name . '" href="' . $tag_link . '">' . $tag->name . '</a>';
                            $field->{$prop}[] = $pretext . $display . $posttext;
                            $field->value[] = $tag->name;
                        }
                        $field->{$prop} = implode($separatorf, $field->{$prop});
                        $field->{$prop} = $opentag . $field->{$prop} . $closetag;
                    }
                    break;
                case 'maintext':
                    // main text
                    // Special display variables
                    if ($prop != 'display') {
                        switch ($prop) {
                            case 'display_if':
                                $field->{$prop} = $item->introtext . chr(13) . chr(13) . $item->fulltext;
                                break;
                            case 'display_i':
                                $field->{$prop} = $item->introtext;
                                break;
                            case 'display_f':
                                $field->{$prop} = $item->fulltext;
                                break;
                        }
                    } else {
                        if (!$item->fulltext) {
                            $field->{$prop} = $item->introtext;
                        } else {
                            if ($view != FLEXI_ITEMVIEW) {
                                if ($item->parameters->get('force_full', 0)) {
                                    $field->{$prop} = $item->introtext . chr(13) . chr(13) . $item->fulltext;
                                } else {
                                    $field->{$prop} = $item->introtext;
                                }
                            } else {
                                if ($item->parameters->get('show_intro', 1)) {
                                    $field->{$prop} = $item->introtext . chr(13) . chr(13) . $item->fulltext;
                                } else {
                                    $field->{$prop} = $item->fulltext;
                                }
                            }
                        }
                    }
                    // Get ogp configuration
                    $useogp = $field->parameters->get('useogp', 1);
                    $ogpinview = $field->parameters->get('ogpinview', array());
                    $ogpinview = FLEXIUtilities::paramToArray($ogpinview);
                    $ogpmaxlen = $field->parameters->get('ogpmaxlen', 300);
                    if ($useogp && $field->{$prop}) {
                        if (in_array($view, $ogpinview)) {
                            if ($item->metadesc) {
                                JFactory::getDocument()->addCustomTag('<meta property="og:description" content="' . $item->metadesc . '" />');
                            } else {
                                $content_val = flexicontent_html::striptagsandcut($field->{$prop}, $ogpmaxlen);
                                JFactory::getDocument()->addCustomTag('<meta property="og:description" content="' . $content_val . '" />');
                            }
                        }
                    }
                    break;
            }
        }
    }
Beispiel #2
0
    function onDisplayCoreFieldValue(&$_field, &$_item, &$params, $_tags = null, $_categories = null, $_favourites = null, $_favoured = null, $_vote = null, $values = null, $prop = 'display')
    {
        // this function is a mess and need complete refactoring
        // execute the code only if the field type match the plugin type
        $view = JRequest::setVar('view', JRequest::getVar('view', FLEXI_ITEMVIEW));
        static $cat_links = array();
        static $tag_links = array();
        if (!is_array($_item)) {
            $items = array(&$_item);
        } else {
            $items =& $_item;
        }
        // Prefix - Suffix - Separator parameters
        // these parameters should be common so we will retrieve them from the first item instead of inside the loop
        $item = reset($items);
        if (is_object($_field)) {
            $field = $_field;
        } else {
            $field = $item->fields[$_field];
        }
        $remove_space = $field->parameters->get('remove_space', 0);
        $_pretext = $field->parameters->get('pretext', '');
        $_posttext = $field->parameters->get('posttext', '');
        $separatorf = $field->parameters->get('separatorf', 3);
        $_opentag = $field->parameters->get('opentag', '');
        $_closetag = $field->parameters->get('closetag', '');
        $pretext_cacheable = $posttext_cacheable = $opentag_cacheable = $closetag_cacheable = false;
        foreach ($items as $item) {
            //if (!is_object($_field)) echo $item->id." - ".$_field ."<br/>";
            if (is_object($_field)) {
                $field = $_field;
            } else {
                $field = $item->fields[$_field];
            }
            if ($field->iscore != 1) {
                continue;
            }
            $field->item_id = $item->id;
            // Replace item properties or values of other fields
            if (!$pretext_cacheable) {
                $pretext = FlexicontentFields::replaceFieldValue($field, $item, $_pretext, 'pretext', $pretext_cacheable);
                if ($pretext && !$remove_space) {
                    $pretext = $pretext . ' ';
                }
            }
            if (!$posttext_cacheable) {
                $posttext = FlexicontentFields::replaceFieldValue($field, $item, $_posttext, 'posttext', $posttext_cacheable);
                if ($posttext && !$remove_space) {
                    $posttext = ' ' . $posttext;
                }
            }
            if (!$opentag_cacheable) {
                $opentag = FlexicontentFields::replaceFieldValue($field, $item, $_opentag, 'opentag', $opentag_cacheable);
            }
            // used by some fields
            if (!$closetag_cacheable) {
                $closetag = FlexicontentFields::replaceFieldValue($field, $item, $_closetag, 'closetag', $closetag_cacheable);
            }
            // used by some fields
            switch ($separatorf) {
                case 0:
                    $separatorf = ' ';
                    break;
                case 1:
                    $separatorf = '<br />';
                    break;
                case 2:
                    $separatorf = ' | ';
                    break;
                case 3:
                    $separatorf = ', ';
                    break;
                case 4:
                    $separatorf = $closetag . $opentag;
                    break;
                case 5:
                    $separatorf = '';
                    break;
                default:
                    $separatorf = '&nbsp;';
                    break;
            }
            $field->value = array();
            switch ($field->field_type) {
                case 'created':
                    // created
                    $field->value[] = $item->created;
                    $dateformat = $field->parameters->get('date_format', '');
                    $customdate = $field->parameters->get('custom_date', '');
                    $dateformat = $dateformat ? $dateformat : $customdate;
                    $field->display = $pretext . JHTML::_('date', $item->created, JText::_($dateformat)) . $posttext;
                    break;
                case 'createdby':
                    // created by
                    $field->value[] = $item->created_by;
                    $field->display = $pretext . ($field->parameters->get('name_username', 1) == 2 ? $item->cuname : $item->creator) . $posttext;
                    break;
                case 'modified':
                    // modified
                    $field->value[] = $item->modified;
                    $dateformat = $field->parameters->get('date_format', '');
                    $customdate = $field->parameters->get('custom_date', '');
                    $dateformat = $dateformat ? $dateformat : $customdate;
                    $field->display = $pretext . JHTML::_('date', $item->modified, JText::_($dateformat)) . $posttext;
                    break;
                case 'modifiedby':
                    // modified by
                    $field->value[] = $item->modified_by;
                    $field->display = $pretext . ($field->parameters->get('name_username', 1) == 2 ? $item->muname : $item->modifier) . $posttext;
                    break;
                case 'title':
                    // title
                    $field->value[] = $item->title;
                    $field->display = $pretext . $item->title . $posttext;
                    // Get ogp configuration
                    $useogp = $field->parameters->get('useogp', 1);
                    $ogpinview = $field->parameters->get('ogpinview', array());
                    $ogpinview = FLEXIUtilities::paramToArray($ogpinview);
                    $ogpmaxlen = $field->parameters->get('ogpmaxlen', 300);
                    if ($useogp && $field->{$prop}) {
                        if (in_array($view, $ogpinview)) {
                            $content_val = flexicontent_html::striptagsandcut($field->display, $ogpmaxlen);
                            JFactory::getDocument()->addCustomTag('<meta property="og:title" content="' . $content_val . '" />');
                        }
                    }
                    break;
                case 'hits':
                    // hits
                    $field->value[] = $item->hits;
                    $field->display = $pretext . $item->hits . $posttext;
                    break;
                case 'type':
                    // document type
                    $field->value[] = $item->type_id;
                    $field->display = $pretext . JText::_($item->typename) . $posttext;
                    break;
                case 'version':
                    // version
                    $field->value[] = $item->version;
                    $field->display = $pretext . $item->version . $posttext;
                    break;
                case 'state':
                    // state
                    $field->value[] = $item->state;
                    $field->display = $pretext . flexicontent_html::stateicon($item->state, $field->parameters) . $posttext;
                    break;
                case 'voting':
                    // voting button
                    if ($_vote === false) {
                        $vote =& $item->vote;
                    } else {
                        $vote =& $_vote;
                    }
                    $field->value[] = 'button';
                    // dummy value to force display
                    $field->display = $pretext . flexicontent_html::ItemVote($field, 'all', $vote) . $posttext;
                    break;
                case 'favourites':
                    // favourites button
                    if ($_favourites === false) {
                        $favourites =& $item->favs;
                    } else {
                        $favourites =& $_favourites;
                    }
                    if ($_favoured === false) {
                        $favoured =& $item->fav;
                    } else {
                        $favoured =& $_favoured;
                    }
                    $field->value[] = 'button';
                    // dummy value to force display
                    $favs = flexicontent_html::favoured_userlist($field, $item, $favourites);
                    $field->display = $pretext . '
					<span class="fav-block">
						' . flexicontent_html::favicon($field, $favoured, $item) . '
						<span id="fcfav-reponse_' . $field->item_id . '" class="fcfav-reponse">
							<small>' . $favs . '</small>
						</span>
					</span>
						' . $posttext;
                    break;
                case 'categories':
                    // assigned categories
                    $field->display = '';
                    if ($_categories === false) {
                        $categories =& $item->cats;
                    } else {
                        $categories =& $_categories;
                    }
                    if ($categories) {
                        // Get categories that should be excluded from linking
                        global $globalnoroute;
                        if (!is_array($globalnoroute)) {
                            $globalnoroute = array();
                        }
                        // Create list of category links, excluding the "noroute" categories
                        $field->display = array();
                        foreach ($categories as $category) {
                            $cat_id = $category->id;
                            if (in_array($cat_id, @$globalnoroute)) {
                                continue;
                            }
                            if (!isset($cat_links[$cat_id])) {
                                $cat_links[$cat_id] = JRoute::_(FlexicontentHelperRoute::getCategoryRoute($category->slug));
                            }
                            $cat_link = $cat_links[$cat_id];
                            $display = '<a class="fc_categories fc_category_' . $cat_id . ' link_' . $field->name . '" href="' . $cat_link . '">' . $category->title . '</a>';
                            $field->display[] = $pretext . $display . $posttext;
                            $field->value[] = $category->title;
                        }
                        $field->display = implode($separatorf, $field->display);
                        $field->display = $opentag . $field->display . $closetag;
                    }
                    break;
                case 'tags':
                    // assigned tags
                    $field->display = '';
                    if ($_tags === false) {
                        $tags =& $item->tags;
                    } else {
                        $tags =& $_tags;
                    }
                    if ($tags) {
                        // Create list of tag links
                        $field->display = array();
                        foreach ($tags as $tag) {
                            $tag_id = $tag->id;
                            if (!isset($tag_links[$tag_id])) {
                                $tag_links[$tag_id] = JRoute::_(FlexicontentHelperRoute::getTagRoute($tag->slug));
                            }
                            $tag_link = $tag_links[$tag_id];
                            $display = '<a class="fc_tags fc_tag_' . $tag->id . ' link_' . $field->name . '" href="' . $tag_link . '">' . $tag->name . '</a>';
                            $field->display[] = $pretext . $display . $posttext;
                            $field->value[] = $tag->name;
                        }
                        $field->display = implode($separatorf, $field->display);
                        $field->display = $opentag . $field->display . $closetag;
                    }
                    break;
                case 'maintext':
                    // main text
                    // Special display variables
                    if ($prop != 'display') {
                        switch ($prop) {
                            case 'display_if':
                                $field->{$prop} = $item->introtext . chr(13) . chr(13) . $item->fulltext;
                                break;
                            case 'display_i':
                                $field->{$prop} = $item->introtext;
                                break;
                            case 'display_f':
                                $field->{$prop} = $item->fulltext;
                                break;
                        }
                    } else {
                        if (!$item->fulltext) {
                            $field->display = $item->introtext;
                        } else {
                            if ($view != FLEXI_ITEMVIEW) {
                                if ($item->parameters->get('force_full', 0)) {
                                    $field->display = $item->introtext . chr(13) . chr(13) . $item->fulltext;
                                } else {
                                    $field->display = $item->introtext;
                                }
                            } else {
                                if ($item->parameters->get('show_intro', 1)) {
                                    $field->display = $item->introtext . chr(13) . chr(13) . $item->fulltext;
                                } else {
                                    $field->display = $item->fulltext;
                                }
                            }
                        }
                    }
                    // Get ogp configuration
                    $useogp = $field->parameters->get('useogp', 1);
                    $ogpinview = $field->parameters->get('ogpinview', array());
                    $ogpinview = FLEXIUtilities::paramToArray($ogpinview);
                    $ogpmaxlen = $field->parameters->get('ogpmaxlen', 300);
                    if ($useogp && $field->{$prop}) {
                        if (in_array($view, $ogpinview)) {
                            if ($item->metadesc) {
                                JFactory::getDocument()->addCustomTag('<meta property="og:description" content="' . $item->metadesc . '" />');
                            } else {
                                $content_val = flexicontent_html::striptagsandcut($field->display, $ogpmaxlen);
                                JFactory::getDocument()->addCustomTag('<meta property="og:description" content="' . $content_val . '" />');
                            }
                        }
                    }
                    break;
            }
        }
    }