Skip to content

Commit e4f11cf

Browse files
authored
Merge pull request #24 from mambax7/master
Updates/fixes by Zyspec & Mamba
2 parents fb46c91 + 2a6750d commit e4f11cf

147 files changed

Lines changed: 3740 additions & 1730 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitattributes

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
*.cs diff=csharp
66

77
# Standard to msysgit
8-
*.doc diff=astextplain
9-
*.DOC diff=astextplain
8+
*.doc diff=astextplain
9+
*.DOC diff=astextplain
1010
*.docx diff=astextplain
1111
*.DOCX diff=astextplain
1212
*.dot diff=astextplain
1313
*.DOT diff=astextplain
1414
*.pdf diff=astextplain
15-
*.PDF diff=astextplain
16-
*.rtf diff=astextplain
17-
*.RTF diff=astextplain
15+
*.PDF diff=astextplain
16+
*.rtf diff=astextplain
17+
*.RTF diff=astextplain

.scrutinizer.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# language: php
22
build:
3+
environment:
4+
php: 8.0.11
35
nodes:
46
tests: true
57
analysis:
@@ -17,3 +19,4 @@ build:
1719
filter:
1820
dependency_paths:
1921
- XoopsCore25/*
22+
- tag/*

CONTRIBUTING.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
![alt XOOPS CMS](https://xoops.org/images/logoXoops4GithubRepository.png)
1+
![alt XOOPS CMS](https://xoops.org/images/logoXoopsPhp8.png)
22
# Contributing to [XOOPS CMS](https://xoops.org)
33
[![XOOPS CMS Module](https://img.shields.io/badge/XOOPS%20CMS-Module-blue.svg)](https://xoops.org)
4-
[![Software License](https://img.shields.io/badge/license-GPL-brightgreen.svg?style=flat)](http://www.gnu.org/licenses/gpl-2.0.html)
4+
[![Software License](https://img.shields.io/badge/license-GPL-brightgreen.svg?style=flat)](https://www.gnu.org/licenses/gpl-2.0.html)
55

66
Contributions are **welcome** and will be fully **credited**.
77

8-
We accept contributions via Pull Requests on [Github](https://github.com/XoopsModules25x/xoopseditors).
8+
We accept contributions via Pull Requests on [Github](https://github.com/XoopsModules25x/tag).
99

1010
## Pull Requests
1111

12-
- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer).
13-
- **Add tests!** - We encourage to provide tests for your contributions.
14-
- **Document any change in behavior** - Make sure the `/docs/changelog.txt` and any other relevant documentation are kept up-to-date.
12+
- **[PSR-12 Coding Standard](https://www.php-fig.org/psr/psr-12/)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer).
13+
- **Add tests!** - We encourage providing tests for your contributions.
14+
- **Document any change in behavior** - Make sure the `/docs/changelog.txt` and any other relevant documentation are up-to-date.
1515
- **Consider our release cycle** - We try to follow [Semantic Versioning v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.
1616
- **Create feature branches** - Don't ask us to pull from your master branch.
1717
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
1818
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please squash them before submitting.
1919

20-
**Happy coding, and _May the Source be with You_!**
20+
Happy coding, and **_May the Source be with You_**!

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
![alt XOOPS CMS](https://xoops.org/images/logoXoops4GithubRepository.png)
2-
## Tag module for [XOOPS CMS 2.5.9+](https://xoops.org)
1+
![alt XOOPS CMS](https://xoops.org/images/logoXoopsPhp8.png)
2+
## Tag module for [XOOPS CMS 2.5.10+](https://xoops.org)
33
[![XOOPS CMS Module](https://img.shields.io/badge/XOOPS%20CMS-Module-blue.svg)](https://xoops.org)
4-
[![Software License](https://img.shields.io/badge/license-GPL-brightgreen.svg?style=flat)](http://www.gnu.org/licenses/gpl-2.0.html)
4+
[![Software License](https://img.shields.io/badge/license-GPL-brightgreen.svg?style=flat)](https://www.gnu.org/licenses/gpl-2.0.html)
55

66
[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/XoopsModules25x/tag.svg?style=flat)](https://scrutinizer-ci.com/g/XoopsModules25x/tag/?branch=master)
77
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/0fdcfa1725a14753865921b99bb3611e)](https://www.codacy.com/app/mambax7/tag_2)
88
[![Code Climate](https://img.shields.io/codeclimate/github/XoopsModules25x/tag.svg?style=flat)](https://codeclimate.com/github/XoopsModules25x/tag)
9-
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/0ffc2915-82a8-446a-978e-df50e2e58858/mini.png)](https://insight.sensiolabs.com/projects/0ffc2915-82a8-446a-978e-df50e2e58858)
10-
[![Latest Pre-Release](https://img.shields.io/github/tag/XoopsModules25x/tag.svg?style=flat)](https://github.com/XoopsModules25x/tag/tags/)
119
[![Latest Version](https://img.shields.io/github/release/XoopsModules25x/tag.svg?style=flat)](https://github.com/XoopsModules25x/tag/releases/)
1210

1311
**Tag module** for [XOOPS CMS](https://xoops.org) is designed for site-wide tag management, handling tag input, display and stats for each module that enables tag plugin.
@@ -19,4 +17,4 @@ To contribute to the Tutorial, [fork it on GitHub](https://github.com/XoopsDocs/
1917

2018
Please visit us on https://xoops.org
2119

22-
Current and upcoming "next generation" versions of XOOPS CMS are being crafted on GitHub at: https://github.com/XOOPS
20+
Current and upcoming "next generation" versions of XOOPS CMS are crafted on GitHub at: https://github.com/XOOPS

admin/about.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/**
1313
* XOOPS tag management module
1414
*
15-
* @package tag
15+
* @package XoopsModules\Tag
1616
* @copyright {@link http://sourceforge.net/projects/xoops/ The XOOPS Project}
1717
* @license {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
1818
* @author Mage
@@ -22,6 +22,7 @@
2222
require_once __DIR__ . '/admin_header.php';
2323
xoops_cp_header();
2424

25+
/** @var \Xmf\Module\Admin $adminObject */
2526
$adminObject->displayNavigation(basename(__FILE__));
2627
$adminObject::setPaypal('xoopsfoundation@gmail.com');
2728
$adminObject->displayAbout(false);

admin/admin.tag.php

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/**
1313
* XOOPS tag management module
1414
*
15-
* @package tag
15+
* @package XoopsModules\Tag
1616
* @copyright {@link http://sourceforge.net/projects/xoops/ The XOOPS Project}
1717
* @license {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
1818
* @author Taiwen Jiang <phppp@users.sourceforge.net>
@@ -26,30 +26,50 @@
2626
require_once __DIR__ . '/admin_header.php';
2727
require_once $GLOBALS['xoops']->path('/class/xoopsformloader.php');
2828

29-
$adminObject = \Xmf\Module\Admin::getInstance();
30-
3129
xoops_cp_header();
3230

33-
require_once $GLOBALS['xoops']->path('/modules/tag/include/vars.php');
31+
/** @var XoopsModules\Tag\Helper $helper */
32+
require_once $helper->path('include/vars.php');
33+
34+
/** @var Xmf\Module\Admin $adminObject */
3435
$adminObject->displayNavigation(basename(__FILE__));
3536

3637
$limit = $GLOBALS['xoopsModuleConfig']['items_perpage'];
3738
$modid = Request::getInt('modid', Constants::DEFAULT_ID);
3839
$start = Request::getInt('start', Constants::BEGINNING);
3940
$status = Request::getInt('status', Constants::STATUS_ALL, 'GET');
40-
///** @var \XoopsModules\Tag\TagHandler $tagHandler */
41-
//$tagHandler = xoops_getModuleHandler('tag', $moduleDirName);
42-
//$linkHandler = xoops_getModuleHandler('link', $moduleDirName);
4341

44-
/** @var Tag\TagHandler $tagHandler */
45-
/** @var Tag\LinkHandler $linkHandler */
42+
/**
43+
* @var XoopsModules\Tag\TagHandler $tagHandler
44+
* @var XoopsModules\Tag\LinkHandler $linkHandler
45+
*/
4646
$tagHandler = Tag\Helper::getInstance()->getHandler('Tag');
4747
$linkHandler = Tag\Helper::getInstance()->getHandler('Link');
4848

49-
$postTags = Request::getArray('tags', [], 'POST');
50-
if (!empty($postTags)) {
51-
$msgDBUpdated = '';
52-
foreach ($postTags as $tag => $tag_status) {
49+
$post_tags = Request::getArray('tags', [], 'POST');
50+
if (!empty($post_tags)) {
51+
$msg_db_updated = '';
52+
/** {@internal - Test using following code to reduce dB accesses }} */
53+
/*
54+
$postTagIdArray = array_keys($post_tags);
55+
$postTagIdArray = array_map('intval', $postTagIdArray);
56+
$postTagIdArray = array_unique($postTagIdArray);
57+
$criteria = new \Criteria('tag_id', '(' . implode(',', $postTagIdArray) . ')', 'IN');
58+
$tagObjArray = $tagHandler->getAll($criteria);
59+
foreach ($post_tags as $tagId => $postTagStatus) {
60+
if ($tagObjArray[$tagId]->isNew() || !$tagObjArray[$tagId]->getVar('tag_id')) {
61+
continue;
62+
}
63+
if ($postTagStatus < Constants::STATUS_ACTIVE) {
64+
$tagHandler->delete($tagObjArray[$tagId]);
65+
} elseif ($postTagStatus != $tagObjArray[$tagId]->getVar('tag_status')) {
66+
$tagObjArray[$tagId]->setVar('tag_status', $postTagStatus);
67+
$tagHandler->insert($tagObjArray[$tagId]);
68+
$msg_db_updated = _AM_TAG_DB_UPDATED;
69+
}
70+
}
71+
*/
72+
foreach ($post_tags as $tag => $tag_status) {
5373
$tag_obj = $tagHandler->get($tag);
5474
if (!($tag_obj instanceof Tag\Tag) || !$tag_obj->getVar('tag_id')) {
5575
continue;
@@ -59,18 +79,19 @@
5979
} elseif ($tag_status != $tag_obj->getVar('tag_status')) {
6080
$tag_obj->setVar('tag_status', $tag_status);
6181
$tagHandler->insert($tag_obj);
62-
$msgDBUpdated = _AM_TAG_DB_UPDATED;
82+
$msg_db_updated = _AM_TAG_DB_UPDATED;
6383
}
6484
}
65-
redirect_header("admin.tag.php?modid={$modid}&amp;start={$start}&amp;status={$status}", Constants::REDIRECT_DELAY_MEDIUM, $msgDBUpdated);
85+
$helper->redirect("admin/admin.tag.php?modid={$modid}&amp;start={$start}&amp;status={$status}", Constants::REDIRECT_DELAY_MEDIUM, $msg_db_updated);
6686
}
6787

68-
$sql = 'SELECT tag_modid, COUNT(DISTINCT tag_id) AS count_tag';
69-
$sql .= ' FROM ' . $GLOBALS['xoopsDB']->prefix('tag_link');
70-
$sql .= ' GROUP BY tag_modid';
7188
$counts_module = [];
7289
$module_list = [];
73-
$result = $GLOBALS['xoopsDB']->query($sql);
90+
91+
/** {#internal use direct SQL instead of Tag\TagHandler CRUD operations because XOOPS can't handle COUNT(DISTINCT xx) }} */
92+
$sql = 'SELECT tag_modid, COUNT(DISTINCT tag_id) AS count_tag' . ' FROM ' . $GLOBALS['xoopsDB']->prefix('tag_link') . ' GROUP BY tag_modid';
93+
$result = $GLOBALS['xoopsDB']->query($sql);
94+
7495
if (false === $result) {
7596
xoops_error($GLOBALS['xoopsDB']->error());
7697
} else {
@@ -83,8 +104,9 @@
83104
$module_list = $moduleHandler->getList(new \Criteria('mid', '(' . implode(', ', array_keys($counts_module)) . ')', 'IN'));
84105
}
85106
}
86-
87-
$opform = new \XoopsSimpleForm('', 'moduleform', xoops_getenv('PHP_SELF'), 'get', true);
107+
//
108+
$opform = new \XoopsSimpleForm('', 'moduleform', $_SERVER['SCRIPT_NAME'], 'get', true);
109+
//$opform = new \XoopsSimpleForm('', 'moduleform', xoops_getenv('SCRIPT_NAME'), 'post', true);
88110
$tray = new \XoopsFormElementTray('');
89111
$mod_select = new \XoopsFormSelect(_SELECT, 'modid', $modid);
90112
$mod_select->addOption(0, _ALL);
@@ -103,7 +125,7 @@
103125

104126
$criteria = new \CriteriaCompo();
105127
$criteria->setSort('a');
106-
$criteria->setOrder('ASC');
128+
$criteria->order = 'ASC'; // patch for XOOPS <= 2.5.10, does not set order correctly using setOrder() method
107129
$criteria->setStart($start);
108130
$criteria->setLimit($limit);
109131
if ($status >= Constants::STATUS_ACTIVE) {
@@ -112,12 +134,12 @@
112134
if (!empty($modid)) {
113135
$criteria->add(new \Criteria('l.tag_modid', $modid));
114136
}
115-
$tags = &$tagHandler->getByLimit(0, 0, $criteria, null, false);
137+
$tags = $tagHandler->getByLimit(0, 0, $criteria, null, false);
116138

117139
$form_tags = "<form name='tags' method='post' action='"
118-
. xoops_getenv('PHP_SELF')
140+
. $_SERVER['SCRIPT_NAME']
119141
. "'>\n"
120-
. "<table style='border-width: 0px; margin: 1px; padding: 4px;' cellspacing='1' class='outer width100'>\n"
142+
. "<table style='margin: 1px; padding: 4px;' class='outer width100 bnone bspacing1'>\n"
121143
. " <thead>\n"
122144
. " <tr class='txtcenter'>\n"
123145
. " <th class='bg3'>"
@@ -139,7 +161,6 @@
139161
$form_tags .= " <tr><td colspan='4'>" . _NONE . "</td></tr>\n";
140162
} else {
141163
$class_tr = 'odd';
142-
$i = 0;
143164
foreach (array_keys($tags) as $key) {
144165
$form_tags .= " <tr class='{$class_tr}'>\n"
145166
. ' <td>'
@@ -161,6 +182,7 @@
161182
. " </tr>\n";
162183
$class_tr = ('even' === $class_tr) ? 'odd' : 'even';
163184
}
185+
164186
if (!empty($start) || (count($tags) >= $limit)) {
165187
$count_tag = $tagHandler->getCount($criteria);
166188

admin/admin_footer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
/**
1313
* XOOPS tag management module
1414
*
15-
* @package tag
15+
* @package XoopsModules\Tag
1616
* @copyright {@link http://sourceforge.net/projects/xoops/ The XOOPS Project}
1717
* @license {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
1818
* @author Mamba {@link https://xoops.org}
1919
* @since 2.31
2020
*/
21-
$pathIcon32 = Xmf\Module\Admin::iconUrl('', 32);
21+
$pathIcon32 = Xmf\Module\Admin::iconUrl('', '32');
2222

23-
echo "<div class='adminfooter'>\n" . " <div style='text-align: center;'>\n" . " <a href='https://xoops.org' rel='external'><img src='{$pathIcon32}/xoopsmicrobutton.gif' alt='XOOPS' title='XOOPS'></a>\n" . " </div>\n" . ' ' . _AM_MODULEADMIN_ADMIN_FOOTER . "\n" . '</div>';
23+
echo "<div class='adminfooter'>\n" . "<div class='center'>\n" . " <a href='https://xoops.org' rel='external' target='_blank'><img src='{$pathIcon32}/xoopsmicrobutton.gif' 'alt='XOOPS' title='XOOPS'></a>\n" . "</div>\n" . _AM_MODULEADMIN_ADMIN_FOOTER . "\n" . "</div>\n";
2424

2525
xoops_cp_footer();

admin/admin_header.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,30 @@
1212
/**
1313
* XOOPS tag management module
1414
*
15+
* @package XoopsModules\Tag
1516
* @copyright XOOPS Project (https://xoops.org)
1617
* @license http://www.fsf.org/copyleft/gpl.html GNU public license
1718
* @since 1.00
1819
* @author Taiwen Jiang <phppp@users.sourceforge.net>
1920
* */
2021

21-
use XoopsModules\Tag;
22+
use Xmf\Module\Admin;
23+
use XoopsModules\Tag\Helper;
2224

23-
require_once dirname(dirname(dirname(__DIR__))) . '/include/cp_header.php';
24-
// require_once dirname(__DIR__) . '/class/constants.php';
25-
require_once dirname(__DIR__) . '/include/common.php';
25+
require \dirname(__DIR__) . '/preloads/autoloader.php';
2626

27-
$moduleDirName = basename(dirname(__DIR__));
28-
/** @var Tag\Helper $helper */
29-
$helper = Tag\Helper::getInstance();
27+
require \dirname(__DIR__, 3) . '/include/cp_header.php';
28+
// require_once \dirname(__DIR__) . '/class/constants.php';
29+
require_once \dirname(__DIR__) . '/include/common.php';
3030

31-
/** @var Xmf\Module\Admin $adminObject */
32-
$adminObject = \Xmf\Module\Admin::getInstance();
31+
/**
32+
* {@internal $helper defined in ./include/common.php }}
33+
*
34+
*/
35+
$helper = Helper::getInstance();
36+
37+
/** @var \Xmf\Module\Admin $adminObject */
38+
$adminObject = Admin::getInstance();
3339

3440
// Load language files
3541
$helper->loadLanguage('admin');

admin/index.php

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,39 @@
1212
/**
1313
* XOOPS tag management module
1414
*
15-
* @package tag
16-
* @subpackage admin
15+
* @package XoopsModules\Tag
1716
* @copyright {@link http://sourceforge.net/projects/xoops/ The XOOPS Project}
1817
* @license {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
1918
* @author Taiwen Jiang <phppp@users.sourceforge.net>
2019
* @since 1.00
2120
*/
2221

22+
use Xmf\Module\Admin;
2323
use XoopsModules\Tag;
24+
use XoopsModules\Tag\Utility;
2425

2526
require_once __DIR__ . '/admin_header.php';
26-
xoops_cp_header();
27-
require_once $GLOBALS['xoops']->path('/modules/tag/include/vars.php');
27+
/** @var XoopsModules\Tag\Helper $helper */
28+
require_once $helper->path('include/vars.php');
2829

29-
$adminObject = \Xmf\Module\Admin::getInstance();
30-
///** @var \XoopsModules\Tag\TagHandler $tagHandler */
31-
//$tagHandler = xoops_getModuleHandler('tag', $moduleDirName);
32-
/** @var Tag\TagHandler $tagHandler */
33-
$tagHandler = Tag\Helper::getInstance()->getHandler('Tag');
30+
xoops_cp_header();
3431

35-
$count_tag = $tagHandler->getCount();
32+
$adminObject = Admin::getInstance();
33+
/** @var XoopsModules\Tag\TagHandler $tagHandler */
34+
$tagHandler = $helper->getHandler('Tag');
35+
$count_tag = $tagHandler->getCount();
3636

37+
$linkHandler = $helper->getHandler('Link');
38+
$count_item = $linkHandler->getCount();
39+
/*
3740
$count_item = 0;
3841
$sql = 'SELECT COUNT(DISTINCT tl_id) FROM ' . $GLOBALS['xoopsDB']->prefix('tag_link');
3942
if (false === ($result = $GLOBALS['xoopsDB']->query($sql))) {
4043
xoops_error($GLOBALS['xoopsDB']->error());
4144
} else {
4245
list($count_item) = $GLOBALS['xoopsDB']->fetchRow($result);
4346
}
44-
47+
*/
4548
$sql = 'SELECT tag_modid, SUM(tag_count) AS count_item, COUNT(DISTINCT tag_id) AS count_tag';
4649
$sql .= ' FROM ' . $GLOBALS['xoopsDB']->prefix('tag_stats');
4750
$sql .= ' GROUP BY tag_modid';
@@ -68,25 +71,9 @@
6871
$adminObject->addInfoBoxLine(sprintf('<infolabel>' . _AM_TAG_COUNT_MODULE . '</infolabel>' . '<infotext>' . _AM_TAG_COUNT_MODULE_TITLE . '</infotext>'));
6972

7073
foreach ($counts_module as $module => $count) {
71-
$moduleStat = '<infolabel>'
72-
. $module_list[$module]
73-
. ":</infolabel>\n"
74-
. '<infotext>'
75-
. $count['count_tag']
76-
. ' / '
77-
. $count['count_item']
78-
. "\n"
79-
. " [<a href='"
80-
. $GLOBALS['xoops']->url("www/modules/tag/admin/admin.tag.php?modid={$module}")
81-
. "'>"
82-
. _AM_TAG_EDIT
83-
. "</a>]\n"
84-
. " [<a href='"
85-
. $GLOBALS['xoops']->url("www/modules/tag/admin/syn.tag.php?modid={$module}")
86-
. "'>"
87-
. _AM_TAG_SYNCHRONIZATION
88-
. "</a>]\n"
89-
. "</infotext> \n";
74+
$moduleStat = "<infolabel>{$module_list[$module]}:</infolabel>\n" . "<infotext>{$count['count_tag']} / {$count['count_item']}\n" . " [<a href='" . $helper->url("admin/admin.tag.php?modid={$module}") . "'>" . _AM_TAG_EDIT . "</a>]\n" . " [<a href='" . $helper->url(
75+
"admin/syn.tag.php?modid={$module}"
76+
) . "'>" . _AM_TAG_SYNCHRONIZATION . "</a>]\n" . "</infotext> \n";
9077
$adminObject->addInfoBoxLine(sprintf($moduleStat));
9178
}
9279

@@ -98,7 +85,6 @@
9885
$adminObject->displayNavigation(basename(__FILE__));
9986
$adminObject->displayIndex();
10087

101-
echo $utility::getServerStats();
88+
echo Utility::getServerStats();
10289

10390
require_once __DIR__ . '/admin_footer.php';
104-
//xoops_cp_footer();

0 commit comments

Comments
 (0)