Ejemplo n.º 1
0
 /**
  * Save the group [add/edit]
  *
  * @param 	string		'add' or 'edit'
  * @return	@e void		[Outputs to screen]
  */
 protected function _saveGroup($type = 'edit')
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $group_id = intval($this->request['id']);
     $oldGroup = $this->caches['group_cache'][$group_id];
     //-----------------------------------------
     // Auth check...
     //-----------------------------------------
     ipsRegistry::getClass('adminFunctions')->checkSecurityKey($this->request['secure_key']);
     //-----------------------------------------
     // Check...
     //-----------------------------------------
     if (!$this->request['g_title']) {
         $this->registry->output->showError($this->lang->words['g_title_error'], 1127);
     }
     if (intval($this->request['g_max_mass_pm']) > 500) {
         $this->registry->output->showError($this->lang->words['g_mass_pm_too_large'], 1127);
     }
     #MSSQL needs a check on this
     if (IPSText::mbstrlen($this->request['g_title']) > 32) {
         $this->registry->output->showError($this->lang->words['g_title_error'], 1127);
     }
     if ($type == 'edit') {
         if (!$group_id) {
             $this->registry->output->showError($this->lang->words['g_whichgroup'], 1128);
         }
         //-----------------------------------------
         // Check restrictions.
         //-----------------------------------------
         if ($this->caches['group_cache'][$group_id]['g_access_cp']) {
             $this->registry->getClass('class_permissions')->checkPermissionAutoMsg('groups_edit_admin');
         }
     }
     //-----------------------------------------
     // Check restrictions.
     //-----------------------------------------
     if (($type == 'add' or !$this->caches['group_cache'][$group_id]['g_access_cp']) and $this->request['g_access_cp']) {
         $this->registry->getClass('class_permissions')->checkPermissionAutoMsg('groups_add_admin');
     }
     //-----------------------------------------
     // Sort out the perm mask id things
     //-----------------------------------------
     $new_perm_set_id = 0;
     if ($this->request['g_new_perm_set']) {
         $this->DB->insert('forum_perms', array('perm_name' => $this->request['g_new_perm_set']));
         $new_perm_set_id = $this->DB->getInsertId();
     } else {
         if (!is_array($this->request['permid'])) {
             $this->registry->output->showError($this->lang->words['g_oneperm'], 1129);
         }
     }
     $this->lang->loadLanguageFile(array('admin_permissions'), 'members');
     //-----------------------------------------
     // Some other generic fields
     //-----------------------------------------
     $promotion_a = '-1';
     // id
     $promotion_b = '-1';
     // posts
     if ($this->request['g_promotion_id'] and $this->request['g_promotion_id'] > 0) {
         $promotion_a = $this->request['g_promotion_id'];
         $promotion_b = $this->request['g_promotion_posts'];
     }
     if ($this->request['g_attach_per_post'] and $this->request['g_attach_max'] > 0) {
         if ($this->request['g_attach_per_post'] > $this->request['g_attach_max']) {
             $this->registry->output->global_message = $this->lang->words['g_pergreater'];
             $this->_groupForm('edit');
             return;
         }
     }
     $this->request['p_max'] = str_replace(":", "", $this->request['p_max']);
     $this->request['p_width'] = str_replace(":", "", $this->request['p_width']);
     $this->request['p_height'] = str_replace(":", "", $this->request['p_height']);
     $this->request['g_attach_max'] = intval($this->request['g_attach_max']);
     $this->request['g_attach_per_post'] = intval($this->request['g_attach_per_post']);
     $this->request['p_max'] = intval($this->request['p_max']);
     $sig_limits = array($this->request['use_signatures'], $this->request['max_images'], $this->request['max_dims_x'], $this->request['max_dims_y'], $this->request['max_urls'], $this->request['max_lines']);
     //-----------------------------------------
     // Set the db array
     //-----------------------------------------
     $db_string = array('g_view_board' => intval($this->request['g_view_board']), 'g_mem_info' => intval($this->request['g_mem_info']), 'g_can_add_friends' => intval($this->request['g_can_add_friends']), 'g_use_search' => intval($this->request['g_use_search']), 'g_edit_profile' => intval($this->request['g_edit_profile']), 'g_use_pm' => intval($this->request['g_use_pm']), 'g_pm_perday' => intval($this->request['g_pm_perday']), 'g_is_supmod' => intval($this->request['g_is_supmod']), 'g_access_cp' => intval($this->request['g_access_cp']), 'g_title' => trim($this->request['g_title']), 'g_access_offline' => intval($this->request['g_access_offline']), 'g_dname_changes' => intval($this->request['g_dname_changes']), 'g_dname_date' => intval($this->request['g_dname_date']), 'prefix' => trim(IPSText::safeslashes($_POST['prefix'])), 'suffix' => trim(IPSText::safeslashes($_POST['suffix'])), 'g_hide_from_list' => intval($this->request['g_hide_from_list']), 'g_perm_id' => $new_perm_set_id ? $new_perm_set_id : implode(",", $this->request['permid']), 'g_icon' => trim(IPSText::safeslashes($_POST['g_icon'])), 'g_attach_max' => $this->request['g_attach_max'] == '' ? 0 : intval($this->request['g_attach_max']), 'g_max_messages' => intval($this->request['g_max_messages']), 'g_max_mass_pm' => intval($this->request['g_max_mass_pm']), 'g_pm_flood_mins' => intval($this->request['g_pm_flood_mins']), 'g_search_flood' => intval($this->request['g_search_flood']), 'g_promotion' => $promotion_a . '&' . $promotion_b, 'g_photo_max_vars' => $this->request['p_max'] . ':' . $this->request['p_width'] . ':' . $this->request['p_height'], 'g_dohtml' => intval($this->request['g_dohtml']), 'g_bypass_badwords' => intval($this->request['g_bypass_badwords']), 'g_can_msg_attach' => intval($this->request['g_can_msg_attach']), 'g_attach_per_post' => intval($this->request['g_attach_per_post']), 'g_rep_max_positive' => intval($this->request['g_rep_max_positive']), 'g_rep_max_negative' => intval($this->request['g_rep_max_negative']), 'g_signature_limits' => implode(':', $sig_limits), 'g_hide_online_list' => intval($this->request['g_hide_online_list']), 'g_displayname_unit' => intval($this->request['g_displayname_unit']), 'g_sig_unit' => intval($this->request['g_sig_unit']), 'g_max_notifications' => intval($this->request['g_max_notifications']), 'g_max_bgimg_upload' => intval($this->request['g_max_bgimg_upload']), 'g_bitoptions' => IPSBWOPtions::freeze($this->request, 'groups', 'global'));
     $this->DB->setDataType('g_title', 'string');
     //-----------------------------------------
     // Ok? Load interface and child classes
     //-----------------------------------------
     IPSLib::loadInterface('admin/group_form.php');
     $_groupPlugins = array();
     foreach (IPSLib::getEnabledApplications() as $app_dir => $app_data) {
         if (is_file(IPSLib::getAppDir($app_dir) . '/extensions/admin/group_form.php')) {
             $_class = IPSLib::loadLibrary(IPSLib::getAppDir($app_dir) . '/extensions/admin/group_form.php', 'admin_group_form__' . $app_dir, $app_dir);
             $_groupPlugins[$_class] = new $_class($this->registry);
             $remote = $_groupPlugins[$_class]->getForSave();
             $db_string = array_merge($db_string, $remote);
         }
     }
     //-----------------------------------------
     // Editing...do an update
     //-----------------------------------------
     if ($type == 'edit') {
         $this->DB->update('groups', $db_string, 'g_id=' . $group_id);
         //-----------------------------------------
         // Update moderator table too
         //-----------------------------------------
         $this->DB->update('moderators', array('group_name' => $db_string['g_title']), 'group_id=' . $group_id);
         $this->cache->rebuildCache('moderators', 'forums');
         ipsRegistry::getClass('adminFunctions')->saveAdminLog(sprintf($this->lang->words['g_editedlog'], $db_string['g_title']));
         $this->registry->output->global_message = $this->lang->words['g_edited'];
     } else {
         $this->DB->insert('groups', $db_string);
         $group_id = $this->DB->getInsertId();
         ipsRegistry::getClass('adminFunctions')->saveAdminLog(sprintf($this->lang->words['g_addedlog'], $db_string['g_title']));
         $this->registry->output->global_message = $this->lang->words['g_added'];
     }
     $this->rebuildGroupCache();
     //-----------------------------------------
     // Post save callbacks
     //-----------------------------------------
     if (count($_groupPlugins)) {
         foreach ($_groupPlugins as $_className => $_object) {
             if (method_exists($_object, 'postSave')) {
                 $_object->postSave($group_id);
             }
         }
     }
     if ($new_perm_set_id) {
         $from = '';
         if ($type == 'edit' and $db_string['g_access_cp'] and !$oldGroup['g_access_cp'] or $type == 'add' and $db_string['g_access_cp']) {
             //-----------------------------------------
             // Do they already have restrictions?
             //-----------------------------------------
             $test = $this->DB->buildAndFetch(array('select' => 'row_id', 'from' => 'admin_permission_rows', 'where' => "row_id_type='group' AND row_id=" . $group_id));
             if (!$test['row_id']) {
                 $from = '&_from=group-' . $group_id;
             }
         }
         $this->registry->output->global_message = $this->lang->words['per_saved'];
         $this->registry->output->silentRedirectWithMessage($this->settings['base_url'] . 'module=groups&section=permissions&do=edit_set_form' . $from . '&id=' . $new_perm_set_id);
     } else {
         if ($type == 'edit' and $db_string['g_access_cp'] and !$oldGroup['g_access_cp'] or $type == 'add' and $db_string['g_access_cp']) {
             //-----------------------------------------
             // Do they already have restrictions?
             //-----------------------------------------
             $test = $this->DB->buildAndFetch(array('select' => 'row_id', 'from' => 'admin_permission_rows', 'where' => "row_id_type='group' AND row_id=" . $group_id));
             if (!$test['row_id']) {
                 $this->registry->output->html .= $this->html->groupAdminConfirm($group_id);
             }
         }
         $this->_mainScreen();
     }
 }
Ejemplo n.º 2
0
 /**
  * Edit a member [process]
  *
  * @return	@e void
  */
 protected function _memberDoEdit()
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $this->request['member_id'] = intval($this->request['member_id']);
     //-----------------------------------------
     // Send to form if this isn't a POST request
     //-----------------------------------------
     if ($this->request['request_method'] != 'post') {
         $this->_memberView();
         return;
     }
     //-----------------------------------------
     // Auth check...
     //-----------------------------------------
     ipsRegistry::getClass('adminFunctions')->checkSecurityKey($this->request['secure_key']);
     //-----------------------------------------
     // Load and config the std/rte editors
     //-----------------------------------------
     IPSText::getTextClass('editor')->from_acp = 1;
     //-----------------------------------------
     // Get member
     //-----------------------------------------
     $member = IPSMember::load($this->request['member_id'], 'all');
     //-----------------------------------------
     // Allowed to edit administrators?
     //-----------------------------------------
     if ($member['member_id'] != $this->memberData['member_id'] and $member['g_access_cp'] and !$this->registry->getClass('class_permissions')->checkPermission('member_edit_admin')) {
         $this->registry->output->global_message = $this->lang->words['m_editadmin'];
         $this->_memberView();
         return;
     }
     //-----------------------------------------
     // Allowed to change an admin's groups?
     //-----------------------------------------
     if ($member['g_access_cp'] and !$this->registry->getClass('class_permissions')->checkPermission('member_move_admin1')) {
         $same = false;
         if ($this->request['member_group_id'] == $member['member_group_id']) {
             $member['mgroup_others'] = IPSText::cleanPermString($member['mgroup_others']);
             $omgroups = $member['mgroup_others'] ? explode(',', $member['mgroup_others']) : array();
             $groups = $this->request['mgroup_others'] ? $this->request['mgroup_others'] : array();
             if (!count(array_diff($omgroups, $groups)) and !count(array_diff($groups, $omgroups))) {
                 $same = true;
             }
         }
         if (!$same) {
             $this->registry->output->global_message = $this->lang->words['m_admindemote'];
             $this->_memberView();
             return;
         }
     }
     //-----------------------------------------
     // What about promoting to admin?
     //-----------------------------------------
     if (!$member['g_access_cp'] and !$this->registry->getClass('class_permissions')->checkPermission('member_move_admin2')) {
         $groups = $_POST['mgroup_others'] ? $_POST['mgroup_others'] : array();
         $groups[] = intval($this->request['member_group_id']);
         foreach ($groups as $group_id) {
             if ($this->caches['group_cache'][$group_id]['g_access_cp']) {
                 $this->registry->output->global_message = $this->lang->words['m_adminpromote'];
                 $this->_memberView();
                 return;
             }
         }
     }
     //-----------------------------------------
     // What about moving member in general?
     //-----------------------------------------
     if ($this->request['member_group_id'] != $member['member_group_id'] and !$this->registry->getClass('class_permissions')->checkPermission('member_move')) {
         $this->registry->output->global_message = $this->lang->words['m_movemembers'];
         $this->_memberView();
         return;
     }
     //-----------------------------------------
     // Restricted?
     //-----------------------------------------
     $restricted = (is_array($this->registry->getClass('class_permissions')->restrictions_row) and count($this->registry->getClass('class_permissions')->restrictions_row)) ? true : false;
     /* Load editor stuff */
     $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/editor/composite.php', 'classes_editor_composite');
     $_editor = new $classToLoad();
     /* Load parser */
     $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/text/parser.php', 'classes_text_parser');
     $parser = new $classToLoad();
     /* Get signature */
     $_editor->setAllowBbcode(true);
     $_editor->setAllowSmilies(false);
     $_editor->setIsHtml($this->request['bw_html_sig'] && $member['g_dohtml']);
     $_editor->setAllowHtml($member['g_dohtml']);
     $_editor->setBbcodeSection('signatures');
     $signature = $_editor->process($_POST['signature']);
     $cacheSignature = $parser->display($signature);
     /* About me editor */
     $_editor->setAllowBbcode(true);
     $_editor->setAllowSmilies(true);
     $_editor->setAllowHtml($member['g_dohtml']);
     $_editor->setBbcodeSection('aboutme');
     $aboutme = $_editor->process($_POST['aboutme']);
     //-----------------------------------------
     // Ok? Load interface and child classes
     //-----------------------------------------
     $additionalCore = array();
     $additionalExtended = array();
     $additionalMCache = array();
     IPSLib::loadInterface('admin/member_form.php');
     foreach (IPSLib::getEnabledApplications() as $app_dir => $app_data) {
         if (is_file(IPSLib::getAppDir($app_dir) . '/extensions/admin/member_form.php')) {
             $_class = IPSLib::loadLibrary(IPSLib::getAppDir($app_dir) . '/extensions/admin/member_form.php', 'admin_member_form__' . $app_dir, $app_dir);
             $_object = new $_class($this->registry);
             $remote = $_object->getForSave();
             $additionalCore = is_array($remote['core']) ? array_merge($remote['core'], $additionalCore) : $additionalCore;
             $additionalExtended = is_array($remote['extendedProfile']) ? array_merge($remote['extendedProfile'], $additionalExtended) : $additionalExtended;
             $additionalMCache = is_array($remote['member_cache']) ? array_merge($remote['member_cache'], $additionalMCache) : $additionalMCache;
         }
     }
     //-----------------------------------------
     // Fix custom title
     // @see	http://forums.invisionpower.com/index.php?app=tracker&showissue=17383
     //-----------------------------------------
     $memberTitle = $this->request['title'];
     $rankCache = ipsRegistry::cache()->getCache('ranks');
     if (is_array($rankCache) && count($rankCache)) {
         foreach ($rankCache as $k => $v) {
             if ($member['posts'] >= $v['POSTS']) {
                 /* If this is the title passed to us from the form, we didn't have a custom title */
                 if ($v['TITLE'] == $memberTitle) {
                     $memberTitle = '';
                 }
                 break;
             }
         }
     }
     //-----------------------------------------
     // Start array
     //-----------------------------------------
     $newMember = array('member_group_id' => intval($this->request['member_group_id']), 'title' => $memberTitle, 'time_offset' => floatval($this->request['time_offset']), 'members_auto_dst' => intval($this->request['dstCheck']), 'dst_in_use' => intval($this->request['dstOption']), 'language' => $this->request['language'], 'skin' => intval($this->request['skin']), 'allow_admin_mails' => intval($this->request['allow_admin_mails']), 'view_sigs' => intval($this->request['view_sigs']), 'posts' => intval($this->request['posts']), 'bday_day' => intval($this->request['bday_day']), 'bday_month' => intval($this->request['bday_month']), 'bday_year' => intval($this->request['bday_year']), 'warn_level' => intval($this->request['warn_level']), 'members_disable_pm' => intval($this->request['members_disable_pm']), 'mgroup_others' => $this->request['mgroup_others'] ? ',' . implode(",", $this->request['mgroup_others']) . ',' : '', 'members_bitoptions' => IPSBWOPtions::freeze($this->request, 'members', 'global'), 'member_uploader' => $this->request['member_uploader']);
     //-----------------------------------------
     // Notifications library
     //-----------------------------------------
     $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . '/sources/classes/member/notifications.php', 'notifications');
     $notifyLibrary = new $classToLoad($this->registry);
     $notifyLibrary->setMember($member);
     //-----------------------------------------
     // Show the form
     //-----------------------------------------
     $_basicOptions = array(array('email', $this->lang->words['notopt__email']), array('inline', $this->lang->words['notopt__inline']), array('mobile', $this->lang->words['notopt__mobile']));
     $_configOptions = $notifyLibrary->getNotificationData();
     $_notifyConfig = $notifyLibrary->getMemberNotificationConfig($newMember);
     $_defaultConfig = $notifyLibrary->getDefaultNotificationConfig();
     $_saveConfig = array();
     foreach ($_configOptions as $option) {
         $_saveConfig[$option['key']] = array();
         $_saveConfig[$option['key']]['selected'] = array();
         //-----------------------------------------
         // Loop through and mark what we selected.
         // Do not allow changing of stuff from disable_override
         //	and disabled, however
         //-----------------------------------------
         if (is_array($this->request['config_' . $option['key']]) and count($this->request['config_' . $option['key']])) {
             foreach ($this->request['config_' . $option['key']] as $_selected) {
                 if (!is_array($_defaultConfig[$option['key']]['disabled']) or !in_array($_selected, $_defaultConfig[$option['key']]['disabled'])) {
                     $_saveConfig[$option['key']]['selected'][] = $_selected;
                 }
             }
         }
         if ($_defaultConfig[$option['key']]['disable_override']) {
             $_saveConfig[$option['key']]['selected'] = $_defaultConfig[$option['key']]['selected'];
         }
     }
     //-----------------------------------------
     // Save
     //-----------------------------------------
     IPSMember::packMemberCache($member['member_id'], array_merge($additionalMCache, array('notifications' => $_saveConfig, 'show_notification_popup' => intval($this->request['show_notification_popup']))), $member['members_cache']);
     //-----------------------------------------
     // Topic preferences
     //-----------------------------------------
     $_trackChoice = '';
     if ($this->request['auto_track']) {
         if (in_array($this->request['auto_track_method'], array('none', 'immediate', 'offline', 'daily', 'weekly'))) {
             $_trackChoice = $this->request['auto_track_method'];
         }
     }
     $newMember['auto_track'] = $_trackChoice;
     //-----------------------------------------
     // Custom profile field stuff
     //-----------------------------------------
     $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/customfields/profileFields.php', 'customProfileFields');
     $fields = new $classToLoad();
     $fields->initData('edit');
     $fields->parseToSave($_POST);
     /* Check the website url field */
     $website_field = $fields->getFieldIDByKey('website');
     if ($website_field && $fields->out_fields['field_' . $website_field]) {
         if (stristr($fields->out_fields['field_' . $website_field], 'http://') === FALSE && stristr($fields->out_fields['field_' . $website_field], 'https://') === FALSE) {
             $fields->out_fields['field_' . $website_field] = 'http://' . $fields->out_fields['field_' . $website_field];
         }
     }
     //-----------------------------------------
     // Throw to the DB
     //-----------------------------------------
     IPSMember::save($this->request['member_id'], array('core' => array_merge($newMember, $additionalCore), 'extendedProfile' => array_merge(array('pp_about_me' => $aboutme, 'signature' => $signature, 'pp_reputation_points' => intval($this->request['pp_reputation_points']), 'pp_setting_count_visitors' => intval($this->request['pp_setting_count_visitors']), 'pp_setting_count_comments' => intval($this->request['pp_setting_count_comments']), 'pp_setting_count_friends' => intval($this->request['pp_setting_count_friends']), 'pp_setting_moderate_comments' => intval($this->request['pp_setting_moderate_comments']), 'pp_setting_moderate_friends' => intval($this->request['pp_setting_moderate_friends']), 'pp_customization' => $this->request['removeCustomization'] ? serialize(array()) : $member['pp_customization']), $additionalExtended), 'customFields' => count($fields->out_fields) ? $fields->out_fields : array()));
     if ($member['member_group_id'] != $newMember['member_group_id']) {
         IPSLib::runMemberSync('onGroupChange', $this->request['member_id'], $newMember['member_group_id'], $member['member_group_id']);
         //-----------------------------------------
         // Remove restrictions if member demoted
         // Commenting out as this may cause more problems than it's worth
         // e.g. if you had accidentally changed their group, you'd need to reconfigure all restrictions
         //-----------------------------------------
         /*if( !$this->caches['group_cache'][ $newMember['member_group_id'] ]['g_access_cp'] )
         		{
         			$this->DB->delete( 'admin_permission_rows', 'row_id=' . $member['member_id'] . " AND row_id_type='member'" );
         		}*/
         //-----------------------------------------
         // Restriction permissions stuff
         //-----------------------------------------
         $is_admin = 0;
         $groups = ipsRegistry::cache()->getCache('group_cache');
         if (is_array($this->request['mgroup_others']) and count($this->request['mgroup_others'])) {
             foreach ($this->request['mgroup_others'] as $omg) {
                 if ($groups[intval($omg)]['g_access_cp']) {
                     $is_admin = 1;
                     break;
                 }
             }
         }
         if ($groups[intval($this->request['member_group_id'])]['g_access_cp']) {
             $is_admin = 1;
         }
         if ($is_admin && $restricted) {
             //-------------------------------------------------
             // Copy restrictions if they do not have any yet...
             //-------------------------------------------------
             $check = $this->DB->buildAndFetch(array('select' => 'row_updated', 'from' => 'admin_permission_rows', 'where' => "row_id_type='member' AND row_id=" . $this->request['member_id']));
             if (!$check['row_updated']) {
                 $this->DB->replace('admin_permission_rows', array('row_id' => $this->request['member_id'], 'row_id_type' => 'member', 'row_perm_cache' => serialize($this->registry->getClass('class_permissions')->restrictions_row), 'row_updated' => time()), array('row_id', 'row_id_type'));
             }
         }
     }
     //-----------------------------------------
     // Moved from validating group?
     //-----------------------------------------
     if ($member['member_group_id'] == $this->settings['auth_group']) {
         if ($this->request['member_group_id'] != $this->settings['auth_group']) {
             //-----------------------------------------
             // Yes...
             //-----------------------------------------
             $this->DB->delete('validating', "member_id=" . $this->request['member_id']);
         }
     }
     /* Update cache */
     IPSContentCache::update($this->request['member_id'], 'sig', $cacheSignature);
     /* Rebuild birthday cache */
     $this->cache->rebuildCache('birthdays', 'calendar');
     //-----------------------------------------
     // Redirect
     //-----------------------------------------
     ipsRegistry::getClass('adminFunctions')->saveAdminLog(sprintf($this->lang->words['m_editedlog'], $member['members_display_name']));
     $this->registry->output->global_message = $this->lang->words['m_edited'];
     if ($is_admin) {
         if (!$restricted) {
             $member = IPSMember::load($member['member_id']);
             $this->_showAdminForm($member, array());
             $this->_memberView();
         } else {
             $this->registry->output->global_message = $this->lang->words['m_edited_restricted'];
             $this->registry->output->silentRedirectWithMessage($this->settings['base_url'] . $this->form_code . '&do=viewmember&member_id=' . $this->request['member_id']);
         }
     } else {
         $this->registry->output->silentRedirectWithMessage($this->settings['base_url'] . $this->form_code . '&do=viewmember&member_id=' . $this->request['member_id']);
     }
 }
Ejemplo n.º 3
0
 /**
  * Save the forum
  *
  * @param	string		$type		[new|edit]
  * @return	@e void
  */
 public function forumSave($type = 'new')
 {
     /* If this is not a redirect forum anymore empty the redirect url - #35126 */
     if ($this->request['forum_type'] != 'redirect') {
         $this->request['redirect_url'] = '';
     }
     //-----------------------------------------
     // Converting the type?
     //-----------------------------------------
     if ($this->request['convert']) {
         $this->forumForm($type, 1);
         return;
     }
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $this->request['name'] = trim($this->request['name']);
     $this->request['f'] = intval($this->request['f']);
     $this->request['parent_id'] = !empty($this->request['parent_id']) ? intval($this->request['parent_id']) : -1;
     $forum_cat_lang = intval($this->request['parent_id']) == -1 ? $this->lang->words['for_iscat_y'] : $this->lang->words['for_iscat_n'];
     //-----------------------------------------
     // Auth check...
     //-----------------------------------------
     $this->registry->adminFunctions->checkSecurityKey();
     //-----------------------------------------
     // Check
     //-----------------------------------------
     if ($this->request['name'] == "") {
         $this->registry->output->global_message = sprintf($this->lang->words['for_entertitle'], mb_strtolower($forum_cat_lang));
         $this->forumForm($type);
         return;
     }
     //-----------------------------------------
     // Are we trying to do something stupid
     // like running with scissors or moving
     // the parent of a forum into itself
     // spot?
     //-----------------------------------------
     if ($this->request['parent_id'] != $this->registry->getClass('class_forums')->forum_by_id[$this->request['f']]['parent_id']) {
         $ids = $this->registry->getClass('class_forums')->forumsGetChildren($this->request['f']);
         $ids[] = $this->request['f'];
         if (in_array($this->request['parent_id'], $ids)) {
             $this->registry->output->global_error = $this->lang->words['for_whymovethere'];
             $this->forumForm($type);
             return;
         }
     }
     //if( $this->request['parent_id'] < 1 )
     //{
     //	$this->request['sub_can_post'] = 1;
     //}
     //-----------------------------------------
     // Save array
     //-----------------------------------------
     $save = array('name' => IPSText::getTextClass('bbcode')->xssHtmlClean(nl2br(IPSText::stripslashes($_POST['name']))), 'name_seo' => IPSText::makeSeoTitle(strip_tags(IPSText::UNhtmlspecialchars($this->request['name']))), 'description' => IPSText::getTextClass('bbcode')->xssHtmlClean(nl2br(IPSText::stripslashes($_POST['description']))), 'use_ibc' => isset($this->request['use_ibc']) ? intval($this->request['use_ibc']) : 1, 'use_html' => intval($this->request['use_html']), 'password' => $this->request['password'], 'password_override' => is_array($this->request['password_override']) ? implode(",", $this->request['password_override']) : '', 'sort_key' => $this->request['sort_key'], 'sort_order' => $this->request['sort_order'], 'prune' => intval($this->request['prune']), 'topicfilter' => $this->request['topicfilter'], 'preview_posts' => intval($this->request['preview_posts']), 'allow_poll' => intval($this->request['allow_poll']), 'allow_pollbump' => intval($this->request['allow_pollbump']), 'forum_allow_rating' => intval($this->request['forum_allow_rating']), 'inc_postcount' => intval($this->request['inc_postcount']), 'parent_id' => intval($this->request['parent_id']), 'sub_can_post' => intval($this->request['sub_can_post']), 'redirect_on' => intval($this->request['redirect_on']), 'redirect_hits' => intval($this->request['redirect_hits']), 'redirect_url' => $this->request['redirect_url'], 'notify_modq_emails' => $this->request['notify_modq_emails'], 'permission_showtopic' => $this->request['parent_id'] == -1 ? 1 : intval($this->request['permission_showtopic']), 'min_posts_post' => intval($this->request['min_posts_post']), 'min_posts_view' => intval($this->request['min_posts_view']), 'can_view_others' => intval($this->request['can_view_others']), 'hide_last_info' => intval($this->request['hide_last_info']), 'disable_sharelinks' => intval($this->request['disable_sharelinks']), 'tag_predefined' => $this->request['tag_predefined'], 'forums_bitoptions' => IPSBWOPtions::freeze($this->request, 'forums', 'forums'), 'permission_custom_error' => nl2br(IPSText::stripslashes($_POST['permission_custom_error'])), 'ipseo_priority' => $this->request['ipseo_priority'], 'viglink' => intval($this->request['viglink']));
     /* Save data from application tabs */
     IPSLib::loadInterface('admin/forum_form.php');
     $_forumPlugins = array();
     foreach (IPSLib::getEnabledApplications() as $app_dir => $app_data) {
         if (is_file(IPSLib::getAppDir($app_dir) . '/extensions/admin/forum_form.php')) {
             $_class = IPSLib::loadLibrary(IPSLib::getAppDir($app_dir) . '/extensions/admin/forum_form.php', 'admin_forum_form__' . $app_dir, $app_dir);
             $_forumPlugins[$_class] = new $_class($this->registry);
             $remote = $_forumPlugins[$_class]->getForSave();
             $save = array_merge($save, $remote);
         }
     }
     //-----------------------------------------
     // ADD
     //-----------------------------------------
     if ($type == 'new') {
         $this->DB->build(array('select' => 'MAX(id) as top_forum', 'from' => 'forums'));
         $this->DB->execute();
         $row = $this->DB->fetch();
         if ($row['top_forum'] < 1) {
             $row['top_forum'] = 0;
         }
         $row['top_forum']++;
         /* Forum Information */
         //$save['id']               = $row['top_forum'];
         $save['position'] = $row['top_forum'];
         $save['topics'] = 0;
         $save['posts'] = 0;
         $save['last_post'] = 0;
         $save['last_poster_id'] = 0;
         $save['last_poster_name'] = "";
         /* Insert the record */
         $this->DB->insert('forums', $save);
         $forum_id = $this->DB->getInsertId();
         /* Permissions */
         $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/class_public_permissions.php', 'classPublicPermissions');
         $permissions = new $classToLoad(ipsRegistry::instance());
         $permissions->savePermMatrix($this->request['perms'], $forum_id, 'forum');
         if (!$save['can_view_others']) {
             $this->DB->update('permission_index', array('owner_only' => 1), "app='forums' AND perm_type='forum' AND perm_type_id={$forum_id}");
         }
         /* Done */
         $this->registry->output->global_message = $forum_cat_lang . $this->lang->words['for__created'];
         $this->registry->adminFunctions->saveAdminLog($forum_cat_lang . " '" . $this->request['name'] . "'" . mb_strtolower($this->lang->words['for__created']));
     } else {
         $forumData = $this->registry->class_forums->getForumById($this->request['f']);
         if ($this->request['parent_id'] == -1) {
             $save['can_view_others'] = 1;
             /* Permissions */
             //$classToLoad = IPSLib::loadLibrary( IPS_ROOT_PATH . 'sources/classes/class_public_permissions.php', 'classPublicPermissions' );
             //$permissions = new $classToLoad( ipsRegistry::instance() );
             //$permissions->savePermMatrix( $this->request['perms'], $this->request['f'], 'forum' );
             if (!$save['can_view_others']) {
                 $this->DB->update('permission_index', array('owner_only' => 1), "app='forums' AND perm_type='forum' AND perm_type_id={$this->request['f']}");
             } else {
                 $this->DB->update('permission_index', array('owner_only' => 0), "app='forums' AND perm_type='forum' AND perm_type_id={$this->request['f']}");
             }
         }
         $this->DB->update('forums', $save, "id=" . $this->request['f']);
         $forum_id = $this->request['f'];
         /* Tags */
         $this->registry->getClass('class_forums')->forumsInit();
         $this->registry->tags->updatePermssionsByParentId($this->request['f']);
         /* Did we enable/disable tagging? @todo find a better way to do this. Perhaps another field in tags? */
         if (isset($this->request['bw_disable_tagging'])) {
             if ($forumData['bw_disable_tagging'] != $this->request['bw_disable_tagging']) {
                 $toggle = $this->request['bw_disable_tagging'] ? 0 : 1;
                 $this->registry->tags->updateVisibilityByParentId($this->request['f'], $toggle);
                 if ($this->request['bw_disable_tagging'] == 0) {
                     /* We just restored all tags, so lets return hidden topics back to 0 */
                     $this->DB->build(array('select' => 'tid', 'from' => 'topics', 'where' => 'forum_id=' . $this->request['f'] . ' AND ' . $this->registry->class_forums->fetchTopicHiddenQuery(array('sdeleted', 'hidden', 'pdelete', 'oktoremove')), 'order' => 'last_post DESC', 'limit' => array(0, 500)));
                     $this->DB->execute();
                     $topics = array();
                     while ($row = $this->DB->fetch()) {
                         $topics[] = $row['tid'];
                     }
                     if (count($topics)) {
                         $this->registry->tags->updateVisibilityByMetaId($topics, 0);
                     }
                 }
             }
         }
         $this->registry->output->global_message = $forum_cat_lang . $this->lang->words['for__edited'];
         $this->registry->adminFunctions->saveAdminLog($forum_cat_lang . " '" . $this->request['name'] . "' " . mb_strtolower($this->lang->words['for__edited']));
     }
     $this->request['f'] = '';
     if ($save['parent_id'] > 0) {
         $this->request['f'] = $save['parent_id'];
     }
     //-----------------------------------------
     // Post save callbacks
     //-----------------------------------------
     if (count($_forumPlugins)) {
         foreach ($_forumPlugins as $_className => $_object) {
             if (method_exists($_object, 'postSave')) {
                 $_object->postSave($forum_id);
             }
         }
     }
     $this->registry->getClass('class_forums')->forumsInit();
     $this->showForums();
 }
Ejemplo n.º 4
0
 /**
  * Execute selected method
  *
  * @param	object		Registry object
  * @return	@e void
  */
 public function fixGroups()
 {
     $this->DB->build(array('select' => '*', 'from' => 'groups'));
     $o = $this->DB->execute();
     while ($row = $this->DB->fetch($o)) {
         $row['gbw_view_last_info'] = 1;
         $row['gbw_view_online_lists'] = 1;
         $row['gbw_hide_leaders_page'] = 0;
         $g_bitoptions = IPSBWOPtions::freeze($row, 'groups', 'global');
         $this->DB->update('groups', array('g_bitoptions' => $g_bitoptions), 'g_id=' . $row['g_id']);
     }
     $this->registry->output->addMessage("Groups updated");
     $this->request['workact'] = 'posts';
 }