Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- mysql_connect("a88466.mysql.mchost.ru", "a88466_avatar", "zxcvbn") or die (mysql_error ());
- mysql_select_db("a88466_avatar") or die(mysql_error());
- # Назначаем временную зону
- # Выбираем token из таблицы "base"
- $result = mysql_query( "SELECT `weather`, `copyright`, `skype`, `icq`, `token` FROM base" );
- while($token = mysql_fetch_array($result))
- {
- if( intval($time) == 0 ) $time=time();
- $time = time() + 3600*0;
- $font = 'tahoma.ttf';
- $font_bold = 'tahomabd.ttf';
- $informer = $token['weather'];
- $copyright = $token['copyright'];
- //_____НАСТРОЙКИ_____\\
- /*
- Чтобы получить токен -- перейдите по ссылке, разрешните доступ и из адресной строки скопируйте занчение access_token
- http://oauth.vk.com/authorize?response_type=token&client_id=3213852&scope=photos,friends,offline,wall,messages
- */
- $skype = $token['skype']; //Логин в скайпе
- $icqnum = $token['icq']; //номер ICQ
- #################Шрифт###################################
- function imagegettextsize($image,$sizze,$angle,$font_file,$texxt)
- {
- $arr = imagettftext($image,$sizze,$angle,-1000,-1000,0,$font_file,$texxt);
- return $arr[2]-$arr[0];
- }
- #########################################################
- ##################Печать текста##########################
- function print_text ($image, $x, $y, $left, $size, $color, $text, $font_file, $angle)
- {
- /*$text = iconv("windows-1251", "UTF-8",$text);*/
- if ($left)
- $x = 200 - $x - imagegettextsize($image,$size,$angle,$font_file,$text);
- $color = substr($color, 1, 10);
- $color1 = substr($color, 0, 2);
- $color2 = substr($color, 2,2);
- $color3 = substr($color, 4,2);
- $color1 = base_convert($color1,16,10);
- $color2 = base_convert($color2,16,10);
- $color3 = base_convert($color3,16,10);
- $color = imagecolorallocate($image, $color1, $color2, $color3);
- imagettftext($image,$size,$angle,$x,$y,$color,$font_file,$text);
- }
- ########################################################
- ##################Рандомное фото########################
- function getphoto()
- {
- $url = "bg";
- if (is_dir($url)) {
- if ($dir = opendir($url)) {
- while (false !== ($file = readdir($dir))){
- if ($file != "." && $file != "..") {
- $kol++;
- }
- }
- closedir($dir);
- }
- }
- $foto =rand (1, $kol++);
- $foto ="bg/foto".$foto.".png";
- return $foto;
- }
- #########################################################
- ####################################################
- function get_content()
- {
- $date = date("d/m/Y");
- $link = "http://www.cbr.ru/scripts/XML_daily.asp?date_req=$date";
- $fd = fopen($link, "r");
- $text="";
- if (!$fd) echo "Запрашиваемая страница не найдена";
- else
- {
- while (!feof ($fd)) $text .= fgets($fd, 4096);
- }
- fclose ($fd);
- return $text;
- }
- $content = get_content();
- $pattern = "#<Valute ID=\"([^\"]+)[^>]+>[^>]+>([^<]+)[^>]+>[^>]+>[^>]+>[^>]+>[^>]+>[^>]+>([^<]+)[^>]+>[^>]+>([^<]+)#i";
- preg_match_all($pattern, $content, $out, PREG_SET_ORDER);
- $dollar = "";
- $euro = "";
- foreach($out as $cur)
- {
- if($cur[2] == 840) $dollar = str_replace(",",".",$cur[4]);
- if($cur[2] == 978) $euro = str_replace(",",".",$cur[4]);
- }
- $dollar = "".$dollar." руб."; //курс валют , рег. вместо сообщений и онлайна
- $euro = "".$euro." руб.";
- ####################################################
- function todate ($d,$m,$y)
- {
- global $time;
- return round((mktime(0,0,0,$m,$d,$y)-$time)/(3600*24),0);
- }
- #########################################################
- $q[]="";
- $q[]="января";
- $q[]="февраля";
- $q[]="марта";
- $q[]="апреля";
- $q[]="мая";
- $q[]="июня";
- $q[]="июля";
- $q[]="августа";
- $q[]="сентября";
- $q[]="октября";
- $q[]="ноября";
- $q[]="декабря";
- //-- определяем массив для дней недели --
- $e[0]="воскресенье";
- $e[1]="понедельник";
- $e[2]="вторник";
- $e[3]="среда";
- $e[4]="четверг";
- $e[5]="пятница";
- $e[6]="суббота";
- // ---- считываем месяц
- $m=date('m');
- if ($m=="01") $m=1;
- if ($m=="02") $m=2;
- if ($m=="03") $m=3;
- if ($m=="04") $m=4;
- if ($m=="05") $m=5;
- if ($m=="06") $m=6;
- if ($m=="07") $m=7;
- if ($m=="08") $m=8;
- if ($m=="09") $m=9;
- // ---- считываем день недели
- $we=date('w');
- // ---- считываем число
- $chislo=date('d');
- // — извлекаем день недели
- $den_nedeli = $e[$we];
- // — извлекаем значение месяца
- $mesyac = $q[$m];
- ##########################################################
- function get_calend($link)
- {
- $s=file_get_contents($link);
- preg_match_all('#write\("(.*?)"\)#',$s,$matches);
- foreach($matches[1] as $key=>$str)
- {
- if ($key==count($matches[1])-2) break;
- if ($key==9) break;
- $str = strip_tags($str);
- if (strlen($str)>1)
- {
- $i++;
- $str = '- '.$str;
- $str=wordwrap($str,32,"\n ");
- if ($i>=3)
- {
- $r .= $str . "\n";
- }
- }
- }
- return $r;
- }
- $calend = get_calend('http://www.calend.ru/img/export/informer_new_3.js');
- $calend = iconv("windows-1251", "UTF-8",$calend);
- ####################Погода###############################
- $file = file_get_contents("http://informer.gismeteo.ru/xml/33506_1.xml");
- /*$file = iconv("UTF-8", "windows-1251",$file);*/
- preg_match_all("#<item.*?>(.*?)</item>#is", $file, $items);
- foreach($items[1] as $item)
- {
- preg_match("#<title>(.*?)</title>#is", $item, $title);
- $name = explode(":", $title[1]);
- $date = $date[1];
- preg_match("#<description>(.*?)</description>#is", $item, $descr);
- $descr = preg_replace("#(\d{1,2,3}\.\.-\d{1,2,3} С).*#i", "$1", $descr[1]);
- preg_match("#<enclosure url=(['\"])(.*?)\\1#is", $item, $img);
- $data[] = $dat;
- }
- $dat['descr'] = $descr;
- $tt = explode("С,", $dat['descr']);
- $tt = explode(".,", $tt[1]);
- $t = explode("температура", $dat['descr']);
- $t = explode(",", $t[1]);
- $t = explode("..", $t[0]);
- $t ="".$t[0]." °C"; //температура
- $name = $name[0]; //Город
- $pogodaimg = $img[2];// картинка
- $davlenie = $tt[0]; // давление
- $veter = $tt[1]; // ветер
- #########################################################
- addlog('Start!');
- //Ключ проверяющий первый запуск или нет
- $firstLaunch = true;
- while ($firstLaunch) {
- //Получаем нужные данные с ВК шечки
- //Получаем количество новых сообщений
- addlog('Get inform');
- $tokken = $token['token'];
- $getMsg = api('messages.get','access_token='.$tokken.'&filters=1');
- $msgCount = $getMsg['response'][0];
- //Получаем количество онлайн юзеров
- $getOnline = api('friends.getOnline', 'access_token='.$token['token']);
- $onlineCount = count($getOnline['response']);
- //Получаем количество заявок
- $getRequests = api('friends.getRequests', 'access_token='.$tokken.'&count=1000');
- $requestCount = count($getRequests['response']);
- //А тут уже работам с созданием пикчи
- //Клеим фон и интерфейс
- $path = dirname(__FILE__);
- $top = imagecreatefrompng($path.'/bkgrnd.png');
- $imag = getphoto();
- $size = getimagesize($imag);
- $image = imagecreatefrompng($imag);
- imagecopyresampled($image, $top, 0, 0, 0, 0, $size[0], $size[1], $size[0], $size[1]);
- ############Добавляем статусы месенджеров################
- $num = file_get_contents("http://mystatus.skype.com/$skype.num");
- if($num==0) $skypeimg=$path.'/etc/4.png';
- elseif($num==1) $skypeimg=$path.'/etc/4.png';
- elseif($num==2) $skypeimg=$path.'/etc/1.png';
- elseif($num==3) $skypeimg=$path.'/etc/2.png';
- elseif($num==4) $skypeimg=$path.'/etc/4.png';
- elseif($num==5) $skypeimg=$path.'/etc/3.png';
- elseif($num==6) $skypeimg=$path.'/etc/4.png';
- #########################################################
- $fp = fsockopen ("status.icq.com", 80, &$errno, &$errstr, 30) or die("[ERROR - Could not connect to server (status.icq.com)]");
- fputs($fp, "GET /online.gif?icq=$icqnum&img=5&online= HTTP/1.0\n\n");
- while(!feof($fp) && !$icq_finished) {
- $line = fgets ($fp,128);
- if (substr($line,0,9) == 'Location:') {
- if (substr($line,13,11) == 'online1.gif') { // online
- $imgicq = imagecreatefrompng($path.'/etc/36.png');
- $icq_finished = true;
- } else {
- $imgicq = imagecreatefrompng($path.'/etc/48.png');
- $icq_finished = true;
- }
- }
- }
- fclose($fp);
- #########################################################
- $skypeimg = imagecreatefrompng($skypeimg);
- imagecopy($image,$skypeimg,21,58,0,0,25,25);
- imagecopy($image,$imgicq,156,60,0,0,25,25);
- ##################Пишем текст ^_^########################
- ####################################################################
- print_text($image,21,115,0,7.5, '#FFFFFF', '',$font,0);
- print_text($image,21,142,0,7.5, '#FFFFFF',$informer,$font_bold,0);
- print_text($image,38,200,0,7.5, '#FFFFFF', 'Колличество сообщений:',$font,0);
- print_text($image,20,200,1,7.5, '#FFFFFF',$msgCount,$font_bold,0);
- print_text($image,38,213,0,7.5, '#FFFFFF', 'Колличество заявок:',$font,0);
- print_text($image,20,213,1,7.5, '#FFFFFF',$requestCount,$font_bold,0);
- print_text($image,38,230,0,7.5, '#FFFFFF', 'Друзья онлайн:',$font,0);
- print_text($image,20,230,1,7.5, '#FFFFFF',$onlineCount,$font_bold,0);
- #######################################################################
- print_text($image,14,426,0,24,'#FFFFFF', $t,$font,0);
- print_text($image,25,398,0,12, '#FFFFFF', $name,$font_bold,0);
- print_text($image,16,438,0,8.9, '#FFFFFF', $davlenie,$font,0);
- print_text($image,16,450,0,8.9, '#FFFFFF', $veter,$font,0);
- $pogoda = imagecreatefrompng($pogodaimg);
- imagecopy($image,$pogoda,130,386,0,0,55,55);
- $copyr = $token['copyright']
- ##########################################################
- print_text($image,19,271,0,8, '#FFFFFF',$calend,$font,0);
- print_text($image,60,476,0,8, '#000000', 'WellNetQety',$font_bold,0);
- print_text($image,60,490,0,8, '#FFFFFF', '.$copyr.',$font_bold,0);
- #######################################################
- print_text($image,52,82,0,25, '#FFFFFF', date('H:i', $time),$font_bold,0);
- print_text($image,19,99,0,9, '#FFFFFF', $chislo .' '.$mesyac,$font_bold,0);
- print_text($image,17,99,1,9, '#FFFFFF', $den_nedeli,$font_bold,0);
- //Сейвим результ
- imagepng($image, $path.'/avatar.png');
- //Асвабаждаем рысурсы
- //imagedestroy($image);
- //Проверяем, елси это первый запуск, то нахуй, если нет, дропаем предыдущее фото
- if (!$firstLaunch) {
- addlog('Delete old avatar!');
- $getAllPhoto = api('photos.getProfile', 'access_token='.$token['token']);
- $infLastPhoto = end($getAllPhoto['response']);
- api('photos.delete', 'pid='.$infLastPhoto['pid'].'&access_token='.$token['token']);
- }
- //А тут мы будем грузить фоточку
- //Получаем url для аплоада
- addlog('Upload avatar!');
- $getUploadServer = api('photos.getProfileUploadServer', 'access_token='.$token['token']);
- $uploadUrl = $getUploadServer['response']['upload_url'];
- //Загружаем
- $uploadPhoto = curl($uploadUrl, array('photo' => '@'.$path.'/avatar.png'));
- $uploadJson = json_decode($uploadPhoto, true);
- //Сохраняем
- $savePhoto = api('photos.saveProfilePhoto', 'access_token='.$tokken.'&server='.$uploadJson['server'].'&photo='.$uploadJson['photo'].'&hash='.$uploadJson['hash']);
- //Получаем запись о обновление фото
- $getWall = api('wall.get','count=1&access_token='.$token['token']);
- $wllMsgId = $getWall['response'][1]['id'];
- //Удаляем запись о обновление
- api('wall.delete', 'post_id='.$wllMsgId.'&access_token='.$token['token']);
- //Задаём ключ, который говорит что мы уже грузили фото
- $firstLaunch = false;
- addlog('Done!');
- sleep(1); //регулируем параметры обновления
- }
- //Апишечка
- function api($method, $parametrs) {
- $getApi = curl('https://api.vk.com/method/'.$method.'?'.$parametrs);
- return json_decode($getApi, true);
- }
- //Лог
- function addlog($text){
- echo date('H:i:s: ').$text.PHP_EOL;
- }
- //Курлик
- function curl($url, $post = false) {
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- 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');
- if ($post) {
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
- }
- $response = curl_exec ($ch);
- curl_close($ch);
- return $response;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment