function recordReferral($referid = 0, $action = '', $itemid = 0) { // record the referral in the log // $this->session->userid was referred to $action page by $referid userid, $itemid may be siteContentId // action may be referReader or referToSite if ($this->session->isLoaded and $this->session->userid != 0) { // log referid as having referred this user require_once PATH_CORE . '/classes/log.class.php'; $logObj = new log($this->db); $logItem = $logObj->serialize(0, $referid, $action, $itemid, $this->session->userid); $inLog = $logObj->update($logItem); // check if UserInfo.refuid has not been set before if ($this->session->u->refuid == 0) { // load the userinfo for this user $this->session->ui->refuid = $referid; $this->session->ui->update(); } // sign up page will use refuid to mark invites as accepted } }
function ajaxIdeaRecordLike($isSessionValid = false, $userid = 0, $id = 0) { //$this->db->log('inside ajaxidearecordlike'); if ($isSessionValid) { require_once PATH_CORE . '/classes/log.class.php'; $logObj = new log($this->db); // record the like in the log $logItem = $logObj->serialize(0, $userid, 'likeIdea', $id); $inLog = $logObj->update($logItem); if ($inLog) { $iTable = new ideasTable($this->db); $ir = $iTable->getRowObject(); $ir->load($id); $ir->numLikes += 1; $ir->update(); $code = '<a href="#" class="voteLink" onclick="return ideaRecordLike(' . $id . ');" title="like this idea">Like</a> ' . $ir->numLikes; } else { $code = 'You already liked this!'; } } else { $code = '<a href="' . URL_CANVAS . '?p=ideas" requirelogin="******">Please authorize ' . SITE_TITLE . ' with Facebook before continuing.</a>'; } return $code; }
$itemid = $_GET['itemid']; } else { $itemid = 0; } if ($userid == 0) { $error = true; $errorMsg = 'No user id'; } else { } switch ($mode) { case 'wire': // publish a wire story require_once $_SERVER['DOCUMENT_ROOT'] . "/newsroom/core/classes/log.class.php"; $logObj = new log($fb->db); $info = $logObj->serialize(0, $userid, 'publishWire', $itemid); $logObj->update($info); $storyOption = '<li><a href="?p=read&cid=' . $contentid . '" target="_cts">Read the story</a></li>'; break; case 'ncStory': // publish a journal story $fb->publishNewsCloudStory('publishStory', $itemid); $contentid = $itemid; $storyOption = '<li><a href="?p=read&cid=' . $contentid . '" target="_cts">Read the story</a></li>'; break; } if (!$error) { $code = '<div id="dialogMessage"><p>Your story has been published successfully.</p><p>What would you like to do next?</p>'; $code .= '<ul><li><a href="?p=read&cid=' . $contentid . '" onclick="hideDialog(); readStory(' . $contentid . ');return false;">Add a comment</a></li>' . $storyOption . '<li><a href="#" onclick="hideDialog(); return shareStory(this,' . $cid . ');">Share story with friends</a>Share story with friends</a></li><li><a href="?p=invite" onclick="hideDialog(); switchPage(\'invite\',\'\');return false;">Invite friends to ' . SITE_TITLE . '</a></li></ul></div>'; } else { $code = '<div id="dialogMessage">Sorry, there was a problem publishing your story. Error: ' . $errorMsg . '</div>'; }
function buildSend() { $code .= '<div >'; if (isset($_GET['submit'])) { $this->db->log($_POST); //validate form $errorMessage = ''; if (sizeof($_POST['ids']) < 1) { $errorMessage = 'Please specify someone to send the ' . CARDS_NAME . ' to!'; } else { if ($_POST['pickCard'] == '' or $_POST['pickCard'] == 0) { $errorMessage = ' You must select a ' . CARDS_NAME . '!'; } } if ($errorMessage != '') { $msgType = 'error'; $title = 'There was a problem...'; $message = $errorMessage; } else { $postMsg = $_POST['msg']; if ($postMsg == $defaultMsg) { $postMsg = ''; } // reset default msg to blank $checkDuplicate = $this->cardsObj->checkResubmit($this->session->userid, $_POST['pickCard'], $_POST['ids']); if (!$checkDuplicate) { // look up card name $q = $this->db->query("SELECT name FROM Cards WHERE id={$_POST['pickCard']};"); $ci = $this->db->readQ($q); require_once PATH_CORE . '/classes/log.class.php'; $logObj = new log($this->db); foreach ($_POST['ids'] as $id) { // record sendCard in log table $logItem = $logObj->serialize(0, $this->session->userid, 'sendCard', $_POST['pickCard'], $id); $inLog = $logObj->update($logItem); $lastId = $logObj->db->getId(); if (is_numeric($lastId)) { // add postMsg to logExtra $xTable = new LogExtraTable($this->db); $le = $xTable->getRowObject(); $le->logid = $lastId; $le->txt = $postMsg; $le->insert(); } $noteMsg = ' sent you a <a href="' . URL_CANVAS . '?p=cards&o=display&id=' . $lastId . '&sid=' . $this->session->userid . '">' . $ci->name . ' ' . CARDS_NAME . '</a> via <a href="' . URL_CANVAS . '">' . SITE_TITLE . '</a>'; $apiResult = $this->page->app->facebook->api_client->notifications_send($id, $noteMsg, 'user_to_user'); } $message = ''; // success - display msg in $code directly $code .= $this->cardsObj->makeFancyTitle(CARDS_NAME . ' SENT SUCCESSFULLY', '500px'); $rxList = $this->templateObj->buildFacebookUserList('', $_POST['ids']); $code .= $this->cardsObj->makeOneCard($_POST['pickCard'], $postMsg, $rxList); $code .= '<h2><a href="?p=cards&o=send" requirelogin="******">Click here to send another ' . CARDS_NAME . '</h2></a>'; $code .= '<br><h2><a href="?p=cards&o=tx">Click here to see all the ' . CARDS_NAME . 's you have sent.</h2></a>'; $code .= '</div>'; return $code; } else { $msgType = 'error'; $title = 'There was a problem...'; $message = "<b>You have already sent that " . CARDS_NAME . " to one or more of these people.</b>"; } } } if ($message != '') { $code .= $this->page->buildMessage($msgType, $title, $message); } // prefill is user to send to if (isset($_GET['prefillId'])) { $prefillId = $_GET['prefillId']; } else { $prefillId = 0; } $code .= $this->cardsObj->buildSendForm($prefillId); $code .= '</div>'; return $code; }
function updateUserLevels($limit = 100) { // scan every use account and adjust the user level to match their cached points require_once PATH_CORE . '/classes/user.class.php'; if ($limit == 0) { $useridList = $this->db->query("SELECT SQL_CALC_FOUND_ROWS\tuserid FROM UserInfo;"); // $this->page->rowsPerPage } else { $useridList = $this->db->query("SELECT SQL_CALC_FOUND_ROWS\tuserid FROM UserInfo ORDER BY lastUpdateLevels ASC LIMIT 0,{$limit}"); // $this->page->rowsPerPage } $userTable = new UserTable($this->db); $userInfoTable = new UserInfoTable($this->db); $user = $userTable->getRowObject(); $userinfo = $userInfoTable->getRowObject(); $userLevels = $this->setUserLevels(); $pointLevels = $userLevels->pointLevels; $nameLevels = array_keys($userLevels->nameLevels); $this->log('<pre>' . print_r($pointLevels, true) . print_r($nameLevels, true) . '</pre>'); $levels = array_combine($pointLevels, $nameLevels); $this->log('updateUserLevels...'); if ($this->db->countQ($useridList) > 0) { while ($data = $this->db->readQ($useridList)) { if ($user->load($data->userid) && $userinfo->load($data->userid)) { $x = 0; if (is_array($levels)) { foreach ($levels as $val => $name) { if ($user->cachedPointsEarned >= $val) { $userLevel = $name; $pointLevel = $val; $votePower = $userLevels->votePowerLevels[$x]; } $x += 1; } } // minor hack: assume user levels only increase. deducting earned points would require revoking challenges // also, the limit on redemptions of the levelIncrease challenge should limit potential for abuse // AND checking for duplicate log entries with itemid=pts will also prevent multiple level ups at the same level if ($user->userLevel != $userLevel && $userLevel != $nameLevels[0]) { require_once PATH_CORE . '/classes/log.class.php'; $log = new log($this->db); $log->update($log->serialize(0, $user->userid, 'levelIncrease', array_search($pointLevel, $pointLevels), 0)); $user->votePower = $votePower; $this->db->log('VotePower increase ' . $user->userid . ' ' . $userLevel . ' ' . $votePower); } $user->userLevel = $userLevel; $user->update(); $userinfo->lastUpdateLevels = date('Y-m-d H:i:s', time()); $userinfo->update(); //$this->log('updated user '. $data->userid.'<br/>'); } else { $this->log('updateUserLevels: couldnt load user ' . $data->userid); } } } else { $this->log('updateUserLevels: got no user records!'); } }
/* process request variables */ if (isset($_GET['permalink'])) { $permalink = $_GET['permalink']; } else { // go to 404 error page header("Location: " . URL_ROOT); exit; } $story = $cObj->getByPermalink($permalink); // record story read by this user if ($db->ui->isLoggedIn) { require_once PATH_CORE . '/classes/log.class.php'; $logObj = new log(&$db); $logItem = $logObj->serialize(0, $db->ui->userid, 'readStory', $story->siteContentId); // note this is the local contentid $logObj->update($logItem); } /* begin building the page */ $page->setTitle($story->title); $page->pkgStyles(CACHE_PREFIX . 'nrStory', array(PATH_PHP_STYLES . '/newsroom.css', PATH_PHP_STYLES . '/tabs.css')); $page->pkgScripts(CACHE_PREFIX . 'nrStory', array(PATH_PHP_SCRIPTS . '/comments.js', PATH_PHP_SCRIPTS . '/voting.js', PATH_PHP_SCRIPTS . '/journal.js')); $page->addToHeader($common->buildHeader() . $common->buildNavigation('Read Story')); $page->addToFooter($common->buildFooter()); $page->addRSSFeed(URL_HOME . '?p=rss'); $code = ''; $code .= '<div id="pageBody">'; $code .= '<div id="pageContent">'; $templateObj->registerTemplates('PHP'); /* fetch story */ $templateObj->db->result = $cObj->getByPermalink($permalink, true); $templateObj->db->setTemplateCallback('time_since', array($utilObj, 'time_since'), 'date');
function logWinner($userid, $prizeid) { require_once PATH_CORE . '/classes/log.class.php'; $log = new log(); $db = $log->db; $log->update($log->serialize(0, $userid, 'wonPrize', $prizeid, 0)); }
function fetch($option = 'comments', $cid = 0) { // to do - remove, temp for vanishteam if (CACHE_PREFIX == 'van' and !$this->session->isAppAuthorized) { $fHandle = fopen(PATH_SERVER_LOGS . 'edr.log', 'a'); fwrite($fHandle, 'Required to authorize:' . $_SERVER['HTTP_X_FB_USER_REMOTE_ADDR'] . "\n"); $this->facebook = $this->session->app->loadFacebookLibrary(); $user = $this->facebook->require_login(); } // build the read story page require_once PATH_CORE . '/classes/read.class.php'; $readObj = new read($this->db, $this->session); $readObj->setPageLink($this); require_once PATH_FACEBOOK . '/classes/actionTeam.class.php'; $this->teamObj = new actionTeam($this->page); if (isset($_GET['cid']) and !is_numeric($_GET['cid'])) { $this->page->decloak(); } if ($cid == 0) { // need for ajax readStory script if (isset($_GET['cid']) and is_numeric($_GET['cid'])) { $cid = $_GET['cid']; } else { exit('error2'); } } $referid = $this->page->fetchReferral(); if ($referid !== false && is_numeric($referid)) { // record chat action if (isset($_GET['chat'])) { if (!$this->session->isAppAuthorized) { // require authorization so we can get their fbId - redirs to signup $this->facebook = $this->session->app->loadFacebookLibrary(); $user = $this->facebook->require_login(); } if (isset($_POST['fb_sig_added']) and $_POST['fb_sig_added'] == 1) { $targetfbId = $_POST['fb_sig_user']; } else { if (isset($_POST['fb_sig_canvas_user'])) { $targetfbId = $_POST['fb_sig_canvas_user']; } else { $targetfbId = 0; } } // make sure the referer is not clicking on the link themselves if ($targetfbId != 0 and $referid != $this->session->userid) { // log referid as having referred this user require_once PATH_CORE . '/classes/log.class.php'; $logObj = new log($this->db); $logItem = $logObj->serialize(0, $referid, 'chatStory', $cid, $targetfbId); $inLog = $logObj->update($logItem); } } // check for notification and display it if ($this->session->isLoaded and $referid != $this->session->userid) { // reader was referred here by someone require_once PATH_CORE . '/classes/notifications.class.php'; $notificationsTable = new NotificationsTable($this->db); $msgid = $notificationsTable->lookupReferral($referid, $cid, $this->session->fbId); if ($msgid !== false and $msgid != '' and !is_null($msgid)) { $notificationsTable->setStatus($msgid, $this->session->fbId, 'opened'); // get fbId from userid require_once PATH_CORE . '/classes/user.class.php'; $uit = new UserInfoTable($this->db); $ui = $uit->getRowObject(); $ui->load($referid); $msgTable = new NotificationMessagesTable($this->db); $msg = $msgTable->getRowObject(); // load the message $msg->load($msgid); // cast msg object into comment property array for token replacement $referObj = array(); $referObj[fbId] = $ui->fbId; $referObj[userid] = $referid; $referObj[comments] = $msg->message; $referObj[date] = $msg->dateCreated; $referMsg = $readObj->fetchReferComment($referObj); } } $this->page->recordReferral($referid, 'referReader', $cid); } if (isset($_GET['viaBookmarklet'])) { //$inside.='<script type="text/javascript">function closeWindow() {window.opener = self;window.close();}</script><a href="#" onclick="closeWindow();">test</a>'; //$inside.=$this->page->buildMessage('success','Your story has been posted','Click here if you wish to <a href="#" onclick="closeWindow();">close this window</a>.'); } else { if (isset($_GET['justPosted'])) { // to do: put some options here } } $inside .= '<div id="col_left"><!-- begin left side -->'; $inside .= $referMsg; $inside .= $readObj->fetchReadStory($cid, $option); $inside .= '</div><!-- end left side -->'; $inside .= '<div id="col_right">'; if ($this->session->isAdmin) { $inside .= '<div class="panel_1"><div class="panelBar clearfix">'; $inside .= '<h2>Administrative Options</h2>'; $inside .= '</div><!-- end panelBar -->'; $inside .= '<div class="panel_block">'; $inside .= '<ul><li><span id="banStoryPoster"><a href="#" onclick="banStoryPoster(' . $cid . ');return false;">Ban Member</a></span></li></ul>'; // <span id="blockStory"><a href="#" onclick="blockStory('.$cid.');return false;">Block story</a></span><span class="pipe">|</span> $inside .= '</div><!-- end panel_block --></div><!-- end panel_1 -->'; } $inside .= $readObj->fetchReadSidePanel($cid, $this->session, $this->page->isAjax); if (defined('ADS_ANY_SIDEBAR_BOTTOM')) { $inside .= str_replace("{ad}", '<fb:iframe src="' . URL_CALLBACK . '?p=cache&m=ad&locale=anySidebarBottom" frameborder="0" scrolling="no" style="width:180px;height:600px;padding:0px;margin:-5px 0px 0px 0px;"/>', $this->common['adWrapTallSidebar']); } $inside .= '</div> <!-- end right side -->'; if ($this->page->isAjax) { return $inside; } $code .= '<input type="hidden" id="filter" value="default">'; $code .= $this->page->constructPage('read', $inside); return $code; }
} } else { $code .= SIGNIN_LINK; } } else { $error = true; } break; case 'publishWire': if (isset($_GET['itemid'])) { $itemid = $_GET['itemid']; if ($db->ui->isLoggedIn) { require_once PATH_CORE . '/classes/log.class.php'; $logObj = new log($db); $logItem = $logObj->serialize(0, $db->ui->userid, 'publishWire', $itemid); $inLog = $logObj->update($logItem); if ($inLog) { $code = 'Story published!'; } else { $code = 'Story already published!'; } // create temporary content item, temp permalink require_once PATH_CORE . '/classes/newswire.class.php'; $nwObj = new newswire($db); $db->log('call tempcontent'); $siteContentId = $nwObj->createTempContent($db->ui, $itemid); // add to user's journal if ($siteContentId !== false) { // add to journal $logItem = $logObj->serialize(0, $db->ui->userid, 'publishStory', $siteContentId); $inLog = $logObj->update($logItem);
function ajaxAskRecordLike($isSessionValid = false, $mode = 'question', $userid = 0, $id = 0) { if ($isSessionValid) { require_once PATH_CORE . '/classes/log.class.php'; $logObj = new log($this->db); if ($mode == 'question') { // record the like in the log $logItem = $logObj->serialize(0, $userid, 'likeQuestion', $id); $inLog = $logObj->update($logItem); if ($inLog) { $aqTable = new askQuestionsTable($this->db); $qr = $aqTable->getRowObject(); $qr->load($id); $qr->numLikes += 1; $qr->update(); $code = '<a href="#" class="voteLink" onclick="return askRecordLike(\'' . $mode . '\',' . $id . ');" title="like this question">Like</a> ' . $qr->numLikes; } else { $code = 'You already liked this!'; } } else { // mode : answer $logItem = $logObj->serialize(0, $userid, 'likeAnswer', $id); $inLog = $logObj->update($logItem); if ($inLog) { $aaTable = new askAnswersTable($this->db); $ar = $aaTable->getRowObject(); $ar->load($id); $ar->numLikes += 1; $ar->update(); $code = '<a href="#" class="voteLink" onclick="return askRecordLike(\'' . $mode . '\',' . $id . ');" title="like this question">Like</a> ' . $ar->numLikes; } else { $code = 'You already liked this!'; } } } else { $code = '<a href="' . URL_CANVAS . '?p=ask" requirelogin="******">Please authorize ' . SITE_TITLE . ' with Facebook before continuing.</a>'; } return $code; }