示例#1
0
文件: Lists.php 项目: rjha/sc
 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;
 }
示例#2
0
文件: Mail.php 项目: rjha/sc
 /**
  * @return code - returned from sendgrid mail wrapper. 
  * A non zero code indicate failure, zero means success 
  *
  */
 static function sendActivityMail($name, $email, $feedText, $feedHtml)
 {
     $templates = \com\indigloo\sc\html\Mail::getActivity($name, $feedText, $feedHtml);
     //get new text and html now.
     $text = $templates["text"];
     $html = $templates["html"];
     // According to mail chimp research - mail  subject
     // should be 50 chars or less
     // However we need to send long post titles in subject.
     $subject = Util::abbreviate("3mik.com - " . $feedText, 100);
     $subject .= "...";
     $from = Config::getInstance()->get_value("default.mail.address");
     $fromName = Config::getInstance()->get_value("default.mail.name");
     $tos = array($email);
     $code = \com\indigloo\mail\SendGrid::sendViaWeb($tos, $from, $fromName, $subject, $text, $html);
     return $code;
 }
示例#3
0
文件: Post.php 项目: rjha/sc
 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;
 }
示例#4
0
文件: Post.php 项目: rjha/sc
 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;
 }
示例#5
0
文件: edit.php 项目: rjha/sc
use com\indigloo\exception\UIException;
if (isset($_POST['save']) && $_POST['save'] == 'Save') {
    $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('links_json', 'links_json', array('rawData' => 1));
        $fhandler->addRule('images_json', 'images_json', array('rawData' => 1));
        $fhandler->addRule('group_names', 'Tags', array('maxlength' => 64, 'rawData' => 1));
        $fhandler->addRule('qUrl', 'qUrl', array('required' => 1, 'rawData' => 1));
        $fvalues = $fhandler->getValues();
        $qUrl = base64_decode($fvalues['qUrl']);
        if ($fhandler->hasErrors()) {
            throw new UIException($fhandler->getErrors());
        }
        $groupDao = new \com\indigloo\sc\dao\Group();
        $group_names = $fvalues['group_names'];
        $group_slug = $groupDao->nameToSlug($group_names);
        $postDao = new com\indigloo\sc\dao\Post();
        $title = Util::abbreviate($fvalues['description'], 128);
        $postDao->update($fvalues['post_id'], $title, $fvalues['description'], $_POST['links_json'], $_POST['images_json'], $group_slug, $fvalues['category']);
        //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);
    }
}
示例#6
0
文件: Comment.php 项目: rjha/sc
 static function create($loginId, $name, $ownerId, $postId, $title, $comment)
 {
     $dbh = NULL;
     try {
         // insert into sc_comment, adjust counters via trigger
         $sql1 = " insert into sc_comment(post_id,description,login_id, created_on) ";
         $sql1 .= " values(:post_id,:comment,:login_id,now()) ";
         $dbh = PDOWrapper::getHandle();
         //Tx start
         $dbh->beginTransaction();
         $stmt1 = $dbh->prepare($sql1);
         $stmt1->bindParam(":post_id", $postId);
         $stmt1->bindParam(":comment", $comment);
         $stmt1->bindParam(":login_id", $loginId);
         $stmt1->execute();
         $stmt1 = NULL;
         $sql2 = " insert into sc_activity(owner_id,subject_id,subject,object_id, ";
         $sql2 .= " object,verb, verb_name, op_bit, content,created_on) ";
         $sql2 .= " values(:owner_id, :subject_id, :subject, :object_id, ";
         $sql2 .= " :object, :verb, :verb_name, :op_bit, :content,now()) ";
         $verb = AppConstants::COMMENT_VERB;
         $op_bit = 0;
         $verbName = AppConstants::STR_COMMENT;
         $content = Util::abbreviate($comment, 100);
         $stmt2 = $dbh->prepare($sql2);
         $stmt2->bindParam(":owner_id", $ownerId);
         $stmt2->bindParam(":subject_id", $loginId);
         $stmt2->bindParam(":object_id", $postId);
         $stmt2->bindParam(":subject", $name);
         $stmt2->bindParam(":object", $title);
         $stmt2->bindParam(":verb", $verb);
         $stmt2->bindParam(":verb_name", $verbName);
         $stmt2->bindParam(":op_bit", $op_bit);
         $stmt2->bindParam(":content", $content);
         $stmt2->execute();
         $stmt2 = NULL;
         //Tx end
         $dbh->commit();
         $dbh = null;
     } catch (\PDOException $e) {
         $dbh->rollBack();
         $dbh = null;
         throw new DBException($e->getMessage(), $e->getCode());
     } catch (\Exception $ex) {
         $dbh->rollBack();
         $dbh = null;
         $message = $ex->getMessage();
         throw new DBException($message);
     }
 }