本文整理汇总了PHP中Vote::insert方法的典型用法代码示例。如果您正苦于以下问题:PHP Vote::insert方法的具体用法?PHP Vote::insert怎么用?PHP Vote::insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vote
的用法示例。
在下文中一共展示了Vote::insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wfVoteClick
function wfVoteClick($voteValue, $pageId)
{
global $wgUser;
if (!$wgUser->isAllowed('voteny')) {
return '';
}
if (is_numeric($pageId) && is_numeric($voteValue)) {
$vote = new Vote($pageId);
$vote->insert($voteValue);
return $vote->count(1);
} else {
return 'error';
}
}
示例2: execute
function execute()
{
global $wgUser, $wgOut, $wgVoteDirectory, $wgCommentsDirectory, $IP;
require_once "{$wgVoteDirectory}/VoteClass.php";
require_once "{$wgVoteDirectory}/Publish.php";
require_once "{$wgVoteDirectory}/RSS.php";
require_once "{$wgCommentsDirectory}/CommentClass.php";
if ($_POST["mk"] == md5($_POST["pid"] . 'pants' . $wgUser->mName)) {
require_once "{$IP}/extensions/UserStats/UserStatsClass.php";
$stats = new UserStatsTrack(1, $wgUser->mId, $wgUser->mName);
if (($_GET["Action"] == 1 || $_GET["Action"] == 2) && is_numeric($_POST["pid"]) && (is_numeric($_POST["TheVote"]) || $_GET["Action"] == 2)) {
//echo 'test2';
$Vote = new Vote($_POST["pid"]);
$Vote->setUser($wgUser->mName, $wgUser->mId);
if ($_GET["Action"] == 1) {
$Vote->insert($_POST["TheVote"]);
$stats->incVoteCount();
} else {
$Vote->delete();
}
$CommentList = new Comment($_POST["pid"]);
$publish = new Publish();
$publish->PageID = $_POST["pid"];
$publish->VoteCount = $Vote->count(1);
$publish->CommentCount = $CommentList->count();
$publish->check_score();
echo $Vote->count(1);
}
if ($_GET["Action"] == 3) {
$Vote = new VoteStars($_POST["pid"]);
$Vote->setUser($wgUser->mName, $wgUser->mId);
$Vote->insert($_POST["TheVote"]);
$stats->incVoteCount();
echo $Vote->display();
}
if ($_GET["Action"] == 4) {
$Vote = new VoteStars($_POST["pid"]);
$Vote->setUser($wgUser->mName, $wgUser->mId);
$Vote->delete();
echo $Vote->display();
}
}
// This line removes the navigation and everything else from the
// page, if you don't set it, you get what looks like a regular wiki
// page, with the body you defined above.
$wgOut->setArticleBodyOnly(true);
}
示例3: postVote
public function postVote()
{
$isVoted = false;
$picture = Picture::where('id', '=', Input::get('id'))->first();
if (Auth::check()) {
foreach ($picture->voted as $vote) {
if ($vote->user->id == Auth::user()->id) {
$isVoted = true;
}
}
if (!$isVoted) {
Picture::where('id', '=', Input::get('id'))->increment('votes', 1);
Vote::insert(array('picture_id' => $picture->id, 'user_id' => Auth::user()->id));
$picture = Picture::where('id', '=', Input::get('id'))->first();
return intval($picture->votes);
}
}
return false;
}
示例4: execute
//.........这里部分代码省略.........
// Protect against cross-site request forgery (CSRF)
if (!$wgUser->matchEditToken($wgRequest->getVal('wpEditToken'))) {
$wgOut->addHTML(wfMsg('sessionfailure'));
return;
}
// Create a Title object, or try to, anyway
$userSuppliedTitle = $wgRequest->getVal('title2');
$title = Title::makeTitleSafe(NS_BLOG, $userSuppliedTitle);
// @todo CHECKME: are these still needed? The JS performs these
// checks already but then again JS is also easy to fool...
// The user didn't supply a title? Ask them to supply one.
if (!$userSuppliedTitle) {
$wgOut->setPageTitle(wfMsg('errorpagetitle'));
$wgOut->addWikiMsg('blog-create-error-need-title');
$wgOut->addReturnTo($this->getTitle());
return;
}
// The user didn't supply the blog post text? Ask them to supply it.
if (!$wgRequest->getVal('pageBody')) {
$wgOut->setPageTitle(wfMsg('errorpagetitle'));
$wgOut->addWikiMsg('blog-create-error-need-content');
$wgOut->addReturnTo($this->getTitle());
return;
}
// Localized variables that will be used when creating the page
$localizedCatNS = $wgContLang->getNsText(NS_CATEGORY);
$today = $wgContLang->date(wfTimestampNow());
// Create the blog page if it doesn't already exist
$article = new Article($title, 0);
if ($article->exists()) {
$wgOut->setPageTitle(wfMsg('errorpagetitle'));
$wgOut->addWikiMsg('blog-create-error-page-exists');
$wgOut->addReturnTo($this->getTitle());
return;
} else {
// The blog post will be by default categorized into two
// categories, "Articles by User $1" and "(today's date)",
// but the user may supply some categories themselves, so
// we need to take those into account, too.
$categories = array('[[' . $localizedCatNS . ':' . wfMsgForContent('blog-by-user-category', wfMsgForContent('blog-category')) . wfMsgForContent('word-separator') . $wgUser->getName() . ']]', "[[{$localizedCatNS}:{$today}]]");
$userSuppliedCategories = $wgRequest->getVal('pageCtg');
if (!empty($userSuppliedCategories)) {
// Explode along commas so that we will have an array that
// we can loop over
$userSuppliedCategories = explode(',', $userSuppliedCategories);
foreach ($userSuppliedCategories as $cat) {
$cat = trim($cat);
// GTFO@excess whitespace
if (!empty($cat)) {
$categories[] = "[[{$localizedCatNS}:{$cat}]]";
}
}
}
// Convert the array into a string
$wikitextCategories = implode("\n", $categories);
// Perform the edit
$article->doEdit('<vote />' . "\n" . '<!--start text-->' . "\n" . $wgRequest->getVal('pageBody') . "\n\n" . '<comments />' . "\n\n" . $wikitextCategories . "\n__NOEDITSECTION__", wfMsgForContent('blog-create-summary'));
$articleId = $article->getID();
// Add a vote for the page
// This was originally in its own global function,
// wfFinishCreateBlog and after that in the BlogHooks class but
// it just wouldn't work with Special:CreateBlogPost so I
// decided to move it here since this is supposed to be like
// the primary way of creating new blog posts...
// Using OutputPageBeforeHTML hook, which, according to its
// manual page, runs on *every* page view was such a stupid
// idea IMHO.
$vote = new Vote($articleId);
$vote->insert(1);
$stats = new UserStatsTrack($wgUser->getID(), $wgUser->getName());
$stats->updateWeeklyPoints($stats->point_values['opinions_created']);
$stats->updateMonthlyPoints($stats->point_values['opinions_created']);
//if( $wgEnableFacebook ) {
// BlogHooks::updateFacebookProfile();
//}
//if( $wgSendNewArticleToFriends ) {
// $invite = SpecialPage::getTitleFor( 'EmailNewArticle' );
// $wgOut->redirect(
// $invite->getFullURL( 'page=' . $title->getPrefixedText() )
// );
//}
// Redirect the user to the new blog post they just created
$wgOut->redirect($title->getFullURL());
}
} else {
$_SESSION['alreadysubmitted'] = false;
// Start building the HTML
$output = '';
// Show the blog rules, if the message containing them ain't empty
$message = trim(wfMsgExt('blog-create-rules', array('parse', 'content')));
// Yes, the strlen() is needed, I dunno why wfEmptyMsg() won't work
if (!wfEmptyMsg('blog-create-rules', $message) && strlen($message) > 0) {
$output .= $message . '<br />';
}
// Main form
$output .= $this->displayForm();
// Show everything to the user
$wgOut->addHTML($output);
}
}
示例5: User
function insert_vote($user=0) {
global $anon_karma;
require_once(mnminclude.'votes.php');
$vote = new Vote;
$vote->user=$user;
$vote->link=$this->id;
if ($vote->exists()) return false;
$vote->value=$anon_karma;
if($user>0) {
require_once(mnminclude.'user.php');
$dbuser = new User($user);
if($dbuser->id>0) {
$vote->value = round($dbuser->karma);
}
}
if($vote->insert()) {
$vote->user=-1;
$this->votes=$vote->count();
$this->store_basic();
return true;
}
return false;
}
示例6: Vote
function insert_vote($user, $value)
{
global $db, $current_user;
require_once mnminclude . 'votes.php';
$vote = new Vote();
$vote->user = $user;
$vote->link = $this->id;
if ($vote->exists()) {
return false;
}
$vote->value = $value;
// For karma calculation
if ($this->status != 'published') {
if ($value < 0 && $user > 0) {
$karma_value = round(($value - $current_user->user_karma) / 2);
} else {
$karma_value = round($value);
}
} else {
$karma_value = 0;
}
if ($vote->insert()) {
if ($value < 0) {
$db->query("update links set link_negatives=link_negatives+1, link_karma=link_karma+{$karma_value} where link_id = {$this->id}");
} else {
$db->query("update links set link_votes = link_votes+1, link_karma=link_karma+{$karma_value} where link_id = {$this->id}");
}
$new = $db->get_row("select link_votes, link_negatives, link_karma from links where link_id = {$this->id}");
$this->votes = $new->link_votes;
$this->negatives = $new->link_negatives;
$this->karma = $new->link_karma;
return true;
}
return false;
}
示例7: Vote
function insert_vote($value)
{
global $db, $current_user, $globals;
$vote = new Vote('links', $this->id, $current_user->user_id);
if ($vote->exists(true)) {
return false;
}
// For karma calculation
if ($this->status != 'published') {
if ($value < 0 && $current_user->user_id > 0) {
if ($globals['karma_user_affinity'] && $current_user->user_id != $this->author && ($affinity = User::get_affinity($this->author, $current_user->user_id)) < 0) {
$karma_value = round(min(-5, $current_user->user_karma * $affinity / 100));
} else {
$karma_value = round(-$current_user->user_karma);
}
} else {
if ($globals['karma_user_affinity'] && $current_user->user_id > 0 && $current_user->user_id != $this->author && ($affinity = User::get_affinity($this->author, $current_user->user_id)) > 0) {
$karma_value = $value = round(max($current_user->user_karma * $affinity / 100, 5));
} else {
$karma_value = round($value);
}
}
} else {
$karma_value = 0;
}
$vote->value = $value;
$db->transaction();
if ($vote->insert()) {
if ($vote->user > 0) {
if ($value > 0) {
$r = $db->query("update links set link_votes=link_votes+1 where link_id = {$this->id}");
} else {
$r = $db->query("update links set link_negatives=link_negatives+1 where link_id = {$this->id}");
}
} else {
$r = $db->query("update links set link_anonymous=link_anonymous+1 where link_id = {$this->id}");
}
// For published links we update counter fields
if ($r && $this->status != 'published') {
// If not published we update karma and count all votes
$r = $db->query("update links set link_karma=link_karma+{$karma_value} where link_id = {$this->id}");
}
if (!$r) {
syslog(LOG_INFO, "failed transaction in Link::insert_vote: {$this->id} ({$r})");
$value = false;
} else {
// Update in memory object
if ($vote->user > 0) {
if ($value > 0) {
$this->votes += 1;
} else {
$this->negatives += 1;
}
} else {
$this->anonymous += 1;
}
// Update karma and check votes
if ($this->status != 'published') {
$this->karma += $karma_value;
$this->update_votes();
}
}
$db->commit();
} else {
$db->rollback();
$value = false;
}
return $value;
}
示例8: Vote
function insert_vote($user_id = false, $value = 0)
{
global $current_user, $db;
if (!$user_id) {
$user_id = $current_user->user_id;
}
if (!$value && $current_user->user_karma) {
$value = $current_user->user_karma;
}
$vote = new Vote('posts', $this->id, $user_id);
$vote->link = $this->id;
if ($vote->exists(true)) {
return false;
}
$vote->value = $value;
$db->transaction();
if ($r = $vote->insert()) {
if ($current_user->user_id != $this->author) {
$r = $db->query("update posts set post_votes=post_votes+1, post_karma=post_karma+{$value}, post_date=post_date where post_id={$this->id}");
}
}
$c = $db->commit();
if ($r && $c) {
return $vote->value;
}
syslog(LOG_INFO, "failed insert post vote for {$this->id}");
return false;
}
示例9: Vote
/**
* return "OK" only delete
* > 0 - usual behavior: first delete then insert
* 0 error
*/
function insert_vote($value = 0) {
global $current_user, $db;
if (!$value) $value = $current_user->user_karma;
$vote = new Vote('comments', $this->id, $current_user->user_id);
$result = 'CREATE'; // vote doesn't exits?
if ($old_value = $vote->exists(false)) { // save old vote value
$result = 'REPLACE';
$vote->delete_comment_vote($old_value); // always destroy current vote
// check if they have the same sign
if ($value * $old_value > 0) {
return Array('DELETE',$old_value); // equal => only delete
}
}
// Affinity
if ($current_user->user_id != $this->author
&& ($affinity = User::get_affinity($this->author, $current_user->user_id)) ) {
if ($value < -1 && $affinity < 0) {
$value = round(min(-1, $value * abs($affinity/100)));
} elseif ($value > 1 && $affinity > 0) {
$value = round(max($value * $affinity/100, 1));
}
}
$value>0?$svalue='+'.$value:$svalue=$value;
$vote->value = $value;
$db->transaction();
if($vote->insert()) {
if ($current_user->user_id != $this->author) {
//echo "update comments set comment_votes=comment_votes+1, comment_karma=comment_karma$svalue, comment_date=comment_date where comment_id=$this->id";
$db->query("update comments set comment_votes=comment_votes+1, comment_karma=comment_karma$svalue, comment_date=comment_date where comment_id=$this->id");
}
} else {
$vote->value = false;
}
$db->commit();
if ($result == 'CREATE') {
return Array($result, $vote->value);
} else { // replace
return Array($result, $old_value);
}
}
示例10: json_encode
$user->karma = $user->karma - 0.2;
$user->store();
error(_('¡tranquilo cowboy!, tu karma ha bajado: ') . $user->karma);
} else {
error(_('¡tranquilo cowboy!'));
}
}
$vote->value = $value * $current_user->user_karma;
$votes_info = $db->get_row("select post_user_id, post_votes, post_karma, UNIX_TIMESTAMP(post_date) as date from posts where post_id={$id}");
if ($votes_info->post_user_id == $current_user->user_id) {
error(_('no puedes votar a tus comentarios'));
}
if ($votes_info->date < time() - $globals['time_enabled_votes']) {
error(_('votos cerrados'));
}
if (!$vote->insert()) {
error(_('ya ha votado antes'));
}
$votes_info->post_votes++;
$votes_info->post_karma += $vote->value;
if ($vote->value > 0) {
$dict['image'] = $globals['base_static'] . 'img/common/vote-up-gy02.png';
} else {
$dict['image'] = $globals['base_static'] . 'img/common/vote-down-gy02.png';
}
$dict['id'] = $id;
$dict['votes'] = $votes_info->post_votes;
$dict['value'] = $vote->value;
$dict['karma'] = $votes_info->post_karma;
echo json_encode($dict);
$db->query("update posts set post_votes=post_votes+1, post_karma=post_karma+{$vote->value}, post_date=post_date where post_id={$id} and post_user_id != {$current_user->user_id}");
示例11: Vote
}
}
if ($skipthis == 0) {
echo "Importing <hr>";
$linkres->store();
tags_insert_string($linkres->id, $dblang, $linkres->tags);
require_once mnminclude . 'votes.php';
for ($i = 1; $i <= $feed->feed_votes; $i++) {
$value = 10;
$vote = new Vote();
$vote->type = 'links';
$vote->user = 0;
$vote->link = $linkres->id;
$vote->ip = '0.0.0.' . $i;
$vote->value = $value;
$vote->insert();
$vote = "";
$vote = new Vote();
$vote->type = 'links';
$vote->link = $linkres->id;
$linkres->votes = $vote->count();
$linkres->store_basic();
$linkres->check_should_publish();
}
$thecount = $thecount + 1;
}
}
$sql = "Update `" . table_prefix . "feeds` set `feed_last_check` = FROM_UNIXTIME(" . (time() - 300) . ") where `feed_id` = {$feed->feed_id};";
//echo $sql;
$db->query($sql);
} else {
示例12: _
$vote->user=$user_id;
if($vote->exists()) {
error(_('Ya ha votado antes'));
}
$votes_freq = $db->get_var("select count(*) from votes where vote_type='links' and vote_user_id=$current_user->user_id and vote_date > from_unixtime(unix_timestamp(now())-30) and vote_ip = '".$globals['user_ip']."'");
if ( $globals['interface'] == "digg" ) {
if ($current_user->user_id > 0) $freq = 2;
else $freq = 2;
} elseif ($globals['interface'] == "monouser" ) {
$freq = 1000;
}
if ($votes_freq > $freq) {
error(_('¡tranquilo cowboy!'));
}
$vote->value = $value;
if($link->status == 'published' || !$vote->insert()) {
error(_('Error insertando voto'));
}
echo _('Será tomado en cuenta, gracias');
function error($mess) {
echo "ERROR:$mess";
die;
}
?>
示例13: Vote
function insert_vote($user = 0, $value = 10)
{
global $anon_karma;
require_once mnminclude . 'votes.php';
if ($value > 10) {
$value = 10;
}
$vote = new Vote();
$vote->type = 'links';
$vote->user = $user;
$vote->link = $this->id;
$vote->value = $value;
// if($value<10) {$vote->value=($anon_karma/10)*$value;}
if ($user > 0) {
require_once mnminclude . 'user.php';
$dbuser = new User($user);
if ($dbuser->id > 0) {
$vote->karma = $dbuser->karma;
}
} elseif (!anonymous_vote) {
return;
} else {
$vote->karma = $anon_karma;
}
if ($vote->insert()) {
$vote = new Vote();
$vote->type = 'links';
$vote->link = $this->id;
if (Voting_Method == 1) {
$this->votes = $vote->count();
$this->reports = $this->count_all_votes("<0");
} elseif (Voting_Method == 2) {
$this->votes = $vote->rating();
$this->votecount = $vote->count();
$this->reports = $this->count_all_votes("<0");
} elseif (Voting_Method == 3) {
$this->votes = $vote->count();
$this->votecount = $vote->count();
$this->karma = $vote->karma();
$this->reports = $this->count_all_votes("<0");
}
$this->store_basic();
$this->check_should_publish();
/***** This code was to update the user_karma with the value of "Voted on an article" when the auto vote is set to true upon story submission. It was causing double update of the user_karma upon voting. We provisioned a new code in /module/karma_main.php in the karma_do_submit3 function *****/
//$vars = array('vote' => $this);
//check_actions('link_insert_vote_post', $vars);
return true;
}
return false;
}
示例14: Vote
function insert_vote()
{
global $current_user;
require_once mnminclude . 'votes.php';
$vote = new Vote();
$vote->user = $current_user->user_id;
$vote->type = 'posts';
$vote->link = $this->id;
if ($vote->exists()) {
return false;
}
$vote->value = $current_user->user_karma;
if ($vote->insert()) {
return true;
}
return false;
}
示例15: Vote
function insert_vote($value = 0)
{
global $current_user, $db;
if (!$value) {
$value = $current_user->user_karma;
}
$vote = new Vote('comments', $this->id, $current_user->user_id);
// Affinity
if ($current_user->user_id != $this->author && ($affinity = User::get_affinity($this->author, $current_user->user_id))) {
if ($value < -1 && $affinity < 0) {
$value = round(min(-1, $value * abs($affinity / 100)));
} elseif ($value > 1 && $affinity > 0) {
$value = round(max($value * $affinity / 100, 1));
}
}
if ($vote->exists(true)) {
return false;
}
$vote->value = $value;
$db->transaction();
if ($r = $vote->insert()) {
if ($current_user->user_id != $this->author) {
$r = $db->query("update comments set comment_votes=comment_votes+1, comment_karma=comment_karma+{$value}, comment_date=comment_date where comment_id={$this->id}");
}
}
if ($r && $db->commit()) {
return $vote->value;
}
syslog(LOG_INFO, "failed insert comment vote for {$this->id}");
return false;
}