Esempio n. 1
0
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';
    }
}
Esempio n. 2
0
 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);
 }
 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;
 }
 /**
  * Show the special page
  *
  * @param $par Mixed: parameter passed to the special page or null
  */
 public function execute($par)
 {
     global $wgOut, $wgUser, $wgRequest, $wgContLang;
     // If the user can't create blog posts, display an error
     if (!$wgUser->isAllowed('createblogpost')) {
         $wgOut->permissionRequired('createblogpost');
         return;
     }
     // Show a message if the database is in read-only mode
     if (wfReadOnly()) {
         $wgOut->readOnlyPage();
         return;
     }
     // If user is blocked, s/he doesn't need to access this page
     if ($wgUser->isBlocked()) {
         $wgOut->blockedPage(false);
         return false;
     }
     // Set page title, robot policies, etc.
     $this->setHeaders();
     // Add CSS & JS
     $wgOut->addModules('ext.blogPage.create');
     // If the request was POSTed, we haven't submitted a request yet AND
     // we have a title, create the page...otherwise just display the
     // creation form
     if ($wgRequest->wasPosted() && $_SESSION['alreadysubmitted'] == false) {
         $_SESSION['alreadysubmitted'] = true;
         // 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);
     }
 }
Esempio n. 5
0
	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;
	}
Esempio n. 6
0
 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;
 }
Esempio n. 7
0
 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;
 }
Esempio n. 8
0
 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;
 }
Esempio n. 9
0
  /**
   * 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);
    }
	}
Esempio n. 10
0
        $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}");
Esempio n. 11
0
             }
         }
         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 {
Esempio n. 12
0
$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;
}
?>
Esempio n. 13
0
 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;
 }
Esempio n. 14
0
 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;
 }
Esempio n. 15
0
 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;
 }
Esempio n. 16
0
 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
     $status = !empty($this->sub_status) ? $this->sub_status : $this->status;
     $vote_value = $value > 0 ? $value : -$current_user->user_karma;
     $karma_value = round($vote_value);
     /******* Simplified, it doesn't make much sense with subs
     		if ($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($vote_value);
     				}
     			} 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($vote_value);
     				}
     			}
     		} else {
     			$karma_value=round($vote_value);
     		}
     */
     $vote->value = $value;
     $db->transaction();
     if ($vote->insert()) {
         if ($vote->user > 0) {
             if ($value > 0) {
                 $what = 'link_votes=link_votes+1';
             } else {
                 $what = 'link_negatives=link_negatives+1';
             }
         } else {
             $what = 'link_anonymous=link_anonymous+1';
         }
         $r = $db->query("update links set {$what}, 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 ($status != 'published') {
                 $this->karma += $karma_value;
                 $this->update_votes();
             }
         }
         $db->commit();
     } else {
         $db->rollback();
         $value = false;
     }
     return $value;
 }
Esempio n. 17
0
	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($vote->insert()) {
			if ($current_user->user_id != $this->author) {
				$db->query("update posts set post_votes=post_votes+1, post_karma=post_karma+$value, post_date=post_date where post_id=$this->id");
			}
		} else {
			$vote->value = false;
		}
		$db->commit();
		return $vote->value;
	}
function do_the_import_stuff($feed)
{
    global $db, $dblang, $RSSImport;
    $RSSImport = new RSSImport();
    $added_one = false;
    $url = $feed->feed_url;
    $rss = fetch_rss($url);
    if ($_GET['override'] == $feed->feed_id) {
        $canIhaveAccess = 0;
        $canIhaveAccess = $canIhaveAccess + checklevel('god');
        if (!$canIhaveAccess == 1) {
            die('You are not authorized to override.');
        }
    }
    $MyArray = array();
    $Feed_Links = $RSSImport->get_feed_field_links($feed->feed_id);
    if (count($Feed_Links) > 0) {
        foreach ($Feed_Links as $link) {
            if ($link->pligg_field == 'link_title') {
                $MyArray['title'] = $link->feed_field;
            }
            if ($link->pligg_field == 'link_content') {
                $MyArray['content'] = $link->feed_field;
            }
            if ($link->pligg_field == 'link_url') {
                $MyArray['link_url'] = $link->feed_field;
            }
            if ($link->pligg_field == 'link_tags') {
                $MyArray['link_tags'] = $link->feed_field;
            }
            if ($link->pligg_field == 'link_field1') {
                $MyArray['link_field1'] = $link->feed_field;
            }
            if ($link->pligg_field == 'link_field2') {
                $MyArray['link_field2'] = $link->feed_field;
            }
            if ($link->pligg_field == 'link_field3') {
                $MyArray['link_field3'] = $link->feed_field;
            }
            if ($link->pligg_field == 'link_field4') {
                $MyArray['link_field4'] = $link->feed_field;
            }
            if ($link->pligg_field == 'link_field5') {
                $MyArray['link_field5'] = $link->feed_field;
            }
            if ($link->pligg_field == 'link_field6') {
                $MyArray['link_field6'] = $link->feed_field;
            }
            if ($link->pligg_field == 'link_field7') {
                $MyArray['link_field7'] = $link->feed_field;
            }
            if ($link->pligg_field == 'link_field8') {
                $MyArray['link_field8'] = $link->feed_field;
            }
            if ($link->pligg_field == 'link_field9') {
                $MyArray['link_field9'] = $link->feed_field;
            }
            if ($link->pligg_field == 'link_field10') {
                $MyArray['link_field10'] = $link->feed_field;
            }
            if ($link->pligg_field == 'link_field11') {
                $MyArray['link_field11'] = $link->feed_field;
            }
            if ($link->pligg_field == 'link_field12') {
                $MyArray['link_field12'] = $link->feed_field;
            }
            if ($link->pligg_field == 'link_field13') {
                $MyArray['link_field13'] = $link->feed_field;
            }
            if ($link->pligg_field == 'link_field14') {
                $MyArray['link_field14'] = $link->feed_field;
            }
            if ($link->pligg_field == 'link_field15') {
                $MyArray['link_field15'] = $link->feed_field;
            }
        }
        $thecount = 0;
        if ($feed->feed_last_item_first == 0) {
            $the_items = array_reverse($rss->items);
        } else {
            $the_items = $rss->items;
        }
        foreach ($the_items as $item) {
            echo "<strong>Title: " . get_val($item, $MyArray['title']) . "</strong><br/>";
            echo "<strong>Content:</strong> " . strip_tags(substr(get_val($item, $MyArray['content']), 0, 256)) . "...<br>";
            echo "<strong>URL:</strong> " . get_val($item, $MyArray['link_url']) . "<br/>";
            $skipthis = 0;
            $linkres = new Link();
            $linkres->randkey = rand(10000, 10000000);
            $linkres->status = $feed->feed_status;
            $linkres->author = $feed->feed_submitter;
            $linkres->title = get_val($item, $MyArray['title']);
            $linkres->title = strip_tags($linkres->title);
            $linkres->tags = get_val($item, $MyArray['link_tags']);
            // MJE: MOD to include title words as tags ----------------------------
            if (trim($linkres->tags) == '') {
                $temp1 = strtolower($linkres->title);
                $stopwords = file(mnmpath . '/modules/rss_import/templates/stopwords.txt');
                for ($zz = 0; $zz < count($stopwords); $zz++) {
                    $pos = strpos($temp1, $stopwords[$zz] . ' ');
                    if ($pos !== false && $pos == 0) {
                        $temp1 = str_replace(trim($stopwords[$zz]) . ' ', ' ', $temp1);
                    }
                    $temp1 = str_replace(' ' . trim($stopwords[$zz]) . ' ', ' ', $temp1);
                }
                $pos = strpos($temp1, '  ');
                while ($pos !== false) {
                    $temp1 = str_replace('  ', ' ', $temp1);
                    $pos = strpos($temp1, '  ');
                }
                $temp1 = str_replace(' ', ", ", $temp1);
                // $out = ereg_replace("[^[:alpha:]]", "", $in);
                // strip all except letters and spaces and commas
                $linkres->tags = preg_replace('/[^a-z A-Z,]+/i', '', $temp1);
            }
            //----------------------------------------------------------------------
            if (checklevel('god')) {
                $Story_Content_Tags_To_Allow = Story_Content_Tags_To_Allow_God;
            } elseif (checklevel('admin')) {
                $Story_Content_Tags_To_Allow = Story_Content_Tags_To_Allow_Admin;
            } else {
                $Story_Content_Tags_To_Allow = Story_Content_Tags_To_Allow_Normal;
            }
            $linkres->title_url = makeUrlFriendly($linkres->title);
            $linkres->url = get_val($item, $MyArray['link_url']);
            $linkres->url_title = $linkres->title;
            $linkres->content = get_val($item, $MyArray['content']);
            $linkres->content = strip_tags($linkres->content, $Story_Content_Tags_To_Allow);
            $linkres->content = str_replace("\n", "<br />", $linkres->content);
            $linkres->link_field1 = get_val($item, $MyArray['link_field1']);
            $linkres->link_field2 = get_val($item, $MyArray['link_field2']);
            $linkres->link_field3 = get_val($item, $MyArray['link_field3']);
            $linkres->link_field4 = get_val($item, $MyArray['link_field4']);
            $linkres->link_field5 = get_val($item, $MyArray['link_field5']);
            $linkres->link_field6 = get_val($item, $MyArray['link_field6']);
            $linkres->link_field7 = get_val($item, $MyArray['link_field7']);
            $linkres->link_field8 = get_val($item, $MyArray['link_field8']);
            $linkres->link_field9 = get_val($item, $MyArray['link_field9']);
            $linkres->link_field10 = get_val($item, $MyArray['link_field10']);
            $linkres->link_field11 = get_val($item, $MyArray['link_field11']);
            $linkres->link_field12 = get_val($item, $MyArray['link_field12']);
            $linkres->link_field13 = get_val($item, $MyArray['link_field13']);
            $linkres->link_field14 = get_val($item, $MyArray['link_field14']);
            $linkres->link_field15 = get_val($item, $MyArray['link_field15']);
            $linkres->category = $feed->feed_category;
            //MJE: MOD
            $linkres->link_summary = utf8_substr(strip_tags($linkres->content), 0, StorySummary_ContentTruncate - 1);
            //---------
            if ($thecount >= $feed->feed_item_limit && $skipthis == 0) {
                echo "Reached import limit, skipping<HR>";
                $skipthis = 1;
            }
            if ($feed->feed_title_dupe == 0 && $skipthis == 0) {
                // 0 means don't allow, 1 means allow
                if ($linkres->duplicates_title($linkres->title) > 0) {
                    //echo "Title Match, skipping: " . $linkres->title . "<HR>";
                    echo '<span style="color:#fc0000;">Title Match, skipping</span> <hr>';
                    $skipthis = 1;
                }
            }
            if ($feed->feed_url_dupe == 0 && $linkres->url != "" && $skipthis == 0) {
                // 0 means don't allow, 1 means allow
                if ($linkres->duplicates($linkres->url) > 0) {
                    //echo "URL Match, skipping: " . $linkres->title . "<HR>";
                    echo '<span style="color:#fc0000;">URL Match, skipping</span> <hr>';
                    $skipthis = 1;
                }
            }
            if ($skipthis == 0) {
                echo "Importing <hr>";
                $added_one = true;
                $linkres->store();
                totals_adjust_count($linkres->status, 1);
                tags_insert_string($linkres->id, $dblang, $linkres->tags);
                require_once mnminclude . 'votes.php';
                if ($feed->feed_random_vote_enable == 1) {
                    $feed->feed_votes = rand($feed->feed_random_vote_min, $feed->feed_random_vote_max);
                }
                $votes = 0;
                for ($i = 1; $i <= $feed->feed_votes; $i++) {
                    $value = 1;
                    $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 = "";
                    $votes += $value;
                    //								$vote = new Vote;
                    //								$vote->type='links';
                    //								$vote->link=$linkres->id;
                }
                $linkres->votes = $votes;
                $linkres->store_basic();
                $linkres->check_should_publish();
                $thecount = $thecount + 1;
            }
        }
        $sql = "UPDATE `" . table_feeds . "` SET `feed_last_check` = FROM_UNIXTIME(" . (time() - 300) . ") WHERE `feed_id` = {$feed->feed_id};";
        //echo $sql;
        $db->query($sql);
    } else {
        echo "Feed not fully setup, skipping <hr>";
    }
    if ($added_one) {
        return true;
    } else {
        return false;
    }
}
Esempio n. 19
0
	function insert_vote($value, $former_value = null) {
		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 ($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 ($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;
		}


    // former_value only for negatives
    if ($former_value != null) {
      $vote->value=$former_value;
      $karma_value = $karma_value /3;
    } else {
      $vote->value=$value;
    }

		$db->transaction();
		if($vote->insert()) {
			// For published links we update counter fields
			if ($this->status == 'published') {
				if ($vote->user > 0) {
					if ($value > 0) {
						$db->query("update links set link_votes=link_votes+1 where link_id = $this->id");
					} else {
						$db->query("update links set link_negatives=link_negatives+1 where link_id = $this->id");
					}
				} else {
					$db->query("update links set link_anonymous=link_anonymous+1 where link_id = $this->id");
				}
			} else {
				// If not published we update karma and count all votes
				$db->query("update links set link_karma=link_karma+$karma_value where link_id = $this->id");
				$this->update_votes();
			}
			$db->commit();
			$this->read_basic();
		} else {
			$db->commit();
			$value = false;
		}
		return $value;
	}
Esempio n. 20
0
 function insert_vote($user = 0, $value = 10)
 {
     global $anon_karma;
     require_once mnminclude . 'votes.php';
     if (!is_numeric($this->id)) {
         return false;
     }
     $vote = new Vote();
     $vote->type = 'comments';
     $vote->user = $user;
     $vote->link = $this->id;
     $vote->value = $value;
     if ($vote->insert()) {
         $vote = new Vote();
         $vote->type = 'comments';
         $vote->link = $this->id;
         $this->votes = $vote->count();
         $vars = array('vote' => $this);
         check_actions('comment_insert_vote_post', $vars);
         return $vote->sum();
     }
     return false;
 }
Esempio n. 21
0
 function insert_vote($user = 0, $value = 10)
 {
     global $anon_karma;
     require_once mnminclude . 'votes.php';
     if (!is_numeric($this->id)) {
         return false;
     }
     $vote = new Vote();
     $vote->type = 'comments';
     $vote->user = $user;
     $vote->link = $this->id;
     $vote->value = $value;
     if ($vote->insert()) {
         $vote = new Vote();
         $vote->type = 'comments';
         $vote->link = $this->id;
         $this->votes = $vote->count() - $vote->count('<0');
         if (comment_buries_spam > 0 && $vote->count_all("<0") >= comment_buries_spam) {
             $this->status = 'discard';
             $this->store();
             $vars = array('comment_id' => $this->id);
             check_actions('comment_spam', $vars);
             require_once mnminclude . 'link.php';
             $link = new Link();
             $link->id = $this->link;
             $link->read();
             $link->recalc_comments();
             $link->store();
         }
         $vars = array('vote' => $this);
         check_actions('comment_insert_vote_post', $vars);
         return $vote->sum();
     }
     return false;
 }
Esempio n. 22
0
 function insert_vote($user = 0, $value = 10)
 {
     global $anon_karma;
     require_once mnminclude . 'votes.php';
     $vote = new Vote();
     $vote->type = 'comments';
     $vote->user = $user;
     $vote->link = $this->id;
     $vote->value = $value;
     if ($vote->insert()) {
         $vote = new Vote();
         $vote->type = 'comments';
         $vote->link = $this->id;
         $this->votes = $vote->count();
         return $vote->sum();
     }
     return false;
 }
Esempio n. 23
0
 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();
         $vars = array('vote' => $this);
         check_actions('link_insert_vote_post', $vars);
         return true;
     }
     return false;
 }
Esempio n. 24
0
 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) {
             if ($value < 10) {
                 $vote->value = $dbuser->karma / 10 * $value;
             }
         }
     } else {
         if (!anonymous_vote) {
             return;
         }
     }
     if ($vote->insert()) {
         $vote = new Vote();
         $vote->type = 'links';
         $vote->link = $this->id;
         if (Voting_Method == 1) {
             $this->votes = $vote->sum();
         }
         if (Voting_Method == 2) {
             $this->votes = $vote->rating();
             $this->votecount = $vote->sum();
         }
         $this->store_basic();
         /*********
         			//
         			// check karma
         			//
         			***********/
         $this->check_should_publish();
         return true;
     }
     return false;
 }