| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | error_reporting(E_ALL); |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | set_time_limit(30); |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | require(dirname(__FILE__)."/plog-load-config.php"); |
|---|
| 12 | |
|---|
| 13 | header("Content-Type: text/xml"); |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | $xml = '<?xml version="1.0" standalone="yes" ?>'; |
|---|
| 18 | |
|---|
| 19 | $xml .= '<plogger name="'.htmlspecialchars($config["gallery_name"]).'">'; |
|---|
| 20 | |
|---|
| 21 | if (!isset($_GET["noconfig"]) || (!$_GET["noconfig"])){ |
|---|
| 22 | $xml .= '<config>'; |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | unset($config["admin_username"]); |
|---|
| 30 | unset($config["admin_password"]); |
|---|
| 31 | unset($config["admin_email"]); |
|---|
| 32 | unset($config["basedir"]); |
|---|
| 33 | |
|---|
| 34 | foreach ($config as $var => $val){ |
|---|
| 35 | $xml .= '<'.$var.'>'.$val.'</'.$var.'>'; |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | $xml .= '</config>'; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | if (isset($_GET["all"]) && ($_GET["all"] == 1)){ |
|---|
| 57 | $_GET["collections"] = 1; |
|---|
| 58 | $_GET["albums"] = 1; |
|---|
| 59 | $_GET["pictures"] = 1; |
|---|
| 60 | $_GET["comments"] = 1; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | if (isset($_GET["limit"])){ |
|---|
| 64 | $limit = intval($_GET["limit"]); |
|---|
| 65 | $limitType = ""; |
|---|
| 66 | } |
|---|
| 67 | else { |
|---|
| 68 | $limit = 0; |
|---|
| 69 | $limitType = ""; |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | if (isset($_GET["comment_id"])){ |
|---|
| 77 | unset($_GET["collections"]); |
|---|
| 78 | unset($_GET["albums"]); |
|---|
| 79 | unset($_GET["pictures"]); |
|---|
| 80 | unset($_GET["comments"]); |
|---|
| 81 | |
|---|
| 82 | $limit = 0; |
|---|
| 83 | $limitType = ""; |
|---|
| 84 | } else if (isset($_GET["picture_id"])){ |
|---|
| 85 | unset($_GET["collections"]); |
|---|
| 86 | unset($_GET["albums"]); |
|---|
| 87 | unset($_GET["pictures"]); |
|---|
| 88 | |
|---|
| 89 | if ($limit > 0){ |
|---|
| 90 | if (!empty($_GET["comments"])){ |
|---|
| 91 | $limitType = "comments"; |
|---|
| 92 | } else { |
|---|
| 93 | $limitType = ''; |
|---|
| 94 | $limit = 0; |
|---|
| 95 | } |
|---|
| 96 | } |
|---|
| 97 | } else if (isset($_GET["album_id"])){ |
|---|
| 98 | unset($_GET["collections"]); |
|---|
| 99 | unset($_GET["albums"]); |
|---|
| 100 | |
|---|
| 101 | if ($limit > 0){ |
|---|
| 102 | if (!empty($_GET["pictures"])){ |
|---|
| 103 | $limitType = "pictures"; |
|---|
| 104 | } else if (!empty($_GET["comments"])){ |
|---|
| 105 | $limitType = "comments"; |
|---|
| 106 | } else { |
|---|
| 107 | $limitType = ''; |
|---|
| 108 | $limit = 0; |
|---|
| 109 | } |
|---|
| 110 | } |
|---|
| 111 | } else if (isset($_GET["collection_id"])){ |
|---|
| 112 | unset($_GET["collections"]); |
|---|
| 113 | |
|---|
| 114 | if ($limit > 0){ |
|---|
| 115 | if (!empty($_GET["albums"])){ |
|---|
| 116 | $limitType = "albums"; |
|---|
| 117 | } else if (!empty($_GET["pictures"])){ |
|---|
| 118 | $limitType = "pictures"; |
|---|
| 119 | } else if (!empty($_GET["comments"])){ |
|---|
| 120 | $limitType = "comments"; |
|---|
| 121 | } else { |
|---|
| 122 | $limitType = ''; |
|---|
| 123 | $limit = 0; |
|---|
| 124 | } |
|---|
| 125 | } |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | if (($limit > 0) && ($limitType == '')){ |
|---|
| 129 | if ($limit > 0){ |
|---|
| 130 | if (!empty($_GET["collections"])){ |
|---|
| 131 | $limitType = "collections"; |
|---|
| 132 | } |
|---|
| 133 | else if (!empty($_GET["albums"])){ |
|---|
| 134 | $limitType = "albums"; |
|---|
| 135 | } |
|---|
| 136 | else if (!empty($_GET["pictures"])){ |
|---|
| 137 | $limitType = "pictures"; |
|---|
| 138 | } |
|---|
| 139 | else if (!empty($_GET["comments"])){ |
|---|
| 140 | $limitType = "comments"; |
|---|
| 141 | } |
|---|
| 142 | else { |
|---|
| 143 | $limit = 0; |
|---|
| 144 | $limitType = ''; |
|---|
| 145 | } |
|---|
| 146 | } |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | if (isset($_GET["collections"]) || isset($_GET["albums"]) || isset($_GET["pictures"]) || isset($_GET["comments"]) || isset($_GET["collection_id"]) || isset($_GET["album_id"]) || isset($_GET["picture_id"]) || isset($_GET["comment_id"])){ |
|---|
| 150 | if (isset($_GET["collection_id"])){ |
|---|
| 151 | $collections = array(get_collection_by_id($_GET["collection_id"])); |
|---|
| 152 | } |
|---|
| 153 | else if (isset($_GET["collections"])){ |
|---|
| 154 | $collections = get_collections("mod","DESC"); |
|---|
| 155 | } |
|---|
| 156 | else if (isset($_GET["albums"]) || isset($_GET["album_id"]) || isset($_GET["pictures"]) || isset($_GET["picture_id"]) || isset($_GET["comments"]) || isset($_GET["comment_id"])){ |
|---|
| 157 | $collections = get_collection_ids("mod","DESC"); |
|---|
| 158 | } |
|---|
| 159 | else { |
|---|
| 160 | $collections = array(); |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | $total = 0; |
|---|
| 166 | |
|---|
| 167 | foreach ($collections as $collection){ |
|---|
| 168 | |
|---|
| 169 | |
|---|
| 170 | if ((isset($_GET["collections"]) && ($_GET["collections"] == 1)) || |
|---|
| 171 | (isset($_GET["collection_id"]) && ($_GET["collection_id"] == $collection["id"]))){ |
|---|
| 172 | if ($limitType == 'collections'){ |
|---|
| 173 | if ($total == $limit){ |
|---|
| 174 | break; |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | $total++; |
|---|
| 178 | } |
|---|
| 179 | |
|---|
| 180 | $collection["thumb_path"] = "plog-thumb.php?id=".$collection["thumbnail_id"]; |
|---|
| 181 | |
|---|
| 182 | $xml .= '<collection'; |
|---|
| 183 | |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | foreach ($collection as $var => $val){ |
|---|
| 187 | $xml .= ' '.$var.'="'.htmlspecialchars($val).'"'; |
|---|
| 188 | } |
|---|
| 189 | |
|---|
| 190 | $xml .= '>'; |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | if (isset($_GET["albums"]) || isset($_GET["album_id"])){ |
|---|
| 194 | $albums = get_albums($collection["id"], "mod", "DESC"); |
|---|
| 195 | } |
|---|
| 196 | else if (isset($_GET["pictures"]) || isset($_GET["picture_id"]) || isset($_GET["comments"]) || isset($_GET["comment_id"])){ |
|---|
| 197 | $albums = get_album_ids($collection["id"],"mod","DESC"); |
|---|
| 198 | } |
|---|
| 199 | else { |
|---|
| 200 | $albums = array(); |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | foreach ($albums as $album){ |
|---|
| 204 | if ((isset($_GET["collection_id"]) && ($_GET["collection_id"] == $album["collection_id"])) || !isset($_GET["collection_id"])){ |
|---|
| 205 | if ((isset($_GET["albums"]) && ($_GET["albums"] == 1)) || |
|---|
| 206 | (isset($_GET["album_id"]) && ($_GET["album_id"] == $album["album_id"]))){ |
|---|
| 207 | if ($limitType == 'albums'){ |
|---|
| 208 | if ($total == $limit){ |
|---|
| 209 | break; |
|---|
| 210 | } |
|---|
| 211 | |
|---|
| 212 | $total++; |
|---|
| 213 | } |
|---|
| 214 | |
|---|
| 215 | $album["thumb_path"] = "plog-thumb.php?id=".$album["thumbnail_id"]; |
|---|
| 216 | |
|---|
| 217 | $xml .= '<album'; |
|---|
| 218 | foreach ($album as $var => $val){ |
|---|
| 219 | $xml .= ' '.$var.'="'.htmlspecialchars($val).'"'; |
|---|
| 220 | } |
|---|
| 221 | $xml .= '>'; |
|---|
| 222 | } |
|---|
| 223 | |
|---|
| 224 | if (isset($_GET["pictures"])){ |
|---|
| 225 | $pictures = get_pictures($album["album_id"], "mod", "DESC"); |
|---|
| 226 | } |
|---|
| 227 | else if (isset($_GET["picture_id"])){ |
|---|
| 228 | $pic = get_picture_by_id($_GET["picture_id"], $album["album_id"]); |
|---|
| 229 | |
|---|
| 230 | if ($pic) { |
|---|
| 231 | $pictures = array($pic); |
|---|
| 232 | } |
|---|
| 233 | else { |
|---|
| 234 | $pictures = array(); |
|---|
| 235 | } |
|---|
| 236 | } |
|---|
| 237 | else if (isset($_GET["comments"]) || isset($_GET["comment_id"])){ |
|---|
| 238 | $pictures = get_picture_ids($album["album_id"], "mod", "DESC"); |
|---|
| 239 | } |
|---|
| 240 | else { |
|---|
| 241 | $pictures = array(); |
|---|
| 242 | } |
|---|
| 243 | |
|---|
| 244 | foreach ($pictures as $picture){ |
|---|
| 245 | if ((isset($_GET["album_id"]) && ($_GET["album_id"] == $picture["parent_album"])) || !isset($_GET["album_id"])){ |
|---|
| 246 | if ((isset($_GET["pictures"]) && ($_GET["pictures"] == 1)) || |
|---|
| 247 | (isset($_GET["picture_id"]) && ($_GET["picture_id"] == $picture["id"]))){ |
|---|
| 248 | if ($limitType == 'pictures'){ |
|---|
| 249 | if ($total == $limit){ |
|---|
| 250 | break; |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| 253 | $total++; |
|---|
| 254 | } |
|---|
| 255 | |
|---|
| 256 | $picture["sm_thumb_path"] = 'plog-thumb.php?id='.$picture["id"]; |
|---|
| 257 | $picture["lg_thumb_path"] = 'plog-thumb.php?id='.$picture["id"].'&type=2'; |
|---|
| 258 | |
|---|
| 259 | $xml .= '<picture'; |
|---|
| 260 | |
|---|
| 261 | foreach ($picture as $var => $val){ |
|---|
| 262 | $xml .= ' '.$var.'="'.htmlspecialchars($val).'"'; |
|---|
| 263 | } |
|---|
| 264 | |
|---|
| 265 | $xml .= '>'; |
|---|
| 266 | } |
|---|
| 267 | |
|---|
| 268 | if (isset($_GET["comments"]) || isset($_GET["comment_id"])){ |
|---|
| 269 | $comments = get_comments($picture["id"], "mod", "DESC"); |
|---|
| 270 | |
|---|
| 271 | foreach ($comments as $comment){ |
|---|
| 272 | if ((isset($_GET["picture_id"]) && ($_GET["picture_id"] == $comment["parent_id"])) || !isset($_GET["picture_id"])){ |
|---|
| 273 | if ((isset($_GET["comments"]) && ($_GET["comments"] == 1)) || |
|---|
| 274 | (isset($_GET["comment_id"]) && ($_GET["comment_id"] == $comment["id"]))){ |
|---|
| 275 | if ($limitType == 'comments'){ |
|---|
| 276 | if ($total == $limit){ |
|---|
| 277 | break; |
|---|
| 278 | } |
|---|
| 279 | |
|---|
| 280 | $total++; |
|---|
| 281 | } |
|---|
| 282 | |
|---|
| 283 | $xml .= '<comment'; |
|---|
| 284 | |
|---|
| 285 | foreach ($comment as $var => $val){ |
|---|
| 286 | $xml .= ' '.$var.'="'.htmlspecialchars($val).'"'; |
|---|
| 287 | } |
|---|
| 288 | |
|---|
| 289 | $xml .= '/>'; |
|---|
| 290 | } |
|---|
| 291 | } |
|---|
| 292 | } |
|---|
| 293 | } |
|---|
| 294 | |
|---|
| 295 | if ((isset($_GET["pictures"]) && ($_GET["pictures"] == 1)) || |
|---|
| 296 | (isset($_GET["picture_id"]) && ($_GET["picture_id"] == $picture["id"]))){ |
|---|
| 297 | $xml .= '</picture>'; |
|---|
| 298 | } |
|---|
| 299 | } |
|---|
| 300 | } |
|---|
| 301 | |
|---|
| 302 | if ((isset($_GET["albums"]) && ($_GET["albums"] == 1)) || |
|---|
| 303 | (isset($_GET["album_id"]) && ($_GET["album_id"] == $album["album_id"]))){ |
|---|
| 304 | $xml .= '</album>'; |
|---|
| 305 | } |
|---|
| 306 | } |
|---|
| 307 | } |
|---|
| 308 | |
|---|
| 309 | if ((isset($_GET["collections"]) && ($_GET["collections"] == 1)) || |
|---|
| 310 | (isset($_GET["collection_id"]) && ($_GET["collection_id"] == $collection["id"]))){ |
|---|
| 311 | $xml .= '</collection>'; |
|---|
| 312 | } |
|---|
| 313 | } |
|---|
| 314 | } |
|---|
| 315 | |
|---|
| 316 | $xml .= '</plogger>'; |
|---|
| 317 | |
|---|
| 318 | echo $xml; |
|---|
| 319 | exit; |
|---|
| 320 | |
|---|
| 321 | function get_collection_ids($sort = "alpha", $order = "DESC") { |
|---|
| 322 | global $config; |
|---|
| 323 | |
|---|
| 324 | if ($sort == "mod"){ |
|---|
| 325 | $query = "SELECT |
|---|
| 326 | `c`.`id` |
|---|
| 327 | FROM `".TABLE_PREFIX."pictures` AS `i` |
|---|
| 328 | LEFT JOIN `".TABLE_PREFIX."collections` AS `c` ON `i`.`parent_collection`=`c`.`id` |
|---|
| 329 | GROUP BY `i`.`parent_collection` |
|---|
| 330 | ORDER BY `i`.`date_submitted` "; |
|---|
| 331 | |
|---|
| 332 | if ($order == "ASC"){ |
|---|
| 333 | $query .= " ASC "; |
|---|
| 334 | } else { |
|---|
| 335 | $query .= " DESC "; |
|---|
| 336 | } |
|---|
| 337 | } else { |
|---|
| 338 | $query = "SELECT |
|---|
| 339 | `c`.`id` |
|---|
| 340 | FROM `".TABLE_PREFIX."collections` AS `c` |
|---|
| 341 | ORDER BY `c`.`name` "; |
|---|
| 342 | |
|---|
| 343 | if ($order == "ASC"){ |
|---|
| 344 | $query .= " ASC "; |
|---|
| 345 | } else { |
|---|
| 346 | $query .= " DESC "; |
|---|
| 347 | } |
|---|
| 348 | } |
|---|
| 349 | |
|---|
| 350 | $resultCollection = run_query($query); |
|---|
| 351 | |
|---|
| 352 | $collections = array(); |
|---|
| 353 | |
|---|
| 354 | while ($collection = mysql_fetch_assoc($resultCollection)){ |
|---|
| 355 | $collections[$collection["id"]] = $collection; |
|---|
| 356 | } |
|---|
| 357 | |
|---|
| 358 | return $collections; |
|---|
| 359 | } |
|---|
| 360 | |
|---|
| 361 | function get_album_ids($collection_id = null, $sort = "alpha", $order = "DESC") { |
|---|
| 362 | global $config; |
|---|
| 363 | |
|---|
| 364 | $albums = array(); |
|---|
| 365 | |
|---|
| 366 | if ($sort == "mod"){ |
|---|
| 367 | $query = "SELECT |
|---|
| 368 | `a`.`id` AS `album_id` |
|---|
| 369 | FROM `".TABLE_PREFIX."pictures` AS `i` |
|---|
| 370 | LEFT JOIN `".TABLE_PREFIX."albums` AS `a` ON `i`.`parent_album`=`a`.`id`"; |
|---|
| 371 | |
|---|
| 372 | if ($collection_id){ |
|---|
| 373 | $query .= " WHERE `i`.`parent_collection`=".intval($collection_id); |
|---|
| 374 | } |
|---|
| 375 | |
|---|
| 376 | $query .= " |
|---|
| 377 | GROUP BY `i`.`parent_album` |
|---|
| 378 | ORDER BY `i`.`date_submitted` "; |
|---|
| 379 | |
|---|
| 380 | if ($order == "ASC"){ |
|---|
| 381 | $query .= " ASC "; |
|---|
| 382 | } else { |
|---|
| 383 | $query .= " DESC "; |
|---|
| 384 | } |
|---|
| 385 | } else { |
|---|
| 386 | $query = "SELECT |
|---|
| 387 | `a`.`id` AS `album_id` |
|---|
| 388 | FROM `".TABLE_PREFIX."albums` AS `a` |
|---|
| 389 | LEFT JOIN `".TABLE_PREFIX."collections` AS `c` ON `a`.`parent_id`=`c`.`id`"; |
|---|
| 390 | |
|---|
| 391 | if ($collection_id){ |
|---|
| 392 | $query .= " WHERE `c`.id=".intval($collection_id)." "; |
|---|
| 393 | } |
|---|
| 394 | |
|---|
| 395 | $query .= " ORDER BY `c`.`name` ASC, `a`.`name` ASC"; |
|---|
| 396 | } |
|---|
| 397 | |
|---|
| 398 | $result = run_query($query); |
|---|
| 399 | |
|---|
| 400 | while ($album = mysql_fetch_assoc($result)) { |
|---|
| 401 | $albums[$album["album_id"]] = $album; |
|---|
| 402 | } |
|---|
| 403 | |
|---|
| 404 | return $albums; |
|---|
| 405 | } |
|---|
| 406 | |
|---|
| 407 | function get_picture_ids($album_id, $order = "alpha", $sort = "DESC") { |
|---|
| 408 | global $config; |
|---|
| 409 | |
|---|
| 410 | $query = "SELECT |
|---|
| 411 | `p`.`id` |
|---|
| 412 | FROM `".TABLE_PREFIX."pictures` AS `p` |
|---|
| 413 | LEFT JOIN `".TABLE_PREFIX."albums` AS `a` ON `p`.`parent_album`=`a`.`id` |
|---|
| 414 | WHERE `a`.`id`=".intval($album_id); |
|---|
| 415 | |
|---|
| 416 | if ($order == "mod"){ |
|---|
| 417 | $query .= " ORDER BY `p`.`date_submitted` "; |
|---|
| 418 | } |
|---|
| 419 | else { |
|---|
| 420 | $query .= " ORDER BY `p`.`caption` "; |
|---|
| 421 | } |
|---|
| 422 | |
|---|
| 423 | if ($sort == "ASC"){ |
|---|
| 424 | $query .= " ASC "; |
|---|
| 425 | } else { |
|---|
| 426 | $query .= " DESC "; |
|---|
| 427 | } |
|---|
| 428 | |
|---|
| 429 | $result = run_query($query); |
|---|
| 430 | |
|---|
| 431 | $pictures = array(); |
|---|
| 432 | |
|---|
| 433 | while ($row = mysql_fetch_assoc($result)){ |
|---|
| 434 | $pictures[$row["id"]] = $row; |
|---|
| 435 | } |
|---|
| 436 | |
|---|
| 437 | return $pictures; |
|---|
| 438 | } |
|---|
| 439 | |
|---|
| 440 | ?> |
|---|