public static function hook(GWF_User $user, GWF_Download $dl) { $dlid = $dl->getID(); if ($dlid > 2) { return true; } $demo = $dlid == 2; if (false === ($row = BAIM_MC::generate($user, $demo))) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } $mime = $dl->getVar('dl_mime'); $path = $dl->getDownloadPath(); $temp_path = GWF_PATH . 'extra/temp/baim/' . $user->getVar('user_id') . '_' . $row->getToken(); if (!Common::isFile($path)) { return GWF_HTML::err('ERR_FILE_NOT_FOUND', htmlspecialchars($path)); } if (Common::isFile($temp_path)) { if (false === unlink($temp_path)) { return GWF_HTML::err('ERR_WRITE_FILE', array($temp_path)); } } if ($mime === 'application/zip') { if (false === copy($path, $temp_path)) { return GWF_HTML::err('ERR_WRITE_FILE', array($temp_path)); } $have_zip = true; } else { $have_zip = false; } $zip = new GWF_ZipArchive(); if (false === $zip->open($temp_path, GWF_ZipArchive::CREATE)) { return GWF_HTML::err('ERR_WRITE_FILE', array($temp_path)); } if ($have_zip === false) { $filename = $dl->getVar('dl_filename'); $zip->addFile($path, $filename); $dl->setCustomDownloadName($filename . '.zip'); } if (false === $zip->addFromString('B.AiM/key.dat', self::getIniContent($row))) { return GWF_HTML::error('BAIM', 'The download slot is not a zip archive!'); } $zip->addFromString('B.AiM/readme.txt', self::getReadmeContent($row)); $zip->addFromString('B.AiM/release_notes.txt', self::getReleaseNotes($row)); $zip->close(); $dl->setCustomDownloadPath($temp_path); return ''; }
public static function insertToken(Module_Download $module, GWF_Download $dl, $user, $token) { $expires = $dl->expires() ? GWF_Time::getDate(GWF_Date::LEN_SECOND, time() + $dl->getVar('dl_expire')) : ''; $row = new self(array('dlt_dlid' => $dl->getID(), 'dlt_uid' => $user === false ? 0 : $user->getID(), 'dlt_token' => $token, 'dlt_expires' => $expires)); if (false === $row->insert()) { return false; } return true; }
private function getForm(GWF_Download $dl) { $data = array(); $data['filename'] = array(GWF_Form::STRING, $dl->getVar('dl_filename'), $this->module->lang('th_dl_filename')); $data['group'] = array(GWF_Form::SELECT, GWF_GroupSelect::single('group', $dl->getVar('dl_gid')), $this->module->lang('th_dl_gid')); $data['level'] = array(GWF_Form::INT, $dl->getVar('dl_level'), $this->module->lang('th_dl_level')); if (GWF_User::isAdminS()) { $data['price'] = array(GWF_Form::FLOAT, $dl->getVar('dl_price'), $this->module->lang('th_dl_price')); } $data['expire'] = array(GWF_Form::STRING, GWF_Time::humanDuration($dl->getVar('dl_expire')), $this->module->lang('th_dl_expire'), $this->module->lang('tt_dl_expire')); $data['guest_view'] = array(GWF_Form::CHECKBOX, $dl->isOptionEnabled(GWF_Download::GUEST_VISIBLE), $this->module->lang('th_dl_guest_view'), $this->module->lang('tt_dl_guest_view')); $data['guest_down'] = array(GWF_Form::CHECKBOX, $dl->isOptionEnabled(GWF_Download::GUEST_DOWNLOAD), $this->module->lang('th_dl_guest_down'), $this->module->lang('tt_dl_guest_down')); $data['adult'] = array(GWF_Form::CHECKBOX, $dl->isOptionEnabled(GWF_Download::ADULT), $this->module->lang('th_adult')); $data['huname'] = array(GWF_Form::CHECKBOX, $dl->isOptionEnabled(GWF_Download::HIDE_UNAME), $this->module->lang('th_huname')); $data['enabled'] = array(GWF_Form::CHECKBOX, $dl->isEnabled(), $this->module->lang('th_enabled')); $data['descr'] = array(GWF_Form::MESSAGE, $dl->getVar('dl_descr'), $this->module->lang('th_dl_descr')); $data['buttons'] = array(GWF_Form::SUBMITS, array('edit' => $this->module->lang('btn_edit'), 'delete' => $this->module->lang('btn_delete'))); return new GWF_Form($this, $data); }
public function mayDownload($user, GWF_Download $download) { if ($user === false) { # Guest if (!$download->isEnabled()) { return $this->error('err_disabled'); } if ($download->isAdult()) { return $this->error('err_adult'); } if (!$download->isOptionEnabled(GWF_Download::GUEST_DOWNLOAD)) { return $this->error('err_guest'); } if (!$this->cfgAnonDown()) { return $this->error('err_guest'); } return false; } else { $user instanceof GWF_User; # Admin if ($user->isAdmin()) { return false; } if (!$download->isEnabled()) { return $this->error('err_disabled'); } if ($download->isAdult() && !$user->wantsAdult()) { return $this->error('err_adult'); } # Level if ($download->getVar('dl_level') > $user->getVar('user_level')) { return $this->error('err_level', $download->getVar('dl_level')); } # Group $gid = $download->getVar('dl_gid'); if (false === ($group = GWF_Group::getByID($gid))) { } elseif ($gid > 0 && !$user->isInGroupID($download->getVar('dl_gid'))) { return $this->error('err_group', $group->display('group_name')); } return false; } }
private function getTokenForm(GWF_Download $dl) { $data = array('name' => array(GWF_Form::SSTRING, $dl->getVar('dl_filename', ''), $this->module->lang('th_dl_filename')), 'token' => array(GWF_Form::STRING, '', $this->module->lang('th_token')), 'dl_token' => array(GWF_Form::SUBMIT, $this->module->lang('btn_download'))); return new GWF_Form($this, $data); }