From 63278a5887ec7e03487e81daa47c2da609b22f26 Mon Sep 17 00:00:00 2001 From: Devansh Bawari Date: Thu, 19 Sep 2024 18:53:23 +0530 Subject: [PATCH 1/8] feat: imap work and enhancement --- .env.example | 7 + composer.json | 3 +- composer.lock | 160 ++++++++++++- config/imap.php | 226 ++++++++++++++++++ .../Http/Controllers/Mail/EmailController.php | 7 +- .../Webkul/Email/src/Helpers/Attachment.php | 33 ++- packages/Webkul/Email/src/Helpers/Charset.php | 13 +- .../src/Helpers/Contracts/CharsetManager.php | 10 +- .../Webkul/Email/src/Helpers/Exception.php | 5 - .../{Htmlfilter.php => HtmlFilter.php} | 173 ++++++-------- packages/Webkul/Email/src/Helpers/Parser.php | 192 ++++++++------- .../Contracts/InboundEmailProcessor.php | 13 + .../SendgridEmailProcessor.php | 102 ++++++++ .../WebklexImapEmailProcessor.php | 112 +++++++++ .../src/Providers/EmailServiceProvider.php | 5 + .../src/Repositories/EmailRepository.php | 121 +--------- 16 files changed, 854 insertions(+), 328 deletions(-) create mode 100644 config/imap.php delete mode 100644 packages/Webkul/Email/src/Helpers/Exception.php rename packages/Webkul/Email/src/Helpers/{Htmlfilter.php => HtmlFilter.php} (88%) create mode 100644 packages/Webkul/Email/src/InboundEmailProcessor/Contracts/InboundEmailProcessor.php create mode 100644 packages/Webkul/Email/src/InboundEmailProcessor/SendgridEmailProcessor.php create mode 100644 packages/Webkul/Email/src/InboundEmailProcessor/WebklexImapEmailProcessor.php diff --git a/.env.example b/.env.example index 5f172ce5d..760849d11 100644 --- a/.env.example +++ b/.env.example @@ -42,6 +42,13 @@ MAIL_FROM_ADDRESS=laravel@krayincrm.com MAIL_FROM_NAME="${APP_NAME}" MAIL_DOMAIN=webkul.com +IMAP_HOST=imap.example.com +IMAP_PORT=993 +IMAP_ENCRYPTION=ssl +IMAP_VALIDATE_CERT=true +IMAP_USERNAME=your_username +IMAP_PASSWORD=your_password + AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= AWS_DEFAULT_REGION=us-east-1 diff --git a/composer.json b/composer.json index dd412015c..64e606612 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,8 @@ "laravel/ui": "^4.5", "maatwebsite/excel": "^3.1", "mpdf/mpdf": "^8.2", - "prettus/l5-repository": "^2.7.9" + "prettus/l5-repository": "^2.7.9", + "webklex/laravel-imap": "^5.3" }, "require-dev": { "barryvdh/laravel-debugbar": "^3.6", diff --git a/composer.lock b/composer.lock index d1b3ece89..65bf5b6a3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c9cae30842ed7c9020a3f23f06e1c0b2", + "content-hash": "ef03fb88351c6329aca7d8e4ab65aea4", "packages": [ { "name": "barryvdh/laravel-dompdf", @@ -7799,6 +7799,164 @@ ], "time": "2022-03-08T17:03:00+00:00" }, + { + "name": "webklex/laravel-imap", + "version": "5.3.0", + "source": { + "type": "git", + "url": "https://github.com/Webklex/laravel-imap.git", + "reference": "a424988a314c09f924390011a7baa8025efb9e14" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Webklex/laravel-imap/zipball/a424988a314c09f924390011a7baa8025efb9e14", + "reference": "a424988a314c09f924390011a7baa8025efb9e14", + "shasum": "" + }, + "require": { + "laravel/framework": ">=6.0.0", + "php": "^8.0.2", + "webklex/php-imap": "^5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + }, + "laravel": { + "providers": [ + "Webklex\\IMAP\\Providers\\LaravelServiceProvider" + ], + "aliases": { + "Client": "Webklex\\IMAP\\Facades\\Client" + } + } + }, + "autoload": { + "psr-4": { + "Webklex\\IMAP\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Malte Goldenbaum", + "email": "github@webklex.com", + "role": "Developer" + } + ], + "description": "Laravel IMAP client", + "homepage": "https://github.com/webklex/laravel-imap", + "keywords": [ + "idle", + "imap", + "laravel", + "laravel-imap", + "mail", + "oauth", + "pop3", + "webklex" + ], + "support": { + "issues": "https://github.com/Webklex/laravel-imap/issues", + "source": "https://github.com/Webklex/laravel-imap/tree/5.3.0" + }, + "funding": [ + { + "url": "https://www.buymeacoffee.com/webklex", + "type": "custom" + }, + { + "url": "https://ko-fi.com/webklex", + "type": "ko_fi" + } + ], + "time": "2023-06-20T11:42:58+00:00" + }, + { + "name": "webklex/php-imap", + "version": "5.5.0", + "source": { + "type": "git", + "url": "https://github.com/Webklex/php-imap.git", + "reference": "3c23c8f66b772ce8597772816e068326559e7e4b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Webklex/php-imap/zipball/3c23c8f66b772ce8597772816e068326559e7e4b", + "reference": "3c23c8f66b772ce8597772816e068326559e7e4b", + "shasum": "" + }, + "require": { + "ext-fileinfo": "*", + "ext-iconv": "*", + "ext-json": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-openssl": "*", + "ext-zip": "*", + "illuminate/pagination": ">=5.0.0", + "nesbot/carbon": "^2.62.1", + "php": "^8.0.2", + "symfony/http-foundation": ">=2.8.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.5.10" + }, + "suggest": { + "symfony/mime": "Recomended for better extension support", + "symfony/var-dumper": "Usefull tool for debugging" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "Webklex\\PHPIMAP\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Malte Goldenbaum", + "email": "github@webklex.com", + "role": "Developer" + } + ], + "description": "PHP IMAP client", + "homepage": "https://github.com/webklex/php-imap", + "keywords": [ + "imap", + "mail", + "php-imap", + "pop3", + "webklex" + ], + "support": { + "issues": "https://github.com/Webklex/php-imap/issues", + "source": "https://github.com/Webklex/php-imap/tree/5.5.0" + }, + "funding": [ + { + "url": "https://www.buymeacoffee.com/webklex", + "type": "custom" + }, + { + "url": "https://ko-fi.com/webklex", + "type": "ko_fi" + } + ], + "time": "2023-06-28T01:57:03+00:00" + }, { "name": "webmozart/assert", "version": "1.11.0", diff --git a/config/imap.php b/config/imap.php new file mode 100644 index 000000000..789f13485 --- /dev/null +++ b/config/imap.php @@ -0,0 +1,226 @@ + env('IMAP_DEFAULT_ACCOUNT', 'default'), + + /* + |-------------------------------------------------------------------------- + | Default date format + |-------------------------------------------------------------------------- + | + | The default date format is used to convert any given Carbon::class object into a valid date string. + | These are currently known working formats: "d-M-Y", "d-M-y", "d M y" + | + */ + 'date_format' => 'd-M-Y', + + /* + |-------------------------------------------------------------------------- + | Available IMAP accounts + |-------------------------------------------------------------------------- + | + | Please list all IMAP accounts which you are planning to use within the + | array below. + | + */ + 'accounts' => [ + + 'default' => [// account identifier + 'host' => env('IMAP_HOST', 'localhost'), + 'port' => env('IMAP_PORT', 993), + 'protocol' => env('IMAP_PROTOCOL', 'imap'), //might also use imap, [pop3 or nntp (untested)] + 'encryption' => env('IMAP_ENCRYPTION', 'ssl'), // Supported: false, 'ssl', 'tls', 'notls', 'starttls' + 'validate_cert' => env('IMAP_VALIDATE_CERT', true), + 'username' => env('IMAP_USERNAME', 'root@example.com'), + 'password' => env('IMAP_PASSWORD', ''), + 'authentication' => env('IMAP_AUTHENTICATION', null), + 'proxy' => [ + 'socket' => null, + 'request_fulluri' => false, + 'username' => null, + 'password' => null, + ], + 'timeout' => 30, + 'extensions' => [], + ], + + /* + 'gmail' => [ // account identifier + 'host' => 'imap.gmail.com', + 'port' => 993, + 'encryption' => 'ssl', + 'validate_cert' => true, + 'username' => 'example@gmail.com', + 'password' => 'PASSWORD', + 'authentication' => 'oauth', + ], + + 'another' => [ // account identifier + 'host' => '', + 'port' => 993, + 'encryption' => false, + 'validate_cert' => true, + 'username' => '', + 'password' => '', + 'authentication' => null, + ] + */ + ], + + /* + |-------------------------------------------------------------------------- + | Available IMAP options + |-------------------------------------------------------------------------- + | + | Available php imap config parameters are listed below + | -Delimiter (optional): + | This option is only used when calling $oClient-> + | You can use any supported char such as ".", "/", (...) + | -Fetch option: + | IMAP::FT_UID - Message marked as read by fetching the body message + | IMAP::FT_PEEK - Fetch the message without setting the "seen" flag + | -Fetch sequence id: + | IMAP::ST_UID - Fetch message components using the message uid + | IMAP::ST_MSGN - Fetch message components using the message number + | -Body download option + | Default TRUE + | -Flag download option + | Default TRUE + | -Soft fail + | Default FALSE - Set to TRUE if you want to ignore certain exception while fetching bulk messages + | -RFC822 + | Default TRUE - Set to FALSE to prevent the usage of \imap_rfc822_parse_headers(). + | See https://github.com/Webklex/php-imap/issues/115 for more information. + | -Debug enable to trace communication traffic + | -UID cache enable the UID cache + | -Fallback date is used if the given message date could not be parsed + | -Boundary regex used to detect message boundaries. If you are having problems with empty messages, missing + | attachments or anything like this. Be advised that it likes to break which causes new problems.. + | -Message key identifier option + | You can choose between the following: + | 'id' - Use the MessageID as array key (default, might cause hickups with yahoo mail) + | 'number' - Use the message number as array key (isn't always unique and can cause some interesting behavior) + | 'list' - Use the message list number as array key (incrementing integer (does not always start at 0 or 1) + | 'uid' - Use the message uid as array key (isn't always unique and can cause some interesting behavior) + | -Fetch order + | 'asc' - Order all messages ascending (probably results in oldest first) + | 'desc' - Order all messages descending (probably results in newest first) + | -Disposition types potentially considered an attachment + | Default ['attachment', 'inline'] + | -Common folders + | Default folder locations and paths assumed if none is provided + | -Open IMAP options: + | DISABLE_AUTHENTICATOR - Disable authentication properties. + | Use 'GSSAPI' if you encounter the following + | error: "Kerberos error: No credentials cache + | file found (try running kinit) (...)" + | or ['GSSAPI','PLAIN'] if you are using outlook mail + | -Decoder options (currently only the message subject and attachment name decoder can be set) + | 'utf-8' - Uses imap_utf8($string) to decode a string + | 'mimeheader' - Uses mb_decode_mimeheader($string) to decode a string + | + */ + 'options' => [ + 'delimiter' => '/', + 'fetch' => \Webklex\PHPIMAP\IMAP::FT_PEEK, + 'sequence' => \Webklex\PHPIMAP\IMAP::ST_UID, + 'fetch_body' => true, + 'fetch_flags' => true, + 'soft_fail' => false, + 'rfc822' => true, + 'debug' => false, + 'uid_cache' => true, + // 'fallback_date' => "01.01.1970 00:00:00", + 'boundary' => '/boundary=(.*?(?=;)|(.*))/i', + 'message_key' => 'list', + 'fetch_order' => 'asc', + 'dispositions' => ['attachment', 'inline'], + 'common_folders' => [ + 'root' => 'INBOX', + 'junk' => 'INBOX/Junk', + 'draft' => 'INBOX/Drafts', + 'sent' => 'INBOX/Sent', + 'trash' => 'INBOX/Trash', + ], + 'decoder' => [ + 'message' => 'utf-8', // mimeheader + 'attachment' => 'utf-8', // mimeheader + ], + 'open' => [ + // 'DISABLE_AUTHENTICATOR' => 'GSSAPI' + ], + ], + + /* + |-------------------------------------------------------------------------- + | Available flags + |-------------------------------------------------------------------------- + | + | List all available / supported flags. Set to null to accept all given flags. + */ + 'flags' => ['recent', 'flagged', 'answered', 'deleted', 'seen', 'draft'], + + /* + |-------------------------------------------------------------------------- + | Available events + |-------------------------------------------------------------------------- + | + */ + 'events' => [ + 'message' => [ + 'new' => \Webklex\IMAP\Events\MessageNewEvent::class, + 'moved' => \Webklex\IMAP\Events\MessageMovedEvent::class, + 'copied' => \Webklex\IMAP\Events\MessageCopiedEvent::class, + 'deleted' => \Webklex\IMAP\Events\MessageDeletedEvent::class, + 'restored' => \Webklex\IMAP\Events\MessageRestoredEvent::class, + ], + 'folder' => [ + 'new' => \Webklex\IMAP\Events\FolderNewEvent::class, + 'moved' => \Webklex\IMAP\Events\FolderMovedEvent::class, + 'deleted' => \Webklex\IMAP\Events\FolderDeletedEvent::class, + ], + 'flag' => [ + 'new' => \Webklex\IMAP\Events\FlagNewEvent::class, + 'deleted' => \Webklex\IMAP\Events\FlagDeletedEvent::class, + ], + ], + + /* + |-------------------------------------------------------------------------- + | Available masking options + |-------------------------------------------------------------------------- + | + | By using your own custom masks you can implement your own methods for + | a better and faster access and less code to write. + | + | Checkout the two examples custom_attachment_mask and custom_message_mask + | for a quick start. + | + | The provided masks below are used as the default masks. + */ + 'masks' => [ + 'message' => \Webklex\PHPIMAP\Support\Masks\MessageMask::class, + 'attachment' => \Webklex\PHPIMAP\Support\Masks\AttachmentMask::class, + ], +]; diff --git a/packages/Webkul/Admin/src/Http/Controllers/Mail/EmailController.php b/packages/Webkul/Admin/src/Http/Controllers/Mail/EmailController.php index 2c0008b07..a4245ba80 100644 --- a/packages/Webkul/Admin/src/Http/Controllers/Mail/EmailController.php +++ b/packages/Webkul/Admin/src/Http/Controllers/Mail/EmailController.php @@ -14,6 +14,7 @@ use Webkul\Admin\Http\Requests\MassDestroyRequest; use Webkul\Admin\Http\Requests\MassUpdateRequest; use Webkul\Admin\Http\Resources\EmailResource; +use Webkul\Email\InboundEmailProcessor\Contracts\InboundEmailProcessor; use Webkul\Email\Mails\Email; use Webkul\Email\Repositories\AttachmentRepository; use Webkul\Email\Repositories\EmailRepository; @@ -196,13 +197,13 @@ public function update($id) } /** - * Run process inbound parse email + * Run process inbound parse email. * * @return \Illuminate\Http\Response */ - public function inboundParse() + public function inboundParse(InboundEmailProcessor $inboundEmailProcessor) { - $this->emailRepository->processInboundParseMail(request('email')); + $inboundEmailProcessor->process(request('email')); return response()->json([], 200); } diff --git a/packages/Webkul/Email/src/Helpers/Attachment.php b/packages/Webkul/Email/src/Helpers/Attachment.php index 3731f4c7f..b1014cfd5 100644 --- a/packages/Webkul/Email/src/Helpers/Attachment.php +++ b/packages/Webkul/Email/src/Helpers/Attachment.php @@ -5,14 +5,11 @@ class Attachment { /** + * Content. + * * @var File Content */ - private $content; - - /** - * @var Filename extension - */ - private $extension; + private $content = null; /** * Create an helper instance @@ -24,12 +21,10 @@ public function __construct( public $contentDisposition = 'attachment', public $contentId = '', public $headers = [] - ) { - $this->content = null; - } + ) {} /** - * retrieve the attachment filename + * Retrieve the attachment filename. * * @return string */ @@ -39,7 +34,7 @@ public function getFilename() } /** - * Retrieve the Attachment Content-Type + * Retrieve the attachment content type. * * @return string */ @@ -49,7 +44,7 @@ public function getContentType() } /** - * Retrieve the Attachment Content-Disposition + * Retrieve the attachment content disposition. * * @return string */ @@ -59,7 +54,7 @@ public function getContentDisposition() } /** - * Retrieve the Attachment Content-ID + * Retrieve the attachment content ID. * * @return string */ @@ -69,7 +64,7 @@ public function getContentID() } /** - * Retrieve the Attachment Headers + * Retrieve the attachment headers. * * @return string */ @@ -79,8 +74,9 @@ public function getHeaders() } /** - * Read the contents a few bytes at a time until completed - * Once read to completion, it always returns false + * Read the contents a few bytes at a time until completed. + * + * Once read to completion, it always returns false. * * @param int $bytes * @return string @@ -91,8 +87,9 @@ public function read($bytes = 2082) } /** - * Retrieve the file content in one go - * Once you retrieve the content you cannot use MimeMailParser_attachment::read() + * Retrieve the file content in one go. + * + * Once you retrieve the content you cannot use MimeMailParser_attachment::read(). * * @return string */ diff --git a/packages/Webkul/Email/src/Helpers/Charset.php b/packages/Webkul/Email/src/Helpers/Charset.php index 9ff0478f9..331d0da17 100644 --- a/packages/Webkul/Email/src/Helpers/Charset.php +++ b/packages/Webkul/Email/src/Helpers/Charset.php @@ -7,7 +7,9 @@ class Charset implements CharsetManager { /** - * Charset Aliases + * Charset aliases. + * + * @var array */ private $charsetAlias = [ 'ascii' => 'us-ascii', @@ -310,11 +312,10 @@ class Charset implements CharsetManager 'x-gbk' => 'gbk', 'windows-936' => 'gbk', 'ansi-1251' => 'windows-1251', - // '' => 'UTF-8', ]; /** - * Decode the string from Charset + * Decode the string from charset. * * @param string $encodedString * @param string $charset @@ -334,7 +335,7 @@ public function decodeCharset($encodedString, $charset) } /** - * Get charset alias + * Get charset alias. * * @param string $charset. * @return string @@ -345,8 +346,8 @@ public function getCharsetAlias($charset) if (array_key_exists($charset, $this->charsetAlias)) { return $this->charsetAlias[$charset]; - } else { - return null; } + + return null; } } diff --git a/packages/Webkul/Email/src/Helpers/Contracts/CharsetManager.php b/packages/Webkul/Email/src/Helpers/Contracts/CharsetManager.php index 3b4dea22f..5fc1b3d7f 100644 --- a/packages/Webkul/Email/src/Helpers/Contracts/CharsetManager.php +++ b/packages/Webkul/Email/src/Helpers/Contracts/CharsetManager.php @@ -5,18 +5,16 @@ interface CharsetManager { /** - * Decode the string from Charset + * Decode the string from Charset. * - * @param $encodedString The string in its original encoded state - * @param $charset The Charset header of the part. - * @return string the decoded string + * @return string */ public function decodeCharset($encodedString, $charset); /** - * Get charset alias + * Get charset alias. * - * @return string the charset alias + * @return string */ public function getCharsetAlias($charset); } diff --git a/packages/Webkul/Email/src/Helpers/Exception.php b/packages/Webkul/Email/src/Helpers/Exception.php deleted file mode 100644 index 5f4fcc99a..000000000 --- a/packages/Webkul/Email/src/Helpers/Exception.php +++ /dev/null @@ -1,5 +0,0 @@ -'; } else { $fulltag = '<'.$tagname; + if (is_array($attary) && count($attary)) { $atts = []; @@ -34,8 +43,8 @@ public function tln_tagprint($tagname, $attary, $tagtype) * A small helper function to use with array_walk. Modifies a by-ref * value and makes it lowercase. * - * @param string $val a value passed by-ref. - * @return void since it modifies a by-ref value. + * @param string $val + * @return void */ public function tln_casenormalize(&$val) { @@ -46,10 +55,9 @@ public function tln_casenormalize(&$val) * This function skips any whitespace from the current position within * a string and to the next non-whitespace value. * - * @param string $body the string - * @param int $offset the offset within the string where we should start - * looking for the next non-whitespace character. - * @return int the location within the $body where the next non-whitespace char is located. + * @param string $body + * @param int $offset + * @return int */ public function tln_skipspace($body, $offset) { @@ -72,10 +80,10 @@ public function tln_skipspace($body, $offset) * really just a glorified "strpos", except it catches the failures * nicely. * - * @param string $body The string to look for needle in. - * @param int $offset Start looking from this position. - * @param string $needle The character/string to look for. - * @return int location of the next occurrence of the needle, or strlen($body) if needle wasn't found. + * @param string $body + * @param int $offset + * @param string $needle + * @return int */ public function tln_findnxstr($body, $offset, $needle) { @@ -92,14 +100,10 @@ public function tln_findnxstr($body, $offset, $needle) * This function takes a PCRE-style regexp and tries to match it * within the string. * - * @param string $body The string to look for needle in. - * @param int $offset Start looking from here. - * @param string $reg A PCRE-style regex to match. - * @return array|bool Returns a false if no matches found, or an array - * with the following members: - * - integer with the location of the match within $body - * - string with whatever content between offset and the match - * - string with whatever it is we matched + * @param string $body + * @param int $offset + * @param string $reg + * @return array|bool */ public function tln_findnxreg($body, $offset, $reg) { @@ -125,16 +129,9 @@ public function tln_findnxreg($body, $offset, $reg) /** * This function looks for the next tag. * - * @param string $body String where to look for the next tag. - * @param int $offset Start looking from here. - * @return array|bool false if no more tags exist in the body, or - * an array with the following members: - * - string with the name of the tag - * - array with attributes and their values - * - integer with tag type (1, 2, or 3) - * - integer where the tag starts (starting "<") - * - integer where the tag ends (ending ">") - * first three members will be false, if the tag is invalid. + * @param string $body + * @param int $offset + * @return array|bool */ public function tln_getnxtag($body, $offset) { @@ -243,14 +240,14 @@ public function tln_getnxtag($body, $offset) return $retary; } - //intentional fall-through + // Intentional fall-through. case '>': return [$tagname, false, $tagtype, $lt, $pos]; break; default: /** - * Check if it's whitespace + * Check if it's whitespace. */ if (! preg_match('/\s/', $match)) { /** @@ -357,7 +354,7 @@ public function tln_getnxtag($body, $offset) return $retary; } - //intentional fall-through + // Intentional fall-through. case '>': $attary[$attname] = '"yes"'; @@ -461,10 +458,10 @@ public function tln_getnxtag($body, $offset) /** * Translates entities into literal values so they can be checked. * - * @param string $attvalue the by-ref value to check. - * @param string $regex the regular expression to check against. - * @param bool $hex whether the entites are hexadecimal. - * @return bool True or False depending on whether there were matches. + * @param string $attvalue + * @param string $regex + * @param bool $hex + * @return bool */ public function tln_deent(&$attvalue, $regex, $hex = false) { @@ -496,8 +493,8 @@ public function tln_deent(&$attvalue, $regex, $hex = false) * and returns them translated into 8-bit strings so we can run * checks on them. * - * @param string $attvalue A string to run entity check against. - * @return Void, modifies a reference value. + * @param string $attvalue + * @return void */ public function tln_defang(&$attvalue) { @@ -525,8 +522,8 @@ public function tln_defang(&$attvalue) * makers of the browser with 95% market value decided that it'd * be funny to make "java[tab]script" be just as good as "javascript". * - * @param string $attvalue The attribute value before extraneous spaces removed. - * @return Void, modifies a reference value. + * @param string $attvalue + * @return void */ public function tln_unspace(&$attvalue) { @@ -542,11 +539,11 @@ public function tln_unspace(&$attvalue) /** * This function runs various checks against the attributes. * - * @param string $tagname String with the name of the tag. - * @param array $attary Array with all tag attributes. - * @param array $rm_attnames See description for tln_sanitize - * @param array $bad_attvals See description for tln_sanitize - * @param array $add_attr_to_tag See description for tln_sanitize + * @param string $tagname + * @param array $attary + * @param array $rm_attnames + * @param array $bad_attvals + * @param array $add_attr_to_tag * @param string $trans_image_path * @param bool $block_external_images * @return array with modified attributes. @@ -645,6 +642,11 @@ public function tln_fixatts( return $attary; } + /** + * Fix url. + * + * @return void + */ public function tln_fixurl($attname, &$attvalue, $trans_image_path, $block_external_images) { $sQuote = '"'; @@ -662,7 +664,7 @@ public function tln_fixurl($attname, &$attvalue, $trans_image_path, $block_exter * Replace empty src tags with the blank image. src is only used * for frames, images, and image inputs. Doing a replace should * not affect them working as should be, however it will stop - * IE from being kicked off when src for img tags are not set + * IE from being kicked off when src for img tags are not set. */ if ($attvalue == '') { $attvalue = $sQuote.$trans_image_path.$sQuote; @@ -718,11 +720,15 @@ public function tln_fixurl($attname, &$attvalue, $trans_image_path, $block_exter } } + /** + * Fix style. + * + * @return void + */ public function tln_fixstyle($body, $pos, $trans_image_path, $block_external_images) { $me = 'tln_fixstyle'; - // workaround for in between comments $iCurrentPos = $pos; $content = ''; @@ -862,6 +868,11 @@ public function tln_fixstyle($body, $pos, $trans_image_path, $block_external_ima return [$content, $newpos]; } + /** + * Body to div. + * + * @return void + */ public function tln_body2div($attary, $trans_image_path) { $me = 'tln_body2div'; @@ -910,17 +921,19 @@ public function tln_body2div($attary, $trans_image_path) } /** - * @param string $body The HTML you wish to filter - * @param array $tag_list see description above - * @param array $rm_tags_with_content see description above - * @param array $self_closing_tags see description above - * @param bool $force_tag_closing see description above - * @param array $rm_attnames see description above - * @param array $bad_attvals see description above - * @param array $add_attr_to_tag see description above + * Sanitize. + * + * @param string $body + * @param array $tag_list + * @param array $rm_tags_with_content + * @param array $self_closing_tags + * @param bool $force_tag_closing + * @param array $rm_attnames + * @param array $bad_attvals + * @param array $add_attr_to_tag * @param string $trans_image_path * @param bool $block_external_images - * @return string Sanitized html safe to show on your pages. + * @return string */ public function tln_sanitize( $body, @@ -966,7 +979,7 @@ public function tln_sanitize( $free_content = substr($body, $curpos, $lt - $curpos); /** - * Take care of