Skip to content

Instantly share code, notes, and snippets.

@Sama34

Sama34/ougc_disablequotemedia.php Secret

Last active Aug 15, 2020
Embed
What would you like to do?
OUGC Disable Quotes Media
<?php
/***************************************************************************
*
* OUGC Disable Quotes Media plugin (/inc/plugins/ougc_disablequotemedia.php)
* Author: Omar Gonzalez
* Copyright: © 2020 Omar Gonzalez
*
* Website: https://ougc.network
*
* Convert images and videos in quotes to links.
*
***************************************************************************
****************************************************************************
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
// Die if IN_MYBB is not defined, for security reasons.
defined('IN_MYBB') or die('This file cannot be accessed directly.');
// Run our hook.
if(!defined('IN_ADMINCP'))
{
$plugins->add_hook('parse_message_me_mycode','ougc_disablequotemedia_parser');
}
define('OUGC_DISABLEQUOTEMEDIA_PATTER', "#\[quote\](.*?)\[\/quote\](\r\n?|\n?)#si");
define('OUGC_DISABLEQUOTEMEDIA_PATTER_COMPLEX', "#\[quote=([\"']|&quot;|)(.*?)(?:\\1)(.*?)(?:[\"']|&quot;)?\](.*?)\[/quote\](\r\n?|\n?)#si");
// Plugin API
function ougc_disablequotemedia_info()
{
return array(
'name' => 'OUGC Disable Quotes Media',
'description' => 'Convert images and videos in quotes to links.',
'website' => 'https://ougc.network',
'author' => 'Omar G.',
'authorsite' => 'https://ougc.network',
'version' => '1.8.1',
'versioncode' => 1801,
'compatibility' => '18*',
'codename' => 'ougc_ougc_disablequotemedia'
);
}
// Hook: parse_message_me_mycode
function ougc_disablequotemedia_parser(&$message)
{
global $parser, $post, $lang;
if(!(
$parser instanceof postParser ||
empty($parser->options['allow_mycode'] ||
empty($post['pid']))) ||
(
empty($parser->options['allow_imgcode']) &&
empty($parser->options['allow_videocode']
)
))
{
return;
}
do
{
$previous_message = $message;
$message = preg_replace_callback(OUGC_DISABLEQUOTEMEDIA_PATTER, 'ougc_disablequotemedia_simple', $message, -1, $count);
$message = preg_replace_callback(OUGC_DISABLEQUOTEMEDIA_PATTER_COMPLEX, 'ougc_disablequotemedia_callback', $message, -1, $count_callback);
if(!$message)
{
$message = $previous_message;
break;
}
} while($count || $count_callback);
}
function ougc_disablequotemedia_simple($matches)
{
if(empty($matches) || empty($matches[0]))
{
return $matches[0];
}
global $lang;
$replace = "<blockquote class=\"mycode_quote\"><cite>$lang->quote</cite>$1</blockquote>\n";
$message = preg_replace(OUGC_DISABLEQUOTEMEDIA_PATTER, $replace, $matches[0]);
ougc_disablequotemedia_helper($message);
return $message;
}
function ougc_disablequotemedia_callback($matches)
{
global $parser;
if(empty($matches) || empty($matches[0]))
{
return $matches[0];
}
$message = $parser->mycode_parse_post_quotes_callback1($matches);
ougc_disablequotemedia_helper($message);
return $message;
}
function ougc_disablequotemedia_helper(&$message)
{
global $parser;
if(!empty($parser->options['allow_imgcode']))
{
$message = preg_replace_callback("#\[img\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#is", array($parser, 'mycode_parse_img_disabled_callback1'), $message);
$message = preg_replace_callback("#\[img=([1-9][0-9]*)x([1-9][0-9]*)\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#is", array($parser, 'mycode_parse_img_disabled_callback2'), $message);
$message = preg_replace_callback("#\[img align=(left|right)\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#is", array($parser, 'mycode_parse_img_disabled_callback3'), $message);
$message = preg_replace_callback("#\[img=([1-9][0-9]*)x([1-9][0-9]*) align=(left|right)\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#is", array($parser, 'mycode_parse_img_disabled_callback4'), $message);
}
if(!empty($parser->options['allow_videocode']))
{
$message = preg_replace_callback("#\[video=(.*?)\](.*?)\[/video\]#i", array($parser, 'mycode_parse_video_disabled_callback'), $message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment