function process($feedObj, $templates = array()) { $html = ''; $keys = array("subject", "subjectId", "object", "objectId"); $flag = $this->checkKeys($feedObj, $keys); $view = array(); if (empty($templates)) { $templates = array(AppConstants::FOLLOW_VERB => "/fragments/feed/vanilla.tmpl"); } if ($flag) { $view['subject'] = $feedObj->subject; $view['object'] = $feedObj->object; $pubId = PseudoId::encode($feedObj->subjectId); $view['subjectUrl'] = sprintf("%s/pub/user/%s", Url::base(), $pubId); $pubId = PseudoId::encode($feedObj->objectId); $view['objectUrl'] = sprintf("%s/pub/user/%s", Url::base(), $pubId); $view['verb'] = $this->getVerb($feedObj->verb); if (isset($templates[$feedObj->verb])) { $template = $templates[$feedObj->verb]; } else { trigger_error("invalid feed template", E_USER_ERROR); } $html = Template::render($template, $view); } return $html; }
function process($params, $options) { $qparams = Url::getRequestQueryParams(); $gpage = Url::tryQueryParam("gpage"); $gpage = empty($gpage) ? "1" : $gpage; $redis = new redis\Activity(); $pageSize = Config::getInstance()->get_value("main.page.items"); $paginator = new \com\indigloo\ui\Pagination($qparams, $pageSize); $zsetKey = Nest::score("post", "likes"); $members = $redis->getPagedZSet($zsetKey, $paginator); //first one is id, second one is score $count = 0; $scores = array(); $ids = array(); for ($i = 1; $i < sizeof($members); $i++) { if ($i % 2 == 0) { array_push($scores, $members[$i - 1]); } else { $itemId = $members[$i - 1]; $postId = PseudoId::decode($itemId); array_push($ids, $postId); } } //get post rows using ids $postDao = new \com\indigloo\sc\dao\Post(); $postDBRows = $postDao->getOnSearchIds($ids); $pageHeader = 'Most popular'; $pageBaseUrl = '/pub/popular'; $pageTitle = SeoData::getPageTitleWithNumber($gpage, "popular items"); $metaKeywords = SeoData::getHomeMetaKeywords(); $metaDescription = SeoData::getMetaDescriptionWithNumber($gpage, "popular items"); $file = APP_WEB_DIR . '/view/tiles-page.php'; include $file; }
function execute($params) { $action = $params->action; $itemId = intval($params->itemId); $loginId = intval($params->loginId); $name = $params->name; if (empty($action) || empty($itemId) || empty($loginId) || empty($name)) { $message = "Bad input: missing required parameters."; $response = array("code" => 500, "message" => $message); return $response; } $bookmarkDao = new \com\indigloo\sc\dao\Bookmark(); $postDao = new \com\indigloo\sc\dao\Post(); $postId = PseudoId::decode($itemId); $postDBRow = $postDao->getOnId($postId); $title = $postDBRow["title"]; $ownerId = $postDBRow["login_id"]; $code = 200; switch ($action) { case UIConstants::LIKE_POST: $bookmarkDao->like($ownerId, $loginId, $name, $itemId, $title); $message = sprintf(" Success! Like for item %s done.", $title); break; default: break; } $response = array("code" => $code, "message" => $message); return $response; }
static function getWidget($row, $options = NULL) { $html = NULL; $view = new \stdClass(); $template = '/fragments/comment/text.tmpl'; if (is_null($options)) { $options = ~UIConstants::COMMENT_ALL; } $view->id = $row['id']; $view->title = $row['title']; $view->postId = $row['post_id']; $view->itemId = PseudoId::encode($view->postId); $view->comment = $row['description']; $view->createdOn = AppUtil::convertDBTime($row['created_on']); $view->showUser = false; if ($options & UIConstants::COMMENT_USER) { $view->loginId = $row['login_id']; $view->pubUserId = PseudoId::encode($view->loginId); $view->userName = $row['user_name']; $view->showUser = true; } $encodedId = PseudoId::encode($view->id); $params = array('id' => $encodedId, 'q' => base64_encode(Url::current())); $view->editUrl = Url::createUrl('/qa/comment/edit.php', $params); $view->deleteUrl = Url::createUrl('/qa/comment/delete.php', $params); $html = Template::render($template, $view); return $html; }
function process($feedObj, $templates = array()) { $html = ''; $keys = array("subject", "subjectId", "title", "objectId"); $flag = $this->checkKeys($feedObj, $keys); $view = array(); if (empty($templates)) { $templates = array(AppConstants::LIKE_VERB => "/fragments/feed/image/post.tmpl", AppConstants::COMMENT_VERB => "/fragments/feed/image/comment.tmpl", AppConstants::POST_VERB => "/fragments/feed/image/post.tmpl", AppConstants::FOLLOW_VERB => NULL); } if ($flag) { // extra processing for comments // @imp: activity row for comment stores // post_id as object_id and not item_id if (strcmp($feedObj->verb, AppConstants::COMMENT_VERB) == 0) { if (property_exists($feedObj, 'content')) { $view['content'] = $feedObj->content; } $feedObj->objectId = PseudoId::encode($feedObj->objectId); } $view['subject'] = $feedObj->subject; $view['object'] = $feedObj->title; $pubId = PseudoId::encode($feedObj->subjectId); $view['subjectUrl'] = sprintf("%s/pub/user/%s", Url::base(), $pubId); $view['objectUrl'] = sprintf("%s/item/%s", Url::base(), $feedObj->objectId); $view['hasImage'] = false; //image for feed if (property_exists($feedObj, 'srcImage')) { if (!empty($feedObj->srcImage)) { $srcImage = $feedObj->srcImage; $m_bucket = \parse_url($srcImage, \PHP_URL_HOST); // aws s3 bucket mapping for cloud front // host is a CNAME mapped to amazon s3 bucket // format is store.bucket.mapto=<mapped-bucket> $mapKey = sprintf("s3.%s.mapto", $m_bucket); $bucket = Config::getInstance()->get_value($mapKey, $m_bucket); $view['srcImage'] = str_replace($m_bucket, $bucket, $srcImage); $view['nameImage'] = $feedObj->nameImage; $view['hasImage'] = true; } } $view['verb'] = $this->getVerb($feedObj->verb); if (isset($templates[$feedObj->verb])) { $template = $templates[$feedObj->verb]; } else { trigger_error("invalid feed template", E_USER_ERROR); } $html = Template::render($template, $view); } return $html; }
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 createListView($row) { $view = new \stdClass(); $view->id = $row["id"]; $view->pseudoId = PseudoId::encode($view->id); $view->name = $row["name"]; $view->seoName = $row["seo_name"]; $view->items = json_decode($row["items_json"]); $view->count = $row["item_count"] == 0 ? "no" : $row["item_count"]; $view->hasImage = false; if (is_array($view->items)) { $view->hasImage = true; } else { $view->items = array(); } return $view; }
function process($feedObj) { $html = ''; $keys = array("subject", "subjectId", "object", "objectId"); $flag = $this->checkKeys($feedObj, $keys); $view = array(); if ($flag) { $view['subject'] = $feedObj->subject; $view['object'] = "this item"; $pubId = PseudoId::encode($feedObj->subjectId); $view['subjectUrl'] = sprintf("%s/pub/user/%s", Url::base(), $pubId); $view['objectUrl'] = sprintf("%s/item/%s", Url::base(), $feedObj->objectId); $view['verb'] = $this->getVerb($feedObj->verb); $template = '/fragments/feed/vanilla.tmpl'; $html = Template::render($template, $view); } return $html; }
function pushToRedis($row) { $verb = $row["verb"]; $feed = NULL; switch ($verb) { case AppConstants::FOLLOW_VERB: $feed = $this->getFollowingFeed($row); $this->proxy->addFollower($row["subject_id"], $row["object_id"], $feed); $this->proxy->addGlobalFeed($row["subject_id"], $feed); break; //no fallthrough! //no fallthrough! case AppConstants::LIKE_VERB: $feed = $this->getBookmarkFeed($row); $this->proxy->addBookmark($row["subject_id"], $row["object_id"], $feed); $this->proxy->addGlobalFeed($row["subject_id"], $feed); break; case AppConstants::POST_VERB: $feed = $this->getPostFeed($row); $this->proxy->addPost($row["subject_id"], $row["object_id"], $feed); $this->proxy->addGlobalFeed($row["subject_id"], $feed); break; case AppConstants::COMMENT_VERB: $feed = $this->getCommentFeed($row); // @imp: activity row for comment stores // post_id as object_id and not item_id $postId = $row["object_id"]; $itemId = PseudoId::encode($postId); $this->proxy->addComment($row["subject_id"], $itemId, $feed); $this->proxy->addGlobalFeed($row["subject_id"], $feed); break; case AppConstants::UNFOLLOW_VERB: $this->proxy->removeFollower($row["subject_id"], $row["object_id"]); break; default: $message = "Unknown activity verb : aborting! "; trigger_error($message, E_USER_ERROR); } return $feed; }
use com\indigloo\Util; use com\indigloo\Url; use com\indigloo\exception\UIException; use com\indigloo\sc\util\PseudoId; if (isset($_POST['delete']) && $_POST['delete'] == 'Delete') { $gWeb = \com\indigloo\core\Web::getInstance(); $fvalues = array(); $fUrl = \com\indigloo\Url::tryFormUrl("fUrl"); try { $fhandler = new Form\Handler('web-form-1', $_POST); $fhandler->addRule('comment_id', 'comment_id', array('required' => 1)); $fhandler->addRule('qUrl', 'qUrl', array('required' => 1, 'rawData' => 1)); $fvalues = $fhandler->getValues(); $ferrors = $fhandler->getErrors(); //decode qUrl to use in redirect $qUrl = base64_decode($fvalues['qUrl']); $encodedId = PseudoId::encode($fvalues['comment_id']); if ($fhandler->hasErrors()) { throw new UIException($fhandler->getErrors()); } $commentDao = new com\indigloo\sc\dao\Comment(); $commentDao->delete($fvalues['comment_id']); //success header("Location: " . $qUrl); } catch (UIException $ex) { $gWeb->store(Constants::STICKY_MAP, $fvalues); $gWeb->store(Constants::FORM_ERRORS, $ex->getMessages()); header("Location: " . $fUrl); exit(1); } }
<?php include 'sc-app.inc'; include APP_CLASS_LOADER; use com\indigloo\mysql as MySQL; use com\indigloo\Configuration as Config; use com\indigloo\sc\util\PseudoId; $mysqli = MySQL\Connection::getInstance()->getHandle(); $sql = " select max(id) as max_id from sc_post "; $row = MySQL\Helper::fetchRow($mysqli, $sql); $maxId = $row['max_id']; echo "Max id = {$maxId} \n"; for ($i = 1; $i <= $maxId; $i++) { $ei = PseudoId::encode($i); update($mysqli, $i, $ei); } function update($mysqli, $x, $ex) { $sql = "update sc_post set pseudo_id = ? where id = ? "; $stmt = $mysqli->prepare($sql); if ($stmt) { $stmt->bind_param("ss", $ex, $x); $stmt->execute(); $stmt->close(); } }
break; case "tainted": $filter = new Filter($model); $filter->add($model::TAINTED, Filter::EQ, 1); array_push($filters, $filter); $ftname = "Tainted"; break; case "name": $filter = new Filter($model); $filter->add($model::USER_NAME, Filter::LIKE, $gtoken); array_push($filters, $filter); $ftname = "name:" . $gtoken; break; case "user": $filter = new Filter($model); $loginId = PseudoId::decode($userId); $filter->add($model::LOGIN_ID, Filter::EQ, $loginId); array_push($filters, $filter); $ftname = "user:"******"user.page.items"); $total = $userDao->getTotal($filters); $paginator = new \com\indigloo\ui\Pagination($qparams, $pageSize); $userDBRows = $userDao->getPaged($paginator, $filters); $gtoken = "";
break; default: $sortVariable = "likes"; } $zsetKey = Nest::score("post", $sortVariable); $members = $redis->getPagedZSet($zsetKey, $paginator); $count = 0; $scores = array(); $ids = array(); if (sizeof($members) >= 2) { for ($i = 1; $i < sizeof($members); $i++) { // odd ones are members // evens are scores if ($i % 2 != 0) { $itemId = $members[$i - 1]; $postId = PseudoId::decode($itemId); array_push($ids, $postId); //score is next one $scores[$itemId] = isset($members[$i]) ? $members[$i] : 0; } } } $rows = $postDao->getOnSearchIds($ids); $pageNo = $paginator->getPageNo(); $startId = ($pageNo - 1) * $pageSize; $endId = $startId + $pageSize - 1; $rowsHtml = ""; $gNumRecords = sizeof($rows); foreach ($rows as $row) { $score = isset($scores[$row["pseudo_id"]]) ? $scores[$row["pseudo_id"]] : 0; $rowsHtml .= \com\indigloo\sc\html\Post::getAdminWidget($row, $score);
//sc/user/dashboard/posts.php include 'sc-app.inc'; include APP_WEB_DIR . '/inc/header.inc'; include APP_WEB_DIR . '/inc/role/user.inc'; 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();
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; }
<?php include 'sc-app.inc'; include APP_CLASS_LOADER; use com\indigloo\sc\util\PseudoId; if ($argc < 3) { printf("Usage : {$php} change.php <pseudo_id> <password> \n"); exit; } $pseudoId = $argv[1]; $pseudoId = trim($pseudoId); $password = $argv[2]; $loginId = PseudoId::decode($pseudoId); //get email lookup on loginId $userDao = new \com\indigloo\sc\dao\User(); $row = $userDao->getOnLoginId($loginId); $email = $row["email"]; printf("change for login_id = %s, email = %s \n ", $loginId, $email); $data = \com\indigloo\auth\User::changePassword("sc_user", $loginId, $email, $password);
static function createPostView($row, $voptions = NULL) { $voptions = empty($voptions) ? array() : $voptions; //default options $options = array(); $options["abbreviate"] = false; $options["image"] = true; $options["group"] = false; //override defaults foreach ($voptions as $key => $value) { $options[$key] = $value; } $imagesJson = $row["images_json"]; $images = json_decode($imagesJson); $view = new \stdClass(); $view->hasImage = false; $view->images = NULL; $view->hasGroups = false; $view->groups = array(); $view->id = $row['id']; $view->itemId = PseudoId::encode($view->id); // title in DB is 128 chars long. // here on page we want to use a 70 char title. // also used in item images alt text // clean up bad utf-8 data for display $view->title = Util::filterBadUtf8($row['title']); $view->title = Util::abbreviate($view->title, 70); $view->description = Util::filterBadUtf8($row['description']); if ($options["abbreviate"]) { $view->description = Util::abbreviate($view->description, 160); } $view->userName = $row['user_name']; $view->createdOn = AppUtil::convertDBTime($row['created_on']); $view->pubUserId = PseudoId::encode($row['login_id']); $view->loginId = $row['login_id']; $view->userPageURI = "/pub/user/" . $view->pubUserId; //process post image. if (!empty($images) && sizeof($images) > 0 && $options["image"]) { /* process image #1 */ $view->hasImage = true; $image = $images[0]; $imgv = self::convertImageJsonObj($image); $view->thumbnail = $imgv["thumbnail"]; $view->height = $imgv["height"]; $view->width = $imgv["width"]; $view->srcImage = $imgv["source"]; /* assign all images */ $view->images = $images; } //process groups if ($options["group"] === true) { $group_slug = $row['group_slug']; $groups = array(); if (!is_null($group_slug) && strlen($group_slug) > 0) { $slugs = explode(Constants::SPACE, $group_slug); $display = NULL; foreach ($slugs as $slug) { if (empty($slug)) { continue; } //@imp @todo @hack // dirty hack - for single quotes in group name - for old data // anything indexed as flury's - should be converted to flury // now we ignore the single quote in group name so we should be fine $slug = str_replace("'s", "", $slug); $display = StringUtil::convertKeyToName($slug); $groups[] = array("slug" => $slug, "display" => $display); } } if (sizeof($groups) > 0) { $view->hasGroups = true; $view->groups = $groups; } } return $view; }
use com\indigloo\ui\form\Message as FormMessage; use com\indigloo\sc\auth\Login; use com\indigloo\sc\util\PseudoId; $sticky = new Sticky($gWeb->find(Constants::STICKY_MAP, true)); $encodedId = Url::getQueryParam("id"); $commentId = PseudoId::decode($encodedId); $qUrl = Url::tryBase64QueryParam("q", "/"); $fUrl = Url::current(); $commentDao = new com\indigloo\sc\dao\Comment(); $commentDBRow = $commentDao->getOnId($commentId); if (!(Login::isOwner($commentDBRow['login_id']) || Login::isAdmin())) { header("Location: /site/error/403.html"); exit; } $sticky = new Sticky($gWeb->find(Constants::STICKY_MAP, true)); $itemId = PseudoId::encode($commentDBRow['post_id']); ?> <!DOCTYPE html> <html> <head> <title> Edit Comment</title> <?php include APP_WEB_DIR . '/inc/meta.inc'; ?> <?php echo \com\indigloo\sc\util\Asset::version("/css/bundle.css"); ?> </head>
static function getSessionTable($rows) { for ($i = 0; $i < count($rows); $i++) { $rows[$i]["pubUrl"] = "/pub/user/" . PseudoId::encode($rows[$i]["login_id"]); } $html = NULL; $template = '/fragments/site/analytic/session.tmpl'; $view = new \stdClass(); $view->rows = $rows; $html = Template::render($template, $view); return $html; }
function getOnItemId($itemId) { $postId = PseudoId::decode($itemId); $row = mysql\Post::getOnId($postId); return $row; }
include 'sc-app.inc'; include APP_WEB_DIR . '/inc/header.inc'; include APP_WEB_DIR . '/inc/role/user.inc'; use com\indigloo\Url; use com\indigloo\Logger; use com\indigloo\sc\auth\Login; use com\indigloo\Constants; use com\indigloo\ui\form\Sticky; use com\indigloo\ui\form\Message as FormMessage; use com\indigloo\sc\util\PseudoId; $sticky = new Sticky($gWeb->find(Constants::STICKY_MAP, true)); $qUrl = Url::tryBase64QueryParam("q", "/"); $fUrl = Url::current(); $encodedId = Url::getQueryParam("id"); $commentId = PseudoId::decode($encodedId); $commentDao = new \com\indigloo\sc\dao\Comment(); $commentDBRow = $commentDao->getOnId($commentId); if (!(Login::isOwner($commentDBRow['login_id']) || Login::isAdmin())) { header("Location: /site/error/403.html"); exit; } ?> <!DOCTYPE html> <html> <head> <title>3mik.com - Delete a comment</title> <?php include APP_WEB_DIR . '/inc/meta.inc';
static function create($title, $description, $loginId, $name, $linksJson, $imagesJson, $groupSlug, $categoryCode) { $dbh = NULL; try { $sql1 = " insert into sc_post(title,description,login_id,links_json, "; $sql1 .= " images_json,group_slug,cat_code, pseudo_id,created_on) "; $sql1 .= " values (:title,:description,:login_id,:links_json,:images_json, "; $sql1 .= " :group_slug, :cat_code, :pseudo_id, now()) "; $dbh = PDOWrapper::getHandle(); //Tx start $dbh->beginTransaction(); //insert into sc_post, change counters via trigger $stmt1 = $dbh->prepare($sql1); $stmt1->bindParam(":title", $title); $stmt1->bindParam(":description", $description); $stmt1->bindParam(":login_id", $loginId); $stmt1->bindParam(":links_json", $linksJson); $stmt1->bindParam(":images_json", $imagesJson); $stmt1->bindParam(":group_slug", $groupSlug); $stmt1->bindParam("cat_code", $categoryCode); // @see http://drupal.org/node/1369332 // pseudo_id is part of a UNIQUE index and mysql has to lock // the index attached to pseudo_id if we do not insert anything // NULL not being comparable to anything, it doesn't participate // in uniqueness constraints and MySQL doesn't have to lock the index. // $pseudoId = NULL ; // $stmt1->bindParam(":pseudo_id", $pseudoId); $stmt1->bindValue(":pseudo_id", null, \PDO::PARAM_STR); $stmt1->execute(); $stmt1 = NULL; $postId = $dbh->lastInsertId(); settype($postId, "integer"); $itemId = PseudoId::encode($postId); if (strlen($itemId) > 32) { throw new DBException("exceeds pseudo_id column size of 32"); } $sql2 = "update sc_post set pseudo_id = :item_id where id = :post_id "; $stmt2 = $dbh->prepare($sql2); $stmt2->bindParam(":item_id", $itemId); $stmt2->bindParam(":post_id", $postId); $stmt2->execute(); $stmt2 = NULL; $sql3 = " insert into sc_activity(owner_id,subject_id,subject,object_id, "; $sql3 .= " object,verb, verb_name, op_bit, created_on) "; $sql3 .= " values(:owner_id, :subject_id, :subject, :object_id, "; $sql3 .= " :object, :verb, :verb_name, :op_bit, now()) "; $verb = AppConstants::POST_VERB; $op_bit = 0; $verbName = AppConstants::STR_POST; $stmt3 = $dbh->prepare($sql3); $stmt3->bindParam(":owner_id", $loginId); $stmt3->bindParam(":subject_id", $loginId); $stmt3->bindParam(":object_id", $itemId); $stmt3->bindParam(":subject", $name); $stmt3->bindParam(":object", $title); $stmt3->bindParam(":verb", $verb); $stmt3->bindParam(":verb_name", $verbName); $stmt3->bindParam(":op_bit", $op_bit); $stmt3->execute(); $stmt3 = NULL; //Tx end $dbh->commit(); $dbh = null; return $itemId; } catch (\PDOException $e) { $dbh->rollBack(); $dbh = null; throw new DBException($e->getMessage(), $e->getCode()); } catch (\Exception $ex) { $dbh->rollBack(); $dbh = null; throw new DBException($ex->getMessage()); } }
function deleteItems($loginId, $listId, $itemsJson) { $items = json_decode($itemsJson); //get all the itemIds $itemIds = array(); foreach ($items as $item) { $itemId = PseudoId::decode($item); array_push($itemIds, $itemId); } if (empty($itemIds)) { //@todo - throw error? return; } mysql\Lists::deleteItems($loginId, $listId, $itemIds); }
$listDao = new \com\indigloo\sc\dao\Lists(); $name = $fvalues["new-list-name"]; if ($flag == 1 && empty($listId)) { // create new list if (!Util::isAlphaNumeric($name)) { $error = "Bad name : only letters and numbers are allowed!"; throw new UIException(array($error)); } $listId = $listDao->create($loginId, $name, $itemId); $pListId = PseudoId::encode($listId); } else { // Add to existing list // this can also be defaults lists // so we should get listId from addItem call $listId = $listDao->addItem($loginId, $listId, $itemId); $pListId = PseudoId::encode($listId); } $listUrl = ListHtml::getPubLink($pListId); $message = sprintf("success! items added to list %s", $listUrl); $gWeb->store(Constants::FORM_MESSAGES, array($message)); header("Location: " . $qUrl); } catch (UIException $ex) { $gWeb->store(Constants::STICKY_MAP, $fvalues); $gWeb->store(Constants::FORM_ERRORS, $ex->getMessages()); header("Location: " . $qUrl); exit(1); } catch (DBException $ex) { Logger::getInstance()->error($ex->getMessage()); Logger::getInstance()->backtrace($ex->getTrace()); $gWeb->store(Constants::STICKY_MAP, $fvalues); $message = "Error: something went wrong with database operation";
<?php //sc/qa/show.php include 'sc-app.inc'; include APP_WEB_DIR . '/inc/header.inc'; use com\indigloo\Util; use com\indigloo\Url; use com\indigloo\sc\util\PseudoId; $postId = Url::getQueryParam("id"); //Add permanent redirect $redirectUrl = "/item/" . PseudoId::encode($postId); header("HTTP/1.1 301 Moved Permanently"); header("Location: " . $redirectUrl); exit;
static function create($loginId, $name, $seoName, $hash, $bin_hash, $strItemsJson, $postId, $dl_bit) { try { //input check settype($loginId, "integer"); settype($postId, "integer"); Util::isEmpty("name", $name); Util::isEmpty("md5 hash of name", $hash); Util::isEmpty("md5 bin hash of name", $bin_hash); //list // op_bit is offline_processing bit - set to zero on create $sql1 = "insert into sc_list (login_id,name, seo_name,md5_name, bin_md5_name, "; $sql1 .= "items_json, version, op_bit , created_on, pseudo_id, dl_bit) "; $sql1 .= " values(:login_id,:name,:seo_name,:hash,:bin_hash, "; $sql1 .= " :items_json, 1 , 0, now(), :pseudo_id, :dl_bit) "; $dbh = PDOWrapper::getHandle(); // *** Tx start *** $dbh->beginTransaction(); $stmt = $dbh->prepare($sql1); $stmt->bindParam(":login_id", $loginId); $stmt->bindParam(":name", $name); $stmt->bindParam(":seo_name", $seoName); $stmt->bindParam(":hash", $hash); $stmt->bindParam(":bin_hash", $bin_hash); $stmt->bindParam(":items_json", $strItemsJson); //set pseudo_id to NULL explicitly $stmt->bindValue(":pseudo_id", null, \PDO::PARAM_STR); $stmt->bindParam(":dl_bit", $dl_bit); $stmt->execute(); $stmt = NULL; $listId = $dbh->lastInsertId(); settype($listId, "integer"); // list:item relationships $sql2 = "insert into sc_list_item(list_id, item_id) values (%d,%d)"; $sql2 = sprintf($sql2, $listId, $postId); $dbh->exec($sql2); // update item_count + pseudo_id of list $pseudoId = PseudoId::encode($listId); $sql3 = " update sc_list set item_count = 1, pseudo_id = :pseudo_id "; $sql3 .= " where id = :list_id "; $stmt3 = $dbh->prepare($sql3); $stmt3->bindParam(":list_id", $listId); $stmt3->bindParam(":pseudo_id", $pseudoId); $stmt3->execute(); $stmt3 = NULL; // *** Tx end *** $dbh->commit(); $dbh = null; return $listId; } catch (\PDOException $e) { $dbh->rollBack(); $dbh = null; throw new DBException($e->getMessage(), $e->getCode()); } catch (\Exception $ex) { $dbh->rollBack(); $dbh = null; throw new DBException($ex->getMessage(), $ex->getCode()); } }
} printf("\n\n"); /* Do not select items that were liked but deleted in the iterim select subject_id, object_id, verb from sc_bookmark b,sc_post p where b.object_id = p.pseudo_id and b.verb = 1 ; */ $sql = "select subject_id, object_id from sc_bookmark b,sc_post p "; $sql .= " where b.object_id = p.pseudo_id and b.verb = 1 "; $rows = MySQL\Helper::fetchRows($mysqli, $sql); $t11 = " update sc_user_counter set like_count = like_count + 1 where login_id = %s ; "; $t21 = " update sc_post_counter set like_count = like_count + 1 where post_id = %s ; "; foreach ($rows as $row) { $t1sql = sprintf($t11, $row["subject_id"]); //sc_bookmark.object_id is pseudo_id $postId = PseudoId::decode($row["object_id"]); $t2sql = sprintf($t21, $postId); printf("%s \n", $t1sql); printf("%s \n", $t2sql); } printf("\n\n"); /* no concept of deleting the user in system as on 22 nov. 2012 */ $sql = " select follower_id, following_id from sc_follow "; $rows = MySQL\Helper::fetchRows($mysqli, $sql); $t1 = " update sc_user_counter set follower_count = follower_count + 1 where login_id = %s ; "; $t2 = " update sc_user_counter set following_count = following_count + 1 where login_id = %s ; "; foreach ($rows as $row) { $t1sql = sprintf($t1, $row["following_id"]); $t2sql = sprintf($t2, $row["follower_id"]); printf("%s \n", $t1sql); printf("%s \n", $t2sql);
use com\indigloo\sc\auth\Login; use com\indigloo\ui\form\Message as FormMessage; use com\indigloo\ui\form\Sticky; use com\indigloo\ui\Filter; use com\indigloo\sc\util\PseudoId; $sticky = new Sticky($gWeb->find(Constants::STICKY_MAP, true)); $panelId = $sticky->get("panel_id"); $qparams = Url::getRequestQueryParams(); $gSessionLogin = \com\indigloo\sc\auth\Login::getLoginInSession(); $loginId = $gSessionLogin->id; $loginName = $gSessionLogin->name; if (is_null($loginId)) { trigger_error("Error : NULL or invalid login_id", E_USER_ERROR); } $plistId = Url::getQueryParam("list_id"); $listId = PseudoId::decode($plistId); settype($listId, "int"); $listDao = new \com\indigloo\sc\dao\Lists(); $listDBRow = $listDao->getOnId($listId); $listName = $listDBRow["name"]; //list owner check if (!Login::isOwner($listDBRow["login_id"])) { header("Location: /site/error/403.html"); exit; } $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");
function process($params, $options) { if (is_null($params) || empty($params)) { $controller = new \com\indigloo\sc\controller\Http400(); $controller->process(); exit; } $itemId = Util::getArrayKey($params, "item_id"); if ($itemId < 1200) { //@todo remove permanent redirect $redirectUrl = "/item/" . PseudoId::encode($itemId); header("HTTP/1.1 301 Moved Permanently"); header("Location: " . $redirectUrl); exit; } $postDao = new \com\indigloo\sc\dao\Post(); $postId = PseudoId::decode($itemId); $postDBRow = $postDao->getOnId($postId); if (empty($postDBRow)) { //not found $controller = new \com\indigloo\sc\controller\Http404(); $controller->process(); exit; } $options = array(); $options["group"] = true; $postView = \com\indigloo\sc\html\Post::createPostView($postDBRow, $options); // links is separate from postView for historical reasons $linksJson = $postDBRow['links_json']; $dblinks = json_decode($linksJson); $links = array(); foreach ($dblinks as $link) { $link = Url::addHttp($link); array_push($links, $link); } /* data for facebook/google+ dialogs */ $itemObj = new \stdClass(); $itemObj->appId = Config::getInstance()->get_value("facebook.app.id"); $itemObj->host = Url::base(); /* google+ cannot redirect to local box */ $itemObj->netHost = "http://www.3mik.com"; $itemObj->callback = $itemObj->host . "/callback/fb-share.php"; if ($postView->hasImage) { /* use original image for og snippets, smaller images may be ignored */ /* facebook and google+ dialogs need absolute URL */ $itemObj->picture = $postView->srcImage; } else { $itemObj->picture = $itemObj->host . "/css/asset/sc/logo.png"; } //do not urlencode - as we use this value as canonical url $itemObj->link = $itemObj->host . "/item/" . $itemId; $itemObj->netLink = $itemObj->netHost . "/item/" . $itemId; // title in DB is 128 chars long. // here on page we want to use a 70 char title. // also used in item images alt text // item description should be 160 chars. $itemObj->title = Util::abbreviate($postView->title, 70); $itemObj->title = sprintf("item %s - %s", $itemId, $itemObj->title); $itemObj->description = Util::abbreviate($postView->description, 160); $itemObj->description = sprintf("item %s - %s by user %s", $itemId, $itemObj->description, $postView->userName); $strItemObj = json_encode($itemObj); //make the item json string form safe $strItemObj = Util::formSafeJson($strItemObj); /* likes data */ $bookmarkDao = new \com\indigloo\sc\dao\Bookmark(); $likeDBRows = $bookmarkDao->getLikeOnItemId($itemId); $gWeb = \com\indigloo\core\Web::getInstance(); /* sticky is used by comment form */ $sticky = new Sticky($gWeb->find(Constants::STICKY_MAP, true)); $gRegistrationPopup = false; $loginIdInSession = \com\indigloo\sc\auth\Login::tryLoginIdInSession(); //show registration popup if (is_null($loginIdInSession)) { $register_popup = $gWeb->find("sc:browser:registration:popup"); $register_popup = is_null($register_popup) ? false : $register_popup; if (!$register_popup) { $gRegistrationPopup = true; $gWeb->store("sc:browser:registration:popup", true); } } $group_slug = $postDBRow["group_slug"]; $groupDao = new \com\indigloo\sc\dao\Group(); $group_names = $groupDao->tokenizeSlug($group_slug, ",", true); $pageTitle = $itemObj->title; $metaKeywords = SeoData::getMetaKeywords($group_names); $pageUrl = Url::base() . Url::current(); $file = APP_WEB_DIR . '/view/item.php'; include $file; }
static function getAdminWidget($row, $score = 0) { $view = new \stdClass(); //db fields $view->id = $row["id"]; $view->loginId = $row["login_id"]; $view->provider = $row["provider"]; $view->email = $row["email"]; $view->website = $row["website"]; $view->name = $row["name"]; $view->location = $row["location"]; //display fields $view->pubId = PseudoId::encode($row["login_id"]); $view->createdOn = AppUtil::convertDBTime($row["created_on"]); $ts = Util::secondsInDBTimeFromNow($row["created_on"]); $span = 24 * 3600; $view->last24hr = $ts < $span ? true : false; $view->ban = $row["bu_bit"] == 0 ? true : false; $view->unban = $row["bu_bit"] == 1 ? true : false; $view->taint = $row["tu_bit"] == 0 ? true : false; $view->score = $score > 0 ? $score : ""; $html = NULL; $template = "/fragments/user/admin/widget.tmpl"; $html = Template::render($template, $view); return $html; }