function load_in_redis($mysqli) { $sql = "select max(id) as total from sc_activity "; $row = MySQL\Helper::fetchRow($mysqli, $sql); $total = $row["total"]; $pageSize = 50; $pages = ceil($total / $pageSize); $count = 0; $activityDao = new \com\indigloo\sc\dao\Activity(); while ($count <= $pages) { $start = $count * $pageSize + 1; $end = $start + ($pageSize - 1); $sql = " select * from sc_activity where (id <= {end}) and (id >= {start} ) "; $sql = str_replace(array("{end}", "{start}"), array(0 => $end, 1 => $start), $sql); $rows = MySQL\Helper::fetchRows($mysqli, $sql); foreach ($rows as $row) { $activityDao->pushToRedis($row); } printf("processed rows between %s and %s \n", $start, $end); flush(); sleep(1); $count++; } }
<?php //sc/site/feed.php include 'sc-app.inc'; include APP_WEB_DIR . '/inc/header.inc'; use com\indigloo\Util; use com\indigloo\Url; use com\indigloo\Configuration as Config; $feedDao = new \com\indigloo\sc\dao\Activity(); $feedDataObj = $feedDao->getGlobalFeeds(50); ?> <!DOCTYPE html> <html> <head> <title> 3mik.com - Activity feeds </title> <?php include APP_WEB_DIR . '/inc/meta.inc'; ?> <?php echo \com\indigloo\sc\util\Asset::version("/css/bundle.css"); ?> </head> <body> <?php include APP_WEB_DIR . '/inc/toolbar.inc';
use com\indigloo\ui\form\Message as FormMessage; $gSessionLogin = Login::getLoginInSession(); $loginId = $gSessionLogin->id; $pubId = PseudoId::encode($loginId); $homeUrl = Url::base(); $pubUrl = $homeUrl . "/pub/user/" . $pubId; //data:1:user $userDao = new \com\indigloo\sc\dao\User(); $userDBRow = $userDao->getOnLoginId($loginId); $loginName = $gSessionLogin->name; if (is_null($loginId)) { trigger_error("Error : NULL login_id on user dashboard", E_USER_ERROR); } $analyticDao = new \com\indigloo\sc\dao\Analytic(); $counters = $analyticDao->getUserCounters($loginId); $activityDao = new \com\indigloo\sc\dao\Activity(); $feedDataObj = $activityDao->getUserFeeds($loginId, 20); //suggestions are editor picks right now $postDao = new \com\indigloo\sc\dao\Post(); //post featured filter $filters = array(); $model = new \com\indigloo\sc\model\Post(); $filter = new Filter($model); $filter->add($model::FEATURED, Filter::EQ, TRUE); array_push($filters, $filter); // pick 12 posts from editor picks $postDBRows = $postDao->getPosts(12, $filters); $dashItemHelp = \com\indigloo\sc\html\Site::getDashItemHelp($counters["post_count"]); $params = array("q" => base64_encode(Url::current())); $linkInvitation = Url::createUrl("/user/invite.php", $params); ?>
function process_activities($mysqli) { /* * process activities data * @imp activities should be brought in the order that they have happened * so sort on id ASC */ $sql = " select * from sc_activity where op_bit = 0 order by id limit 50"; $rows = MySQL\Helper::fetchRows($mysqli, $sql); $activityDao = new \com\indigloo\sc\dao\Activity(); foreach ($rows as $row) { try { $sql2 = " update sc_activity set op_bit = 1 where id = " . $row["id"]; $feed = $activityDao->pushToRedis($row); $activityDao->sendMail($row, $feed); //flip the op_bit for this activity MySQL\Helper::executeSQL($mysqli, $sql2); } catch (\Exception $ex) { Logger::getInstance()->error($ex->getMessage()); } } }
$options = array(); $options["group"] = true; $postView = \com\indigloo\sc\html\Post::createPostView($postDBRow, $options); echo \com\indigloo\sc\html\Post::getHeader($postView); ?> </div> </div> <div class="row"> <div class="span9"> <?php echo \com\indigloo\sc\html\Post::getGalleria($itemObj->title, $images); echo \com\indigloo\sc\html\Post::getDetail($postView, $links, $siteDBRow); echo \com\indigloo\sc\html\Post::getToolbar($loginIdInSession, $postDBRow['login_id'], $itemId); //inject activity tile $activityDao = new \com\indigloo\sc\dao\Activity(); $feedDataObj = $activityDao->getPostFeeds($itemId, 10); $htmlObj = new \com\indigloo\sc\html\Activity(); $feedHtml = $htmlObj->getPostTile($feedDataObj); echo \com\indigloo\sc\html\Post::getActivity($feedHtml); echo \com\indigloo\sc\html\Comment::getFeedHtml($commentDBRows); include APP_WEB_DIR . '/qa/inc/comment.inc'; ?> <h3> explore 3mik </h3> <div id="tiles"> <?php foreach ($xrows as $xrow) { echo \com\indigloo\sc\html\Post::getSmallTile($xrow); } ?> </div> <!-- tiles -->
private function processIndex($params, $options) { $pubUserId = Util::getArrayKey($params, "login_id"); $loginId = PseudoId::decode($pubUserId); $qparams = Url::getRequestQueryParams(); $gNumDBRows = array(); //data:1:user $userDao = new \com\indigloo\sc\dao\User(); $userDBRow = $userDao->getOnLoginId($loginId); $this->isValidUser($userDBRow); //data:2:counters $analyticDao = new \com\indigloo\sc\dao\Analytic(); $ucounters = $analyticDao->getUserCounters($loginId); //data:3:items $postDao = new \com\indigloo\sc\dao\Post(); $model = new \com\indigloo\sc\model\Post(); $filters = array(); $filter = new Filter($model); $filter->add($model::LOGIN_ID, Filter::EQ, $loginId); array_push($filters, $filter); $postDBRows = $postDao->getLatest(8, $filters); $gNumDBRows["items"] = sizeof($postDBRows); //data:social graph $socialGraphDao = new \com\indigloo\sc\dao\SocialGraph(); $followers = $socialGraphDao->getFollowers($loginId, 5); $followings = $socialGraphDao->getFollowing($loginId, 5); $gNumDBRows["followers"] = sizeof($followers); $gNumDBRows["followings"] = sizeof($followings); $followerUIOptions = array("ui" => "feed", "more" => "#"); $followingUIOptions = array("ui" => "feed", "more" => "#", "image" => false); //data:4:activity $activityDao = new \com\indigloo\sc\dao\Activity(); $feedDataObj = $activityDao->getUserActivities($loginId, 20); // data:5:likes $bookmarkDao = new \com\indigloo\sc\dao\Bookmark(); $model = new \com\indigloo\sc\model\Bookmark(); $filters = array(); $filter = new Filter($model); $filter->add($model::SUBJECT_ID_COLUMN, Filter::EQ, $loginId); array_push($filters, $filter); $filter = new Filter($model); $filter->add($model::VERB_COLUMN, Filter::EQ, AppConstants::LIKE_VERB); array_push($filters, $filter); $likeDBRows = $bookmarkDao->getLatest(8, $filters); $gNumDBRows["likes"] = sizeof($likeDBRows); //data:6:lists $listDao = new \com\indigloo\sc\dao\Lists(); $listDBRows = $listDao->getLatestOnLoginId($loginId, 4); $gNumDBRows["lists"] = sizeof($listDBRows); $template = APP_WEB_DIR . '/view/user/pub.php'; //page variables $pageBaseUrl = "/pub/user/" . $pubUserId; $pageTitle = SeoData::getHomePageTitle(); $metaKeywords = SeoData::getHomeMetaKeywords(); $metaDescription = SeoData::getHomeMetaDescription(); include $template; }
function post_to_activity($mysqli) { $sql = "select max(id) as total from sc_post"; $row = MySQL\Helper::fetchRow($mysqli, $sql); $total = $row["total"]; $pageSize = 50; $pages = ceil($total / $pageSize); $count = 0; $userDao = new \com\indigloo\sc\dao\User(); $activityDao = new \com\indigloo\sc\dao\Activity(); while ($count <= $pages) { $start = $count * $pageSize + 1; $end = $start + ($pageSize - 1); $sql = " select * from sc_post where (id <= {end}) and (id >= {start} ) "; $sql = str_replace(array("{end}", "{start}"), array(0 => $end, 1 => $start), $sql); $rows = MySQL\Helper::fetchRows($mysqli, $sql); foreach ($rows as $row) { $subjectId = $row['login_id']; $ownerId = $row['login_id']; $postId = $row['id']; $objectId = PseudoId::encode($postId); $userDBRow = $userDao->getOnLoginId($subjectId); $subject = $userDBRow['name']; $object = $row['title']; $object = Util::filterBadUtf8($object); $verb = \com\indigloo\sc\Constants::POST_VERB; $activityDao->addRow($ownerId, $subjectId, $objectId, $subject, $object, $verb); } flush(); sleep(1); $count++; } }