clipbucket/upload/ajax/home.php

121 lines
3 KiB
PHP
Raw Normal View History

2016-03-14 05:27:34 -07:00
<?php
/**
* File: Home Ajax
* Description: ClipBucket home page will now be Ajax based to imporve page loading
* and to enhance user experience. This file will handle all ajax requests
* for ClipBucket's home page
* @since: 14th March, 2016, ClipBucket 2.8.1
* @author: Saqib Razzaq
* @modified: 14th March, 2016
*/
require '../includes/config.inc.php';
2016-03-17 17:20:58 +05:00
$params = array();
2016-03-14 05:27:34 -07:00
if (isset($_POST['load_type'])) {
$load_type = $_POST['load_type'];
if (isset($_POST['load_mode'])) {
$load_mode = $_POST['load_mode'];
if ($load_mode == 'featured') {
$params['featured'] = "yes";
}
if ($load_mode == 'recent') {
$params['order'] = 'date_added DESC';
} else {
$params['order'] = 'views';
}
2016-03-14 05:27:34 -07:00
}
if (isset($_POST['load_limit'])) {
$load_limit = $_POST['load_limit'];
} else {
$load_limit = "6";
2016-03-14 05:27:34 -07:00
}
if (isset($_POST['load_hit'])) {
$cur_load_hit = $_POST['load_hit'];
$start = $load_limit * $cur_load_hit - $load_limit;
} else {
2016-03-18 18:17:10 +05:00
$start = "0";
2016-03-14 05:27:34 -07:00
}
$params['limit'] = "$start,$load_limit";
2016-04-05 20:08:43 +05:00
if ($cur_load_hit == 1) {
$arr = array();
$params['count_only'] = true;
$shown = $load_limit * ($cur_load_hit - 1);
$videos = get_videos($params);
$vcount = $videos - $shown;
if ($vcount < 1) {
$arr['more_vids'] = "none";
2016-04-05 20:08:43 +05:00
#echo $arr;
#return false;
} else {
$arr['more_vids'] = $vcount;
2016-04-05 20:08:43 +05:00
#echo $arr;
#return true;
}
}
2016-03-14 05:27:34 -07:00
switch ($load_type) {
case 'video':
2016-04-05 20:08:43 +05:00
$total_vids = get_videos($params);
$params['count_only'] = false;
2016-03-14 05:27:34 -07:00
$data = get_videos($params);
break;
case 'users':
$data = get_users($params);
break;
case 'photos':
$data = get_photos($params);
break;
case 'collections':
$data = get_collections($params);
break;
default:
$data = get_videos($params);
break;
}
2016-03-17 17:20:58 +05:00
#pr($params,true);
2016-03-14 05:27:34 -07:00
if (is_array($data)) {
2016-03-17 17:20:58 +05:00
if (count($data) < 1) {
$msg = array();
$msg['notice'] = "You've reached end of list";
#echo json_encode($msg);
return false;
}
2016-03-14 05:27:34 -07:00
$json_string['loadhit'] = $cur_load_hit + 1;
$json_string['array_meta'] = $data;
2016-03-17 17:20:58 +05:00
if ($load_mode == 'recent') {
$display_type = 'ajaxHome';
} else {
$display_type = 'featuredHome';
}
$quicklists = $_COOKIE['fast_qlist'];
$clean_cookies = str_replace(array("[","]"), "", $quicklists);
$clean_cookies = explode(",", $clean_cookies);
$clean_cookies = array_filter($clean_cookies);
assign("qlist_vids", $clean_cookies);
2016-04-05 20:08:43 +05:00
$count = 0;
foreach ($data as $key => $video) {
2016-04-05 20:08:43 +05:00
if ($cur_load_hit == 1 && $count == 0) {
assign("total_vids", $total_vids);
} else {
assign("total_vids","");
}
assign("video",$video);
2016-03-17 17:20:58 +05:00
assign("display_type",$display_type);
Template('blocks/videos/video.html');
2016-04-05 20:08:43 +05:00
$count = $count + 1;
}
2016-03-14 05:27:34 -07:00
}
} else {
$msg = array();
$msg['error'] = "Invalid request made";
echo json_encode($msg);
}
?>