Page 1 of 1

Modifying freetag output

Posted: Sun Feb 08, 2015 11:23 pm
by Don Chambers
The freetag plugin has a tpl for displaying in the sidebar. Is there something like that available when in entry view?

I want to eliminate the text "Defined tags for this entry"... I also want to use a different html element to display the tag names, which are emitted by the plugin simply as a series of links.

Re: Modifying freetag output

Posted: Tue Feb 10, 2015 9:17 pm
by Don Chambers
Anyone?

Re: Modifying freetag output

Posted: Tue Feb 10, 2015 9:46 pm
by onli
I think yes, but probably not in the way a theme author would like it.

If I see and remember that correctly: When the extended_smarty option is enabled, the plugin does not emit any html for entries. It instead fills smarty variables (freetag.tags.tags) and lets the template of the theme handle the tag display. The relevant code is here: https://github.com/s9y/additional_plugi ... .php#L1402

So you should be able to design this as you want in entries.inc.tpl, but users would only see it if they enable that option.

Re: Modifying freetag output

Posted: Tue Feb 10, 2015 9:59 pm
by Don Chambers
Sweet. Not exactly what I was looking for, but I think I can make something work with that. Thanks!

Re: Modifying freetag output

Posted: Wed Feb 11, 2015 9:54 pm
by Don Chambers
I finally had a chance to test this.
onli wrote:When the extended_smarty option is enabled, the plugin does not emit any html for entries.
That's not completely true.... the value for each $tag is a full link <a href="tag_url">TAGNAME</a> which is html. True, there are no containers, nor anything else.

Should anyone modify this plugin in the future, I would love the ability to retrieve the tagname, and tag url individually, much like what works here with categories:

Code: Select all

{foreach from=$entry.categories item="entry_category" name="categories"}
    <a href="{$entry_category.category_link}">{$entry_category.category_name|escape}</a>{if not $smarty.foreach.categories.last}, {/if}
{/foreach}

Re: Modifying freetag output

Posted: Wed Aug 12, 2015 5:40 pm
by peggylon
I just happened to do modify related links today the way you asked for. If you use extended smarty you can change the output as follows:

In serendipity_event_freetag.php in function getRelatedEntriesHtml():
vorher:

Code: Select all

$return['entries'][] = '<a href="' . serendipity_archiveURL($entryid, $title) . '" title="' . htmlspecialchars($title) . '">' . htmlspecialchars($title) . '</a>';
nachher:

Code: Select all

$return['entries'][]['url'] = serendipity_archiveURL($entryid, $title);
$return['entries'][]['title']	= htmlspecialchars($title);
In entries.tpl:

Code: Select all

{if isset($entry.freetag.extended) && $entry.freetag.extended == 1}
	{if $entry.freetag.tags.tags}
		<div class="serendipity_freeTag">{$entry.freetag.tags.description}
			{foreach from=$entry.freetag.tags.tags item="tag"}
				{$tag}
			{/foreach}
		</div>
		{if $is_single_entry or $is_preview}
			{$entry.freetag.related.description}
			<div class="serendipity_freeTag_related"> <!-- (oder ul) -->
			{foreach from=$entry.freetag.related.entries item="link"}
				<div class="grid4"> <!-- (oder li) -->
					<a href="{$link.url}">{$link.title}</a>
				</div>
			{/foreach}
			</div>
		{/if}
	{/if}
{else}
	{$entry.freetag}
{/if}
Hope, that helps.

Re: Modifying freetag output

Posted: Wed Aug 12, 2015 5:57 pm
by peggylon
As I stated in the previous post I somewhat changed the freetag plugin's output in my system.

What I couldn't figure out though, was how to get first image's url from related entries' bodies as third parameter.

So far I'm able to retrieve the desired images' urls in function getRelatedEntries() by adding

Code: Select all

SUBSTRING_INDEX( SUBSTRING( body, LOCATE( '/uploads', e2.body )),'.jpg', 1 ) AS imgurl,

to the query. But I don't know how to properly transfer them into getRelatedEntriesHtml().

What I'd like to do there:

Code: Select all

$return['entries'][]['imgurl']
I'd be glad, if someone could give me a hint. Thanks guys.

Re: Modifying freetag output

Posted: Tue Aug 18, 2015 4:26 pm
by peggylon
I finally figured out how to display preview pictures with related entries links. If there is a general interest in that I could perhaps update the plugin, if I get help along the way. Am not familiar with the process.

In my version of the plugin I edited two lines of the function getRelatedEntries as follows:

Code: Select all

$q = "SELECT DISTINCT 
     e1.entryid,
     e2.title,
     SUBSTRING_INDEX( SUBSTRING( body, LOCATE( '/uploads', e2.body )),'.jpg', 1 ) AS img,  
     e2.timestamp
     FROM {$serendipity['dbPrefix']}entrytags AS e1
     LEFT JOIN {$serendipity['dbPrefix']}entries   AS e2
             ON e1.entryid = e2.id
     WHERE e1.tag IN ('" . implode("', '", $tags) . "')
             AND e1.entryid != " . (int)$postID . "
             AND e2.isdraft = 'false'
                     " . (!serendipity_db_bool($serendipity['showFutureEntries']) ? " AND e2.timestamp <= " . time() : '') . "
     ORDER BY  e2.timestamp DESC
     LIMIT " . $this->get_config('show_related_count', 10);
$result = serendipity_db_query($q, false,'assoc');
and in function getRelatedEntries:

Code: Select all

$i = 0;
foreach($entries AS $entry) {
        $return['entries'][$i]['url'] = serendipity_archiveURL($entry['entryid'], $entry['title']);
	$return['entries'][$i]['title']	= htmlspecialchars($entry['title']);
	$return['entries'][$i]['img'] = $entry['img'];
	$i++;
}
Finally in template entries.tpl:

Code: Select all

{if isset($entry.freetag.extended) && $entry.freetag.extended == 1}
	{if $entry.freetag.tags.tags}
		....
		{if $is_single_entry or $is_preview}
			{$entry.freetag.related.description}
			 <div class="serendipity_freeTag_related">
			 {foreach from=$entry.freetag.related.entries item="link"}
				<div class="grid4">                      //floating containers
					<a href="{$link.url}"><img src="{$link.img}.serendipityThumb.jpg"></a>
					<a href="{$link.url}">{$link.title}</a>
				</div>
			{/foreach}
			</div>
		{/if}
	{/if}
{else}
	{$entry.freetag}
{/if}

Re: Modifying freetag output

Posted: Tue Aug 18, 2015 6:27 pm
by Timbalu
Hey, great you solved that for yourself!
About using this for an official update, we should play with and find out, what it does and what it does not..., since it is a special usecase, or how it could be enhanced. So we will come back to this ...

But I am pretty sure you used an outdated plugin version, below 3.58.1.