Skip to content

Commit

Permalink
Merge pull request #12 from jslirola/bugfix
Browse files Browse the repository at this point in the history
Check undefined index
  • Loading branch information
jslirola committed Apr 4, 2021
2 parents e74a1ed + ace5016 commit d847863
Showing 1 changed file with 37 additions and 33 deletions.
70 changes: 37 additions & 33 deletions src/HideContentInPosts.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,50 @@ class HideContentInPosts extends FormatContent
{
public function __invoke($serializer, $model, $attributes)
{
$newHTML = $attributes['contentHtml'];
if (isset($attributes["contentHtml"])) {

if (!$serializer->getActor()->isGuest())
return $attributes;
$newHTML = $attributes['contentHtml'];

$s_php = $this->settings->get('jslirola.login2seeplus.php', false);
$s_post = (int)$this->settings->get('jslirola.login2seeplus.post', 100);
$s_link = $this->settings->get('jslirola.login2seeplus.link', false);
$s_code = $this->settings->get('jslirola.login2seeplus.code', false);
if (!$serializer->getActor()->isGuest())
return $attributes;

// 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);
}
$s_php = $this->settings->get('jslirola.login2seeplus.php', false);
$s_post = (int)$this->settings->get('jslirola.login2seeplus.post', 100);
$s_link = $this->settings->get('jslirola.login2seeplus.link', false);
$s_code = $this->settings->get('jslirola.login2seeplus.code', false);

// 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);
// 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);
}

// 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);
}
// 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);

// 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>';
// 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;
$attributes['contentHtml'] = $newHTML;

}

return $attributes;
}
Expand Down

0 comments on commit d847863

Please sign in to comment.