File: /home/assibfaf/assignmentghostwriter.com/prox-papers.php
<?php
/**
* @package Proxim
* @author Davison Pro <davisonpro.coder@gmail.com | https://davisonpro.dev>
* @copyright 2019 Proxim
* @version 1.0.0
* @since File available since Release 1.0.0
*/
use Proxim\Configuration;
use Proxim\Database\DbQuery;
use Proxim\Module\Module;
use Proxim\Pager;
use Proxim\Tools;
use Proxim\Util\ArrayUtils;
use Proxim\Util\DateUtils;
use Proxim\Util\StringUtils;
use Proxim\Validate;
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'prox-bootstrap.php';
$smarty = $app->container->smarty;
$params = Tools::getAllValues();
$do = ArrayUtils::get($params, 'do', false);
if(!Module::getInstanceByName('prepapers')) {
$app->setTemplate('404');
$app->display();
}
if(!Configuration::get('SELL_PREWRITTEN_PAPERS')) {
$app->setTemplate('404');
$app->display();
}
$app->unregisterStylesheet('app-css');
$app->unregisterJavascript('app-js');
$app->registerStylesheet('bootstrap-css', 'https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css', ['media' => 'all', 'server' => 'remote', 'priority' => 1]);
$app->registerStylesheet('fontello-css', '/prox-modules/prepapers/css/fontello.css', ['media' => 'all']);
$app->registerStylesheet('prepapers-css', '/prox-modules/prepapers/css/main.css', ['media' => 'all']);
$app->registerJavascript('bootstrap-js', 'https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js', ['media' => 'all', 'server' => 'remote', 'priority' => 1]);
$page_title = Configuration::get('PREWRITTEN_PAPERS_TITLE', PROX_SITE_ID, 'Get Inspired by Our Essay Database');
$page_description = Configuration::get('PREWRITTEN_PAPERS_DESCRIPTION', PROX_SITE_ID, 'Enjoy our daily updated collection of over 500k samples, extensive book reviews, chapter summaries and plot overviews');
$smarty->assign([
'site_name' => Configuration::get('SITE_NAME'),
'page_title' => $page_title,
'page_description' => $page_description,
'PREWRITTEN_PAPERS_HEADER_COLOR' => Configuration::get('PREWRITTEN_PAPERS_HEADER_COLOR') ? Configuration::get('PREWRITTEN_PAPERS_HEADER_COLOR') : '#ffffff',
'PREWRITTEN_PAPERS_NAVLINK_COLOR' => Configuration::get('PREWRITTEN_PAPERS_NAVLINK_COLOR') ? Configuration::get('PREWRITTEN_PAPERS_NAVLINK_COLOR') : '#102341',
'PREWRITTEN_PAPERS_BUTTON_PRIMARY' => Configuration::get('PREWRITTEN_PAPERS_BUTTON_PRIMARY') ? Configuration::get('PREWRITTEN_PAPERS_BUTTON_PRIMARY') : '#e14652',
'PREWRITTEN_PAPERS_BUTTON_SECONDARY' => Configuration::get('PREWRITTEN_PAPERS_BUTTON_SECONDARY') ? Configuration::get('PREWRITTEN_PAPERS_BUTTON_SECONDARY') : '#f59f1b',
'site_logo' => Configuration::get('SITE_DOMAIN', PROX_ADMIN_SITE_ID) . '/uploads/' . Configuration::get('SITE_EMAIL_LOGO')
]);
switch( $do ) {
case 'listPapers':
$app->setVars([
'page' => [
'title' => $page_title . ' | ' . Configuration::get('SITE_NAME'),
'description' => $page_description
]
]);
$search_query = ArrayUtils::get($params, 'q', false);
$academicLevelId = ArrayUtils::get($params, 'academicLevel', false);
$disciplineId = ArrayUtils::get($params, 'discipline', false);
$paperTypeId = ArrayUtils::get($params, 'paperType', false);
$is_search = false;
$selected_page = ArrayUtils::has($params, 'page') ? (int) ArrayUtils::get($params, 'page') : 1;
$sql = new DbQuery();
$sql->select('p.prepaper_id');
$sql->from('prepaper', 'p');
if($academicLevelId) $sql->where('p.academic_level_id = ' . (int) $academicLevelId);
if($disciplineId) $sql->where('p.topic_category_id = ' . (int) $disciplineId);
if($paperTypeId) $sql->where('p.paper_type_id = ' . (int) $paperTypeId);
if ($search_query) {
$is_search = true;
$sql->where('
p.title LIKE \'%' . pSQL($search_query) . '%\' OR
p.question LIKE \'%' . pSQL($search_query) . '%\'
');
}
$sql->orderBy('p.prepaper_id DESC');
$result = Db::getInstance(PROX_USE_SQL_SLAVE)->executeS($sql);
$total_prepapers = count($result);
$prepapers = array();
if( $total_prepapers > 0) {
$params['total_items'] = $total_prepapers;
$params['selected_page'] = $selected_page;
$params['items_per_page'] = Configuration::get('MAX_RESULTS', null, 10)*2;
$params['url'] = $app->base_uri ."/papers?page=%s";
$pager = new Pager( $params );
$limit_query = $pager->getLimitSql();
$result = Db::getInstance(PROX_USE_SQL_SLAVE)->executeS($sql . $limit_query);
$prepaperPresenter = new PrePaperPresenter();
foreach( $result as $prepaper ) {
$prepaper = new PrePaper($prepaper['prepaper_id']);
if( Validate::isLoadedObject($prepaper) ) {
$prepapers[] = $prepaperPresenter->present( $prepaper );
}
}
$smarty->assign([
'pager' => $pager->getPager()
]);
}
$smarty->assign([
'is_search' => $is_search,
'search_query' => $search_query,
'prepapers' => $prepapers,
'total_prepapers' => $total_prepapers
]);
$app->setTemplate('prepapers/list');
$app->display();
case 'showPaper':
$slug = ArrayUtils::get($params, 'slug', false);
$cookie = $app->container->cookie;
$user = $app->container->user;
$prepaper = new PrePaper();
$prepaper = $prepaper->getBySlug( $slug );
if(!Validate::isLoadedObject($prepaper)) {
$app->setTemplate('404');
$app->display();
}
$app->setVars([
'page' => [
'title' => $prepaper->title . ' | ' . Configuration::get('SITE_NAME'),
'description' => $page_description
],
]);
if(!isset($cookie->viewed_prepapers)) {
$cookie->viewed_prepapers = null;
}
$viewed_prepapers = $cookie->viewed_prepapers;
// get prepaper ids
$viewed_prepapers = explode(',', $viewed_prepapers);
if(empty($viewed_prepapers)) {
$viewed_prepapers = array();
}
// check if prepaper is in array
if(!in_array($prepaper->id, $viewed_prepapers)) {
$viewed_prepapers[] = $prepaper->id;
$prepaper->views = $prepaper->views+1;
$prepaper->update();
}
$cookie->viewed_prepapers = implode(",", $viewed_prepapers);
$prepaperPresenter = new PrePaperPresenter();
$smarty->assign([
'prepaper' => $prepaperPresenter->present( $prepaper )
]);
$app->setTemplate('prepapers/paper');
$app->display();
break;
case 'download':
if(!$user->isLogged()) {
$app->setTemplate('404');
$app->display();
}
$fileId = ArrayUtils::get($params, 'file_id', false);
$file = new PrePaperFile( (int) $fileId );
if (!Validate::isLoadedObject($file)) {
$app->setTemplate('404');
$app->display();
}
$hasPurchased = PrePaper::hasPurchased($file->prepaper_id, $user->id);
if (!$hasPurchased) {
$app->setTemplate('404');
$app->display();
}
$file_path = PROX_DIR_UPLOADS . $file->source;
$downloadFile = @fopen($file_path,"rb");
if (!$downloadFile) {
$app->setTemplate('404');
$app->display();
}
$downloadFileName = $file->name;
if($file->extension && !StringUtils::endsWith($downloadFileName, $file->extension)) {
$downloadFileName .= "." . $file->extension;
}
$downloadFileSize = filesize($file_path);
$mime_types = array(
"htm" => "text/html",
"exe" => "application/octet-stream",
"zip" => "application/zip",
"doc" => "application/msword",
"docx" => "application/msword",
"jpg" => "image/jpg",
"php" => "text/plain",
"xls" => "application/vnd.ms-excel",
"ppt" => "application/vnd.ms-powerpoint",
"gif" => "image/gif",
"pdf" => "application/pdf",
"txt" => "text/plain",
"html"=> "text/html",
"png" => "image/png",
"jpeg"=> "image/jpg",
"js" => "application/x-javascript"
);
if( array_key_exists($file->extension, $mime_types) ) {
$mime_type = $mime_types[$file->extension];
} else {
$mime_type = "application/force-download";
}
@ob_end_clean();
if( ini_get('zlib.output_compression') ) {
ini_set('zlib.output_compression', 'Off');
}
header('Pragma: public');
header("Expires: 0");
header('Connection: Keep-Alive');
header("Cache-Control: public, must-revalidate, post-check=0, pre-check=0");
header('Content-Type: ' . $mime_type);
header('Content-Disposition: attachment; filename="'.$downloadFileName.'"');
header("Content-Transfer-Encoding: binary");
header('Accept-Ranges: bytes');
if( isset($_SERVER['HTTP_RANGE']) ) {
list($a, $range) = explode("=",$_SERVER['HTTP_RANGE'],2);
list($range) = explode(",",$range,2);
list($range, $range_end) = explode("-", $range);
$range=intval($range);
if(!$range_end) {
$range_end=$size-1;
} else {
$range_end=intval($range_end);
}
$new_length = $range_end-$range+1;
header("HTTP/1.1 206 Partial Content");
header("Content-Length: $new_length");
header("Content-Range: bytes $range-$range_end/$downloadFileSize");
} else {
$new_length = $downloadFileSize;
header("Content-Length: " . $downloadFileSize);
}
$chunksize = 1*(1024*1024);
$bytes_sent = 0;
if(isset($_SERVER['HTTP_RANGE'])) {
fseek($downloadFile, $range);
}
while(
!feof($downloadFile) &&
(!connection_aborted()) &&
($bytes_sent < $new_length)
) {
$buffer = fread($downloadFile, $chunksize);
echo($buffer);
flush();
$bytes_sent += strlen($buffer);
}
@fclose($downloadFile);
exit;
break;
case 'sitemap':
header("Content-type: text/xml");
$sql = new DbQuery();
$sql->select('p.*');
$sql->from('prepaper', 'p');
$sql->orderBy('p.prepaper_id DESC');
$result = Db::getInstance(PROX_USE_SQL_SLAVE)->executeS($sql);
$total_prepapers = count($result);
$prepapers = array();
if($total_prepapers > 0) {
foreach( $result as $prepaper ) {
$prepapers[] = array(
'loc' => $app->base_uri . '/paper/' . $prepaper['slug'],
'lastmod' => DateUtils::convertToISOFormat($prepaper['date_upd']),
'priority' => PrePapers::PRIORITY,
'changefreq' => PrePapers::CHANGEFREQ
);
}
}
$smarty->assign([
'xls_url' => $app->base_uri . '/prox-modules/prepapers/sitemap.xsl',
'prepapers' => $prepapers
]);
$app->setTemplate('prepapers/sitemap');
$app->display();
break;
default:
$app->setTemplate('404');
$app->display();
break;
}