From e7db57427a3ed17da7a14a3dfa20438712ddcb43 Mon Sep 17 00:00:00 2001 From: Danny Date: Sun, 28 Aug 2016 15:12:34 -0400 Subject: [PATCH 1/8] Added ability to add HTML links to twitter handles Added processTwitterHandles to Linkify Interface and linkifyTwitter function to add HTML links to @Twitter Handles --- src/Misd/Linkify/Linkify.php | 49 +++++++++++++++++++++++---- src/Misd/Linkify/LinkifyInterface.php | 12 +++++++ 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/src/Misd/Linkify/Linkify.php b/src/Misd/Linkify/Linkify.php index 0e3c9e6..e055c38 100644 --- a/src/Misd/Linkify/Linkify.php +++ b/src/Misd/Linkify/Linkify.php @@ -13,6 +13,8 @@ /** * Converts URLs and/or email addresses into HTML links. + * + * @author Chris Wilkinson */ class Linkify implements LinkifyInterface { @@ -38,7 +40,7 @@ public function __construct(array $options = array()) */ public function process($text, array $options = array()) { - return $this->linkify($text, true, true, $options); + return $this->linkify($text, true, true, true, $options); } /** @@ -46,7 +48,7 @@ public function process($text, array $options = array()) */ public function processUrls($text, array $options = array()) { - return $this->linkify($text, true, false, $options); + return $this->linkify($text, true, false, false, $options); } /** @@ -54,9 +56,13 @@ public function processUrls($text, array $options = array()) */ public function processEmails($text, array $options = array()) { - return $this->linkify($text, false, true, $options); - } + return $this->linkify($text, false, true, false, $options); + } + public function processTwitterHandles($text, array $options = array()) + { + return $this->linkify($text, false, false, true, $options); + } /** * Add links to text. * @@ -67,9 +73,9 @@ public function processEmails($text, array $options = array()) * * @return string Linkified text. */ - protected function linkify($text, $urls = true, $emails = true, array $options = array()) + protected function linkify($text, $urls = true, $emails = true, $twitter = true, array $options = array()) { - if (false === $urls && false === $emails) { + if (false === $urls && false === $emails && false === $twitter) { // nothing to do... return $text; } @@ -105,6 +111,9 @@ protected function linkify($text, $urls = true, $emails = true, array $options = if (true === $emails) { $chunks[$i] = $this->linkifyEmails($chunks[$i], $options); } + if (true === $twitter) { + $chunks[$i] = $this->linkifyTwitter($chunks[$i], $options); + } } } else { // odd numbers are tags // Only process this tag if there are no unclosed $ignoreTags @@ -213,4 +222,32 @@ protected function linkifyEmails($text, $options = array('attr' => '')) return preg_replace_callback($pattern, $callback, $text); } + + /** + * Add HTML links to Twitter Handles in plain text. + * + * @param string $text Text to linkify. + * @param array $options Options, 'attr' key being the attributes to add to the links, with a preceding space. + * + * @return string Linkified text. + */ + + protected function linkifyTwitter($text, $options = array('attr' => '')) + { + $pattern = '/@([\w]+)([[^\s])/i'; + + $callback = function ($match) use ($options) { + if (isset($options['callback'])) { + $cb = $options['callback']($match[0], $match[0], true); + if (!is_null($cb)) { + return $cb; + } + } + + return ''. $match[0] .''; + }; + + return preg_replace_callback($pattern, $callback, $text); + } + } diff --git a/src/Misd/Linkify/LinkifyInterface.php b/src/Misd/Linkify/LinkifyInterface.php index 7b589ef..6fb8bda 100644 --- a/src/Misd/Linkify/LinkifyInterface.php +++ b/src/Misd/Linkify/LinkifyInterface.php @@ -13,6 +13,8 @@ /** * Converts URLs and/or email addresses into HTML links. + * + * @author Chris Wilkinson */ interface LinkifyInterface { @@ -45,4 +47,14 @@ public function processUrls($text, array $options = array()); * @return string Processed text. */ public function processEmails($text, array $options = array()); + + /** + * Add HTML links to @Twitter Handles + * + * @param string $text Text to process. + * @param array $options Options. + * + * @return string Processed text. + */ + public function processTwitterHandles($text, array $options = array()); } From 72396ac77eec301e1fd362db8519ae0bdeed70c1 Mon Sep 17 00:00:00 2001 From: Danny Date: Sun, 28 Aug 2016 20:47:59 -0400 Subject: [PATCH 2/8] Fixed @handler regex fixed the regex for linkifytwitter --- src/Misd/Linkify/Linkify.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Misd/Linkify/Linkify.php b/src/Misd/Linkify/Linkify.php index e055c38..b045bf8 100644 --- a/src/Misd/Linkify/Linkify.php +++ b/src/Misd/Linkify/Linkify.php @@ -234,7 +234,7 @@ protected function linkifyEmails($text, $options = array('attr' => '')) protected function linkifyTwitter($text, $options = array('attr' => '')) { - $pattern = '/@([\w]+)([[^\s])/i'; + $pattern = '/\B@[^\B]([^.\s]+)/igm'; $callback = function ($match) use ($options) { if (isset($options['callback'])) { From 08424e6f09a52f2a8ba336b0cd0bae55f3124673 Mon Sep 17 00:00:00 2001 From: Danny Date: Sun, 28 Aug 2016 21:18:17 -0400 Subject: [PATCH 3/8] Fixed Twitter Regex Fixed Twitter regex --- src/Misd/Linkify/Linkify.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Misd/Linkify/Linkify.php b/src/Misd/Linkify/Linkify.php index b045bf8..7b7ec18 100644 --- a/src/Misd/Linkify/Linkify.php +++ b/src/Misd/Linkify/Linkify.php @@ -234,7 +234,7 @@ protected function linkifyEmails($text, $options = array('attr' => '')) protected function linkifyTwitter($text, $options = array('attr' => '')) { - $pattern = '/\B@[^\B]([^.\s]+)/igm'; + $pattern = '/\B@[^\B]([^.\s]+)/i'; $callback = function ($match) use ($options) { if (isset($options['callback'])) { From 1c20b7f991f76571438ba3fef53fb7202abb8e72 Mon Sep 17 00:00:00 2001 From: Danny Date: Tue, 28 Feb 2017 16:21:29 -0500 Subject: [PATCH 4/8] Added PMS @ Code --- .phpintel/052b22ff0e04838a4cab006c50e58961 | Bin 0 -> 3111 bytes .phpintel/0c23ba91e4716b6f699f904ac8e649cc | Bin 0 -> 504 bytes .phpintel/index | Bin 0 -> 212 bytes src/Misd/Linkify/Linkify.php | 12 +++++++----- 4 files changed, 7 insertions(+), 5 deletions(-) create mode 100644 .phpintel/052b22ff0e04838a4cab006c50e58961 create mode 100644 .phpintel/0c23ba91e4716b6f699f904ac8e649cc create mode 100644 .phpintel/index diff --git a/.phpintel/052b22ff0e04838a4cab006c50e58961 b/.phpintel/052b22ff0e04838a4cab006c50e58961 new file mode 100644 index 0000000000000000000000000000000000000000..0989a66725576d2287bc863ddd78d3b37e404fba GIT binary patch literal 3111 zcmd^>`&S!96o5ksq=Zsv5wZ9hHA+Ov*7vJg+ES$oR%=$*N5skQBr~$v?A@7=#)_@4 z|GRf56Ed4XO#Sr!C0KM6!R4e;H*0>6;;BA8F%6e6y1DG6^B`G z3zs>rWQlYd&|x(x6q8P;({Xx##XPDLc+xE-OtllNOA_zW-dS$>Ys@$-D1FYpUq9>eu^F}u9 zuOi`!AzaghuOZ>OO?X)oZVVARql8z+5x#C}ZwTEal<>xBDc`gx-_n$CBjr0b<-3~l zy&=l?M=3uTNBJRA&JF5#t4RfNUOg@6M;7PDn)4cRZrYsJHRp{X&YPp0TjMxyA?MP7 zv(ga?M|PV=LC7S0!k19$K3gHWk z-6`t^E3sZlz8plq!suO-kLrQI*E-9}P?oMW&)?|&&hCZZj!W4yEpGNa_ztC9oXBi8 z*MoqhVM$brq|2kA!68G+oymqvc zW!Lt~G+3*z2@Qe-$CHgbrnf-+2(wL+JH3;nPjd7jy`7Pm1bQHX1({?W_?|D@YJV{E z{iAM!Dz?E-b{p*3Ykx+WbVysx(&itdEf}Ybp|+y#RMyyQQsr}~qq+G}bK8~Ooq@iz zxI{!G4k`Zp|74y}>25!kYpfH z*vh{N8|v`K%$>@*Ya4e5+Fb|T-Lu_wZFj$-yZb}#ezV*i9^>x!aqb@2?jD}TojE^< nIY1sWcYkEv{b}6&rQQ9_3+}Y}=klM?s^dAkh~M^k%QhYXoPK;A literal 0 HcmV?d00001 diff --git a/.phpintel/0c23ba91e4716b6f699f904ac8e649cc b/.phpintel/0c23ba91e4716b6f699f904ac8e649cc new file mode 100644 index 0000000000000000000000000000000000000000..798ef523fced4cce8664abf56956ae4318a32c73 GIT binary patch literal 504 zcmZ9JzfQw25XMuQwh$r5z1DiRxs3376vzVTdRqa^EreJNW2-ZhC>pD zdbzXp`@Zi^{yupJ?+ZE)%;#o@;I3U3d?-{K6)RhUAND=Z%koXEBIvO`T5es}XPqY) zFhApV52xYEF_fV+NOw@k4Js><7DYkpF5731vC;>%Eh(Cat`rKoY#y5WqOCMr9?6-b z;f(d7m?J_Ej-2^11LrJINfygQYKw5eJQyD&%Bb1)IyfnLe>ahD%b)y L5^Nn?VyPYgKo&_A literal 0 HcmV?d00001 diff --git a/src/Misd/Linkify/Linkify.php b/src/Misd/Linkify/Linkify.php index 7b7ec18..e5d834b 100644 --- a/src/Misd/Linkify/Linkify.php +++ b/src/Misd/Linkify/Linkify.php @@ -40,7 +40,7 @@ public function __construct(array $options = array()) */ public function process($text, array $options = array()) { - return $this->linkify($text, true, true, true, $options); + return $this->linkify($text, true, false, true, $options); } /** @@ -183,7 +183,7 @@ protected function linkifyUrls($text, $options = array('attr' => '')) } } - return '' . $caption . ''; + return '' . $caption . ''; }; return preg_replace_callback($pattern, $callback, $text); @@ -217,7 +217,7 @@ protected function linkifyEmails($text, $options = array('attr' => '')) } } - return '' . $match[0] . ''; + return '' . $match[0] . ''; }; return preg_replace_callback($pattern, $callback, $text); @@ -234,7 +234,9 @@ protected function linkifyEmails($text, $options = array('attr' => '')) protected function linkifyTwitter($text, $options = array('attr' => '')) { - $pattern = '/\B@[^\B]([^.\s]+)/i'; + $pattern = '/\B@[^\B]([^.\s]+)/'; + //$pattern = '/@([\w]+)([[^\s])/i'; + ///$pattern = '/@([\w]+)([^\s]+)/i'; $callback = function ($match) use ($options) { if (isset($options['callback'])) { @@ -244,7 +246,7 @@ protected function linkifyTwitter($text, $options = array('attr' => '')) } } - return ''. $match[0] .''; + return ''. $match[0] .''; }; return preg_replace_callback($pattern, $callback, $text); From be1db9f26258e36d7c6fa516a4ddea9f4c61ef99 Mon Sep 17 00:00:00 2001 From: Danny Date: Sun, 19 Mar 2017 17:21:40 -0400 Subject: [PATCH 5/8] Changed @URL to Match PlugMatch.com --- src/Misd/Linkify/Linkify.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Misd/Linkify/Linkify.php b/src/Misd/Linkify/Linkify.php index e5d834b..d313fea 100644 --- a/src/Misd/Linkify/Linkify.php +++ b/src/Misd/Linkify/Linkify.php @@ -246,7 +246,7 @@ protected function linkifyTwitter($text, $options = array('attr' => '')) } } - return ''. $match[0] .''; + return ''. $match[0] .''; }; return preg_replace_callback($pattern, $callback, $text); From 8f3ddbf90681f90b9672874aee86510a12481ec2 Mon Sep 17 00:00:00 2001 From: Danny Date: Sun, 19 Mar 2017 17:53:14 -0400 Subject: [PATCH 6/8] Changed @URL to Match PlugMatch.com --- src/Misd/Linkify/Linkify.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Misd/Linkify/Linkify.php b/src/Misd/Linkify/Linkify.php index d313fea..66f9f88 100644 --- a/src/Misd/Linkify/Linkify.php +++ b/src/Misd/Linkify/Linkify.php @@ -246,7 +246,7 @@ protected function linkifyTwitter($text, $options = array('attr' => '')) } } - return ''. $match[0] .''; + return ''. $match[0] .''; }; return preg_replace_callback($pattern, $callback, $text); From fed3bae99145a8b81e399c5a4ca23cfbd036c77c Mon Sep 17 00:00:00 2001 From: Danny Date: Tue, 6 Jun 2017 13:47:50 -0400 Subject: [PATCH 7/8] changed linkify menation regex --- .DS_Store | Bin 0 -> 6148 bytes src/.DS_Store | Bin 0 -> 6148 bytes src/Misd/.DS_Store | Bin 0 -> 6148 bytes src/Misd/Linkify/Linkify.php | 2 +- 4 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 .DS_Store create mode 100644 src/.DS_Store create mode 100644 src/Misd/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..51c476f825dad8c0a568a10a0e3eed7ea465ca18 GIT binary patch literal 6148 zcmeHK&2G~`5T0#PY6BHMAhkzdkT^tDQho|TNN$>_MB+~b!2wWf$5vzHcq7{(KnTi( zcL3giN8t&05FP-&{Q(jOt`MOeY4)34&+K?UYj?dw#G0e9LF5pT1r=C5jpjEZo(o-) zH9cYjnVjR0+H{-l(IM?Dd7A;lfMHX57b6A|xQsk#n-P2an=teB_)z z;A!EmKYbjhAs;vSC=GKt&wan>BUUCla<(Uv-7D8>?r!7ywB}Cs_UbkF@};ZO zsby_lXx!`^4_>{VyqUiJfPx_m+qRT*8h^k?7`nU{-7HObdV&$*y^aqM3DPMq(IYU*hNZw3zX~G8)#z!Q zDZ~>9Q=vc=%Jdb3sc?+D+RxKCQ>em;>B|SxnVG(!Fqs|myV9MQr_i*90mHx|0~OVE z#QER;^ZkD@$n*>YhJpWz0ak5wTTPUt&(@{l#98Y?kD)?@-%OzlL8FgjX^5kE8!83Q YTwwq`jWdN9ftViwNrPz&1Amo)?{$r;y#N3J literal 0 HcmV?d00001 diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..e91803b83103656afa82a040713c0838a1e16969 GIT binary patch literal 6148 zcmeHK%}T>S5Z-O0CWzRBV2`;79(ri&PZbeDt%n{2A)*JBHZjEpVzxA?MPnqdp>O09 z_&7TI)1X#wB2s2x_M6PkY?yDuZiWy-ncN`7WKEJqwz>nf;^_3Qi+T8qt zZWy|;q+i;7Hnw9Y9z{)OcrKoNujeZJgs~vE9rx7ljXR~40~W@PANGbH!Y|JJ&|~8! z8--pZ);V_KKIDoQbxP$Vsc-F6%zAA%t(ZxpQLUJp8{28B>#J+E{dV`}?ml@)AD`r2 zQ20=VEGwMAGZ=Y+xArg$Sa=P-N&F-Z5g9-RkbxOsKpk!R;tbS+B_IRH!0$4^&j%Bf zqopvDD2@&oL<<0@fm;aJ;@2P0S5T32orij>spvS!k9(ri~t0F?EdJsGa6+NhEVyg|tthA}6)=FMO-^eHM zaddWeTh!`NQJI06Z!$Zxn|uko82}LFR<#I_0{{nAV=9a06Vc;Zha_bqBZz|L2;dw# z+o3x1!=Y>r{6+@!yUV~11Q5X`+QIu%K91mmAzcO4ns5C*rNV*l`TIeweUh8nP*Lm!QLXVN z{pcWws;XU9t*F|hd3L?HjcV_e!i z*J5JOl!LI%hp;OP+o1?r9p{&n4#G9amKk6M-ZP+kKa`w4|F^#G|0#(LGr$b|PX '')) protected function linkifyTwitter($text, $options = array('attr' => '')) { - $pattern = '/\B@[^\B]([^.\s]+)/'; + $pattern = '/\B@[^]([^.\s]+)/'; //$pattern = '/@([\w]+)([[^\s])/i'; ///$pattern = '/@([\w]+)([^\s]+)/i'; From 8328fc8f5a482bbf0981678a11fd82e1b521f7d6 Mon Sep 17 00:00:00 2001 From: Danny Date: Tue, 6 Jun 2017 16:02:54 -0400 Subject: [PATCH 8/8] regex change --- src/Misd/Linkify/Linkify.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Misd/Linkify/Linkify.php b/src/Misd/Linkify/Linkify.php index d6ae4ff..b197b11 100644 --- a/src/Misd/Linkify/Linkify.php +++ b/src/Misd/Linkify/Linkify.php @@ -234,7 +234,7 @@ protected function linkifyEmails($text, $options = array('attr' => '')) protected function linkifyTwitter($text, $options = array('attr' => '')) { - $pattern = '/\B@[^]([^.\s]+)/'; + $pattern = '/\B@[^\b]([^.\s]+)/'; //$pattern = '/@([\w]+)([[^\s])/i'; ///$pattern = '/@([\w]+)([^\s]+)/i';