Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Forum Passwords
- * Moderator control panel plugin: Forum password tool
- * Last Updated: October 23rd, 2011
- *
- * @author Tomato
- * @copyright Tomato (c) 2011
- * @version 1.1.0 (10100)
- *
- */
- if ( ! defined( 'IN_IPB' ) )
- {
- print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded all the relevant files.";
- exit();
- }
- class plugin_forumpass_forumpassword
- {
- /**
- * Registry Object Shortcuts
- *
- * @var $registry
- * @var $DB
- * @var $settings
- * @var $request
- * @var $lang
- * @var $member
- * @var $memberData
- * @var $cache
- * @var $caches
- */
- protected $registry;
- protected $DB;
- protected $settings;
- protected $request;
- protected $lang;
- protected $member;
- protected $memberData;
- protected $cache;
- protected $caches;
- /**
- * Main function executed automatically by the controller
- *
- * @param object $registry Registry object
- * @return @e void
- */
- public function __construct( ipsRegistry $registry )
- {
- //-----------------------------------------
- // Make shortcuts
- //-----------------------------------------
- $this->registry = $registry;
- $this->DB = $this->registry->DB();
- $this->settings =& $this->registry->fetchSettings();
- $this->request =& $this->registry->fetchRequest();
- $this->member = $this->registry->member();
- $this->memberData =& $this->registry->member()->fetchMemberData();
- $this->cache = $this->registry->cache();
- $this->caches =& $this->registry->cache()->fetchCaches();
- $this->lang = $this->registry->class_localization;
- $this->registry->getClass('class_localization')->loadLanguageFile( array( 'public_modcp'), 'forumpass' );
- }
- /**
- * Returns the primary tab key for the navigation bar
- *
- * @return @e string
- */
- public function getPrimaryTab()
- {
- return 'forumpassword';
- }
- /**
- * Returns the secondary tab key for the navigation bar
- *
- * @return @e string
- */
- public function getSecondaryTab()
- {
- return 'forumpassword';
- }
- /**
- * Determine if we can view tab
- *
- * @param array $permissions Moderator permissions
- * @return @e bool
- */
- public function canView()
- {
- if( $this->memberData['mgroup_others'] )
- {
- $mgroup_others_query = ' OR group_id IN ( '. IPSText::cleanPermString( $this->memberData['mgroup_others'] ) .' )';
- }
- /* Check Permissions */
- $this->DB->build( array( 'select' => '*', 'from' => 'forumpass_moderators', 'where' => 'can_view_pass = 1 AND member_id= '. $this->memberData['member_id'] .' OR group_id = '. $this->memberData['member_group_id'] .''. $mgroup_others_query, 'limit' => array(0,1) ) );
- $this->DB->execute();
- if ( $mod = $this->DB->fetch() )
- {
- return true;
- }
- return false;
- }
- /**
- * Execute plugin
- *
- * @param array $permissions Moderator permissions
- * @return @e string
- */
- public function executePlugin( $permissions )
- {
- //-----------------------------------------
- // Check permissions
- //-----------------------------------------
- if( !$this->canView( $permissions ) )
- {
- return '';
- }
- //-----------------------------------------
- // Doing something else?
- //-----------------------------------------
- switch( $this->request['_do'] )
- {
- case 'edit':
- return $this->_edit();
- break;
- case 'save':
- return $this->_save();
- break;
- }
- $perpage = 15;
- $st = ( $this->request['st'] > 0 ) ? intval( $this->request['st'] ) : 0;
- $can_view = 0;
- $can_edit = 0;
- $mods_edit_string = '';
- $mods_view_string = '';
- if( $this->memberData['mgroup_others'] )
- {
- $mgroup_others_query = ' OR group_id IN ( '. IPSText::cleanPermString( $this->memberData['mgroup_others'] ) .' )';
- }
- $this->DB->build( array( 'select' => '*', 'from' => 'forumpass_moderators', 'where' => 'member_id= '. $this->memberData['member_id'] .' OR group_id = '. $this->memberData['member_group_id'] .''. $mgroup_others_query ) );
- $this->DB->execute();
- while ( $mod = $this->DB->fetch() )
- {
- if( $mod['can_edit_pass'] AND $mod['can_view_pass'] )
- {
- $can_edit = 1;
- $mod['forum_id'] = substr( $mod['forum_id'], 1 );
- $mods_edit_string .= $mod['forum_id'];
- }
- if( $mod['can_view_pass'] )
- {
- $can_view = 1;
- $mod['forum_id'] = substr( $mod['forum_id'], 1 );
- $mods_view_string .= $mod['forum_id'];
- }
- }
- $mods_edit_array = explode( ',', $mods_edit_string );
- $mods_view_array = explode( ',', $mods_view_string );
- $mods_array = array_merge( IPSLib::cleanIntArray($mods_edit_array), IPSLib::cleanIntArray($mods_view_array) );
- $mods_array = array_unique( $mods_array );
- $forums_view_string = implode( ',', IPSLib::cleanIntArray($mods_array) );
- $forums_view_string = ( $forums_view_string != '' ) ? $forums_view_string : 0;
- $total = $this->DB->buildAndFetch( array( 'select' => 'count(*) as count', 'from' => 'forums', 'where' => 'password != "" AND id IN ( '.$forums_view_string.' )' ) );
- /* Build a list of the forums with passwords */
- $this->DB->build( array( 'select' => 'f.*,m.members_seo_name,m.member_id,m.members_display_name,m.member_group_id',
- 'from' => array( 'forums' => 'f'),
- 'where' => 'password != "" AND id IN ( '.$forums_view_string.' )',
- 'add_join' => array(
- 0 => array ( 'from' => array( 'members' => 'm' ),
- 'where' => 'f.last_password_change_mid=m.member_id' ) ),
- 'order' => 'f.name ASC',
- 'limit' => array( $st, $perpage ) ) );
- $this->DB->execute();
- while ( $forum = $this->DB->fetch() )
- {
- if ( $forum['member_id'] > 0 )
- {
- $forum['members_display_name'] = IPSMember::makeNameFormatted( $forum['members_display_name'], $forum['member_group_id'] );
- $forum['member_formatted'] = IPSMember::makeProfileLink( $forum['members_display_name'], $forum['member_id'], $forum['members_seo_name'] );
- }
- $forum['last_password_change'] = $this->registry->getClass( 'class_localization')->getDate( $forum['last_password_change'], $format='LONG', $relative='true' );
- if ( in_array( $forum['id'], $mods_edit_array ) )
- {
- $forum['edit'] = 1;
- }
- $forums[] = $forum;
- }
- /* Generate our pages */
- $pages = $this->registry->output->generatePagination( array( 'totalItems' => $total['count'],
- 'itemsPerPage' => $perpage,
- 'currentStartValue' => $st,
- 'baseUrl' => "app=core&module=modcp&fromapp=forumpass&tab=forumpass",
- ) );
- return $this->registry->getClass('output')->getTemplate('forumpass')->modForumPass($forums,$pages);
- }
- /**
- * Edit password screen
- *
- * @return string HTML
- */
- protected function _edit()
- {
- $fid = ( $this->request['fid'] > 0 ) ? intval( $this->request['fid'] ) : 0;
- $fromforum = intval( $this->request['fromf'] ) ? 1 : 0;
- /* Check ID */
- if( ! $fid )
- {
- $this->registry->getClass('output')->showError( $this->lang->words['forumpass_nofid'] );
- }
- /* Check Permissions */
- $this->DB->build( array( 'select' => '*', 'from' => 'forumpass_moderators', 'where' => 'can_edit_pass = 1 AND can_view_pass = 1 AND forum_id LIKE "%,'.$fid.',%" AND member_id= '. $this->memberData['member_id'] .' OR group_id = '. $this->memberData['member_group_id'] .''. $mgroup_others_query ) );
- $this->DB->execute();
- if ( ! $mod = $this->DB->fetch() )
- {
- $this->registry->getClass('output')->showError( $this->lang->words['forumpass_noedit'] );
- }
- /* Load Forum */
- $forum = $this->DB->buildAndFetch( array( 'select' => '*', 'from' => 'forums', 'where' => 'id=' . $fid ) );
- if( ! $forum['id'] )
- {
- $this->registry->getClass('output')->showError( $this->lang->words['forumpass_noforum'] );
- }
- if ( $forum['last_password_change_mid'] > 0 )
- {
- $last_editor = IPSMember::load( $forum['last_password_change_mid'] );
- $forum['members_display_name'] = IPSMember::makeNameFormatted( $last_editor['members_display_name'], $last_editor['member_group_id'] );
- $forum['member_formatted'] = IPSMember::makeProfileLink( $forum['members_display_name'], $last_editor['member_id'], $last_editor['members_seo_name'] );
- }
- $forum['last_password_change'] = $this->registry->getClass( 'class_localization')->getDate( $forum['last_password_change'], $format='LONG', $relative='true' );
- $forum['redir'] = $fromforum;
- return $this->registry->getClass('output')->getTemplate('forumpass')->modForumPassForm( $forum );
- }
- /**
- * Save our password
- *
- * @return void Outputs to screen
- */
- protected function _save()
- {
- $fid = ( $this->request['fid'] > 0 ) ? intval( $this->request['fid'] ) : 0;
- $password = $this->request['pass'];
- $time = time();
- $redir = intval( $this->request['redir'] ) ? 1 : 0;
- /* Check ID */
- if( ! $fid )
- {
- $this->registry->getClass('output')->showError( $this->lang->words['forumpass_nofid'] );
- }
- /* Check Permissions */
- $this->DB->build( array( 'select' => '*', 'from' => 'forumpass_moderators', 'where' => 'can_edit_pass = 1 AND can_view_pass = 1 AND forum_id LIKE "%,'.$fid.',%" AND member_id= '. $this->memberData['member_id'] .' OR group_id = '. $this->memberData['member_group_id'] .''. $mgroup_others_query ) );
- $this->DB->execute();
- if ( ! $mod = $this->DB->fetch() )
- {
- $this->registry->getClass('output')->showError( $this->lang->words['forumpass_noedit'] );
- }
- /* Load Forum */
- $forum = $this->DB->buildAndFetch( array( 'select' => '*', 'from' => 'forums', 'where' => 'id=' . $fid ) );
- if( ! $forum['id'] )
- {
- $this->registry->getClass('output')->showError( $this->lang->words['forumpass_noforum'] );
- }
- if( trim( $password ) == '' || ! $password )
- {
- $this->registry->getClass('output')->showError( $this->lang->words['forumpass_nopass'] );
- }
- $password = substr( $password, 0, 32 );
- /* Update our forum */
- $this->DB->update( 'forums', array( 'password' => $password, 'last_password_change' => $time, 'last_password_change_mid' => $this->memberData['member_id'] ), 'id='.$fid );
- $password = IPSText::parseCleanValue( $password );
- $this->DB->insert( 'moderator_logs', array(
- 'forum_id' => intval( $fid ),
- 'member_id' => $this->memberData['member_id'],
- 'member_name' => $this->memberData['members_display_name'],
- 'ip_address' => $this->member->ip_address,
- 'http_referer' => htmlspecialchars( getenv('HTTP_REFERER') ),
- 'ctime' => time(),
- 'action' => sprintf( $this->lang->words['forumpass_changepass'], $forum['name'], $password),
- 'query_string' => htmlspecialchars( getenv('QUERY_STRING') ),
- ) );
- //$this->registry->output->silentRedirect( $this->settings['base_url']."app=core&module=modcp&fromapp=forumpass&tab=forumpassword&edited=1" );
- if ( $redir )
- {
- $this->registry->output->redirectScreen( $this->lang->words['forumpass_passchanged'], $this->settings['base_url']."showforum={$fid}", $forum['name_seo'], 'showforum' );
- }
- else
- {
- $this->registry->output->redirectScreen( $this->lang->words['forumpass_passchanged'], $this->settings['base_url']."app=core&module=modcp&fromapp=forumpass&tab=forumpassword" );
- }
- }
- }
- ?>
Add Comment
Please, Sign In to add comment