Skip to content

Commit

Permalink
Added Autocomplete, added Followers/Followees blocks, Taginput widget,
Browse files Browse the repository at this point in the history
made
Tags
page
sortable,
several
bug
fixes
  • Loading branch information
snytkine committed Apr 7, 2011
1 parent 82a06a6 commit 1c78883
Show file tree
Hide file tree
Showing 62 changed files with 1,808 additions and 824 deletions.
11 changes: 11 additions & 0 deletions !config.ini.dist
Expand Up @@ -158,6 +158,17 @@ SHOW_TIMER = false;
;
GFC_ID =
;
; disable autocomplete widget
; in search form and in Title in "Ask" form
; Autocomplete does send request to server
; on every key press, and search by title tags
; is run on server.
; This is fast process and does
; not add much load to server but if you
; still don't want it then set this to true
; to disable autocomplete
;
DISABLE_AUTOCOMPLETE = false

[CAPTCHA]
; to disable captcha for any reason
Expand Down
1 change: 1 addition & 0 deletions RewriteRules.txt
Expand Up @@ -30,6 +30,7 @@ RewriteRule ^/tags/page([0-9]+)\.htm([l]{0,1})$ /index.php?a=viewqtags&pageID=$1
RewriteRule ^/tags/name([\/]{0,1})$ /index.php?a=viewqtags&cond=name
RewriteRule ^/tags/recent([\/]{0,1})$ /index.php?a=viewqtags&cond=recent
RewriteRule ^/tags/popular([\/]{0,1})$ /index.php?a=viewqtags&cond=popular
RewriteRule ^/tags/(name|recent|popular)/page([0-9]+)\.html$ /index.php?a=viewqtags&cond=$1&pageID=$2
RewriteRule ^/tagged/(.*)/$ /index.php?a=tagged&tags=$1
RewriteRule ^/tagged/(.*)/page([0-9]+)\.html$ /index.php?a=tagged&tags=$1&pageID=$2
RewriteRule ^/vote/([0-9]+)/(up|down)$ /index.php?a=vote&resid=$1&res=q&type=$2
Expand Down
4 changes: 2 additions & 2 deletions lib/Lampcms/Answers.php
Expand Up @@ -172,10 +172,10 @@ public function getAnswers(Question $oQuestion, $result = 'html'){
*/
if(!($a['accepted'])){
if($showLink){
$a['accept_link'] = '<a class="accept" title="'.$alt.'" href="/accept/'.$a['_id'].'">'.$accept.'</a>';
$a['accept_link'] = '<a class="accept ttt" title="'.$alt.'" href="/accept/'.$a['_id'].'">'.$accept.'</a>';
}
} else {
$a['accepted'] = '<img src="/images/accepted.png" alt="Best answer" title="Owner of the question accepted this as best answer">';
$a['accepted'] = '<img src="/images/accepted.png" alt="Best answer" class="ttt" title="Owner of the question accepted this as best answer">';
}

$a['nocomments'] = $noComments;
Expand Down
2 changes: 2 additions & 0 deletions lib/Lampcms/Bodytagger.php
Expand Up @@ -85,6 +85,8 @@ public static function highlight($mystring, array $aTags){

$key = '/\b'.preg_quote($key).'\b/i';
});

d('$aTags: '.print_r($aTags, 1));

$ret = preg_replace_callback($aTags, function($matches){
$tag = 'em';
Expand Down
28 changes: 17 additions & 11 deletions lib/Lampcms/Controllers/Editor.php
Expand Up @@ -52,6 +52,7 @@

namespace Lampcms\Controllers;



use \Lampcms\Responder;
use \Lampcms\Request;
Expand Down Expand Up @@ -122,22 +123,20 @@ protected function process()
$formVals = $this->oForm->getSubmittedValues();
d('formVals: '.print_r($formVals, 1));

/**
* @todo for the Anwer object there is no need
* to worry about the title at all!
*
* @todo run the reason through Utf8String also and use htmlentities()
* instead of strip_tags.
*/
$this->oResource['b'] = $this->makeBody($formVals['qbody']);

/**
* Don't attempt to edit the value of title
* for the answer since it technically does not have the title
* and we don't want to change existing one
*/
if($this->oRequest instanceof \Lampcms\Question){
$this->oResource['title'] = $this->makeTitle($formVals['title']);
if($this->oResource instanceof \Lampcms\Question){
$title = $this->makeTitle($formVals['title']);
d('title: '.$title);
$this->oResource['title'] = $title;
$this->oResource['a_title'] = \Lampcms\TitleTokenizer::factory($title)->getArrayCopy();
}

$this->oResource->setEdited($this->oRegistry->Viewer, strip_tags($formVals['reason']));
$this->oResource->save();

Expand Down Expand Up @@ -177,10 +176,16 @@ protected function makeTitle($title){
protected function updateQuestion(){
if('ANSWERS' === $this->collection){
d('need to update QUESTION');

try{
$this->oRegistry->Mongo->QUESTIONS
->update(array('_id' => $this->oResource['i_qid']), array('$set' => array('i_lm_ts' => time())));
->update(array('_id' => $this->oResource['i_qid']),
array(
'$set' => array(
'i_lm_ts' => time(),
'i_etag' => time())
)
);
} catch(\MongoException $e){
d('unable to update question '.$e->getMessage());
}
Expand All @@ -191,6 +196,7 @@ protected function updateQuestion(){


protected function returnResult(){

Responder::redirectToPage($this->oResource->getUrl());
}
}
1 change: 0 additions & 1 deletion lib/Lampcms/Controllers/Getanswers.php
Expand Up @@ -72,7 +72,6 @@ class Getanswers extends Viewquestion
protected $oAnswers;

protected function main(){

$this->getQuestion()->getAnswers()->setReturn();
}

Expand Down
9 changes: 5 additions & 4 deletions lib/Lampcms/Controllers/Retag.php
Expand Up @@ -55,7 +55,7 @@
use \Lampcms\Utf8String;
use \Lampcms\WebPage;
use \Lampcms\ReputationAcl;
use \Lampcms\TagsNormalizer;
use \Lampcms\TagsTokenizer;
use \Lampcms\Request;
use \Lampcms\Responder;

Expand Down Expand Up @@ -83,16 +83,17 @@ class Retag extends WebPage

/**
* Array of submitted tags
* after they are run through TagsNormalizer
* after they are run through TagsTokenizer
*
* @var array
*/
protected $aSubmitted;


protected function main(){
$this->aSubmitted = TagsNormalizer::parse(Utf8String::factory($this->oRequest['tags']) );

$this->aSubmitted = TagsTokenizer::factory(Utf8String::factory($this->oRequest['tags']))->getArrayCopy();
d('$this->aSubmitted: '.print_r($this->aSubmitted, 1));

$this->getQuestion()
->checkPermission()
->checkForChanges()
Expand Down
17 changes: 10 additions & 7 deletions lib/Lampcms/Controllers/Search.php
Expand Up @@ -63,12 +63,18 @@ class Search extends WebPage

/**
* Search term
*
*
* @var string
*/
protected $term;


/**
* Pagination links on the page
* will not be handled by Ajax
*
* @var bool
*/
protected $notAjaxPaginatable = true;

/**
* (non-PHPdoc)
Expand All @@ -83,9 +89,6 @@ protected function main(){
*/
$this->term = $this->oRequest['q'];
$this->aPageVars['qheader'] = '<h1>Search results for: '.$this->term.'</h1>';
/*if('recent' == $this->oRequest->get('ord', 's', '')){
$this->order = 'ORDER by ts DESC';
}*/

$this->aPageVars['title'] = 'Questions matching &#39;'.$this->term.'&#39;';
d('$this->term: '.$this->term);
Expand Down Expand Up @@ -126,9 +129,9 @@ protected function makeInfo(){


protected function makeBody(){


$this->aPageVars['body'] = \tplQlist::parse(array('', $this->oSearch->getHtml(), $this->oSearch->getPagerLinks()), false);

$this->aPageVars['body'] = \tplQlist::parse(array('', $this->oSearch->getHtml(), $this->oSearch->getPagerLinks(), $this->notAjaxPaginatable), false);

return $this;
}
Expand Down
91 changes: 91 additions & 0 deletions lib/Lampcms/Controllers/Taghint.php
@@ -0,0 +1,91 @@
<?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\WebPage;
use Lampcms\Responder;

/**
* Controller for getting array
* of tags that partially match the
* value of 'q' using "starts with" regex search
*
* This controller is used from the auto-complete tag widget
* on the "Ask" form
*
* @author Dmitri Snytkine
*
*/
class Taghint extends Titlehint
{

protected function getData(){

$q = $this->oRequest->get('q', 's');
$q = mb_strtolower($q);
d('looking for tag hint $q: '.$q);

try{
$cur = $this->oRegistry->Mongo->QUESTION_TAGS->find(
array('tag' => array('$regex' => '^'.$q) ), array('tag'))
->sort(array('i_count' => -1))
->limit(200);
$this->aData = iterator_to_array($cur, false);
d('$this->aData: '.print_r($this->aData, 1));
} catch(\MongoException $e){
d('MongoException: '.$e->getMessage().' $q was: '.$q);
}

return $this;
}
}

0 comments on commit 1c78883

Please sign in to comment.