rudolfcms /
rudolf
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 | namespace Rudolf\Component\Feed; |
||
| 4 | |||
| 5 | /** |
||
| 6 | * This file is part of Rudolf articles module. |
||
| 7 | * |
||
| 8 | * RSS2 Feed generator |
||
| 9 | * |
||
| 10 | * @see http://cyber.law.harvard.edu/rss/rss.html |
||
| 11 | * |
||
| 12 | * @author Mikołaj Pich <[email protected]> |
||
| 13 | * |
||
| 14 | * @version 0.1 |
||
| 15 | */ |
||
| 16 | class RSS2Item implements IRSS2Item |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * @var string |
||
| 20 | */ |
||
| 21 | private $title; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var string |
||
| 25 | */ |
||
| 26 | private $link; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var string |
||
| 30 | */ |
||
| 31 | private $description; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var string |
||
| 35 | */ |
||
| 36 | private $author; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var string |
||
| 40 | */ |
||
| 41 | private $category; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var string |
||
| 45 | */ |
||
| 46 | private $comments; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @var string |
||
| 50 | */ |
||
| 51 | private $enclosure; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @var string |
||
| 55 | */ |
||
| 56 | private $guid; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @var string |
||
| 60 | */ |
||
| 61 | private $pubDate; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @var string |
||
| 65 | */ |
||
| 66 | private $source; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Set item title. |
||
| 70 | * |
||
| 71 | * @param string $title |
||
| 72 | */ |
||
| 73 | public function setTitle($title) |
||
| 74 | { |
||
| 75 | $this->title = $title; |
||
| 76 | } |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Set item link. |
||
| 80 | * |
||
| 81 | * @param string $link |
||
| 82 | */ |
||
| 83 | public function setLink($link) |
||
| 84 | { |
||
| 85 | $this->link = $link; |
||
| 86 | } |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Set item description. |
||
| 90 | * |
||
| 91 | * @param string $description |
||
| 92 | */ |
||
| 93 | public function setDescription($description) |
||
| 94 | { |
||
| 95 | $this->description = $description; |
||
| 96 | } |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Set item author. |
||
| 100 | * |
||
| 101 | * @param string $author |
||
| 102 | */ |
||
| 103 | public function setAuthor($author) |
||
| 104 | { |
||
| 105 | $this->author = $author; |
||
| 106 | } |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Set item category. |
||
| 110 | * |
||
| 111 | * @param string $category |
||
| 112 | */ |
||
| 113 | public function setCategory($category) |
||
| 114 | { |
||
| 115 | $this->category = $category; |
||
| 116 | } |
||
| 117 | |||
| 118 | public function setComments($comments) |
||
| 119 | { |
||
| 120 | $this->comments = $comments; |
||
| 121 | } |
||
| 122 | |||
| 123 | public function setEnclosure($enclosure) |
||
| 124 | { |
||
| 125 | $this->enclosure = $enclosure; |
||
| 126 | } |
||
| 127 | |||
| 128 | public function setGuid($guid) |
||
| 129 | { |
||
| 130 | $this->guid = $guid; |
||
| 131 | } |
||
| 132 | |||
| 133 | public function setPubDate($pubDate) |
||
| 134 | { |
||
| 135 | $this->pubDate = $pubDate; |
||
| 136 | } |
||
| 137 | |||
| 138 | public function setSource($source) |
||
| 139 | { |
||
| 140 | $this->source = $source; |
||
| 141 | } |
||
| 142 | |||
| 143 | /** |
||
| 144 | * Get item title. |
||
| 145 | * |
||
| 146 | * @return bool|string |
||
| 147 | */ |
||
| 148 | public function getTitle() |
||
| 149 | { |
||
| 150 | if (empty($this->title)) { |
||
| 151 | return false; |
||
| 152 | } |
||
| 153 | |||
| 154 | return '<title>'.strip_tags($this->title).'</title>'; |
||
| 155 | } |
||
| 156 | |||
| 157 | /** |
||
| 158 | * Get item link. |
||
| 159 | * |
||
| 160 | * @return bool|string |
||
| 161 | */ |
||
| 162 | public function getLink() |
||
| 163 | { |
||
| 164 | if (empty($this->link)) { |
||
| 165 | return false; |
||
| 166 | } |
||
| 167 | |||
| 168 | return '<link>'.$this->link.'</link>'; |
||
| 169 | } |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Get item description. |
||
| 173 | * |
||
| 174 | * @return bool|string |
||
| 175 | */ |
||
| 176 | public function getDescription() |
||
| 177 | { |
||
| 178 | if (empty($this->description)) { |
||
| 179 | return false; |
||
| 180 | } |
||
| 181 | |||
| 182 | $content = str_replace(array("\n", "\r"), '', $this->description); |
||
| 183 | |||
| 184 | return '<description>'.htmlspecialchars($content).'</description>'; |
||
| 185 | } |
||
| 186 | |||
| 187 | /** |
||
| 188 | * Get item author. |
||
| 189 | * |
||
| 190 | * @return bool|string |
||
| 191 | */ |
||
| 192 | public function getAuthor() |
||
| 193 | { |
||
| 194 | if (empty($this->author)) { |
||
| 195 | return false; |
||
| 196 | } |
||
| 197 | |||
| 198 | return '<author>'.$this->author.'</author>'; |
||
| 199 | } |
||
| 200 | |||
| 201 | /** |
||
| 202 | * Get item category. |
||
| 203 | * |
||
| 204 | * @return bool|string |
||
| 205 | */ |
||
| 206 | public function getCategory() |
||
| 207 | { |
||
| 208 | if (empty($this->category)) { |
||
| 209 | return false; |
||
| 210 | } |
||
| 211 | |||
| 212 | return '<category>'.$this->category.'</category>'; |
||
| 213 | } |
||
| 214 | |||
| 215 | /** |
||
| 216 | * Get item pub date. |
||
| 217 | * |
||
| 218 | * @return bool|string |
||
| 219 | */ |
||
| 220 | public function getPubDate() |
||
| 221 | { |
||
| 222 | if (empty($this->pubDate)) { |
||
| 223 | return false; |
||
| 224 | } |
||
| 225 | |||
| 226 | return '<pubDate>'.$this->pubDate.'</pubDate>'; |
||
| 227 | } |
||
| 228 | |||
| 229 | /** |
||
| 230 | * Get <item> element. |
||
| 231 | * |
||
| 232 | * @return string |
||
| 233 | */ |
||
| 234 | public function getItem() |
||
| 235 | { |
||
| 236 | $xml[] = $this->getTitle(); |
||
|
0 ignored issues
–
show
|
|||
| 237 | $xml[] = $this->getLink(); |
||
| 238 | $xml[] = $this->getDescription(); |
||
| 239 | $xml[] = $this->getAuthor(); |
||
| 240 | $xml[] = $this->getPubDate(); |
||
| 241 | $xml[] = $this->getCategory(); |
||
| 242 | |||
| 243 | $xml = array_filter($xml); |
||
| 244 | |||
| 245 | foreach ($xml as $key => $value) { |
||
| 246 | $xml[$key] = "\t\t\t".$value; |
||
| 247 | } |
||
| 248 | |||
| 249 | array_unshift($xml, "\t\t".'<item>'); |
||
| 250 | |||
| 251 | $xml[] = "\t\t".'</item>'; |
||
| 252 | |||
| 253 | return implode("\n", array_filter($xml)); |
||
| 254 | } |
||
| 255 | } |
||
| 256 |
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:
As you can see in this example, the array
$myArrayis initialized the first time when the foreach loop is entered. You can also see that the value of thebarkey 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.