Пример #1
0
 function index()
 {
     if (isset($this->args[0]) && $this->args[0] != "index") {
         system::setParam("page", "layout");
         $cacheID = $this->args[0] . "|ARTICLE";
         $this->smarty->setCacheID($cacheID);
         if (isset($_POST["contentID"]) && $_POST["contentID"]) {
             comments::add(intval($_POST["contentID"]));
         }
         $this->smarty->assign("isFav", blog::isFavorite($this->args[0]));
         if (!$this->smarty->isCached()) {
             $sqlData = blog::getOnePost($this->args[0], "article")->fetch();
             if ($sqlData) {
                 $this->smarty->assign("comments", comments::get(intval($sqlData["contentID"])));
                 $this->smarty->assign("post", $sqlData);
             }
         }
     } else {
         $offset = 1;
         system::setParam("page", "list");
         if (isset($this->get["offset"])) {
             $offset = intval($this->get["offset"]);
         }
         $cacheID = "ARTICLES|artoffset_{$offset}";
         $this->smarty->setCacheID($cacheID);
         if (!$this->smarty->isCached()) {
             $allCount = $this->db->query("SELECT COUNT(*) as cnt FROM `content` WHERE `type`='article'")->fetch();
             $this->smarty->assign("posts", news::getPosts(core::pagination($allCount["cnt"], $offset), "article")->fetchAll());
         }
     }
 }
Пример #2
0
 /**
  * Метод редактирования комментария
  * @param int $id ID комментария
  * @return null
  */
 protected function edit_form($id)
 {
     $id = (int) $id;
     lang::o()->get('comments');
     $poster = db::o()->p($id)->query('SELECT poster_id, text FROM comments WHERE id=? LIMIT 1');
     $poster = db::o()->fetch_assoc($poster);
     if (!$poster) {
         return;
     }
     if ($poster['poster_id'] == users::o()->v('id')) {
         users::o()->check_perms('edit_comm');
     } else {
         users::o()->check_perms('edit_comm', 2);
     }
     $name = "comment_" . $id;
     tpl::o()->assign("text", $poster['text']);
     tpl::o()->assign("id", $id);
     tpl::o()->assign("name", $name);
     $this->comments->add("", $name, $id);
 }
 function runJob($job, $force = false)
 {
     $stopAfterJob = false;
     $startTime = microtime(true);
     $this->log($job->task . ', started ' . date('g:i a \\a\\t D M n, Y', $startTime));
     if (!isset($_GET['test']) && !$force) {
         if ($job->isRunning == 1) {
             $this->db->log('Cron race condition: ' . $job->task . ' last start= ' . $job->lastStart);
             echo 'Warning: Cron Race condition<br />';
             return;
         } else {
             $this->db->update("cronJobs", "isRunning=1,failureNoticeSent=0", "id={$job->id}");
         }
     }
     //echo 'Task: '.$job->task."\n";
     switch ($job->task) {
         default:
             // do nothing
             break;
         case 'updateUserLevels':
             require_once 'teamBackend.class.php';
             $teamObj = new teamBackend($this->db);
             $teamObj->updateUserLevels();
             break;
         case 'updateSiteChallenges':
             require_once 'teamBackend.class.php';
             $teamObj = new teamBackend($this->db);
             $teamObj->updateSiteChallenges();
             break;
         case 'updateCachedPointsAndChallenges':
             require_once 'teamBackend.class.php';
             $teamObj = new teamBackend($this->db);
             $teamObj->updateCachedPointsAndChallenges();
             break;
         case 'calcWeeklyLeaders':
             require_once 'teamBackend.class.php';
             $teamObj = new teamBackend($this->db);
             $teamObj->calcWeeklyLeaders();
             break;
         case 'updateUserLevels':
             require_once 'teamBackend.class.php';
             $teamObj = new teamBackend($this->db);
             $teamObj->updateUserLevels();
         case 'updateTwitter':
             // post top stories to twitter
             if (USE_TWITTER) {
                 require_once 'twitter.class.php';
                 $twitterObj = new twitter_old($this->db);
                 $twitterObj->postFeaturedStories();
                 $twitterObj->postNextTopStory();
             }
             break;
         case 'microAccountsSync':
             // sync twitter service accounts for micro blog room - done daily
             if (defined('ENABLE_MICRO')) {
                 require_once PATH_FACEBOOK . "/classes/micro.class.php";
                 $mObj = new micro();
                 $mObj->cleanRoom();
                 try {
                     $mObj->resetFriends(false);
                 } catch (Exception $e) {
                     $this->log('Failed running ' . $job->task . ', Error: ' . $e);
                     // reset this cron task manually because of twitter class trown exceptions
                     $execTime = microtime(true) - $startTime;
                     $this->db->update("cronJobs", "nextRun=date_sub(NOW(), INTERVAL (0-{$job->freqMinutes}) MINUTE),lastExecTime={$execTime},lastStart='" . date('Y-m-d H:i:s', $startTime) . "',isRunning=0", "id={$job->id}");
                 }
             }
             break;
         case 'microBlog':
             // post top stories to micro blog room
             if (defined('ENABLE_MICRO')) {
                 require_once PATH_FACEBOOK . "/classes/micro.class.php";
                 $mObj = new micro();
                 try {
                     $mObj->updateRoom();
                 } catch (Exception $e) {
                     $this->log('Failed running ' . $job->task . ', Error: ' . $e);
                     // reset this cron task manually because of twitter class trown exceptions
                     $execTime = microtime(true) - $startTime;
                     $this->db->update("cronJobs", "nextRun=date_sub(NOW(), INTERVAL (0-{$job->freqMinutes}) MINUTE),lastExecTime={$execTime},lastStart='" . date('Y-m-d H:i:s', $startTime) . "',isRunning=0", "id={$job->id}");
                 }
             }
             break;
         case 'updateCache':
             // build cached content for cover page layout
             require_once 'cache.class.php';
             $cacheObj = new cache($this->db);
             $cacheObj->update();
             break;
         case 'syncProperties':
             // sync Cloud properties with NewsCloud services
             require_once 'apiCloud.class.php';
             $apiObj = new apiCloud($this->db, $this->apiKey);
             $props = $apiObj->syncProperties($this->cloudid);
             require_once 'systemStatus.class.php';
             $ssObj = new systemStatus($this->db);
             $ssObj->setProperties($props['items'][0]);
             break;
         case 'syncAnnouncements':
             require_once 'apiCloud.class.php';
             $apiObj = new apiCloud($this->db, $this->apiKey);
             $resp = $apiObj->syncAnnouncements($this->cloudid);
             if ($resp[result] !== false) {
                 $itemlist = $resp[items];
                 require_once 'systemStatus.class.php';
                 $ssObj = new systemStatus($this->db);
                 $ssObj->resetAnnouncements();
                 if (count($itemlist) > 0) {
                     foreach ($itemlist as $data) {
                         $ssObj->insertState('announcement', html_entity_decode($data['announce']));
                     }
                 }
             }
             break;
         case 'syncNewswire':
             /* deprecated
             			require_once ('apiCloud.class.php');
             			$apiObj=new apiCloud($this->db,$this->apiKey);
             			$resp=$apiObj->syncNewswire($this->cloudid,$this->timeStrToUnixModB($job->lastItemTime));
             			$itemlist=$resp[items];
             			echo 'count: '.count($itemlist).'<br />';
             			if (count($itemlist)>0) {
             				require_once('newswire.class.php');
             				$nwObj=new newswire($this->db);
             				$lastItemTime=date('Y-m-d H:i:s',(time()-(6*30*24*3600))); // set to six months earlier 
             				foreach ($itemlist as $data) {					
             					$wire=$nwObj->serialize($data[title],$data[caption],$data[blogtitle],$data[webpage],$data[date],$data[blogid]);						
             					$id=$nwObj->add($wire);
             					if ($data[date]>$lastItemTime)						
             						$lastItemTime=$data[date];
             					if ($id===false)
             						echo 'skip '.$data[title].'<br />';
             					else						
             						echo 'adding '.$data[title].' id->'.$id.'<br />';
             				}
             				$this->db->update("cronJobs","lastItemTime='$lastItemTime'","id=$job->id");
             			}
             			*/
             break;
         case 'syncLog':
             require_once 'apiCloud.class.php';
             $apiObj = new apiCloud($this->db, $this->apiKey);
             // request server ask for log
             $resp = $apiObj->requestSyncLog($this->cloudid, URL_HOME, $this->timeStrToUnixModB($job->lastStart));
             // get result of log sync
             $logResult = $resp[items][0][log];
             require_once PATH_CORE . "/classes/log.class.php";
             $logObj = new log($this->db);
             // process results from sync operation
             $result = $logObj->receive($logResult);
             echo $result;
             break;
         case 'syncContent':
             // bring content from NewsCloud for this cloud to the remote site
             require_once 'apiCloud.class.php';
             $apiObj = new apiCloud($this->db, $this->apiKey);
             $resp = $apiObj->syncContent($this->cloudid, $this->timeStrToUnixModB($job->lastItemTime));
             $itemlist = $resp[items];
             if (count($itemlist) > 0) {
                 require_once 'content.class.php';
                 $cObj = new content($this->db);
                 // to do : set this to actual time
                 $lastItemTime = date('Y-m-d H:i:s', time() - 6 * 30 * 24 * 3600);
                 // set to six months earlier
                 foreach ($itemlist as $data) {
                     echo 'Contentid' . $data[contentid] . '<br />';
                     // to do: before we can do this below, we need to be syncing ncuid when new users register
                     // to do: get userid from ncUid
                     // lookup userid in user table where ncuid=submitbyid
                     // if not found make it 0
                     // to do: if external story, then check for local userid and set here
                     $story = $cObj->serialize($data[contentid], $data[title], $data[description], '', $data[webpage], $data[permalink], $data[submitbyid], $data[submit_member], $data[userid], $data[date], $data[avgrank], 0, $data[imageid]);
                     $id = $cObj->add($story);
                     // update comments table with new contentids
                     $cObj->updateCommentsTable($data[contentid], $id);
                     if ($data[date] > $lastItemTime) {
                         $lastItemTime = $data[date];
                     }
                     echo 'story added' . $id . '<br><br/>';
                 }
                 $this->db->update("cronJobs", "lastItemTime='{$lastItemTime}'", "id={$job->id}");
             }
             break;
         case 'syncComments':
             // bring comments from stories in this cloud from NewsCloud over to remote site
             require_once 'content.class.php';
             $cObj = new content($this->db);
             $idList = $cObj->fetchRecentStoryList(14, 99, true);
             $this->db->log('syncComments - stories to check for.', PATH_SYNCLOGFILE);
             $this->db->log($idList, PATH_SYNCLOGFILE);
             if ($idList != '') {
                 require_once 'comments.class.php';
                 $commentsObj = new comments($this->db);
                 require_once 'apiCloud.class.php';
                 $apiObj = new apiCloud($this->db, $this->apiKey);
                 $result = $apiObj->syncComments($this->cloudid, $idList, $this->timeStrToUnixModB($job->lastItemTime));
                 $itemlist = $result[items];
                 $this->db->log($itemlist, PATH_SYNCLOGFILE);
                 // update comment thread for each story
                 if (count($itemlist) > 0) {
                     $lastItemTime = date('Y-m-d H:i:s', time() - 6 * 30 * 24 * 3600);
                     // set to six months earlier
                     foreach ($itemlist as $data) {
                         $temp = 'Bring over contentid' . $data[contentid] . ' Commentid' . $data[commentid] . '<br />';
                         // to do: if external story, then check for local userid and set here
                         $comment = $commentsObj->remoteSerialize($data);
                         if ($data[date] > $lastItemTime) {
                             $lastItemTime = $data[date];
                         }
                         $id = $commentsObj->add($comment);
                         echo $temp . '<br />';
                         var_dump($comment);
                         $this->db->log($temp, PATH_SYNCLOGFILE);
                         $this->db->log($comment, PATH_SYNCLOGFILE);
                     }
                 }
                 $this->db->update("cronJobs", "lastItemTime='{$lastItemTime}'", "id={$job->id}");
             }
             break;
         case 'syncScores':
             require_once 'content.class.php';
             $cObj = new content($this->db);
             $idList = $cObj->fetchRecentStoryList(14, 99, true);
             if ($idList != '') {
                 require_once 'apiCloud.class.php';
                 $apiObj = new apiCloud($this->db, $this->apiKey);
                 $resp = $apiObj->syncScores($this->cloudid, $idList, $this->timeStrToUnixModB($job->lastStart));
                 $itemlist = $resp[items];
                 //var_dump($resp);
                 if (count($itemlist) > 0) {
                     // update the score for each story with new votes
                     foreach ($itemlist as $data) {
                         $this->db->update("Content", "score={$data['score']}", "contentid={$data['contentid']}");
                         $temp = 'Set score of contentid:' . $data[contentid] . 'to ' . $data[score];
                         echo $temp . '<br />';
                         $this->db->log($temp, PATH_SYNCLOGFILE);
                     }
                 }
             }
             break;
         case 'syncResources':
             require_once 'apiCloud.class.php';
             $apiObj = new apiCloud($this->db, $this->apiKey);
             require_once 'resources.class.php';
             $resObj = new resources($this->db);
             $result = $apiObj->syncResources($this->cloudid);
             $resObj->sync(html_entity_decode($result[items][0][resources]));
             break;
         case 'updateSiteMap':
             $currentHour = date('G');
             // 0 - 24
             $currentDayOfWeek = date('w');
             // day of week 0-6
             $currentDayOfMonth = date('j');
             // day of month 1-31
             require_once 'siteMap.class.php';
             $smObj = new siteMap($this->db);
             // do always - build the map for content from the last hour
             $smObj->buildMap('hourly');
             // only do this as midnight
             if ($currentHour == 0) {
                 // map to all the content from the last day
                 $smObj->buildMap('daily');
             }
             // only do this at 3 am on first day of week
             if ($currentDayOfWeek = 0 and $currentHour == 3) {
                 // map to all the content from the last week, etc.
                 $smObj->buildMap('weekly');
             }
             // only do this at 2 am on first day of month
             if ($currentDayOfMonth == 1 and $currentHour == 2) {
                 $smObj->buildMap('monthly');
             }
             // call buildIndexMap after updating any individual child maps above
             // just the time stamps from each individual map file are updated in the indexmap
             // warning: if a individual map hasn't been built - the index map won't include a reference to it
             $smObj->buildIndexMap();
             break;
         case 'fetchFeeds':
             // import stories from feeds
             require_once 'feed.class.php';
             $feedObj = new feed($this->db);
             $feedObj->fetchBookmarks();
             $feedObj->fetchFeeds();
             $feedObj->fetchImages();
             if ($feedObj->newStoryLoaded) {
                 // update features
             }
             break;
         case 'logHourlyStats':
             require_once 'statistics.class.php';
             $statsObj = new statistics($this->db);
             $statsObj->logHourlyStats();
             break;
         case 'facebookMinifeed':
             require_once PATH_FACEBOOK . "/classes/app.class.php";
             $app = new app(NULL, true);
             $facebook =& $app->loadFacebookLibrary();
             require_once PATH_FACEBOOK . '/classes/miniFeeds.class.php';
             $feedObj = new miniFeeds($this->db);
             $feedObj->loadFacebook($facebook);
             $feedObj->updateMiniFeeds();
             break;
         case 'facebookProfileBoxes':
             require_once PATH_FACEBOOK . "/classes/app.class.php";
             $app = new app(NULL, true);
             $facebook =& $app->loadFacebookLibrary();
             require_once PATH_FACEBOOK . '/classes/profileBoxes.class.php';
             $proObj = new profileBoxes($this->db);
             $proObj->loadFacebook($facebook);
             $proObj->updateProfileBoxes();
             break;
         case 'facebookEmailEngine':
             // tbd
             break;
         case 'facebookAllocations':
             // check nightly facebook allocations
             $ssObj = new systemStatus($this->db);
             /* initialize the SMT Facebook appliation class, NO Facebook library */
             require_once PATH_FACEBOOK . "/classes/app.class.php";
             $app = new app(NULL, true);
             $facebook =& $app->loadFacebookLibrary();
             $npd = $facebook->api_client->admin_getAllocation('notifications_per_day');
             $ssObj->setState('notifications_per_day', $npd);
             $ssObj->setState('announcement_notifications_per_week', $facebook->api_client->admin_getAllocation('announcement_notifications_per_week'));
             $ssObj->setState('requests_per_day', $facebook->api_client->admin_getAllocation('requests_per_day'));
             $ssObj->setState('emails_per_day', $facebook->api_client->admin_getAllocation('emails_per_day'));
             break;
         case 'facebookSendNotifications':
             require_once PATH_FACEBOOK . "/classes/app.class.php";
             $app = new app(NULL, true);
             $facebook =& $app->loadFacebookLibrary();
             require_once PATH_FACEBOOK . "/classes/shareStories.class.php";
             $ssObj = new shareStories($app);
             $ssObj->processNotifications();
             break;
         case 'facebookSendPromos':
             /* not needed for now
             				if (date('G')==0) {
             					require_once PATH_FACEBOOK."/classes/promos.class.php";
             					$promoObj=new promos($this->db);				
             					$promoObj->send();
             				}			
             */
             break;
         case 'insertNewResearchData':
             require_once PATH_CORE . "/classes/researchRawSession.class.php";
             require_once PATH_CORE . "/classes/researchRawExtLink.class.php";
             require_once PATH_CORE . "/classes/researchSessionLength.class.php";
             require_once PATH_CORE . "/classes/researchLogDump.class.php";
             require_once PATH_CORE . "/classes/researchUserCollective.class.php";
             $rawExtLinkTable = new RawExtLinkTable($this->db);
             $rawExtLinkTable->insertNewestData();
             $rawSessionTable = new RawSessionTable($this->db);
             $rawSessionTable->insertNewestData();
             $sessionLengthTable = new SessionLengthTable($this->db);
             $sessionLengthTable->insertNewestData();
             $logDumpTable = new LogDumpTable($this->db);
             $logDumpTable->insertNewestData();
             $userCollectiveTable = new UserCollectiveTable($this->db);
             $userCollectiveTable->assimilateUsers();
             $stopAfterJob = true;
             break;
         case 'autoFeature':
             require_once PATH_CORE . '/classes/content.class.php';
             $cObj = new content($this->db);
             $cObj->autoFeature();
             break;
         case 'cleanup':
             require_once 'cleanup.class.php';
             $cleanObj = new cleanup($this->db, 'daily');
             break;
             // deprecated
         // deprecated
         case 'syncFeedList':
             require_once 'apiCloud.class.php';
             $apiObj = new apiCloud($this->db, $this->apiKey);
             $result = $apiObj->syncFeedList($this->cloudid);
             require_once 'feed.class.php';
             $feedObj = new feed($this->db);
             $feedObj->syncFeedList($result[items]);
             break;
     }
     $execTime = microtime(true) - $startTime;
     $this->log('...completed in ' . $execTime . ' seconds.');
     $this->history[$this->cntJobs]['task'] = $job->task;
     $this->history[$this->cntJobs]['time'] = $execTime;
     $this->cntJobs += 1;
     $this->db->update("cronJobs", "nextRun=date_sub(NOW(), INTERVAL (0-{$job->freqMinutes}) MINUTE),lastExecTime={$execTime},lastStart='" . date('Y-m-d H:i:s', $startTime) . "',isRunning=0", "id={$job->id}");
     if ($stopAfterJob) {
         exit;
     }
 }
Пример #4
0
 public function _activityshow()
 {
     $Comments = new comments();
     $Comments->add($_SESSION["USERID"], $_POST['activityrecive'], $_SESSION["ACTIVITYID"]);
     $re = $Comments->show($_SESSION["ACTIVITYID"], $_POST['groupactivity']);
     $i = $_POST['groupactivity'];
     foreach ($re as $r) {
         $commentshow .= "<div id='comment-" . $r->CommentsId . "' style='display:none'>\n\t\t\t\t<div id='comment_recive'>\n\t\t\t\t<div id='user_picture'><img src='/upload/avatar_small/" . $r->UserId . "_small.jpg' style='float:left'>\n\t\t\t\t</div>\n\t\t\t\t<div id='comment_text'>\n\t\t\t\t" . htmlspecialchars($r->CommentText) . "\n\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t\t</div>";
         $i++;
         $commentshow .= "<script>\$('#comment-" . $r->CommentsId . "').show('slow')</script>";
     }
     $commentshow .= "<script>\$('#groupactivity').val(" . $i . ");</script>";
     echo $commentshow;
 }
Пример #5
0
 public static function addCommentQueue($contentID, $comments)
 {
     if (empty($comments)) {
         return false;
     }
     foreach ($comments as $key => $value) {
         if (!$comments[$key]) {
             continue;
         }
         comments::add($contentID, $value);
     }
     return true;
 }
Пример #6
0
     }
     break;
 case 'readStory':
     define("INIT_SESSION", true);
     include_once 'initialize.php';
     switch ($cmd) {
         case 'addComment':
             if (isset($_GET['siteContentId']) and isset($_GET['comments'])) {
                 $comments = $_GET['comments'];
                 $siteContentId = $_GET['siteContentId'];
                 if ($comments != '') {
                     require_once PATH_CORE . 'classes/comments.class.php';
                     $comObj = new comments($db);
                     $comInfo = $comObj->serialize(0, 0, $siteContentId, 0, $comments, 0, $db->ui->userid, $db->ui->memberName, '', 0);
                     // $db->ui->uid
                     $siteCommentId = $comObj->add($comInfo);
                     require_once PATH_CORE . '/classes/log.class.php';
                     $logObj = new log($db);
                     $logItem = $logObj->serialize(0, $db->ui->userid, 'comment', $siteContentId);
                     $logItem->itemid2 = $siteCommentId;
                     // djm: hack for now so I have it
                     $inLog = $logObj->add($logItem);
                     $code = 'Your comment has been posted!';
                 } else {
                     $error = true;
                     $errorMsg = 'Please enter a valid comment.';
                 }
             } else {
                 $error = true;
                 $errorMsg = 'There was a problem posting your comment.';
             }
Пример #7
0
$usersClass = new users();
$item['user'] = $usersClass->get($item['user_id']);
abr('item', $item);
$commentsClass = new comments();
#举报评论
if (check_login_bool() && isset($_GET['report']) && is_numeric($_GET['report'])) {
    $s = $commentsClass->report($_GET['report']);
    if ($s === true) {
        refresh('/' . $languageURL . 'items/comments/' . $itemID, $langArray['complete_report_comment'], 'complete');
    } else {
        addErrorMessage($s, '', 'error');
    }
}
#添加评论
if (check_login_bool() && isset($_POST['add'])) {
    $s = $commentsClass->add();
    if ($s === true) {
        refresh('/' . $languageURL . 'items/comments/' . $itemID, $langArray['complete_add_comment'], 'complete');
    } else {
        addErrorMessage($langArray['error_item_comment'], '', 'error');
    }
} elseif (isset($_POST['add_reply'])) {
    if (!isset($_POST['comment_id'])) {
        $_POST['comment_id'] = 0;
    }
    $s = $commentsClass->add($_POST['comment_id']);
    if ($s === true) {
        refresh('/' . $languageURL . 'items/comments/' . $itemID, $langArray['complete_add_reply'], 'complete');
    } else {
        addErrorMessage($langArray['error_item_comment'], '', 'error');
    }