Файл: InstantSocial/uploud/plugins/p_usertab/plugin.php
Строк: 100
<?php
/******************************************************************************/
// //
// InstantCMS v1.9 //
// http://www.instantcms.ru/ //
// //
// written by InstantCMS Team, 2007-2011 //
// produced by InstantSoft, (www.instantsoft.ru) //
// //
// LICENSED BY GNU/GPL v2 //
// //
/******************************************************************************/
class p_usertab extends cmsPlugin {
// ==================================================================== //
public function __construct(){
parent::__construct();
// Информация о плагине
$this->info['plugin'] = 'p_usertab';
$this->info['title'] = 'Demo Profile Plugin';
$this->info['description'] = 'Пример плагина - Добавляет вкладку "Статьи" в профили всех пользователей';
$this->info['author'] = 'InstantCMS Team';
$this->info['version'] = '1.0';
$this->info['tab'] = 'Статьи'; //-- Заголовок закладки в профиле
// Настройки по-умолчанию
$this->config['Количество статей'] = 10;
// События, которые будут отлавливаться плагином
$this->events[] = 'USER_PROFILE';
$this->events[] = 'LOAD_PROFILE_CONTENT';
}
// ==================================================================== //
/**
* Процедура установки плагина
* @return bool
*/
public function install(){
return parent::install();
}
// ==================================================================== //
/**
* Процедура обновления плагина
* @return bool
*/
public function upgrade(){
$inDB = cmsDatabase::getInstance();
if (!$inDB->isFieldExists('cms_event_hooks', 'LOAD_PROFILE_CONTENT')){
$inDB->query("NSERT INTO cms_event_hooks (id, event, plugin_id) VALUES (id,'LOAD_PROFILE_CONTENT',6 )");
}
return parent::upgrade();
}
// ==================================================================== //
/**
* Обработка событий
* @param string $event
* @param array $user
* @return html
*/
public function execute($event, $user){
parent::execute();
$inCore = cmsCore::getInstance();
$items = array();
$user_id = $user['id'];
$limit = $this->config['Количество статей'];
$inCore->loadModel('content');
$model = new cms_model_content();
$page = isset($user['page']) ? $user['page'] : 1;
$perpage = 5;
$model->limitPage($page, $perpage);
$sql = "SELECT i.id, i.title, i.hits, i.pubdate, i.seolink, i.description, cat.title as cat_title, cat.seolink as cat_url
FROM cms_content i
LEFT JOIN cms_category cat ON cat.id = i.category_id
WHERE i.user_id = {$user_id} AND cat.parent_id = 6 AND i.published = 1
ORDER BY i.pubdate DESC
LIMIT ".(($page-1)*$perpage).", $limit";
$result = $this->inDB->query($sql);
$total = $this->inDB->num_rows($result);
if ($total){
while($item = $this->inDB->fetch_assoc($result)){
$item['url'] = $model->getArticleURL(null, $item['seolink']);
$item['comments'] = $inCore->getCommentsCount('article', $item['id']);
$item['image'] = (file_exists(PATH.'/images/photos/small/article'.$item['id'].'.jpg') ? 'article'.$item['id'].'.jpg' : '/images/catalog/small/nopic.jpg');
$items[] = $item;
}
}
if ($total > $perpage){
$pages_url = 'javascript:getContent(%page%)';
$pagebar = cmsPage::getPagebar($total, $page, $perpage, $pages_url);
} else {
$pagebar = '';
}
ob_start();
$smarty= $this->inCore->initSmarty('plugins', 'p_usertab.tpl');
$smarty->assign('total', $total);
$smarty->assign('user_id', $user['id']);
$smarty->assign('items', $items);
$smarty->assign('pagebar', $pagebar);
$smarty->display('p_usertab.tpl');
$html = ob_get_clean();
return $html;
}
// ==================================================================== //
}
?>