Sfoglia il codice sorgente

#24 - Timeline.
1. Minor fixes and improvements.
2. "Timeline" slider to "Jump To" selector.
3. Tile layout update.

AntonLV 13 anni fa
parent
commit
1a4ecfdbc4

+ 17 - 1
modules/boonex/timeline/classes/BxTimelineDb.php

@@ -193,10 +193,15 @@ class BxTimelineDb extends BxDolModuleDb
 					$sWhereClause .= $this->_getFilterAddon($aParams['owner_id'], $aParams['filter']);
 
 				//--- Apply timeline
-		        if(isset($aParams['timeline'])) {            
+		        if(isset($aParams['timeline']) && !empty($aParams['timeline'])) {
+		        	/*
+		        	//TODO: Remove if old timeline slider is not used
 		            $iDays = (int)$aParams['timeline'];
 		            $iNowMorning = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
 		            $sWhereClause .= $this->prepare("AND `date`>=? ", ($iNowMorning - 86400 * $iDays));
+		            */
+		        	$iYear = (int)$aParams['timeline'];
+		        	$sWhereClause .= $this->prepare("AND `date`<=? ", mktime(23, 59, 59, 12, 31, $iYear));
 		        }
 
 		        //--- Apply modules or handlers filter
@@ -225,6 +230,11 @@ class BxTimelineDb extends BxDolModuleDb
 		
 							$aQueryParts = $oConnection->getConnectedContentAsSQLParts($this->_sPrefix . "events", 'owner_id', $aParams['owner_id']);
 							$sJoinClause .= ' ' . $aQueryParts['join'];
+
+							$iUserId = bx_get_logged_profile_id();
+							$sCommonPostPrefix = $this->_oConfig->getPrefix('common_post');
+
+							$sWhereClause .= "AND IF(SUBSTRING(`{$this->_sTable}`.`type`, 1, " . strlen($sCommonPostPrefix) . ") = '" . $sCommonPostPrefix . "', `{$this->_sTable}`.`object_id` <> " . $iUserId . ", 1)";
 							break;
 					}
 
@@ -251,6 +261,7 @@ class BxTimelineDb extends BxDolModuleDb
                 `{$this->_sTable}`.`content` AS `content`,
                 `{$this->_sTable}`.`comments` AS `comments`,
                 `{$this->_sTable}`.`date` AS `date`,
+                YEAR(FROM_UNIXTIME(`{$this->_sTable}`.`date`)) AS `year`,
                 DAYOFYEAR(FROM_UNIXTIME(`{$this->_sTable}`.`date`)) AS `day_date`,
                 DAYOFYEAR(NOW()) AS `day_now`,
                 (UNIX_TIMESTAMP() - `{$this->_sTable}`.`date`)/86400 AS `ago_days`
@@ -271,7 +282,12 @@ class BxTimelineDb extends BxDolModuleDb
         if(empty($aEvent) || !is_array($aEvent))
             return 0;
 
+		$iNowYear = date('Y', time());
+		return (int)$aEvent['year'] < $iNowYear ? (int)$aEvent['year'] : 0;
+        /*
+		//TODO: Remove if old timeline slider is not used
         return $aEvent['day_date'] == $aEvent['day_now'] ? (int)floor($aEvent['ago_days']) : (int)ceil($aEvent['ago_days']);
+        */
     }
 
 	public function savePhoto($iEventId, $iPhId, $sPhTitle, $sPhText)

+ 4 - 4
modules/boonex/timeline/classes/BxTimelineModule.php

@@ -130,9 +130,9 @@ class BxTimelineModule extends BxDolModule
         $this->_oConfig->setJsMode(true);
 
 		$aParams = $this->_prepareParamsGet();
-		list($sItems, $sLoadMore) = $this->_oTemplate->getPosts($aParams);
+		list($sItems, $sLoadMore, $sBack) = $this->_oTemplate->getPosts($aParams);
 
-		$this->_echoResultJson(array('items' => $sItems, 'load_more' => $sLoadMore));
+		$this->_echoResultJson(array('items' => $sItems, 'load_more' => $sLoadMore, 'back' => $sBack));
     }
 
     public function actionGetPostForm($sType)
@@ -610,7 +610,7 @@ class BxTimelineModule extends BxDolModule
     	$aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage();
     	$aParams['filter'] = !empty($sFilter) ? $sFilter : BX_TIMELINE_FILTER_ALL;
     	$aParams['modules'] = is_array($aModules) && !empty($aModules) ? $aModules : array();
-    	$aParams['timeline'] = (int)$iTimeline > 0 ? $iTimeline : $this->_oDb->getMaxDuration($aParams);
+    	$aParams['timeline'] = (int)$iTimeline > 0 ? $iTimeline : 0;
 
     	return $aParams;
     }
@@ -638,7 +638,7 @@ class BxTimelineModule extends BxDolModule
 		$aParams['modules'] = $aModules !== false ? bx_process_input($aModules, BX_DATA_TEXT) : array();
 
 		$iTimeline = bx_get('timeline');
-		$aParams['timeline'] = $iTimeline !== false ? bx_process_input($iTimeline, BX_DATA_INT) : $this->_oDb->getMaxDuration($aParams);
+		$aParams['timeline'] = $iTimeline !== false ? bx_process_input($iTimeline, BX_DATA_INT) : 0;
 
 		return $aParams;
     }

+ 59 - 6
modules/boonex/timeline/classes/BxTimelineTemplate.php

@@ -77,12 +77,16 @@ class BxTimelineTemplate extends BxDolModuleTemplate
 
     public function getViewBlock($aParams)
     {
-		list($sContent, $sLoadMore) = $this->getPosts($aParams);
+		list($sContent, $sLoadMore, $sBack) = $this->getPosts($aParams);
 
     	$this->getCssJs();
     	return $this->parseHtmlByName('view.html', array(
     		'style_prefix' => $this->_oConfig->getPrefix('style'),
+    		/*
+		    //TODO: Remove if old timeline slider is not used
             'timeline' => $this->getTimeline($aParams),
+            */
+    		'back' => $sBack,
             'content' => $sContent,
     		'load_more' =>  $sLoadMore,
             'js_content' => $this->getJsCode('view', array(
@@ -169,8 +173,12 @@ class BxTimelineTemplate extends BxDolModuleTemplate
             $sContent .= $sEvent;
         }
 
-        $sLoadMore = $this->getLoadMore($iStart, $iPerPage, $bNext, $iEvents > 0);
-        return array($sContent, $sLoadMore);
+        $iYearSel = (int)$aParams['timeline'];
+        $iYearMin = $this->_oDb->getMaxDuration($aParams);
+
+        $sBack = $this->getBack($iYearSel);
+        $sLoadMore = $this->getLoadMore($iStart, $iPerPage, $bNext, $iYearSel, $iYearMin, $iEvents > 0);
+        return array($sContent, $sLoadMore, $sBack);
     }
 
 	public function getEmpty($bVisible)
@@ -201,11 +209,49 @@ class BxTimelineTemplate extends BxDolModuleTemplate
         	'value' => $iTimeline
         ));
     }
+	public function getBack($iYearSel)
+	{
+		if($iYearSel == 0)
+			return '';
 
-	public function getLoadMore($iStart, $iPerPage, $bEnabled = true, $bVisible = true)
+		$sStylePrefix = $this->_oConfig->getPrefix('style');
+    	$sJsObject = $this->_oConfig->getJsObject('view');
+
+		$iYearNow = date('Y', time());
+		return $this->parseHtmlByName('back.html', array(
+			'style_prefix' => $sStylePrefix,
+			'href' => 'javascript:void(0)',
+    		'title' => _t('_bx_timeline_txt_jump_to_n_year', $iYearNow),
+    		'bx_repeat:attrs' => array(
+    			array('key' => 'onclick', 'value' => 'javascript:' . $sJsObject . '.changeTimeline(this, 0)')
+    		),
+    		'content' => _t('_bx_timeline_txt_jump_to_recent')
+		));
+	}
+
+	public function getLoadMore($iStart, $iPerPage, $bEnabled, $iYearSel, $iYearMin, $bVisible = true)
     {
+    	$sStylePrefix = $this->_oConfig->getPrefix('style');
+    	$sJsObject = $this->_oConfig->getJsObject('view');
+
+    	$sYears = '';
+    	if(!empty($iYearMin)) {
+    		$iYearMax = date('Y', time()) - 1;
+    		for($i = $iYearMax; $i >= $iYearMin; $i--)
+    			$sYears .= ($i != $iYearSel ? $this->parseHtmlByName('bx_a.html', array(
+    				'href' => 'javascript:void(0)',
+    				'title' => _t('_bx_timeline_txt_jump_to_n_year', $i),
+    				'bx_repeat:attrs' => array(
+    					array('key' => 'onclick', 'value' => 'javascript:' . $sJsObject . '.changeTimeline(this, ' . $i . ')')
+    				),
+    				'content' => $i
+    			)) : $i) . ', ';
+    		
+    		$sYears = substr($sYears, 0, -2);
+    	}
+    	
         $aTmplVars = array(
-        	'style_prefix' => $this->_oConfig->getPrefix('style'),
+        	'style_prefix' => $sStylePrefix,
             'visible' => $bVisible ? 'block' : 'none',
             'bx_if:is_disabled' => array(
                 'condition' => !$bEnabled,
@@ -214,8 +260,15 @@ class BxTimelineTemplate extends BxDolModuleTemplate
             'bx_if:show_on_click' => array(
                 'condition' => $bEnabled,
                 'content' => array(
-                    'on_click' => $this->_oConfig->getJsObject('view') . '.changePage(this, ' . ($iStart + $iPerPage) . ', ' . $iPerPage . ')'
+                    'on_click' => 'javascript:' . $sJsObject . '.changePage(this, ' . ($iStart + $iPerPage) . ', ' . $iPerPage . ')'
                 )
+            ),
+            'bx_if:show_jump_to' => array(
+            	'condition' => !empty($sYears),
+                'content' => array(
+            		'style_prefix' => $sStylePrefix,
+            		'years' => $sYears
+            	)
             )
         );
         return $this->parseHtmlByName('load_more.html', $aTmplVars);

+ 3 - 2
modules/boonex/timeline/install/langs/en.xml

@@ -111,11 +111,12 @@
 	<string name="_bx_timeline_txt_err_cannot_perform_action"><![CDATA[Cannot perform action. Please report.]]></string>
 
 	<string name="_bx_timeline_txt_load_more"><![CDATA[Load More]]></string>
+	<string name="_bx_timeline_txt_or_jump_to"><![CDATA[... or jump to:]]></string>
+	<string name="_bx_timeline_txt_jump_to_n_year"><![CDATA[Jump to {0} year]]></string>
+	<string name="_bx_timeline_txt_jump_to_recent"><![CDATA[Jump to recent posts]]></string>
 	<string name="_bx_timeline_txt_wrote"><![CDATA[wrote]]></string>
 	<string name="_bx_timeline_txt_shared_link"><![CDATA[shared a link]]></string>
 	<string name="_bx_timeline_txt_added_photo"><![CDATA[added a photo]]></string>
-	<string name="_bx_timeline_txt_date_from"><![CDATA[today]]></string>
-	<string name="_bx_timeline_txt_date_to"><![CDATA[olden days]]></string>
 
 	<string name="_bx_timeline_txt_plus"><![CDATA[Plus]]></string>
 	

+ 21 - 5
modules/boonex/timeline/js/view.js

@@ -57,12 +57,22 @@ BxTimelineView.prototype.changeFilter = function(oLink) {
     this._getPosts(oLink, 'filter');
 };
 
+/*
+//TODO: Remove if old timeline slider is not used
 BxTimelineView.prototype.changeTimeline = function(oEvent, oUi) {
 	this._oRequestParams.start = 0;
     this._oRequestParams.timeline = oUi.value;
 
 	this._getPosts($(oUi.handle), 'timeline');
 };
+*/
+
+BxTimelineView.prototype.changeTimeline = function(oLink, iYear) {
+	this._oRequestParams.start = 0;
+    this._oRequestParams.timeline = iYear;
+
+	this._getPosts(oLink, 'timeline');
+};
 
 BxTimelineView.prototype.deletePost = function(oLink, iId) {
     var $this = this;
@@ -198,21 +208,20 @@ BxTimelineView.prototype._getPosts = function(oElement, sAction) {
         this._sActionsUrl + 'get_posts/',
         this._getDefaultData(),
         function(oData) {
-        	if($.trim(oData.load_more).length > 0)
-        		oView.find('.bx-tl-load-more').replaceWith(oData.load_more);
+        	if(oData && oData.items != undefined) {
+        		var sItems = $.trim(oData.items);
 
-        	if($.trim(oData.items).length > 0)
 	        	switch(sAction) { 
 	        		case 'page':
 	        			$this.loadingInButton(oElement, false);
-	        			$this.appendMasonry($(oData.items).bxTime());
+	        			$this.appendMasonry($(sItems).bxTime());
 			            break;
 
 	        		default:
 	        			$this.loadingInBlock(oElement, false);
 
 	        			oView.find('.bx-tl-items').bx_anim('hide', $this._sAnimationEffect, $this._iAnimationSpeed, function() {
-			                $(this).html(oData.items).show().bxTime();
+			                $(this).html(sItems).show().bxTime();
 
 			                if($this.isMasonryEmpty()) {
 			                	$this.destroyMasonry();
@@ -226,6 +235,13 @@ BxTimelineView.prototype._getPosts = function(oElement, sAction) {
 			            });
 		            	break;
 	            }
+        	}
+
+        	if(oData && oData.load_more != undefined)
+        		oView.find('.bx-tl-load-more-holder').html($.trim(oData.load_more));
+
+        	if(oData && oData.back != undefined)
+        		oView.find('.bx-tl-back-holder').html($.trim(oData.back));
         },
         'json'
     );

+ 3 - 0
modules/boonex/timeline/template/back.html

@@ -0,0 +1,3 @@
+<div class="__style_prefix__-back bx-def-margin-sec-bottom">
+	<bx_include_auto:bx_a.html />
+</div>

+ 11 - 3
modules/boonex/timeline/template/css/view.css

@@ -14,9 +14,15 @@ div.bx-tl-items {
 	width: 100%;
 }
 
+/*--- Back Style ---*/
+
 /*--- Load More Style ---*/
-div.bx-tl-load-more .bx-btn {
-    float: none;
+div.bx-tl-load-more {}
+
+div.bx-tl-jump-to {
+	position: relative;
+	float: right;
+	line-height: 36px;
 }
 
 /*--- Item Style ---*/
@@ -53,7 +59,6 @@ div.bx-tl-item-menu-button a:hover {
 }
 div.bx-tl-item-image {
 	margin-left: -20px;
-	margin-top: -20px;
 	margin-right: -20px;
 	border: 1px solid #ffffff;
 	text-align: center;
@@ -93,6 +98,8 @@ div.bx-tl-empty div.bx-msg-box-container {
 }
 
 /*--- Timeline Styles ---*/
+/*
+//TODO: Remove if old timeline slider is not used
 div.bx-tl-timeline {}
 div.bx-tl-timeline-date-from,
 div.bx-tl-timeline-date-to {
@@ -120,6 +127,7 @@ div.bx-tl-timeline .ui-slider-handle {
 div.bx-tl-timeline .ui-slider-handle:hover {
 	text-decoration: none;
 }
+*/
 
 /*--- Comments Styles ---*/
 div.bx-tl-comments {}

+ 7 - 2
modules/boonex/timeline/template/load_more.html

@@ -1,5 +1,10 @@
-<div class="__style_prefix__-load-more bx-def-padding-sec-topbottom" style="display:__visible__;">
-    <button class="bx-btn<bx_if:is_disabled> bx-btn-disabled</bx_if:is_disabled>" <bx_if:show_on_click>onclick="javascript:__on_click__"</bx_if:show_on_click>>
+<div class="__style_prefix__-load-more bx-def-padding-sec-topbottom bx-clearfix" style="display:__visible__;">
+    <button class="bx-btn<bx_if:is_disabled> bx-btn-disabled</bx_if:is_disabled>" <bx_if:show_on_click>onclick="__on_click__"</bx_if:show_on_click>>
         <bx_text:_bx_timeline_txt_load_more />
     </button>
+    <bx_if:show_jump_to>
+    	<div class="__style_prefix__-jump-to">
+    		<bx_text:_bx_timeline_txt_or_jump_to />&nbsp;__years__
+    	</div>
+    </bx_if:show_jump_to>
 </div>

+ 5 - 5
modules/boonex/timeline/template/text.html

@@ -1,11 +1,6 @@
 <div id="bx-timeline-item-__id__" class="__style_prefix__-item bx-tl-grid-sizer">
 	<div class="__style_prefix__-item-ind bx-def-padding-sec">
 	    <div class="__style_prefix__-item-cnt bx-def-padding bx-def-round-corners bx-def-shadow">
-	    	<bx_if:show_images>
-	    		<bx_repeat:images>
-		    		<div class="__style_prefix__-item-image bx-def-thumb bx-def-margin-bottom">__image__</div>
-		    	</bx_repeat:images>
-	    	</bx_if:show_images>
 	    	<div class="__style_prefix__-owner bx-def-margin-bottom bx-def-icon-size-min-height"> 
 		       	<div class="__style_prefix__-owner-icon bx-def-icon bx-def-icon-size">
 					<bx_if:show_icon>
@@ -36,6 +31,11 @@
 					</div>
 			   	</bx_if:show_menu_item_manage>
 			</div>
+			<bx_if:show_images>
+	    		<bx_repeat:images>
+		    		<div class="__style_prefix__-item-image bx-def-thumb bx-def-margin-bottom">__image__</div>
+		    	</bx_repeat:images>
+	    	</bx_if:show_images>
 			<bx_if:show_title>
 				<div class="__style_prefix__-title bx-def-margin-sec-bottom bx-def-font-large">__title__</div>
 			</bx_if:show_title>

+ 6 - 0
modules/boonex/timeline/template/view.html

@@ -1,7 +1,13 @@
 <div id="bx-timeline" class="__style_prefix__-view bx-def-bc-margin">
 	<div class="__style_prefix__-cnt">
+		<!--
+	    //TODO: Remove if old timeline slider is not used
 		<div class="__style_prefix__-timeline-holder">
             __timeline__
+        </div>
+        -->
+        <div class="__style_prefix__-back-holder">
+            __back__
         </div>
 		<div class="__style_prefix__-items">
 			__content__