/**
  * Returns an instance of class (singleton pattern implementation).
  *
  * @return CONTACTUS_BOL_Service
  */
 public static function getInstance()
 {
     if (self::$classInstance === null) {
         self::$classInstance = new self();
     }
     return self::$classInstance;
 }
示例#2
0
 public function category($params)
 {
     SPDOWNLOAD_BOL_FileCategoryService::getInstance()->deleteId($params);
 }
示例#3
0
 public function delete($params)
 {
     $countParent = SPDOWNLOAD_BOL_CategoryService::getInstance()->getCountCategoryParent($params['categoryId']);
     if ($countParent != 0) {
         throw new Redirect404Exception();
     }
     SPDOWNLOAD_BOL_FileCategoryService::getInstance()->deleteId($params);
     SPDOWNLOAD_BOL_CategoryService::getInstance()->deleteIdCategory($params['categoryId']);
     $this->redirect(OW::getRouter()->urlForRoute('spdownload.category_list'));
 }
示例#4
0
 public function detail($params)
 {
     $document = OW::getDocument();
     $plugin = OW::getPluginManager()->getPlugin('spdownload');
     $document->addStyleSheet($plugin->getStaticCssUrl() . 'file_detail.css');
     $check = $params['fileId'];
     if (!stripos($params['fileId'], "-")) {
         throw new Redirect404Exception();
     }
     $params['fileId'] = substr($params['fileId'], 0, stripos($params['fileId'], "-"));
     $file = SPDOWNLOAD_BOL_FileService::getInstance()->getFileId($params['fileId']);
     if ($file->id . '-' . $file->slug != $check) {
         throw new Redirect404Exception();
     }
     $cmpThumbnails = new SPDOWNLOAD_CMP_Thumbnail($params['fileId']);
     $this->addComponent('cmpThumbnails', $cmpThumbnails);
     $params['authorId'] = $file->authorId;
     $params['quantitySoft'] = 2;
     $cmpRelatedItemUser = new SPDOWNLOAD_CMP_RelatedItemUser($params);
     $this->addComponent('cmpRelatedItemUser', $cmpRelatedItemUser);
     $filevernew = SPDOWNLOAD_BOL_VersionService::getInstance()->getFileVerNew($params['fileId']);
     $limit = 3;
     $fileverold = SPDOWNLOAD_BOL_VersionService::getInstance()->getFileOldVersion($params['fileId'], $filevernew[0]->id, $limit);
     $filevernew[0]->size = $this->splitFilesize($filevernew[0]->size);
     foreach ($fileverold as $key => $value) {
         $value->size = $this->splitFilesize($value->size);
     }
     // rate
     $rateInfo = new BASE_CMP_Rate('spdownload', 'spdownload-software', $file->getId(), $file->authorId);
     $this->addComponent('rate', $rateInfo);
     // comments
     $allow_comments = true;
     if ($file->authorId != OW::getUser()->getId() && !OW::getUser()->isAuthorized('spdownload')) {
         $eventParams = array('action' => 'spdownload_comment_spdownload-posts', 'ownerId' => $file->authorId, 'viewerId' => OW::getUser()->getId());
         try {
             OW::getEventManager()->getInstance()->call('privacy_check_permission', $eventParams);
         } catch (RedirectException $ex) {
             $allow_comments = false;
         }
     }
     $cmpParams = new BASE_CommentsParams('spdownload', 'spdownload-post');
     $cmpParams->setEntityId($file->getId())->setOwnerId($file->authorId)->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_BOTTOM_FORM_WITH_FULL_LIST)->setAddComment($allow_comments);
     $this->addComponent('comments', new BASE_CMP_Comments($cmpParams));
     $arraylabel = array("filename" => OW::getLanguage()->text('spdownload', 'label_file_name'), "filesize" => OW::getLanguage()->text('spdownload', 'label_file_size'), "filetype" => OW::getLanguage()->text('spdownload', 'label_file_type'), "filedown" => OW::getLanguage()->text('spdownload', 'label_file_download'));
     $url = OW::getPluginManager()->getPlugin('spdownload')->getUserFilesUrl();
     $nameImage = 'icon_large_' . $file->id . '.png';
     $file->icon = $url . $nameImage;
     $CategoryIdList = SPDOWNLOAD_BOL_FileCategoryService::getInstance()->getCategoryId($params['fileId']);
     $arrayCategory = array();
     foreach ($CategoryIdList as $key => $value) {
         $categories = SPDOWNLOAD_BOL_CategoryDao::getInstance()->findById($value->categoryId);
         $arrayCategory[$value->categoryId] = $categories->name;
     }
     $this->assign('arrayCategory', $arrayCategory);
     $this->assign('file', $file);
     $this->assign('var', $file->id);
     $this->assign('filevernew', $filevernew[0]);
     $this->assign('fileverold', $fileverold);
     $this->assign('arraylabel', $arraylabel);
 }
示例#5
0
 public function index($params)
 {
     $filevernew = array();
     $file = array();
     $flag = false;
     $this->setPageTitle(OW::getLanguage()->text('spdownload', 'index_upload_title'));
     $this->setPageHeading(OW::getLanguage()->text('spdownload', 'index_upload_heading'));
     $arrayCheckCategory = array();
     if (!empty($params) && isset($params['fileId'])) {
         if (!stripos($params['fileId'], "-")) {
             throw new Redirect404Exception();
         }
         $check = $params['fileId'];
         $params['fileId'] = substr($params['fileId'], 0, stripos($params['fileId'], "-"));
         $file = SPDOWNLOAD_BOL_FileService::getInstance()->getFileId($params['fileId']);
         if ($file->id . '-' . $file->slug != $check) {
             throw new Redirect404Exception();
         }
         $CategoryIdList = SPDOWNLOAD_BOL_FileCategoryService::getInstance()->getCategoryId($params['fileId']);
         foreach ($CategoryIdList as $key => $value) {
             array_push($arrayCheckCategory, $value->categoryId);
         }
         $flag = true;
         $file = SPDOWNLOAD_BOL_FileService::getInstance()->getFileId($params['fileId']);
         if ($file === NULL) {
             throw new Redirect404Exception();
         }
         $filevernew = SPDOWNLOAD_BOL_VersionService::getInstance()->getFileVerNew($params['fileId']);
         $url = OW::getPluginManager()->getPlugin('spdownload')->getUserFilesUrl();
         $file->icon = $url . 'icon_small_' . $params['fileId'] . '.png';
         $thumbnails = SPDOWNLOAD_BOL_FileService::getInstance()->getThumbnailList($params['fileId']);
         foreach ($thumbnails as $key => $value) {
             $value->image = $url . $value->fileId . '_thumb_small_' . $value->uri . '.jpg';
         }
         $this->assign('file', $file);
         $this->assign('thumbnails', $thumbnails);
     }
     $form = new Form('upload_form');
     $form->setEnctype(Form::ENCTYPE_MULTYPART_FORMDATA);
     $cmpCategories = new SPDOWNLOAD_CMP_Category(false, $arrayCheckCategory);
     $this->addComponent('cmpCategories', $cmpCategories);
     $fieldName = new TextField('upname');
     $fieldName->setLabel($this->text('spdownload', 'form_label_name_up'));
     $fieldName->setRequired();
     if (!empty($params) && isset($params['fileId'])) {
         $fieldName->setValue($file->name);
     }
     $form->addElement($fieldName);
     $fieldSlug = new TextField('upslug');
     $fieldSlug->setLabel($this->text('spdownload', 'form_label_slug_up'));
     $fieldSlug->setRequired();
     if (!empty($params) && isset($params['fileId'])) {
         $fieldSlug->setValue($file->slug);
     }
     $form->addElement($fieldSlug);
     $fieldFile = new FileField('upfile');
     $fieldFile->setLabel($this->text('spdownload', 'form_label_file_up'));
     $form->addElement($fieldFile);
     $fieldIcon = new FileField('upicon');
     $fieldIcon->setLabel($this->text('spdownload', 'form_label_icon_up'));
     $form->addElement($fieldIcon);
     $fieldThumb = new MultiFileField('upthumb', 5);
     $fieldThumb->setLabel($this->text('spdownload', 'form_label_thumb_up'));
     $form->addElement($fieldThumb);
     $fieldDescription = new Textarea('updescription');
     $fieldDescription->setLabel($this->text('spdownload', 'form_label_description_up'));
     if (!empty($params) && isset($params['fileId'])) {
         $fieldDescription->setValue($file->description);
     }
     $form->addElement($fieldDescription);
     $fieldCategory = new CheckboxGroup('ct');
     $form->addElement($fieldCategory);
     $submit = new Submit('upload');
     $submit->setValue($this->text('spdownload', 'form_label_submit_up'));
     $form->addElement($submit);
     $this->addForm($form);
     $this->assign('flag', $flag);
     if (OW::getRequest()->isPost()) {
         if ($form->isValid($_POST)) {
             if (!empty($params) && isset($params['fileId'])) {
                 if (!empty($_POST['ct'])) {
                     $arrayAdd = array_diff($_POST['ct'], $arrayCheckCategory);
                     $arrayDelete = array_diff($arrayCheckCategory, $_POST['ct']);
                     foreach ($arrayDelete as $key => $value) {
                         SPDOWNLOAD_BOL_FileCategoryService::getInstance()->deleteId($params['fileId'], $value);
                     }
                     foreach ($arrayAdd as $key => $value) {
                         SPDOWNLOAD_BOL_FileCategoryService::getInstance()->addFileCategory($params['fileId'], $value);
                     }
                 } else {
                     SPDOWNLOAD_BOL_FileCategoryService::getInstance()->deleteId($params['fileId'], null);
                 }
             }
             $arrayFile = array();
             $arrayFile['id'] = null;
             if (!empty($params) && isset($params['fileId'])) {
                 $arrayFile['id'] = $params['fileId'];
             }
             $arrayFile['name'] = $_POST['upname'];
             $arrayFile['description'] = $_POST['updescription'];
             $arrayFile['slug'] = $_POST['upslug'];
             $arrayFile['authorId'] = OW::getUser()->getId();
             $arrayFile['addedTime'] = time();
             SPDOWNLOAD_BOL_FileService::getInstance()->addFile($arrayFile);
             if (isset($arrayFile['id']) && !empty($arrayFile['id'])) {
             } else {
                 $fileNew = SPDOWNLOAD_BOL_FileService::getInstance()->getIdNew($arrayFile);
                 $arrayFile['id'] = $fileNew[0]->id;
             }
             if (empty($params) && !isset($params['fileId'])) {
                 if (isset($_POST['ct']) && !empty($_POST['ct'])) {
                     foreach ($_POST['ct'] as $key => $value) {
                         SPDOWNLOAD_BOL_FileCategoryService::getInstance()->addFileCategory($arrayFile['id'], $value);
                     }
                 }
             }
             $arrayInputFile = array();
             $arrayInputFile['size'] = $_FILES['upfile']['size'];
             $arrayInputFile['name'] = $_FILES['upfile']['name'];
             $arrayInputFile['type'] = $_FILES['upfile']['type'];
             $arrayInputFile['tmp_name'] = $_FILES['upfile']['tmp_name'];
             $arrayInputFile['error'] = $_FILES['upfile']['error'];
             $arrayInputFile['addedTime'] = $arrayFile['addedTime'];
             $arrayInputFile['fileId'] = $arrayFile['id'];
             $path = SPDOWNLOAD_BOL_FileService::getInstance()->getFilePath();
             if ($arrayInputFile['error'] == 0) {
                 SPDOWNLOAD_BOL_VersionService::getInstance()->addVersion($arrayInputFile);
                 $verNew = SPDOWNLOAD_BOL_VersionService::getInstance()->getIdVer($arrayInputFile);
                 $arrayInputFile['id'] = $verNew[0]->id;
                 SPDOWNLOAD_BOL_FileService::getInstance()->move_file($arrayInputFile['tmp_name'], $path, $arrayInputFile['id']);
             }
             if ($_FILES['upicon']['error'] == 0 && !empty($_FILES['upicon']['name'])) {
                 SPDOWNLOAD_BOL_FileService::getInstance()->copy_resize_image($_FILES['upicon']['tmp_name'], 'icon_small', $arrayFile['id'], 'png', 48, 48);
                 SPDOWNLOAD_BOL_FileService::getInstance()->copy_resize_image($_FILES['upicon']['tmp_name'], 'icon_large', $arrayFile['id'], 'png', 128, 128);
             }
             foreach ($_FILES['upthumb']['tmp_name'] as $key => $value) {
                 if ($_FILES['upthumb']['error'][$key] == 0 && !empty($_FILES['upthumb']['name'][$key])) {
                     SPDOWNLOAD_BOL_FileThumbService::getInstance()->addThumb($arrayFile['id'], $key);
                     SPDOWNLOAD_BOL_FileService::getInstance()->copy_resize_image($_FILES['upthumb']['tmp_name'][$key], $arrayFile['id'] . '_thumb_small', $key, 'jpg', 360, 180);
                     SPDOWNLOAD_BOL_FileService::getInstance()->copy_resize_image($_FILES['upthumb']['tmp_name'][$key], $arrayFile['id'] . '_thumb_large', $key, 'jpg', 720, 360);
                 }
             }
         }
         $this->redirect(OW::getRouter()->urlForRoute('spdownload.up_myfile', array('userId' => OW::getUser()->getId())));
     }
 }