Reference for writing tags

You want to write an own Tag? This desciption can help you to understand how to do it.

If you have more questions or problems, use ours internal forum to ask your questions. Questions sent to our email address can't be answered.

Tag name

Give your Tag a name, the name must beginnig with a character and can including digits, underscore and hyphen.

The Tag name is not case sensitive, but for better reading you can write the Tagname case sensitive.

$params

The params contains the parameters for the Tag name, eg. <YourTag parameter1="example">. You can add as many parameters to your Tag as you need. But it gives two parameters witch will be always set for you. These are the id of the Tag and the jplgid. The jpligid is used to determine whether the Tag was made on your server, and the id is the id of the current system.

Why you should need that? You can use the same name multiple times but you shouldn't do it. The problem could occur when Tags are coming from different providers. On installation the Tag gets a new id, but the jplgid is fixed on the creator of the Tag. E.g. you have two Tags with the name <xy/>, the plugin calls the first Tag with the lowest id in the database to execute the code. But if you want call the second Tag, you'd have to write <xy id="10"/>, if the second Tag had the id 10. But if you are a content provider, this case is not helpful to you as the id differs on each system. So it is better to use the jplgid on the Tag, e.g. for the second Tag. <xy jplgid="7abc5c5e356dc92337c4d86094b65c26"/>

7abc5c5e356dc92337c4d86094b65c26 is the jplgid from the www.jplugger.com server.

All names in $params are lower case, you can access the your parameters with $params['id'] and $params['jplgid'].

&$content

The variable content is read and writable. It's contains the content between the opener tag and the closing tag. E.g. <xy>Content</xy>. What you do with the content is something you have to decide for yourself. What you write to the variable is later displayed as the content on the page.

$jpfunc

Some internal functions to make the development for a Tag a little bit easier.

You call the internal function like $jpfunc->getFunctionalityVersion();

Functons are:

  • int getFunctionalityVersion();
    • Available since: 1
    • This function returning the jplugger plugin version. So you can check if you use a new internal version and whether the installed version supporting the functionality.
  • void listParams($params);
    • Available since: 1
    • The function helps debugging, since it gives the $params out to the message field on the called site.
  • void listVars($vars);
    • Available since: 1
    • The function helps debugging, since it gives the $vars out to the message field on the called site.
  • void listDump($misc);
    • Available since: 1
    • The function helps debugging, since it gives the $misc out to the message field on the called site.
  • void addMessage($message);
    • Available since: 1
    • Creates an message on the message field on the site.
  • void addError($message);
    • Available since: 1
    • Creates an error message on the message field on the site.
  • void addNotice($message);
    • Available since: 1
    • Creates an notice message on the message field on the site.
  • void addWarning($message);
    • Available since: 1
    • Creates an warning message on the message field on the site.
  • string getFileSystemPath($id);
    • Available since: 1
    • Returns the system path to the filesystem folder for the id. Files can be stored over the media manager in the jplugger folder /Id of the Tag.
  • string getURLPath($id);
    • Available since: 1
    • Returns the URL for the Id. Files can be stored over the media manager in the jplugger folder/Id of the Tag.
  • void addScript($scriptUrl, $type = "text/javascript", $defer = false, $async = false);
    • Available since: 1
    • Adds a script file to the header section of the html output.
    • $scriptUrl must contain the URL to the script file, not the file system path.
  • void addScriptCode($code);
    • Available since: 1
    • Adds JavaScript code to the header section of the html output.
  • void addCSS($cssUrl);
    • Available since: 1
    • Add a css file to the header section of the html output.
    • $cssUrl must contain the URL of the ccs file, not the file system path.
  • void addCSSCode($code);
    • Available since: 1
    • Adds CSS code to the header of the html output.
  • string executeCode($code);
    • Available since: 1
    • Executes the code witch is given in $code and returns the result of the executing code.
  • string getNativeCode($code, $stripTags=false);
    • Available since: 1
    • If your code has quotas, e.g. &amp;, this function converts the code to the normal form.
    • If you want to strip html tags before the converting is running, set $stripTags to true.
  • string removeInvalidHTMLTags($content);
    • removing leading and trailing broken/invalid tags from the content.
  • array function getHtmlTags($htmltags=array(), $content=""); //deprecated
    • Use activatePHPQuery() instead
    • Available since: 1; Will be removed in future releases
    • If you want parsing html tags in you content, you can use this fuction. The function retruning a array with the parsing result.
    • E.g. $htmltags=array("p","a","span");
    • The structure of the result can be seen, if you make a debug output of the result with the listDump function.

New in library version 2

Check always the if($jpfunc->getFunctionalityVersion() >= 2) { /* use the new function */ }

  • array grabURL( $url, $referer = null, $postvars=array());
    • Avaliable since: 2
    • $url: the to grab
    • $referer: website do you come from (default the base of $url)
    • $postvars: if you want to send with post variables array("name"=>"value", ...)
    • returns a result array $result[0] the content, $result[1] the header array (use $jpfunc->listDump($result[0]); )
    • returns false on a communication error.

New in library version 3

Check always the if($jpfunc->getFunctionalityVersion() >= 3 ) { /* use the new function */ }

  • void activatePHPQuery();
    • activate PHPQuery
    • to use PHPQuery see then manual for PHPQuery in the internet.
// Inside of your Tag
// check the version - if < 3 display a error message
if( $jpfunc->getFunctionalityVersion() < 3) {
$jpfunc->addError('Install the lastest version of plg_jplugger on the <a href="https://www.jplugger.com">JPluggger Site</a>');
return;
}

// activate the library
$jpfunc->activatePHPQuery();

// create a PHPQuery object
$pq = phpQuery::newDocumentHTML($content);

// grep all images on the content
$pq['img] == $pq->find('img');

// find and modify all img alt tags
foreach ($pq['img'] as $idx) {
$url = pq($idx)->attr('src');
$alt = pq($idx)->attr('alt');
if( $alt == "" ) {
// modify the attribute if empty
pq($idx)->attr('alt','Image from JPlugger.com');
}
}

// output the modified html code
$content=$pq->html();

&$vars

If your Tag must store values, the Tag can store them to the variable $vars. $vars is an array and by default empty. In the most cases you need it to push variable form inner Tags to outer Tags. $vars['myTag']=array( "var1" => "value1"); You can use this in the outer Tag. If you don't need the Tag anymore, make a unset to protect from side effects. The plugin will not do it by itself.

PHP Code

In this field you can write your PHP-Code using the internal function of jplugger. Dont use <?php on the first line.

Status

In this field you can select the state of the Tag. Published or not published. Only published Tags will execute from the jplugger plugin.

Execute on Administrator

If you want to execute your Tag on the administrator site, use the checkbox to select the fuctionality. In the most cases you don't need this.

Execute on Title

If you want use Tags on titles, you must switch on the functionality on the checkbox.

Execute on introtext

If you want use the Tag on the introtext, you must switch on the functionality on the checkbox.

Execute on fulltext

If you want use the Tag on the fulltext, you must switch on the functionality on the checkbox.

Execute on Text

This is the default and means execute on introtext and fulltext, but not on titles.

Help link

If you want to be a publisher for customer, you can set a URL to a help page for your Tag.

For publishing you can find a component in the download area.

Advertising

© 2010 - 2017 FINWICK® UG

We have 28 guests and no members online