Skip to content

Commit 2eea8c4

Browse files
committed
addx mnews plugin
1 parent e4f11cf commit 2eea8c4

1 file changed

Lines changed: 91 additions & 0 deletions

File tree

plugin/xmnews.php

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
/*
3+
You may not change or alter any portion of this comment or credits
4+
of supporting developers from this source code or any supporting source code
5+
which is considered copyrighted (c) material of the original comment or credit authors.
6+
7+
This program is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10+
*/
11+
12+
/**
13+
* xmnews module
14+
*
15+
* @copyright XOOPS Project (https://xoops.org)
16+
* @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
17+
* @author Mage Gregory (AKA Mage)
18+
*/
19+
20+
//use XoopsModules\Tag\Helper;
21+
use Xmf\Module\Helper;
22+
23+
function xmnews_tag_iteminfo(&$items)
24+
{
25+
if (empty($items) || !is_array($items)) {
26+
return false;
27+
}
28+
29+
$items_id = [];
30+
foreach (array_keys($items) as $cat_id) {
31+
// Some handling here to build the link upon catid
32+
// If catid is not used, just skip it
33+
foreach (array_keys($items[$cat_id]) as $item_id) {
34+
// In article, the item_id is "art_id"
35+
$items_id[] = (int)$item_id;
36+
}
37+
}
38+
$helper = Helper::getHelper('xmnews');
39+
$newsHandler = $helper->getHandler('xmnews_news');
40+
$items_obj = $newsHandler->getObjects(new \Criteria('news_id', '(' . implode(', ', $items_id) . ')', 'IN'), true);
41+
if (count($items_obj) > 0){
42+
foreach (array_keys($items) as $cat_id) {
43+
foreach (array_keys($items[$cat_id]) as $item_id) {
44+
$item_obj = $items_obj[$item_id];
45+
$items[$cat_id][$item_id] = [
46+
'title' => $item_obj->getVar('news_title'),
47+
'uid' => $item_obj->getVar('news_userid'),
48+
'link' => "article.php?news_id={$item_id}",
49+
'time' => $item_obj->getVar('news_date'),
50+
'tags' => \XoopsModules\Tag\Utility::tag_parse_tag($item_obj->getVar('news_mkeyword', 'n')), // optional
51+
'content' => '',
52+
];
53+
}
54+
}
55+
unset($items_obj);
56+
return true;
57+
}
58+
return false;
59+
}
60+
61+
/** Remove orphan tag-item links *
62+
* @param int $mid
63+
* @return bool
64+
*/
65+
function publisher_tag_synchronization($mid)
66+
{
67+
//$itemHandler = \XoopsModules\xmnews\Helper::getInstance()->getHandler('xmnews_news');
68+
$helper = Helper::getHelper('xmnews');
69+
$newsHandler = $helper->getHandler('xmnews_news');
70+
71+
/** @var \XoopsModules\Tag\LinkHandler $itemHandler */
72+
$linkHandler = Helper::getInstance()->getHandler('Link');
73+
74+
// $mid = XoopsFilterInput::clean($mid, 'INT');
75+
$mid = \Xmf\Request::getInt('mid');
76+
77+
/* clear tag-item links */
78+
$sql = " DELETE FROM {$linkHandler->table}"
79+
. ' WHERE '
80+
. " tag_modid = {$mid}"
81+
. ' AND '
82+
. ' ( tag_itemid NOT IN '
83+
. " ( SELECT DISTINCT {$newsHandler->keyName} "
84+
. " FROM {$newsHandler->table} "
85+
. " WHERE {$newsHandler->table}.status = 1"
86+
. ' ) '
87+
. ' )';
88+
$result = $linkHandler->db->queryF($sql);
89+
90+
return $result ? true : false;
91+
}

0 commit comments

Comments
 (0)