www_archline_hu/deployed/smartshoutbox/components/com_smartshoutbox/controller.php
LÁZÁR Imre AI Agent a8e6138d0d feat(deployed): add Smart Shoutbox 3.0.6 (no-source, vetted live)
Smart Shoutbox (The Krotek); no repo -> deployed files.

Signed-off-by: LÁZÁR Imre <imre@illusion.hu>
Assisted-by: claude-code@claude-opus-4-8
2026-07-16 11:24:46 +02:00

237 lines
6.5 KiB
PHP

<?php
/*------------------------------------------------------------------------
# Smart Shoutbox
# ------------------------------------------------------------------------
# The Krotek
# Copyright (C) 2011-2018 The Krotek. All Rights Reserved.
# @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
# Website: https://thekrotek.com
# Support: support@thekrotek.com
-------------------------------------------------------------------------*/
defined('_JEXEC') or die('Restricted access');
class SmartShoutboxController extends JControllerLegacy
{
var $app, $params, $post, $model;
public function __construct($config = array())
{
$this->app = JFactory::getApplication();
$this->params = JComponentHelper::getParams(SCOMPONENT);
$this->post = $this->app->input->post;
if (!class_exists('SmartShoutboxModelMain')) {
require_once(JPATH_SITE.'/components/'.SCOMPONENT.'/models/main.php');
}
$this->model = new SmartShoutboxModelMain();
parent::__construct($config);
}
public function display($cachable = false, $urlparams = false)
{
if (!$this->app->input->get('view', '', 'cmd')) {
$this->app->input->set('view', 'chat');
}
if ($this->params->get('license_result', '')) {
$this->app->enqueueMessage($this->params->get('license_result'), 'error');
}
parent::display($cachable, $urlparams);
}
public function cron()
{
$this->model->helper->cron($this->app->input->get('secret', 0, 'cmd'));
jexit();
}
public function getShouts($data = array())
{
$data['shout_mode'] = $this->post->get('shout_mode', '', 'cmd');
$data['shout_task'] = $this->post->get('shout_task', '', 'cmd');
$data['lastshout'] = $this->post->get('lastshout', 0, 'int');
$data['category_id'] = $this->post->get('category_id', '', 'int');
$columns = $this->post->get('shoutcolumns', array(), 'array');
if ($data['shout_task'] == 'refresh') {
$data['lastshout'] = 0;
$this->model->syshelper->deleteCookie('lastshout');
}
$result = $this->model->getShouts($data);
if ($data['shout_mode'] != 'ajax') {
return $result;
} else {
if (isset($result['shouts']) && !isset($result['error'])) {
$result['shouts'] = array_reverse($this->displayShouts($result['shouts'], $columns));
}
echo json_encode($result);
}
jexit();
}
public function getShout()
{
$shout_id = $this->post->get('shout_id', 0, 'int');
$mode = $this->post->get('shout_mode', '', 'cmd');
echo json_encode($this->model->getShout($shout_id, $mode));
jexit();
}
public function addShout()
{
if ($this->params->get('debug', 0)) {
$fp = fopen(JPATH_SITE.'/components/'.SCOMPONENT.'/shouts.log', 'a+');
fwrite($fp, $this->post->get('author', '', 'string').": ".$this->post->get('message', '', 'raw')."\n");
fclose($fp);
}
$columns = $this->post->get('shoutcolumns', array(), 'array');
$data = array(
'lastshout' => $this->post->get('lastshout', 0, 'int'),
'category_id' => $this->post->get('category_id', 0, 'int'),
'author' => trim(strip_tags(htmlspecialchars($this->post->get('author', '', 'string')))),
'message' => $this->post->get('message', '', 'raw'),
'attachments' => $this->post->get('attachments', '', 'string'));
$result = $this->model->addShout($data);
if (isset($result['shouts']) && !isset($result['error'])) {
$result['shouts'] = array_reverse($this->displayShouts($result['shouts'], $columns));
}
echo json_encode($result);
jexit();
}
public function editShout()
{
$data = array(
'shout_id' => $this->post->get('shout_id', 0, 'int'),
'message' => $this->post->get('message', '', 'raw'),
'attachments' => $this->post->get('attachments', '', 'string'));
echo json_encode($this->model->editShout($data));
jexit();
}
public function displayShouts($shouts, $columns)
{
$result = array();
foreach ($shouts as $key => $shout) {
ob_start();
echo $this->model->displayShout($shout, $columns, $key + 1);
$result[] = array(
'id' => $shout['id'],
'category_id' => $shout['category_id'],
'shout' => str_replace(array("\r", "\n", "\t", "\v"), '', ob_get_contents()));
ob_end_clean();
}
return $result;
}
public function editAnnounce()
{
$data = array(
'target' => $this->post->get('target', 0, 'int'),
'announce' => $this->post->get('announce', '', 'raw'));
echo json_encode($this->model->editAnnounce($data));
jexit();
}
public function deleteShout()
{
$data = array(
'shout_id' => $this->post->get('shout_id', 0, 'int'),
'lastshout' => $this->post->get('lastshout', 0, 'int'),
'category_id' => $this->post->get('category_id', '', 'int'));
echo json_encode($this->model->deleteShout($data));
jexit();
}
public function likeShout()
{
echo json_encode($this->model->likeShout($this->post->get('shout_id', 0, 'int')));
jexit();
}
public function toggleBan()
{
$shout_id = $this->post->get('shout_id', 0, 'int');
echo json_encode($this->model->toggleBan($shout_id));
jexit();
}
public function upload()
{
if (!empty($_FILES['files']['name'][0])) {
$json = $this->model->syshelper->processAttachments($_FILES['files'], $this->params->get('filetypes'));
echo json_encode($json);
}
jexit();
}
public function filterShouts()
{
$author = $this->app->getUserStateFromRequest('filter.author', 'filter_author', '', 'string');
$this->app->setUserState('filter.author', $author);
$message = $this->app->getUserStateFromRequest('filter.message', 'filter_message', '', 'string');
$this->app->setUserState('filter.message', $message);
$date = $this->app->getUserStateFromRequest('filter.date', 'filter_date');
if ($date && (DateTime::createFromFormat(JText::_(SSTR.'FILTER_DATE'), $date) === FALSE)) {
if (strtotime($date) !== false) {
$date = date(JText::_(SSTR.'FILTER_DATE'), strtotime($date));
} else {
$date = "";
$this->app->enqueueMessage(JText::_(SSTR.'ERROR_DATE_INVALID'), 'error');
}
}
$this->app->setUserState('filter.date', $date);
$limit = $this->app->getUserStateFromRequest('filter.limit', 'filter_limit', '50', 'uint');
$this->app->setUserState('filter.limit', $limit);
$ordering = $this->app->getUserStateFromRequest('filter.ordering', 'filter_ordering', 'desc', 'cmd');
$this->app->setUserState('filter.ordering', $ordering);
$uri = JUri::getInstance();
$uri->setVar('option', SCOMPONENT);
$uri->setVar('view', 'chat');
$this->app->redirect(JRoute::_('index.php'.$uri->toString(array('query', 'fragment')), false));
}
}
?>