Completed
Pull Request — master (#4)
by Michael
03:07
created

partner.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 *
5
 * Module: SmartPartner
6
 * Author: The SmartFactory <www.smartfactory.ca>
7
 * Licence: GNU
8
 */
9
10
include_once __DIR__ . '/header.php';
11
$xoopsOption['template_main'] = 'smartpartner_partner.tpl';
12
include_once(XOOPS_ROOT_PATH . '/header.php');
13
include_once __DIR__ . '/footer.php';
14
15
global $xoopsUser, $xoopsConfig, $xoopsModuleConfig, $xoopsModule;
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...
16
17
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
18
19
if ($id == 0) {
20
    redirect_header('javascript:history.go(-1)', 2, _MD_SPARTNER_NOPARTNERSELECTED);
21
}
22
23
// Creating the Partner object for the selected FAQ
24
$partnerObj = new SmartpartnerPartner($id);
25
26
// If the selected partner was not found, exit
27
if ($partnerObj->notLoaded()) {
28
    redirect_header('javascript:history.go(-1)', 2, _MD_SPARTNER_NOPARTNERSELECTED);
29
}
30
include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobjectpermission.php';
31
$smartPermissionsHandler = new SmartobjectPermissionHandler($smartPartnerPartnerHandler);
32
$grantedItems            = $smartPermissionsHandler->getGrantedItems('full_view');
33
$grantedItems            = array_merge($grantedItems, $smartPermissionsHandler->getGrantedItems('partial_view'));
34
35
// Chech the status
36
if ($partnerObj->status() != _SPARTNER_STATUS_ACTIVE || (!in_array($id, $grantedItems))) {
37
    redirect_header('javascript:history.go(-1)', 2, _NOPERM);
38
}
39
40
// Updating the counter
41
$partnerObj->updateHits_page();
42
43
// Populating the smarty variables with informations related to the selected Partner
44
$partner = $partnerObj->toArray();
45
// Creating the files object associated with this item
46
$filesObj = $partnerObj->getFiles();
47
48
$files         = array();
49
$embeded_files = array();
50
51
foreach ($filesObj as $fileObj) {
52
    if ($fileObj->mimetype() === 'application/x-shockwave-flash') {
53
        $file['content'] = $fileObj->displayFlash();
54
55
        if (strpos($partner['maintext'], '[flash-' . $fileObj->getVar('fileid') . ']')) {
56
            $partner['maintext'] = str_replace('[flash-' . $fileObj->getVar('fileid') . ']', $file['content'], $partner['maintext']);
57
        } else {
58
            $embeded_files[] = $file;
59
        }
60
        unset($file);
61
    } else {
62
        $file['fileid']      = $fileObj->fileid();
63
        $file['name']        = $fileObj->name();
64
        $file['description'] = $fileObj->description();
65
        $file['name']        = $fileObj->name();
66
        $file['type']        = $fileObj->mimetype();
67
        $file['datesub']     = $fileObj->datesub();
68
        $file['hits']        = $fileObj->counter();
69
        $files[]             = $file;
70
        unset($file);
71
    }
72
}
73
$partner['files']         = $files;
74
$partner['embeded_files'] = $embeded_files;
75
$xoopsTpl->assign('partner', $partner);
76
77
//Get offers of this partner
78
$criteria = new CriteriaCompo();
79
$criteria->add(new Criteria('partnerid', $id));
80
$criteria->add(new Criteria('date_pub', time(), '<'));
81
$criteria->add(new Criteria('date_end', time(), '>'));
82
$criteria->add(new Criteria('status', _SPARTNER_STATUS_ONLINE));
83
84
$offersObj = $smartPartnerOfferHandler->getObjects($criteria);
85
$offers    = array();
86
foreach ($offersObj as $offerObj) {
87
    $offers[] = $offerObj->toArray();
88
}
89
$xoopsTpl->assign('offers', $offers);
90
$categoryPath = '';
91
if (isset($_GET['cid'])) {
92
    $categoryObj = $smartPartnerCategoryHandler->get($_GET['cid']);
93
} else {
94
    $categoryObj = $smartPartnerCategoryHandler->get($partnerObj->categoryid());
95
}
96
97
if (!$categoryObj->isNew()) {
98
    $categoryPath = $categoryObj->getCategoryPath() . ' > ';
99
}
100
$categoryPath .= $partnerObj->title();
101
$xoopsTpl->assign('categoryPath', $categoryPath);
102
$xoopsTpl->assign('module_home', '<a href="' . SMARTPARTNER_URL . '">' . $smartPartnerModuleName . '</a>');
103
104
// Lanugage constants
105
$xoopsTpl->assign('lang_offers', _CO_SPARTNER_OFFERS);
106
$xoopsTpl->assign('lang_offer_click_here', _CO_SPARTNER_OFFER_CLICKHERE);
107
$xoopsTpl->assign('lang_contact', _CO_SPARTNER_CONTACT);
108
$xoopsTpl->assign('lang_email', _CO_SPARTNER_EMAIL);
109
$xoopsTpl->assign('lang_adress', _CO_SPARTNER_ADRESS);
110
$xoopsTpl->assign('lang_phone', _CO_SPARTNER_PHONE);
111
$xoopsTpl->assign('lang_website', _CO_SPARTNER_WEBSITE);
112
$xoopsTpl->assign('lang_times', _CO_SPARTNER_TIMES);
113
$xoopsTpl->assign('lang_stats', _CO_SPARTNER_STATS);
114
$xoopsTpl->assign('lang_partner_informations', _CO_SPARTNER_PARTNER_INFORMATIONS);
115
$xoopsTpl->assign('lang_page_been_seen', _CO_SPARTNER_PAGE_BEEN_SEEN);
116
$xoopsTpl->assign('lang_url_been_visited', _CO_SPARTNER_URL_BEEN_VISITED);
117
$xoopsTpl->assign('lang_backtoindex', _MD_SPARTNER_BACKTOINDEX);
118
$xoopsTpl->assign('modulepath', SMARTPARTNER_URL);
119
$xoopsTpl->assign('lang_private', _CO_SPARTNER_PRIVATE);
120
$xoopsTpl->assign('partview_msg', $myts->xoopsCodeDecode($myts->displayTarea($xoopsModuleConfig['partview_msg'], 1)));
121
122
$show_stats_block = false;
123
if ($xoopsUser) {
124
    foreach ($xoopsModuleConfig['stats_group'] as $group) {
125
        if (in_array($group, $xoopsUser->getGroups())) {
126
            $show_stats_block = true;
127
        }
128
    }
129
} else {
130
    $show_stats_block = in_array(XOOPS_GROUP_ANONYMOUS, $xoopsModuleConfig['stats_group']);
131
}
132
133
$xoopsTpl->assign('show_stats_block', $show_stats_block);
134
135
// MetaTag Generator
136
smartpartner_createMetaTags($partnerObj->title(), '', $partnerObj->summary());
137
138
//code to include smartie
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
139
/*if (file_exists(XOOPS_ROOT_PATH . '/modules/smarttie/smarttie_links.php')) {
140
    include_once XOOPS_ROOT_PATH . '/modules/smarttie/smarttie_links.php';
141
    $xoopsTpl->assign('smarttie',1);
142
}*/
143
//end code for smarttie
144
145
include_once XOOPS_ROOT_PATH . '/footer.php';
146