Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
Arquivo: Comment.php Projeto: rjha/sc
 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;
 }
Exemplo n.º 3
0
 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;
 }
Exemplo n.º 4
0
Arquivo: Lists.php Projeto: rjha/sc
 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;
 }
Exemplo n.º 5
0
 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;
 }
Exemplo n.º 6
0
Arquivo: Activity.php Projeto: rjha/sc
 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;
 }
Exemplo n.º 7
0
<?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();
    }
}
Exemplo n.º 8
0
Arquivo: delete.php Projeto: rjha/sc
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);
    }
}
Exemplo n.º 9
0
Arquivo: User.php Projeto: rjha/sc
 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;
 }
Exemplo n.º 10
0
Arquivo: Lists.php Projeto: rjha/sc
 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());
     }
 }
Exemplo n.º 11
0
 static function getTable($loginId, $rows, $source, $options)
 {
     $html = NULL;
     $view = new \stdClass();
     $defaults = array("ui" => "table", "image" => false);
     $settings = Util::getSettings($options, $defaults);
     $records = array();
     foreach ($rows as $row) {
         $record = array();
         $userId = $row['login_id'];
         $pubUserId = PseudoId::encode($userId);
         $pubUserUrl = "/pub/user/" . $pubUserId;
         $record['pubUserUrl'] = $pubUserUrl;
         $record['name'] = $row['name'];
         $record['followingId'] = $userId;
         $record['followerId'] = $loginId;
         $record['hasImage'] = false;
         /*
                         if(!Util::tryEmpty($row["photo_url"])) {
                             $record['srcImage'] = $row["photo_url"];
                             $record['hasImage'] = true ;
                         }else {
                              $record['srcImage'] = UIConstants::PH2_PIC;
                         } */
         $record['srcImage'] = UIConstants::PH3_PIC;
         $records[] = $record;
     }
     $view->records = $records;
     settype($source, "integer");
     $template = self::getTemplate($source, $settings["ui"], $settings["image"]);
     $html = Template::render($template, $view);
     return $html;
 }
Exemplo n.º 12
0
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++;
    }
}
Exemplo n.º 13
0
Arquivo: edit.php Projeto: rjha/sc
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>
Exemplo n.º 14
0
Arquivo: Post.php Projeto: rjha/sc
 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());
     }
 }
Exemplo n.º 15
0
Arquivo: update.php Projeto: rjha/sc
    $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";
Exemplo n.º 16
0
Arquivo: Site.php Projeto: rjha/sc
 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;
 }
Exemplo n.º 17
0
Arquivo: show.php Projeto: rjha/sc
<?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;
Exemplo n.º 18
0
Arquivo: Post.php Projeto: 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&#039;s - should be converted to flury
                 // now we ignore the single quote in group name so we should be fine
                 $slug = str_replace("&#039;s", "", $slug);
                 $display = StringUtil::convertKeyToName($slug);
                 $groups[] = array("slug" => $slug, "display" => $display);
             }
         }
         if (sizeof($groups) > 0) {
             $view->hasGroups = true;
             $view->groups = $groups;
         }
     }
     return $view;
 }
Exemplo n.º 19
0
Arquivo: index.php Projeto: rjha/sc
//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();
Exemplo n.º 20
0
Arquivo: Post.php Projeto: 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;
 }