Guest User

Untitled

a guest
Jan 18th, 2014
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.12 KB | None | 0 0
  1. <?php
  2. mysql_connect("a88466.mysql.mchost.ru", "a88466_avatar", "zxcvbn") or die (mysql_error ());
  3. mysql_select_db("a88466_avatar") or die(mysql_error());
  4.  
  5. # Назначаем временную зону
  6.  
  7. # Выбираем token из таблицы "base"
  8. $result = mysql_query( "SELECT `weather`, `copyright`, `skype`, `icq`, `token` FROM base" );
  9.  
  10. while($token = mysql_fetch_array($result))
  11. {
  12. if( intval($time) == 0 ) $time=time();
  13.  
  14. $time = time() + 3600*0;
  15. $font = 'tahoma.ttf';
  16. $font_bold = 'tahomabd.ttf';
  17. $informer = $token['weather'];
  18. $copyright = $token['copyright'];
  19.  
  20. //_____НАСТРОЙКИ_____\\
  21. /*
  22. Чтобы получить токен -- перейдите по ссылке, разрешните доступ и из адресной строки скопируйте занчение access_token
  23. http://oauth.vk.com/authorize?response_type=token&client_id=3213852&scope=photos,friends,offline,wall,messages
  24. */
  25. $skype = $token['skype']; //Логин в скайпе
  26. $icqnum = $token['icq']; //номер ICQ
  27.  
  28. #################Шрифт###################################
  29. function imagegettextsize($image,$sizze,$angle,$font_file,$texxt)
  30. {
  31. $arr = imagettftext($image,$sizze,$angle,-1000,-1000,0,$font_file,$texxt);
  32. return $arr[2]-$arr[0];
  33. }
  34. #########################################################
  35.  
  36. ##################Печать текста##########################
  37. function print_text ($image, $x, $y, $left, $size, $color, $text, $font_file, $angle)
  38. {
  39. /*$text = iconv("windows-1251", "UTF-8",$text);*/
  40. if ($left)
  41. $x = 200 - $x - imagegettextsize($image,$size,$angle,$font_file,$text);
  42. $color = substr($color, 1, 10);
  43. $color1 = substr($color, 0, 2);
  44. $color2 = substr($color, 2,2);
  45. $color3 = substr($color, 4,2);
  46. $color1 = base_convert($color1,16,10);
  47. $color2 = base_convert($color2,16,10);
  48. $color3 = base_convert($color3,16,10);
  49. $color = imagecolorallocate($image, $color1, $color2, $color3);
  50. imagettftext($image,$size,$angle,$x,$y,$color,$font_file,$text);
  51. }
  52. ########################################################
  53. ##################Рандомное фото########################
  54. function getphoto()
  55. {
  56. $url = "bg";
  57. if (is_dir($url)) {
  58. if ($dir = opendir($url)) {
  59. while (false !== ($file = readdir($dir))){
  60. if ($file != "." && $file != "..") {
  61. $kol++;
  62. }
  63. }
  64. closedir($dir);
  65. }
  66. }
  67.  
  68. $foto =rand (1, $kol++);
  69.  
  70. $foto ="bg/foto".$foto.".png";
  71. return $foto;
  72. }
  73. #########################################################
  74. ####################################################
  75. function get_content()
  76. {
  77. $date = date("d/m/Y");
  78. $link = "http://www.cbr.ru/scripts/XML_daily.asp?date_req=$date";
  79. $fd = fopen($link, "r");
  80. $text="";
  81. if (!$fd) echo "Запрашиваемая страница не найдена";
  82. else
  83. {
  84. while (!feof ($fd)) $text .= fgets($fd, 4096);
  85. }
  86. fclose ($fd);
  87. return $text;
  88. }
  89. $content = get_content();
  90. $pattern = "#<Valute ID=\"([^\"]+)[^>]+>[^>]+>([^<]+)[^>]+>[^>]+>[^>]+>[^>]+>[^>]+>[^>]+>([^<]+)[^>]+>[^>]+>([^<]+)#i";
  91. preg_match_all($pattern, $content, $out, PREG_SET_ORDER);
  92. $dollar = "";
  93. $euro = "";
  94. foreach($out as $cur)
  95. {
  96. if($cur[2] == 840) $dollar = str_replace(",",".",$cur[4]);
  97. if($cur[2] == 978) $euro = str_replace(",",".",$cur[4]);
  98. }
  99. $dollar = "".$dollar." руб."; //курс валют , рег. вместо сообщений и онлайна
  100. $euro = "".$euro." руб.";
  101. ####################################################
  102. function todate ($d,$m,$y)
  103. {
  104. global $time;
  105. return round((mktime(0,0,0,$m,$d,$y)-$time)/(3600*24),0);
  106. }
  107. #########################################################
  108. $q[]="";
  109. $q[]="января";
  110. $q[]="февраля";
  111. $q[]="марта";
  112. $q[]="апреля";
  113. $q[]="мая";
  114. $q[]="июня";
  115. $q[]="июля";
  116. $q[]="августа";
  117. $q[]="сентября";
  118. $q[]="октября";
  119. $q[]="ноября";
  120. $q[]="декабря";
  121. //-- определяем массив для дней недели --
  122. $e[0]="воскресенье";
  123. $e[1]="понедельник";
  124. $e[2]="вторник";
  125. $e[3]="среда";
  126. $e[4]="четверг";
  127. $e[5]="пятница";
  128. $e[6]="суббота";
  129.  
  130. // ---- считываем месяц
  131. $m=date('m');
  132. if ($m=="01") $m=1;
  133. if ($m=="02") $m=2;
  134. if ($m=="03") $m=3;
  135. if ($m=="04") $m=4;
  136. if ($m=="05") $m=5;
  137. if ($m=="06") $m=6;
  138. if ($m=="07") $m=7;
  139. if ($m=="08") $m=8;
  140. if ($m=="09") $m=9;
  141.  
  142. // ---- считываем день недели
  143. $we=date('w');
  144.  
  145. // ---- считываем число
  146. $chislo=date('d');
  147.  
  148. // — извлекаем день недели
  149. $den_nedeli = $e[$we];
  150.  
  151. // — извлекаем значение месяца
  152. $mesyac = $q[$m];
  153. ##########################################################
  154. function get_calend($link)
  155. {
  156. $s=file_get_contents($link);
  157. preg_match_all('#write\("(.*?)"\)#',$s,$matches);
  158. foreach($matches[1] as $key=>$str)
  159. {
  160. if ($key==count($matches[1])-2) break;
  161. if ($key==9) break;
  162. $str = strip_tags($str);
  163. if (strlen($str)>1)
  164. {
  165. $i++;
  166. $str = '- '.$str;
  167. $str=wordwrap($str,32,"\n ");
  168. if ($i>=3)
  169. {
  170. $r .= $str . "\n";
  171. }
  172. }
  173. }
  174. return $r;
  175. }
  176. $calend = get_calend('http://www.calend.ru/img/export/informer_new_3.js');
  177. $calend = iconv("windows-1251", "UTF-8",$calend);
  178. ####################Погода###############################
  179. $file = file_get_contents("http://informer.gismeteo.ru/xml/33506_1.xml");
  180. /*$file = iconv("UTF-8", "windows-1251",$file);*/
  181. preg_match_all("#<item.*?>(.*?)</item>#is", $file, $items);
  182. foreach($items[1] as $item)
  183. {
  184. preg_match("#<title>(.*?)</title>#is", $item, $title);
  185. $name = explode(":", $title[1]);
  186. $date = $date[1];
  187. preg_match("#<description>(.*?)</description>#is", $item, $descr);
  188. $descr = preg_replace("#(\d{1,2,3}\.\.-\d{1,2,3} С).*#i", "$1", $descr[1]);
  189. preg_match("#<enclosure url=(['\"])(.*?)\\1#is", $item, $img);
  190. $data[] = $dat;
  191. }
  192. $dat['descr'] = $descr;
  193. $tt = explode("С,", $dat['descr']);
  194. $tt = explode(".,", $tt[1]);
  195. $t = explode("температура", $dat['descr']);
  196. $t = explode(",", $t[1]);
  197. $t = explode("..", $t[0]);
  198. $t ="".$t[0]." °C"; //температура
  199. $name = $name[0]; //Город
  200. $pogodaimg = $img[2];// картинка
  201. $davlenie = $tt[0]; // давление
  202. $veter = $tt[1]; // ветер
  203. #########################################################
  204.  
  205. addlog('Start!');
  206. //Ключ проверяющий первый запуск или нет
  207. $firstLaunch = true;
  208. while ($firstLaunch) {
  209. //Получаем нужные данные с ВК шечки
  210. //Получаем количество новых сообщений
  211. addlog('Get inform');
  212. $tokken = $token['token'];
  213. $getMsg = api('messages.get','access_token='.$tokken.'&filters=1');
  214. $msgCount = $getMsg['response'][0];
  215. //Получаем количество онлайн юзеров
  216. $getOnline = api('friends.getOnline', 'access_token='.$token['token']);
  217. $onlineCount = count($getOnline['response']);
  218. //Получаем количество заявок
  219. $getRequests = api('friends.getRequests', 'access_token='.$tokken.'&count=1000');
  220. $requestCount = count($getRequests['response']);
  221. //А тут уже работам с созданием пикчи
  222. //Клеим фон и интерфейс
  223. $path = dirname(__FILE__);
  224. $top = imagecreatefrompng($path.'/bkgrnd.png');
  225. $imag = getphoto();
  226. $size = getimagesize($imag);
  227. $image = imagecreatefrompng($imag);
  228. imagecopyresampled($image, $top, 0, 0, 0, 0, $size[0], $size[1], $size[0], $size[1]);
  229. ############Добавляем статусы месенджеров################
  230. $num = file_get_contents("http://mystatus.skype.com/$skype.num");
  231. if($num==0) $skypeimg=$path.'/etc/4.png';
  232. elseif($num==1) $skypeimg=$path.'/etc/4.png';
  233. elseif($num==2) $skypeimg=$path.'/etc/1.png';
  234. elseif($num==3) $skypeimg=$path.'/etc/2.png';
  235. elseif($num==4) $skypeimg=$path.'/etc/4.png';
  236. elseif($num==5) $skypeimg=$path.'/etc/3.png';
  237. elseif($num==6) $skypeimg=$path.'/etc/4.png';
  238. #########################################################
  239. $fp = fsockopen ("status.icq.com", 80, &$errno, &$errstr, 30) or die("[ERROR - Could not connect to server (status.icq.com)]");
  240. fputs($fp, "GET /online.gif?icq=$icqnum&img=5&online= HTTP/1.0\n\n");
  241.  
  242. while(!feof($fp) && !$icq_finished) {
  243. $line = fgets ($fp,128);
  244. if (substr($line,0,9) == 'Location:') {
  245. if (substr($line,13,11) == 'online1.gif') { // online
  246. $imgicq = imagecreatefrompng($path.'/etc/36.png');
  247.  
  248. $icq_finished = true;
  249.  
  250. } else {
  251.  
  252. $imgicq = imagecreatefrompng($path.'/etc/48.png');
  253. $icq_finished = true;
  254. }
  255. }
  256. }
  257. fclose($fp);
  258. #########################################################
  259. $skypeimg = imagecreatefrompng($skypeimg);
  260. imagecopy($image,$skypeimg,21,58,0,0,25,25);
  261. imagecopy($image,$imgicq,156,60,0,0,25,25);
  262. ##################Пишем текст ^_^########################
  263. ####################################################################
  264. print_text($image,21,115,0,7.5, '#FFFFFF', '',$font,0);
  265. print_text($image,21,142,0,7.5, '#FFFFFF',$informer,$font_bold,0);
  266. print_text($image,38,200,0,7.5, '#FFFFFF', 'Колличество сообщений:',$font,0);
  267. print_text($image,20,200,1,7.5, '#FFFFFF',$msgCount,$font_bold,0);
  268. print_text($image,38,213,0,7.5, '#FFFFFF', 'Колличество заявок:',$font,0);
  269. print_text($image,20,213,1,7.5, '#FFFFFF',$requestCount,$font_bold,0);
  270. print_text($image,38,230,0,7.5, '#FFFFFF', 'Друзья онлайн:',$font,0);
  271. print_text($image,20,230,1,7.5, '#FFFFFF',$onlineCount,$font_bold,0);
  272. #######################################################################
  273. print_text($image,14,426,0,24,'#FFFFFF', $t,$font,0);
  274. print_text($image,25,398,0,12, '#FFFFFF', $name,$font_bold,0);
  275. print_text($image,16,438,0,8.9, '#FFFFFF', $davlenie,$font,0);
  276. print_text($image,16,450,0,8.9, '#FFFFFF', $veter,$font,0);
  277. $pogoda = imagecreatefrompng($pogodaimg);
  278. imagecopy($image,$pogoda,130,386,0,0,55,55);
  279.  
  280. $copyr = $token['copyright']
  281. ##########################################################
  282. print_text($image,19,271,0,8, '#FFFFFF',$calend,$font,0);
  283. print_text($image,60,476,0,8, '#000000', 'WellNetQety',$font_bold,0);
  284. print_text($image,60,490,0,8, '#FFFFFF', '.$copyr.',$font_bold,0);
  285. #######################################################
  286. print_text($image,52,82,0,25, '#FFFFFF', date('H:i', $time),$font_bold,0);
  287. print_text($image,19,99,0,9, '#FFFFFF', $chislo .' '.$mesyac,$font_bold,0);
  288. print_text($image,17,99,1,9, '#FFFFFF', $den_nedeli,$font_bold,0);
  289. //Сейвим результ
  290. imagepng($image, $path.'/avatar.png');
  291. //Асвабаждаем рысурсы
  292. //imagedestroy($image);
  293. //Проверяем, елси это первый запуск, то нахуй, если нет, дропаем предыдущее фото
  294. if (!$firstLaunch) {
  295. addlog('Delete old avatar!');
  296. $getAllPhoto = api('photos.getProfile', 'access_token='.$token['token']);
  297. $infLastPhoto = end($getAllPhoto['response']);
  298. api('photos.delete', 'pid='.$infLastPhoto['pid'].'&access_token='.$token['token']);
  299. }
  300. //А тут мы будем грузить фоточку
  301. //Получаем url для аплоада
  302. addlog('Upload avatar!');
  303. $getUploadServer = api('photos.getProfileUploadServer', 'access_token='.$token['token']);
  304. $uploadUrl = $getUploadServer['response']['upload_url'];
  305. //Загружаем
  306. $uploadPhoto = curl($uploadUrl, array('photo' => '@'.$path.'/avatar.png'));
  307. $uploadJson = json_decode($uploadPhoto, true);
  308. //Сохраняем
  309. $savePhoto = api('photos.saveProfilePhoto', 'access_token='.$tokken.'&server='.$uploadJson['server'].'&photo='.$uploadJson['photo'].'&hash='.$uploadJson['hash']);
  310. //Получаем запись о обновление фото
  311. $getWall = api('wall.get','count=1&access_token='.$token['token']);
  312. $wllMsgId = $getWall['response'][1]['id'];
  313. //Удаляем запись о обновление
  314. api('wall.delete', 'post_id='.$wllMsgId.'&access_token='.$token['token']);
  315. //Задаём ключ, который говорит что мы уже грузили фото
  316. $firstLaunch = false;
  317. addlog('Done!');
  318. sleep(1); //регулируем параметры обновления
  319. }
  320. //Апишечка
  321. function api($method, $parametrs) {
  322. $getApi = curl('https://api.vk.com/method/'.$method.'?'.$parametrs);
  323. return json_decode($getApi, true);
  324. }
  325. //Лог
  326. function addlog($text){
  327. echo date('H:i:s: ').$text.PHP_EOL;
  328. }
  329. //Курлик
  330. function curl($url, $post = false) {
  331. $ch = curl_init($url);
  332. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  333. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  334. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  335. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  336. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4 AlexaToolbar/alxg-3.1');
  337. if ($post) {
  338. curl_setopt($ch, CURLOPT_POST, 1);
  339. curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  340. }
  341. $response = curl_exec ($ch);
  342. curl_close($ch);
  343. return $response;
  344. }
  345. ?>
Advertisement
Add Comment
Please, Sign In to add comment