Completed
Push — master ( 369c90...324e29 )
by Michael
04:57
created

plugin.tag.php ➔ references_tag_synchronization()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 21
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
eloc 16
c 2
b 0
f 0
nc 4
nop 1
dl 0
loc 21
rs 9.3142
1
<?php
2
/**
3
 * ****************************************************************************
4
 * references - MODULE FOR XOOPS
5
 * Copyright (c) Hervé Thouzard of Instant Zero (http://www.instant-zero.com)
6
 *
7
 * You may not change or alter any portion of this comment or credits
8
 * of supporting developers from this source code or any supporting source code
9
 * which is considered copyrighted (c) material of the original comment or credit authors.
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 *
14
 * @copyright       Hervé Thouzard of Instant Zero (http://www.instant-zero.com)
15
 * @license         http://www.fsf.org/copyleft/gpl.html GNU public license
16
 * @package         references
17
 * @author          Hervé Thouzard of Instant Zero (http://www.instant-zero.com)
18
 *
19
 * ****************************************************************************
20
 * @param $items
21
 */
22
23
function references_tag_iteminfo(&$items)
24
{
25
    $items_id = array();
26
    foreach (array_keys($items) as $cat_id) {
27
        foreach (array_keys($items[$cat_id]) as $item_id) {
28
            $items_id[] = (int)$item_id;
29
        }
30
    }
31
    include XOOPS_ROOT_PATH . '/modules/references/include/common.php';
32
    $items_obj = $h_references_articles->getItemsFromIds($items_id);
0 ignored issues
show
Bug introduced by
The variable $h_references_articles does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
33
34
    foreach (array_keys($items) as $cat_id) {
35
        foreach (array_keys($items[$cat_id]) as $item_id) {
36
            $item_obj                 =& $items_obj[$item_id];
37
            /** @noinspection SenselessCommaInArrayDefinitionInspection */
38
            $items[$cat_id][$item_id] = array(
39
                'title'   => $item_obj->getVar('article_title'),
40
                'uid'     => $item_obj->getVar('article_author'),
41
                'link'    => 'index.php',
42
                'time'    => $item_obj->getVar('article_timestamp'),
43
                'tags'    => '',
44
                'content' => '',
45
            );
46
        }
47
    }
48
    unset($items_obj);
49
}
50
51
/** Remove orphan tag-item links *
52
 * @param $mid
53
 */
54
function references_tag_synchronization($mid)
55
{
56
    global $xoopsDB;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
57
    $item_handler_keyName = 'article_id';
58
    $item_handler_table   = $xoopsDB->prefix('references_articles');
59
    $link_handler         = xoops_getModuleHandler('link', 'tag');
60
    $where                = "($item_handler_table.article_online = 1)";
61
    $where1               = "($item_handler_table.article_online = 0)";
62
63
    /* clear tag-item links */
64
    if ($link_handler->mysql_major_version() >= 4):
65
        $sql = " DELETE FROM {$link_handler->table}" . '   WHERE ' . "       tag_modid = {$mid}" . '       AND ' . '       ( tag_itemid NOT IN ' . "           ( SELECT DISTINCT {$item_handler_keyName} " . "               FROM {$item_handler_table} " . "               WHERE $where" . '           ) '
66
               . '       )';
67
    else:
68
        $sql = " DELETE {$link_handler->table} FROM {$link_handler->table}" . "   LEFT JOIN {$item_handler_table} AS aa ON {$link_handler->table}.tag_itemid = aa.{$item_handler_keyName} " . '   WHERE ' . "       tag_modid = {$mid}" . '       AND ' . "       ( aa.{$item_handler_keyName} IS NULL"
69
               . "           OR $where1" . '       )';
70
    endif;
71
    if (!$link_handler->db->queryF($sql)) {
72
        trigger_error($link_handler->db->error());
73
    }
74
}
75