本文整理汇总了PHP中gGetDb函数的典型用法代码示例。如果您正苦于以下问题:PHP gGetDb函数的具体用法?PHP gGetDb怎么用?PHP gGetDb使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了gGetDb函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getForRequest
/**
* @param integer $id
* @param null|PdoDatabase $database
* @return Comment[]
* @throws Exception
*/
public static function getForRequest($id, PdoDatabase $database = null)
{
if ($database == null) {
$database = gGetDb();
}
if (User::getCurrent()->isAdmin() || User::getCurrent()->isCheckuser()) {
// current user is an admin or checkuser, so retrieve everything.
$statement = $database->prepare("SELECT * FROM comment WHERE request = :target;");
} else {
// current user isn't an admin, so limit to only those which are visible to users, and private comments
// the user has posted themselves.
$statement = $database->prepare(<<<SQL
SELECT * FROM comment
WHERE request = :target AND (visibility = 'user' OR user = :userid);
SQL
);
$statement->bindValue(":userid", User::getCurrent()->getId());
}
$statement->bindValue(":target", $id);
$statement->execute();
$result = array();
/** @var Comment $v */
foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
$v->isNew = false;
$v->setDatabase($database);
$result[] = $v;
}
return $result;
}
示例2: executeQueryToArray
public function executeQueryToArray($query)
{
$database = gGetDb();
$statement = $database->prepare($query);
$statement->execute();
return $statement->fetchAll($this->rowFetchMode);
}
示例3: getUserDetail
private function getUserDetail($userId)
{
$database = gGetDb();
$user = User::getById($userId, $database);
if ($user == false) {
return BootstrapSkin::displayAlertBox("User not found", "alert-error", "Error", true, false, true);
}
global $smarty;
$activitySummary = $database->prepare(<<<SQL
SELECT COALESCE(c.mail_desc, l.log_action) AS action, COUNT(*) AS count
FROM acc_log l
LEFT JOIN closes c ON l.log_action = c.closes
WHERE l.log_user = :username
GROUP BY action;
SQL
);
$activitySummary->execute(array(":username" => $user->getUsername()));
$activitySummaryData = $activitySummary->fetchAll(PDO::FETCH_ASSOC);
$smarty->assign("user", $user);
$smarty->assign("activity", $activitySummaryData);
$usersCreatedQuery = $database->prepare(<<<SQL
SELECT l.log_time time, r.name name, r.id id
FROM acc_log l
JOIN request r ON r.id = l.log_pend
LEFT JOIN emailtemplate e ON concat('Closed ', e.id) = l.log_action
WHERE l.log_user = :username
AND l.log_action LIKE 'Closed %'
AND (e.oncreated = '1' OR l.log_action = 'Closed custom-y')
ORDER BY l.log_time;
SQL
);
$usersCreatedQuery->execute(array(":username" => $user->getUsername()));
$usersCreated = $usersCreatedQuery->fetchAll(PDO::FETCH_ASSOC);
$smarty->assign("created", $usersCreated);
$usersNotCreatedQuery = $database->prepare(<<<SQL
SELECT l.log_time time, r.name name, r.id id
FROM acc_log l
JOIN request r ON r.id = l.log_pend
LEFT JOIN emailtemplate e ON concat('Closed ', e.id) = l.log_action
WHERE l.log_user = :username
AND l.log_action LIKE 'Closed %'
AND (e.oncreated = '0' OR l.log_action = 'Closed custom-n' OR l.log_action='Closed 0')
ORDER BY l.log_time;
SQL
);
$usersNotCreatedQuery->execute(array(":username" => $user->getUsername()));
$usersNotCreated = $usersNotCreatedQuery->fetchAll(PDO::FETCH_ASSOC);
$smarty->assign("notcreated", $usersNotCreated);
$accountLogQuery = $database->prepare(<<<SQL
SELECT *
FROM acc_log l
WHERE l.log_pend = :userid
\t AND log_action IN ('Approved','Suspended','Declined','Promoted','Demoted','Renamed','Prefchange');
SQL
);
$accountLogQuery->execute(array(":userid" => $user->getId()));
$accountLog = $accountLogQuery->fetchAll(PDO::FETCH_ASSOC);
$smarty->assign("accountlog", $accountLog);
return $smarty->fetch("statistics/userdetail.tpl");
}
示例4: displayInternalFooter
/**
* Prints the internal interface footer to the screen.
*
* @param string|null $tailscript JavaScript to append to the page, usually so it can call jQuery
* @throws Exception
*/
public static function displayInternalFooter($tailscript = null)
{
global $smarty;
// close all declared open tags
while (count(self::$tagstack) != 0) {
echo array_pop(self::$tagstack);
}
$last5min = time() - 300;
$last5mins = date("Y-m-d H:i:s", $last5min);
$database = gGetDb();
$statement = $database->prepare("SELECT * FROM user WHERE lastactive > :lastfive;");
$statement->execute(array(":lastfive" => $last5mins));
$resultSet = $statement->fetchAll(PDO::FETCH_CLASS, "User");
$resultSetCount = count($resultSet);
$creators = implode(", ", array_map(function ($arg) {
/** @var User $arg */
return "<a href=\"statistics.php?page=Users&user=" . $arg->getId() . "\">" . htmlentities($arg->getUsername()) . "</a>";
}, $resultSet));
// not equal to one, as zero uses the plural form too.
if ($resultSetCount != 1) {
$onlinemessage = $resultSetCount . " Account Creators currently online (past 5 minutes): {$creators}";
} else {
$onlinemessage = $resultSetCount . " Account Creator currently online (past 5 minutes): {$creators}";
}
$online = '<p class="span6 text-right"><small>' . $onlinemessage . '</small></p>';
if (isset($_SESSION['user'])) {
$smarty->assign("onlineusers", $online);
} else {
$emptystring = "";
$smarty->assign("onlineusers", $emptystring);
}
$smarty->assign("tailscript", $tailscript);
$smarty->display("footer.tpl");
}
示例5: isTrusted
/**
* Returns a value if the IP address is a trusted proxy
* @param string $ip
* @param PdoDatabase $database
* @return bool
*/
public function isTrusted($ip, PdoDatabase $database = null)
{
if (in_array($ip, $this->trustedCache)) {
return true;
}
if (in_array($ip, $this->untrustedCache)) {
return false;
}
if ($database == null) {
$database = gGetDb();
}
$query = "SELECT COUNT(*) FROM xfftrustcache WHERE ip = :ip;";
$statement = $database->prepare($query);
$statement->execute(array(":ip" => $ip));
$result = $statement->fetchColumn();
$statement->closeCursor();
if ($result == 0) {
$this->untrustedCache[] = $ip;
return false;
}
if ($result >= 1) {
$this->trustedCache[] = $ip;
return true;
}
// something weird has happened if we've got here.
// default to untrusted.
return false;
}
示例6: execute
/**
* Summary of execute
* @param \DOMElement $apiDocument
* @return \DOMElement
* @throws ApiException
* @throws \Exception
*/
public function execute(\DOMElement $apiDocument)
{
$username = isset($_GET['user']) ? trim($_GET['user']) : '';
$wikiusername = isset($_GET['wikiuser']) ? trim($_GET['wikiuser']) : '';
if ($username === '' && $wikiusername === '') {
throw new ApiException("Please specify a username using either user or wikiuser parameters.");
}
$userElement = $this->document->createElement("user");
$apiDocument->appendChild($userElement);
$this->database = gGetDb();
if ($username !== '') {
$this->user = \User::getByUsername($username, $this->database);
} else {
$this->user = \User::getByOnWikiUsername($wikiusername, $this->database);
}
if ($this->user === false) {
$userElement->setAttribute("missing", "true");
return $apiDocument;
}
$userElement->setAttribute("username", $this->user->getUsername());
$userElement->setAttribute("status", $this->user->getStatus());
$userElement->setAttribute("lastactive", $this->user->getLastActive());
$userElement->setAttribute("welcome_template", $this->user->getWelcomeTemplate());
$userElement->setAttribute("onwikiname", $this->user->getOnWikiName());
$userElement->setAttribute("oauth", $this->user->isOAuthLinked() ? "true" : "false");
return $apiDocument;
}
示例7: smallStats
/**
* Gets the relevant statistics from the database for the small statistics table
*/
private function smallStats()
{
global $smarty;
$database = gGetDb();
$requestsQuery = "SELECT COUNT(*) FROM request WHERE status = :status AND emailconfirm = 'Confirmed';";
$requestsStatement = $database->prepare($requestsQuery);
// TODO: use the request states thing here.
// Open Requests
$requestsStatement->execute(array(":status" => "Open"));
$open = $requestsStatement->fetchColumn();
$requestsStatement->closeCursor();
$smarty->assign("statsOpen", $open);
// Admin Requests
$requestsStatement->execute(array(":status" => "Admin"));
$admin = $requestsStatement->fetchColumn();
$requestsStatement->closeCursor();
$smarty->assign("statsAdmin", $admin);
// Checkuser Requests
$requestsStatement->execute(array(":status" => "Checkuser"));
$checkuser = $requestsStatement->fetchColumn();
$requestsStatement->closeCursor();
$smarty->assign("statsCheckuser", $checkuser);
// Unconfirmed requests
$unconfirmedStatement = $database->query("SELECT COUNT(*) FROM request WHERE emailconfirm != 'Confirmed' AND emailconfirm != '';");
$unconfirmed = $unconfirmedStatement->fetchColumn();
$unconfirmedStatement->closeCursor();
$smarty->assign("statsUnconfirmed", $unconfirmed);
$userStatusStatement = $database->prepare("SELECT COUNT(*) FROM user WHERE status = :status;");
// Admin users
$userStatusStatement->execute(array(":status" => "Admin"));
$adminusers = $userStatusStatement->fetchColumn();
$userStatusStatement->closeCursor();
$smarty->assign("statsAdminUsers", $adminusers);
// Users
$userStatusStatement->execute(array(":status" => "User"));
$users = $userStatusStatement->fetchColumn();
$userStatusStatement->closeCursor();
$smarty->assign("statsUsers", $users);
// Suspended users
$userStatusStatement->execute(array(":status" => "Suspended"));
$suspendedUsers = $userStatusStatement->fetchColumn();
$userStatusStatement->closeCursor();
$smarty->assign("statsSuspendedUsers", $suspendedUsers);
// New users
$userStatusStatement->execute(array(":status" => "New"));
$newUsers = $userStatusStatement->fetchColumn();
$userStatusStatement->closeCursor();
$smarty->assign("statsNewUsers", $newUsers);
// Most comments on a request
$mostCommentsStatement = $database->query("SELECT request FROM comment GROUP BY request ORDER BY COUNT(*) DESC LIMIT 1;");
$mostComments = $mostCommentsStatement->fetchColumn();
$mostCommentsStatement->closeCursor();
$smarty->assign("mostComments", $mostComments);
}
示例8: execute
protected function execute()
{
global $smarty;
$showImmune = false;
if (isset($_GET['showimmune'])) {
$showImmune = true;
}
$smarty->assign("showImmune", $showImmune);
$inactiveUsers = User::getAllInactive(gGetDb());
$smarty->assign("inactiveUsers", $inactiveUsers);
return $smarty->fetch("statistics/inactiveusers.tpl");
}
示例9: execute
public function execute(\DOMElement $apiDocument)
{
$this->database = gGetDb();
$statusElement = $this->document->createElement("status");
$apiDocument->appendChild($statusElement);
$query = $this->database->prepare(<<<SQL
SELECT /* Api/StatusAction */ COUNT(*) AS count
FROM request
WHERE
status = :pstatus
AND emailconfirm = 'Confirmed';
SQL
);
global $availableRequestStates;
foreach ($availableRequestStates as $key => $value) {
$query->bindValue(":pstatus", $key);
$query->execute();
$sus = $query->fetchColumn();
$statusElement->setAttribute($value['api'], $sus);
$query->closeCursor();
}
$query = $this->database->prepare(<<<SQL
SELECT /* Api/StatusAction */ COUNT(*) AS count
FROM ban
WHERE
(duration > UNIX_TIMESTAMP() OR duration = -1)
AND active = 1;
SQL
);
$query->execute();
$sus = $query->fetchColumn();
$statusElement->setAttribute("bans", $sus);
$query->closeCursor();
$query = $this->database->prepare("SELECT /* Api/StatusAction */ COUNT(*) AS count FROM user WHERE status = :ulevel;");
$query->bindValue(":ulevel", "Admin");
$query->execute();
$sus = $query->fetchColumn();
$statusElement->setAttribute("useradmin", $sus);
$query->closeCursor();
$query->bindValue(":ulevel", "User");
$query->execute();
$sus = $query->fetchColumn();
$statusElement->setAttribute("user", $sus);
$query->closeCursor();
$query->bindValue(":ulevel", "New");
$query->execute();
$sus = $query->fetchColumn();
$statusElement->setAttribute("usernew", $sus);
$query->closeCursor();
return $apiDocument;
}
示例10: cleanExpiredUnconfirmedRequests
/**
* This function removes all old requests which are not yet email-confirmed
* from the database.
*/
public static function cleanExpiredUnconfirmedRequests()
{
global $emailConfirmationExpiryDays;
$database = gGetDb();
$statement = $database->prepare(<<<SQL
DELETE FROM request
WHERE
date < DATE_SUB(CURRENT_TIMESTAMP(), INTERVAL {$emailConfirmationExpiryDays} DAY)
AND emailconfirm != 'Confirmed'
AND emailconfirm != '';
SQL
);
$statement->execute();
}
示例11: execute
public function execute(\DOMElement $apiDocument)
{
$this->database = gGetDb();
$now = new \DateTime();
$old = $this->getOldest();
$oldest = new \DateTime($old);
$new = $this->getNewest();
$newest = new \DateTime($new);
$monitoringElement = $this->document->createElement("data");
$monitoringElement->setAttribute("date", $now->format('c'));
$monitoringElement->setAttribute("oldest", $old == null ? null : $oldest->format('c'));
$monitoringElement->setAttribute("newest", $new == null ? null : $newest->format('c'));
$apiDocument->appendChild($monitoringElement);
return $apiDocument;
}
示例12: getAll
/**
* Summary of getAll
* @param PdoDatabase $database
* @return WelcomeTemplate[]
*/
public static function getAll(PdoDatabase $database = null)
{
if ($database == null) {
$database = gGetDb();
}
$statement = $database->prepare("SELECT * FROM welcometemplate;");
$statement->execute();
$result = array();
foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
$v->isNew = false;
$v->setDatabase($database);
$result[] = $v;
}
return $result;
}
示例13: getCurrent
/**
* Summary of getCurrent
* @param PdoDatabase $database
* @return User The currently logged in user, or an anonymous coward with userid -1.
*/
public static function getCurrent(PdoDatabase $database = null)
{
if ($database === null) {
$database = gGetDb();
}
if (self::$currentUser === null) {
if (isset($_SESSION['userID'])) {
self::$currentUser = self::getById($_SESSION['userID'], $database);
} else {
$anonymousCoward = new CommunityUser();
self::$currentUser = $anonymousCoward;
}
}
return self::$currentUser;
}
示例14: getAllActiveTemplates
/**
* Gets active non-preload and preload templates
* @param string $defaultAction Default action to take (EmailTemplate::CREATED or EmailTemplate::NOT_CREATED)
* @param PdoDatabase $database
* @return array|false
*/
public static function getAllActiveTemplates($defaultAction, PdoDatabase $database = null)
{
if ($database == null) {
$database = gGetDb();
}
$statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE defaultaction = :forcreated AND active = 1;");
if ($defaultAction === false) {
$statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE defaultaction not in ('created', 'not created') AND active = 1;");
}
$statement->bindValue(":forcreated", $defaultAction);
$statement->execute();
$resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
foreach ($resultObject as $t) {
$t->setDatabase($database);
$t->isNew = false;
}
return $resultObject;
}
示例15: getSpoofs
public function getSpoofs($username)
{
global $mediawikiWebServiceEndpoint;
$cacheResult = AntiSpoofCache::getByUsername($username, gGetDb());
if ($cacheResult == false) {
// get the data from the API
$data = file_get_contents($mediawikiWebServiceEndpoint . "?action=antispoof&format=php&username=" . urlencode($username));
$cacheEntry = new AntiSpoofCache();
$cacheEntry->setDatabase(gGetDb());
$cacheEntry->setUsername($username);
$cacheEntry->setData($data);
$cacheEntry->save();
$cacheResult = $cacheEntry;
} else {
$data = $cacheResult->getData();
}
$result = unserialize($data);
if (!isset($result['antispoof']) || !isset($result['antispoof']['result'])) {
$cacheResult->delete();
if (isset($result['error']['info'])) {
throw new Exception("Unrecognised API response to query: " . $result['error']['info']);
}
throw new Exception("Unrecognised API response to query.");
}
if ($result['antispoof']['result'] == "pass") {
// All good here!
return array();
}
if ($result['antispoof']['result'] == "conflict") {
// we've got conflicts, let's do something with them.
return $result['antispoof']['users'];
}
if ($result['antispoof']['result'] == "error") {
// we've got conflicts, let's do something with them.
throw new Exception("Encountered error while getting result: " . $result['antispoof']['error']);
}
throw new Exception("Unrecognised API response to query.");
}