Support ⇒ Dragonfly CMS v10 ⇒ Auxiliar functions ⇒ Community Forums ⇒ CPG Dragonfly™ CMS
Forum IndexDragonfly CMS v10

Auxiliar functions Reply to topic


After a long time working on CMS programming (version 9 and now version 10), I have created several functions that have been very useful for working with chains both to cut them and to perform certain manipulations. I think it can be useful to integrate them into the system under a denomination of utilities or something similar.

The file has 3 functions. The "main" functions are cleanAndCut and getKeys, the third function is equally functional, but its main use is as an auxiliary for the others. All of them work with UTF8 encoded strings and to cut strings you work with multibyte functions for the new characters.

/** * Returns a text trimmed and edited according to the parameters. * <p>This function allows you to treat a text with a series of operations from simply cut (both at the end as at the beginning) to clear the contents of tags bbcode, html and php to get the contents as plain text. The configuration allows choosing the desired cleanliness level for output text.</p> * <p>If you just want a list of keywords to a chain or you want to set the type of words you get, you should use <b>getKeys(string, int, bool)</b>, because the configuration options and the efficiency of the function are almost over for this purpose.</p> * * @param <b>text (string):</b> Text on which you want to work</p> * @param <b>length (int[optional, default -1]):</b> Length of the result string. If this value is greater than the size of the string, or a negative value, the entire string will be returned.</p> * @param <b>params (array[optional, default null]):</b> Array with a list of extra parameters like:<br /> * <i>clean (bool[optional, default true]):</i> Set option to clean text or not.</p> * <i>initPos (int[optional, default 0]):</b> Starting point for result. If the value is greater than the length of the string, the result will be an empty string.</p> * <i>searchBlanks (bool[optional, default true]):</b> Set option to cut text by blanks. If false, text will be cutted at exactly lenght.</p> * <i>Ellipsis (bool[optional, default true]):</i> No add ellipsis to text.</p> * <i>remainingChain (string[optional, defualt false]):</i> Return rest of string into array at returnValues.</p> * @param <b>returnValues (array[IN/OUT]):</b> Array of returned optional values. This array contents all optional trated values</p> * * @return String that results after treatment * * @version 2.0.0 */ public static function cleanAndCut($text, $length=-1, $params=null, &$returnValues=null) {} /** * Return text without any html, php, bbcode or any listed tag. In addition it's possible to delete some extra elements to show text with out any sign. * * @param <b>text (string):</b> Text to clean tags.</p> * @param <b>cleanQuotes (bool[optional, default false]):</b> Use this option to clean all content for a quotes tags.</p> * @param <b>extended (bool[optional, default false]):</b> Use this option to clean extra tags and signs from text.</p> * * @return String clean text * * @version 1.2.0 */ public static function cleanText($text, $cleanQuotes=false, $extended=false) {} /** * Extract keywords separated by coma from original text. * @param <b>text (string):</b> Chain to be extracted keywords.<p> * @param <b>minLength (int[optional, default 3]):</b> Minimum length of words that are considered key.<p> * @param <b>clean (bool[optional, default true]):</b> Whether you need to apply filters to remove tags before extract keywords.<p> * * @return string with keywords * * @version 1.1.0 */ public static function getKeys($text, $minWordLength=3, $maxStringLength=Utilities::V_MAX_TEXT_LENGTH, $clean=true, $returnArray=false) {}

I hope that these functions can be useful for everyone.
Attachment: g_functions.php.txt
Description File with utilities functions. Rename it to .php
Filename g_functions.php.txt
Filesize 10.48 KiB
Downloaded 4 Time(s)
You are not allowed to view/download this attachment

until the next (Bye),

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Dragonfly 9.2 (PHP5.4)


Hi Grimpow, if you drop this into /includes/geonis/utilities.php would simply calling Geonis\Utilities from within any module work?

P.S.: I reviewed your bitbucket pull requests a couple of months ago

.:: I met php the 03 December 2003 :: Unforgettable day! ::.

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
CloudLinux / Apache 2.4 LSAPI / MySQLi 5.7 / PHP 7.3 / head

Last edited by NanoCaiordo on Sat Jan 05, 2019 10:59 am; edited 1 time in total


Hi NanoCaiordo,

I Use this functions exactly like you say and it works perfectlly.

until the next (Bye),

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Dragonfly 9.2 (PHP5.4)


Could you tell us about practical uses, would also be nice to ear if others finds use of it.

Cheers

.:: I met php the 03 December 2003 :: Unforgettable day! ::.

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
CloudLinux / Apache 2.4 LSAPI / MySQLi 5.7 / PHP 7.3 / head


Actually I use this functions to create descriptions for every topic page from message texts. I can clean all characters that don't like to description and cut to mas length for google.

until the next (Bye),

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Dragonfly 9.2 (PHP5.4)


Do a pull request, from clients it's easier to pull the patch and track future changes, if any.

Include a working example code for basic usage please.

Cheers.

.:: I met php the 03 December 2003 :: Unforgettable day! ::.

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
CloudLinux / Apache 2.4 LSAPI / MySQLi 5.7 / PHP 7.3 / head

All times are UTC


Jump to: