Textpattern CMS support forum

You are not logged in. Register | Login | Help

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

whocarez
Plugin Author
From: Germany/Ukraine
Registered: 2007-10-08
Posts: 237
Website

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: 237
Website

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: 74

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,152

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: 90

Re: tru_tags: A tagging plugin for textpattern

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


The WIPsnakebite.cafe
A place for conversations like #techxiety the podcast and #SingleTracking the new, text-only-for-now topic about parenting. It’s just so easy to find ways to stay busy with Textpattern!

Offline

Board footer

Powered by FluxBB