PDA

View Full Version : Plugin Manual


CleanDesignDk
12-23-2011, 07:02 AM
Hi,

Is the support - manual for development of plugins updated with all new functions to version 3.4.2 ?

or is it the same functions we can use as allways ?

Tobias
12-23-2011, 09:53 AM
Hi,
there are one or two new functions and classes, but some of these are still undergoing refinements and I'll have to postpone documentation for those for a bit.

All previously existing functions should still be there, though probably with smaller enhancements or minor changes.
One function worth re-checking is "sd_PrintAvatar", if used by your plugin(s).
It's HTML markup and parameters may have changed.

With SD 3.4.3 I'll add documentation of a new, static class named "SDUserCache", which makes it much easier to keep a cached list of users with all important data and pre-defined generated HTML tags (like link to user profile page), which can be shared/used by all plugins during pageload (primarily with SD userbase, not so much integrated forum yet).

Please feel free to ask me about any function if there are specific questions.

Regards,
Tobias

ValsiS
12-23-2011, 07:44 PM
Hello there,

I will ask you something ...

How can i use the SEO *(mod-rewrite)? i look a little bit in cod and i see you create table/row in DB for seo link on articles and categories
what is the function for that ? to change the title to be good for seo.... i have a function for that, but i want to use the same function from SD.

pls give me much more details ... how to use in getvar function ....

thanks in advence

Tobias
12-24-2011, 07:06 AM
Hello,

For generation of SEO titles:
Open file "/includes/class_articles_settings.php" and search for "function InsertArticle()" (around line 495) for an example how to generate a SEO title from user input.

The basic work is done by calling the core function "ConvertNewsTitleToUrl" like this:
$seotitle = ConvertNewsTitleToUrl($title, 0, 0, true);where "$title" is the variable containing your item's regular title.

Description for the function (in "includes/functions_global.php"):
/**
* Converts the passed SEO article $title into SEO URL-compatible formatted string.
* If $title_only is set to false, this can be used for any URL parameters.
*
* @param string $title SEO title of the article
* @param int $artId Article ID
* @param int $page Page of article (defaults to 1)
* @param bool $title_only If true, the article id and page are not used
* @return string or null
*/
Although it talks about articles, you can use this for any other plugin.

The articles plugin does a lot more work around it, like checking for already existing SEO titles to avoid duplicates and check for either title or existing seo title of the article.

The 1st and 2nd parameters MUST be passed as correct values.
The 3rd parameter for the page number is usually "0" and would only be specified for dynamic generation when e.g. displaying links within your plugin item for pagination.
If the 4th parameter is "false", unlike in above example, the SEO title will get a suffix like "-a123" as an extra unique identifier with "123" being the 2nd parameter. This is up to SD342 a fixed "a" character and originally comes from SD2.x times.

With SD 3.4.3 there will be a 5th parameter "$tail" which allows to specify the "tailing" character, instead of the default "a".
This can be already seen on the Subdreamer.com (http://www.subdreamer.com/forum.html)'s Forum where all forum- and topic titles have SEO titles with a special identifying suffix.
Example: forum "Announcements" looks like "announcements-f80.html" or an example topic "mytopic-t99.html" where the tail is either "fxxx" for a forum or "txxx" for a topic so that the forum plugin can uniquely identify the content.

The "GetVar()" function:
This core function, defined in "includes/functions_global.php", is both to make development in SD easier and assure a consistent data type when using buffer variables (mainly POST/GET).
Note that by design SD applies both "htmlspecialchars" and adds slashes to all buffer variables' quotes before any plugin is loaded and therefore "string" results are ready to be inserted into the DB.

Example 1:
"string" - get a string value with default "nothing" (checks both GET and POST). As mentioned before, value is already htmlspecialchar'ed/slashed:
$title = GetVar('title', 'nothing', 'string'); Example 2:
"html" - get a value as HTML, i.e. HTML tags are intact and quotes are NOT escaped!
$title = GetVar('title', 'nothing', 'html');
Important: before storing any "html" result in the database, you MUST use "$DB->escape_string($title)" for any query operation, like in a query to check for an existing title:
if($seo_title_exists = $DB->query_first('SELECT seo_title FROM {yourtablename} WHERE id != %d AND seo_title = '%s'",
$myid, $DB->escape_string($title)))
{ /* a title was found, do something */ } Example 3:
"whole_number" - allows for all positive int values starting from 1:
$mynumber = GetVar('html_element_name', 0, 'whole_number', true, false);If the value for the element is not 1 or any higher int, it will be defaulted to 0 (2nd parameter).
The "true", "false" parameters mean to only get POST, but not GET values.

Is_Valid_Number()
To check if a variable value (integer) is in a specific range and apply a default value, use code like this:
$displayorder = Is_Valid_Number($displayorder, 0, 1, 9999);If the variable has a value between 1..9999 the value will be returned, otherwise it will return the specified default value of 0 (2nd parameter).
The 4th parameter (example: 9999) is optional, but is recommended to be specified to check against unreasonable numbers, i.e. a month value should have "12" as the maximum allowed value etc.

I hope this helps out a bit.

Happy holidays! :)

ValsiS
12-24-2011, 07:28 AM
Thanks,
Very nice explained.

Happy Holidays!

Tobias
12-24-2011, 08:33 AM
Thanks, Very nice explained.

You're welcome.

Btw, I moved this thread to "SD3 - Plugin development" forum (instead of "SD2...").