Exemplo n.º 1
0
 public function uninstall()
 {
     $this->drop_tables();
     ConfigManager::delete('download', 'config');
     CacheManager::invalidate('module', 'download');
     DownloadService::get_keywords_manager()->delete_module_relations();
 }
 public function execute(HTTPRequestCustom $request)
 {
     AppContext::get_session()->csrf_get_protect();
     $this->get_downloadfile($request);
     $this->check_authorizations();
     DownloadService::delete('WHERE id=:id', array('id' => $this->downloadfile->get_id()));
     DownloadService::get_keywords_manager()->delete_relations($this->downloadfile->get_id());
     PersistenceContext::get_querier()->delete(DB_TABLE_EVENTS, 'WHERE module=:module AND id_in_module=:id', array('module' => 'download', 'id' => $this->downloadfile->get_id()));
     CommentsService::delete_comments_topic_module('download', $this->downloadfile->get_id());
     NotationService::delete_notes_id_in_module('download', $this->downloadfile->get_id());
     Feed::clear_cache('download');
     DownloadCache::invalidate();
     AppContext::get_response()->redirect($request->get_url_referrer() ? $request->get_url_referrer() : DownloadUrlBuilder::home(), StringVars::replace_vars(LangLoader::get_message('download.message.success.delete', 'common', 'download'), array('name' => $this->downloadfile->get_name())));
 }
 private function save()
 {
     $downloadfile = $this->get_downloadfile();
     $downloadfile->set_name($this->form->get_value('name'));
     $downloadfile->set_rewrited_name(Url::encode_rewrite($downloadfile->get_name()));
     $downloadfile->set_id_category($this->form->get_value('id_category')->get_raw_value());
     $downloadfile->set_url(new Url($this->form->get_value('url')));
     $downloadfile->set_contents($this->form->get_value('contents'));
     $downloadfile->set_short_contents($this->form->get_value('short_contents_enabled') ? $this->form->get_value('short_contents') : '');
     $downloadfile->set_picture(new Url($this->form->get_value('picture')));
     if ($this->config->is_author_displayed()) {
         $downloadfile->set_author_display_name($this->form->get_value('author_display_name') && $this->form->get_value('author_display_name') !== $downloadfile->get_author_user()->get_display_name() ? $this->form->get_value('author_display_name') : '');
     }
     $file_size = $status = 0;
     $file = new File($downloadfile->get_url()->rel());
     if ($file->exists()) {
         $file_size = $file->get_file_size();
     }
     if (empty($file_size)) {
         $file_headers = get_headers($downloadfile->get_url()->absolute(), true);
         if (is_array($file_headers)) {
             if (isset($file_headers['Content-Length'])) {
                 $file_size = $file_headers['Content-Length'];
             }
             if (preg_match('/^HTTP\\/[12]\\.[01] (\\d\\d\\d)/', $file_headers[0], $matches)) {
                 $status = (int) $matches[1];
             }
         }
     }
     $file_size = $status == 200 && empty($file_size) && $downloadfile->get_size() ? $downloadfile->get_size() : $file_size;
     $downloadfile->set_size($file_size);
     if ($this->get_downloadfile()->get_id() !== null && $downloadfile->get_number_downloads() > 0 && $this->form->get_value('reset_number_downloads')) {
         $downloadfile->set_number_downloads(0);
     }
     if ($this->is_contributor_member()) {
         $downloadfile->set_approbation_type(DownloadFile::NOT_APPROVAL);
         $downloadfile->clean_start_and_end_date();
     } else {
         $downloadfile->set_creation_date($this->form->get_value('creation_date'));
         $downloadfile->set_approbation_type($this->form->get_value('approbation_type')->get_raw_value());
         if ($downloadfile->get_approbation_type() == DownloadFile::APPROVAL_DATE) {
             $downloadfile->set_start_date($this->form->get_value('start_date'));
             if ($this->form->get_value('end_date_enable')) {
                 $downloadfile->set_end_date($this->form->get_value('end_date'));
             } else {
                 $downloadfile->clean_end_date();
             }
         } else {
             $downloadfile->clean_start_and_end_date();
         }
     }
     if ($this->is_new_downloadfile) {
         $id = DownloadService::add($downloadfile);
     } else {
         $downloadfile->set_updated_date(new Date());
         $id = $downloadfile->get_id();
         DownloadService::update($downloadfile);
     }
     $this->contribution_actions($downloadfile, $id);
     DownloadService::get_keywords_manager()->put_relations($id, $this->form->get_value('keywords'));
     Feed::clear_cache('download');
     DownloadCache::invalidate();
 }
Exemplo n.º 4
0
 public function get_keywords()
 {
     if ($this->keywords === null) {
         $this->keywords = DownloadService::get_keywords_manager()->get_keywords($this->id);
     }
     return $this->keywords;
 }
 private function get_keyword()
 {
     if ($this->keyword === null) {
         $rewrited_name = AppContext::get_request()->get_getstring('tag', '');
         if (!empty($rewrited_name)) {
             try {
                 $this->keyword = DownloadService::get_keywords_manager()->get_keyword('WHERE rewrited_name=:rewrited_name', array('rewrited_name' => $rewrited_name));
             } catch (RowNotFoundException $e) {
                 $error_controller = PHPBoostErrors::unexisting_page();
                 DispatchManager::redirect($error_controller);
             }
         } else {
             $error_controller = PHPBoostErrors::unexisting_page();
             DispatchManager::redirect($error_controller);
         }
     }
     return $this->keyword;
 }