Completed
Push — master ( 01b1a5...81f493 )
by Michael
04:03
created

SmartObjectController::getEditLanguageLink()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 27
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 1 Features 0
Metric Value
cc 3
eloc 23
c 5
b 1
f 0
nc 3
nop 3
dl 0
loc 27
rs 8.8571
1
<?php
2
3
/**
4
 * Contains the basis classes for managing any objects derived from SmartObjects
5
 *
6
 * @license    GNU
7
 * @author     marcan <[email protected]>
8
 * @link       http://smartfactory.ca The SmartFactory
9
 * @package    SmartObject
10
 * @subpackage SmartObjectCore
11
 */
12
13
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% 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...
14
15
/**
16
 * Persistable SmartObject Controller class.
17
 *
18
 * This class is responsible for providing operations to an object
19
 * for managing the object's manipulation
20
 *
21
 * @package SmartObject
22
 * @author  marcan <[email protected]>
23
 * @credit  Jan Keller Pedersen <[email protected]> - IDG Danmark A/S <www.idg.dk>
24
 * @link    http://smartfactory.ca The SmartFactory
25
 */
26
include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php';
27
include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobjecthandler.php';
28
29
/**
30
 * Class SmartObjectController
31
 */
32
class SmartObjectController
33
{
34
    public $handler;
35
36
    /**
37
     * SmartObjectController constructor.
38
     * @param $handler
39
     */
40
    public function __construct($handler)
41
    {
42
        $this->handler = $handler;
43
    }
44
45
    /**
46
     * @param $smartObj
47
     */
48
    public function postDataToObject(&$smartObj)
49
    {
50
        foreach (array_keys($smartObj->vars) as $key) {
51
            switch ($smartObj->vars[$key]['data_type']) {
52
                case XOBJ_DTYPE_IMAGE:
53 View Code Duplication
                    if (isset($_POST['url_' . $key]) && $_POST['url_' . $key] !== '') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
54
                        $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e');
55
                        $smartObj->setVar($key, $_POST['url_' . $key]);
56
                        if (file_exists($oldFile)) {
57
                            unlink($oldFile);
58
                        }
59
                    }
60 View Code Duplication
                    if (isset($_POST['delete_' . $key]) && $_POST['delete_' . $key] == '1') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
61
                        $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e');
62
                        $smartObj->setVar($key, '');
63
                        if (file_exists($oldFile)) {
64
                            unlink($oldFile);
65
                        }
66
                    }
67
                    break;
68
69
                case XOBJ_DTYPE_URLLINK:
70
                    $linkObj = $smartObj->getUrlLinkObj($key);
71
                    $linkObj->setVar('caption', $_POST['caption_' . $key]);
72
                    $linkObj->setVar('description', $_POST['desc_' . $key]);
73
                    $linkObj->setVar('target', $_POST['target_' . $key]);
74
                    $linkObj->setVar('url', $_POST['url_' . $key]);
75
                    if ($linkObj->getVar('url') !== '') {
76
                        $smartObj->storeUrlLinkObj($linkObj);
77
                    }
78
                    //todo: catch errors
79
                    $smartObj->setVar($key, $linkObj->getVar('urllinkid'));
80
                    break;
81
82
                case XOBJ_DTYPE_FILE:
83
                    if (!isset($_FILES['upload_' . $key]['name']) || $_FILES['upload_' . $key]['name'] === '') {
84
                        $fileObj = $smartObj->getFileObj($key);
85
                        $fileObj->setVar('caption', $_POST['caption_' . $key]);
86
                        $fileObj->setVar('description', $_POST['desc_' . $key]);
87
                        $fileObj->setVar('url', $_POST['url_' . $key]);
88
                        if (!($fileObj->getVar('url') === '' && $fileObj->getVar('url') === '' && $fileObj->getVar('url') === '')) {
89
                            $res = $smartObj->storeFileObj($fileObj);
90
                            if ($res) {
91
                                $smartObj->setVar($key, $fileObj->getVar('fileid'));
92
                            } else {
93
                                //error setted, but no error message (to be improved)
94
                                $smartObj->setErrors($fileObj->getErrors());
95
                            }
96
                        }
97
                    }
98
                    break;
99
100
                case XOBJ_DTYPE_STIME:
101
                case XOBJ_DTYPE_MTIME:
102
                case XOBJ_DTYPE_LTIME:
103
                    // check if this field's value is available in the POST array
104
                    if (is_array($_POST[$key]) && isset($_POST[$key]['date'])) {
105
                        $value = strtotime($_POST[$key]['date']) + $_POST[$key]['time'];
106
                    } else {
107
                        $value = strtotime($_POST[$key]);
108
                        //if strtotime returns false, the value is already a time stamp
109
                        if (!$value) {
110
                            $value = (int)$_POST[$key];
111
                        }
112
                    }
113
                    $smartObj->setVar($key, $value);
114
115
                    break;
116
117
                default:
118
                    $smartObj->setVar($key, $_POST[$key]);
119
                    break;
120
            }
121
        }
122
    }
123
124
    /**
125
     * @param        $smartObj
126
     * @param        $objectid
127
     * @param        $created_success_msg
128
     * @param        $modified_success_msg
129
     * @param  bool  $redirect_page
130
     * @param  bool  $debug
131
     * @return mixed
132
     */
133
    public function doStoreFromDefaultForm(&$smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page = false, $debug = false)
134
    {
135
        global $smart_previous_page;
136
137
        $this->postDataToObject($smartObj);
138
139
        if ($smartObj->isNew()) {
140
            $redirect_msg = $created_success_msg;
141
        } else {
142
            $redirect_msg = $modified_success_msg;
143
        }
144
145
        // Check if there were uploaded files
146
        if (isset($_POST['smart_upload_image']) || isset($_POST['smart_upload_file'])) {
147
            include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartuploader.php';
148
            $uploaderObj = new SmartUploader($smartObj->getImageDir(true), $this->handler->_allowedMimeTypes, $this->handler->_maxFileSize, $this->handler->_maxWidth, $this->handler->_maxHeight);
149
            foreach ($_FILES as $name => $file_array) {
150
                if (isset($file_array['name']) && $file_array['name'] !== '' && in_array(str_replace('upload_', '', $name), array_keys($smartObj->vars))) {
151
                    if ($uploaderObj->fetchMedia($name)) {
152
                        $uploaderObj->setTargetFileName(time() . '_' . $uploaderObj->getMediaName());
153
                        if ($uploaderObj->upload()) {
154
                            // Find the related field in the SmartObject
155
                            $related_field   = str_replace('upload_', '', $name);
156
                            $uploadedArray[] = $related_field;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$uploadedArray was never initialized. Although not strictly required by PHP, it is generally a good practice to add $uploadedArray = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
157
                            //si c'est un fichier Rich
158
                            if ($smartObj->vars[$related_field]['data_type'] === XOBJ_DTYPE_FILE) {
159
                                $object_fileurl = $smartObj->getUploadDir();
160
                                $fileObj        = $smartObj->getFileObj($related_field);
161
                                $fileObj->setVar('url', $object_fileurl . $uploaderObj->getSavedFileName());
162
                                $fileObj->setVar('caption', $_POST['caption_' . $related_field]);
163
                                $fileObj->setVar('description', $_POST['desc_' . $related_field]);
164
                                $smartObj->storeFileObj($fileObj);
165
                                //todo: catch errors
166
                                $smartObj->setVar($related_field, $fileObj->getVar('fileid'));
167
                            } else {
168
                                $old_file = $smartObj->getUploadDir(true) . $smartObj->getVar($related_field);
169
                                unlink($old_file);
170
                                $smartObj->setVar($related_field, $uploaderObj->getSavedFileName());
171
                            }
172
                        } else {
173
                            $smartObj->setErrors($uploaderObj->getErrors(false));
174
                        }
175
                    } else {
176
                        $smartObj->setErrors($uploaderObj->getErrors(false));
177
                    }
178
                }
179
            }
180
        }
181
182
        if ($debug) {
183
            $storeResult = $this->handler->insertD($smartObj);
184
        } else {
185
            $storeResult = $this->handler->insert($smartObj);
186
        }
187
188
        if ($storeResult) {
189
            if ($this->handler->getPermissions()) {
190
                $smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler);
191
                $smartPermissionsHandler->storeAllPermissionsForId($smartObj->id());
192
            }
193
        }
194
195
        if ($redirect_page === null) {
196
            return $smartObj;
197
        } else {
198
            if (!$storeResult) {
199
                redirect_header($smart_previous_page, 3, _CO_SOBJECT_SAVE_ERROR . $smartObj->getHtmlErrors());
200
            }
201
202
            $redirect_page = $redirect_page ?: smart_get_page_before_form();
203
204
            redirect_header($redirect_page, 2, $redirect_msg);
205
        }
206
    }
207
208
    /**
209
     * Store the object in the database autmatically from a form sending POST data
210
     *
211
     * @param  string      $created_success_msg  message to display if new object was created
212
     * @param  string      $modified_success_msg message to display if object was successfully edited
213
     * @param  bool|string $redirect_page        redirect page, if not set, then we backup once
214
     * @param  bool        $debug
215
     * @param  bool        $x_param
216
     * @return bool
217
     * @internal param string $created_redir_page redirect page after creating the object
218
     * @internal param string $modified_redir_page redirect page after editing the object
219
     * @internal param bool $exit if set to TRUE then the script ends
220
     */
221
    public function storeFromDefaultForm($created_success_msg, $modified_success_msg, $redirect_page = false, $debug = false, $x_param = false)
222
    {
223
        $objectid = isset($_POST[$this->handler->keyName]) ? (int)$_POST[$this->handler->keyName] : 0;
224
        if ($debug) {
225 View Code Duplication
            if ($x_param) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
226
                $smartObj = $this->handler->getD($objectid, true, $x_param);
227
            } else {
228
                $smartObj = $this->handler->getD($objectid);
229
            }
230 View Code Duplication
        } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
231
            if ($x_param) {
232
                $smartObj = $this->handler->get($objectid, true, false, false, $x_param);
233
            } else {
234
                $smartObj = $this->handler->get($objectid);
235
            }
236
        }
237
238
        // if handler is the Multilanguage handler, we will need to treat this for multilanguage
239
        if (is_subclass_of($this->handler, 'smartpersistablemlobjecthandler')) {
240
            if ($smartObj->isNew()) {
241
                // This is a new object. We need to store the meta data and then the language data
242
                // First, we will get rid of the multilanguage data to only store the meta data
243
                $smartObj->stripMultilanguageFields();
244
                $newObject = $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug);
0 ignored issues
show
Bug introduced by
It seems like $redirect_page defined by parameter $redirect_page on line 221 can also be of type string; however, SmartObjectController::doStoreFromDefaultForm() does only seem to accept boolean, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
245
                /**
246
                 * @todo we need to trap potential errors here
247
                 */
248
249
                // ok, the meta daa is stored. Let's recreate the object and then
250
                // get rid of anything not multilanguage
251
                unset($smartObj);
252
                $smartObj = $this->handler->get($objectid);
253
                $smartObj->stripNonMultilanguageFields();
254
255
                $smartObj->setVar($this->handler->keyName, $newObject->getVar($this->handler->keyName));
256
                $this->handler->changeTableNameForML();
257
                $ret = $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug);
0 ignored issues
show
Bug introduced by
It seems like $redirect_page defined by parameter $redirect_page on line 221 can also be of type string; however, SmartObjectController::doStoreFromDefaultForm() does only seem to accept boolean, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
258
259
                return $ret;
260
            }
261
        } else {
262
            return $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug);
0 ignored issues
show
Bug introduced by
It seems like $redirect_page defined by parameter $redirect_page on line 221 can also be of type string; however, SmartObjectController::doStoreFromDefaultForm() does only seem to accept boolean, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
263
        }
264
    }
265
266
    /**
267
     * @return bool
268
     */
269
    public function storeSmartObjectD()
270
    {
271
        return $this->storeSmartObject(true);
272
    }
273
274
    /**
275
     * @param  bool $debug
276
     * @param  bool $xparam
277
     * @return bool
278
     */
279
    public function storeSmartObject($debug = false, $xparam = false)
280
    {
281
        $ret = $this->storeFromDefaultForm('', '', null, $debug, $xparam);
282
283
        return $ret;
284
    }
285
286
    /**
287
     * Handles deletion of an object which keyid is passed as a GET param
288
     *
289
     * @param  bool   $confirm_msg
290
     * @param  string $op
291
     * @param  bool   $userSide
292
     * @return bool
293
     * @internal param string $redir_page redirect page after deleting the object
294
     */
295
    public function handleObjectDeletion($confirm_msg = false, $op = 'del', $userSide = false)
0 ignored issues
show
Unused Code introduced by
The parameter $userSide is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
296
    {
297
        global $smart_previous_page;
298
299
        $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0;
300
        $smartObj = $this->handler->get($objectid);
301
302
        if ($smartObj->isNew()) {
303
            redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED);
304
        }
305
306
        $confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0;
307
        if ($confirm) {
308 View Code Duplication
            if (!$this->handler->delete($smartObj)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
309
                redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors());
310
                exit;
311
            }
312
313
            redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS);
314
        } else {
315
            // no confirm: show deletion condition
316
317
            xoops_cp_header();
318
319
            if (!$confirm_msg) {
320
                $confirm_msg = _CO_SOBJECT_DELETE_CONFIRM;
321
            }
322
323
            xoops_confirm(array('op' => $op, $this->handler->keyName => $smartObj->getVar($this->handler->keyName), 'confirm' => 1, 'redirect_page' => $smart_previous_page), xoops_getenv('PHP_SELF'),
324
                          sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE);
325
326
            xoops_cp_footer();
327
        }
328
        exit();
329
    }
330
331
    /**
332
     * @param bool   $confirm_msg
333
     * @param string $op
334
     */
335
    public function handleObjectDeletionFromUserSide($confirm_msg = false, $op = 'del')
336
    {
337
        global $smart_previous_page, $xoopsTpl;
338
339
        $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0;
340
        $smartObj = $this->handler->get($objectid);
341
342
        if ($smartObj->isNew()) {
343
            redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED);
344
        }
345
346
        $confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0;
347
        if ($confirm) {
348 View Code Duplication
            if (!$this->handler->delete($smartObj)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
349
                redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors());
350
                exit;
351
            }
352
353
            redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS);
354
        } else {
355
            // no confirm: show deletion condition
356
            if (!$confirm_msg) {
357
                $confirm_msg = _CO_SOBJECT_DELETE_CONFIRM;
358
            }
359
360
            ob_start();
361
            xoops_confirm(array('op' => $op, $this->handler->keyName => $smartObj->getVar($this->handler->keyName), 'confirm' => 1, 'redirect_page' => $smart_previous_page), xoops_getenv('PHP_SELF'),
362
                          sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE);
363
            $smartobjectDeleteConfirm = ob_get_clean();
364
            $xoopsTpl->assign('smartobject_delete_confirm', $smartobjectDeleteConfirm);
365
        }
366
    }
367
368
    /**
369
     * Retreive the object admin side link for a {@link SmartObjectSingleView} page
370
     *
371
     * @param  SmartObject $smartObj  reference to the object from which we want the user side link
372
     * @param  bool   $onlyUrl   wether or not to return a simple URL or a full <a> link
373
     * @param  bool   $withimage
374
     * @return string admin side link to the object
375
     */
376
    public function getAdminViewItemLink(SmartObject $smartObj, $onlyUrl = false, $withimage = false)
377
    {
378
        $ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=view&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
379
        if ($onlyUrl) {
380
            return $ret;
381
        } elseif ($withimage) {
382
            return "<a href='" .
383
                   $ret .
384
                   "'><img src='" .
385
                   SMARTOBJECT_IMAGES_ACTIONS_URL .
386
                   "viewmag.png' style='vertical-align: middle;' alt='" .
387
                   _CO_SOBJECT_ADMIN_VIEW .
388
                   "'  title='" .
389
                   _CO_SOBJECT_ADMIN_VIEW .
390
                   "'/></a>";
391
        }
392
393
        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
394
    }
395
396
    /**
397
     * Retreive the object user side link
398
     *
399
     * @param  SmartObject $smartObj reference to the object from which we want the user side link
400
     * @param  bool   $onlyUrl  wether or not to return a simple URL or a full <a> link
401
     * @return string user side link to the object
402
     */
403
    public function getItemLink(SmartObject $smartObj, $onlyUrl = false)
404
    {
405
        $seoMode       = smart_getModuleModeSEO($this->handler->_moduleName);
406
        $seoModuleName = smart_getModuleNameForSEO($this->handler->_moduleName);
407
408
        /**
409
         * $seoIncludeId feature is not finished yet, so let's put it always to true
410
         */
411
        //$seoIncludeId = smart_getModuleIncludeIdSEO($this->handler->_moduleName);
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% 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...
412
        $seoIncludeId = true;
413
414
        if ($seoMode === 'rewrite') {
415
            $ret = XOOPS_URL .
416
                   '/' .
417
                   $seoModuleName .
418
                   '.' .
419
                   $this->handler->_itemname .
420
                   ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') .
421
                   '/' .
422
                   $smartObj->getVar('short_url') .
423
                   '.html';
424
        } elseif ($seoMode === 'pathinfo') {
425
            $ret = SMARTOBJECT_URL .
426
                   'seo.php/' .
427
                   $seoModuleName .
428
                   '.' .
429
                   $this->handler->_itemname .
430
                   ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') .
431
                   '/' .
432
                   $smartObj->getVar('short_url') .
433
                   '.html';
434
        } else {
435
            $ret = $this->handler->_moduleUrl . $this->handler->_page . '?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
436
        }
437
438
        if (!$onlyUrl) {
439
            $ret = "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
440
        }
441
442
        return $ret;
443
    }
444
445
    /**
446
     * @param         $smartObj
447
     * @param  bool   $onlyUrl
448
     * @param  bool   $withimage
449
     * @return string
450
     */
451
    public function getEditLanguageLink($smartObj, $onlyUrl = false, $withimage = true)
452
    {
453
        $ret = $this->handler->_moduleUrl .
454
               'admin/' .
455
               $this->handler->_page .
456
               '?op=mod&' .
457
               $this->handler->keyName .
458
               '=' .
459
               $smartObj->getVar($this->handler->keyName) .
460
               '&language=' .
461
               $smartObj->getVar('language');
462
        if ($onlyUrl) {
463
            return $ret;
464
        } elseif ($withimage) {
465
            return "<a href='" .
466
                   $ret .
467
                   "'><img src='" .
468
                   SMARTOBJECT_IMAGES_ACTIONS_URL .
469
                   "wizard.png' style='vertical-align: middle;' alt='" .
470
                   _CO_SOBJECT_LANGUAGE_MODIFY .
471
                   "'  title='" .
472
                   _CO_SOBJECT_LANGUAGE_MODIFY .
473
                   "'/></a>";
474
        }
475
476
        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
477
    }
478
479
    /**
480
     * @param         $smartObj
481
     * @param  bool   $onlyUrl
482
     * @param  bool   $withimage
483
     * @param  bool   $userSide
484
     * @return string
485
     */
486 View Code Duplication
    public function getEditItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false)
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...
487
    {
488
        $admin_side = $userSide ? '' : 'admin/';
489
        $ret        = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
490
        if ($onlyUrl) {
491
            return $ret;
492
        } elseif ($withimage) {
493
            return "<a href='" .
494
                   $ret .
495
                   "'><img src='" .
496
                   SMARTOBJECT_IMAGES_ACTIONS_URL .
497
                   "edit.png' style='vertical-align: middle;' alt='" .
498
                   _CO_SOBJECT_MODIFY .
499
                   "'  title='" .
500
                   _CO_SOBJECT_MODIFY .
501
                   "'/></a>";
502
        }
503
504
        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
505
    }
506
507
    /**
508
     * @param         $smartObj
509
     * @param  bool   $onlyUrl
510
     * @param  bool   $withimage
511
     * @param  bool   $userSide
512
     * @return string
513
     */
514 View Code Duplication
    public function getDeleteItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false)
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...
515
    {
516
        $admin_side = $userSide ? '' : 'admin/';
517
        $ret        = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=del&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
518
        if ($onlyUrl) {
519
            return $ret;
520
        } elseif ($withimage) {
521
            return "<a href='" .
522
                   $ret .
523
                   "'><img src='" .
524
                   SMARTOBJECT_IMAGES_ACTIONS_URL .
525
                   "editdelete.png' style='vertical-align: middle;' alt='" .
526
                   _CO_SOBJECT_DELETE .
527
                   "'  title='" .
528
                   _CO_SOBJECT_DELETE .
529
                   "'/></a>";
530
        }
531
532
        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
533
    }
534
535
    /**
536
     * @param $smartObj
537
     * @return string
538
     */
539
    public function getPrintAndMailLink($smartObj)
540
    {
541
        global $xoopsConfig;
542
543
        $printlink = $this->handler->_moduleUrl . 'print.php?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
544
        $js        = "javascript:openWithSelfMain('" . $printlink . "', 'smartpopup', 700, 519);";
545
        $printlink = '<a href="' . $js . '"><img  src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'fileprint.png" alt="" style="vertical-align: middle;"/></a>';
546
547
        $smartModule = smart_getModuleInfo($smartObj->handler->_moduleName);
548
        $link        = smart_getCurrentPage();
549
        $mid         = $smartModule->getVar('mid');
550
        $friendlink  = "<a href=\"javascript:openWithSelfMain('" .
551
                       SMARTOBJECT_URL .
552
                       'sendlink.php?link=' .
553
                       $link .
554
                       '&amp;mid=' .
555
                       $mid .
556
                       "', ',',',',',','sendmessage', 674, 500);\"><img src=\"" .
557
                       SMARTOBJECT_IMAGES_ACTIONS_URL .
558
                       "mail_send.png\"  alt=\"" .
559
                       _CO_SOBJECT_EMAIL .
560
                       "\" title=\"" .
561
                       _CO_SOBJECT_EMAIL .
562
                       "\" style=\"vertical-align: middle;\"/></a>";
563
564
        $ret = '<span id="smartobject_print_button">' . $printlink . '&nbsp;</span>' . '<span id="smartobject_mail_button">' . $friendlink . '</span>';
565
566
        return $ret;
567
    }
568
569
    /**
570
     * @return string
571
     */
572
    public function getModuleItemString()
573
    {
574
        $ret = $this->handler->_moduleName . '_' . $this->handler->_itemname;
575
576
        return $ret;
577
    }
578
}
579