Advertisement
AndreyKlipikov

Mosaica Rating

Nov 21st, 2013
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.08 KB | None | 0 0
  1. $link = "http://mosaica.ru/poll/foto/32077"; // Ссылка на страницу с голосованием
  2. header("Content-Type: text/html; charset=utf-8");
  3. require_once "phpQuery.php";
  4.  
  5. $load_page = file_get_contents($link);
  6. $document = phpQuery::newDocument(substr($load_page, strpos($load_page, '<fieldset class="form-wrapper" id="edit-foto">'), strpos($load_page, '<div id="competition-general-rules">') - strpos($load_page, '<fieldset class="form-wrapper" id="edit-foto">') - 21));
  7. $photos = $document->find(".fieldset-wrapper > fieldset");
  8. $title = "Мой любимый горячий напиток!";
  9.  
  10. $list_link = Array();
  11. $list_people = Array();
  12. $list_rating = Array();
  13. $list_preview = Array();
  14.  
  15. foreach ($photos as $photo) {
  16.     $rate = substr(pq($photo)->find(".image_info .counter")->text(), 16);
  17.     $list_rating[] = str_pad(substr(pq($photo)->find(".image_info .counter")->text(), 16), 4, "0", STR_PAD_LEFT);
  18.     $list_link[] = pq($photo)->find(".image_preview > a")->attr("href");
  19.     $list_preview[] = pq($photo)->find(".image_preview > a > img")->attr("src");
  20.     $list_people[] = pq($photo)->find(".image_info .title")->text();
  21. }
  22.  
  23. array_multisort($list_rating, SORT_DESC, SORT_NUMERIC, $list_people, $list_link, $list_preview);
  24.  
  25. for($i = 0; $i < count($list_rating); $i++) {
  26.     $content .= "<div class=\"item\"><div class=\"pull-right\"><code>" .($i + 1) . "</code></div><img class=\"img-polaroid\" src=\"" . $list_preview[$i] . "\" width=\"200\" align=\"center\" style=\"margin:5px 40px 5px 5px\" /><span style=\"font-size:16px;font-weight:bold\">" . $list_people[$i] . "</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(<strong>" . intval($list_rating[$i]) . "</strong>)\n<div style=\"margin:-30px 0 0\" class=\"pull-right\"><a href=\"" . $list_link[$i] . "\" target=\"_blank\">Посмотреть полную фотографию</a></div></div><div style=\"clear:both\"></div>\n";
  27. }
  28.  
  29. $in = Array("{CONTENT}", "{PEOPLE}", "{TITLE}");
  30. $out = Array("$content", count($list_rating), "$title");
  31.  
  32. $template = file_get_contents("index.tpl");
  33. $template = str_replace($in, $out, $template);
  34.  
  35. echo $template;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement