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

referencesNewreferenceAction::registerEvents()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 9

Duplication

Lines 21
Ratio 87.5 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 2
b 0
f 0
nc 1
nop 0
dl 21
loc 24
rs 8.9713
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
 */
21
22
/**
23
 * Plugin chargé de notifier de la création d'une nouvelle catégorie
24
 *
25
 */
26
class referencesNewreferenceAction extends references_action
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
27
{
28 View Code Duplication
    public function registerEvents()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
    {
30
        /**
31
         * La liste des évènements traités par le plugin se présente sous la forme d'un tableau compposé comme ceci :
32
         *
33
         * Indice   Signification
34
         * ----------------------
35
         *    0        Evènement sur lequel se raccrocher (voir class/references_plugins.php::EVENT_ON_PRODUCT_CREATE
36
         *    1        Priorité du plugin (de 1 à 5)
37
         *    2        Script Php à inclure
38
         *    3        Classe à instancier
39
         *    4        Méthode à appeler
40
         */
41
        $events   = array();
42
        $events[] = array(
43
            references_plugins::EVENT_ON_REFERENCE_CREATE,
44
            references_plugins::EVENT_PRIORITY_1,
45
            basename(__FILE__),
46
            __CLASS__,
47
            'fireNewReference'
48
        );
49
50
        return $events;
51
    }
52
53
    /**
54
     * Méthode appelée pour indiquer qu'une nouvelle référence a été créée
55
     *
56
     * @param object $parameters La référence qui vient d'être publiée
57
     * @return void
58
     */
59
    public function fireNewReference($parameters)
60
    {
61
        $article              = $parameters['reference'];
62
        $notification_handler = xoops_getHandler('notification');
63
        $articleForTemplate   = array();
64
        $originalArticle      = $article->toArray('n');
65
66
        foreach ($originalArticle as $key => $value) {
67
            @$articleForTemplate[strtoupper($key)] = strip_tags($value);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
68
        }
69
        $articleForTemplate['REFERENCES_URL']     = $article->getUrl();
70
        $articleForTemplate['ARTICLE_SHORT_TEXT'] = references_utils::truncate_tagsafe($article->getVar('article_text'), REFERENCES_SHORTEN_TEXT);
71
        $notification_handler->triggerEvent('global', 0, 'new_article', $articleForTemplate);
72
    }
73
}
74