Skip to content

Commit

Permalink
Merge pull request #120 from mambax7/master
Browse files Browse the repository at this point in the history
Publisher 1.07 RC2
  • Loading branch information
mambax7 committed Jun 8, 2019
2 parents caedb15 + 6a08cb4 commit 88e3d53
Show file tree
Hide file tree
Showing 25 changed files with 137 additions and 60 deletions.
8 changes: 4 additions & 4 deletions admin/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@
$max_imgheight = $helper->getConfig('maximum_image_height');
$allowed_mimetypes = Publisher\Utility::getAllowedImagesTypes();
if (('' == $temp['tmp_name']) || !is_readable($temp['tmp_name'])) {
redirect_header('javascript:history.go(-1)', 2, _AM_PUBLISHER_FILEUPLOAD_ERROR);
redirect_header('<script>javascript:history.go(-1)</script>', 2, _AM_PUBLISHER_FILEUPLOAD_ERROR);
}

xoops_load('XoopsMediaUploader');
$uploader = new \XoopsMediaUploader(Publisher\Utility::getImageDir('category'), $allowed_mimetypes, $max_size, $max_imgwidth, $max_imgheight);
if ($uploader->fetchMedia($filename) && $uploader->upload()) {
$categoryObj->setVar('image', $uploader->getSavedFileName());
} else {
redirect_header('javascript:history.go(-1)', 2, _AM_PUBLISHER_FILEUPLOAD_ERROR . $uploader->getErrors());
redirect_header('<script>javascript:history.go(-1)</script>', 2, _AM_PUBLISHER_FILEUPLOAD_ERROR . $uploader->getErrors());
}
}
} else {
Expand Down Expand Up @@ -124,7 +124,7 @@
}

if (!$categoryObj->store()) {
redirect_header('javascript:history.go(-1)', 3, _AM_PUBLISHER_CATEGORY_SAVE_ERROR . Publisher\Utility::formatErrors($categoryObj->getErrors()));
redirect_header('<script>javascript:history.go(-1)</script>', 3, _AM_PUBLISHER_CATEGORY_SAVE_ERROR . Publisher\Utility::formatErrors($categoryObj->getErrors()));
}
// TODO : put this function in the category class
Publisher\Utility::saveCategoryPermissions($grpread, $categoryObj->categoryid(), 'category_read');
Expand All @@ -143,7 +143,7 @@
$categoryObj->setVar('parentid', $parentCat);

if (!$categoryObj->store()) {
redirect_header('javascript:history.go(-1)', 3, _AM_PUBLISHER_SUBCATEGORY_SAVE_ERROR . Publisher\Utility::formatErrors($categoryObj->getErrors()));
redirect_header('<script>javascript:history.go(-1)</script>', 3, _AM_PUBLISHER_SUBCATEGORY_SAVE_ERROR . Publisher\Utility::formatErrors($categoryObj->getErrors()));
}
// TODO : put this function in the category class
Publisher\Utility::saveCategoryPermissions($grpread, $categoryObj->categoryid(), 'category_read');
Expand Down
4 changes: 2 additions & 2 deletions admin/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function publisher_editFile($showmenu = false, $fileid = 0, $itemid = 0)
$fileObj = $helper->getHandler('File')->get($fileid);

if ($fileObj->notLoaded()) {
redirect_header('javascript:history.go(-1)', 1, _AM_PUBLISHER_NOFILESELECTED);
redirect_header('<script>javascript:history.go(-1)</script>', 1, _AM_PUBLISHER_NOFILESELECTED);
}

echo "<br>\n";
Expand Down Expand Up @@ -86,7 +86,7 @@ function publisher_editFile($showmenu = false, $fileid = 0, $itemid = 0)
$fileid = Request::getInt('fileid', 0, 'GET');
$itemid = Request::getInt('itemid', 0, 'GET');
if ((0 == $fileid) && (0 == $itemid)) {
redirect_header('javascript:history.go(-1)', 3, _AM_PUBLISHER_NOITEMSELECTED);
redirect_header('<script>javascript:history.go(-1)</script>', 3, _AM_PUBLISHER_NOITEMSELECTED);
}

Publisher\Utility::cpHeader();
Expand Down
4 changes: 2 additions & 2 deletions admin/item.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@

// Storing the item
if (!$itemObj->store()) {
redirect_header('javascript:history.go(-1)', 3, $error_msg . Publisher\Utility::formatErrors($itemObj->getErrors()));
redirect_header('<script>javascript:history.go(-1)</script>', 3, $error_msg . Publisher\Utility::formatErrors($itemObj->getErrors()));
}

// attach file if any
if (($item_upload_file = Request::getArray('item_upload_file', '', 'FILES')) && '' !== $item_upload_file['name']) {
$file_upload_result = Publisher\Utility::uploadFile(false, false, $itemObj);
if (true !== $file_upload_result) {
redirect_header('javascript:history.go(-1)', 3, $file_upload_result);
redirect_header('<script>javascript:history.go(-1)</script>', 3, $file_upload_result);
}
}

Expand Down
16 changes: 15 additions & 1 deletion blocks/category_items_sel.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,23 @@ function publisher_category_items_sel_show($options)
continue;
}

$criteria = new \Criteria('categoryid', $catId);
// $criteria = new \Criteria('categoryid', $catId);


$criteria = new \CriteriaCompo();
$criteria->add(new \Criteria('categoryid', $catId));



/** @var Publisher\ItemHandler $itemHandler */
$itemHandler = $helper->getHandler('Item');

$publisherIsAdmin = $helper->isUserAdmin();
if (!$publisherIsAdmin) {
$criteriaDateSub = new \Criteria('datesub', time(), '<=');
$criteria->add($criteriaDateSub);
}

$items = $itemHandler->getItems($limit, $start, [Constants::PUBLISHER_STATUS_PUBLISHED], -1, $sort, $order, '', true, $criteria, true);
unset($criteria);

Expand Down
18 changes: 18 additions & 0 deletions blocks/items_new.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,25 @@ function publisher_items_new_show($options)
} else {
$criteria = new \CriteriaCompo();
$criteria->add(new \Criteria('categoryid', '(' . $options[0] . ')', 'IN'));

}


$publisherIsAdmin = $helper->isUserAdmin();
if (!$publisherIsAdmin) {
if (null === $criteria) {
$criteria = new \CriteriaCompo();
}
$criteriaDateSub = new \Criteria('datesub', time(), '<=');
$criteria->add($criteriaDateSub);
}

// $optCatItems = (int)$options[2];
// $categoryId = -1;
// $categoryItemsObj = $itemHandler->getAllPublished($optCatItems, 0, $categoryId);



$itemsObj = $itemHandler->getItems($limit, $start, [Constants::PUBLISHER_STATUS_PUBLISHED], -1, $sort, $order, '', true, $criteria, 'none');

$totalitems = count($itemsObj);
Expand Down
11 changes: 11 additions & 0 deletions blocks/items_recent.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,18 @@ function publisher_items_recent_show($options)
} else {
$criteria = new \CriteriaCompo();
$criteria->add(new \Criteria('categoryid', '(' . $options[0] . ')', 'IN'));

}

$publisherIsAdmin = $helper->isUserAdmin();
if (!$publisherIsAdmin) {
if (null === $criteria) {
$criteria = new \CriteriaCompo();
}
$criteriaDateSub = new \Criteria('datesub', time(), '<=');
$criteria->add($criteriaDateSub);
}

$itemsObj = $itemHandler->getItems($limit, $start, [Constants::PUBLISHER_STATUS_PUBLISHED], -1, $sort, $order, '', true, $criteria, 'none');

$totalItems = count($itemsObj);
Expand Down
9 changes: 9 additions & 0 deletions blocks/latest_news.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ function publisher_latest_news_show($options)
$criteria->add(new \Criteria('itemid', '(' . $selectedStories . ')', 'IN'));
}

$publisherIsAdmin = $helper->isUserAdmin();
if (!$publisherIsAdmin) {
if (null === $criteria) {
$criteria = new \CriteriaCompo();
}
$criteriaDateSub = new \Criteria('datesub', time(), '<=');
$criteria->add($criteriaDateSub);
}

$itemsObj = $itemHandler->getItems($limit, $start, [Constants::PUBLISHER_STATUS_PUBLISHED], -1, $sort, $order, '', true, $criteria, 'itemid');

$scount = count($itemsObj);
Expand Down
4 changes: 2 additions & 2 deletions category.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@

// if the selected category was not found, exit
if (!is_object($categoryObj) || $categoryObj->notLoaded()) {
redirect_header('javascript:history.go(-1)', 1, _MD_PUBLISHER_NOCATEGORYSELECTED);
redirect_header('<script>javascript:history.go(-1)</script>', 1, _MD_PUBLISHER_NOCATEGORYSELECTED);
}

// Check user permissions to access this category
if (!$categoryObj->checkPermission()) {
redirect_header('javascript:history.go(-1)', 1, _NOPERM);
redirect_header('<script>javascript:history.go(-1)</script>', 1, _NOPERM);
}

// At which record shall we start
Expand Down
2 changes: 2 additions & 0 deletions class/BaseObjectHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class BaseObjectHandler extends \XoopsPersistableObjectHandler
protected $idfield = 'id';

public $helper = null;
public $publisherIsAdmin = null;


/**
* @param \XoopsDatabase|null $db
Expand Down
7 changes: 3 additions & 4 deletions class/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,8 @@ public function notLoaded()
*/
public function checkPermission()
{
// global $publisherIsAdmin;
$ret = false;
if ($GLOBALS['publisherIsAdmin']) {
if (Publisher\Utility::userIsAdmin()) {
return true;
}
if (is_object($GLOBALS['xoopsUser']) && $GLOBALS['xoopsUser']->getVar('uid') == $this->moderator) {
Expand Down Expand Up @@ -181,7 +180,7 @@ public function getCategoryPath($withAllLink = true)
}
catch (\Exception $e) {
$this->helper->addLog($e);
// redirect_header('javascript:history.go(-1)', 1, _NOPERM);
// redirect_header('<script>javascript:history.go(-1)</script>', 1, _NOPERM);
}

$ret = $parentObj->getCategoryPath($withAllLink) . ' <li> ' . $ret . '</li>';
Expand Down Expand Up @@ -214,7 +213,7 @@ public function getCategoryPathForMetaTitle()
}
catch (\Exception $e) {
$this->helper->addLog($e);
// redirect_header('javascript:history.go(-1)', 1, _NOPERM);
// redirect_header('<script>javascript:history.go(-1)</script>', 1, _NOPERM);
}

$ret = $parentObj->getCategoryPath(false);
Expand Down
22 changes: 11 additions & 11 deletions class/CategoryHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class CategoryHandler extends \XoopsPersistableObjectHandler
* @var Helper
*/
public $helper;
public $publisherIsAdmin;

/**
* @param \XoopsDatabase $db
Expand All @@ -50,6 +51,7 @@ public function __construct(\XoopsDatabase $db = null, $helper = null)
{
/** @var \XoopsModules\Publisher\Helper $this->helper */
$this->helper = $helper;
$publisherIsAdmin = $this->helper->isUserAdmin();
parent::__construct($db, 'publisher_categories', Category::class, 'categoryid', 'name');
}

Expand Down Expand Up @@ -190,14 +192,13 @@ public function &getObjects(\CriteriaElement $criteria = null, $idAsKey = false,
*/
public function &getCategories($limit = 0, $start = 0, $parentid = 0, $sort = 'weight', $order = 'ASC', $idAsKey = true)
{
// global $publisherIsAdmin;
$criteria = new \CriteriaCompo();
$criteria = new \CriteriaCompo();
$criteria->setSort($sort);
$criteria->setOrder($order);
if (-1 != $parentid) {
$criteria->add(new \Criteria('parentid', $parentid));
}
if (!$GLOBALS['publisherIsAdmin']) {
if (!$this->publisherIsAdmin) {
/** @var Publisher\PermissionHandler $permissionHandler */
$permissionHandler = $this->helper->getHandler('Permission');
$categoriesGranted = $permissionHandler->getGrantedItems('category_read');
Expand Down Expand Up @@ -244,12 +245,12 @@ public function getSubCatArray($category, $level, $catArray, $catResult)
*/
public function &getCategoriesForSubmit()
{
global $publisherIsAdmin, $theresult;
global $theresult;
$ret = [];
$criteria = new \CriteriaCompo();
$criteria->setSort('name');
$criteria->setOrder('ASC');
if (!$publisherIsAdmin) {
if (!$this->publisherIsAdmin) {
$categoriesGranted = $this->helper->getHandler('Permission')->getGrantedItems('item_submit');
if (count($categoriesGranted) > 0) {
$criteria->add(new \Criteria('categoryid', '(' . implode(',', $categoriesGranted) . ')', 'IN'));
Expand Down Expand Up @@ -286,12 +287,13 @@ public function &getCategoriesForSubmit()
*/
public function getCategoriesForSearch()
{
global $publisherIsAdmin, $theresult;
global $theresult;

$ret = [];
$criteria = new \CriteriaCompo();
$criteria->setSort('name');
$criteria->setOrder('ASC');
if (!$publisherIsAdmin) {
if (!$this->publisherIsAdmin) {
$categoriesGranted = $this->helper->getHandler('Permission')->getGrantedItems('category_read');
if (count($categoriesGranted) > 0) {
$criteria->add(new \Criteria('categoryid', '(' . implode(',', $categoriesGranted) . ')', 'IN'));
Expand Down Expand Up @@ -330,14 +332,13 @@ public function getCategoriesForSearch()
*/
public function getCategoriesCount($parentid = 0)
{
// global $publisherIsAdmin;
if (-1 == $parentid) {
return $this->getCount();
}
$criteria = new \CriteriaCompo();
if (isset($parentid) && (-1 != $parentid)) {
$criteria->add(new \Criteria('parentid', $parentid));
if (!$GLOBALS['publisherIsAdmin']) {
if (!$this->publisherIsAdmin) {
$categoriesGranted = $this->helper->getHandler('Permission')->getGrantedItems('category_read');
if (count($categoriesGranted) > 0) {
$criteria->add(new \Criteria('categoryid', '(' . implode(',', $categoriesGranted) . ')', 'IN'));
Expand All @@ -362,10 +363,9 @@ public function getCategoriesCount($parentid = 0)
*/
public function getSubCats($categories)
{
// global $publisherIsAdmin;
$criteria = new \CriteriaCompo(new \Criteria('parentid', '(' . implode(',', array_keys($categories)) . ')', 'IN'));
$ret = [];
if (!$GLOBALS['publisherIsAdmin']) {
if (!$this->publisherIsAdmin) {
$categoriesGranted = $this->helper->getHandler('Permission')->getGrantedItems('category_read');
if (count($categoriesGranted) > 0) {
$criteria->add(new \Criteria('categoryid', '(' . implode(',', $categoriesGranted) . ')', 'IN'));
Expand Down
28 changes: 18 additions & 10 deletions class/ItemHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

use XoopsModules\Publisher;

//namespace Publisher;

// defined('XOOPS_ROOT_PATH') || die('Restricted access');
require_once dirname(__DIR__) . '/include/common.php';

Expand All @@ -42,6 +40,7 @@ class ItemHandler extends \XoopsPersistableObjectHandler
* @var Publisher\Helper
*/
public $helper;
public $publisherIsAdmin;

protected $resultCatCounts = [];

Expand All @@ -53,6 +52,7 @@ public function __construct(\XoopsDatabase $db = null, $helper = null)
{
/** @var Publisher\Helper $this->helper */
$this->helper = $helper;
$this->publisherIsAdmin = $this->helper->isUserAdmin();
parent::__construct($db, 'publisher_items', Item::class, 'itemid', 'title');
}

Expand Down Expand Up @@ -311,9 +311,8 @@ private function getItemsCriteria($categoryid = -1, $status = '', $notNullFields
*/
public function getItemsCount($categoryid = -1, $status = '', $notNullFields = '')
{
// global $publisherIsAdmin;
$criteriaPermissions = null;
if (!$GLOBALS['publisherIsAdmin']) {
if (!$this->publisherIsAdmin) {
$criteriaPermissions = new \CriteriaCompo();
// Categories for which user has access
$categoriesGranted = $this->helper->getHandler('Permission')->getGrantedItems('category_read');
Expand All @@ -326,6 +325,15 @@ public function getItemsCount($categoryid = -1, $status = '', $notNullFields = '
}
// $ret = array();
$criteria = $this->getItemsCriteria($categoryid, $status, $notNullFields, $criteriaPermissions);

// $publisherIsAdmin = $this->helper->isUserAdmin(); //mb
// if (!$this->publisherIsAdmin) {
// $criteriaDateSub = new \Criteria('datesub', time(), '<=');
// $criteria->add($criteriaDateSub);
// }



/*
if (isset($categoryid) && $categoryid != -1) {
$criteriaCategory = new \Criteria('categoryid', $categoryid);
Expand Down Expand Up @@ -371,8 +379,10 @@ public function getAllPublished($limit = 0, $start = 0, $categoryid = -1, $sort
{

$otherCriteria = new \CriteriaCompo();
$criteriaDateSub = new \Criteria('datesub', time(), '<=');
$otherCriteria->add($criteriaDateSub);
if (!$this->publisherIsAdmin) {
$criteriaDateSub = new \Criteria('datesub', time(), '<=');
$otherCriteria->add($criteriaDateSub);
}
if ($excludeExpired) {
// by default expired items are excluded from list of published items
$criteriaExpire = new \CriteriaCompo();
Expand Down Expand Up @@ -509,9 +519,8 @@ public function getAllRejected($limit = 0, $start = 0, $categoryid = -1, $sort =
*/
public function getItems($limit = 0, $start = 0, $status = '', $categoryid = -1, $sort = 'datesub', $order = 'DESC', $notNullFields = '', $asObject = true, $otherCriteria = null, $idKey = 'none')
{
// global $publisherIsAdmin;
$criteriaPermissions = null;
if (!$GLOBALS['publisherIsAdmin']) {
if (!$this->publisherIsAdmin) {
$criteriaPermissions = new \CriteriaCompo();
// Categories for which user has access
$categoriesGranted = $this->helper->getHandler('Permission')->getGrantedItems('category_read');
Expand Down Expand Up @@ -659,7 +668,6 @@ public function notNullFieldClause($notNullFields = '', $withAnd = false)
*/
public function getItemsFromSearch($queryArray = [], $andor = 'AND', $limit = 0, $offset = 0, $userid = 0, $categories = [], $sortby = 0, $searchin = '', $extra = '')
{
// global $publisherIsAdmin;
$count = 0;
$ret = [];
$criteriaKeywords = $criteriaPermissions = $criteriaUser = null;
Expand Down Expand Up @@ -705,7 +713,7 @@ public function getItemsFromSearch($queryArray = [], $andor = 'AND', $limit = 0,
unset($criteriaKeyword);
}
}
if (!$GLOBALS['publisherIsAdmin'] && (count($categories) > 0)) {
if (!$this->publisherIsAdmin && (count($categories) > 0)) {
$criteriaPermissions = new \CriteriaCompo();
// Categories for which user has access
$categoriesGranted = $grouppermHandler->getItemIds('category_read', $groups, $this->helper->getModule()->getVar('mid'));
Expand Down
Loading

0 comments on commit 88e3d53

Please sign in to comment.