array( 'name' => 'Thumbnail image', 'action' => 'resizeClipped', 'path' => 'pictures/blog/thumbnails/', 'width' => 134, 'height' => 202, 'quality' => 80 ), 'original' => array( 'name' => 'Original image', 'action' => 'copy', 'path' => 'pictures/blog/originals/', ), 'full' => array( 'name' => 'Full image', 'action' => 'resizeFit', 'path' => 'pictures/blog/full/', 'width' => 1000, 'height' => 2400, 'quality' => 80 ) ); public static $_imagesWatermark = array( 'path' => '../catalogue/watermark.png', 'location' => array(false,5,5,false), 'percent' => 30 ); /** * Creating new instance * @param int $id [optional] - id of the news item to load */ public function __construct( $id = false) { // self::getTags(); if ( $id !== false ) { $this->load($id); } } /** * Loading news item contents * @param int $id - id or link of the item to load * @return bool true on load, false on load error */ public function load($id) { if ( !$item = db::get(self::TABLE, $this->fields,array('id' => $id) ) ) { $item = db::get(self::TABLE, $this->fields,array('link' => $id) ); } if ( $item === false ) { return false; } foreach ( $item as $k => $v ) { $this->$k = $v; } // $this->loadProducts(); // $this->loadPosts(); // $this->loadTags(); $this->gallery = new gallery(self::TABLE_PICTURES,self::$_imagesBatch,'file',self::$_imagesBatch['original']['path'],$this->link,'../','title','visible','position','newsID',$this->id,array('watermark' => 'watermark')); return true; } /** * Loading all tags related to current news and build them into array with keys and names * * @return true on success, false on error */ /* public function loadTags() { if ( $this->id === false ) { return false; } $tags = db::table(self::TABLE_NEWS2TAGS,'tagID','tagID','','',''," AND newsID='" . $this->id . "'"); if ( empty($tags) ) { return false; } // $this->tags = array(); foreach ( $tags as $tID ) { if ( isset(self::$tagslist[$tID])) { // && self::$tagslist[$tID]['visible'] $this->tags[$tID] = self::$tagslist[$tID]['name']; } } return true; } /** * Loading all possible VISIBLE tags * @return array of tags */ /* public static function getTags() { if ( empty(self::$tagslist) ) { self::$tagslist = db::table(self::TABLE_TAGS,'id',array('name','visible'),'visible','',''); } return self::$tagslist; } /** * Getting link to current news item * @param $absolute [optional] - if the link should be absolute, false by default * * @return string - link to current news item (absolute one, from site root) */ public function getLink($absolute = false) { return ($absolute ? SITE::WEBSITE_ADDRESS : '' ) . '/' . self::LINK . '/' . $this->link; } /** * Loading products related to the news * @return true on success, false on error */ /* private function loadProducts() { $this->products = db::table(self::TABLE_RELATED,'position','relatedID','','position','ASC'," AND newsID='" . $this->id . "' AND (SELECT visibility FROM catalogue WHERE id=relatedID)=1"); return true; } /** * Checking if we have some products related to current news * @return true if we have products, false otherwise */ /* public function hasProducts() { return !empty($this->products); } /** * Checking if product with given id is already related to the news * @param int $productID - id of the product to check * @return bool true if product is already related to the news, false otherwise */ /* public function haveProduct($productID) { return $this->hasProducts() && array_search($productID, $this->products) ? true : false; } /** * Adding new product to news * @param int $productID - id of the product to add * @return bool true on success, false on error */ /* public function addProduct($productID) { if ( !$this->id ) { return false; } $data['position'] = $this->hasProducts() ? sizeof($this->products) + 1 : 1; $data['newsID'] = $this->id; $data['relatedID']= $productID; if ( false === db::add(self::TABLE_RELATED, $data) ) { return false; } $this->products[$data['position']] = $productID; return true; } /** * Removing product from news * @param int $productID - id of the product to remove * @return bool true on success, false on error */ /* public function removeProduct($productID) { if ( !$this->id ) { return false; } if ( !$this->haveProduct($productID) ) { return false; } if ( !db::remove(self::TABLE_RELATED,array('newsID' => $this->id, 'relatedID' => $productID) ) ) { return false; } $position = array_search($productID,$this->products); db::query("UPDATE `" . self::TABLE_RELATED . "` SET position=position-1 WHERE newsID='" . $this->id . "' AND position>='" . $position . "'"); unset($this->products[$position]); return true; } /** * Loading posts related to the news * @return true on success, false on error */ /* private function loadPosts() { $this->posts = db::table(self::TABLE_RELATED_POSTS,'position','relatedID','','position','ASC'," AND newsID='" . $this->id . "' AND (SELECT visibility FROM news WHERE id=relatedID)=1"); return true; } /** * Checking if we have some posts related to current news * @return true if we have posts, false otherwise */ /* public function hasPosts() { return !empty($this->posts); } /** * Checking if post with given id is already related to the news * @param int $postID - id of the post to check * @return bool true if post is already related to the news, false otherwise */ /* public function havePost($postID) { return $this->hasPosts() && array_search($postID, $this->posts) ? true : false; } /** * Adding new post to news * @param int $postID - id of the post to add * @return bool true on success, false on error */ /* public function addPost($postID) { if ( !$this->id ) { return false; } $data['position'] = $this->hasPosts() ? sizeof($this->posts) + 1 : 1; $data['newsID'] = $this->id; $data['relatedID']= $postID; if ( false === db::add(self::TABLE_RELATED_POSTS, $data) ) { return false; } $this->posts[$data['position']] = $postID; return true; } /** * Removing post from news * @param int $postID - id of the post to remove * @return bool true on success, false on error */ /* public function removePost($postID) { if ( !$this->id ) { return false; } if ( !$this->havePost($postID) ) { return false; } if ( !db::remove(self::TABLE_RELATED_POSTS,array('newsID' => $this->id, 'relatedID' => $postID) ) ) { return false; } $position = array_search($postID,$this->posts); db::query("UPDATE `" . self::TABLE_RELATED_POSTS . "` SET position=position-1 WHERE newsID='" . $this->id . "' AND position>='" . $position . "'"); unset($this->posts[$position]); return true; } /** * Render one current news - short form (for list of news on Blog page and Store) * @param array $im - image for current news * @param array $row - from DB with info on current news * @return string - news item */ /* public function renderNewsShort() { $html = '
'. ( $this->preview != '' ? '
'. ''. htmlspecialchars(stripslashes($this->name))  . ''. '
' : '' ). '
'. '

' . ''. stripslashes($this->name) . '' . '

'. '
'. date('F d, Y',strtotime($this->date)) .'
'. //date(SITE::DATE_FORMAT_NEWS,$row['date']) '
'. '

'. stripslashes($this->short_description) .'

'. '
'; if(!empty($this->tags)){ $html .= '
'. '
'; foreach($this->tags as $tagID => $tagName){ // $num = db::count(self::TABLE_NEWS2TAGS ,$search=array('tagID' => $tagID)," AND (SELECT visibility FROM news WHERE id=" . self::TABLE_NEWS2TAGS . ".newsID)=1 AND (SELECT deleted FROM news WHERE id=" . self::TABLE_NEWS2TAGS . ".newsID)=0"); $html .= ''.$tagName .' '; //' ('.$num.') } /*
10 */ /* $html .= '
'. '
'; } $html .= '
'. '
'; return $html; } /** * Getting all comments on the news */ /* static function loadComments($news_id) { return db::table(commentNews::TABLE_COMMENT_NEWS,'id',array('left_key','level'),'visibility','left_key','ASC',' AND deleted=0 AND approved=1 AND news_id='.$news_id); } /** * @param int $news_id - news for which comments will be rendering * @param user $_user - current user * @return string */ /* static function renderCommentBox ($news_id, $_user){ $html = ''; $comment_to_show = 3;//3 comment $counter = 0; //counter for root comment; if more than self:: then show button "More comment" $settingsComments = SITE::getParametersGroup('comments'); $avatar = '/'.SITE::PATH_AVATARS.'/avatar/'.(($_user->authorized && $_user->avatar)? $_user->avatar : SITE::NO_AVATAR); $book = self::loadComments($news_id); $num = is_array($book) ? count($book) : 0; $html .= '
'. '
'. ''. '
'. '
'. '
'. '
'. '

Write a comment

'. '
'. '
'. '
'. '
'. commentProduct::renderNewCommentBox($news_id,$_user,1). '
'. '
'; if ($num > 0){ $html .= '
'. '
'. '
'. '
'. commentProduct::renderNewCommentBox($news_id,$_user,true,1). '
'. '
'. '
    '; $arr = array(); $i = 0; foreach ($book as $id=>$val){ if ($val['level']==0) { $i++; } $arr[$i][$id] = $val; } for ($j=count($arr); $j>0; $j--){ $book1 = $arr[$j]; foreach ($book1 as $id=>$val){ $comment = new commentNews($id); if ($comment->level==0){$counter++;} if ($comment->user_id==0){ $ava = SITE::NO_AVATAR; } else { $ava= db::get(user::TABLE, 'avatar', array('id'=>$comment->user_id)); } $html .= '
  • '. '
    '. '
    ' . '' . '
    '. '
    '. '
    '. '' . $comment->name.' '.date( 'd \o\f F Y', strtotime($comment->date)).':'. '
    '. '

    '.stripslashes($comment->comment).'

    '. '
    '. '
    '. '
    '. 'reply'. //a href="" '
    '; if ($comment->hasChild()){$html .= '
      ';} else if ($level_delta = $comment->lastChild($book)){ for ($i=0; $i < $level_delta; $i++){ $html .= '
    '; } }; $html .= '
  • '; } } $html .= '
'. ($counter > $comment_to_show ? '
'. 'More comments'. ''. '
' : '' ); // data-toggle="collapse" data-target=".more">'.($more ? 'Less comments' : 'More comments') } $html .= ''. '
'.// '
'. // '
'. // '
';// return $html; } /** * Loading news JSON for the search in input field in CMS * @param bool $visible [optional] - if we should load only visible products * * @return string JSON object with product names and ids */ public static function getNewsJSON($visible=false) { $news = db::table(self::TABLE,'id',array('name','date'),$visible ? 'visibility' : '','date','DESC'); if ( empty($news) ) { return false; } $newsJSON = ' var news = ['; foreach ( $news as $id => $post ) { $newsJSON .= '{'. 'label: "' . addslashes($post['date'] . '. ' . $post['name']) .'",'. 'value : "' . $id . '"'. '},'; } $newsJSON = rtrim($newsJSON,', ') . '];'; return $newsJSON; } } ?>