Skip to content

Commit

Permalink
Added sort tabs and pagination to profile pages
Browse files Browse the repository at this point in the history
  • Loading branch information
snytkine committed Apr 13, 2011
1 parent 3fd69d4 commit 59ec717
Show file tree
Hide file tree
Showing 28 changed files with 962 additions and 137 deletions.
1 change: 1 addition & 0 deletions RewriteRules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ RewriteRule ^/([a-zA-Z\-]+)/page([0-9]+)\.html$ /index.php?a=$1&pageID=$2
RewriteRule ^/aa/([0-9]+)/([a-f0-9]+)$ /index.php?a=activate&eid=$1&hash=$2
RewriteRule ^/([a-zA-Z\-]+)/$ /index.php?a=$1
RewriteRule ^/search/(m|r)/(.*)/page([0-9]+)\.html$ /index.php?a=search&ord=$1&q=$2&pageID=$3
RewriteRule ^/tab/(a|q)/([0-9]+)/([a-zA-Z]+)/page([0-9]+)\.html$ /index.php?a=userinfotab&tab=$1&uid=$2&sort=$3&pageID=$4 [L]
19 changes: 12 additions & 7 deletions lib/Lampcms/Answers.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,18 @@ public function getAnswers(Question $oQuestion, $result = 'html'){
$where['i_del_ts'] = null;
}

/**
* In case of i_ts (by timestamp of answer)
* we actuall need from oldest to newest - Ascending
* and for other types we need Descending order
*
*/
$sort = ('i_ts' == $cond) ? array($cond => 1): array($cond => -1);
switch($cond){
case 'i_ts':
$sort = array('i_ts' => 1);
break;

case 'i_votes':
$sort = array('i_votes' => -1);
break;

default:
$sort = array($cond => -1);
}

$cursor = $this->oRegistry->Mongo->ANSWERS->find($where, $aFields);
d('$cursor: '.gettype($cursor));
Expand Down
2 changes: 1 addition & 1 deletion lib/Lampcms/Controllers/Unanswered.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ protected function getTags(){
}

$this->rawTags = $tags;
$this->title = \htmlspecialchars_decode(\urldecode($tags));
$this->title = $this->tags;
d('this->title: '.$this->title);

if(empty($this->tags)){
Expand Down
94 changes: 91 additions & 3 deletions lib/Lampcms/Controllers/Userinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@
use Lampcms\UserVotesBlock;
use Lampcms\WebPage;
use Lampcms\User;
use Lampcms\Template\Urhere;
use Lampcms\ProfileDiv;
use Lampcms\UserTagsBlock;
use Lampcms\UserFollowedTags;
use Lampcms\UserQuestions;
use Lampcms\UserAnswers;

Expand Down Expand Up @@ -91,10 +93,21 @@ protected function main(){
->addQuestions()
->addAnswers()
->addVotes()
->addFollowedTags()
->addTags();
}


/**
* Create $this->oUser object
* that represents User whose profile
* is being viewed currently
*
* @throws \Lampcms\Exception if user could not be
* found by user id passed in request
*
* @return object $this
*/
protected function getUser(){
$a = $this->oRegistry->Mongo->USERS->findOne(array('_id' => $this->oRequest['uid']));

Expand All @@ -109,8 +122,21 @@ protected function getUser(){
}


/**
* Check that username passed in url matches the
* username of user.
*
* @throws \Lampcms\RedirectException in case username passed
* in url does not match actual username for this user, in which
* case there will be a redirect to user with correct user name.
* This is basically good for SEO to prevent possibility of different urls
* pointing to the same page
*
* @return object $this
*/
protected function checkUsername(){
$supplied = $this->oRequest['username'];
$supplied = $this->oRequest->get('username', 's', '');

if(!empty($supplied)){
$username = $this->oUser->username;
if(!empty($username) && (strtolower($username) !== strtolower($supplied) )){
Expand Down Expand Up @@ -147,7 +173,30 @@ protected function addProfile(){
*/
protected function addQuestions(){

$this->aPageVars['body'] .= UserQuestions::get($this->oRegistry, $this->oUser);
/**
*
* html of parsed questions and pagination links
* at the bottom all wrapped inside <div class="user_tags">
* @var $userQuestions
*/
$userQuestions = UserQuestions::get($this->oRegistry, $this->oUser);

/**
* UserQuestions::get() may return an empty string
* if this user does not have
* any questions in which case skip the
* rest of the method
*/
if(empty($userQuestions)){
return $this;
}

$cond = $this->oRegistry->Request->get('sort', 's', 'recent');
$tabs = Urhere::factory($this->oRegistry)->get('tplSortuq', $cond, array('uid' => $this->oUser->getUid()));

$questiondBlock = '<div id="uquestions" class="sortable paginated">'.$userQuestions.'</div>';

$this->aPageVars['body'] .= $tabs.$questiondBlock;

return $this;
}
Expand All @@ -163,7 +212,30 @@ protected function addQuestions(){
*/
protected function addAnswers(){

$this->aPageVars['body'] .= UserAnswers::get($this->oRegistry, $this->oUser);
/**
*
* html of parsed answers and pagination links
* at the bottom all wrapped inside <div class="user_answers">
* @var $userQuestions
*/
$userQuestions = UserAnswers::get($this->oRegistry, $this->oUser);

/**
* UserQuestions::get() may return an empty string
* if this user does not have
* any answers in which case skip the
* rest of the method
*/
if(empty($userQuestions)){
return $this;
}

$cond = $this->oRegistry->Request->get('sort', 's', 'recent');
$tabs = Urhere::factory($this->oRegistry)->get('tplSortuans', $cond, array('uid' => $this->oUser->getUid()));

$ansBlock = '<div id="useranswers" class="cp fl sortable paginated">'.$userQuestions.'</div>';

$this->aPageVars['body'] .= $tabs.$ansBlock;

return $this;
}
Expand Down Expand Up @@ -193,4 +265,20 @@ protected function addTags(){
return $this;
}


/**
* Add block that shows tags that this user
* is following and also possibly block with tags
* that both Viewer and User are following
*
* @return object $this
*/
protected function addFollowedTags(){

$this->aPageVars['body'] .= UserFollowedTags::get($this->oRegistry, $this->oUser);


return $this;
}

}
102 changes: 102 additions & 0 deletions lib/Lampcms/Controllers/Userinfotab.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php
/**
*
* License, TERMS and CONDITIONS
*
* This software is lisensed under the GNU LESSER GENERAL PUBLIC LICENSE (LGPL) version 3
* Please read the license here : http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* ATTRIBUTION REQUIRED
* 4. All web pages generated by the use of this software, or at least
* the page that lists the recent questions (usually home page) must include
* a link to the http://www.lampcms.com and text of the link must indicate that
* the website\'s Questions/Answers functionality is powered by lampcms.com
* An example of acceptable link would be "Powered by <a href="http://www.lampcms.com">LampCMS</a>"
* The location of the link is not important, it can be in the footer of the page
* but it must not be hidden by style attibutes
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This product includes GeoLite data created by MaxMind,
* available from http://www.maxmind.com/
*
*
* @author Dmitri Snytkine <cms@lampcms.com>
* @copyright 2005-2011 (or current year) ExamNotes.net inc.
* @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU LESSER GENERAL PUBLIC LICENSE (LGPL) version 3
* @link http://www.lampcms.com Lampcms.com project
* @version Release: @package_version@
*
*
*/


namespace Lampcms\Controllers;

use \Lampcms\Responder;

/**
* This controller processes Ajax requests only
* requests are for sorted and/or paginaged block
* with user answers or user questions
*
*
* @author Dmitri Snytkine
*
*/
class Userinfotab extends Userinfo
{


protected function main(){
$this->getUser();
$tab = $this->oRequest->get('tab');
if('q' === $tab){
return $this->getQuestions();
}

return $this->getAnswers();
}

/**
* Get content of sorted and paginated User Questions
* block and return in via XHR
*
*/
protected function getQuestions(){
$s = \Lampcms\UserQuestions::get($this->oRegistry, $this->oUser);
Responder::sendJSON(array('replace' => array('target' => 'uquestions', 'content' => $s) ));
}


/**
* Get paginated and sorted block with user
* Answers and returl via XHR
*
*/
protected function getAnswers(){
d('getting answers block');
$s = \Lampcms\UserAnswers::get($this->oRegistry, $this->oUser);
Responder::sendJSON(array('replace' => array('target' => 'useranswers', 'content' => $s) ));
}

}
2 changes: 1 addition & 1 deletion lib/Lampcms/Object.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

namespace Lampcms;

const JS_MIN_ID = '04102011_2';
const JS_MIN_ID = '04132011';

const LF = "\n";
const CR = "\r";
Expand Down
2 changes: 2 additions & 0 deletions lib/Lampcms/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public function getPager(){
* @param mixed int|array|object MongoCursor $arrData
* @param int $perPage
* @param array $arrExtraParams
*
* @return array paged data
*
* @throws LampcmsDevException
*/
Expand Down
15 changes: 5 additions & 10 deletions lib/Lampcms/RegBlockQuickReg.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
namespace Lampcms;

use \Lampcms\Forms\Form;

/**
* Generates html of the QuickRegistration block
* it extends RegBlock
Expand Down Expand Up @@ -124,15 +125,7 @@ protected function makeLoginBlock(){
*
* @return string HTML block
*/
protected function makeCaptchaBlock()
{
/*$oCaptcha = new Captcha($this->oRegistry);
$aVals = $oCaptcha->getCaptchaArray();
d('got captcha vals: '.print_r($aVals, 1));
$s = \tplCaptcha::parse($aVals, false);
d('Captcha block: '.$s);*/

protected function makeCaptchaBlock(){
$s = Captcha::factory($this->oRegistry)->getCaptchaBlock();

return $s;
Expand Down Expand Up @@ -173,7 +166,9 @@ public function makeSocialAuthBlock($or = '<h2>-OR-</h2>')
$s .= '<div class="extauth"><a href="#" onClick="google.friendconnect.requestSignIn(); return false;"><img class="hand" src="/images/gfcbutton.jpg" width="226" height="40" alt="Sign in with Google Friend Connect"/></a></div>';
}

return \tplSocial::parse(array($s, '', '<h3>Join with account you already have</h3>'), false);
$label = (!empty($s)) ? '<h3>Join with account you already have</h3><hr class="line1"/>' : '';

return \tplSocial::parse(array($s, '', $label), false);
}

}
Loading

0 comments on commit 59ec717

Please sign in to comment.