-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from jslirola/beta15
Update for Flarum beta 15
- Loading branch information
Showing
6 changed files
with
187 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of jslirola/flarum-ext-login2seeplus. | ||
* | ||
* Copyright (c) 2020 | ||
* Original Extension by WiseClock | ||
* Updated by jslirola | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace JSLirola\Login2SeePlus; | ||
|
||
use Flarum\Api\Serializer\PostSerializer; | ||
use Flarum\Settings\SettingsRepositoryInterface; | ||
use Symfony\Component\Translation\TranslatorInterface; | ||
|
||
class FormatContent | ||
{ | ||
public function __construct() | ||
{ | ||
$this->settings = app(SettingsRepositoryInterface::class); | ||
$this->translator = app(TranslatorInterface::class); | ||
} | ||
|
||
protected function truncate_html($string, $length) | ||
{ | ||
$string = trim($string); | ||
$i = 0; | ||
$tags = array(); | ||
|
||
preg_match_all('/<[^>]+>([^<]*)/', $string, $tagMatches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER); | ||
foreach($tagMatches as $tagMatch) | ||
{ | ||
if ($tagMatch[0][1] - $i >= $length) | ||
break; | ||
$tag = mb_substr(strtok($tagMatch[0][0], " \t\n\r\0\x0B>"), 1); | ||
if ($tag[0] != '/') | ||
$tags[] = $tag; | ||
elseif (end($tags) == mb_substr($tag, 1)) | ||
array_pop($tags); | ||
$i += $tagMatch[1][1] - $tagMatch[0][1]; | ||
} | ||
|
||
return mb_substr($string, 0, $length = min(mb_strlen($string), $length + $i)) . (count($tags = array_reverse($tags)) ? '</' . implode('></', $tags) . '>' : ''); | ||
} | ||
|
||
protected function get_link($trans) | ||
{ | ||
return '<a class="l2sp">' . $this->translator->trans($trans) . '</a>'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of jslirola/flarum-ext-login2seeplus. | ||
* | ||
* Copyright (c) 2020 | ||
* Original Extension by WiseClock | ||
* Updated by jslirola | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace JSLirola\Login2SeePlus; | ||
|
||
class HideContentInPostPreviews extends FormatContent | ||
{ | ||
public function __invoke($serializer, $model, $attributes) | ||
{ | ||
$newHTML = $attributes["contentHtml"]; | ||
|
||
if (!$serializer->getActor()->isGuest()) | ||
return $attributes; | ||
|
||
$s_summary_links = $this->settings->get('jslirola.login2seeplus.link', false); | ||
|
||
if (!is_null($newHTML) && $s_summary_links == 1) | ||
$newHtml = preg_replace('/(<a((?!PostMention).)*?>)[^<]*<\/a>/is', | ||
'[' . $this->get_link('jslirola-login2seeplus.forum.link') . ']', $newHtml); | ||
|
||
$attributes['contentHtml'] = $newHTML; | ||
|
||
return $attributes; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of jslirola/flarum-ext-login2seeplus. | ||
* | ||
* Copyright (c) 2020 | ||
* Original Extension by WiseClock | ||
* Updated by jslirola | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace JSLirola\Login2SeePlus; | ||
|
||
class HideContentInPosts extends FormatContent | ||
{ | ||
public function __invoke($serializer, $model, $attributes) | ||
{ | ||
$newHTML = $attributes['contentHtml']; | ||
|
||
if (!$serializer->getActor()->isGuest()) | ||
return $attributes; | ||
|
||
$s_php = $this->settings->get('jslirola.login2seeplus.php', false); | ||
if (!$s_php) | ||
return $attributes; | ||
|
||
$s_post = (int)$this->settings->get('jslirola.login2seeplus.post', 100); | ||
$s_link = $this->settings->get('jslirola.login2seeplus.link', false); | ||
$s_image = $this->settings->get('jslirola.login2seeplus.image', false); | ||
$s_code = $this->settings->get('jslirola.login2seeplus.code', false); | ||
|
||
// truncate | ||
if ($s_post != -1 && function_exists('mb_substr') && function_exists('mb_strlen')) { | ||
$newHTML = $this->truncate_html($newHTML, $s_post); | ||
$newHTML = preg_replace('/(<p>)([^<]*)<\/p>$/is', '$1$2...$3', $newHTML); | ||
} | ||
|
||
// links | ||
if ($s_link == 1) { | ||
$newHTML = preg_replace('/(<a((?!PostMention).)*?>)[^<]*<\/a>/is', $this->get_link('jslirola-login2seeplus.forum.link'), $newHTML); | ||
// $newHTML = preg_replace('/<GOOGLEDRIVE(.*?)>[^>]*<\/GOOGLEDRIVE>/is', $this->get_link('jslirola-login2seeplus.forum.link'), $newHTML); | ||
// $newHTML = preg_replace('/<GOOGLESHEETS(.*?)>[^>]*<\/GOOGLESHEETS>/is', $this->get_link('jslirola-login2seeplus.forum.link'), $newHTML); | ||
$newHTML = preg_replace('/<span data-s9e-mediaembed=(.*?)><span (.*?)><iframe(.*?)><\/iframe><\/span><\/span>/is', $this->get_link('jslirola-login2seeplus.forum.link'), $newHTML); | ||
$newHTML = preg_replace('/<iframe data-s9e-mediaembed=(.*?)><\/iframe>/is', $this->get_link('jslirola-login2seeplus.forum.link'), $newHTML); | ||
} elseif ($s_link == 2) // hide address | ||
$newHTML = preg_replace('/<a href=".*?"/is', '<a class="l2sp"', $newHTML); | ||
|
||
// images | ||
if ($s_image) | ||
$newHTML = preg_replace('/<img((.(?!class=))*)\/?>/is', '<div class="jslirolaLogin2seeplusImgPlaceholder">' . $this->get_link('jslirola-login2seeplus.forum.image') . '</div>', $newHTML); | ||
|
||
// code | ||
if ($s_code) { | ||
$newHTML = preg_replace('/<pre><code(.*?)>[^>]*<\/pre>/is', $this->get_link('jslirola-login2seeplus.forum.code'), $newHTML); | ||
$newHTML = preg_replace('/<code(.*?)>[^>]*<\/code>/is', $this->get_link('jslirola-login2seeplus.forum.code'), $newHTML); | ||
} | ||
|
||
// show alert | ||
if ($s_post != -1) | ||
$newHTML .= '<div class="jslirolaLogin2seeplusAlert">' . $this->translator->trans('jslirola-login2seeplus.forum.post', array( | ||
'{login}' => '<a class="jslirolaLogin2seeplusLogin">' . $this->translator->trans('core.forum.header.log_in_link') . '</a>', | ||
'{register}' => '<a class="jslirolaLogin2seeplusRegister">' . $this->translator->trans('core.forum.header.sign_up_link') . '</a>' | ||
)) . '</div>'; | ||
|
||
$attributes['contentHtml'] = $newHTML; | ||
|
||
return $attributes; | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.