File indexing completed on 2024-12-22 05:33:31
0001 <?php 0002 /** 0003 * ocs-webserver 0004 * 0005 * Copyright 2016 by pling GmbH. 0006 * 0007 * This file is part of ocs-webserver. 0008 * 0009 * This program is free software: you can redistribute it and/or modify 0010 * it under the terms of the GNU Affero General Public License as 0011 * published by the Free Software Foundation, either version 3 of the 0012 * License, or (at your option) any later version. 0013 * 0014 * This program is distributed in the hope that it will be useful, 0015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0017 * GNU Affero General Public License for more details. 0018 * 0019 * You should have received a copy of the GNU Affero General Public License 0020 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0021 **/ 0022 0023 class Embedv1Controller extends Zend_Controller_Action 0024 { 0025 0026 protected $_format = 'json'; 0027 protected $_params = array(); 0028 0029 public function init() 0030 { 0031 parent::init(); 0032 $this->initView(); 0033 $this->_initResponseHeader(); 0034 } 0035 0036 public function initView() 0037 { 0038 // Disable render view 0039 $this->_helper->layout->disableLayout(); 0040 $this->_helper->viewRenderer->setNoRender(true); 0041 } 0042 0043 /** 0044 * @throws Zend_Exception 0045 0046 protected function _initRequestParamsAndFormat() 0047 { 0048 // Set request parameters 0049 switch (strtoupper($_SERVER['REQUEST_METHOD'])) { 0050 case 'GET': 0051 $this->_params = $_GET; 0052 break; 0053 case 'PUT': 0054 parse_str(file_get_contents('php://input'), $_PUT); 0055 $this->_params = $_PUT; 0056 break; 0057 case 'POST': 0058 $this->_params = $_POST; 0059 break; 0060 default: 0061 Zend_Registry::get('logger')->err( 0062 __METHOD__ . ' - request method not supported - ' 0063 . $_SERVER['REQUEST_METHOD'] 0064 ); 0065 exit('request method not supported'); 0066 } 0067 0068 // Set format option 0069 if (isset($this->_params['format']) 0070 && strtolower($this->_params['format']) == 'json' 0071 ) { 0072 $this->_format = 'json'; 0073 } 0074 } 0075 */ 0076 0077 0078 protected function _initResponseHeader() 0079 { 0080 $duration = 1800; // in seconds 0081 $expires = gmdate("D, d M Y H:i:s", time() + $duration) . " GMT"; 0082 0083 $this->getResponse() 0084 ->setHeader('X-FRAME-OPTIONS', 'ALLOWALL', true) 0085 // ->setHeader('Last-Modified', $modifiedTime, true) 0086 ->setHeader('Expires', $expires, true) 0087 ->setHeader('Pragma', 'cache', true) 0088 ->setHeader('Cache-Control', 'max-age=1800, public', true); 0089 } 0090 0091 public function indexAction() 0092 { 0093 $this->_sendErrorResponse(999, 'unknown request'); 0094 } 0095 0096 protected function _sendErrorResponse($statuscode, $message = '') 0097 { 0098 if ($this->_format == 'json') { 0099 $response = array( 0100 'status' => 'failed', 0101 'statuscode' => $statuscode, 0102 'message' => $message 0103 ); 0104 } 0105 $this->_sendResponse($response, $this->_format); 0106 } 0107 0108 protected function _sendResponse($response, $format = 'json', $xmlRootTag = 'ocs') 0109 { 0110 header('Pragma: public'); 0111 header('Cache-Control: cache, must-revalidate'); 0112 $duration = 1800; // in seconds 0113 $expires = gmdate("D, d M Y H:i:s", time() + $duration) . " GMT"; 0114 header('Expires: ' . $expires); 0115 $callback = $this->getParam('callback'); 0116 if ($callback != "") 0117 { 0118 header('Content-Type: text/javascript; charset=UTF-8'); 0119 // strip all non alphanumeric elements from callback 0120 $callback = preg_replace('/[^a-zA-Z0-9_]/', '', $callback); 0121 echo $callback. '('. json_encode($response). ')'; 0122 }else{ 0123 header('Content-Type: application/json; charset=UTF-8'); 0124 echo json_encode($response); 0125 } 0126 exit; 0127 } 0128 0129 0130 public function projectdetailAction(){ 0131 0132 $product = $this->_getProject($this->getParam('projectid')); 0133 0134 $html = ''; 0135 $html = $this->_getHTMLProjectDetail($product); 0136 $response = array( 0137 'status' => 'ok', 0138 'statuscode' => 100, 0139 'message' => '', 0140 'data' => array(), 0141 'html' =>'' 0142 ); 0143 if (!empty($product)) { 0144 $response['data'] = $product; 0145 } 0146 $response['html'] = $html; 0147 $this->_sendResponse($response, $this->_format); 0148 } 0149 0150 protected function _getHTMLProjectDetail($project) 0151 { 0152 $helperImage = new Default_View_Helper_Image(); 0153 $helperPrintDate = new Default_View_Helper_PrintDate(); 0154 $printRating= new Default_View_Helper_PrintRatingWidgetSimple(); 0155 $html = ''; 0156 $html = $html.'<div class="opendesktopwidget-main-detail-container-body-header">'; 0157 0158 $html = $html.'<div class="opendesktopwidget-img-member"><img src="'.$helperImage->Image($project['profile_image_url'], array('width' => 85, 'height' => 85)).'" /></div>'; 0159 $html = $html.'<div class="opendesktopwidget-description">'.$project['title']; 0160 $html = $html.'<span class="opendesktopwidget-category">'.$project['cat_title']; 0161 $html = $html.'</span>'; 0162 $html = $html.'</div>'; 0163 0164 $html = $html.'<div class="opendesktopwidget-rating">'; 0165 $html = $html.$printRating->printRatingWidgetSimple($project['laplace_score'],$project['count_likes'],$project['count_dislikes']); 0166 $html = $html.'</div>'; 0167 0168 $html = $html.'</div> <!-- end of opendesktopwidget-main-detail-container-body-header -->'; 0169 0170 0171 $html = $html.'<div class="opendesktopwidget-main-detail-container-body-content">'; 0172 0173 // carousels 0174 if(count($project['pics'])>0){ 0175 $html = $html.'<div class="opendesktopwidget-imgs">'; 0176 $html = $html.'<div id="opendesktopwidget-main-detail-carousel" data-simple-slider>'; 0177 //$html = $html.'<img src="'.$helperImage->Image($project['pics'][0], array('height' => '600')).'" />'; 0178 foreach ($project['pics'] as $pic) { 0179 $html = $html.'<div><img src="'.$helperImage->Image($pic, array('width' => '621', 'height' => '621')).'" /></div>'; 0180 } 0181 0182 $html = $html.'</div>'; 0183 /* 0184 if(count($project['pics'])>1){ 0185 $html = $html.'<button class="prev opendesktop-widget-btn"><i class="fa fa-chevron-left opendesktop-navi" aria-hidden="true"></i></button>'; 0186 $html = $html.'<button class="next opendesktop-widget-btn"><i class="fa fa-chevron-right opendesktop-navi" aria-hidden="true"></i></button>'; 0187 } 0188 */ 0189 $html = $html.'</div>'; 0190 } 0191 0192 0193 // begin opendesktopwidget-content 0194 $html = $html.'<div class="opendesktopwidget-content">'; 0195 $html = $html.'<div id="opendesktopwidget-content-tabs" class="pling-nav-tabs">'; 0196 $html = $html.'<ul>'; 0197 $html = $html.'<li class="active"><a data-wiget-target="#opendesktopwidget-content-description" data-toggle="tab">Product</a></li>'; 0198 if($project['files'] && count($project['files'])>0){ 0199 $html = $html.'<li><a data-wiget-target="#opendesktopwidget-content-files" data-toggle="tab">Files ('.count($project['files']).')</a></li>'; 0200 } 0201 if($project['changelogs'] && count($project['changelogs'])>0){ 0202 $html = $html.'<li><a data-wiget-target="#opendesktopwidget-content-changelogs" data-toggle="tab">Changelogs ('.count($project['changelogs']).')</a></li>'; 0203 } 0204 if($project['reviews'] && count($project['reviews'])>0){ 0205 $html = $html.'<li><a data-wiget-target="#opendesktopwidget-content-reviews" data-toggle="tab">Reviews ('.count($project['reviews']).')</a></li>'; 0206 } 0207 $html = $html.'</ul>'; 0208 $html = $html.'</div>'; 0209 0210 // begin opendesktopwidget-tab-pane-content 0211 $html = $html.'<div class="opendesktopwidget-tab-pane-content">'; 0212 0213 $html = $html.'<div id="opendesktopwidget-content-description" class="opendesktopwidget-tab-pane active">'; 0214 $html = $html.'<span class="description"> Description</span>'; 0215 $html = $html.$project['description']; 0216 if($project['lastchangelog']){ 0217 $html = $html.'<span class="description"> Last change log</span>'; 0218 $html = $html.'<span class="title"> '.$project['lastchangelog']['title'].'</span>'; 0219 $html = $html.'<span class="updatetime">'. $helperPrintDate->printDate($project['lastchangelog']['created_at']).'</span>'; 0220 $html = $html.'<span class="text"> '.$project['lastchangelog']['text'].'</span>'; 0221 } 0222 0223 // comments begin 0224 $html = $html.'<div class="opendesktopwidgetcomments">'; 0225 $html_comment = $this->_getHTMLPagerComments($project['comments']) 0226 .'<div id="opendesktopwidget-main-container-comments">' 0227 .$this->_getHTMLComments($project['comments']) 0228 .'</div>'; 0229 $html = $html.$html_comment; 0230 $html = $html.'</div>'; 0231 // comments end 0232 0233 $html = $html.'</div>'; // end opendesktopwidget-content-description 0234 0235 // begin opendesktopwidget-content-files 0236 $html = $html.'<div id="opendesktopwidget-content-files" class="opendesktopwidget-tab-pane">'; 0237 $html = $html.$this->_getHTMLFiles($project['files']); 0238 $html = $html.'</div>'; 0239 // end opendesktopwidget-content-files 0240 0241 // begin opendesktopwidget-content-changelogs 0242 $html = $html.'<div id="opendesktopwidget-content-changelogs" class="opendesktopwidget-tab-pane">'; 0243 $html = $html.$this->_getHTMLChangelogs($project['changelogs']); 0244 $html = $html.'</div>'; 0245 // end opendesktopwidget-content-changelogs 0246 0247 // begin opendesktopwidget-content-reviews 0248 $html = $html.'<div id="opendesktopwidget-content-reviews" class="opendesktopwidget-tab-pane">'; 0249 $html = $html.$this->_getHTMLReviews($project['reviews']); 0250 $html = $html.'</div>'; 0251 // end opendesktopwidget-content-reviews 0252 0253 0254 // end opendesktopwidget-tab-pane-content 0255 $html = $html.'</div>'; 0256 0257 0258 $html = $html.'</div>'; //opendesktopwidget-main-detail-container-body-content 0259 0260 $html = $html.'</div>'; // end opendesktopwidget-content 0261 // end opendesktopwidget-content 0262 0263 0264 return $html; 0265 } 0266 0267 protected function _getHTMLChangelogs($logs) 0268 { 0269 $helperPrintDate = new Default_View_Helper_PrintDate(); 0270 $html = '<div id="opendesktopwidget-changelogs">'; 0271 foreach ($logs as $log) { 0272 $html = $html.'<div class="opendesktopwidget-changelogs-title"><span class="opendesktopwidget-changelogs-title-1">'.$log['title'].'</span>'; 0273 $html = $html.'<span class="opendesktopwidget-changelogs-title-2">'.$helperPrintDate->printDate($log['created_at']).'</span>'; 0274 $html = $html.'</div>'; 0275 $html = $html.'<span class="opendesktopwidget-changelogs-text">'.$log['text'].'</span>'; 0276 } 0277 $html = $html.'</div>'; 0278 return $html; 0279 } 0280 0281 protected function _getHTMLReviews($reviews) 0282 { 0283 0284 $helperImage = new Default_View_Helper_Image(); 0285 $helperPrintDate = new Default_View_Helper_PrintDate(); 0286 0287 $cntActive = 0; 0288 $cntLikes = 0; 0289 $cntDislike = 0; 0290 $cntAll = count($reviews); 0291 foreach ($reviews as $review) { 0292 if($review['rating_active']==1) { 0293 $cntActive =$cntActive+1; 0294 $cntLikes = $cntLikes + $review['user_like']; 0295 $cntDislike = $cntDislike + $review['user_dislike']; 0296 } 0297 } 0298 0299 $html = '<div id="opendesktopwidget-reviews">'; 0300 0301 $html = $html.'<div class="opendesktopwidget-reviews-filters">'; 0302 $html = $html.'<button id="opendesktopwidget-reviews-filters-hates" class="opendesktop-widget-btn opendesktop-widget-reviews-filters-btn">Show ' 0303 .'<i class="fa fa-thumbs-o-down" aria-hidden="true" style="color:red"></i> ('.$cntDislike.')</button>'; 0304 $html = $html.'<button id="opendesktopwidget-reviews-filters-likes" class="opendesktop-widget-btn opendesktop-widget-reviews-filters-btn">Show ' 0305 .'<i class="fa fa-thumbs-o-up" aria-hidden="true" style="color:green"></i> ('.$cntLikes.')</button>'; 0306 $html = $html.'<button id="opendesktopwidget-reviews-filters-active" class="opendesktop-widget-btn opendesktop-widget-reviews-filters-btn opendesktopwidget-reviews-activeRating">Show Active Reviews ('.$cntActive.')</button>'; 0307 $html = $html.'<button id="opendesktopwidget-reviews-filters-all" class="opendesktop-widget-btn opendesktop-widget-reviews-filters-btn">Show all Reviews ('.$cntAll.')</button>'; 0308 $html = $html.'</div>'; 0309 0310 0311 foreach ($reviews as $review) { 0312 $clsActive = ''; 0313 $clsLike = ''; 0314 if($review['rating_active']==0){ 0315 $clsActive ='opendesktopwidget-reviews-rows-inactive '; 0316 }else{ 0317 $clsActive ='opendesktopwidget-reviews-rows-active '; 0318 } 0319 if($review['user_like']==1){ 0320 $clsLike ='opendesktopwidget-reviews-rows-clsUpvotes '; 0321 }else{ 0322 $clsLike ='opendesktopwidget-reviews-rows-clsDownvotes '; 0323 } 0324 0325 $html = $html.'<div class="opendesktopwidget-reviews-rows '.$clsActive.$clsLike.'">'; 0326 $html = $html.'<div class="opendesktopwidget-reviews-title">'; 0327 $html = $html.'<img class="opendesktopwidget-reviews-userimg" src="'.$helperImage->Image($review['profile_image_url'], array('width' => 40, 'height' => 40)).'" />'; 0328 $html = $html.'<span class="opendesktopwidget-reviews-title-1">'.$review['username'].'</span>'; 0329 $html = $html.'<span class="opendesktopwidget-reviews-title-2">'.$helperPrintDate->printDate($review['created_at']).'</span>'; 0330 if($review['user_like']==1){ 0331 $html = $html.'<i class="fa fa-thumbs-o-up opendesktopwidget-like" aria-hidden="true" ></i>'; 0332 }else{ 0333 $html = $html.'<i class="fa fa-thumbs-o-down opendesktopwidget-dislike" aria-hidden="true" ></i>'; 0334 } 0335 $html = $html.'</div>'; 0336 $html = $html.'<span class="opendesktopwidget-reviews-text">'.$review['comment_text'].'</span>'; 0337 $html = $html.'</div>'; 0338 } 0339 $html = $html.'</div>'; 0340 return $html; 0341 } 0342 0343 protected function _getProject($project_id){ 0344 $modelProduct = new Default_Model_Project(); 0345 $project = $modelProduct->fetchProductInfo($project_id); 0346 if ($project==null) { 0347 $this->_sendErrorResponse(101, 'content not found'); 0348 } 0349 0350 $result = array(); 0351 $result = array( 0352 'project_id' => $project['project_id'], 0353 'member_id' => $project['member_id'], 0354 'title' => $project['title'], 0355 'description' => $project['description'], 0356 'version' => $project['version'], 0357 'project_category_id' =>$project['project_category_id'], 0358 'project_created_at' =>$project['project_created_at'], 0359 'project_changed_at' => $project['project_changed_at'], 0360 'laplace_score' => $project['laplace_score'], 0361 'ppload_collection_id' => $project['ppload_collection_id'], 0362 'image_small' => $project['image_small'], 0363 'count_likes' => $project['count_likes'], 0364 'count_dislikes' => $project['count_dislikes'], 0365 'count_comments' => $project['count_comments'], 0366 'cat_title' => $project['cat_title'], 0367 'username' => $project['username'], 0368 'profile_image_url' => $project['profile_image_url'], 0369 'comments' => array(), 0370 'files' =>array(), 0371 'lastchangelog' => array(), 0372 'pics' => array(), 0373 'changelogs' => array(), 0374 'reviews' => array() 0375 ); 0376 0377 // gallerypics 0378 $galleryPictureTable = new Default_Model_DbTable_ProjectGalleryPicture(); 0379 $stmt = $galleryPictureTable->select()->where('project_id = ?', $project_id)->order(array('sequence')); 0380 $pics = array(); 0381 foreach ($galleryPictureTable->fetchAll($stmt) as $pictureRow) { 0382 $pics[] = $pictureRow['picture_src']; 0383 } 0384 $result['pics'] = $pics; 0385 0386 // changelogs 0387 $tableProjectUpdates = new Default_Model_ProjectUpdates(); 0388 $updates = $tableProjectUpdates->fetchProjectUpdates($project_id); 0389 if (count($updates) > 0) { 0390 $logs = array(); 0391 foreach ($updates as $update) { 0392 $logs[] = array( 0393 'title' => $update['title'], 0394 'text' => $update['text'], 0395 'created_at' => $update['created_at'], 0396 ); 0397 } 0398 $result['lastchangelog'] = $logs[0]; 0399 $result['changelogs'] = $logs; 0400 } 0401 0402 //reviews 0403 $tableProjectRatings = new Default_Model_DbTable_ProjectRating(); 0404 $reviews = $tableProjectRatings->fetchRating($project_id); 0405 $r = array(); 0406 foreach ($reviews as $review) { 0407 $r[] = array( 0408 'member_id' => $review['member_id'], 0409 'user_like' => $review['user_like'], 0410 'user_dislike' => $review['user_dislike'], 0411 'rating_active' => $review['rating_active'], 0412 'created_at' => $review['created_at'], 0413 'profile_image_url' => $review['profile_image_url'], 0414 'username' => $review['username'], 0415 'comment_text' => $review['comment_text'] 0416 ); 0417 } 0418 $result['reviews'] = $r; 0419 0420 // comments 0421 $comments = $this->_getCommentsForProject($project_id); 0422 $result['comments'] = $comments; 0423 0424 // pploadfiles 0425 $files = $this->_getPploadFiles($project['ppload_collection_id']); 0426 $result['files'] = $files; 0427 0428 return $result; 0429 } 0430 0431 public function commentsAction() 0432 { 0433 0434 $project_id = $this->getParam('id'); 0435 $page = $this->getParam('page'); 0436 $nopage = $this->getParam('nopage'); // with param nopage will only show prudusts list otherwise show 0437 $pageLimit = $this->getParam('pagelimit'); 0438 0439 if(empty($project_id)){ 0440 $response = array( 0441 'status' => 'ok', 0442 'statuscode' => 100, 0443 'message' => '', 0444 'totalitems' =>0, 0445 'html' =>'', 0446 'data' => array() 0447 ); 0448 }else{ 0449 0450 if(empty($page)) $page=0; 0451 if(empty($pageLimit)) $pageLimit=10; 0452 $comments = $this->_getCommentsForProject($project_id,$page,$pageLimit); 0453 0454 $commentsResult = $comments['result']; 0455 0456 $response = array( 0457 'status' => 'ok', 0458 'statuscode' => 100, 0459 'message' => '', 0460 'totalitems' => count($commentsResult), 0461 'data' => array() 0462 ); 0463 0464 if (!empty($commentsResult)) { 0465 $response['data'] = $commentsResult; 0466 // create html 0467 if(empty($nopage)) { 0468 // init with comments & pager 0469 $html = $this->_getHTMLPagerComments($comments) 0470 .'<div id="opendesktopwidget-main-container-comments">' 0471 .$this->_getHTMLComments($comments) 0472 .'</div>'; 0473 }else{ 0474 // for only ajax paging content 0475 $html =$this->_getHTMLComments($comments); 0476 } 0477 $response['html'] =$html; 0478 } 0479 0480 } 0481 0482 $this->_sendResponse($response, $this->_format); 0483 0484 0485 } 0486 0487 protected function _getHTMLComments($comments) 0488 { 0489 $commentslist = $comments['result']; 0490 $helperImage = new Default_View_Helper_Image(); 0491 $helperBuildMemberUrl = new Default_View_Helper_BuildMemberUrl(); 0492 $helperPrintDate = new Default_View_Helper_PrintDate(); 0493 $html = ''; 0494 foreach ($commentslist as $p) { 0495 $html = $html.'<div class="opendesktopwidgetcommentrow level'.$p['level'].'" id="opendesktopwidgetcommentrow_'.$p['comment_id'].'">'; 0496 0497 $html = $html.'<img class="image_small" src="'.$helperImage->Image($p['profile_image_url'], array('width' => 60, 'height' => 60)).'" />'; 0498 0499 $html = $html.'<div class="opendesktopwidgetcommentrow-header">'; 0500 $html = $html.'<span class="username">'.$p['username'].'</span>'; 0501 $html = $html.'<span class="updatetime">'. $helperPrintDate->printDate($p['comment_created_at']).'</span>'; 0502 $html = $html.'</div>'; 0503 0504 $html = $html.'<div class="opendesktopwidgetcomment_content">'; 0505 0506 0507 $html = $html.'<div class="commenttext">'.$p['comment_text'].'</div>'; 0508 0509 $html = $html.'</div><div style="clear:both"/> '; 0510 $html = $html.'</div><!-- end of opendesktopwidgetcommentrow -->'; 0511 } 0512 return $html; 0513 0514 } 0515 0516 0517 protected function _getCommentsForProject($project_id,$curPage=1,$pageItemsCount=10) 0518 { 0519 0520 $modelComments = new Default_Model_ProjectComments(); 0521 $comments = $modelComments->getCommentTreeForProject($project_id); 0522 $comments->setItemCountPerPage($pageItemsCount); 0523 $comments->setCurrentPageNumber($curPage); 0524 0525 $result = array(); 0526 0527 foreach ($comments as $comment) { 0528 0529 $c = $comment['comment']; 0530 0531 $result[] = array( 0532 'comment_id' => $c['comment_id'], 0533 'member_id' => $c['member_id'], 0534 'comment_text' => nl2br(Default_Model_HtmlPurify::purify($c['comment_text']),true), 0535 'level' => $comment['level'], 0536 'comment_type' => $c['comment_type'], 0537 'profile_image_url' => $c['profile_image_url'], 0538 'username' => $c['username'], 0539 'comment_target_id'=>$c['comment_target_id'], 0540 'comment_created_at' => $c['comment_created_at'] 0541 ); 0542 } 0543 0544 $rlt = array( 0545 'totalItemCount' => $comments->getTotalItemCount(), 0546 'count' => $comments->count(), 0547 'itemCountPerPage'=>$comments->getItemCountPerPage(), 0548 'result' => $result 0549 ); 0550 0551 0552 0553 0554 return $rlt; 0555 } 0556 0557 0558 public function memberprojectsAction() 0559 { 0560 $user_id = $this->getParam('memberid'); 0561 $page = $this->getParam('page'); 0562 $nopage = $this->getParam('nopage'); // with param nopage will only show prudusts list otherwise show member+pager+productlist 0563 $pageLimit = $this->getParam('pagelimit'); 0564 $catids = $this->getParam('catids'); 0565 0566 if(empty($pageLimit)){ 0567 $pageLimit = 10; 0568 } 0569 0570 if(empty($catids)){ 0571 $catids = null; 0572 } 0573 0574 if(empty($page)){ 0575 $page = 1; 0576 } 0577 if(empty($user_id)){ 0578 $response = array( 0579 'status' => 'ok', 0580 'statuscode' => 100, 0581 'message' => '', 0582 'totalitems' =>0, 0583 'html' =>'', 0584 'data' => array() 0585 ); 0586 }else{ 0587 0588 $userProducts = $this->_getMemberProducts($user_id, $pageLimit, $page,$catids); 0589 0590 $response = array( 0591 'status' => 'ok', 0592 'statuscode' => 100, 0593 'message' => '', 0594 'totalitems' => count($userProducts), 0595 'data' => array() 0596 ); 0597 if (!empty($userProducts)) { 0598 $response['data'] = $userProducts; 0599 // create html 0600 if(empty($nopage)) { 0601 // init with member & pager & products 0602 $html = $this->_getHTMLMember($user_id) 0603 .'<div id="opendesktopwidget-main">' 0604 .$this->_getHTMLPager($user_id,$pageLimit,$page,$catids) 0605 .'<div id="opendesktopwidget-main-container">' 0606 .$this->_getHTMLProducts($userProducts) 0607 .'</div>' 0608 .'</div>'; 0609 }else{ 0610 // for only ajax paging content 0611 $html =$this->_getHTMLProducts($userProducts); 0612 } 0613 $response['html'] =$html; 0614 } 0615 0616 } 0617 $this->_sendResponse($response, $this->_format); 0618 } 0619 0620 protected function _getHTMLMember($user_id) 0621 { 0622 $html = ''; 0623 $modelMember = new Default_Model_Member(); 0624 $m = $modelMember->fetchMemberData($user_id); 0625 $helperImage = new Default_View_Helper_Image(); 0626 $html = $html.'<div class="opendesktopwidgetheader">'; 0627 $html = $html.'<a href="https://www.opendesktop.org" target="_blank"><img class="opendesktoplogo" src="https://www.opendesktop.org/images_sys/store_opendesktop/logo.png" /></a>'; 0628 $html = $html.'<img class="profile_image" src="'.$helperImage->Image($m['profile_image_url'], array('width' => 110, 'height' => 110)).'" />'; 0629 $html = $html.'</div> <!--end of header-->'; 0630 return $html; 0631 0632 } 0633 0634 protected function _getHTMLProducts($userProducts) 0635 { 0636 $helperImage = new Default_View_Helper_Image(); 0637 $helperBuildProductUrl = new Default_View_Helper_BuildProductUrl(); 0638 $printRating= new Default_View_Helper_PrintRatingWidgetSimple(); 0639 $helperPrintDate = new Default_View_Helper_PrintDate(); 0640 $html = ''; 0641 foreach ($userProducts as $p) { 0642 $html = $html.'<div class="opendesktopwidgetrow" id="opendesktopwidgetrow_'.$p['id'] 0643 .' " data-project-id="'.$p['id'] 0644 .' " data-ppload-collection-id="'.$p['ppload_collection_id'].'">'; 0645 //$html = $html.'<a href="'.$this->_config['baseurl'].'p/'.$p['id'].'" target="_blank">'; 0646 $html = $html.'<img class="image_small" src="'.$helperImage->Image($p['image_small'], array('width' => 167, 'height' => 167)).'" />'; 0647 0648 $html = $html.'<div class="description-container">'; 0649 $html = $html.'<div class="description">'; 0650 $html = $html.'<span class="title">'.$p['title'].'</span>'; 0651 $html = $html.'<span class="version">'.$p['version'].'</span>'; 0652 $html = $html.'<span class="cat_name">'.$p['cat_name'].'</span>'; 0653 if($p['count_comments']>0){ 0654 $html = $html.'<span class="count_comments">'.$p['count_comments'].' comment' .($p['count_comments']>1?'s':'').'</span>'; 0655 } 0656 $html = $html.'</div><!--end of description-->'; 0657 0658 $html = $html.'<div class="rating">'; 0659 $html = $html.$printRating->printRatingWidgetSimple($p['laplace_score'],$p['count_likes'],$p['count_dislikes']); 0660 $html = $html.'<span class="updatetime">'. $helperPrintDate->printDate($p['changed']).'</span>'; 0661 $html = $html.'</div>'; 0662 0663 $html = $html.'</div><!--end of description-container-->'; 0664 //$html = $html.'</a><!--end of a-->'; 0665 $html = $html.'</div> <!-- end of opendesktopwidgetrow -->'; 0666 } 0667 return $html; 0668 } 0669 0670 protected function _getHTMLPager($user_id,$pageLimit=10,$page=1,$catids=null) 0671 { 0672 $modelProject = new Default_Model_Project(); 0673 $total_records = $modelProject->countAllProjectsForMemberCatFilter($user_id,true,$catids); 0674 $total_pages = ceil($total_records / $pageLimit); 0675 if($total_pages <=1) return ''; 0676 $html = '<div class="opendesktopwidgetpager"><ul class="opendesktopwidgetpager">'; 0677 for ($i=1; $i<=$total_pages; $i++) { 0678 if($i==$page){ 0679 $html = $html.'<li class="active"><span>'.$i.'</span></li>'; 0680 }else{ 0681 $html = $html.'<li><span>'.$i.'</span></li>'; 0682 } 0683 0684 }; 0685 $html = $html.'</ul></div>'; 0686 return $html; 0687 } 0688 0689 protected function _getHTMLPagerComments($comments) 0690 { 0691 0692 $total_pages = $comments['count']; 0693 if($total_pages<=1) return ''; 0694 $html = '<div class="opendesktopwidgetpager"><ul class="opendesktopwidgetpager">'; 0695 for ($i=1; $i<=$total_pages; $i++) { 0696 if($i==1){ 0697 $html = $html.'<li class="active"><span>'.$i.'</span></li>'; 0698 }else{ 0699 $html = $html.'<li><span>'.$i.'</span></li>'; 0700 } 0701 }; 0702 $html = $html.'</ul></div>'; 0703 return $html; 0704 } 0705 0706 0707 0708 protected function _getMemberProducts($user_id,$pageLimit=5,$page=1,$catids = null) 0709 { 0710 0711 $modelProject = new Default_Model_Project(); 0712 $userProjects = $modelProject->fetchAllProjectsForMemberCatFilter($user_id, $pageLimit,($page - 1) * $pageLimit, true,$catids); 0713 0714 $result = array(); 0715 foreach ($userProjects as $project) { 0716 $result[] = array( 0717 'id' => $project['project_id'], 0718 'title' => Default_Model_HtmlPurify::purify($project['title']), 0719 'desc' => Default_Model_HtmlPurify::purify($project['description']), 0720 'version' =>Default_Model_HtmlPurify::purify($project['version']), 0721 'cat_id' =>$project['project_category_id'], 0722 'cat_name' => $project['catTitle'], 0723 'created' =>$project['project_created_at'], 0724 'changed' => $project['project_changed_at'], 0725 'laplace_score' => $project['laplace_score'], 0726 'image_small' => $project['image_small'] , 0727 'count_dislikes' => $project['count_dislikes'], 0728 'count_likes' => $project['count_likes'], 0729 'count_comments' => $project['count_comments'] , 0730 'ppload_collection_id' => $project['ppload_collection_id'] 0731 ); 0732 0733 } 0734 return $result; 0735 } 0736 0737 0738 protected function _getPploadFiles($ppload_collection_id) 0739 { 0740 $result = array(); 0741 $pploadApi = new Ppload_Api(array( 0742 'apiUri' => PPLOAD_API_URI, 0743 'clientId' => PPLOAD_CLIENT_ID, 0744 'secret' => PPLOAD_SECRET 0745 )); 0746 if ($ppload_collection_id) { 0747 $filesRequest = array( 0748 'collection_id' => $ppload_collection_id, 0749 'perpage' => 100 0750 ); 0751 0752 $filesResponse = $pploadApi->getFiles($filesRequest); 0753 0754 if (isset($filesResponse->status) && $filesResponse->status == 'success') { 0755 $i = 0; 0756 foreach ($filesResponse->files as $file) { 0757 $downloadLink = PPLOAD_API_URI . 'files/download/' . 'id/' . $file->id . '/' . $file->name; 0758 $payload = array('id' => $file->id); 0759 $downloadLink = Default_Model_PpLoad::createDownloadUrlJwt($ppload_collection_id, $file->name, $payload); 0760 0761 $tags = $this->_parseFileTags($file->tags); 0762 $p_type = $this->_getPackagetypeText($tags['packagetypeid']); 0763 $p_lice = $this->_getLicenceText($tags['licensetype']); 0764 $result[] = array( 0765 'id' => $file->id, 0766 'downloadlink' => $downloadLink, 0767 'name' => $file->name, 0768 'version' => $file->version, 0769 'description' => $file->description, 0770 'type' => $file->type, 0771 'downloaded_count' => $file->downloaded_count, 0772 'size' => round($file->size / (1024 * 1024), 2), 0773 'license' => $p_lice, 0774 'package_type' => $p_type, 0775 'package_arch' => $tags['packagearch'], 0776 'created' => $file->created_timestamp, 0777 'updated' => $file->updated_timestamp 0778 ); 0779 } 0780 } 0781 } 0782 0783 return $result; 0784 } 0785 0786 protected function _getHTMLFiles($files) 0787 { 0788 if(count($files)==0) return ''; 0789 $helperPrintDate = new Default_View_Helper_PrintDate(); 0790 $html = '<div class="opendesktoppploadfiles">'; 0791 $html = $html.'<table class="opendesktoppploadfilestable">'; 0792 $html = $html.'<thead><tr><th>File</th><th>Version</th><th>Description</th><th>Filetype</th><th>Packagetype</th><th>License</th>'; 0793 $html = $html.'<th>Downloads</th><th>Date</th><th>Filesize</th></tr></thead>'; 0794 $html = $html.'<tbody>'; 0795 foreach ($files as $file) { 0796 $html = $html.'<tr>'; 0797 $html = $html.'<td><a href="'.$file['downloadlink'].'" >'.$file['name'].'</a></td>'; 0798 $html = $html.'<td>'.$file['version'].'</td>'; 0799 $html = $html.'<td>'.$file['description'].'</td>'; 0800 $html = $html.'<td>'.$file['type'].'</td>'; 0801 $html = $html.'<td>'.$file['package_type'].'</td>'; 0802 $html = $html.'<td>'.$file['license'].'</td>'; 0803 $html = $html.'<td class="opendesktoppploadfilestabletdright">'.$file['downloaded_count'].'</td>'; 0804 $html = $html.'<td>'.$file['created'].'</td>'; 0805 $html = $html.'<td class="opendesktoppploadfilestabletdright">'.$file['size'].'MB</td>'; 0806 $html = $html.'</tr>'; 0807 } 0808 $html = $html.'</tbody></table> </div>'; 0809 return $html; 0810 } 0811 0812 0813 public function pploadAction() 0814 { 0815 $downloadItems = array(); 0816 0817 $ppload_collection_id = $this->getParam('ppload_collection_id'); 0818 0819 $count_downloads_hive = $this->getParam('count_downloads_hive'); 0820 if(empty($count_downloads_hive)){ 0821 $downloads = 0; 0822 }else{ 0823 $downloads = $count_downloads_hive; 0824 } 0825 0826 $files = $this->_getPploadFiles($ppload_collection_id); 0827 $html=''; 0828 $html = $this->_getHTMLFiles($files); 0829 0830 if ($this->_format == 'json') { 0831 $response = array( 0832 'status' => 'ok', 0833 'statuscode' => 100, 0834 'message' => '', 0835 'totalitems' => count($files), 0836 'html' => $html 0837 ); 0838 0839 $this->_sendResponse($response, $this->_format); 0840 } 0841 } 0842 0843 protected function _getLicenceText($id) 0844 { 0845 0846 $typetext = ''; 0847 switch ($id) { 0848 case 0: 0849 $typetext = 'Other'; 0850 break; 0851 case 1: 0852 $typetext = 'GPLv2 or later'; 0853 break; 0854 case 2: 0855 $typetext = 'LGPL'; 0856 break; 0857 case 3: 0858 $typetext = 'Artistic 2.0'; 0859 break; 0860 case 4: 0861 $typetext = 'X11'; 0862 break; 0863 case 5: 0864 $typetext = 'QPL'; 0865 break; 0866 case 6: 0867 $typetext = 'BSD'; 0868 break; 0869 case 7: 0870 $typetext = 'Proprietary License'; 0871 break; 0872 case 8: 0873 $typetext = 'GFDL'; 0874 break; 0875 case 9: 0876 $typetext = 'CPL 1.0'; 0877 break; 0878 case 10: 0879 $typetext = 'Creative Commons by'; 0880 break; 0881 case 11: 0882 $typetext = 'Creative Commons by-sa'; 0883 case 12: 0884 $typetext = 'Creative Commons by-nd'; 0885 break; 0886 case 13: 0887 $typetext = 'Creative Commons by-nc'; 0888 break; 0889 case 14: 0890 $typetext = 'Creative Commons by-nc-sa'; 0891 break; 0892 case 15: 0893 $typetext = 'Creative Commons by-nc-nd'; 0894 break; 0895 case 16: 0896 $typetext = 'AGPL'; 0897 break; 0898 case 18: 0899 $typetext = 'GPLv2 only'; 0900 break; 0901 case 19: 0902 $typetext = 'GPLv3'; 0903 break; 0904 } 0905 return $typetext; 0906 0907 } 0908 0909 protected function _getPackagetypeText($typid) 0910 { 0911 $typetext = ''; 0912 switch ($typid) { 0913 case 1: 0914 $typetext = 'AppImage'; 0915 break; 0916 case 2: 0917 $typetext = 'Android (APK)'; 0918 break; 0919 case 3: 0920 $typetext = 'OS X compatible'; 0921 break; 0922 case 4: 0923 $typetext = 'Windows executable'; 0924 break; 0925 case 5: 0926 $typetext = 'Debian'; 0927 break; 0928 case 6: 0929 $typetext = 'Snappy'; 0930 break; 0931 case 7: 0932 $typetext = 'Flatpak'; 0933 break; 0934 case 8: 0935 $typetext = 'Electron-Webapp'; 0936 break; 0937 case 9: 0938 $typetext = 'Arch'; 0939 break; 0940 case 10: 0941 $typetext = 'open/Suse'; 0942 break; 0943 case 11: 0944 $typetext = 'Redhat'; 0945 break; 0946 case 12: 0947 $typetext = 'Source Code'; 0948 break; 0949 } 0950 return $typetext; 0951 } 0952 /** 0953 * @param string $fileTags 0954 * 0955 * @return array 0956 */ 0957 protected function _parseFileTags($fileTags) 0958 { 0959 $tags = explode(',', $fileTags); 0960 $parsedTags = array( 0961 'link' => '', 0962 'licensetype' => '', 0963 'packagetypeid' => '', 0964 'packagearch' => '' 0965 ); 0966 foreach ($tags as $tag) { 0967 $tag = trim($tag); 0968 if (strpos($tag, 'link##') === 0) { 0969 $parsedTags['link'] = urldecode(str_replace('link##', '', $tag)); 0970 } else { 0971 if (strpos($tag, 'licensetype-') === 0) { 0972 $parsedTags['licensetype'] = str_replace('licensetype-', '', $tag); 0973 } else { 0974 if (strpos($tag, 'packagetypeid-') === 0) { 0975 $parsedTags['packagetypeid'] = str_replace('packagetypeid-', '', $tag); 0976 } else { 0977 if (strpos($tag, 'packagearch-') === 0) { 0978 $parsedTags['packagearch'] = str_replace('packagearch-', '', $tag); 0979 } 0980 } 0981 } 0982 } 0983 } 0984 return $parsedTags; 0985 } 0986 }