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; }
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; }
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)); //q is part of URL and base64 encoded $qUrl = Url::tryBase64QueryParam("q", "/"); $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; } ?> <!DOCTYPE html> <html> <head> <title>3mik.com - Delete a post</title> <?php include APP_WEB_DIR . '/inc/meta.inc'; ?> <?php
function comment_to_activity($mysqli) { $sql = "select max(id) as total from sc_comment"; $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(); $postDao = new \com\indigloo\sc\dao\Post(); while ($count <= $pages) { $start = $count * $pageSize + 1; $end = $start + ($pageSize - 1); $sql = " select * from sc_comment 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) { $postId = $row['post_id']; $postDBRow = $postDao->getOnId($postId); $subjectId = $row['login_id']; $userDBRow = $userDao->getOnLoginId($subjectId); $subject = $userDBRow['name']; $ownerId = $postDBRow['login_id']; $object = $row['title']; $object = Util::filterBadUtf8($object); $content = $row['description']; $content = Util::filterBadUtf8($content); $verb = AppConstants::COMMENT_VERB; $objectId = $postId; $activityDao->addRow($ownerId, $subjectId, $objectId, $subject, $object, $verb, $content); } flush(); sleep(1); $count++; } }