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; }
$fUrl = Url::current(); $itemId = Url::getQueryParam("id"); $postId = PseudoId::decode($itemId); $postDao = new \com\indigloo\sc\dao\Post(); $postDBRow = $postDao->getOnId($postId); if (!(Login::isOwner($postDBRow['login_id']) || Login::isAdmin())) { header("Location: /site/error/403.html"); exit(1); } $loginId = Login::getLoginIdInSession(); $strImagesJson = $sticky->get('images_json', $postDBRow['images_json']); $strLinksJson = $sticky->get('links_json', $postDBRow['links_json']); //@imp: we are enclosing the JSON string in single quotes //so the single quotes in string from DB should be escaped $strImagesJson = Util::formSafeJson($strImagesJson); $strLinksJson = Util::formSafeJson($strLinksJson); $groupDao = new \com\indigloo\sc\dao\Group(); $group_names = $groupDao->tokenizeSlug($postDBRow['group_slug'], ",", true); ?> <!DOCTYPE html> <html> <head> <title> 3mik.com - Share your find, need and knowledge</title> <?php include APP_WEB_DIR . '/inc/meta.inc'; ?> <?php echo \com\indigloo\sc\util\Asset::version("/css/bundle.css");
function addItem($loginId, $listId, $itemId) { // transpose of defaults list // 1 => favorites, 2 => wishlist etc. $transpose = array_flip($this->defaults); if (array_key_exists($listId, $transpose)) { //create new list with dl_bit set to 1 $name = $transpose[$listId]; $listId = $this->create($loginId, $name, $itemId, 1); return $listId; } // list ownership check is required // when we do not pass the loginId to backend // someone assuming a "fake" loginId is a problem // that data layer cannot solve! $this->isOwner($loginId, $listId); $postId = PseudoId::decode($itemId); $row = $this->getOnId($listId); $dbItemsJson = $row["items_json"]; $dbItems = json_decode($dbItemsJson); $dbItemIds = array(); foreach ($dbItems as $dbItem) { array_push($dbItemIds, $dbItem->id); } // update items_json summary only if // #1 - the number of items < 4 // #2 - we have not seen this item earlier if (sizeof($dbItemIds) < 4 && !in_array($itemId, $dbItemIds)) { //get item row $postDao = new \com\indigloo\sc\dao\Post(); $imgv = $postDao->tryImageOnId($postId); if (!is_null($imgv)) { $json = new \stdClass(); $json->id = $itemId; $json->thumbnail = $imgv["thumbnail"]; array_push($dbItems, $json); } } $itemsJson = json_encode($dbItems); $itemsJson = Util::formSafeJson($itemsJson); mysql\Lists::addItem($listId, $itemsJson, $postId); return $listId; }