Example #1
0
File: Util.php Project: rjha/sc
 static function convertDBTime($original)
 {
     if (CoreUtil::tryEmpty($original)) {
         return "";
     }
     $format = "%e %b, %Y";
     $dt = strftime($format, strtotime($original));
     return $dt;
 }
Example #2
0
File: Login.php Project: rjha/sc
 function create($firstName, $lastName, $email, $password)
 {
     $provider = \com\indigloo\sc\auth\Login::MIK;
     if (Util::tryEmpty($firstName) || Util::tryEmpty($lastName)) {
         throw new UIException(array("User name is missing!"));
     }
     $userName = $firstName . ' ' . $lastName;
     $remoteIp = \com\indigloo\Url::getRemoteIp();
     mysql\Login::create($provider, $userName, $firstName, $lastName, $email, $password, $remoteIp);
 }
Example #3
0
File: Post.php Project: rjha/sc
 /**
  * @error if links json is empty or spaces in DB column
  * @error if links json evaluates to NULL by json_decode
  * @error if links json is valid but not an array
  * @return an array of strings (links)
  *
  */
 function getLinkDataOnId($postId)
 {
     $row = mysql\Post::getLinkDataOnId($postId);
     $json = $row['json'];
     $links = NULL;
     if (!Util::tryEmpty($json)) {
         $links = json_decode($json);
     }
     if (is_null($links) || !is_array($links)) {
         $message = sprintf("Post %d has Bad json [ %s ] ", $postId, $json);
         Logger::getInstance()->error($message);
         $links = NULL;
     }
     $data = array('links' => $links, 'version' => $row['version']);
     return $data;
 }
Example #4
0
 function getDBParams()
 {
     $start = 1;
     $direction = "before";
     if (isset($this->qparams["gpa"]) && !Util::tryEmpty($this->qparams["gpa"])) {
         $direction = "after";
         $start = $this->qparams["gpa"];
     }
     if (isset($this->qparams["gpb"]) && !Util::tryEmpty($this->qparams["gpb"])) {
         $direction = "before";
         $start = $this->qparams["gpb"];
     }
     //this should not happen!
     if (Util::tryEmpty($start) || Util::tryEmpty($direction)) {
         trigger_error("paginator is missing [start | direction ] parameter", E_USER_ERROR);
     }
     $start = $this->convert ? base_convert($start, 36, 10) : $start;
     settype($start, "integer");
     return array("start" => $start, "direction" => $direction);
 }
Example #5
0
 static function render($options, $default)
 {
     $tab = Url::tryQueryParam("tab", $default);
     if (Util::tryEmpty($tab)) {
         $tab = $default;
     }
     if (!array_key_exists($tab, $options)) {
         $tab = $default;
     }
     $buffer = '';
     $item = '<li class="%s"> <a href="%s">%s</a></li>';
     foreach ($options as $key => $value) {
         $pageURI = Url::addQueryParameters($_SERVER['REQUEST_URI'], array("tab" => $key));
         $class = $tab == $key ? 'active' : '';
         $strItem = sprintf($item, $class, $pageURI, $value);
         $buffer .= $strItem;
     }
     $buffer = '<ul class="nav nav-tabs">' . $buffer . '</ul>';
     $data = array("buffer" => $buffer, "active" => $tab);
     return $data;
 }
Example #6
0
File: Post.php Project: rjha/sc
 static function getActivity($likeHtml, $commentHtml)
 {
     if (Util::tryEmpty($likeHtml) && Util::tryEmpty($commentHtml)) {
         return "";
     }
     $view = new \stdClass();
     $view->likeHtml = $likeHtml;
     $view->commentHtml = $commentHtml;
     $template = '/fragments/item/activity.tmpl';
     $html = Template::render($template, $view);
     return $html;
 }
Example #7
0
File: Login.php Project: rjha/sc
 static function isOwner($loginId)
 {
     //false on NULL or empty
     if (Util::tryEmpty($loginId)) {
         return false;
     }
     $flag = false;
     if (isset($_SESSION) && isset($_SESSION[self::TOKEN]) && isset($_SESSION[self::LOGIN_ID]) && $_SESSION[self::LOGIN_ID] == $loginId) {
         $flag = true;
     }
     return $flag;
 }
Example #8
0
 public function getSecureHtml($x)
 {
     // post value can be array for checkboxes
     // do not process arrays
     if (is_array($x)) {
         return $x;
     }
     $x = Util::tryEmpty($x) || !$this->translate ? $x : htmlspecialchars($x, ENT_QUOTES, "UTF-8");
     return trim($x);
 }
Example #9
0
File: Group.php Project: rjha/sc
 function nameToSlug($group_names)
 {
     $group_slug = "";
     if (!Util::tryEmpty($group_names)) {
         $slugs = array();
         $names = explode(",", $group_names);
         foreach ($names as $name) {
             if (Util::tryEmpty($name)) {
                 continue;
             }
             // remove single quotes from group names
             // it is a bit difficult to deal with single quotes and sphinx
             $name = str_replace("'", "", $name);
             $slug = \com\indigloo\util\StringUtil::convertNameToKey($name);
             array_push($slugs, $slug);
         }
         $group_slug = implode(Constants::SPACE, $slugs);
     }
     return $group_slug;
 }
Example #10
0
File: Group.php Project: rjha/sc
 static function process($postId, $loginId, $version, $catCode, $group_slug)
 {
     //sanitize input
     settype($postId, "integer");
     settype($loginId, "integer");
     settype($version, "integer");
     $sqlm1 = "insert ignore into sc_group_master(token,name,cat_code,created_on) values('%s','%s','%s',now()) ";
     $sqlm2 = "insert ignore into sc_user_group(login_id,token,name,created_on) values('%d','%s', '%s', now()) ";
     $sqlm3 = "update sc_site_tracker set group_flag = 1 where post_id = %d and version = %d ";
     $dbh = NULL;
     try {
         $dbh = PDOWrapper::getHandle();
         //Tx start
         $dbh->beginTransaction();
         $slugs = explode(Constants::SPACE, $group_slug);
         foreach ($slugs as $slug) {
             if (Util::tryEmpty($slug)) {
                 continue;
             }
             //do processing
             $name = \com\indigloo\util\StringUtil::convertKeyToName($slug);
             $sql = sprintf($sqlm1, $slug, $name, $catCode);
             $dbh->exec($sql);
             $sql = sprintf($sqlm2, $loginId, $slug, $name);
             $dbh->exec($sql);
         }
         //All group slugs for post processed
         $sql = sprintf($sqlm3, $postId, $version);
         $dbh->exec($sql);
         //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);
     }
 }
Example #11
0
File: SphinxQL.php Project: rjha/sc
 function getQuorum($index, $token, $hits, $offset, $limit)
 {
     if (Util::tryEmpty($token)) {
         return array();
     }
     Util::isEmpty("index", $index);
     $sql = sprintf("select id from %s where match('", $index);
     $sql .= '\\"' . $token . '\\"\\/' . $hits . "')";
     $sql .= sprintf(" limit %d,%d ", $offset, $limit);
     $rows = MySQL\Helper::fetchRows($this->connx, $sql);
     $ids = array();
     foreach ($rows as $row) {
         array_push($ids, $row["id"]);
     }
     return $ids;
 }
Example #12
0
File: Site.php Project: rjha/sc
 static function renderSlugPanel($dbslug)
 {
     $records = array();
     //explode DB slug on space
     $slugs = explode(Constants::SPACE, $dbslug);
     //sort slugs on alpha
     sort($slugs);
     foreach ($slugs as $slug) {
         if (Util::tryEmpty($slug)) {
             continue;
         }
         $slug = trim($slug);
         $name = StringUtil::convertKeyToName($slug);
         $records[] = array("slug" => $slug, "name" => $name, "checked" => "checked");
     }
     $view = new \stdClass();
     $template = "/fragments/ui/slug-panel.tmpl";
     $view->records = $records;
     $view->total = sizeof($records);
     $html = Template::render($template, $view);
     return $html;
 }
Example #13
0
 static function getSettings($options, $defaults)
 {
     if (empty($options) && empty($defaults)) {
         //nothing to do
         return array();
     }
     if (is_array($options) && !empty($options)) {
         // keys from options will override the ones
         // in default as array
         // @imp merge order will affect result!
         $settings = array_merge($defaults, $options);
     } else {
         $settings = $defaults;
     }
     //empty strings are equivalent to NULL
     foreach ($settings as $key => $value) {
         if (Util::tryEmpty($value)) {
             $settings[$key] = NULL;
         }
     }
     return $settings;
 }
Example #14
0
 static function getTile($loginId, $row, $source)
 {
     $view = self::createView($loginId, $row);
     $template = NULL;
     $hasImage = Util::tryEmpty($view->srcImage);
     $template = self::getTemplate($source, "tile", $hasImage);
     $html = Template::render($template, $view);
     return $html;
 }