/** * Check a list of nodes and see whether the user has voted them * * @param array $nodeIds A list of Nodes to be checked * @param int $userid User ID to be checked. If not there, currently logged-in user will be checked. * * @return int[] Node IDs that the user has voted. Keyed by nodeid. */ public function fetchNodeVotes(array $nodeIds, $userid = 0) { if (!$userid) { $userid = vB::getCurrentSession()->get('userid'); // TODO: implement guest votes? if ($userid == 0) { return $nodeIds; } } $nodeIds = array_diff($nodeIds, $this->nodevotescache, $this->notVoted); if ($nodeIds) { $nodes = $this->assertor->assertQuery('vBForum:getNodeVotes', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_STORED, 'userid' => $userid, 'nodeid' => $nodeIds)); foreach ($nodes as $node) { $this->nodevotescache[$node['nodeid']] = $node['nodeid']; $key = array_search($node['nodeid'], $nodeIds); if ($key !== false) { unset($nodeIds[$key]); } } } //If we have any nodeIds left, those are nodes for which this user has not voted. // Let's store that to prevent additional queries. if (!empty($nodeIds)) { $this->notVoted = array_merge($this->notVoted, $nodeIds); } return $this->nodevotescache; }
public function shutdown() { if (!empty($this->locked)) { foreach ($this->locked as $cacheid) { unset($this->recordsToSave[$cacheid]); } } if (!empty($this->recordsToSave)) { $this->assertor->assertQuery('saveDbCache', array('cache' => $this->recordsToSave)); } if (!empty($this->newEvents)) { foreach ($this->newEvents as $cacheid => $events) { if (!empty($this->recordsToSave[$cacheid]['events']) and is_array($this->recordsToSave[$cacheid]['events']) and is_array($events)) { $this->newEvents[$cacheid] = array_diff($this->newEvents[$cacheid], $this->recordsToSave[$cacheid]['events']); //now it's possible they are all overlap if (empty($this->newEvents[$cacheid])) { unset($this->newEvents[$cacheid]); } } } if (!empty($this->newEvents)) { $this->assertor->assertQuery('saveDbCacheEvents', array('events' => $this->newEvents)); } } $this->recordsToSave = array(); $this->newEvents = array(); $this->no_values = array(); $this->values_read = array(); }
/** * Verifies that the provided username is valid, and attempts to correct it if it is not valid * * @param string Username * * @return boolean Returns true if the username is valid, or has been corrected to be valid */ function verify_username(&$username) { // this is duplicated from the user manager // fix extra whitespace and invisible ascii stuff $username = trim(preg_replace('#[ \\r\\n\\t]+#si', ' ', strip_blank_ascii($username, ' '))); $username_raw = $username; $username = vB_String::cleanUserName($username); $username = str_replace(chr(0), '', $username); $username = trim($username); $length = vB_String::vbStrlen($username); if ($length < $this->registry->options['minuserlength']) { // name too short $this->error('usernametooshort', $this->registry->options['minuserlength']); return false; } else { if ($length > $this->registry->options['maxuserlength']) { // name too long $this->error('usernametoolong', $this->registry->options['maxuserlength']); return false; } else { if (preg_match('/(?<!&#[0-9]{3}|&#[0-9]{4}|&#[0-9]{5});/', $username)) { // name contains semicolons $this->error('username_contains_semi_colons'); return false; } else { if ($username != fetch_censored_text($username)) { // name contains censored words $this->error('censorfield'); return false; } else { $result = $this->assertor->assertQuery('verifyUsername', array('userid' => intval($this->existing['userid']), 'username' => vB_String::htmlSpecialCharsUni($username), 'username_raw' => vB_String::htmlSpecialCharsUni($username_raw))); if ($result->valid() and $result->current()) { // name is already in use $this->error('usernametaken', vB_String::htmlSpecialCharsUni($username), vB::getCurrentSession()->get('sessionurl')); return false; } else { if (!empty($this->registry->options['illegalusernames'])) { // check for illegal username $usernames = preg_split('/[ \\r\\n\\t]+/', $this->registry->options['illegalusernames'], -1, PREG_SPLIT_NO_EMPTY); foreach ($usernames as $val) { if (strpos(strtolower($username), strtolower($val)) !== false) { // wierd error to show, but hey... $this->error('usernametaken', vB_String::htmlSpecialCharsUni($username), vB::getCurrentSession()->get('sessionurl')); return false; } } } } } } } } // if we got here, everything is okay $username = vB_String::htmlSpecialCharsUni($username); return true; }
public function isForumModerator() { if (isset($this->isForumModerator)) { return $this->isForumModerator; } $moderator = $this->assertor->getField('vBForum:moderator', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_COUNT, 'userid' => $this->userid)); if (!empty($moderator)) { $this->isForumModerator = true; return true; } $this->isForumModerator = false; return false; }
/** * Fetch Human Verification Question Data * * @param $hash * @return string Question */ public function fetchHvQuestion($hash = '') { if (!$hash) { throw new vB_Exception_Api('invalid_hash'); } $hv = $this->assertor->getRow('humanverify', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'hash' => $hash)); $questionid = $hv['answer']; if (!$questionid) { throw new vB_Exception_Api('invalid_hash'); } $phrases = vB_Api::instanceInternal('phrase')->fetch(array('question' . $questionid)); return $phrases['question' . $questionid]; }
/** * Fetches the IDs of the dismissed notices so we do not display them for the user. * * @return array */ protected function fetchDismissedNotices() { static $dismissed_notices = null; if ($dismissed_notices === null) { $userinfo = vB::getCurrentSession()->fetch_userinfo(); $dismissed_notices = array(); if (!$userinfo['userid']) { return $dismissed_notices; } $noticeids = $this->assertor->getRows('vBForum:fetchdismissednotices', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_STORED, 'userid' => $userinfo['userid'])); foreach ($noticeids as $noticeid) { $dismissed_notices[] = $noticeid['noticeid']; } } return $dismissed_notices; }
/** * Create new cpsession for the user and insert it into database or fetch current existing one * * @param bool $renew Whether to renew cpsession hash (Create a new one and drop the old one) * * @throws vB_Exception * @return string The new cpsession hash * */ public function fetchCpsessionHash($renew = false) { if (!$this->created) { throw new vB_Exception_User('session_not_created'); } if ($this->cpsessionHash) { if (!$renew) { return $this->cpsessionHash; } else { // Drop the old cp session record $this->dBAssertor->delete('cpsession', array('hash' => $this->cpsessionHash)); } } $this->cpsessionHash = $this->fetch_sessionhash(); $this->dBAssertor->insert('cpsession', array('userid' => $this->vars['userid'], 'hash' => $this->cpsessionHash, 'dateline' => vB::getRequest()->getTimeNow())); return $this->cpsessionHash; }
public function process() { vB::$vbulletin->input->clean_array_gpc('p', array('userid' => TYPE_UINT, 'tab' => TYPE_NOHTML, 'mindateline' => TYPE_UNIXTIME, 'maxdateline' => TYPE_UNIXTIME, 'minscore' => TYPE_NUM, 'minid' => TYPE_STR, 'maxid' => TYPE_STR, 'pagenumber' => TYPE_UINT, 'perpage' => TYPE_UINT)); vB::$vbulletin->GPC['ajax'] = 1; vB_dB_Assertor::init(vB::$vbulletin->db, vB::$vbulletin->userinfo); vB_ProfileCustomize::getUserTheme(vB::$vbulletin->GPC['userid']); $userhastheme = vB_ProfileCustomize::getUserThemeType(vB::$vbulletin->GPC['userid']) == 1 ? 1 : 0; $showusercss = vB::$vbulletin->userinfo['options'] & vB::$vbulletin->bf_misc_useroptions['showusercss'] ? 1 : 0; if ($userhastheme and $showusercss) { define('AS_PROFILE', true); } $userinfo = verify_id('user', vB::$vbulletin->GPC['userid'], 1, 1); $this->fetchMemberStreamSql(vB::$vbulletin->GPC['tab'], $userinfo['userid']); $this->processExclusions(); $this->setPage(1, vB::$vbulletin->GPC['perpage']); $result = $this->fetchStream(); $this->processAjax($result); }
function do_delete_attachment() { $userinfo = vB_Api::instance('user')->fetchUserInfo(); if ($userinfo['userid'] < 1) { return json_error(ERR_NO_PERMISSION); } $cleaned = vB::getCleaner()->cleanArray($_REQUEST, array('attachmentid' => vB_Cleaner::TYPE_UINT)); if (empty($cleaned['attachmentid'])) { return json_error(ERR_NO_PERMISSION); } $fr_attach = vB_dB_Assertor::instance()->assertQuery('ForumRunner:getAttachmentMarkerById', array('id' => $cleaned['attachmentid'])); if (empty($fr_attach)) { return json_error(ERR_NO_PERMISSION); } $result = vB_Api::instance('content_attach')->deleteAttachment($fr_attach['attachmentid']); if (empty($result) || !empty($result['errors'])) { return json_error(ERR_NO_PERMISSION); } vB_dB_Assertor::instance()->assertQuery('ForumRunner:deleteAttachmentMarker', array('id' => $cleaned['attachmentid'])); return true; }
function fr_process_message_callback($matches) { if (count($matches) > 1) { $fr_attach = vB_dB_Assertor::instance()->getRow('ForumRunner:getAttachmentMarkerById', array('id' => $matches[1])); if (!empty($fr_attach)) { return '[IMG]' . fr_base_url() . 'filedata/fetch?id=' . $fr_attach['attachmentid'] . '[/IMG]'; } } return ''; }
/** * Saves a (new or existing) page * * @param array Page data * @param array Conditions - Must be specified if updating an existing record. * * @return int|mixed If it is a new page, the pageid will be returned */ public function save(array $data, array $conditions = array()) { $this->checkHasAdminPermission('canusesitebuilder'); $db = vB::getDbAssertor(); // We should unset 'pageid' from data // 'pageid' should go to conditions parameter. unset($data['pageid']); // Get page table structure $structure = vB_dB_Assertor::fetchTableStructure('page'); foreach ($data as $k => $v) { if (!in_array($k, $structure['structure'])) { unset($data[$k]); } } if (!empty($conditions)) { return $db->update('page', $data, $conditions); } else { return $db->insert('page', $data); } }
$template->register('themelist', $themelist); $template->register('canusetheme', $canusetheme); $template->register('cancustomize', $cancustomize); $template->register('is_superadmin', can_administer('cansetdefaultprofile') ? 1 : 0); $template->register('caneditfontfamily', $userinfo['permissions']['usercsspermissions'] & $vbulletin->bf_ugp_usercsspermissions['caneditfontfamily']); $template->register('caneditfontsize', $userinfo['permissions']['usercsspermissions'] & $vbulletin->bf_ugp_usercsspermissions['caneditfontsize']); $template->register('caneditbgimage', $userinfo['permissions']['usercsspermissions'] & $vbulletin->bf_ugp_usercsspermissions['caneditbgimage']); $template->register('caneditcolors', $userinfo['permissions']['usercsspermissions'] & $vbulletin->bf_ugp_usercsspermissions['caneditcolors']); $template->register('caneditborders', $userinfo['permissions']['usercsspermissions'] & $vbulletin->bf_ugp_usercsspermissions['caneditborders']); $template->register('contenttypeid', vB_Types::instance()->getContentTypeID('vBForum_Album')); $template->register('poststarttime', TIMENOW); $template->register('posthash', vB_Template_Runtime::escapeJS(md5(TIMENOW . $vbulletin->userinfo['userid'] . $vbulletin->userinfo['salt']))); //see if this user is using the asset manager. $show_albums = 'false'; //see if this user has an album we can use for background images. $albums = vB_dB_Assertor::getInstance()->assertQuery('firstPublicAlbum', array('userid' => $vbulletin->userinfo['userid'])); if ($albums->valid()) { $album = $albums->current(); if (!empty($album)) { //this user has at least one public album $show_albums = 'true'; } } $jsblock .= "var show_albums = {$show_albums};\n"; $template->register('show_assetmanager', $show_albums == 'true'); //Now the initial variables. $template->register('title_text_color', $usertheme['title_text_color']); $template->register('module_text_color', $usertheme['module_text_color']); $template->register('module_link_color', $usertheme['module_link_color']); $template->register('module_border', $usertheme['module_border']); $template->register('content_text_color', $usertheme['content_text_color']);
function do_stats() { $user_counts = vB_Api::instance('wol')->fetchCounts(); if (empty($user_counts) || !empty($user_counts['errors'])) { return json_error(ERR_NO_PERMISSION); } $top = vB_Api::instance('content_channel')->fetchTopLevelChannelIds(); $forumid = $top['forum']; $contenttypeid = vB_Api::instance('contenttype')->fetchContentTypeIdFromClass('Text'); $all_texts = vB_Api::instance('node')->listNodeFullContent($forumid, 1, 10000000000, 10000, $contenttypeid, false); $total_threads = 0; $total_posts = 0; foreach ($all_texts as $node) { if ($node['starter'] == $node['nodeid']) { $total_threads++; } $total_posts++; } $total_members = vB_dB_Assertor::instance()->getRow('ForumRunner:countMembers'); $newuser = vB_dB_Assertor::instance()->getRow('ForumRunner:getNewestUser'); $total_members = $total_members['count']; $newuser = $newuser['username']; $out = array('threads' => $total_threads, 'posts' => $total_posts, 'members' => $total_members, 'newuser' => $newuser, 'record_users' => $user_counts['recordusers'], 'record_date' => $user_counts['recorddate'], 'online_members' => $user_counts['members'], 'online_guests' => $user_counts['guests']); return $out; }
function get_sub_thread_updates() { $userid = vB::getUserContext()->fetchUserId(); $count = vB_dB_Assertor::instance()->getRow('ForumRunner:subscribedContentUpdateCount', array('userid' => $userid)); return intval($count['qty']); }
if (intval($vbulletin->userinfo['userid'])) { $vbulletin->input->clean_array_gpc('r', array('albumid' => TYPE_UINT)); if ($vbulletin->GPC_exists['albumid']) { //class db_Assertor needs to be initialized. vB_dB_Assertor::init(vB::$vbulletin->db, vB::$vbulletin->userinfo); echo vB_ProfileCustomize::getAlbumContents($vbulletin->GPC['albumid'], $vbulletin->userinfo); } } } // ############################################################################# // get the asset picker // if ($_REQUEST['do'] == 'getassetpicker') { if (intval($vbulletin->userinfo['userid'])) { //class db_Assertor needs to be initialized. vB_dB_Assertor::init(vB::$vbulletin->db, vB::$vbulletin->userinfo); vB_ProfileCustomize::getAssetPicker($vbulletin->userinfo, $vbulletin); } } // ############################################################################# // get the confirm close dialog box // if ($_REQUEST['do'] == 'getconfirmclosebox') { if (intval($vbulletin->userinfo['userid'])) { echo vB_ProfileCustomize::getConfirmCloseBox(); } } // ############################################################################# // get the confirm close dialog box // if ($_REQUEST['do'] == 'getprofiledialog') {
/** This sets the db. It will normally be call in the boot process * * @param array config array ***/ public static function init(&$config) { //currently mysqli is handled by the mysql class if ($config['Database']['dbtype'] == 'mysqli') { self::$dbtype = 'MYSQL'; } else { self::$dbtype = strtoupper($config['Database']['dbtype']); } $class = 'vB_dB_' . self::$dbtype . '_Assertor'; if (class_exists($class)) { self::$instance = new $class($config); } vB_Shutdown::instance()->add(array(self::$instance, 'executeShutdownQueries')); }
/** * Validates the provided value of a setting against its datatype. * Extracted from adminfunctions_options * * @param mixed (ref) Setting value * @param string Setting datatype ('number', 'boolean' or other) * @param boolean Represent boolean with 1/0 instead of true/false * @param boolean Query database for username type * * @return mixed Setting value */ protected function validate_setting_value(&$value, $datatype, $bool_as_int = true, $username_query = true) { switch ($datatype) { case 'number': $value += 0; break; case 'integer': $value = intval($value); break; case 'arrayinteger': $key = array_keys($value); $size = sizeOf($key); for ($i = 0; $i < $size; $i++) { $value[$key[$i]] = intval($value[$key[$i]]); } break; case 'arrayfree': $key = array_keys($value); $size = sizeOf($key); for ($i = 0; $i < $size; $i++) { $value[$key[$i]] = trim($value[$key[$i]]); } break; case 'posint': $value = max(1, intval($value)); break; case 'boolean': $value = $bool_as_int ? $value ? 1 : 0 : ($value ? true : false); break; case 'bitfield': if (is_array($value)) { $bitfield = 0; foreach ($value as $bitval) { $bitfield += $bitval; } $value = $bitfield; } else { $value += 0; } break; case 'username': $value = trim($value); if ($username_query) { if (empty($value)) { $value = 0; } else { $result = $this->db_assertor->assertQuery('user', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'username' => htmlspecialchars_uni($value))); if ($result->valid()) { $userinfo = $result->current(); $value = $userinfo['userid']; } else { $value = false; } } } break; default: $value = trim($value); } return $value; }
function addFiledataid($posthash, $filedataid) { $result = vB_dB_Assertor::instance()->assertQuery('vBMAPI:insertPosthashFiledataid', array('posthash' => $posthash, 'filedataid' => $filedataid, 'dateline' => vB::getRequest()->getTimeNow())); return $result; }
} // We have our PM list. Now lets see which ones we've already sent // and eliminate them. $sentpms = $vbulletin->db->query_read_slave("\n\t\t\tSELECT vb_pmid\n\t\t\tFROM " . TABLE_PREFIX . "forumrunner_push_data\n\t\t\tWHERE vb_userid = " . $user['vb_userid'] . " AND vb_pmid IN (" . implode(',', $pmids) . ")\n\t\t\t"); while ($sentpm = $vbulletin->db->fetch_array($sentpms)) { unset($pms[$sentpm['vb_pmid']]); } unset($sentpms); // Save that we sent PM notices foreach ($pms as $pm) { $vbulletin->db->query_write("\n\t\t\t\tINSERT INTO " . TABLE_PREFIX . "forumrunner_push_data\n\t\t\t\t(vb_userid, vb_pmid)\n\t\t\t\tVALUES\n\t\t\t\t({$user['vb_userid']}, {$pm['nodeid']})\n\t\t\t\t"); } } unset($unreadpms); $subs = array(); $sub_threads = vB_dB_Assertor::instance()->getRows('ForumRunner:getNewSubsForPushUser', array('userid' => $user['vb_userid'])); foreach ($sub_threads as $thread) { $push_threaddata = $vbulletin->db->query_first_slave("\n\t\t\tSELECT * FROM " . TABLE_PREFIX . "forumrunner_push_data\n\t\t\tWHERE vb_threadid = {$thread['nodeid']} AND vb_userid = {$user['vb_userid']}\n\t\t\t"); if ($push_threaddata) { if ($push_threaddata['vb_threadread'] < $thread['lastupdate']) { if ($push_threaddata['vb_subsent']) { continue; } $vbulletin->db->query_write("\n\t\t\t\t\tUPDATE " . TABLE_PREFIX . "forumrunner_push_data\n\t\t\t\t\tSET vb_threadread = {$thread['lastupdate']}, vb_subsent = 1\n\t\t\t\t\tWHERE id = {$push_threaddata['id']}\n\t\t\t\t\t"); $subs[] = array('threadid' => $thread['nodeid'], 'title' => $thread['title']); } } else { $subs[] = array('threadid' => $thread['nodeid'], 'title' => $thread['title']); $vbulletin->db->query_write("\n\t\t\t\tINSERT INTO " . TABLE_PREFIX . "forumrunner_push_data\n\t\t\t\t(vb_userid, vb_threadid, vb_threadread, vb_subsent)\n\t\t\t\tVALUES ({$user['vb_userid']}, {$thread['nodeid']}, {$thread['lastupdate']}, 1)\n\t\t\t\t"); } unset($push_threaddata);
/** * Verifies the an image property. Must come from this user's album and the album must be public/profile. * * @param string Value to verfiy. May be modified. * * @return boolean True if value. */ function verify_image(&$value) { $options = vB5_vB::get_datastore()->get_value('options'); $bf_misc_socnet = vB5_vB::get_datastore()->get_value('bf_misc_socnet'); if (!($options['socnet'] & $bf_misc_socnet['enable_albums'])) { $value = ''; return true; } $foundalbum = preg_match('#albumid=([0-9]+)#', $value, $albumid); $foundpicture = preg_match('#attachmentid=([0-9]+)#', $value, $attachmentid); require_once DIR . '/includes/class_bootstrap_framework.php'; require_once DIR . '/vb/types.php'; vB_Bootstrap_Framework::init(); $types = vB_Types::instance(); $contenttypeid = intval($types->getContentTypeID('vBForum_Album')); if ($foundalbum and $foundpicture and $picture = $this->assertor->getRow('getUserPictures', array('attachmentid' => intval($attachmentid[1]), 'contenttypeid' => $contenttypeid, 'state' => array('profile', 'public'), 'userid' => $this->userid, 'albumid' => intval($albumid[1])))) { $value = $albumid[1] . "," . $attachmentid[1]; return true; } else { return false; } }
protected function __construct(&$config) { parent::__construct($config); $this->load_database($config); self::$dbSlave = !empty($config['SlaveServer']['servername']) and !empty($config['SlaveServer']['port']) and !empty($config['SlaveServer']['username']); }
/** * Returns a by-reference the assertor object * @return vB_dB_Assertor */ public static function &getDbAssertor() { if (!isset(self::$db_assertor)) { vB_dB_Assertor::init(self::getConfig()); self::$db_assertor = vB_dB_Assertor::instance(); } return self::$db_assertor; }
public static function getAssetPicker($userinfo, $registry) { //see if this user has an album we can use for background images. $albums = vB_dB_Assertor::instance()->assertQuery('CustomProfileAlbums', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_STORED, 'userid' => $userinfo['userid'])); $album = $albums->current(); $album_select = ''; while ($albums->valid()) { $album_select .= "<option value=\"" . $album['albumid'] . "\">" . $album['title'] . "</option>\n"; $album = $albums->next(); } require_once DIR . '/includes/class_xml.php'; $xml = new vB_XML_Builder_Ajax('text/xml'); if (empty($album_select)) { $xml->add_group('error'); $xml->add_tag('phrase', 'need_public_album_text'); } else { $xml->add_group('content'); $template = vB_Template::create('memberinfo_assetpicker'); $template->register('album_select', $album_select); $phrase = new vB_Phrase('profilefield', 'select_album_to_view'); $template->register('select_album_to_view', $phrase); $body = $template->render(); $template = vB_Template::create('memberinfo_assetpicker_footer'); $footer = $template->render(); $header = new vB_Phrase('profilefield', 'asset_picker'); //Now format this as an xml array. $xml->add_tag('body', $body); $xml->add_tag('header', $header); $xml->add_tag('footer', $footer); } $xml->close_group(); $xml->print_xml(); }
/** This sets the db and userinfo. It will normally be call in the boot process * * @param object the db object * @param array userinfo array ***/ public static function init(&$db, &$userinfo) { self::$db = $db; self::$userinfo = $userinfo; $class = 'vB_dB_' . self::$site_db_type . '_Assertor'; if (class_exists($class)) { self::$instance = new $class(); } }
function addNode($params, $db, $check_only = false) { if ($check_only) { return !empty($params['contenttypeid']) and !empty($params['parentid']) and !empty($params['title']); } $cleaned = vB::getCleaner()->cleanArray($params, array('parentid' => vB_Cleaner::TYPE_UINT)); $params[vB_dB_Query::TYPE_KEY] = vB_dB_Query::QUERY_INSERT; //We must set the protected field. $parent = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "node WHERE nodeid =" . $cleaned['parentid']); $params['protected'] = $parent['protected']; $nodeid = vB_dB_Assertor::instance()->assertQuery('vBForum:node', $params); $config = vB::getConfig(); if ($nodeid) { $nodeid = $nodeid[0]; $sql = "INSERT INTO " . TABLE_PREFIX . "closure(parent, child, depth)\n\t\t\t\tVALUES({$nodeid}, {$nodeid}, 0) \n/**" . __FUNCTION__ . (defined('THIS_SCRIPT') ? '- ' . THIS_SCRIPT : '') . "**/"; if (isset($config['Misc']['debug_sql']) and $config['Misc']['debug_sql']) { echo "sql: {$sql} <br />\n"; } $db->query_write($sql); $sql = "INSERT INTO " . TABLE_PREFIX . "closure(parent, child, depth)\n\t\t\t\tSELECT p.parent, {$nodeid}, p.depth+1\n\t\t\t \tFROM " . TABLE_PREFIX . "closure p\n\t\t\t \tWHERE p.child=" . $cleaned['parentid'] . "\n/**" . __FUNCTION__ . (defined('THIS_SCRIPT') ? '- ' . THIS_SCRIPT : '') . "**/"; if (isset($config['Misc']['debug_sql']) and $config['Misc']['debug_sql']) { echo "sql: {$sql} <br />\n"; } $db->query_write($sql); return $nodeid; } else { return false; } }
/** * Select query builder / executer * * @param mixed condition value * @param integer condition type (reference: in this file define('USERCHANGELOG_COND_TYPE_*')) * @param integer minimum time (UNIX_TIMESTAMP) * @param integer maximum time (UNIX_TIMESTAMP) * @param integer which page we want to select * @param integer how many row on the page * * @return mixed sql query (no execute) / select resultset (execute + no just_count) / selected count (execute + just_count) */ function sql_select_core($cond_value, $cond_type, $time_start, $time_end, $page, $limit) { $page = intval($page); $limit = intval($limit); $just_count = $this->just_count; $where = array(); $where[vB_dB_Query::TYPE_KEY] = vB_dB_Query::QUERY_METHOD; // dbbject need for the escape string // if (!is_object($this->registry) OR !is_object($this->registry->db)) // { // trigger_error('Database object is not an object', E_USER_ERROR); // } // let's create the where condition depend on the condition type switch ($cond_type) { // condition by userid case USERCHANGELOG_COND_TYPE_USERID: //$where = array(); $where['userchangelog.userid'] = intval($cond_value); break; // condition by adminid // condition by adminid case USERCHANGELOG_COND_TYPE_ADMINID: //$where = array(); $where['userchangelog.adminid'] = intval($cond_value); break; // condition by fieldname // condition by fieldname case USERCHANGELOG_COND_TYPE_FIELDNAME: //$where = array(); $where['userchangelog.fieldname'] = strval($cond_value); break; // condition by username // condition by username case USERCHANGELOG_COND_TYPE_USERNAME: //$where = array(); $where['userchangelog.fieldname'] = 'username'; $where['userchangelog.oldvalue'] = strval($cond_value); $where['userchangelog.newvalue'] = strval($cond_value); break; // condition by time (do nothing just avoid the default case) // condition by time (do nothing just avoid the default case) case USERCHANGELOG_COND_TYPE_TIME: break; // unknown condition type, return an empty string // unknown condition type, return an empty string default: return ''; } // when we have timeframe for the select then we add that to the condition if ($time_start) { $where['time_start'] = intval($time_start); // Send time_start for >= comparison } if ($time_end) { $where['time_end'] = intval($time_end); // Send time_end for <= comparison } $where[vB_dB_Query::PARAM_LIMITPAGE] = $page; $where[vB_dB_Query::PARAM_LIMIT] = $limit; // let's build the query if we got $where condition if ($where) { if ($just_count) { $where['just_count'] = $just_count; $result = $this->assertor->getRow('getChangelogData', $where); $result = $result['change_count']; } else { $result = $this->assertor->getRows('getChangelogData', $where); } } // execute: return with the select result /*if ($this->just_count) { $result = $this->registry->db->query_first($query); return $result['change_count']; } else {*/ return $result; //} }