/**
  * Unvote a node
  *
  * @param int $nodeid Node ID.
  * @return array New Node info.
  * @see vB_Api_Node::getNode()
  * @throws vB_Exception_Api
  */
 public function unvote($nodeid)
 {
     $node = vB_Api::instanceInternal('node')->getNodeFullContent($nodeid);
     $node = $node[$nodeid];
     $this->checkCanUseRep($node);
     $loginuser =& vB::getCurrentSession()->fetch_userinfo();
     if ($node['userid'] == $loginuser['userid']) {
         // Can't vote own node
         throw new vB_Exception_Api('reputationownpost');
     }
     // Check if the user has already reputation this node
     $existingreputation = $this->assertor->getRow('vBForum:reputation', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'nodeid' => $node['nodeid'], 'whoadded' => $loginuser['userid']));
     if (!$existingreputation) {
         throw new vB_Exception_Api('reputationnovote');
     }
     $userinfo = vB_Api::instanceInternal('user')->fetchUserinfo($node['userid']);
     if (!$userinfo['userid']) {
         throw new vB_Exception_Api('invalidid', 'User');
     }
     $usergroupcache = vB::getDatastore()->getValue('usergroupcache');
     $bf_ugp_genericoptions = vB::getDatastore()->getValue('bf_ugp_genericoptions');
     if (!($usergroupcache["{$userinfo['usergroupid']}"]['genericoptions'] & $bf_ugp_genericoptions['isnotbannedgroup'])) {
         throw new vB_Exception_Api('reputationbanned');
     }
     $userinfo['reputation'] -= $existingreputation['reputation'];
     // Determine this user's reputationlevelid.
     $reputationlevelid = $this->assertor->getField('vBForum:reputation_userreputationlevel', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_STORED, 'reputation' => $userinfo['reputation']));
     // init user data manager
     $userdata = new vB_Datamanager_User(NULL, vB_DataManager_Constants::ERRTYPE_STANDARD);
     $userdata->set_existing($userinfo);
     $userdata->set('reputation', $userinfo['reputation']);
     $userdata->set('reputationlevelid', intval($reputationlevelid));
     $userdata->pre_save();
     // Delete existing vote
     $this->assertor->assertQuery('vBForum:reputation', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_DELETE, 'reputationid' => $existingreputation['reputationid']));
     $userdata->save();
     $condition = array('nodeid' => $nodeid);
     $this->assertor->assertQuery('vBForum:updateNodeVotes', $condition);
     $votesCount = $this->assertor->getField('vBForum:node', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, vB_dB_Query::COLUMNS_KEY => array('votes'), vB_dB_Query::CONDITIONS_KEY => $condition));
     if ($votesCount == 0) {
         /*
         					TODO: add test for below code
         */
         /*
         				TODO Add a new delete event for LikedNode and replace below with a dismiss event!
         */
         // we need to remove the notification
         $typesByTypename = vB_Library::instance('notification')->getNotificationTypes();
         $typeid = $typesByTypename[vB_Notification_LikedNode::TYPENAME]['typeid'];
         $notificationInfo = array('recipient' => $node['userid'], 'sentbynodeid' => $nodeid, 'typeid' => $typeid);
         $notification = $this->assertor->getRow('vBForum:notification', $notificationInfo);
         if (isset($notification['notificationid'])) {
             vB_Library::instance('notification')->deleteNotification($notification['notificationid']);
         }
     }
     // Expire node cache so this like displays correctly
     vB_Cache::instance()->allCacheEvent('nodeChg_' . $nodeid);
     return array('nodeid' => $nodeid, 'votes' => $votesCount);
 }
 protected function fetchStoredSession($sessionhash)
 {
     $this->cookietimeout = $this->datastore->getOption('cookietimeout');
     if ($sessionhash) {
         $request = vB::getRequest();
         $this->vars = $this->dBAssertor->getRow('session', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, vB_dB_Query::CONDITIONS_KEY => array(array('field' => 'sessionhash', 'value' => $sessionhash, 'operator' => vB_dB_Query::OPERATOR_EQ), array('field' => 'lastactivity', 'value' => $request->getTimeNow() - $this->cookietimeout, 'operator' => vB_dB_Query::OPERATOR_GT), array('field' => 'idhash', 'value' => $this->getSessionIdHash(), 'operator' => vB_dB_Query::OPERATOR_EQ))));
         return $this->vars and $this->fetch_substr_ip($this->vars['host']) == $this->fetch_substr_ip($request->getSessionHost());
     } else {
         return false;
     }
 }
Exemple #3
0
 /**
  * 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];
 }
 /**
  * Verifies that the specified user exists
  *
  * @param	integer	User ID
  *
  * @return 	boolean	Returns true if user exists
  */
 function verify_userid(&$userid)
 {
     if ($userid == $this->registry->userinfo['userid']) {
         $this->info['verifyuser'] =& $this->registry->userinfo;
     } else {
         if ($userinfo = $this->assertor->getRow('user', array('userid' => $userid))) {
             $this->info['verifyuser'] =& $userinfo;
         } else {
             $this->error('no_users_matched_your_query');
             return false;
         }
     }
     return true;
 }
Exemple #5
0
 /**
  * Reads the cache object from storage.
  *
  * @param string $key						- Id of the cache entry to read
  * @return array	includes key, data, expires
  */
 protected function readCache($key)
 {
     $entry = $this->assertor->getRow('cache', array('cacheid' => $key));
     if (!$entry) {
         return false;
     } else {
         if ($entry['expires'] > 0 and $entry['expires'] < $this->timeNow) {
             return false;
         } else {
             if (!empty($entry['data']) and !empty($entry['serialized']) and is_string($entry['data'])) {
                 $entry['data'] = @unserialize($entry['data']);
             }
         }
     }
     return array('key' => $key, 'data' => $entry['data'], 'created' => $entry['created'], 'expires' => $entry['expires']);
 }
 public function setOption($name, $value, $save = true)
 {
     $setting = $this->db_assertor->getRow('setting', array('varname' => $name));
     $new_value = $value;
     $valid_value = $this->validate_setting_value($value, $setting['datatype'], true, false);
     $old_value = $this->validate_setting_value($setting['value'], $setting['datatype'], true, false);
     //If styleid changes we need to clear fastDS'd templates.
     if ($name == 'styleid' and $fastDS = vB_FastDS::instance()) {
         $fastDs->setDsChanged('styleid');
     }
     $options = $this->getValue('options');
     $options[$name] = $valid_value;
     $this->registered['options'] = $options;
     if ($valid_value != $setting['value']) {
         if ($save) {
             $this->db_assertor->update('setting', array('value' => $valid_value), array('varname' => $name));
             $this->build('options', serialize($options), 1);
         }
     }
 }
 /**
  * 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;
     }
 }
 /**
  * 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;
     //}
 }