seo_functions.php ➔ smartpartner_seo_genUrl()   C
last analyzed

Complexity

Conditions 7
Paths 7

Size

Total Lines 25
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 17
nc 7
nop 3
dl 0
loc 25
rs 6.7272
c 0
b 0
f 0
1
<?php
2
/*
3
 * $Id
4
 * Module: SmartPartner
5
 * Author: Sudhaker Raj <http://xoops.biz>
6
 * Licence: GNU
7
 */
8
9
// define SEO_ENABLED in mainfile.php, possible values
10
//   are "rewrite" & "path-info"
11
/**
12
 * @param  string $title
13
 * @return string
14
 */
15
function smartpartner_seo_title($title = '')
16
{
17
    $words = preg_split('/[^0-9a-z.]+/', strtolower($title), -1, PREG_SPLIT_NO_EMPTY);
18
    if (count($words) > 0) {
19
        return implode($words, '-') . '.html';
20
    } else {
21
        return '';
22
    }
23
}
24
25
// TODO: The SEO feature is not fully implemented in the module...
26
/**
27
 * @param         $op
28
 * @param         $id
29
 * @param  string $title
30
 * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
31
 */
32
function smartpartner_seo_genUrl($op, $id, $title = '')
33
{
34
    if (defined('SEO_ENABLED')) {
35
        if (SEO_ENABLED === 'rewrite') {
36
            // generate SEO url using htaccess
37
            return XOOPS_URL . "/smartpartner.${op}.${id}/" . smartpartner_seo_title($title);
38
        } elseif (SEO_ENABLED === 'path-info') {
39
            // generate SEO url using path-info
40
            return XOOPS_URL . "/modules/smartpartner/seo.php/${op}.${id}/" . smartpartner_seo_title($title);
41
        } else {
42
            die('Unknown SEO method.');
0 ignored issues
show
Coding Style Compatibility introduced by
The function smartpartner_seo_genUrl() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
43
        }
44
    } else {
45
        // generate classic url
46
        switch ($op) {
47
            case 'category':
48
                return XOOPS_URL . "/modules/smartpartner/index.php?view_category_id=${id}";
49
            case 'item':
50
            case 'print':
51
                return XOOPS_URL . "/modules/smartpartner/${op}.php?itemid=${id}";
52
            default:
53
                die('Unknown SEO operation.');
0 ignored issues
show
Coding Style Compatibility introduced by
The function smartpartner_seo_genUrl() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
54
        }
55
    }
56
}
57