XoopsModules25x /
smartpartner
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
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 | * @param $document |
||
| 9 | * @return mixed |
||
| 10 | */ |
||
| 11 | |||
| 12 | function smartpartner_metagen_html2text($document) |
||
| 13 | { |
||
| 14 | // PHP Manual:: function preg_replace |
||
| 15 | // $document should contain an HTML document. |
||
| 16 | // This will remove HTML tags, javascript sections |
||
| 17 | // and white space. It will also convert some |
||
| 18 | // common HTML entities to their text equivalent. |
||
| 19 | // Credits: newbb2 |
||
| 20 | |||
| 21 | $search = array( |
||
| 22 | "'<script[^>]*?>.*?</script>'si", // Strip out javascript |
||
| 23 | "'<[\/\!]*?[^<>]*?>'si", // Strip out HTML tags |
||
| 24 | "'([\r\n])[\s]+'", // Strip out white space |
||
| 25 | "'&(quot|#34);'i", // Replace HTML entities |
||
| 26 | "'&(amp|#38);'i", |
||
| 27 | "'&(lt|#60);'i", |
||
| 28 | "'&(gt|#62);'i", |
||
| 29 | "'&(nbsp|#160);'i", |
||
| 30 | "'&(iexcl|#161);'i", |
||
| 31 | "'&(cent|#162);'i", |
||
| 32 | "'&(pound|#163);'i", |
||
| 33 | "'&(copy|#169);'i", |
||
| 34 | "'&#(\d+);'e" |
||
| 35 | ); // evaluate as php |
||
| 36 | |||
| 37 | $replace = array( |
||
| 38 | '', |
||
| 39 | '', |
||
| 40 | "\\1", |
||
| 41 | "\"", |
||
| 42 | '&', |
||
| 43 | '<', |
||
| 44 | '>', |
||
| 45 | ' ', |
||
| 46 | chr(161), |
||
| 47 | chr(162), |
||
| 48 | chr(163), |
||
| 49 | chr(169), |
||
| 50 | "chr(\\1)" |
||
| 51 | ); |
||
| 52 | |||
| 53 | $text = preg_replace($search, $replace, $document); |
||
| 54 | |||
| 55 | return $text; |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @param $description |
||
| 60 | * @param int $maxWords |
||
| 61 | * @return string |
||
| 62 | */ |
||
| 63 | function smartpartner_createMetaDescription($description, $maxWords = 100) |
||
|
0 ignored issues
–
show
|
|||
| 64 | { |
||
| 65 | $myts = MyTextSanitizer::getInstance(); |
||
|
0 ignored issues
–
show
$myts is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 66 | |||
| 67 | $words = array(); |
||
|
0 ignored issues
–
show
$words is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 68 | $words = explode(' ', smartpartner_metagen_html2text($description)); |
||
| 69 | |||
| 70 | $ret = ''; |
||
| 71 | $i = 1; |
||
| 72 | $wordCount = count($words); |
||
| 73 | foreach ($words as $word) { |
||
| 74 | $ret .= $word; |
||
| 75 | if ($i < $wordCount) { |
||
| 76 | $ret .= ' '; |
||
| 77 | } |
||
| 78 | ++$i; |
||
| 79 | } |
||
| 80 | |||
| 81 | return $ret; |
||
| 82 | } |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @param $text |
||
| 86 | * @param $minChar |
||
| 87 | * @return array |
||
| 88 | */ |
||
| 89 | function smartpartner_findMetaKeywords($text, $minChar) |
||
| 90 | { |
||
| 91 | $myts = MyTextSanitizer::getInstance(); |
||
|
0 ignored issues
–
show
$myts is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 92 | |||
| 93 | $keywords = array(); |
||
| 94 | $originalKeywords = explode(' ', $text); |
||
| 95 | foreach ($originalKeywords as $originalKeyword) { |
||
| 96 | $secondRoundKeywords = explode("'", $originalKeyword); |
||
| 97 | foreach ($secondRoundKeywords as $secondRoundKeyword) { |
||
| 98 | if (strlen($secondRoundKeyword) >= $minChar) { |
||
| 99 | if (!in_array($secondRoundKeyword, $keywords)) { |
||
| 100 | $keywords[] = trim($secondRoundKeyword); |
||
| 101 | } |
||
| 102 | } |
||
| 103 | } |
||
| 104 | } |
||
| 105 | |||
| 106 | return $keywords; |
||
| 107 | } |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @param $title |
||
| 111 | * @param string $categoryPath |
||
| 112 | * @param string $description |
||
| 113 | * @param int $minChar |
||
| 114 | */ |
||
| 115 | function smartpartner_createMetaTags($title, $categoryPath = '', $description = '', $minChar = 4) |
||
| 116 | { |
||
| 117 | global $xoopsTpl, $xoopsModule, $xoopsModuleConfig; |
||
|
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 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
Loading history...
|
|||
| 118 | $myts = MyTextSanitizer::getInstance(); |
||
| 119 | |||
| 120 | $ret = ''; |
||
| 121 | |||
| 122 | $title = $myts->displayTarea($title); |
||
| 123 | $title = $myts->undoHtmlSpecialChars($title); |
||
| 124 | |||
| 125 | if (isset($categoryPath)) { |
||
| 126 | $categoryPath = $myts->displayTarea($categoryPath); |
||
| 127 | $categoryPath = $myts->undoHtmlSpecialChars($categoryPath); |
||
| 128 | } |
||
| 129 | |||
| 130 | // Creating Meta Keywords |
||
| 131 | if (isset($title) && ($title != '')) { |
||
| 132 | $keywords = smartpartner_findMetaKeywords($title, $minChar); |
||
| 133 | |||
| 134 | if (isset($xoopsModuleConfig) && isset($xoopsModuleConfig['moduleMetaKeywords']) && $xoopsModuleConfig['moduleMetaKeywords'] != '') { |
||
| 135 | $moduleKeywords = explode(',', $xoopsModuleConfig['moduleMetaKeywords']); |
||
| 136 | foreach ($moduleKeywords as $moduleKeyword) { |
||
| 137 | if (!in_array($moduleKeyword, $keywords)) { |
||
| 138 | $keywords[] = trim($moduleKeyword); |
||
| 139 | } |
||
| 140 | } |
||
| 141 | } |
||
| 142 | |||
| 143 | $keywordsCount = count($keywords); |
||
| 144 | for ($i = 0; $i < $keywordsCount; ++$i) { |
||
| 145 | $ret .= $keywords[$i]; |
||
| 146 | if ($i < $keywordsCount - 1) { |
||
| 147 | $ret .= ', '; |
||
| 148 | } |
||
| 149 | } |
||
| 150 | |||
| 151 | $xoopsTpl->assign('xoops_meta_keywords', $ret); |
||
| 152 | } |
||
| 153 | // Creating Meta Description |
||
| 154 | if ($description != '') { |
||
| 155 | $xoopsTpl->assign('xoops_meta_description', smartpartner_createMetaDescription($description)); |
||
| 156 | } |
||
| 157 | |||
| 158 | // Creating Page Title |
||
| 159 | $moduleName = ''; |
||
| 160 | $titleTag = array(); |
||
| 161 | |||
| 162 | if (isset($xoopsModule)) { |
||
| 163 | $moduleName = $myts->displayTarea($xoopsModule->name()); |
||
| 164 | $titleTag['module'] = $moduleName; |
||
| 165 | } |
||
| 166 | |||
| 167 | if (isset($title) && ($title != '') && (strtoupper($title) != strtoupper($moduleName))) { |
||
| 168 | $titleTag['title'] = $title; |
||
| 169 | } |
||
| 170 | |||
| 171 | if (isset($categoryPath) && ($categoryPath != '')) { |
||
| 172 | $titleTag['category'] = $categoryPath; |
||
| 173 | } |
||
| 174 | |||
| 175 | $ret = ''; |
||
| 176 | |||
| 177 | if (isset($titleTag['title']) && $titleTag['title'] != '') { |
||
| 178 | $ret .= $titleTag['title']; |
||
| 179 | } |
||
| 180 | |||
| 181 | View Code Duplication | if (isset($titleTag['category']) && $titleTag['category'] != '') { |
|
|
0 ignored issues
–
show
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...
|
|||
| 182 | if ($ret != '') { |
||
| 183 | $ret .= ' - '; |
||
| 184 | } |
||
| 185 | $ret .= $titleTag['category']; |
||
| 186 | } |
||
| 187 | View Code Duplication | if (isset($titleTag['module']) && $titleTag['module'] != '') { |
|
|
0 ignored issues
–
show
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...
|
|||
| 188 | if ($ret != '') { |
||
| 189 | $ret .= ' - '; |
||
| 190 | } |
||
| 191 | $ret .= $titleTag['module']; |
||
| 192 | } |
||
| 193 | $xoopsTpl->assign('xoops_pagetitle', $ret); |
||
| 194 | } |
||
| 195 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.