<?php if (!defined('VB_ENTRY')) die('Access denied.'); class vB_DataManager_Prefix extends vB_DataManager { var $validfields = array( 'prefixid' => array(vB_Cleaner::TYPE_STR, vB_DataManager_Constants::REQ_YES, vB_DataManager_Constants::VF_METHOD), 'prefixsetid' => array(vB_Cleaner::TYPE_STR, vB_DataManager_Constants::REQ_YES), 'displayorder' => array(vB_Cleaner::TYPE_UINT, vB_DataManager_Constants::REQ_YES), 'options' => array(vB_Cleaner::TYPE_UINT, vB_DataManager_Constants::REQ_NO), ); var $table = 'vBForum:prefix'; var $prefix = array(); var $info = array( 'title_plain' => null, 'title_rich' => null ); var $keyField = 'prefixid'; function verify_prefixid(&$prefixid) { if ($prefixid === '') { $this->error('please_complete_required_fields'); return false; } if (!preg_match('#^[a-z0-9_]+$#i', $prefixid) OR $prefixid === '0') { $this->error('invalid_string_id_alphanumeric'); return false; } if(vB::getDbAssertor()->getRow('vBForum:prefix', [vB_dB_Query::COLUMNS_KEY => 'prefixid', 'prefixid' => $prefixid])) { $this->error('there_is_already_prefix_named_x', $prefixid); return false; } return true; } function pre_save($doquery = true) { if ($this->presave_called !== null) { return $this->presave_called; } if ((!$this->condition OR $this->info['title_plain'] !== null) AND strval($this->info['title_plain']) === '') { $this->error('please_complete_required_fields'); $this->presave_called = false; return false; } if ((!$this->condition OR $this->info['title_rich'] !== null) AND strval($this->info['title_rich']) === '') { $this->error('please_complete_required_fields'); $this->presave_called = false; return false; } $return_value = true; $this->presave_called = $return_value; return $return_value; } function post_save_each($doquery = true) { $db = vB::getDBAssertor()->getDBConnection(); $phraseLib = vB_Library::instance('phrase'); $haverich = (strval($this->info['title_rich']) !== ''); if (strval($this->info['title_plain']) !== '') { $phraseid = 'prefix_' . $this->fetch_field('prefixid') . '_title_plain'; $phraseLib->saveCustom('vbulletin', 'global', $phraseid, $this->info['title_plain'], $haverich); } if ($haverich) { $phraseid = 'prefix_' . $this->fetch_field('prefixid') . '_title_rich'; $phraseLib->saveCustom('vbulletin', 'global', $phraseid, $this->info['title_rich']); } if (!empty($this->existing['prefixsetid']) AND $this->existing['prefixsetid'] != $this->fetch_field('prefixsetid')) { $old_set = $this->existing['prefixsetid']; $new_set = $this->fetch_field('prefixsetid'); $allowed_channels = [ $old_set => [], $new_set => [] ]; $allowed_channels_sql = $db->query_read("
				SELECT prefixsetid, nodeid
				FROM " . TABLE_PREFIX . "channelprefixset
				WHERE prefixsetid IN (
					'" . $db->escape_string($old_set) . "',
					'" . $db->escape_string($new_set) . "'
				)
			"); while ($allowed_channel = $db->fetch_array($allowed_channels_sql)) { $allowed_channels["$allowed_channel[prefixsetid]"][] = $allowed_channel['nodeid']; } $removed_channels = array_diff($allowed_channels["$old_set"], $allowed_channels["$new_set"]); if ($removed_channels) { require_once(DIR . '/includes/adminfunctions_prefix.php'); remove_prefixes_forum($this->fetch_field('prefixid'), $removed_channels); } } vB_Library::instance('prefix')->buildDatastore(); } protected function pre_delete($doquery = true) { throw new vB_Exception_Api('invalid_action_specified_gcpglobal'); } } 