1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-05-17 08:18:18 +03:00

список всех блогов с постраничным выводом + фикс к восстановлению комментов

This commit is contained in:
Mzhelskiy Maxim 2008-10-26 15:51:03 +00:00
parent 662ea3639b
commit 60323107b4
18 changed files with 242 additions and 29 deletions

View file

@ -0,0 +1,64 @@
<?
/*-------------------------------------------------------
*
* LiveStreet Engine Social Networking
* Copyright © 2008 Mzhelskiy Maxim
*
*--------------------------------------------------------
*
* Official site: www.livestreet.ru
* Contact e-mail: rus.engine@gmail.com
*
* GNU General Public License, version 2:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*
---------------------------------------------------------
*/
/**
* Класс обработки УРЛа вида /comments/
*
*/
class ActionBlogs extends Action {
public function Init() {
}
protected function RegisterEvent() {
$this->AddEventPreg('/^(page(\d+))?$/i','EventShowBlogs');
}
/**********************************************************************************
************************ РЕАЛИЗАЦИЯ ЭКШЕНА ***************************************
**********************************************************************************
*/
protected function EventShowBlogs() {
/**
* Передан ли номер страницы
*/
$iPage= preg_match("/^\d+$/i",$this->GetEventMatch(2)) ? $this->GetEventMatch(2) : 1;
/**
* Получаем список блогов
*/
$aResult=$this->Blog_GetBlogsRating($iPage,BLOG_BLOGS_PER_PAGE);
$aBlogs=$aResult['collection'];
/**
* Формируем постраничность
*/
$aPaging=$this->Viewer_MakePaging($aResult['count'],$iPage,BLOG_BLOGS_PER_PAGE,4,DIR_WEB_ROOT.'/blogs');
/**
* Загружаем переменные в шаблон
*/
$this->Viewer_Assign('aPaging',$aPaging);
$this->Viewer_Assign("aBlogs",$aBlogs);
$this->Viewer_AddHtmlTitle('Список блогов');
/**
* Устанавливаем шаблон вывода
*/
$this->SetTemplateAction('index');
}
}
?>

View file

@ -69,7 +69,8 @@ class ActionTop extends Action {
/**
* Получаем список блогов
*/
$aBlogs=$this->Blog_GetBlogsRating(20);
$aResult=$this->Blog_GetBlogsRating(1,20);
$aBlogs=$aResult['collection'];
/**
* Загружаем переменные в шаблон
*/

View file

@ -24,7 +24,8 @@ class BlockBlogs extends Block {
/**
* Получаем список блогов
*/
$aBlogs=$this->Blog_GetBlogsRating(20);
$aResult=$this->Blog_GetBlogsRating(1,20);
$aBlogs=$aResult['collection'];
/**
* Загружаем переменные в шаблон
*/

View file

@ -285,10 +285,14 @@ class Blog extends Module {
* @param unknown_type $iLimit
* @return unknown
*/
public function GetBlogsRating($iLimit=20) {
if (false === ($data = $this->Cache_Get("blog_rating_{$iLimit}"))) {
$data = $this->oMapperBlog->GetBlogsRating($iLimit);
$this->Cache_Set($data, "blog_rating_{$iLimit}", array("blog_update","blog_new"), 60*5);
public function GetBlogsRating($iCurrPage,$iPerPage) {
$s1=-1;
if ($this->oUserCurrent) {
$s1=$this->oUserCurrent->getId();
}
if (false === ($data = $this->Cache_Get("blog_rating_{$iCurrPage}_{$iPerPage}_$s1"))) {
$data = array('collection'=>$this->oMapperBlog->GetBlogsRating($iCount,$iCurrPage,$iPerPage),'count'=>$iCount);
$this->Cache_Set($data, "blog_rating_{$iCurrPage}_{$iPerPage}_$s1", array("blog_update","blog_new"), 60*15);
}
return $data;
}

View file

@ -89,6 +89,9 @@ class BlogEntity_Blog extends Entity
return DIR_STATIC_SKIN.'/img/avatar_blog_'.$iSize.'x'.$iSize.'.gif';
}
}
public function getCurrentUserIsJoin() {
return $this->_aData['current_user_is_join'];
}

View file

@ -279,14 +279,27 @@ class Mapper_Blog extends Mapper {
public function GetBlogsRating($iLimit) {
public function GetBlogsRating(&$iCount,$iCurrPage,$iPerPage) {
$iCurrentUserId=-1;
if (is_object($this->oUserCurrent)) {
$iCurrentUserId=$this->oUserCurrent->getId();
}
$sql = "SELECT
b.*,
u.user_profile_avatar as user_profile_avatar,
u.user_profile_avatar_type as user_profile_avatar_type,
u.user_login as user_login
u.user_login as user_login,
IF(bu.blog_id IS NULL,0,1) as current_user_is_join
FROM
".DB_TABLE_BLOG." as b,
".DB_TABLE_BLOG." as b
LEFT JOIN (
SELECT
blog_id
FROM ".DB_TABLE_BLOG_USER."
WHERE user_id = ?d
) AS bu ON b.blog_id = bu.blog_id,
".DB_TABLE_USER." as u
WHERE
b.blog_rating >= 0
@ -295,11 +308,11 @@ class Mapper_Blog extends Mapper {
AND
b.user_owner_id=u.user_id
ORDER by b.blog_rating desc
LIMIT 0, ?d
LIMIT ?d, ?d
;
";
$aReturn=array();
if ($aRows=$this->oDb->select($sql,$iLimit)) {
if ($aRows=$this->oDb->selectPage($iCount,$sql,$iCurrentUserId,($iCurrPage-1)*$iPerPage, $iPerPage)) {
foreach ($aRows as $aRow) {
$aReturn[]=new BlogEntity_Blog($aRow);
}

View file

@ -140,7 +140,7 @@ class Mapper_User extends Mapper {
}
public function GetUserByMail($sMail) {
$sql = "SELECT * FROM ".DB_TABLE_USER." WHERE LOWER(user_mail) = ? ";
$sql = "SELECT * FROM ".DB_TABLE_USER." WHERE user_mail = ? ";
if ($aRow=$this->oDb->selectRow($sql,strtolower($sMail))) {
return new UserEntity_User($aRow);
}
@ -177,7 +177,7 @@ class Mapper_User extends Mapper {
) AS uf ON uf.user_frend_id = u.user_id
WHERE
LOWER(u.user_login) = ? ";
u.user_login = ? ";
if ($aRow=$this->oDb->selectRow($sql,$iCurrentUserId,$iCurrentUserId,strtolower($sLogin))) {
return new UserEntity_User($aRow);
}
@ -304,14 +304,13 @@ class Mapper_User extends Mapper {
return $result;
}
public function GetUsersByLoginLike($sUserLogin,$iLimit) {
$sUserLogin=mb_strtolower($sUserLogin,"UTF-8");
public function GetUsersByLoginLike($sUserLogin,$iLimit) {
$sql = "SELECT
user_login
FROM
".DB_TABLE_USER."
WHERE
LOWER(user_login) LIKE ?
user_login LIKE ?
and
user_activate = 1
LIMIT 0, ?d

View file

@ -116,6 +116,7 @@ define('BLOG_TOPIC_NEW_TIME',60*60*24*1); // Время в секундах в
define('BLOG_TOPIC_PER_PAGE',10); // число топиков на одну страницу
define('BLOG_COMMENT_PER_PAGE',20); // число комментариев на одну страницу(это касается только полного списка комментариев прямого эфира)
define('BLOG_COMMENT_BAD',-5); // рейтинг комментария, начиная с которого он будет скрыт
define('BLOG_BLOGS_PER_PAGE',20); // число блогов на страницу
define('USER_PER_PAGE',15); // число юзеров на страницу на странице статистики
define('RSS_EDITOR_MAIL',SYS_MAIL_FROM_EMAIL); // мыло редактора РСС

View file

@ -41,6 +41,7 @@ return array(
'rss' => 'ActionRss',
'link' => 'ActionLink',
'question' => 'ActionQuestion',
'blogs' => 'ActionBlogs',
),
'config' => array(
'action_default' => 'index',

View file

@ -0,0 +1,71 @@
<?php
/*-------------------------------------------------------
*
* LiveStreet Engine Social Networking
* Copyright © 2008 Mzhelskiy Maxim
*
*--------------------------------------------------------
*
* Official site: www.livestreet.ru
* Contact e-mail: rus.engine@gmail.com
*
* GNU General Public License, version 2:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*
---------------------------------------------------------
*/
/**
* Удаление комментария админом
*/
set_include_path(get_include_path().PATH_SEPARATOR.dirname(dirname(dirname(__FILE__))));
chdir(dirname(dirname(dirname(__FILE__))));
require_once("./config/config.ajax.php");
$idComment=@$_REQUEST['idComment'];
$bStateError=true;
$sMsg='';
$sMsgTitle='';
$sCommentText='';
if ($oEngine->User_IsAuthorization()) {
$oUserCurrent=$oEngine->User_GetUserCurrent();
if ($oUserCurrent->isAdministrator()) {
if ($oComment=$oEngine->Comment_GetCommentById($idComment)) {
$oComment->setDelete(0);
if ($oEngine->Comment_UpdateTopicComment($oComment)) {
$sCommentText=$oComment->getText();
$bStateError=false;
$sMsgTitle='Отлично!';
$sMsg='Комментарий восстановлен';
} else {
$sMsgTitle='Ошибка!';
$sMsg='Возникли проблемы при восстановлении!';
}
} else {
$sMsgTitle='Ошибка!';
$sMsg='Комментарий не найден!';
}
} else {
$sMsgTitle='Ошибка!';
$sMsg='Нет доступа!';
}
} else {
$sMsgTitle='Ошибка!';
$sMsg='Необходимо авторизоваться!';
}
$GLOBALS['_RESULT'] = array(
"bStateError" => $bStateError,
"sMsgTitle" => $sMsgTitle,
"sMsg" => $sMsg,
"sCommentText" => $sCommentText,
);
?>
<pre>
<b>Request method:</b> <?=$_SERVER['REQUEST_METHOD'] . "\n"?>
<b>Loader used:</b> <?=$JsHttpRequest->LOADER . "\n"?>
<b>_REQUEST:</b> <?=print_r($_REQUEST, 1)?>
</pre>

View file

@ -69,12 +69,12 @@
<div class="blog_page">
<img class="blog_avatar" src="{$oBlog->getAvatarPath(48)}" width="48" height="48" alt="" title="{$oBlog->getTitle()|escape:'html'}" border="0">
<a href="{$DIR_WEB_ROOT}/blog/{$oBlog->getUrl()}/profile/">{$oBlog->getTitle()|escape:'html'}</a>
(<a id="groupuserscnt" href="{$DIR_WEB_ROOT}/blog/{$oBlog->getUrl()}/profile/"><span id="blog_user_count">{$oBlog->getCountUser()}</span></a>)
(<a id="groupuserscnt" href="{$DIR_WEB_ROOT}/blog/{$oBlog->getUrl()}/profile/"><span id="blog_user_count_{$oBlog->getId()}">{$oBlog->getCountUser()}</span></a>)
{if $oUserCurrent and $oUserCurrent->getId()!=$oBlog->getOwnerId()}
<span id="blog_action_join" {if !$bNeedJoin}style="display: none;"{/if}>
<span id="blog_action_join_{$oBlog->getId()}" {if !$bNeedJoin}style="display: none;"{/if}>
<a href="#" onclick="ajaxJoinLeaveBlog({$oBlog->getId()},'join'); return false;" title="вступить в блог"><img src="{$DIR_STATIC_SKIN}/img/blog_join.gif" border="0" alt="вступить"></a>
</span>
<span id="blog_action_leave" {if $bNeedJoin}style="display: none;"{/if}>
<span id="blog_action_leave_{$oBlog->getId()}" {if $bNeedJoin}style="display: none;"{/if}>
<a href="#" onclick="ajaxJoinLeaveBlog({$oBlog->getId()},'leave'); return false;" title="покинуть блог"><img src="{$DIR_STATIC_SKIN}/img/blog_leave.gif" border="0" alt="покинуть"></a>
</span>
{/if}

View file

@ -70,13 +70,13 @@
<div class="blog_page">
<img class="blog_avatar" src="{$oBlog->getAvatarPath(48)}" width="48" height="48" alt="" title="{$oBlog->getTitle()|escape:'html'}" border="0">
<a href="{$DIR_WEB_ROOT}/blog/{$oBlog->getUrl()}/">{$oBlog->getTitle()|escape:'html'}</a>
(<a id="groupuserscnt" href="{$DIR_WEB_ROOT}/blog/{$oBlog->getUrl()}/profile/" title="подписчиков"><span id="blog_user_count">{$oBlog->getCountUser()}</span></a>)
(<a id="groupuserscnt" href="{$DIR_WEB_ROOT}/blog/{$oBlog->getUrl()}/profile/" title="подписчиков"><span id="blog_user_count_{$oBlog->getId()}">{$oBlog->getCountUser()}</span></a>)
{if $oUserCurrent and $oUserCurrent->getId()!=$oBlog->getOwnerId()}
<span id="blog_action_join" {if !$bNeedJoin}style="display: none;"{/if}>
<span id="blog_action_join_{$oBlog->getId()}" {if !$bNeedJoin}style="display: none;"{/if}>
<a href="#" onclick="ajaxJoinLeaveBlog({$oBlog->getId()},'join'); return false;" title="вступить в блог"><img src="{$DIR_STATIC_SKIN}/img/blog_join.gif" border="0" alt="вступить"></a>
</span>
<span id="blog_action_leave" {if $bNeedJoin}style="display: none;"{/if}>
<span id="blog_action_leave_{$oBlog->getId()}" {if $bNeedJoin}style="display: none;"{/if}>
<a href="#" onclick="ajaxJoinLeaveBlog({$oBlog->getId()},'leave'); return false;" title="покинуть блог"><img src="{$DIR_STATIC_SKIN}/img/blog_leave.gif" border="0" alt="покинуть"></a>
</span>
{/if}

View file

@ -0,0 +1,51 @@
{include file='header.tpl'}
<BR>
<div class="habrablock">
<table width="100%" border="0" cellpadding="5" cellspacing="1" class="story_text" style="width:100%!important;">
<tr>
<td width="2%" align="center"></td>
<td width="53%" align="left" class="blog_page_tb_header">Блог</td>
{if $oUserCurrent}
<td width="10%" align="center" class="blog_page_tb_header">Вступить / Покинуть</td>
{/if}
<td width="10%" align="center" class="blog_page_tb_header">Читатели</td>
<td width="15%" align="center" class="blog_page_tb_header">Рейтинг</td>
</tr>
{foreach from=$aBlogs item=oBlog}
<tr valign="top">
<td align="center"><img src="{$oBlog->getAvatarPath(24)}" width="24" height="24" alt="" title="{$oBlog->getTitle()|escape:'html'}" border="0"></td>
<td align="left"><a href="{$DIR_WEB_ROOT}/blog/{$oBlog->getUrl()}/" class="blog_headline_pop">{$oBlog->getTitle()|escape:'html'}</a><br>
<span class="sf_page_nickname">смотритель:</span>&nbsp;
<a href="{$DIR_WEB_ROOT}/profile/{$oBlog->getUserLogin()}/"><img src="{$DIR_STATIC_SKIN}/img/user.gif" width="11" height="11" border="0" alt="посмотреть профиль" title="посмотреть профиль"></a><a href="{$DIR_WEB_ROOT}/profile/{$oBlog->getUserLogin()}/" class="sf_page_nickname">{$oBlog->getUserLogin()}</a>
</td>
{if $oUserCurrent}
<td nowrap align="center">
{if $oUserCurrent->getId()!=$oBlog->getOwnerId()}
<span id="blog_action_join_{$oBlog->getId()}" {if $oBlog->getCurrentUserIsJoin()}style="display: none;"{/if}>
<a href="#" onclick="ajaxJoinLeaveBlog({$oBlog->getId()},'join'); return false;" title="вступить в блог"><img src="{$DIR_STATIC_SKIN}/img/blog_join.gif" border="0" alt="вступить"></a>
</span>
<span id="blog_action_leave_{$oBlog->getId()}" {if !$oBlog->getCurrentUserIsJoin()}style="display: none;"{/if}>
<a href="#" onclick="ajaxJoinLeaveBlog({$oBlog->getId()},'leave'); return false;" title="покинуть блог"><img src="{$DIR_STATIC_SKIN}/img/blog_leave.gif" border="0" alt="покинуть"></a>
</span>
{/if}
</td>
{/if}
<td nowrap align="center"><a href="{$DIR_WEB_ROOT}/blog/{$oBlog->getUrl()}/profile/" class="blog_popular_link" id="blog_user_count_{$oBlog->getId()}">{$oBlog->getCountUser()}</a></td>
<td nowrap align="center"><span class="blog_rating">&nbsp;{$oBlog->getRating()}&nbsp;</span></td>
</tr>
{/foreach}
</table>
</div>
{include file='paging.tpl' aPaging=`$aPaging`}
{include file='footer.tpl'}

View file

@ -13,7 +13,7 @@
</tr>
{foreach from=$aBlogs item=oBlog}
<tr>
<td align="center"></td>
<td align="center"><img src="{$oBlog->getAvatarPath(24)}" width="24" height="24" alt="" title="{$oBlog->getTitle()|escape:'html'}" border="0"></td>
<td align="left"><a href="{$DIR_WEB_ROOT}/blog/{$oBlog->getUrl()}/" class="blog_headline_pop">{$oBlog->getTitle()|escape:'html'}</a><br>
<span class="sf_page_nickname">смотритель:</span>&nbsp;
<a href="{$DIR_WEB_ROOT}/profile/{$oBlog->getUserLogin()}/"><img src="{$DIR_STATIC_SKIN}/img/user.gif" width="11" height="11" border="0" alt="посмотреть профиль" title="посмотреть профиль"></a><a href="{$DIR_WEB_ROOT}/profile/{$oBlog->getUserLogin()}/" class="sf_page_nickname">{$oBlog->getUserLogin()}</a>

View file

@ -16,5 +16,9 @@
{/foreach}
</table> <br>
</div>
</div>
<div class="live_section_title_all" align="right">
<span style="color:#666666">&#187;</span> <a href="{$DIR_WEB_ROOT}/blogs/">все блоги</a>
</div>
</div>

Binary file not shown.

After

Width:  |  Height:  |  Size: 869 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 539 B

View file

@ -96,15 +96,15 @@ function ajaxJoinLeaveBlog(idBlog,type) {
} else {
msgNoticeBox.alert(req.responseJS.sMsgTitle,req.responseJS.sMsg);
document.getElementById('blog_user_count').innerHTML=req.responseJS.iCountUser;
document.getElementById('blog_user_count_'+idBlog).innerHTML=req.responseJS.iCountUser;
if (req.responseJS.sState=='join') {
document.getElementById('blog_action_join').style.display="none";
document.getElementById('blog_action_leave').style.display="inline";
document.getElementById('blog_action_join_'+idBlog).style.display="none";
document.getElementById('blog_action_leave_'+idBlog).style.display="inline";
}
if (req.responseJS.sState=='leave') {
document.getElementById('blog_action_join').style.display="inline";
document.getElementById('blog_action_leave').style.display="none";
document.getElementById('blog_action_join_'+idBlog).style.display="inline";
document.getElementById('blog_action_leave_'+idBlog).style.display="none";
}
}