public function initContent() { parent::initContent(); $user_id = null; if ($this->context->customer->isLogged() && Tools::getValue('extract') == false) { $user_id = $this->context->customer->id; $purchased_ebooks = PrestaEbooksCore::getUserEbooks($user_id, true); if (PrestaEbooksCore::isPurchased($purchased_ebooks, Tools::getValue('product_id'))) { $ebook_file = PrestaEbooksCore::getEbookPath(Tools::getValue('ebook_id'), Tools::getValue('product_id')); $file_path = dirname(__FILE__) . $ebook_file['file_path'] . $ebook_file['file_name']; if (file_exists($file_path)) { // TO DO : INCREMENT DOWNLOAD COUNT PrestaEbooksCore::iterateDownloads(Tools::getValue('ebook_id')); /* Set headers for download */ header('Content-Transfer-Encoding: binary'); header('Content-Length: ' . filesize($file_path)); header('Content-Disposition: attachment; filename="' . $ebook_file['file_name'] . '"'); readfile($file_path); } } } if (Tools::getValue('extract') == true) { $ebook_file = PrestaEbooksCore::getEbookPath(Tools::getValue('ebook_id'), Tools::getValue('product_id'), true); $file_path = dirname(__FILE__) . $ebook_file['extract_file_path'] . $ebook_file['extract_file_name']; if (file_exists($file_path)) { // TO DO : INCREMENT DOWNLOAD COUNT PrestaEbooksCore::iterateDownloads(Tools::getValue('ebook_id'), true); /* Set headers for download */ header('Content-Transfer-Encoding: binary'); header('Content-Length: ' . filesize($file_path)); header('Content-Disposition: attachment; filename="' . $ebook_file['extract_file_name'] . '"'); readfile($file_path); } } exit; }
public static function deleteFileByType($product_id, $file_type) { $product_id = pSQL($product_id); $file_type = pSQL($file_type); // check if file exists in database $file = PrestaEbooksCore::findByType($product_id, $file_type); if (!empty($file)) { return false; } if (Db::getInstance()->delete('prestaebooks', 'product_id = "' . $product_id . '" and ebook_type = "' . $file_type . '"')) { return true; } return false; }
<?php require_once dirname(__FILE__) . '../../../../../config/config.inc.php'; require_once dirname(__FILE__) . '../../../../../init.php'; include_once dirname(__FILE__) . '/../../classes/PrestaEbooksCore.php'; $product_id = (int) Tools::getValue('product_id'); $file_type = (string) Tools::getValue('file_type'); $upload_dir = '/../../ebook_files/full/'; $upload_path = dirname(__FILE__) . $upload_dir; // check if file has been purchased $sales = PrestaEbooksCore::getBookSales($product_id); if ($sales == 0) { if (PrestaEbooksCore::deleteFileByType($product_id, $file_type)) { exit; } else { die('FILE DELETE ERROR'); } } else { die('FILE HAS BEEN PURCHASED'); }
die('file is not a valid mobi file'); } } } else { die('impossible to move file to server'); } } else { die('mime_type not allowed : ' . $mime_type); } } // SAVE FILE INFOS IN DATABASE VIA CORE CLASS $file_infos = array('ebook_lang' => $ebook_lang, 'ebook_author' => $ebook_author, 'ebook_translator' => $ebook_translator, 'ebook_isbn' => $ebook_isbn, 'ebook_type' => $file_type, 'ebook_active' => $ebook_active); if (isset($ebook_toc)) { $file_infos['ebook_toc'] = $ebook_toc; } if (isset($new_filename)) { $file_infos['file_path'] = $new_path; $file_infos['file_name'] = $new_filename; $file_infos['file_size'] = filesize($full_path); } if (isset($extract_new_filename)) { $file_infos['extract_file_path'] = $extract_new_path; $file_infos['extract_file_name'] = $extract_new_filename; $file_infos['extract_file_size'] = $extract_file_size; } $created = PrestaEbooksCore::createFile($product_id, $file_infos); if ($created === true) { exit; } else { die('created failed'); }
public static function getEbookDownloadLinks($product_id) { $ebooks_links = PrestaEbooksCore::getAvailableEbooks($product_id); return $ebooks_links; }
public function getProductFiles($product_id) { $files = array(); foreach ($this->file_types as $type) { $files[$type] = PrestaEbooksCore::findByType($product_id, $type); } return $files; }