File indexing completed on 2024-12-22 05:33:31
0001 <?php 0002 0003 /** 0004 * ocs-webserver 0005 * 0006 * Copyright 2016 by pling GmbH. 0007 * 0008 * This file is part of ocs-webserver. 0009 * 0010 * This program is free software: you can redistribute it and/or modify 0011 * it under the terms of the GNU Affero General Public License as 0012 * published by the Free Software Foundation, either version 3 of the 0013 * License, or (at your option) any later version. 0014 * 0015 * This program is distributed in the hope that it will be useful, 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0018 * GNU Affero General Public License for more details. 0019 * 0020 * You should have received a copy of the GNU Affero General Public License 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0022 **/ 0023 class CollectionController extends Local_Controller_Action_DomainSwitch 0024 { 0025 0026 const IMAGE_SMALL_UPLOAD = 'image_small_upload'; 0027 const IMAGE_BIG_UPLOAD = 'image_big_upload'; 0028 /** 0029 * Zend_Controller_Request_Abstract object wrapping the request environment 0030 * 0031 * @var Zend_Controller_Request_Http 0032 */ 0033 protected $_request = null; 0034 /** @var int */ 0035 protected $_projectId; 0036 /** @var int */ 0037 protected $_collectionId; 0038 /** @var Zend_Auth */ 0039 protected $_auth; 0040 /** @var string */ 0041 protected $_browserTitlePrepend; 0042 0043 public function init() 0044 { 0045 parent::init(); 0046 $this->_projectId = (int)$this->getParam('project_id'); 0047 $this->_collectionId = (int)$this->getParam('collection_id'); 0048 $this->_auth = Zend_Auth::getInstance(); 0049 $this->_browserTitlePrepend = $this->templateConfigData['head']['browser_title_prepend']; 0050 0051 $action = $this->getRequest()->getActionName(); 0052 if($action =='add') 0053 { 0054 $title = 'add collection'; 0055 }else 0056 { 0057 $title = $action; 0058 } 0059 $this->view->headTitle($title . ' - ' . $this->getHeadTitle(), 'SET'); 0060 } 0061 0062 public function ratingAction() 0063 { 0064 $this->_helper->layout()->disableLayout(); 0065 if (array_key_exists($this->_projectId, $this->_authMember->projects)) { 0066 return; 0067 } 0068 $userRating = (int)$this->getParam('rate', 0); 0069 $modelRating = new Default_Model_DbTable_ProjectRating(); 0070 $modelRating->rateForProject($this->_projectId, $this->_authMember->member_id, $userRating); 0071 } 0072 0073 0074 private function getCollectionProjects() { 0075 $project_id = $this->_projectId; 0076 0077 $collectionProjectsTable = new Default_Model_DbTable_CollectionProjects(); 0078 $projectsArray = $collectionProjectsTable->getCollectionProjects($project_id); 0079 $helperImage = new Default_View_Helper_Image(); 0080 0081 $result = array(); 0082 foreach ($projectsArray as $project) { 0083 $imgUrl = $helperImage->Image($project['image_small'], array('width' => 140, 'height' => 98)); 0084 $project['image_url'] = $imgUrl; 0085 $result[] = $project; 0086 } 0087 0088 return $result; 0089 0090 } 0091 0092 0093 0094 public function getcollectionprojectsajaxAction() { 0095 $this->_helper->layout()->disableLayout(); 0096 $project_id = $this->_projectId; 0097 0098 $collectionProjectsTable = new Default_Model_DbTable_CollectionProjects(); 0099 $projectsArray = $collectionProjectsTable->getCollectionProjects($project_id); 0100 $helperImage = new Default_View_Helper_Image(); 0101 0102 $result = array(); 0103 foreach ($projectsArray as $project) { 0104 $imgUrl = $helperImage->Image($project['image_small'], array('width' => 140, 'height' => 98)); 0105 $project['image_url'] = $imgUrl; 0106 $result[] = $project; 0107 } 0108 $this->_helper->json(array('status' => 'success', 'ResultSize' => count($result), 'projects' => $result)); 0109 //$this->_helper->json($result); 0110 0111 return; 0112 0113 } 0114 0115 0116 public function getprojectsajaxAction() { 0117 $this->_helper->layout()->disableLayout(); 0118 $member_id = null; 0119 $identity = Zend_Auth::getInstance()->getStorage()->read(); 0120 if (Zend_Auth::getInstance()->hasIdentity()){ 0121 $member_id = $identity->member_id; 0122 } 0123 0124 if(!$member_id) { 0125 $this->_helper->json(array('status' => 'success', 'ResultSize' => 0, 'projects' => array())); 0126 0127 } else { 0128 $search = null; 0129 if($this->hasParam('search')) { 0130 $search = $this->getParam('search'); 0131 } 0132 $searchAll = false; 0133 if($this->hasParam('search_all')) { 0134 $searchAll = $this->getParam('search_all') == 'true'; 0135 } 0136 if(empty($search)) { 0137 $this->_helper->json(array('status' => 'success', 'ResultSize' => 0, 'projects' => array())); 0138 return; 0139 } 0140 0141 0142 $collectionProjectsTable = new Default_Model_DbTable_CollectionProjects(); 0143 if(!$searchAll) { 0144 $projectsArray = $collectionProjectsTable->getProjectsForMember($this->_projectId, $member_id, $search); 0145 } else { 0146 $projectsArray = $collectionProjectsTable->getProjectsForAllMembers($this->_projectId, $member_id, $search); 0147 } 0148 0149 $result = array(); 0150 $helperImage = new Default_View_Helper_Image(); 0151 0152 foreach ($projectsArray as $project) { 0153 $imgUrl = $helperImage->Image($project['image_small'], array('width' => 140, 'height' => 98)); 0154 $project['image_url'] = $imgUrl; 0155 0156 $result[] = $project; 0157 } 0158 $this->_helper->json(array('status' => 'success', 'ResultSize' => count($result), 'projects' => $result, 'Search' => $search, 'SearchAll' => $searchAll)); 0159 //$this->_helper->json($result); 0160 } 0161 0162 0163 return; 0164 0165 } 0166 0167 public function searchprojectsajaxAction() { 0168 $this->_helper->layout()->disableLayout(); 0169 $result = null; 0170 $search = ""; 0171 if($this->hasParam('search')) { 0172 $search = $this->getParam('search'); 0173 } 0174 0175 $store->getParam('domain_store_id'); 0176 0177 $param = array('q' => $search ,'store'=>$store,'page' => 0, 'count' => 10, 'qf' => 'f', 'fq' => array()); 0178 0179 $modelSearch = new Default_Model_Solr(); 0180 $searchResult = null; 0181 try { 0182 $searchResult = $modelSearch->search($param); 0183 } catch (Exception $e) { 0184 Zend_Registry::get('logger')->err(__FILE__.'('.__LINE__.') -- params: '.print_r($param, true)."\n".' message: '."\n".$e->getMessage()); 0185 0186 $searchResult = array('hits' => array(), 'highlighting' =>array(),'response' => array('numFound' => 0)); 0187 } 0188 $pagination = $pagination = $modelSearch->getPagination(); 0189 $products = $searchResult['hits']; 0190 0191 0192 $result = array(); 0193 foreach ($products as $project) { 0194 $result[] = $project; 0195 } 0196 $this->_helper->json(array('status' => 'success', 'ResultSize' => count($result), 'projects' => $result)); 0197 0198 return; 0199 0200 } 0201 0202 0203 0204 0205 public function initJsonForReact(){ 0206 $modelProduct = new Default_Model_Collection(); 0207 $productInfo = $modelProduct->fetchProductInfo($this->_projectId); 0208 $this->view->product = $productInfo; 0209 if (empty($this->view->product)) { 0210 throw new Zend_Controller_Action_Exception('This page does not exist', 404); 0211 } 0212 0213 if(null != $this->_authMember) { 0214 $this->view->authMemberJson = Zend_Json::encode( Default_Model_Member::cleanAuthMemberForJson($this->_authMember) ); 0215 } 0216 0217 $helpAddDefaultScheme = new Default_View_Helper_AddDefaultScheme(); 0218 $this->view->product->title = Default_Model_HtmlPurify::purify($this->view->product->title); 0219 $this->view->product->description = Default_Model_BBCode::renderHtml(Default_Model_HtmlPurify::purify($this->view->product->description)); 0220 $this->view->product->version = Default_Model_HtmlPurify::purify($this->view->product->version); 0221 $this->view->product->link_1 = Default_Model_HtmlPurify::purify($helpAddDefaultScheme->addDefaultScheme($this->view->product->link_1),Default_Model_HtmlPurify::ALLOW_URL); 0222 $this->view->product->source_url = Default_Model_HtmlPurify::purify($this->view->product->source_url,Default_Model_HtmlPurify::ALLOW_URL); 0223 $this->view->product->facebook_code = Default_Model_HtmlPurify::purify($this->view->product->facebook_code,Default_Model_HtmlPurify::ALLOW_URL); 0224 $this->view->product->twitter_code = Default_Model_HtmlPurify::purify($this->view->product->twitter_code,Default_Model_HtmlPurify::ALLOW_URL); 0225 $this->view->product->google_code = Default_Model_HtmlPurify::purify($this->view->product->google_code,Default_Model_HtmlPurify::ALLOW_URL); 0226 $this->view->productJson = Zend_Json::encode(Default_Model_Collection::cleanProductInfoForJson($this->view->product) ); 0227 0228 $tableProjectUpdates = new Default_Model_ProjectUpdates(); 0229 $this->view->updatesJson = Zend_Json::encode($tableProjectUpdates->fetchProjectUpdates($this->_projectId)); 0230 $tableProjectRatings = new Default_Model_DbTable_ProjectRating(); 0231 $ratings = $tableProjectRatings->fetchRating($this->_projectId); 0232 $cntRatingsActive = 0; 0233 foreach ($ratings as $p) { 0234 if($p['rating_active']==1) $cntRatingsActive =$cntRatingsActive+1; 0235 } 0236 $this->view->ratingsJson = Zend_Json::encode($ratings); 0237 $this->view->cntRatingsActiveJson = Zend_Json::encode($cntRatingsActive); 0238 0239 $identity = Zend_Auth::getInstance()->getStorage()->read(); 0240 if (Zend_Auth::getInstance()->hasIdentity()){ 0241 $ratingOfUserJson = $tableProjectRatings->getProjectRateForUser($this->_projectId,$identity->member_id); 0242 $this->view->ratingOfUserJson = Zend_Json::encode($ratingOfUserJson); 0243 }else{ 0244 $this->view->ratingOfUserJson = Zend_Json::encode(null); 0245 } 0246 $tableProjectFollower = new Default_Model_DbTable_ProjectFollower(); 0247 $likes = $tableProjectFollower->fetchLikesForProject($this->_projectId); 0248 $this->view->likeJson = Zend_Json::encode($likes); 0249 0250 $projectplings = new Default_Model_ProjectPlings(); 0251 $plings = $projectplings->fetchPlingsForProject($this->_projectId); 0252 $this->view->projectplingsJson = Zend_Json::encode($plings); 0253 0254 $tableProject = new Default_Model_Collection(); 0255 $galleryPictures = $tableProject->getGalleryPictureSources($this->_projectId); 0256 $this->view->galleryPicturesJson = Zend_Json::encode($galleryPictures); 0257 0258 $tagmodel = new Default_Model_Tags(); 0259 $tagsuser = $tagmodel->getTagsUser($this->_projectId, Default_Model_Tags::TAG_TYPE_PROJECT); 0260 $tagssystem = $tagmodel->getTagsSystemList($this->_projectId); 0261 $this->view->tagsuserJson = Zend_Json::encode($tagsuser); 0262 $this->view->tagssystemJson = Zend_Json::encode($tagssystem); 0263 0264 $modelComments = new Default_Model_ProjectComments(); 0265 $offset = 0; 0266 $testComments = $modelComments->getCommentTreeForProjectList($this->_projectId); 0267 $this->view->commentsJson = Zend_Json::encode($testComments); 0268 0269 $modelClone = new Default_Model_ProjectClone(); 0270 $origins = $modelClone->fetchOrigins($this->_projectId); 0271 $this->view->originsJson = Zend_Json::encode($origins); 0272 $related = $modelClone->fetchRelatedProducts($this->_projectId); 0273 $this->view->relatedJson = Zend_Json::encode($related); 0274 0275 $moreProducts = $tableProject->fetchMoreProjects($this->view->product, 8); 0276 $this->view->moreProductsJson = Zend_Json::encode($moreProducts); 0277 0278 $moreProducts = $tableProject->fetchMoreProjectsOfOtherUsr($this->view->product, 8); 0279 $this->view->moreProductsOfOtherUsrJson = Zend_Json::encode($moreProducts); 0280 0281 0282 0283 } 0284 0285 public function indexAction() 0286 { 0287 0288 if (empty($this->_projectId)) { 0289 $this->redirect('/explore'); 0290 } 0291 0292 $this->view->paramPageId = (int)$this->getParam('page'); 0293 $this->view->member_id = null; 0294 if(null != $this->_authMember && null != $this->_authMember->member_id) { 0295 $this->view->member_id = $this->_authMember->member_id; 0296 } 0297 $modelProduct = new Default_Model_Collection(); 0298 $productInfo = $modelProduct->fetchProductInfo($this->_projectId); 0299 if (empty($productInfo)) { 0300 //Coukd be a Project 0301 $modelProduct = new Default_Model_Project(); 0302 $productInfo = $modelProduct->fetchProductInfo($this->_projectId); 0303 //Check if this is a collection 0304 if(!empty($productInfo) && $productInfo->type_id != $modelProduct::PROJECT_TYPE_COLLECTION) { 0305 $this->redirect('/p/'.$this->_projectId); 0306 } 0307 throw new Zend_Controller_Action_Exception('This page does not exist', 404); 0308 } 0309 0310 $this->view->product = $productInfo; 0311 0312 $this->view->collection_projects = $this->getCollectionProjects(); 0313 0314 $collection_ids = array(); 0315 foreach ($this->view->collection_projects as $value) { 0316 if($value['ppload_collection_id']) $collection_ids[] = $value['ppload_collection_id']; 0317 } 0318 0319 $filesmodel = new Default_Model_DbTable_PploadFiles(); 0320 $this->view->collection_projects_dls = $filesmodel->fetchAllActiveFilesForCollection($collection_ids); 0321 0322 //$this->view->collection_ids = $collection_ids; 0323 0324 $this->view->headTitle($productInfo->title . ' - ' . $this->getHeadTitle(), 'SET'); 0325 0326 $this->view->cat_id = $this->view->product->project_category_id; 0327 0328 $helperUserIsOwner = new Default_View_Helper_UserIsOwner(); 0329 $helperIsProjectActive = new Default_View_Helper_IsProjectActive(); 0330 if ((false === $helperIsProjectActive->isProjectActive($this->view->product->project_status)) 0331 AND (false === $helperUserIsOwner->UserIsOwner($this->view->product->member_id)) 0332 ) { 0333 throw new Zend_Controller_Action_Exception('This page does not exist', 404); 0334 } 0335 0336 if ((APPLICATION_ENV != 'searchbotenv') AND (false == SEARCHBOT_DETECTED)) { 0337 Default_Model_Views::saveViewCollection($this->_projectId); 0338 0339 $tablePageViews = new Default_Model_DbTable_StatPageViews(); 0340 $tablePageViews->savePageView($this->_projectId, $this->getRequest()->getClientIp(), 0341 $this->_authMember->member_id); 0342 } 0343 0344 $storeConfig = Zend_Registry::isRegistered('store_config') ? Zend_Registry::get('store_config') : null; 0345 if($storeConfig->layout_pagedetail && $storeConfig->isRenderReact()){ 0346 $this->initJsonForReact(); 0347 $this->_helper->viewRenderer('index-react'); 0348 } 0349 0350 } 0351 0352 public function showAction() 0353 { 0354 $this->view->authMember = $this->_authMember; 0355 $this->_helper->viewRenderer('index'); 0356 $this->indexAction(); 0357 } 0358 0359 0360 0361 public function addAction() 0362 { 0363 $this->view->member = $this->_authMember; 0364 $this->view->mode = 'addcollection'; 0365 $this->view->collection_cat_id = Zend_Registry::get('config')->settings->client->default->collection_cat_id; 0366 0367 $form = new Default_Form_Collection(array('member_id' => $this->view->member->member_id)); 0368 $this->view->form = $form; 0369 0370 if ($this->_request->isGet()) { 0371 return; 0372 } 0373 0374 if (isset($_POST['cancel'])) { // user cancel function 0375 $this->redirect('/member/' . $this->_authMember->member_id . '/news/'); 0376 } 0377 0378 if (false === $form->isValid($_POST)) { // form not valid 0379 $this->view->form = $form; 0380 $this->view->error = 1; 0381 0382 return; 0383 } 0384 0385 $values = $form->getValues(); 0386 0387 0388 0389 $imageModel = new Default_Model_DbTable_Image(); 0390 try { 0391 $values['image_small'] = $imageModel->saveImage($form->getElement(self::IMAGE_SMALL_UPLOAD)); 0392 } catch (Exception $e) { 0393 Zend_Registry::get('logger')->err(__METHOD__ . ' - ERROR upload productPicture - ' . print_r($e, true)); 0394 } 0395 0396 // form was valid, so we can set status to active 0397 $values['status'] = Default_Model_DbTable_Project::PROJECT_ACTIVE; 0398 0399 // save new project 0400 $modelProject = new Default_Model_Collection(); 0401 0402 Zend_Registry::get('logger')->info(__METHOD__ . ' - $post: ' . print_r($_POST, true)); 0403 Zend_Registry::get('logger')->info(__METHOD__ . ' _ input values: ' . print_r($values, true)); 0404 0405 $newProject = null; 0406 try { 0407 if (isset($values['project_id'])) { 0408 $newProject = $modelProject->updateCollection($values['project_id'], $values); 0409 } else { 0410 $newProject = $modelProject->createCollection($this->_authMember->member_id, $values, $this->_authMember->username); 0411 //$this->createSystemPlingForNewProject($newProject->project_id); 0412 } 0413 } catch (Exception $exc) { 0414 Zend_Registry::get('logger')->warn(__METHOD__ . ' - traceString: ' . $exc->getTraceAsString()); 0415 Zend_Registry::get('logger')->info(__METHOD__ . ' _ Exception: ' . print_r($exc, true)); 0416 } 0417 0418 if (!$newProject) { 0419 $this->_helper->flashMessenger->addMessage('<p class="text-error">You did not choose a Category in the last level.</p>'); 0420 $this->forward('add'); 0421 0422 return; 0423 } 0424 0425 //update the gallery pics 0426 //$mediaServerUrls = $this->saveGalleryPics($form->gallery->upload->upload_picture); 0427 //$modelProject->updateGalleryPictures($newProject->project_id, $mediaServerUrls); 0428 0429 //If there is no Logo, we take the 1. gallery pic 0430 if (!isset($values['image_small']) || $values['image_small'] == '') { 0431 $values['image_small'] = $mediaServerUrls[0]; 0432 $newProject = $modelProject->updateProject($newProject->project_id, $values); 0433 } 0434 0435 //New Project in Session, for AuthValidation (owner) 0436 $this->_auth->getIdentity()->projects[$newProject->project_id] = array('project_id' => $newProject->project_id); 0437 0438 0439 $modelTags = new Default_Model_Tags(); 0440 if ($values['tagsuser']) { 0441 $modelTags->processTagsUser($newProject->project_id, implode(',', $values['tagsuser']),Default_Model_Tags::TAG_TYPE_PROJECT); 0442 } else { 0443 $modelTags->processTagsUser($newProject->project_id, null, Default_Model_Tags::TAG_TYPE_PROJECT); 0444 } 0445 /* 0446 if ($values['is_original']) { 0447 $modelTags->processTagProductOriginal($newProject->project_id, $values['is_original']); 0448 } 0449 0450 //set license, if needed 0451 $licenseTag = $form->getElement('license_tag_id')->getValue(); 0452 //only set/update license tags if something was changed 0453 if ($licenseTag && count($licenseTag) > 0) { 0454 $modelTags->saveLicenseTagForProject($newProject->project_id, $licenseTag); 0455 $activityLog = new Default_Model_ActivityLog(); 0456 $activityLog->logActivity($newProject->project_id, $newProject->project_id, $this->_authMember->member_id,Default_Model_ActivityLog::PROJECT_LICENSE_CHANGED, array('title' => 'Set new License Tag', 'description' => 'New TagId: ' . $licenseTag)); 0457 } 0458 0459 $isGitlabProject = $form->getElement('is_gitlab_project')->getValue(); 0460 $gitlabProjectId = $form->getElement('gitlab_project_id')->getValue(); 0461 if ($isGitlabProject && $gitlabProjectId == 0) { 0462 $values['gitlab_project_id'] = null; 0463 } 0464 * 0465 */ 0466 0467 $activityLog = new Default_Model_ActivityLog(); 0468 $activityLog->writeActivityLog($newProject->project_id, $newProject->member_id, Default_Model_ActivityLog::PROJECT_CREATED, $newProject->toArray()); 0469 0470 //$modelTags->processTagProductOriginal($newProject->project_id); 0471 0472 0473 try { 0474 if (100 < $this->_authMember->roleId) { 0475 if (Default_Model_Spam::hasSpamMarkers($newProject->toArray())) { 0476 $tableReportComments = new Default_Model_DbTable_ReportProducts(); 0477 $tableReportComments->save(array('project_id' => $newProject->project_id, 'reported_by' => 24, 'text' => "System: automatic spam detection")); 0478 } 0479 Default_Model_DbTable_SuspicionLog::logProject($newProject, $this->_authMember, $this->getRequest()); 0480 } 0481 } catch (Zend_Exception $e) { 0482 Zend_Registry::get('logger')->err($e->getMessage()); 0483 } 0484 0485 $this->redirect('/member/' . $newProject->member_id . '/collections/'); 0486 } 0487 0488 private function saveGalleryPics($form_element) 0489 { 0490 $imageModel = new Default_Model_DbTable_Image(); 0491 0492 return $imageModel->saveImages($form_element); 0493 } 0494 0495 0496 /** 0497 * @param $projectData 0498 * 0499 * @throws Zend_Exception 0500 * @throws Zend_Queue_Exception 0501 */ 0502 protected function createTaskWebsiteOwnerVerification($projectData) 0503 { 0504 if (empty($projectData->link_1)) { 0505 return; 0506 } 0507 $checkAuthCode = new Local_Verification_WebsiteProject(); 0508 $authCode = $checkAuthCode->generateAuthCode(stripslashes($projectData->link_1)); 0509 $queue = Local_Queue_Factory::getQueue(); 0510 $command = new Backend_Commands_CheckProjectWebsite($projectData->project_id, $projectData->link_1, $authCode); 0511 $queue->send(serialize($command)); 0512 } 0513 0514 0515 0516 public function editAction() 0517 { 0518 if (empty($this->_projectId)) { 0519 $this->redirect($this->_helper->url('add')); 0520 0521 return; 0522 } 0523 0524 $this->_helper->viewRenderer('add'); // we use the same view as you can see at add a product 0525 $this->view->mode = 'editcollection'; 0526 $this->view->collection_cat_id = Zend_Registry::get('config')->settings->client->default->collection_cat_id; 0527 0528 $projectTable = new Default_Model_DbTable_Project(); 0529 $projectModel = new Default_Model_Collection(); 0530 $modelTags = new Default_Model_Tags(); 0531 $tagTable = new Default_Model_DbTable_Tags(); 0532 0533 //check if product with given id exists 0534 $projectData = $projectTable->find($this->_projectId)->current(); 0535 if (empty($projectData)) { 0536 $this->redirect($this->_helper->url('add')); 0537 0538 return; 0539 } 0540 0541 $member = null; 0542 if (isset($this->_authMember) AND (false === empty($this->_authMember->member_id))) { 0543 $member = $this->_authMember; 0544 } else { 0545 throw new Zend_Controller_Action_Exception('no authorization found'); 0546 } 0547 0548 if (("admin" == $this->_authMember->roleName)) { 0549 $modelMember = new Default_Model_Member(); 0550 $member = $modelMember->fetchMember($projectData->member_id, false); 0551 } 0552 0553 $this->view->project_id = $projectData->project_id; 0554 $this->view->product = $projectData; 0555 0556 $this->view->member_id = $member->member_id; 0557 $this->view->member = $member; 0558 0559 0560 //read the already existing gallery pics and add them to the form 0561 $sources = $projectModel->getGalleryPictureSources($this->_projectId); 0562 0563 //get the gitlab projects for this user 0564 0565 //setup form 0566 $form = new Default_Form_Collection(array('pictures' => $sources, 'member_id' => $this->view->member_id)); 0567 if (false === empty($projectData->image_small)) { 0568 $form->getElement('image_small_upload')->setRequired(false); 0569 } 0570 $form->getElement('preview')->setLabel('Save'); 0571 0572 $form->removeElement('project_id'); // we don't need this field in edit mode 0573 0574 if ($this->_request->isGet()) { 0575 $form->populate($projectData->toArray()); 0576 // $form->populate(array('tags' => $modelTags->getTags($projectData->project_id, Default_Model_Tags::TAG_TYPE_PROJECT))); 0577 //$form->populate(array('tagsuser' => $modelTags->getTagsUser($projectData->project_id, Default_Model_Tags::TAG_TYPE_PROJECT))); 0578 $form->getElement('image_small')->setValue($projectData->image_small); 0579 //Bilder voreinstellen 0580 $form->getElement(self::IMAGE_SMALL_UPLOAD)->setValue($projectData->image_small); 0581 0582 /* 0583 $licenseTags = $tagTable->fetchLicenseTagsForProject($this->_projectId); 0584 $licenseTag = null; 0585 if($licenseTags) { 0586 $licenseTag = $licenseTags[0]['tag_id']; 0587 } 0588 $form->getElement('license_tag_id')->setValue($licenseTag); 0589 0590 $is_original = $modelTags->isProuductOriginal($projectData->project_id); 0591 if($is_original){ 0592 $form->getElement('is_original')->checked= true; 0593 } 0594 * 0595 */ 0596 0597 $this->view->form = $form; 0598 0599 return; 0600 } 0601 0602 if (isset($_POST['cancel'])) { // user cancel function 0603 $this->redirect('/member/' . $member->member_id . '/news/'); 0604 } 0605 0606 if (false === $form->isValid($_POST, $this->_projectId)) { // form not valid 0607 $this->view->form = $form; 0608 $this->view->error = 1; 0609 0610 return; 0611 } 0612 0613 $values = $form->getValues(); 0614 0615 /** 0616 //set license, if needed 0617 $tagList = $modelTags->getTagsArray($this->_projectId, $modelTags::TAG_TYPE_PROJECT, $modelTags::TAG_LICENSE_GROUPID); 0618 $oldLicenseTagId = null; 0619 if($tagList && count($tagList) == 1) { 0620 $oldLicenseTagId = $tagList[0]['tag_id']; 0621 } 0622 0623 $licenseTag = $form->getElement('license_tag_id')->getValue(); 0624 //only set/update license tags if something was changed 0625 if($licenseTag <> $oldLicenseTagId) { 0626 $modelTags->saveLicenseTagForProject($this->_projectId, $licenseTag); 0627 $activityLog = new Default_Model_ActivityLog(); 0628 $activityLog->logActivity($this->_projectId, $this->_projectId, $this->_authMember->member_id, Default_Model_ActivityLog::PROJECT_LICENSE_CHANGED, array('title' => 'License Tag', 'description' => 'Old TagId: '.$oldLicenseTagId.' - New TagId: '.$licenseTag)); 0629 } 0630 0631 //gitlab project 0632 $isGitlabProject = $form->getElement('is_gitlab_project')->getValue(); 0633 $gitlabProjectId = $form->getElement('gitlab_project_id')->getValue(); 0634 if($isGitlabProject && $gitlabProjectId == 0) { 0635 $values['gitlab_project_id'] = null; 0636 } 0637 0638 */ 0639 0640 $imageModel = new Default_Model_DbTable_Image(); 0641 try { 0642 $uploadedSmallImage = $imageModel->saveImage($form->getElement(self::IMAGE_SMALL_UPLOAD)); 0643 $values['image_small'] = $uploadedSmallImage ? $uploadedSmallImage : $values['image_small']; 0644 } catch (Exception $e) { 0645 Zend_Registry::get('logger')->err(__METHOD__ . ' - ERROR upload productPicture - ' . print_r($e, true)); 0646 } 0647 0648 // save changes 0649 $projectData->setFromArray($values); 0650 0651 /** 0652 //update the gallery pics 0653 $pictureSources = array_merge($values['gallery']['online_picture'], 0654 $this->saveGalleryPics($form->gallery->upload->upload_picture)); 0655 $projectModel->updateGalleryPictures($this->_projectId, $pictureSources); 0656 */ 0657 0658 //If there is no Logo, we take the 1. gallery pic 0659 if (!isset($projectData->image_small) || $projectData->image_small == '') { 0660 $projectData->image_small = $pictureSources[0]; 0661 } 0662 //20180219 ronald: we set the changed_at only by new files or new updates 0663 //$projectData->changed_at = new Zend_Db_Expr('NOW()'); 0664 $projectData->save(); 0665 0666 //$modelTags->processTagProductOriginal($this->_projectId,$values['is_original']); 0667 0668 0669 if($values['tagsuser']) { 0670 $modelTags->processTagsUser($this->_projectId,implode(',',$values['tagsuser']), Default_Model_Tags::TAG_TYPE_PROJECT); 0671 }else 0672 { 0673 $modelTags->processTagsUser($this->_projectId,null, Default_Model_Tags::TAG_TYPE_PROJECT); 0674 } 0675 0676 $activityLog = new Default_Model_ActivityLog(); 0677 $activityLog->writeActivityLog($this->_projectId, $this->_authMember->member_id, Default_Model_ActivityLog::PROJECT_EDITED, $projectData->toArray()); 0678 0679 try { 0680 if (100 < $this->_authMember->roleId) { 0681 if (Default_Model_Spam::hasSpamMarkers($projectData->toArray())) { 0682 $tableReportComments = new Default_Model_DbTable_ReportProducts(); 0683 $tableReportComments->save(array('project_id' => $projectData->project_id, 'reported_by' => 24, 'text' => "System: automatic spam detection on product edit")); 0684 } 0685 Default_Model_DbTable_SuspicionLog::logProject($projectData, $this->_authMember, $this->getRequest()); 0686 } 0687 } catch (Zend_Exception $e) { 0688 Zend_Registry::get('logger')->err($e->getMessage()); 0689 } 0690 0691 $helperBuildMemberUrl = new Default_View_Helper_BuildMemberUrl(); 0692 $this->redirect($helperBuildMemberUrl->buildMemberUrl($member->username, 'collections')); 0693 } 0694 0695 public function getupdatesajaxAction() 0696 { 0697 $this->view->authMember = $this->_authMember; 0698 $tableProject = new Default_Model_ProjectUpdates(); 0699 0700 $updates = $tableProject->fetchProjectUpdates($this->_projectId); 0701 0702 foreach ($updates as $key => $update) { 0703 $updates[$key]['title'] = Default_Model_HtmlPurify::purify($update['title']); 0704 $updates[$key]['text'] = Default_Model_BBCode::renderHtml(Default_Model_HtmlPurify::purify(htmlentities($update['text'], ENT_QUOTES | ENT_IGNORE))); 0705 $updates[$key]['raw_title'] = $update['title']; 0706 $updates[$key]['raw_text'] = $update['text']; 0707 } 0708 0709 $result['status'] = 'success'; 0710 $result['ResultSize'] = count($updates); 0711 $result['updates'] = $updates; 0712 0713 $this->_helper->json($result); 0714 } 0715 0716 public function saveupdateajaxAction() 0717 { 0718 $filter = 0719 new Zend_Filter_Input( 0720 array( 0721 '*' => 'StringTrim' 0722 ), 0723 array( 0724 '*' => array(), 0725 'title' => array( 0726 new Zend_Validate_StringLength(array('min' => 3, 'max' => 200)), 0727 'presence' => 'required', 0728 'allowEmpty' => false 0729 ), 0730 'text' => array( 0731 new Zend_Validate_StringLength(array('min' => 3, 'max' => 16383)), 0732 'presence' => 'required', 0733 'allowEmpty' => false 0734 ), 0735 'update_id' => array('digits', 'allowEmpty' => true) 0736 ), $this->getAllParams(), array('allowEmpty' => true)); 0737 0738 if ($filter->hasInvalid() OR $filter->hasMissing() OR $filter->hasUnknown()) { 0739 $result['status'] = 'error'; 0740 $result['messages'] = $filter->getMessages(); 0741 $result['update_id'] = null; 0742 0743 $this->_helper->json($result); 0744 } 0745 0746 $update_id = $filter->getEscaped('update_id'); 0747 $tableProjectUpdates = new Default_Model_ProjectUpdates(); 0748 0749 //Save update 0750 if (!empty($update_id)) { 0751 //Update old update 0752 $updateArray = array(); 0753 $updateArray['title'] = $filter->getUnescaped('title'); 0754 $updateArray['text'] = $filter->getUnescaped('text'); 0755 $updateArray['changed_at'] = new Zend_Db_Expr('Now()'); 0756 $countUpdated = $tableProjectUpdates->update($updateArray, 'project_update_id = ' . $update_id); 0757 } else { 0758 //Add new update 0759 $updateArray = array(); 0760 $updateArray['title'] = $filter->getUnescaped('title'); 0761 $updateArray['text'] = $filter->getUnescaped('text'); 0762 $updateArray['public'] = 1; 0763 $updateArray['project_id'] = $this->_projectId; 0764 $updateArray['member_id'] = $this->_authMember->member_id; 0765 $updateArray['created_at'] = new Zend_Db_Expr('Now()'); 0766 $updateArray['changed_at'] = new Zend_Db_Expr('Now()'); 0767 $rowset = $tableProjectUpdates->save($updateArray); 0768 $update_id = $rowset->project_update_id; 0769 0770 //20180219 ronald: we set the changed_at only by new files or new updates 0771 $projectTable = new Default_Model_Collection(); 0772 $projectUpdateRow = $projectTable->find($this->_projectId)->current(); 0773 if (count($projectUpdateRow) == 1) { 0774 $projectUpdateRow->changed_at = new Zend_Db_Expr('NOW()'); 0775 $projectUpdateRow->save(); 0776 } 0777 } 0778 0779 $result['status'] = 'success'; 0780 $result['update_id'] = $update_id; 0781 0782 $this->_helper->json($result); 0783 } 0784 0785 public function deleteupdateajaxAction() 0786 { 0787 $this->view->authMember = $this->_authMember; 0788 $tableProject = new Default_Model_ProjectUpdates(); 0789 0790 $params = $this->getAllParams(); 0791 $project_update_id = $params['update_id']; 0792 $updateArray = array(); 0793 $updateArray['public'] = 0; 0794 $updateArray['changed_at'] = new Zend_Db_Expr('Now()'); 0795 $tableProject->update($updateArray, 'project_update_id = ' . $project_update_id); 0796 0797 $result['status'] = 'success'; 0798 $result['update_id'] = $project_update_id; 0799 0800 $this->_helper->json($result); 0801 } 0802 0803 public function updatesAction() 0804 { 0805 $this->view->authMember = $this->_authMember; 0806 $tableProject = new Default_Model_Collection(); 0807 $this->view->product = $tableProject->fetchProductInfo($this->_projectId); 0808 if (false === isset($this->view->product)) { 0809 throw new Zend_Controller_Action_Exception('This page does not exist', 404); 0810 } 0811 $this->view->relatedProducts = $tableProject->fetchSimilarProjects($this->view->product, 6); 0812 $this->view->supporter = $tableProject->fetchProjectSupporter($this->_projectId); 0813 $this->view->product_views = $tableProject->fetchProjectViews($this->_projectId); 0814 0815 $modelPlings = new Default_Model_DbTable_Plings(); 0816 $this->view->comments = $modelPlings->getCommentsForProject($this->_projectId, 10); 0817 0818 $tableMember = new Default_Model_Member(); 0819 $this->view->member = $tableMember->fetchMemberData($this->view->product->member_id); 0820 0821 $this->view->updates = $tableProject->fetchProjectUpdates($this->_projectId); 0822 0823 $tablePageViews = new Default_Model_DbTable_StatPageViews(); 0824 $tablePageViews->savePageView($this->_projectId, $this->getRequest()->getClientIp(), 0825 $this->_authMember->member_id); 0826 } 0827 0828 public function updatecollectionprojectsajaxAction() { 0829 $this->_helper->layout()->disableLayout(); 0830 0831 $this->view->project_id = $this->_projectId; 0832 $this->view->authMember = $this->_authMember; 0833 0834 0835 //save collection products 0836 $projectIdsString = $this->getParam('collection_project_ids'); 0837 $projectIds = array(); 0838 0839 if(!empty($projectIdsString)) { 0840 $projectIdsString = rtrim($projectIdsString,','); 0841 $projectIds = explode(',', $projectIdsString); 0842 } 0843 0844 $modeCollection = new Default_Model_DbTable_CollectionProjects(); 0845 $modeCollection->setCollectionProjects($this->_projectId, $projectIds); 0846 0847 $this->_helper->json(array( 0848 'status' => 'ok', 0849 'msg' => 'Success.' 0850 )); 0851 } 0852 0853 public function updateAction() 0854 { 0855 0856 $this->_helper->layout()->setLayout('flat_ui'); 0857 0858 $this->view->headScript()->setFile(''); 0859 $this->view->headLink()->setStylesheet(''); 0860 0861 $this->_helper->viewRenderer('add'); 0862 0863 $form = new Default_Form_ProjectUpdate(); 0864 $projectTable = new Default_Model_Collection(); 0865 $projectData = null; 0866 $projectUpdateId = (int)$this->getParam('upid'); 0867 0868 $this->view->member = $this->_authMember; 0869 $this->view->title = 'Add an update for your product'; 0870 0871 $activityLogType = Default_Model_ActivityLog::PROJECT_ITEM_CREATED; 0872 0873 if (false === empty($projectUpdateId)) { 0874 $this->view->title = 'Edit an product update'; 0875 $projectData = $projectTable->find($projectUpdateId)->current(); 0876 $form->populate($projectData->toArray()); 0877 $form->getElement('upid')->setValue($projectUpdateId); 0878 $activityLogType = Default_Model_ActivityLog::PROJECT_ITEM_EDITED; 0879 } 0880 0881 $this->view->form = $form; 0882 0883 if ($this->_request->isGet()) { 0884 return; 0885 } 0886 0887 if (isset($_POST['cancel'])) { // user cancel function 0888 $this->_redirect('/member/' . $this->_authMember->member_id . '/news/'); 0889 } 0890 0891 if (false === $form->isValid($_POST)) { // form not valid 0892 $this->view->form = $form; 0893 $this->view->error = 1; 0894 0895 return; 0896 } 0897 0898 $values = $form->getValues(); 0899 0900 $projectUpdateRow = $projectTable->find($values['upid'])->current(); 0901 0902 if (count($projectUpdateRow) == 0) { 0903 $projectUpdateRow = $projectTable->createRow($values); 0904 $projectUpdateRow->project_id = $values['upid']; 0905 $projectUpdateRow->created_at = new Zend_Db_Expr('NOW()'); 0906 $projectUpdateRow->start_date = new Zend_Db_Expr('NOW()'); 0907 $projectUpdateRow->member_id = $this->_authMember->member_id; 0908 $projectUpdateRow->creator_id = $this->_authMember->member_id; 0909 $projectUpdateRow->status = Default_Model_Collection::PROJECT_ACTIVE; 0910 $projectUpdateRow->type_id = 2; 0911 $projectUpdateRow->pid = $this->_projectId; 0912 } else { 0913 $projectUpdateRow->setFromArray($values); 0914 //20180219 ronald: we set the changed_at only by new files or new updates 0915 //$projectUpdateRow->changed_at = new Zend_Db_Expr('NOW()'); 0916 } 0917 0918 $lastId = $projectUpdateRow->save(); 0919 0920 //New Project in Session, for AuthValidation (owner) 0921 $this->_auth->getIdentity()->projects[$lastId] = array('project_id' => $lastId); 0922 0923 $tableProduct = new Default_Model_Collection(); 0924 $product = $tableProduct->find($this->_projectId)->current(); 0925 $activityLogValues = $projectUpdateRow->toArray(); 0926 $activityLogValues['image_small'] = $product->image_small; 0927 $activityLog = new Default_Model_ActivityLog(); 0928 //$activityLog->writeActivityLog($lastId, $projectUpdateRow->member_id, $activityLogType, $activityLogValues); 0929 $activityLog->writeActivityLog($lastId, $this->_authMember->member_id, $activityLogType, $activityLogValues); 0930 0931 $helperBuildProductUrl = new Default_View_Helper_BuildProductUrl(); 0932 $urlProjectShow = $helperBuildProductUrl->buildProductUrl($this->_projectId); 0933 0934 $this->redirect($urlProjectShow); 0935 } 0936 0937 public function previewAction() 0938 { 0939 $this->view->authMember = $this->_authMember; 0940 0941 $form = new Default_Form_ProjectConfirm(); 0942 0943 if ($this->_request->isGet()) { 0944 $form->populate(get_object_vars($this->_authMember)); 0945 $this->view->form = $form; 0946 $this->fetchDataForIndexView(); 0947 $this->view->preview = $this->view->render('product/index.phtml'); 0948 0949 return; 0950 } 0951 0952 if (isset($_POST['save'])) { 0953 $projectTable = new Default_Model_Collection(); 0954 $projectTable->setStatus(Default_Model_Collection::PROJECT_INACTIVE, $this->_projectId); 0955 0956 //todo: maybe we have to delete the project data from database otherwise we produce many zombies 0957 $this->redirect('/member/' . $this->_authMember->member_id . '/collections/'); 0958 } 0959 0960 if (isset($_POST['back'])) { 0961 $helperBuildProductUrl = new Default_View_Helper_BuildProductUrl(); 0962 $this->redirect($helperBuildProductUrl->buildProductUrl($this->_projectId, 'edit')); 0963 } 0964 0965 if (false === $form->isValid($_POST)) { // form not valid 0966 $this->view->form = $form; 0967 $this->fetchDataForIndexView(); 0968 $this->view->preview = $this->view->render('product/index.phtml'); 0969 $this->view->error = 1; 0970 0971 return; 0972 } 0973 0974 $projectTable = new Default_Model_Collection(); 0975 $projectTable->setStatus(Default_Model_Collection::PROJECT_ACTIVE, $this->_projectId); 0976 0977 // add to search index 0978 // $modelProject = new Default_Model_Collection(); 0979 // $productInfo = $modelProject->fetchProductInfo($this->_projectId); 0980 // $modelSearch = new Default_Model_Search_Lucene(); 0981 // $modelSearch->addDocument($productInfo->toArray()); 0982 0983 $this->redirect('/member/' . $this->_authMember->member_id . '/products/'); 0984 } 0985 0986 protected function fetchDataForIndexView() 0987 { 0988 $tableProject = new Default_Model_Collection(); 0989 $this->view->product = $tableProject->fetchProductInfo($this->_projectId); 0990 if (false === isset($this->view->product)) { 0991 throw new Zend_Controller_Action_Exception('This page does not exist', 404); 0992 } 0993 0994 $desc = $this->view->product->description; 0995 $newDesc = $this->bbcode2html($desc); 0996 $this->view->product->description = $newDesc; 0997 0998 // switch off temporally 02.05.2017 0999 //$this->view->supporting = $tableProject->fetchProjectSupporterWithPlings($this->_projectId); 1000 //$orgUpdates = $tableProjectUpdates->fetchLastProjectUpdate($this->_projectId); 1001 $tableProjectUpdates = new Default_Model_ProjectUpdates(); 1002 $orgUpdates = $tableProjectUpdates->fetchProjectUpdates($this->_projectId); 1003 $newUpdates = array(); 1004 foreach ($orgUpdates as $update) { 1005 $desc = $update['text']; 1006 $newDesc = $this->bbcode2html($desc); 1007 $update['text'] = $newDesc; 1008 $newUpdates[] = $update; 1009 } 1010 1011 $this->view->updates = $newUpdates; 1012 // switch off temporally 02.05.2017 1013 //$this->view->supporter = $tableProject->fetchProjectSupporter($this->_projectId); 1014 1015 $this->view->galleryPictures = $tableProject->getGalleryPictureSources($this->_projectId); 1016 $this->view->product_views = $tableProject->fetchProjectViews($this->_projectId); 1017 1018 $helperFetchCategory = new Default_View_Helper_CatTitle(); 1019 $helperFetchCatParent = new Default_View_Helper_CatParent(); 1020 1021 $this->view->catId = $this->view->product->project_category_id; 1022 $this->view->catTitle = $helperFetchCategory->catTitle($this->view->product->project_category_id); 1023 $this->view->catParentId = 1024 $helperFetchCatParent->getCatParentId(array('project_category_id' => $this->view->product->project_category_id)); 1025 if ($this->view->catParentId) { 1026 $this->view->catParentTitle = $helperFetchCategory->catTitle($this->view->catParentId); 1027 } 1028 1029 $AuthCodeExist = new Local_Verification_WebsiteProject(); 1030 $this->view->websiteAuthCode = $AuthCodeExist->generateAuthCode(stripslashes($this->view->product->link_1)); 1031 1032 // switch off temporally 02.05.2017 1033 //$modelPlings = new Default_Model_DbTable_Plings(); 1034 //$this->view->plings = $modelPlings->getDonationsForProject($this->_projectId, 10); 1035 1036 $tableMember = new Default_Model_Member(); 1037 $this->view->member = $tableMember->fetchMemberData($this->view->product->member_id); 1038 1039 $this->view->more_products = $tableProject->fetchMoreProjects($this->view->product, 8); 1040 $this->view->more_products_otheruser = $tableProject->fetchMoreProjectsOfOtherUsr($this->view->product, 8); 1041 1042 $widgetDefaultModel = new Default_Model_DbTable_ProjectWidgetDefault(); 1043 $widgetDefault = $widgetDefaultModel->fetchConfig($this->_projectId); 1044 $widgetDefault->text->headline = $this->view->product->title; 1045 //$widgetDefault->amounts->current = $this->view->product->amount_received; 1046 $widgetDefault->amounts->goal = $this->view->product->amount; 1047 $widgetDefault->project = $this->_projectId; 1048 $this->view->widgetConfig = $widgetDefault; 1049 1050 $helperBuildProductUrl = new Default_View_Helper_BuildProductUrl(); 1051 $this->view->permaLink = $helperBuildProductUrl->buildProductUrl($this->_projectId, null, null, true); 1052 $this->view->urlPay = $helperBuildProductUrl->buildProductUrl($this->_projectId, 'pay'); 1053 1054 $referrerUrl = $this->readExploreUrlFromReferrer(); 1055 if (false === empty($referrerUrl)) { 1056 $this->view->referrerUrl = $referrerUrl; 1057 } 1058 } 1059 1060 /** 1061 * transforms a string with bbcode markup into html 1062 * 1063 * @param string $txt 1064 * @param bool $nl2br 1065 * 1066 * @return string 1067 */ 1068 private function bbcode2html($txt, $nl2br = true, $forcecolor = '') 1069 { 1070 1071 if (!empty($forcecolor)) { 1072 $fc = ' style="color:' . $forcecolor . ';"'; 1073 } else { 1074 $fc = ''; 1075 } 1076 $newtxt = htmlspecialchars($txt); 1077 if ($nl2br) { 1078 $newtxt = nl2br($newtxt); 1079 } 1080 1081 $patterns = array( 1082 '`\[b\](.+?)\[/b\]`is', 1083 '`\[i\](.+?)\[/i\]`is', 1084 '`\[u\](.+?)\[/u\]`is', 1085 '`\[li\](.+?)\[/li\]`is', 1086 '`\[strike\](.+?)\[/strike\]`is', 1087 '`\[url\]([a-z0-9]+?://){1}([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*)?)\[/url\]`si', 1088 '`\[quote\](.+?)\[/quote\]`is', 1089 '`\[indent](.+?)\[/indent\]`is' 1090 ); 1091 1092 $replaces = array( 1093 '<strong' . $fc . '>\\1</strong>', 1094 '<em' . $fc . '>\\1</em>', 1095 '<span style="border-bottom: 1px dotted">\\1</span>', 1096 '<li' . $fc . ' style="margin-left:20px;">\\1</li>', 1097 '<strike' . $fc . '>\\1</strike>', 1098 '<a href="\1\2" rel="nofollow" target="_blank">\1\2</a>', 1099 '<strong' . $fc 1100 . '>Quote:</strong><div style="margin:0px 10px;padding:5px;background-color:#F7F7F7;border:1px dotted #CCCCCC;width:80%;"><em>\1</em></div>', 1101 '<pre' . $fc . '>\\1</pre>' 1102 ); 1103 1104 $newtxt = preg_replace($patterns, $replaces, $newtxt); 1105 1106 return ($newtxt); 1107 } 1108 1109 protected function readExploreUrlFromReferrer() 1110 { 1111 $helperBuildExploreUrl = new Default_View_Helper_BuildExploreUrl(); 1112 $referrerExplore = $helperBuildExploreUrl->buildExploreUrl(null, null, null, null, true); 1113 1114 /** @var Zend_Controller_Request_Http $request */ 1115 $request = $this->getRequest(); 1116 if (strpos($request->getHeader('referer'), $referrerExplore) !== false) { 1117 return $request->getHeader('referer'); 1118 } 1119 } 1120 1121 public function plingAction() 1122 { 1123 1124 if (empty($this->_projectId)) { 1125 $this->redirect('/explore'); 1126 } 1127 1128 $this->view->authMember = $this->_authMember; 1129 1130 $this->fetchDataForIndexView(); 1131 $helperBuildProductUrl = new Default_View_Helper_BuildProductUrl(); 1132 $this->view->urlPay = $helperBuildProductUrl->buildProductUrl($this->_projectId, 'pay'); 1133 $this->view->amount = (float)$this->getParam('amount', 1); 1134 $this->view->comment = html_entity_decode(strip_tags($this->getParam('comment'), null), ENT_QUOTES, 'utf-8'); 1135 $this->view->provider = 1136 mb_strtolower(html_entity_decode(strip_tags($this->getParam('provider'), null), ENT_QUOTES, 'utf-8'), 1137 'utf-8'); 1138 1139 $this->view->headTitle($this->_browserTitlePrepend . $this->view->product->title, 'SET'); 1140 1141 $helperUserIsOwner = new Default_View_Helper_UserIsOwner(); 1142 $helperIsProjectActive = new Default_View_Helper_IsProjectActive(); 1143 if ((false === $helperIsProjectActive->isProjectActive($this->view->product->project_status)) AND (false 1144 === $helperUserIsOwner->UserIsOwner($this->view->product->member_id)) 1145 ) { 1146 throw new Zend_Controller_Action_Exception('This page does not exist', 404); 1147 } 1148 1149 $tableProject = new Default_Model_Collection(); 1150 $this->view->supporting = $tableProject->fetchProjectSupporterWithPlings($this->_projectId); 1151 } 1152 1153 1154 1155 public function payAction() 1156 { 1157 $this->_helper->layout()->disableLayout(); 1158 $tableProject = new Default_Model_Collection(); 1159 $project = $tableProject->fetchProductInfo($this->_projectId); 1160 1161 //get parameter 1162 $amount = (float)$this->getParam('amount', 1); 1163 $comment = Default_Model_HtmlPurify::purify($this->getParam('comment')); 1164 $paymentProvider = 1165 mb_strtolower(html_entity_decode(strip_tags($this->getParam('provider'), null), ENT_QUOTES, 'utf-8'), 1166 'utf-8'); 1167 $hideIdentity = (int)$this->getParam('hideId', 0); 1168 1169 $paymentGateway = $this->createPaymentGateway($paymentProvider); 1170 $paymentGateway->getUserDataStore()->generateFromArray($project->toArray()); 1171 1172 $requestMessage = 'Thank you for supporting: ' . $paymentGateway->getUserDataStore()->getProductTitle(); 1173 1174 $response = null; 1175 try { 1176 $response = $paymentGateway->requestPayment($amount, $requestMessage); 1177 $this->view->checkoutEndpoint = $paymentGateway->getCheckoutEndpoint(); 1178 $this->view->paymentKey = $response->getPaymentId(); 1179 $this->_helper->viewRenderer->setRender('pay_' . $paymentProvider); 1180 } catch (Exception $e) { 1181 throw new Zend_Controller_Action_Exception('payment error', 500, $e); 1182 } 1183 1184 if (false === $response->isSuccessful()) { 1185 throw new Zend_Controller_Action_Exception('payment failure', 500); 1186 } 1187 1188 if (empty($this->_authMember->member_id) or ($hideIdentity == 1)) { 1189 $memberId = 1; 1190 } else { 1191 $memberId = $this->_authMember->member_id; 1192 } 1193 1194 //Add pling 1195 $modelPlings = new Default_Model_DbTable_Plings(); 1196 $plingId = $modelPlings->createNewPlingFromResponse($response, $memberId, $project->project_id, $amount); 1197 1198 if (false == empty($comment)) { 1199 $modelComments = new Default_Model_ProjectComments(); 1200 $dataComment = array( 1201 'comment_type' => Default_Model_DbTable_Comments::COMMENT_TYPE_PLING, 1202 'comment_target_id' => $project->project_id, 1203 'comment_member_id' => $memberId, 1204 'comment_pling_id' => $plingId, 1205 'comment_text' => $comment 1206 ); 1207 $modelComments->save($dataComment); 1208 } 1209 1210 $activityLog = new Default_Model_ActivityLog(); 1211 $activityLog->writeActivityLog($this->_projectId, $memberId, Default_Model_ActivityLog::PROJECT_PLINGED, 1212 $project->toArray()); 1213 } 1214 1215 /** 1216 * @param string $paymentProvider 1217 * 1218 * @return Local_Payment_GatewayInterface 1219 * @throws Exception 1220 * @throws Local_Payment_Exception 1221 * @throws Zend_Controller_Exception 1222 * @throws Zend_Exception 1223 */ 1224 protected function createPaymentGateway($paymentProvider) 1225 { 1226 $httpHost = $this->getRequest()->getHttpHost(); 1227 /** @var Zend_Config $config */ 1228 $config = Zend_Registry::get('config'); 1229 $helperBuildProductUrl = new Default_View_Helper_BuildProductUrl(); 1230 switch ($paymentProvider) { 1231 case 'paypal': 1232 $paymentGateway = new Default_Model_PayPal_Gateway($config->third_party->paypal); 1233 $paymentGateway->setIpnNotificationUrl('http://' . $httpHost . '/gateway/paypal'); 1234 // $paymentGateway->setIpnNotificationUrl('http://' . $httpHost . '/gateway/paypal?XDEBUG_SESSION_START=1'); 1235 $paymentGateway->setCancelUrl($helperBuildProductUrl->buildProductUrl($this->_projectId, 1236 'paymentcancel', null, true)); 1237 $paymentGateway->setReturnUrl($helperBuildProductUrl->buildProductUrl($this->_projectId, 'paymentok', 1238 null, true)); 1239 break; 1240 1241 case 'dwolla': 1242 $paymentGateway = new Default_Model_Dwolla_Gateway($config->third_party->dwolla); 1243 $paymentGateway->setIpnNotificationUrl('http://' . $httpHost . '/gateway/dwolla'); 1244 // $paymentGateway->setIpnNotificationUrl('http://' . $_SERVER ['HTTP_HOST'] . '/gateway/dwolla?XDEBUG_SESSION_START=1'); 1245 $paymentGateway->setReturnUrl($helperBuildProductUrl->buildProductUrl($this->_projectId, 'dwolla', null, 1246 true)); 1247 break; 1248 1249 case 'amazon': 1250 $paymentGateway = new Default_Model_Amazon_Gateway($config->third_party->amazon); 1251 $paymentGateway->setIpnNotificationUrl('http://' . $httpHost . '/gateway/amazon'); 1252 // $paymentGateway->setIpnNotificationUrl('http://' . $httpHost . '/gateway/amazon?XDEBUG_SESSION_START=1'); 1253 $paymentGateway->setCancelUrl($helperBuildProductUrl->buildProductUrl($this->_projectId, 1254 'paymentcancel', null, true)); 1255 $paymentGateway->setReturnUrl($helperBuildProductUrl->buildProductUrl($this->_projectId, 'paymentok', 1256 null, true)); 1257 break; 1258 1259 default: 1260 throw new Zend_Controller_Exception('No known payment provider found in parameters.'); 1261 break; 1262 } 1263 1264 return $paymentGateway; 1265 } 1266 1267 public function dwollaAction() 1268 { 1269 $modelPling = new Default_Model_DbTable_Plings(); 1270 $plingData = $modelPling->fetchRow(array('payment_reference_key = ?' => $this->getParam('checkoutId'))); 1271 $plingData->payment_transaction_id = (int)$this->getParam('transaction'); 1272 $plingData->save(); 1273 1274 if ($this->_getParam('status') == 'Completed') { 1275 $this->_helper->viewRenderer('paymentok'); 1276 $this->paymentokAction(); 1277 } else { 1278 $this->_helper->viewRenderer('paymentcancel'); 1279 $this->paymentcancelAction(); 1280 } 1281 } 1282 1283 public function paymentokAction() 1284 { 1285 $this->_helper->layout()->disableLayout(); 1286 $this->view->paymentStatus = 'success'; 1287 $this->view->paymentMessage = 'Payment successful.'; 1288 $this->fetchDataForIndexView(); 1289 } 1290 1291 public function paymentcancelAction() 1292 { 1293 $this->_helper->layout()->disableLayout(); 1294 $this->view->paymentStatus = 'danger'; 1295 $this->view->paymentMessage = 'Payment cancelled.'; 1296 $this->fetchDataForIndexView(); 1297 } 1298 1299 public function deleteAction() 1300 { 1301 $this->_helper->layout()->setLayout('flat_ui'); 1302 1303 $memberId = (int)$this->getParam('m'); 1304 1305 if ((empty($this->_authMember->member_id)) OR (empty($memberId)) OR ($this->_authMember->member_id 1306 != $memberId) 1307 ) { 1308 $this->forward('products', 'user', 'default'); 1309 1310 return; 1311 } 1312 1313 $tableProduct = new Default_Model_Collection(); 1314 $tableProduct->setDeleted($this->_authMember->member_id,$this->_projectId); 1315 1316 $product = $tableProduct->find($this->_projectId)->current(); 1317 1318 // delete product from search index 1319 $modelSearch = new Default_Model_Search_Lucene(); 1320 $modelSearch->deleteDocument($product->toArray()); 1321 // $command = new Backend_Commands_DeleteProductExtended($product); 1322 // $command->doCommand(); 1323 // $queue = Local_Queue_Factory::getQueue('search'); 1324 // $command = new Backend_Commands_DeleteProductFromIndex($product->project_id, $product->project_category_id); 1325 // $msg = $queue->send(serialize($command)); 1326 1327 $activityLog = new Default_Model_ActivityLog(); 1328 $activityLog->writeActivityLog($this->_projectId, $this->_authMember->member_id, Default_Model_ActivityLog::PROJECT_DELETED, 1329 $product->toArray()); 1330 1331 $this->forward('products', 'user', 'default'); 1332 } 1333 1334 public function unpublishAction() 1335 { 1336 $this->_helper->layout()->setLayout('flat_ui'); 1337 1338 $memberId = (int)$this->getParam('m'); 1339 1340 if ( 1341 (empty($this->_authMember->member_id)) 1342 OR 1343 (empty($memberId)) 1344 OR ($this->_authMember->member_id != $memberId) 1345 ) { 1346 return; 1347 } 1348 1349 $tableProduct = new Default_Model_Collection(); 1350 $tableProduct->setInActive($this->_projectId, $memberId); 1351 1352 $product = $tableProduct->find($this->_projectId)->current(); 1353 1354 if (isset($product->type_id) && $product->type_id == Default_Model_Collection::PROJECT_TYPE_UPDATE) { 1355 $parentProduct = $tableProduct->find($product->pid)->current(); 1356 $product->image_small = $parentProduct->image_small; 1357 } 1358 1359 $activityLog = new Default_Model_ActivityLog(); 1360 $activityLog->writeActivityLog($this->_projectId, $this->_authMember->member_id, Default_Model_ActivityLog::PROJECT_UNPUBLISHED, 1361 $product->toArray()); 1362 1363 // remove unpublished project from search index 1364 $modelSearch = new Default_Model_Search_Lucene(); 1365 $modelSearch->deleteDocument($product); 1366 1367 $this->forward('collections', 'user', 'default', array('member_id' => $memberId)); 1368 //$this->redirect('/member/'.$memberId.'/products'); 1369 } 1370 1371 public function publishAction() 1372 { 1373 $memberId = (int)$this->getParam('m'); 1374 1375 if ((empty($this->_authMember->member_id)) OR (empty($memberId)) OR ($this->_authMember->member_id 1376 != $memberId) 1377 ) { 1378 return; 1379 } 1380 1381 $tableProduct = new Default_Model_Collection(); 1382 $tableProduct->setActive($this->_authMember->member_id,$this->_projectId); 1383 1384 $product = $tableProduct->find($this->_projectId)->current(); 1385 1386 if (isset($product->type_id) && $product->type_id == Default_Model_Collection::PROJECT_TYPE_UPDATE) { 1387 $parentProduct = $tableProduct->find($product->pid)->current(); 1388 $product->image_small = $parentProduct->image_small; 1389 } 1390 1391 $activityLog = new Default_Model_ActivityLog(); 1392 $activityLog->writeActivityLog($this->_projectId, $this->_authMember->member_id, Default_Model_ActivityLog::PROJECT_PUBLISHED, 1393 $product->toArray()); 1394 1395 // add published project to search index 1396 // $productInfo = $tableProduct->fetchProductInfo($this->_projectId); 1397 // $modelSearch = new Default_Model_Search_Lucene(); 1398 // $modelSearch->addDocument($productInfo); 1399 1400 $this->forward('collections', 'user', 'default', array('member_id' => $memberId)); 1401 //$this->redirect('/member/'.$memberId.'/products'); 1402 } 1403 1404 public function loadratingsAction() 1405 { 1406 $this->_helper->layout->disableLayout(); 1407 $tableProjectRatings = new Default_Model_DbTable_ProjectRating(); 1408 $ratings = $tableProjectRatings->fetchRating($this->_projectId); 1409 $this->_helper->json($ratings); 1410 } 1411 1412 public function loadinstallinstructionAction() 1413 { 1414 $this->_helper->layout->disableLayout(); 1415 $infomodel = new Default_Model_Info(); 1416 $text = $infomodel->getOCSInstallInstruction(); 1417 1418 1419 $this->_helper->json(array( 1420 'status' => 'ok', 1421 'data' => $text 1422 )); 1423 } 1424 1425 public function followAction() 1426 { 1427 $this->_helper->layout()->disableLayout(); 1428 // $this->_helper->viewRenderer->setNoRender(true); 1429 1430 $this->view->project_id = $this->_projectId; 1431 $this->view->authMember = $this->_authMember; 1432 1433 if (array_key_exists($this->_projectId, $this->_authMember->projects)) { 1434 return; 1435 } 1436 1437 $projectFollowTable = new Default_Model_DbTable_ProjectFollower(); 1438 1439 $newVals = array('project_id' => $this->_projectId, 'member_id' => $this->_authMember->member_id); 1440 $where = $projectFollowTable->select()->where('member_id = ?', $this->_authMember->member_id) 1441 ->where('project_id = ?', $this->_projectId, 'INTEGER') 1442 ; 1443 $result = $projectFollowTable->fetchRow($where); 1444 1445 if (null === $result) { 1446 $projectFollowTable->createRow($newVals)->save(); 1447 $tableProduct = new Default_Model_Collection(); 1448 $product = $tableProduct->find($this->_projectId)->current(); 1449 1450 $activityLog = new Default_Model_ActivityLog(); 1451 $activityLog->writeActivityLog($this->_projectId, $this->_authMember->member_id, 1452 Default_Model_ActivityLog::PROJECT_FOLLOWED, $product->toArray()); 1453 } 1454 1455 } 1456 1457 public function unfollowAction() 1458 { 1459 $this->_helper->layout()->disableLayout(); 1460 $this->_helper->viewRenderer('follow'); 1461 1462 $this->view->project_id = $this->_projectId; 1463 $this->view->authMember = $this->_authMember; 1464 1465 $projectFollowTable = new Default_Model_DbTable_ProjectFollower(); 1466 1467 $projectFollowTable->delete('member_id=' . $this->_authMember->member_id . ' AND project_id=' 1468 . $this->_projectId); 1469 1470 1471 $tableProduct = new Default_Model_Collection(); 1472 $product = $tableProduct->find($this->_projectId)->current(); 1473 1474 $activityLog = new Default_Model_ActivityLog(); 1475 $activityLog->writeActivityLog($this->_projectId, $this->_authMember->member_id, 1476 Default_Model_ActivityLog::PROJECT_UNFOLLOWED, $product->toArray()); 1477 1478 1479 } 1480 1481 public function followpAction() 1482 { 1483 $this->_helper->layout()->disableLayout(); 1484 // $this->_helper->viewRenderer->setNoRender(true); 1485 1486 $this->view->project_id = $this->_projectId; 1487 $this->view->authMember = $this->_authMember; 1488 1489 if (array_key_exists($this->_projectId, $this->_authMember->projects)) { 1490 return; 1491 } 1492 1493 $projectFollowTable = new Default_Model_DbTable_ProjectFollower(); 1494 1495 $newVals = array('project_id' => $this->_projectId, 'member_id' => $this->_authMember->member_id); 1496 $where = $projectFollowTable->select()->where('member_id = ?', $this->_authMember->member_id) 1497 ->where('project_id = ?', $this->_projectId, 'INTEGER') 1498 ; 1499 $result = $projectFollowTable->fetchRow($where); 1500 1501 if (null === $result) { 1502 $projectFollowTable->createRow($newVals)->save(); 1503 $tableProduct = new Default_Model_Collection(); 1504 $product = $tableProduct->find($this->_projectId)->current(); 1505 $activityLog = new Default_Model_ActivityLog(); 1506 $activityLog->writeActivityLog($this->_projectId, $this->_authMember->member_id, 1507 Default_Model_ActivityLog::PROJECT_FOLLOWED, $product->toArray()); 1508 } 1509 } 1510 1511 public function unfollowpAction() 1512 { 1513 $this->_helper->layout()->disableLayout(); 1514 $this->_helper->viewRenderer('followp'); 1515 1516 $this->view->project_id = $this->_projectId; 1517 $this->view->authMember = $this->_authMember; 1518 1519 $projectFollowTable = new Default_Model_DbTable_ProjectFollower(); 1520 1521 $projectFollowTable->delete('member_id=' . $this->_authMember->member_id . ' AND project_id=' 1522 . $this->_projectId); 1523 1524 1525 $tableProduct = new Default_Model_Collection(); 1526 $product = $tableProduct->find($this->_projectId)->current(); 1527 1528 $activityLog = new Default_Model_ActivityLog(); 1529 $activityLog->writeActivityLog($this->_projectId, $this->_authMember->member_id, 1530 Default_Model_ActivityLog::PROJECT_UNFOLLOWED, $product->toArray()); 1531 1532 } 1533 1534 protected function logActivity($logId) 1535 { 1536 $tableProduct = new Default_Model_Collection(); 1537 $product = $tableProduct->find($this->_projectId)->current(); 1538 $activityLog = new Default_Model_ActivityLog(); 1539 $activityLog->writeActivityLog($this->_projectId, $this->_authMember->member_id, 1540 $logId, $product->toArray()); 1541 } 1542 1543 1544 public function followprojectAction() 1545 { 1546 $this->_helper->layout()->disableLayout(); 1547 1548 $this->view->project_id = $this->_projectId; 1549 $this->view->authMember = $this->_authMember; 1550 1551 // not allow to pling himself 1552 if (array_key_exists($this->_projectId, $this->_authMember->projects)) 1553 { 1554 $this->_helper->json(array( 1555 'status' => 'error', 1556 'msg' => 'not allowed' 1557 )); 1558 return; 1559 } 1560 1561 1562 $projectFollowTable = new Default_Model_DbTable_ProjectFollower(); 1563 1564 $newVals = array('project_id' => $this->_projectId, 'member_id' => $this->_authMember->member_id); 1565 $where = $projectFollowTable->select()->where('member_id = ?', $this->_authMember->member_id) 1566 ->where('project_id = ?', $this->_projectId, 'INTEGER') ; 1567 1568 $result = $projectFollowTable->fetchRow($where); 1569 1570 if (null === $result) { 1571 $projectFollowTable->createRow($newVals)->save(); 1572 $this->logActivity(Default_Model_ActivityLog::PROJECT_FOLLOWED); 1573 $cnt = $projectFollowTable->countForProject($this->_projectId); 1574 $this->_helper->json(array( 1575 'status' => 'ok', 1576 'msg' => 'Success.', 1577 'cnt' => $cnt, 1578 'action' =>'insert' 1579 )); 1580 }else{ 1581 $projectFollowTable->delete('member_id=' . $this->_authMember->member_id . ' AND project_id=' 1582 . $this->_projectId); 1583 $this->logActivity(Default_Model_ActivityLog::PROJECT_UNFOLLOWED); 1584 $cnt = $projectFollowTable->countForProject($this->_projectId); 1585 $this->_helper->json(array( 1586 'status' => 'ok', 1587 'msg' => 'Success.', 1588 'cnt' => $cnt, 1589 'action' => 'delete' 1590 )); 1591 } 1592 1593 } 1594 1595 1596 public function plingprojectAction() 1597 { 1598 $this->_helper->layout()->disableLayout(); 1599 1600 $this->view->project_id = $this->_projectId; 1601 $this->view->authMember = $this->_authMember; 1602 1603 // not allow to pling himself 1604 if (array_key_exists($this->_projectId, $this->_authMember->projects)) 1605 { 1606 $this->_helper->json(array( 1607 'status' => 'error', 1608 'msg' => 'not allowed' 1609 )); 1610 return; 1611 } 1612 1613 // not allow to pling if not supporter 1614 $helperIsSupporter = new Default_View_Helper_IsSupporter(); 1615 if(!$helperIsSupporter->isSupporter($this->_authMember->member_id)) 1616 { 1617 $this->_helper->json(array( 1618 'status' => 'error', 1619 'msg' => 'become a supporter first please. ' 1620 )); 1621 return; 1622 } 1623 1624 1625 $projectplings = new Default_Model_ProjectPlings(); 1626 1627 $newVals = array('project_id' => $this->_projectId, 'member_id' => $this->_authMember->member_id); 1628 $sql = $projectplings->select() 1629 ->where('member_id = ?', $this->_authMember->member_id) 1630 ->where('is_deleted = ?',0) 1631 ->where('project_id = ?', $this->_projectId, 'INTEGER') 1632 ; 1633 $result = $projectplings->fetchRow($sql); 1634 1635 if (null === $result) { 1636 $projectplings->createRow($newVals)->save(); 1637 //$this->logActivity(Default_Model_ActivityLog::PROJECT_PLINGED_2); 1638 1639 $cnt = $projectplings->getPlingsAmount($this->_projectId); 1640 $this->_helper->json(array( 1641 'status' => 'ok', 1642 'msg' => 'Success.', 1643 'cnt' => $cnt, 1644 'action' =>'insert' 1645 )); 1646 }else{ 1647 1648 // delete pling 1649 $projectplings->setDelete($result->project_plings_id); 1650 //$this->logActivity(Default_Model_ActivityLog::PROJECT_DISPLINGED_2); 1651 1652 $cnt = $projectplings->getPlingsAmount($this->_projectId); 1653 $this->_helper->json(array( 1654 'status' => 'ok', 1655 'msg' => 'Success.', 1656 'cnt' => $cnt, 1657 'action' => 'delete' 1658 )); 1659 } 1660 1661 } 1662 1663 /** 1664 1665 public function unplingprojectAction() 1666 { 1667 $this->_helper->layout()->disableLayout(); 1668 1669 $projectplings = new Default_Model_ProjectPlings(); 1670 $pling = $projectplings->getPling($this->_projectId,$this->_authMember->member_id); 1671 1672 if($pling) 1673 { 1674 $projectplings->setDelete($pling->project_plings_id); 1675 $cnt = count($projectplings->getPlings($this->_projectId)); 1676 $this->_helper->json(array( 1677 'status' => 'ok', 1678 'deleted' => $pling->project_plings_id, 1679 'msg' => 'Success. ', 1680 'cnt' => $cnt 1681 )); 1682 1683 $tableProduct = new Default_Model_Project(); 1684 $product = $tableProduct->find($this->_projectId)->current(); 1685 1686 $activityLog = new Default_Model_ActivityLog(); 1687 $activityLog->writeActivityLog($this->_projectId, $this->_authMember->member_id, 1688 Default_Model_ActivityLog::PROJECT_DISPLINGED_2, $product->toArray()); 1689 }else{ 1690 $this->_helper->json(array( 1691 'status' => 'error', 1692 'msg' => 'not existing.' 1693 )); 1694 } 1695 1696 1697 } 1698 **/ 1699 1700 public function followsAction() 1701 { 1702 $projectFollowTable = new Default_Model_Member(); 1703 1704 $memberId = $this->_authMember->member_id; 1705 $this->view->productList = $projectFollowTable->fetchFollowedProjects($memberId); 1706 1707 $projectArray = $this->generateFollowedProjectsViewData($this->view->productList); 1708 1709 $this->view->productArray['followedProjects'] = $projectArray; 1710 } 1711 1712 /** 1713 * @param $list 1714 * 1715 * @return array 1716 */ 1717 protected function generateFollowedProjectsViewData($list) 1718 { 1719 $viewArray = array(); 1720 1721 if (count($list) == 0) { 1722 return $viewArray; 1723 } 1724 1725 $helperBuildProductUrl = new Default_View_Helper_BuildProductUrl(); 1726 foreach ($list as $element) { 1727 $arr = array(); 1728 $arr['id'] = $element->project_id; 1729 $arr['name'] = $element->title; 1730 $arr['image'] = $element->image_small; 1731 $arr['url'] = $helperBuildProductUrl->buildProductUrl($element->project_id); 1732 $arr['urlUnFollow'] = $helperBuildProductUrl->buildProductUrl($element->project_id, 'unfollow'); 1733 #$arr['showUrlUnFollow'] = $this->view->isMember; 1734 1735 $viewArray[] = $arr; 1736 } 1737 1738 return $viewArray; 1739 } 1740 1741 public function verifycodeAction() 1742 { 1743 $this->_helper->layout()->disableLayout(); 1744 1745 if ($this->_request->isXmlHttpRequest()) { 1746 $tabProject = new Default_Model_DbTable_Project(); 1747 $dataProject = $tabProject->find($this->_projectId)->current(); 1748 $this->createTaskWebsiteOwnerVerification($dataProject); 1749 $this->view->message = 'Your product page is stored for validation.'; 1750 1751 return; 1752 } 1753 1754 $this->view->message = 'This service is not available at the moment. Please try again later.'; 1755 } 1756 1757 /** 1758 * @throws Zend_Controller_Action_Exception 1759 * @deprecated 1760 */ 1761 public function fetchAction() 1762 { 1763 $this->_helper->layout()->disableLayout(); 1764 1765 if ($this->_request->isXmlHttpRequest()) { 1766 $this->view->authMember = $this->_authMember; 1767 1768 $this->fetchDataForIndexView(); 1769 $tableProject = new Default_Model_Collection(); 1770 $this->view->supporting = $tableProject->fetchProjectSupporterWithPlings($this->_projectId); 1771 1772 if (false === isset($this->view->product)) { 1773 throw new Zend_Controller_Action_Exception('This page does not exist', 404); 1774 } 1775 1776 $helperUserIsOwner = new Default_View_Helper_UserIsOwner(); 1777 $helperIsProjectActive = new Default_View_Helper_IsProjectActive(); 1778 if ((false === $helperIsProjectActive->isProjectActive($this->view->product->project_status)) AND (false 1779 === $helperUserIsOwner->UserIsOwner($this->view->product->member_id)) 1780 ) { 1781 throw new Zend_Controller_Action_Exception('This page does not exist', 404); 1782 } 1783 1784 $tablePageViews = new Default_Model_DbTable_StatPageViews(); 1785 $tablePageViews->savePageView($this->_projectId, $this->getRequest()->getClientIp(), 1786 $this->_authMember->member_id); 1787 } 1788 1789 $this->_helper->json(get_object_vars($this->view)); 1790 } 1791 1792 public function claimAction() 1793 { 1794 $modelProduct = new Default_Model_Collection(); 1795 $productInfo = $modelProduct->fetchProductInfo($this->_projectId); 1796 if ($productInfo->claimable != Default_Model_Collection::PROJECT_CLAIMABLE) { 1797 throw new Zend_Controller_Action_Exception('Method not available', 404); 1798 } 1799 $helperBuildProductUrl = new Default_View_Helper_BuildProductUrl(); 1800 if (empty($productInfo->claimed_by_member)) { 1801 $modelProduct->setClaimedByMember($this->_authMember->member_id, $this->_projectId); 1802 1803 $claimMail = new Default_Plugin_SendMail('tpl_mail_claim_product'); 1804 $claimMail->setTemplateVar('sender', $this->_authMember->mail); 1805 $claimMail->setTemplateVar('productid', $productInfo->project_id); 1806 $claimMail->setTemplateVar('producttitle', $productInfo->title); 1807 $claimMail->setTemplateVar('userid', $this->_authMember->member_id); 1808 $claimMail->setTemplateVar('username', $this->_authMember->username); 1809 $claimMail->setTemplateVar('usermail', $this->_authMember->mail); 1810 $claimMail->setReceiverMail(array('contact@opendesktop.org')); 1811 $claimMail->send(); 1812 1813 $claimMailConfirm = new Default_Plugin_SendMail('tpl_mail_claim_confirm'); 1814 $claimMailConfirm->setTemplateVar('sender', 'contact@opendesktop.org'); 1815 $claimMailConfirm->setTemplateVar('producttitle', $productInfo->title); 1816 $claimMailConfirm->setTemplateVar('productlink', 'http://' . $this->getRequest()->getHttpHost() 1817 . $helperBuildProductUrl->buildProductUrl($productInfo->project_id)); 1818 $claimMailConfirm->setTemplateVar('username', $this->_authMember->username); 1819 $claimMailConfirm->setReceiverMail($this->_authMember->mail); 1820 $claimMailConfirm->send(); 1821 } 1822 1823 $this->_helper->viewRenderer('index'); 1824 $this->indexAction(); 1825 } 1826 1827 public function makerconfigAction() 1828 { 1829 $this->_helper->layout()->disableLayout(); 1830 1831 $widgetProjectId = (int)$this->getParam('project_id'); 1832 if (false == isset($widgetProjectId)) { 1833 throw new Zend_Controller_Action_Exception('This page does not exist', 404); 1834 } 1835 $widgetDefaultModel = new Default_Model_DbTable_ProjectWidgetDefault(); 1836 $widgetDefault = $widgetDefaultModel->fetchConfig($widgetProjectId); 1837 if (!isset($widgetDefault)) { 1838 throw new Zend_Controller_Action_Exception('This page does not exist', 404); 1839 } else { 1840 $this->view->widgetConfig = $widgetDefault; 1841 $productModel = new Default_Model_Collection(); 1842 $this->view->product = $productModel->fetchProductDataFromMV($widgetProjectId); 1843 $this->view->supporting = $productModel->fetchProjectSupporterWithPlings($widgetProjectId); 1844 $plingModel = new Default_Model_DbTable_Plings(); 1845 $this->view->comments = $plingModel->getCommentsForProject($widgetProjectId, 10); 1846 $websiteOwner = new Local_Verification_WebsiteProject(); 1847 $this->view->authCode = '<meta name="ocs-site-verification" content="' 1848 . $websiteOwner->generateAuthCode(stripslashes($this->view->product->link_1)) . '" />'; 1849 } 1850 } 1851 1852 1853 public function saveproductAction() 1854 { 1855 $form = new Default_Form_Collection(); 1856 1857 // we don't need to test a file which doesn't exist in this case. The Framework stumbles if $_FILES is empty. 1858 if ($this->_request->isXmlHttpRequest() AND (count($_FILES) == 0)) { 1859 $form->removeElement('image_small_upload'); 1860 // $form->removeElement('image_big_upload'); 1861 $form->removeSubForm('gallery'); 1862 $form->removeElement('project_id'); //(workaround: Some Browsers send "0" in some cases.) 1863 } 1864 1865 if (false === $form->isValid($_POST)) { 1866 $errors = $form->getMessages(); 1867 $messages = $this->getErrorMessages($errors); 1868 $this->_helper->json(array('status' => 'error', 'messages' => $messages)); 1869 } 1870 1871 $formValues = $form->getValues(); 1872 $formValues['status'] = Default_Model_Collection::PROJECT_INCOMPLETE; 1873 1874 $modelProject = new Default_Model_Collection(); 1875 $newProject = 1876 $modelProject->createCollection($this->_authMember->member_id, $formValues, $this->_authMember->username); 1877 //$this->createSystemPlingForNewProject($newProject->project_id); 1878 //New Project in Session, for AuthValidation (owner) 1879 $this->_auth->getIdentity()->projects[$newProject->project_id] = array('project_id' => $newProject->project_id); 1880 1881 $this->_helper->json(array('status' => 'ok', 'project_id' => $newProject->project_id)); 1882 } 1883 1884 1885 protected function createPling($member_id,$project_id) 1886 { 1887 $projectplings = new Default_Model_ProjectPlings(); 1888 $newVals = array('project_id' =>$project_id, 'member_id' => $member_id); 1889 $sql = $projectplings->select() 1890 ->where('member_id = ?', $this->_authMember->member_id) 1891 ->where('is_deleted = ?',0) 1892 ->where('project_id = ?', $this->_projectId, 'INTEGER'); 1893 $result = $projectplings->fetchRow($sql); 1894 if (null === $result) { 1895 $projectplings->createRow($newVals)->save(); 1896 } 1897 } 1898 1899 1900 1901 /** 1902 * @param $errors 1903 * 1904 * @return array 1905 */ 1906 protected function getErrorMessages($errors) 1907 { 1908 $messages = array(); 1909 foreach ($errors as $element => $row) { 1910 if (!empty($row) && $element != 'submit') { 1911 foreach ($row as $validator => $message) { 1912 $messages[$element][] = $message; 1913 } 1914 } 1915 } 1916 1917 return $messages; 1918 } 1919 1920 public function searchAction() 1921 { 1922 // Filter-Parameter 1923 $filterInput = 1924 new Zend_Filter_Input( 1925 array( 1926 '*' => 'StringTrim', 1927 'projectSearchText' => array(new Zend_Filter_Callback('stripslashes'),'StripTags'), 1928 'page' => 'digits', 1929 'pci' => 'digits', 1930 'ls' => 'digits', 1931 't' => array(new Zend_Filter_Callback('stripslashes'),'StripTags'), 1932 'pkg'=> array(new Zend_Filter_Callback('stripslashes'),'StripTags'), 1933 'lic'=> array(new Zend_Filter_Callback('stripslashes'),'StripTags'), 1934 'arch'=> array(new Zend_Filter_Callback('stripslashes'),'StripTags') 1935 1936 ), 1937 array( 1938 'projectSearchText' => array( 1939 new Zend_Validate_StringLength(array('min' => 3, 'max' => 100)), 1940 'presence' => 'required' 1941 ), 1942 'page' => array('digits', 'default' => '1'), 1943 'f' => array( 1944 new Zend_Validate_StringLength(array('min' => 3, 'max' => 100)), 1945 //new Zend_Validate_InArray(array('f'=>'tags')), 1946 'allowEmpty' => true 1947 ), 1948 'pci' => array('digits', 1949 'allowEmpty' => true 1950 ), 1951 'ls' => array('digits', 1952 'allowEmpty' => true 1953 ), 1954 't' => array(new Zend_Validate_StringLength(array('min' => 3, 'max' => 100)), 1955 'allowEmpty' => true 1956 ), 1957 'pkg' => array(new Zend_Validate_StringLength(array('min' => 3, 'max' => 100)), 1958 'allowEmpty' => true 1959 ), 1960 'lic' => array(new Zend_Validate_StringLength(array('min' => 3, 'max' => 100)), 1961 'allowEmpty' => true 1962 ), 1963 'arch' => array(new Zend_Validate_StringLength(array('min' => 3, 'max' => 100)), 1964 'allowEmpty' => true) 1965 ), $this->getAllParams()); 1966 1967 1968 1969 if ($filterInput->hasInvalid()) { 1970 $this->_helper->flashMessenger->addMessage('<p class="text-error">There was an error. Please check your input and try again.</p>'); 1971 return; 1972 } 1973 1974 1975 1976 $this->view->searchText = $filterInput->getEscaped('projectSearchText'); 1977 $this->view->page = $filterInput->getEscaped('page'); 1978 $this->view->searchField = $filterInput->getEscaped('f'); 1979 $this->view->pci = $filterInput->getEscaped('pci'); 1980 $this->view->ls = $filterInput->getEscaped('ls'); 1981 $this->view->t = $filterInput->getEscaped('t'); 1982 $this->view->pkg = $filterInput->getEscaped('pkg'); 1983 $this->view->arch = $filterInput->getEscaped('arch'); 1984 $this->view->lic = $filterInput->getEscaped('lic'); 1985 $this->view->store = $this->getParam('domain_store_id'); 1986 } 1987 1988 /** 1989 * @param $memberId 1990 * 1991 * @throws Zend_Db_Table_Exception 1992 */ 1993 protected function setViewDataForMyProducts($memberId) 1994 { 1995 $tableMember = new Default_Model_Member(); 1996 $this->view->member = $tableMember->find($memberId)->current(); 1997 1998 $tableProduct = new Default_Model_Collection(); 1999 $this->view->products = $tableProduct->fetchAllProjectsForMember($memberId); 2000 } 2001 2002 protected function _initResponseHeader() 2003 { 2004 $duration = 1800; // in seconds 2005 $expires = gmdate("D, d M Y H:i:s", time() + $duration) . " GMT"; 2006 2007 $this->getResponse()->setHeader('X-FRAME-OPTIONS', 'ALLOWALL', 2008 true)// ->setHeader('Last-Modified', $modifiedTime, true) 2009 ->setHeader('Expires', $expires, true)->setHeader('Pragma', 'no-cache', true) 2010 ->setHeader('Cache-Control', 'private, no-cache, must-revalidate', true) 2011 ; 2012 } 2013 2014 /** 2015 * @param $hits 2016 * 2017 * @return array 2018 */ 2019 protected function generateProjectsArrayForView($hits) 2020 { 2021 $viewArray = array(); 2022 $helperBuildProductUrl = new Default_View_Helper_BuildProductUrl(); 2023 /** @var $hit Zend_Search_Lucene_Search_QueryHit */ 2024 foreach ($hits as $hit) { 2025 $project = $hit->getDocument(); 2026 if (null != $project->username) { 2027 $isUpdate = ($project->type_id == 2); 2028 if ($isUpdate) { 2029 $showUrl = 2030 $helperBuildProductUrl->buildProductUrl($project->pid) . '#anker_' . $project->project_id; 2031 $plingUrl = $helperBuildProductUrl->buildProductUrl($project->pid, 'pling'); 2032 } else { 2033 $showUrl = $helperBuildProductUrl->buildProductUrl($project->project_id); 2034 $plingUrl = $helperBuildProductUrl->buildProductUrl($project->project_id, 'pling'); 2035 } 2036 $projectArr = array( 2037 'score' => $hit->score, 2038 'id' => $project->project_id, 2039 'type_id' => $project->type_id, 2040 'title' => $project->title, 2041 'description' => $project->description, 2042 'image' => $project->image_small, 2043 'plings' => 0, 2044 'urlGoal' => $showUrl, 2045 'urlPling' => $plingUrl, 2046 'showUrlPling' => ($project->paypal_mail != null), 2047 'member' => array( 2048 'name' => $project->username, 2049 'url' => 'member/' . $project->member_id, 2050 'image' => $project->profile_image_url, 2051 'id' => $project->member_id 2052 ) 2053 ); 2054 $viewArray[] = $projectArr; 2055 } 2056 } 2057 2058 return $viewArray; 2059 } 2060 2061 2062 protected function setLayout() 2063 { 2064 $layoutName = 'flat_ui_template'; 2065 $storeConfig = Zend_Registry::isRegistered('store_config') ? Zend_Registry::get('store_config') : null; 2066 if($storeConfig && $storeConfig->layout_pagedetail) 2067 { 2068 $this->_helper->layout()->setLayout($storeConfig->layout_pagedetail); 2069 }else{ 2070 $this->_helper->layout()->setLayout($layoutName); 2071 } 2072 } 2073 2074 2075 private function fetchGitlabProject($gitProjectId) 2076 { 2077 $gitlab = new Default_Model_Ocs_Gitlab(); 2078 2079 try { 2080 $gitProject = $gitlab->getProject($gitProjectId); 2081 } catch (Exception $exc) { 2082 //Project is gone 2083 $modelProject = new Default_Model_Collection(); 2084 $modelProject->updateProject($this->_projectId, array('is_gitlab_project' => 0, 'gitlab_project_id' => null, 'show_gitlab_project_issues' => 0, 'use_gitlab_project_readme' => 0)); 2085 $gitProject = null; 2086 } 2087 return $gitProject; 2088 } 2089 2090 private function fetchGitlabProjectIssues($gitProjectId) 2091 { 2092 $gitlab = new Default_Model_Ocs_Gitlab(); 2093 2094 try { 2095 $gitProjectIssues = $gitlab->getProjectIssues($gitProjectId); 2096 } catch (Exception $exc) { 2097 //Project is gone 2098 $modelProject = new Default_Model_Collection(); 2099 $modelProject->updateProject($this->_projectId, array('is_gitlab_project' => 0, 'gitlab_project_id' => null, 'show_gitlab_project_issues' => 0, 'use_gitlab_project_readme' => 0)); 2100 2101 $gitProjectIssues = null; 2102 } 2103 2104 2105 2106 return $gitProjectIssues; 2107 } 2108 2109 }