Skip to content

Commit

Permalink
Merge branch 'combined-storybox-json' into dev
Browse files Browse the repository at this point in the history
Conflicts:
	source.php
  • Loading branch information
nxvipin committed Dec 16, 2011
2 parents 69d4c52 + 97a9a54 commit 8d5e87f
Show file tree
Hide file tree
Showing 11 changed files with 228 additions and 192 deletions.
13 changes: 8 additions & 5 deletions css/storybox.less
Expand Up @@ -16,11 +16,14 @@ div.groupBox {
}

.more, .less {
display:block;
font-size:14px;
position: absolute;
right: 200px;
cursor: url('../pics/pointer.png') , auto;
display:block;
font-size:14px;
position: absolute;
right: 200px;
cursor: pointer;
&:hover {
text-decoration:underline;
}
}

.less {
Expand Down
4 changes: 2 additions & 2 deletions css/structure.less
Expand Up @@ -109,7 +109,7 @@ margin: 0;
height: 100px; /* min logo size */
position: relative;

#logo{
#logo1, #logo2{
background :@offWhite;
border-color: #D2D2D2;
border-right: 1px solid #DDDDDD;
Expand Down Expand Up @@ -201,7 +201,7 @@ z-index:-2;
position:relative;
top:40px; /* Height of bottom bar */

#logo{
#logo1, #logo2{
border-color: #D2D2D2;
background:#f5f5f5;
background: -webkit-gradient(linear, left top, left bottom, from(@gray1), to(white));
Expand Down
1 change: 1 addition & 0 deletions functions/default.settings.php
Expand Up @@ -29,4 +29,5 @@
$global_couch_user = ''; // <CouchDB Username>
$global_couch_password = ''; // <CouchDB Password>


?>
68 changes: 43 additions & 25 deletions functions/interface.php
Expand Up @@ -72,16 +72,6 @@ function getTagSearchJson($tag,$page)
return json_encode($json);
}

/**
* Helper Function. Returs an array(size $count) of the CID's of most popular videos
* @param integer $count The number of videos that should be returned.
* @return array Array of Popular Videos CID's.
*/
function getPopularVideoArray($count){
$sql="Select cn_id from content_video order by cn_views desc limit $count";
return resource2array(dbquery($sql));
}

/**
* Helper Function. Returs an array(size $count) of the CID's of featured videos
* @param integer $count The number of videos that should be returned.
Expand All @@ -105,27 +95,27 @@ function getTopRatedVideoArray($count)
}

/**
* Returs the JSON strings of the $count of $type ofStorybox Video content
* and their details.
* $type = featured | toprated | popular
* Helper Function. Returs an array(size $count) of the CID's of most popular videos
* @param integer $count The number of videos that should be returned.
* @return string Featured Videos JSON.
* @return array Array of Popular Videos CID's.
*/
function getStoryBoxJson($type,$count){
switch ($type) {
case "featured": $contentarray = getFeaturedVideoArray($count);
break;
case "popular": $contentarray = getPopularVideoArray($count);
break;
case "toprated": $contentarray = getTopRatedVideoArray($count);
break;
}
$json=array();
function getPopularVideoArray($count){
$sql="Select cn_id from content_video order by cn_views desc limit $count";
return resource2array(dbquery($sql));
}

/**
* Helper Function. Returns data for each CID in input array as an array
* @param array $contentarray An array of content ID's
* @return array Data for all CID's in input as an array
*/
function getStoryBoxDataArray($contentarray){
$vcount=count($contentarray);
$data = array();
for($i=0;$i<$vcount;$i++)
{
$obj=new video($contentarray[$i]);
array_push($json,array( 'cid'=>$obj->getContentId(),
array_push($data,array( 'cid'=>$obj->getContentId(),
'title'=>$obj->getTitle(),
'viewcount'=>$obj->getViewCount(),
'poster'=>$obj->getPoster(),
Expand All @@ -134,8 +124,36 @@ function getStoryBoxJson($type,$count){
'fullname'=>user::getFullNameS($obj->getUserId()),
'userpic'=>user::getUserPictureS($obj->getUserId())));
}
return $data;
}

/**
* Returs a combined JSON for all the story box sections
* Utilizes various helper functions
* @param integer $fcount The number of videos in featured section
* @param integer $tcount The number of videos in toprated section
* @param integer $pcount The number of videos in popular section
* @return string JSON string containing all Storybox data
*/
function getCombinedStoryBoxJson($fcount, $tcount, $pcount){
$featuredarray = getFeaturedVideoArray($fcount);

//Remove any featured array content from toprated
$topratedarray = getTopRatedVideoArray($tcount+$fcount);
$topratedarray = array_values(array_diff($topratedarray, $featuredarray));
array_splice($topratedarray,$tcount);

//Remove both of the above from popular
$populararray = getPopularVideoArray($pcount+$tcount+$fcount);
$populararray = array_values(array_diff($populararray,array_merge($featuredarray, $topratedarray)));
array_splice($populararray,$pcount);

$json = array( "featured" => getStoryBoxDataArray($featuredarray),
"toprated" => getStoryBoxDataArray($topratedarray),
"popular" => getStoryBoxDataArray($populararray));
return json_encode($json);
}

/**
* Returns liked/disliked videos of a user.
* @param integer $uid User ID
Expand Down
8 changes: 3 additions & 5 deletions index.php
Expand Up @@ -23,11 +23,9 @@
echo $piwik;
?>
<script type="text/javascript">
$(document).ready(function() {
P.updateStoryBox('Featured')
P.updateStoryBox('Popular')
P.updateStoryBox('Top Rated')
});
$(document).ready(function() {
P.updateStoryBox('homePage');
});
</script>

</body>
Expand Down
185 changes: 109 additions & 76 deletions js/functions.js
Expand Up @@ -188,6 +188,26 @@
Paathshaala.validate.video();
});
},
grayOut : function (option){
if(option) {
$("<div>")
.attr('id', 'darkenScreenObject')
.css({
'position': 'absolute',
'top': '0px',
'left': '0px',
backgroundColor: '#030303',
'opacity': '0.25',
'width': '100%',
'height': $(document).height(),
zIndex: 99
})
.appendTo("body");

} else {
$('div#darkenScreenObject').remove();
}
},
hashTag : function(elem) {
var data = $(elem).html(),
reg = /#(\w{1,})/g,
Expand All @@ -201,10 +221,10 @@
},
hideEditProfile : function() {
$('#editProfile').fadeOut("fast");
grayOut(false);
this.grayOut(false);
},
hideFeedback : function () {
grayOut(false);
this.grayOut(false);
$('div#feedback').hide();
},
imageError : function() {
Expand Down Expand Up @@ -276,11 +296,11 @@
});
},
showEditProfile: function () {
grayOut(true);
this.grayOut(true);
$('div#editProfile').load('editprofile.html').fadeIn("slow");
},
showFeedback : function() {
grayOut(true);
this.grayOut(true);
$('div#feedback').show()
$('div#feedback').load('feedback.html', function(){
$('div#feedback ul.links li').click(function() {
Expand Down Expand Up @@ -327,81 +347,91 @@
},
updateStoryBox : function (type) {
/*
type : Featured/ Top Rated / Popular
type : homePage / 'Liked videos' ...
All box layout updated with same code
New ui needed for upload video trigger
*/
var videoBox = function (myobj) {
if( myobj.fullname.length > 18 )
myobj.fullname = myobj.fullname.slice(0 ,15 ) + '...';
return Paathshaala.templates.box.supplant(myobj);
},
link,
title = $("<span>").addClass('groupTitle'),
more = $("<span>").addClass('more').html("Show more"),
less = $("<span>").addClass('less').html("Show less");
title = title.html(type);
var more = $("<span>").addClass('more').html("Show more"),
less = $("<span>").addClass('less').html("Show less"),
complete = function(){
$('img.metaImage').error(function(){
$(this).attr('src','pics/default.png');
});
$('img.thumbnail').error(function(){
$(this).attr('src','pics/error.png');
});

$('span.more').click(function(){
$(this).hide();
$(this).parent().find('.Hidden').slideDown('fast');
$(this).parent().find('.less').fadeIn();
});
$('span.less').click(function(){
$(this).parent().find('.Hidden').slideUp('fast');
$(this).parent().find('.more').fadeIn();
$(this).hide();
});
},
videoBox = function (myobj) {
if( myobj.fullname.length > 18 )
myobj.fullname = myobj.fullname.slice(0 ,15 ) + '...';
return Paathshaala.templates.box.supplant(myobj);
},
groupBox = function(title, json) {
try {
// throw exception if json is invalid
if ($.isEmptyObject(json) )
throw "Empty JSON";
title = $("<span>").addClass('groupTitle').html(title);
var i,
groupBox = $("<div>").addClass('groupBox'),
groupBox2 = $("<div>").addClass('Hidden').addClass('groupBox');
if (json.length === 4 ) {
for (i =0; i <4 ; i +=1)
groupBox = groupBox.append(videoBox(json[i]));
$('div#container').append(title).append(groupBox);
} else { /* All multi boxes handled in same way if more than 4 */
for (i =0; i <4 ; i +=1)
groupBox = groupBox.append(videoBox(json[i]));
for (i =4; i < json.length ; i +=1)
groupBox2 = groupBox2.append(videoBox(json[i]));
$('div#container').append($("<div>").append(title , groupBox , more , groupBox2 , less));
}
} catch(e) {
// handle invalid json case
if (e === "Empty JSON")
console.log("Empty JSON recived from server");
} finally {
// i wonder what to do here.
}
};

switch (type) {
case 'Featured' :
link = 'json/featured.json.php';
break;
case 'Top Rated' :
link = 'json/toprated.json.php';
break;
case 'Popular':
link = 'json/popular.json.php';
case 'homePage':
$.getJSON( 'json/homeStorybox.json.php' , function(json){
groupBox('Featured', json.featured);
groupBox('Popular', json.popular);
groupBox('Top Rated', json.toprated);
}).complete(function(){ complete(); });
break;
case 'Liked videos':
link = 'json/uservideolikes.json.php';
$.getJSON( 'json/uservideolikes.json.php' , function(json){
groupBox('Liked videos', json);
}).complete(function(){ complete(); });
break;
case 'Disliked videos':
link = 'json/uservideodislikes.json.php';
$.getJSON( 'json/uservideodislikes.json.php' ,function(json){
groupBox('Disliked videos', json);
}).complete(function(){ complete(); });
break;
case 'My Uploads':
link = 'json/uservideouploads.json.php';
$.getJSON( 'json/uservideouploads.json.php' , function(json){
groupBox('My Uploads', json);
}).complete(function(){ complete(); });
break;
}

$.getJSON( link , function(json) {
if (json.length !== 0 ) {
var i,
groupBox = $("<div>").addClass('groupBox'),
groupBox2 = $("<div>").addClass('Hidden').addClass('groupBox');
if (json.length === 4 ) {
for (i =0; i <4 ; i +=1)
groupBox = groupBox.append(videoBox(json[i]));
$('div#container').append(title).append(groupBox);
} else { /* All multi boxes handled in same way if more than 4 */
for (i =0; i <4 ; i +=1)
groupBox = groupBox.append(videoBox(json[i]));
for (i =4; i < json.length ; i +=1)
groupBox2 = groupBox2.append(videoBox(json[i]));
$('div#container').append($("<div>").append(title , groupBox , more , groupBox2 , less));
}
} else {
$('div#container').append(title).append(groupBox);
}
}).complete(function(){

$('img.metaImage').error(function(){
$(this).attr('src','pics/default.png');
});
$('img.thumbnail').error(function(){
$(this).attr('src','pics/error.png');
});

$('span.more').click(function(){
$(this).hide();
$(this).parent().find('.Hidden').slideDown('fast');
$(this).parent().find('.less').fadeIn();
});
$('span.less').click(function(){
$(this).parent().find('.Hidden').slideUp('fast');
$(this).parent().find('.more').fadeIn();
$(this).hide();
});

});
}
};

Expand Down Expand Up @@ -650,15 +680,18 @@

/* ! Paathshaala */

function grayOut(vis,options){var options=options||{},zindex=options.zindex||99,opacity=options.opacity||20,opaque=(opacity/80),bgcolor=options.bgcolor||'#030303',dark=document.getElementById('darkenScreenObject');if(!dark){var tbody=document.getElementsByTagName("body")[0],tnode=document.createElement('div');tnode.style.position='fixed';tnode.style.top='0px';tnode.style.left='0px';tnode.style.overflow='hidden';tnode.style.display='none';tnode.id='darkenScreenObject';tbody.appendChild(tnode);dark=document.getElementById('darkenScreenObject');}
if(vis){if(document.body&&(document.body.scrollWidth||document.body.scrollHeight)){var pageWidth='100%';var pageHeight='2000px';}
dark.style.opacity=opaque;dark.style.MozOpacity=opaque;dark.style.filter='alpha(opacity='+opacity+')';dark.style.zIndex=zindex;dark.style.backgroundColor=bgcolor;dark.style.width=pageWidth;dark.style.height=pageHeight;dark.style.display='block';}else{dark.style.display='none';}}

$(document).ready(function(){
P.searchBox();
P.dashBoard();
P.imageError();
P.comments();
P.quirks();
P.validate.join();
});
if($.browser.msie) {
$("div#indexMesssage").remove();
$("<div>").attr('id','indexMesssage')
.html("Have a life, <a href='http://abetterbrowser.org/'><em>use a modern browser</em></a>. We dont support Internet Explorer.")
.appendTo("#container");
} else {
P.searchBox();
P.dashBoard();
P.imageError();
P.comments();
P.quirks();
P.validate.join();
}
});

0 comments on commit 8d5e87f

Please sign in to comment.