Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#796 2017-07-20 10:30:19

spiridon
Member
From: Mariupol, Ukraine
Registered: 2011-01-30
Posts: 58
Website GitHub

Re: tru_tags: A tagging plugin for textpattern

truist wrote #306330:

tru_tags_cloud_query is called from a bunch of places; it’s how tru_tags figures out what tags exist.

I found that I had a call stack like this:

tru_tags_cloud() {
    tru_tags_list() {
        tru_tags_cloud_query()
        tru_tags_render_cloud() {
            tru_tags_tag_parameter() {
                tru_tags_cloud_query()
            }
        }
    }
}

But still, caching the query result does seem like a good idea, given how that function is used, and that it makes a heavy database call. But I am generally super-paranoid about any sort of caching; it usually leads to subtle bugs. (Like do we know if the $rs is just a list, or does it contain other state that might not be safe to cache? I don’t remember my php and textpattern well enough to be sure.)

This is not dangerous. The function safe_row always returns array (empty array in case of error).

Looking at your before and after, it looks like you only saved about 10ms (~13%) on the runtime – is that worth it? But of course, you saved about 25% on the query time, and if that query is used many times in a page, it might have a much bigger effect. Do you have any experimental results that would show that?

You can ignore it, but I can not.
I do not have any experimental results, except those that published earlier. I just found the inefficiency in the code.

If you’d make that change and submit a PR, I’d happily merge it and publish a new version.

Done.

Offline

#797 2017-07-20 12:11:31

makss
Plugin Author
From: Ukraine
Registered: 2008-10-21
Posts: 355

Re: tru_tags: A tagging plugin for textpattern

spiridon wrote #306323:

But for myself I wrote a hack that fixes duplication of a heavy query.

Note that in Txp 4.6+ you can significantly speed up queries with txp/php function now() This approach makes it possible to use mysql query_cache and in this case there is no need for additional caching.

Example usage (copy-paste from the plugin aks_article)

	// Using SQL caching capabilities. Txp 4.6+
	if (function_exists('now')) {
		$where_posted = now('posted');
		$where_expired = " AND (".now('expires')." <= Expires OR Expires IS NULL)";
	} else {
		$where_posted = "now()";
		$where_expired = " AND (now() <= Expires OR Expires = ".NULLDATETIME.")";
	}

	switch ($time) {
		case 'any':	$time = ""; break;
		case 'all':	$time = ""; $expired = 1; break;
		case 'future':	$time = " AND Posted > ".$where_posted; break;
		default:	$time = " AND Posted <= ".$where_posted;
	}
	if (!$expired) {
		$time .= $where_expired;
	}

Can adapt and add to the functions tru_tags_cloud_query and tru_tags_redo_article_search

Last edited by makss (2017-07-20 12:26:06)


aks_cron : Cron inside Textpattern | aks_article : extended article_custom tag
aks_cache : cache for TxP | aks_dragdrop : Drag&Drop categories (article, link, image, file)

Offline

#798 2017-07-20 13:23:19

makss
Plugin Author
From: Ukraine
Registered: 2008-10-21
Posts: 355

Re: tru_tags: A tagging plugin for textpattern

Please check my patch
Unfortunately, I can not check it on a real site.


aks_cron : Cron inside Textpattern | aks_article : extended article_custom tag
aks_cache : cache for TxP | aks_dragdrop : Drag&Drop categories (article, link, image, file)

Offline

#799 2017-07-20 14:48:28

makss
Plugin Author
From: Ukraine
Registered: 2008-10-21
Posts: 355

Re: tru_tags: A tagging plugin for textpattern

michaelkpate wrote #305227:

I am trying to get tru_tags 3.9 working on a site running 4.7 dev. I am constantly getting this error in the backend.

A problem occurred while loading the plugin: tru_tags -> User_Error: Table '[databasename].tru_tags_prefs' doesn't exist on line 409...

Perhaps fixed , please check.


aks_cron : Cron inside Textpattern | aks_article : extended article_custom tag
aks_cache : cache for TxP | aks_dragdrop : Drag&Drop categories (article, link, image, file)

Offline

#800 2017-07-20 17:21:18

spiridon
Member
From: Mariupol, Ukraine
Registered: 2011-01-30
Posts: 58
Website GitHub

Re: tru_tags: A tagging plugin for textpattern

makss wrote #306361:

Note that in Txp 4.6+ you can significantly speed up queries with txp/php function now() This approach makes it possible to use mysql query_cache and in this case there is no need for additional caching.

This will lead to malfunction of the plugin. And besides it fills caches with useless queries.

Offline

#801 2017-07-23 09:39:45

whocarez
Plugin Author
From: Germany/Ukraine
Registered: 2007-10-08
Posts: 305
Website GitHub Twitter

Re: tru_tags: A tagging plugin for textpattern

With textpattern 4.6.2 and tru_tags 3.9 the for me very important auto complete function stopped working. Stylesheet and script are now placed right before the <!DOCTYPE html>

The javascript file doesn’t seems to be still necessary, because the autocomplete function is now part of jquery-ui which is also loaded by the admin-side theme.

How to get the code back into the html body or the head? There is this “head_end” callback, but I don’t know how to change the code for using it right, due to my limited programming skills.

Offline

#802 2017-07-23 21:30:43

whocarez
Plugin Author
From: Germany/Ukraine
Registered: 2007-10-08
Posts: 305
Website GitHub Twitter

Re: tru_tags: A tagging plugin for textpattern

A quick and dirty solution, which is working for me and with the help of this auto complete example from here:

function tru_tags_admin_write_tab_handler($event, $step, $data) {
	global $tru_tags_prefs;
	$atts = tru_tags_get_standard_cloud_atts(array(), true, true, true);
	$cloud = array_unique(tru_tags_cloud_query($atts));
	natcasesort($cloud);

	$id = (empty($GLOBALS['ID']) ? gps('ID') : $GLOBALS['ID']);
	$article_tags = (empty($id) ? array() : tru_tags_get_tags_for_article($id));

	$links = array();
        global $raw_cloud;
	$raw_cloud = '';
	foreach ($cloud as $tag) {
		$style = (in_array($tag, $article_tags) ? ' class="tag_chosen"' : '');
		$links[] = '<a href="#advanced"'.$style.' onclick="toggleClass(this, toggleTag(\\\''.addslashes(addslashes(htmlspecialchars($tag))).'\\\')); return false;">' . addslashes(htmlspecialchars($tag)) . '<\/a>';
		$raw_cloud .= '"' . addSlashes($tag) . '",';
	}
	$raw_cloud = substr($raw_cloud, 0, strlen($raw_cloud) - 1);
	$to_insert = join(', ', $links);

	if ($tru_tags_prefs[TAGS_IN_WRITE_TAB]->value) {
		$js = <<<EOF
			var keywordsField = document.getElementById('keywords');
			keywordsField.parentNode.appendChild(document.createElement('br'));
			var cloud = document.createElement('span');
			keywordsField.parentNode.appendChild(cloud);
			cloud.setAttribute('class', 'tru_tags_admin_tags');
			cloud.innerHTML = '{$to_insert}';

			var styleElement = document.createElement('style');
			styleElement.setAttribute("type", "text/css");
			var styleText = 'a.tag_chosen{background-color: #FEB; color: black;}';
			if (styleElement.styleSheet) { //IE
				styleElement.styleSheet.cssText = styleText;
			} else {
				var textNode = document.createTextNode(styleText);
				styleElement.appendChild(textNode);
			}
			var headElement = document.getElementsByTagName('head')[0];
			headElement.appendChild(styleElement);

			function toggleTag(tagName) {
				var regexTag = tagName.replace(/([\\\\\^\\$*+[\\]?{}.=!:(|)])/g,"\\\\$1");
				var tagRegex = new RegExp("((^|,)\\\s*)" + regexTag + "\\\s*(,\\\s*|$)");
				var textarea = document.getElementById('keywords');
				var curval = textarea.value.replace(/,?\s+$/, '');
				if ('' == curval) {
					textarea.value = tagName;
				} else if (curval.match(tagRegex)) {
					textarea.value = curval.replace(tagRegex, '$1').replace(/,?\s+$/, '');
					return '';
				} else if (',' == curval.charAt(curval.length - 1)) {
					textarea.value += ' ' + tagName;
				} else {
					textarea.value += ', ' + tagName;
				}
				return 'tag_chosen';
			}

			function toggleClass(element, className) {
				element.setAttribute('class', className);
				element.setAttribute('className', className); /* for IE */
			}
EOF;
		return $data . script_js($js);
	}

	if ($tru_tags_prefs[AUTOCOMPLETE_IN_WRITE_TAB]->value) {

		register_callback('tru_tags_admin_write_tab_bodyend', 'admin_side', 'body_end');

                function tru_tags_admin_write_tab_bodyend ($event, $step) {
                          global $raw_cloud;

                          $output='<link rel="stylesheet" type="text/css" href="../js/jquery.autocomplete.css" media="projection, screen" />
         			<script language="JavaScript" type="text/javascript"><!--
          				$(document).ready(function(){ 
          				    var availableTags = ['.$raw_cloud.'];
          				    function split( val ) { return val.split( /,\s*/ ); }
          				    function extractLast( term ) { return split( term ).pop(); }
          				    $("#keywords").autocomplete({ minLength: 0, 
          				                                  source: function( request, response ) {
          				                                            // delegate back to autocomplete, but extract the last term
          				                                            response( $.ui.autocomplete.filter(
          				                                              availableTags, extractLast( request.term ) ) );
          				                                          },
          				                                          focus: function() {
          				                                            // prevent value inserted on focus
          				                                            return false;
          				                                          },
          				                                          select: function( event, ui ) {
          				                                            var terms = split( this.value );
          				                                            // remove the current input
          				                                            terms.pop();
          				                                            // add the selected item
          				                                            terms.push( ui.item.value );
          				                                            // add placeholder to get the comma-and-space at the end
          				                                            terms.push( "" );
          				                                            this.value = terms.join( ", " );
          				                                            return false;
          				                                  }});
         				});
            			//--></script>';
                           echo n.$output.n;
                	}

        }

}

Last edited by whocarez (2017-07-23 21:44:29)

Offline

#803 2018-05-01 19:51:51

moon blake
Member
From: near Hannover, Germany
Registered: 2009-07-16
Posts: 76

Re: tru_tags: A tagging plugin for textpattern

michaelkpate wrote #305227:

As someone who has been using tru_tags on their personal site for nearly a decade, good to have you back.

I am trying to get tru_tags 3.9 working on a site running 4.7 dev. I am constantly getting this error in the backend.

A problem occurred while loading the plugin: tru_tags -> User_Error: Table '[databasename].tru_tags_prefs' doesn't exist on line 409...

While michaelkpate reports an issue with true_tags under 4.7 I get the said error under 4.6.2
Any idea how to solve this?
Looking it up in phpMyAdmin I am also wondering if it is correct that there seems to be no table added to the database by the true_tags plugin.
Thanks for any hint.

Offline

#804 2018-05-01 20:11:48

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,316

Re: tru_tags: A tagging plugin for textpattern

Have you seen makks’ reply?

makss wrote #306363:

Perhaps fixed , please check.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#805 2018-12-02 14:44:16

BryanA.
Member
From: Maryland, USA
Registered: 2007-08-12
Posts: 104

Re: tru_tags: A tagging plugin for textpattern

Is it possible to create different clouds or sets of tags for different categories?


Voice Actor – starting up a site for that good book stuff.

Offline

#806 2020-03-04 10:44:49

Vienuolis
Member
From: Vilnius, Lithuania
Registered: 2009-06-14
Posts: 327
Website GitHub GitLab Mastodon Twitter

Re: tru_tags: A tagging plugin for textpattern

Every tag leads to the 404 error page after upgrading to Textpattern v4.8.0 :-(

Tag links and the tag cloud remain correct. The latest tru_tags version 3.7.

Offline

#807 2020-03-04 11:10:05

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,366
Website GitHub Mastodon Twitter

Re: tru_tags: A tagging plugin for textpattern

Vienuolis wrote #322052:

Every tag leads to the 404 error page after upgrading to Textpattern v4.8.0 :-(

Tag links and the tag cloud remain correct. The latest tru_tags version 3.7.

I do not know a fix for it, but this might be because the plugin is not taking into account the new url schemas.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#808 2020-03-04 11:13:15

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,419
Website GitHub

Re: tru_tags: A tagging plugin for textpattern

Nope, seems to be a bug in 4.8.0. I don’t think there’s anything that can be done in the plugin to fix this, because Txp is throwing out the URL before the plugin even has a chance to intervene. Same with smd_tags. We’ll have to figure this out in core. Sorry for the hassle.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#809 2020-03-04 12:02:37

Vienuolis
Member
From: Vilnius, Lithuania
Registered: 2009-06-14
Posts: 327
Website GitHub GitLab Mastodon Twitter

Re: tru_tags: A tagging plugin for textpattern

Strange behavior: somewhat hidden messy tag URL in a clean URL scheme:

https://on.lt/dalykai/tiesa/

where: ‛tiesa’ is a tag (keyword), and ‛dalykai’ — Lithuanian substitution of the English word ‛tags’.

The bold URL here is obtained by PHP as an environment variable:

 	<txp:php> 
$urn = urldecode($_SERVER['REQUEST_URI']);
$urh = "{$_SERVER['HTTP_SCHEME']}://{$_SERVER['HTTP_HOST']}";
echo $urh . $urn;
	</txp:php>

Where the ?t= comes from?

Offline

#810 2020-03-11 18:56:34

Vienuolis
Member
From: Vilnius, Lithuania
Registered: 2009-06-14
Posts: 327
Website GitHub GitLab Mastodon Twitter

Re: tru_tags: A tagging plugin for textpattern

<meta::description format="" /> output disappear on sections after Textpattern 4.7.3 → 4.8.0 upgrade. No warnings while in debugging mode. And no changes on Meta description docs since v4.6.0.

type="article" context attribute solved the problem. Could this be the cause for tru::tags error 404, too?

Offline

Board footer

Powered by FluxBB