function execute($params) { $action = $params->action; // intval() returns the integer value of var // on success, or 0 on failure $followerId = intval($params->followerId); $followingId = intval($params->followingId); if (empty($followerId) || empty($followingId) || empty($action)) { $message = "Bad input: missing required parameters."; $response = array("code" => 500, "message" => $message); return $response; } $userDao = new \com\indigloo\sc\dao\User(); $followingDBRow = $userDao->getOnLoginId($followingId); $followingName = $followingDBRow['name']; $followerDBRow = $userDao->getOnLoginId($followerId); $followerName = $followerDBRow['name']; $socialGraphDao = new \com\indigloo\sc\dao\SocialGraph(); $message = ""; $code = 200; switch ($action) { case UIConstants::FOLLOW_USER: $socialGraphDao->follow($followerId, $followerName, $followingId, $followingName); $message = sprintf("Success! You are following %s ", $followingName); break; case UIConstants::UNFOLLOW_USER: $socialGraphDao->unfollow($followerId, $followingId); $message = sprintf("Success! You are no longer following %s ", $followingName); break; default: break; } $response = array("code" => $code, "message" => $message); return $response; }
function process($params, $options) { if (is_null($params) || empty($params)) { $controller = new \com\indigloo\sc\controller\Http400(); $controller->process(); exit; } $plistId = Util::getArrayKey($params, "list_id"); $listId = PseudoId::decode($plistId); $qparams = Url::getRequestQueryParams(); $gpage = Url::tryQueryParam("gpage"); $gpage = empty($gpage) ? "1" : $gpage; //@todo input check // people can type all sort of input garbage settype($listId, "int"); $listDao = new \com\indigloo\sc\dao\Lists(); $listDBRow = $listDao->getOnId($listId); if (empty($listDBRow)) { //not found $controller = new \com\indigloo\sc\controller\Http404(); $controller->process(); exit; } $listName = $listDBRow["name"]; $listPubUrl = sprintf("%s/pub/list/%d/%s", Url::base(), $plistId, $listDBRow["seo_name"]); //get items from sc_list_item table $model = new \com\indigloo\sc\model\ListItem(); $filter = new Filter($model); $filter->add($model::LIST_ID, Filter::EQ, $listId); $pageSize = Config::getInstance()->get_value("user.page.items"); $filters = array(); array_push($filters, $filter); $paginator = new \com\indigloo\ui\Pagination($qparams, $pageSize); $itemDBRows = $listDao->getPagedItems($paginator, $filters); $loginId = $listDBRow["login_id"]; $userDao = new \com\indigloo\sc\dao\User(); $userDBRow = $userDao->getOnLoginId($loginId); $template = APP_WEB_DIR . '/view/list/pub.php'; //page variables $pageBaseUrl = $listPubUrl; $pageTitle = sprintf("page %d of %s", $gpage, $listDBRow["name"]); $description = Util::abbreviate($listDBRow["description"], 160); $metaDescription = SeoData::thisOrHomeDescription($description); $metaKeywords = SeoData::getHomeMetaKeywords(); include $template; }
static function startOAuth2Session($loginId, $provider) { // get denorm data on login from $userDao // the data in sc_user is for first time creation only // and denorm columns like name etc. can be stale in sc_user $userDao = new \com\indigloo\sc\dao\User(); $userDBRow = $userDao->getOnLoginId($loginId); // is banned? $ban_bit = $userDBRow["bu_bit"]; settype($ban_bit, "integer"); if ($ban_bit == 1) { //donot start session return self::FORBIDDEN_CODE; } //start session $_SESSION[self::LOGIN_ID] = $loginId; $_SESSION[self::NAME] = $userDBRow["name"]; $_SESSION[self::PROVIDER] = $provider; $_SESSION[self::TOKEN] = Util::getBase36GUID(); // complete any pending session action. self::completeSessionAction($loginId, $userDBRow["name"], $provider); return self::OK_CODE; }
use com\indigloo\Util; use com\indigloo\Url; use com\indigloo\Configuration as Config; use com\indigloo\sc\auth\Login; use com\indigloo\Constants; use com\indigloo\ui\Filter; use com\indigloo\sc\util\PseudoId; 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);
function sendMail($row, $feed) { // determine if we want to send mail for this feed // #1 - who is the target for this mail? // the guy who is the "owner", e.g when I create a post // and you LIKE it, I should get a notification. // so "owner of entity" is the target of our mails. // if X created a post and Y liked it then X gets a mail // if Z likes the same post then also only X gets a mail // Y will not receive a mail. $verb = $row["verb"]; $ownerId = $row["owner_id"]; if ($verb == AppConstants::FOLLOW_VERB) { //mail target is the guy you are following $ownerId = $row["object_id"]; } // #2 : I am not interested in receiving mails where // I am the subject or doer of deed! if (!empty($ownerId) && $ownerId != $row["subject_id"]) { // #3 - get my preference for this feed $preferenceDao = new \com\indigloo\sc\dao\Preference(); $preferenceObj = $preferenceDao->get($ownerId); $flag = $this->getMailflag($preferenceObj, $verb); if ($flag) { $activityHtml = new \com\indigloo\sc\html\Activity(); $emailData = $activityHtml->getEmailData($feed); if (empty($emailData)) { $message = sprintf("ACTIVITY_ERROR : getting email data :id %d ", $row["id"]); throw new \Exception($message); } $text = $emailData["text"]; $html = $emailData["html"]; $userDao = new \com\indigloo\sc\dao\User(); $row = $userDao->getOnLoginId($ownerId); $name = $row["name"]; $email = $row["email"]; if (!empty($email)) { $code = WebMail::sendActivityMail($name, $email, $text, $html); if ($code > 0) { $message = sprintf("ACTIVITY_ERROR : sending mail : id %d ", $row["id"]); throw new \Exception($message); } } } //condition:mail_flag } //condition:owner }
private function processLists($params, $options) { $pubUserId = Util::getArrayKey($params, "login_id"); $loginId = PseudoId::decode($pubUserId); $qparams = Url::getRequestQueryParams(); $userDao = new \com\indigloo\sc\dao\User(); $userDBRow = $userDao->getOnLoginId($loginId); $this->isValidUser($userDBRow); $gpage = Url::tryQueryParam("gpage"); $gpage = empty($gpage) ? "1" : $gpage; $listDao = new \com\indigloo\sc\dao\Lists(); $qparams = Url::getRequestQueryParams(); $pageSize = Config::getInstance()->get_value("user.page.items"); $paginator = new \com\indigloo\ui\Pagination($qparams, $pageSize); $listDBRows = $listDao->getPagedOnLoginId($paginator, $loginId); $template = APP_WEB_DIR . '/view/user/lists.php'; //page variables $pageBaseUrl = "/pub/user/" . $pubUserId; $pageTitle = sprintf("page %d of lists by %s", $gpage, $userDBRow["name"]); $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++; } }