PageRenderTime 26ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/Plugins/Wall/Hooks.php

https://github.com/chaoskaizer/CVbot-community-update
PHP | 231 lines | 156 code | 34 blank | 41 comment | 17 complexity | 2eee875e566f3e2e78c00e1082f785b8 MD5 | raw file
  1. <?php
  2. $this->AddHook('before_harvest_crops', 'Wall');
  3. function Wall($bot) {
  4. if ($bot->firstrun)
  5. { //not work if it's first bot cycle
  6. $Name = "Wall"; $Version = "0.1"; $Date = "2011-02-11";
  7. $bot->ld->UpdatePluginVersion($bot, $Name, $Version, $Date ) ;
  8. return;
  9. }
  10. $bot->ReloadConfig();
  11. $data = $bot->ld->GetPlSettings("Wall");
  12. // if (isset($data->Run)) { $Run = $data->Run; }else {$bot->SendMsg('Wall not activated.'); return;}
  13. // if (!isset($data->Run)) { $bot->SendMsg('Wall not activated...'); return;}
  14. // if (!$data->Run) { $bot->SendMsg('Wall not activated...='); return;}
  15. // if (isset($data->Debug)) {$Debug = false;}else{$Debug = true;}
  16. // if ($data->Debug) {$Debug = false;}else{$Debug = true;}
  17. $now = time();
  18. $uid = $bot->zyUid;
  19. $bot->SendMsg('Wall: Started for: '. $uid);
  20. include('Plugins/Wall/Wall_class.php');
  21. $DB = new LocalDB();
  22. $DB->ConnectTo("User", "Wall");
  23. $DB->InitDB();
  24. // what request has to be checked?
  25. $WallSet = array();
  26. $WallSet["Request"] = (array)$bot->ld->GetPlSettings('WallRequests');
  27. // what request has already in the DB.
  28. $query = "SELECT * FROM Request";
  29. $DBrequests = $DB->GetSelect($query) ;
  30. $bot->SendMsg('Requests in DB: ' . count($DBrequests));
  31. $requestDB = array();
  32. foreach($DBrequests as $option)
  33. {
  34. if($uid == $option['uid'])
  35. {
  36. if(array_key_exists($option['type'], $requestDB))
  37. { // alreadt there check the latest time.
  38. if($option['time'] > $requestDB[$option['type']])
  39. { // time from current request is bigger
  40. $requestDB[$option['type']]=$option['time'];
  41. }
  42. }
  43. else
  44. { // does not exist yet
  45. $requestDB[$option['type']]=$option['time'];
  46. }
  47. }
  48. }
  49. //var_dump($requestDB);
  50. // viral
  51. $query = "SELECT * FROM viral";
  52. $DB1virals = $DB->GetSelect($query) ;
  53. $bot->SendMsg('Virals in DB: ' . count($DB1virals));
  54. $DBvirals = array();
  55. foreach($DB1virals as $option)
  56. {
  57. $timeTillReset = (int)$option['timeTillReset'];
  58. $timeTillReset = $timeTillReset * 60 * 60 ; // sec.
  59. $DBvirals[$option['name']] = $timeTillReset ;
  60. }
  61. //var_dump($DBvirals);
  62. // Check if log folder exist.
  63. // $vFolder = "tmp_dir/GetGift/";
  64. // if (!is_dir($vFolder)) { @mkdir($vFolder, 0777, true); }
  65. // // make file name.
  66. // date_default_timezone_set("Europe/London");
  67. // $date = date("Y-m-d_H-i");
  68. // $filename = $vFolder . $date . "_Get_gifts.html";
  69. $requestsFound = 0;
  70. foreach($WallSet["Request"] as $req => $action)
  71. {
  72. if(!$action) continue; // check if we need to request this item. if not, goto next.
  73. if(array_key_exists($req, $requestDB))
  74. { // We have requested this befoe, check how long this is ago?
  75. // $now = now
  76. // $requestDB[$req] = last time checked.
  77. // $DBvirals[$req] = sec till next request.
  78. $nextRequest = $requestDB[$req] + $DBvirals[$req];
  79. if($nextRequest > $now )
  80. { // it is not yet time for this request.
  81. $bot->SendMsg('Wall request: ' . $req . ' ' . $bot->ld->nicetime($nextRequest));
  82. continue;
  83. }
  84. }
  85. $requestsFound++;
  86. $bot->SendMsg('Wall Request: ' . $req);
  87. //$bot->streamPublish($req);
  88. $type = $req;
  89. $amf = new AMFObject($bot->streamPublish($req));
  90. $deserializer = new AMFDeserializer($amf->rawData);
  91. $deserializer->deserialize($amf);
  92. $bod = new MessageBody();
  93. $bod = $amf->_bodys[0];
  94. $result = "OK";
  95. //result String postLimitReached
  96. if (isset($bod->_value['data'][0]['data']['result'])) $result = $bod->_value['data'][0]['data']['result'];
  97. //if($result != "postLimitReached")
  98. // {
  99. $title = "title";
  100. //title String Reference Jansen needs your help completing a collection.
  101. if (isset($bod->_value['data'][0]['data']['full']['title'])) $title =htmlspecialchars($bod->_value['data'][0]['data']['full']['title'], ENT_QUOTES);
  102. $image = "";
  103. //media Array Reference //type String image
  104. //src String http://assets.cityville.zynga.com/27093/images/feed_virals/feed_viral_wishlist.png
  105. if (isset($bod->_value['data'][0]['data']['full']['media'][0]['src'])) $image =$bod->_value['data'][0]['data']['full']['media'][0]['src'];
  106. $description = "description";
  107. // description String Reference Jansen is looking for any of these items: Zoning Permit in Cityville.
  108. if (isset($bod->_value['data'][0]['data']['full']['description'])) $description =htmlspecialchars($bod->_value['data'][0]['data']['full']['description'], ENT_QUOTES);
  109. $butonHref = "";
  110. $butonText = "";
  111. // buttons Array
  112. // href String Reference http://apps.facebook.com/cityville/neighbors.php?uid=20
  113. // text String Send collectables!
  114. if (isset($bod->_value['data'][0]['data']['full']['buttons'][0]['href'])) $butonHref =$bod->_value['data'][0]['data']['full']['buttons'][0]['href'] ;
  115. if (isset($bod->_value['data'][0]['data']['full']['buttons'][0]['text'])) $butonText =htmlspecialchars($bod->_value['data'][0]['data']['full']['buttons'][0]['text'], ENT_QUOTES);
  116. // feed_type String wall-to-wall
  117. $feed_type = "feed_type";
  118. if (isset($bod->_value['data'][0]['data']['feed_type'])) $feed_type =$bod->_value['data'][0]['data']['feed_type'];
  119. // }
  120. $now = time();
  121. //$butonHref = '';
  122. //$image = '';
  123. $query = "insert into Request values ('$uid','$now','$title','$type','$image','$description','$butonHref','$butonText','$feed_type','$result')";
  124. //$bot->SendMsg('Query: '. $query);
  125. $DB->ExecQuery($query);
  126. // done.
  127. }
  128. // let's make the html file.
  129. if($requestsFound > 0)
  130. {
  131. date_default_timezone_set('GMT');
  132. $now = date("D Y F d H:i:s");
  133. $html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  134. <html xmlns="http://www.w3.org/1999/xhtml" lang="ru">
  135. <head><title>Wall</title><meta http-equiv="Content-type" content="text/html; charset=utf-8">'."\r\n";
  136. $html .= '<style>
  137. body { }
  138. .Wall1 { font-family: "lucida grande",tahoma,verdana,arial,sans-serif; font-size: 11px; color: #333; text-align: left; direction: ltr;
  139. margin-top:6px;overflow:hidden;padding-right:10px;margin-bottom:5px}
  140. .Wall1_Media {float:left;overflow:hidden;padding-right:10px}
  141. .Wall1_MediaSingle {padding-right:10px}
  142. .Wall1_Title {font-weight:bold;padding-top:3px}
  143. .Wall1_Info {display:table}
  144. .Wall1_Caption {color:#808080;padding-top:3px}
  145. .Wall1_Caption a {color: #6D84B4; font-weight:bold;}
  146. .Wall3 img {display:block}
  147. </style>'."\r\n";
  148. $html .= '<script type="text/javascript">function Clicklinks(){var u =0; for (var i = 0; i < document.links.length; ++i){ if(document.links[i].style.visibility == "hidden"){continue;} u++; window.open(document.links[i].href, "_blank"); document.links[i].style.visibility = "hidden"; document.links[i].style.display = "none"; if (u >= 5){alert("Close the windows when they are loaded. Repeat clicking this buton untill all links are gone. Than check you city."); break; }}} </script>';
  149. $html .= '</head><body ><H1>Wall by 12christiaan</H1>';
  150. $html .= 'This file is created: <u>'.$now. '</u> for user <u>'.$bot->usern.'</u> ('.$uid.') <br>';
  151. $html .= 'The request below will send gifts to the creator of this file and / or you will get rewards.<br>';
  152. $html .= 'You can use the requests manualy (open 1 by 1) or click the buton below to open 5 requests at 1 click.<br>';
  153. $html .= 'Please make sure that you are login in to facebook as a different user. You can not give this requests to your self.<br>';
  154. $html .= 'Or send this file to and other user, to open the links.<br>';
  155. $html .= '<hr>';
  156. $html .= '<input type="button" onclick="Clicklinks()" value="Open Links till 5 Gifts"><br>'."\r\n";
  157. $html .= '<br><hr>'."\r\n";
  158. $query = "SELECT * FROM Request WHERE result='OK' AND uid='".$uid."'";
  159. $res = $DB->GetSelect($query) ;
  160. foreach ($res as $item)
  161. {
  162. $html .= '<a href="'.$item['butonHref'].'" target="_blank">';
  163. $html .= '<div class="Wall1" ><div class="Wall1_Media Wall1_MediaSingle" ><div class="Wall3">';
  164. $html .= ' <img class="img" src="'.$item['image'].'"></div></div>';
  165. $html .= '<div class="Wall1_Info "><div class="Wall1_Title">';
  166. $html .= htmlspecialchars_decode($item['title']) ;
  167. $html .= '</div><div class="Wall1_Caption">';
  168. $html .= $item['type'] ;
  169. $html .= '</div><div class="Wall1_Caption">';
  170. $html .= $item['description'] ;
  171. $html .= '</div><div class="Wall1_Caption">';
  172. // orig1 $html .= $bot->ld->nicetime($item['time']) . '&nbsp; via CityVile&nbsp;<a href="'.$item['butonHref'].'" target="_blank">'.$item['butonText'].'</a>';
  173. $html .= $bot->ld->nicetime($item['time']) . '&nbsp; via CityVile&nbsp;<b>'.$item['butonText'].'</b>';
  174. $html .= '</div>';
  175. $html .= '</div></div><hr></a>'."\r\n";
  176. }
  177. $html .= ''."\r\n";
  178. $html .= '';
  179. $html .= '';
  180. // check if folder exist.
  181. $vFolder = 'tmp_dir/Wall/';
  182. if (!is_dir($vFolder)) { @mkdir($vFolder, 0777, true); }
  183. // date
  184. $today = date("Y-m-d-H");
  185. $HTMLFile = $vFolder . $today . '_'.$uid. '_Wall.html';
  186. $fl = fopen($HTMLFile, 'w');
  187. fwrite($fl, $html);
  188. fclose($fl);
  189. $bot->SendMsg('Wall Requests written in file.');
  190. }
  191. else
  192. {
  193. $bot->SendMsg('Wall Requests NOT written to file, there where NO new requests.');
  194. }
  195. $bot->pm->RefreshMePlugin("Wall");
  196. }
  197. ?>