Skip to content

Instantly share code, notes, and snippets.

@Sama34
Created January 28, 2015 02:49
Show Gist options
  • Save Sama34/08414a5259b547c5c755 to your computer and use it in GitHub Desktop.
Save Sama34/08414a5259b547c5c755 to your computer and use it in GitHub Desktop.
OUGC New Thread plugin
<?php
/***************************************************************************
*
* OUGC New Thread plugin (/inc/plugins/ougc_newthread.php)
* Author: Omar Gonzalez
* Copyright: © 2014 Omar Gonzalez
*
* Website: http://omarg.me
*
* Allows your users to create multiple copies of the same thread into multiple forums.
*
***************************************************************************
****************************************************************************
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.');
// Add our hooks
if(!defined('IN_ADMINCP'))
{
$plugins->add_hook('newthread_end', 'ougc_newthread');
$plugins->add_hook('newthread_do_newthread_end', 'ougc_newthread_do');
}
// Plugin API
function ougc_newthread_info()
{
return array(
'name' => 'OUGC New Thread',
'description' => 'Allows your users to create multiple copies of the same thread into multiple forums.',
'website' => '',
'author' => 'Omar G.',
'authorsite' => 'http://omarg.me',
'version' => '1.0',
'versioncode' => 1000,
'compatibility' => '18*'
);
}
// _activate function
function ougc_newthread_activate()
{
global $cache;
// Insert version code into cache
$plugins = $cache->read('ougc_plugins');
if(!$plugins)
{
$plugins = array();
}
$info = ougc_newthread_info();
$plugins['newthread'] = $info['versioncode'];
$cache->update('ougc_plugins', $plugins);
}
// _is_installed function
function ougc_newthread_is_installed()
{
global $cache;
$plugins = $cache->read('ougc_plugins');
return isset($plugins['newthread']);
}
// _uninstall function
function ougc_newthread_uninstall()
{
global $cache;
// Remove version code from cache
$plugins = (array)$cache->read('ougc_plugins');
if(isset($plugins['newthread']))
{
unset($plugins['newthread']);
}
if($plugins)
{
$cache->update('ougc_plugins', $plugins);
}
else
{
$cache->delete('ougc_plugins');
}
}
// Load language file
function ougc_newthread()
{
global $lang, $mybb, $ougc_newthread, $templates;
$ougc_newthread = '';
#isset($lang->ougc_newthread) or $lang->load('ougc_newthread');
$lang->ougc_newthread = 'Additional Forums:';
$forum_select = build_forum_jump(0, null, true, '', false, true, $mybb->usergroup, 'ougc_newthread[]" multiple="multiple');
$templates->cache['ougc_newthread'] = '<tr>
<td class="trow2" width="20%" valign="top"><strong>{$lang->ougc_newthread}</strong></td>
<td class="trow2">{$forum_select}</td>
</tr>';
eval('$ougc_newthread = "'.$templates->get('ougc_newthread').'";');
}
function ougc_newthread_do()
{
global $posthandler, $mybb, $fid, $forum_cache, $new_thread;
if($new_thread['savedraft'])
{
return;
}
// poll issues pending
$forum_cache or cache_forums();
$bu_fid = $posthandler->data['fid'];
foreach($mybb->get_input('ougc_newthread', 2) as $fid)
{
if($forum_cache[$fid]['type'] == 'f' && $forum_cache[$fid]['fid'] != $bu_fid)
{
$posthandler->data['fid'] = (int)$fid;
$posthandler->data['subject'] = '[Copy] '.$posthandler->data['subject'];
if($posthandler->validate_thread())
{
$thread = $posthandler->insert_thread();
mark_thread_read($thread['tid'], $posthandler->data['fid']);
}
}
}
$posthandler->data['fid'] = $bu_fid;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment