Permalink
Browse files

add test functions

  • Loading branch information...
1 parent 107ae07 commit 94672bdd65a5dccbedf8bff03b9b7dc2fea600a0 @saippuakauppias committed May 18, 2012
Showing with 115 additions and 7 deletions.
  1. +1 −1 README.md
  2. +101 −4 classes/vk_poster.class.php
  3. +3 −2 config.php
  4. +10 −0 example.php
View
@@ -4,7 +4,7 @@
### Установка и настройка
1. Склонируйте репозиторий.
-2. Задайте права на запись для файлов из папки /data
+2. Задайте chmod 0777 для папки /data
3. Введите свои данные для конфигурации в файл /config.php
4. По примеру из /example.php сделайте постинг своих сообщений на нужные страницы.
@@ -8,6 +8,7 @@ class vk_auth
private $phone = '';
private $sleeptime = 1;
private $minicurl;
+ private $images = array();
function __construct()
@@ -44,6 +45,36 @@ public function check_auth()
}
/*
+* public attach to post functions
+*/
+ public function attach_photos($photos=array())
+ {
+ if (sizeof($photos) <= 0)
+ {
+ $this->put_error_in_logfile('Photo links not found!');
+ return FALSE;
+ }
+
+ if (is_array($photos))
+ {
+ foreach ($photos as $url)
+ {
+ $this->images[] = $url;
+ }
+ }
+ elseif (is_string($photos))
+ {
+ $this->images[] = $photos;
+ }
+ else {
+ $this->put_error_in_logfile('Var not array or string!');
+ return FALSE;
+ }
+
+ return TRUE;
+ }
+
+/*
* public posting functions
*/
@@ -57,7 +88,8 @@ public function post_to_user($user_id, $message, $friends_only = FALSE)
return FALSE;
}
- $hash = $this->get_hash('id' . $user_id);
+ $user_id = 'id' . $user_id;
+ $hash = $this->get_hash($user_id);
if (empty($hash))
{
$this->put_error_in_logfile('JS-Field "post_hash" not found!');
@@ -81,7 +113,8 @@ public function post_to_group($group_id, $message, $official = FALSE)
return FALSE;
}
- $hash = $this->get_hash('club' . $group_id);
+ $group_id = 'club' . $group_id;
+ $hash = $this->get_hash($group_id);
if (empty($hash))
{
$this->put_error_in_logfile('JS-Field "post_hash" not found!');
@@ -107,7 +140,8 @@ public function post_to_public_page($page_id, $message)
return FALSE;
}
- $hash = $this->get_hash('public' . $page_id);
+ $page_id = 'public' . $page_id;
+ $hash = $this->get_hash($page_id);
if (empty($hash))
{
$this->put_error_in_logfile('JS-Field "post_hash" not found!');
@@ -210,6 +244,8 @@ private function post_to_wall_query($hash, $to_id, $message, $official=FALSE, $f
$official = $official ? '1' : '';
$friends_only = $friends_only ? '1' : '';
+ $to_id_post = str_replace(array('id', 'public', 'club'), '', $to_id);
+
$post = array(
'act' => 'post',
'al' => '1',
@@ -220,10 +256,15 @@ private function post_to_wall_query($hash, $to_id, $message, $official=FALSE, $f
'note_title' => '',
'official' => $official,
'status_export' => '',
- 'to_id' => $to_id,
+ 'to_id' => $to_id_post,
'type' => $type,
);
+ if(sizeof($this->images))
+ {
+ $photos_attach = $this->load_photos($to_id);
+ }
+
$result = $this->minicurl->get_file('http://vkontakte.ru/al_wall.php', $post);
$this->sleep();
@@ -279,6 +320,62 @@ private function get_hash($page_id)
}
/*
+* private attach functions
+*/
+
+ private function load_photos($to_id)
+ {
+ $result = $this->minicurl->get_file('http://vkontakte.ru/' . $to_id);
+ $this->sleep();
+
+ preg_match('#"upload":\{"url":"([^"]+)","params":\{"act":"([^"]+)","aid":([^"]+),"gid":([^"]+),"mid":([^"]+),"hash":"([^"]+)","rhash":"([^"]+)","vk":"([^"]*)","from_host":"([^"]+)"},"opts":\{"server":"([^"]+)","default_error"#isU', $result, $match);
+
+ $url = str_replace('\\', '', $match[1]);
+ $server = $match[10];
+
+ $get_params = array(
+ 'act' => $match[2],
+ 'aid' => $match[3],
+ 'ajx' => '1',
+ 'gid' => $match[4],
+ 'mid' => $match[5],
+ 'hash' => $match[6],
+ 'rhash' => $match[7],
+ 'vk' => $match[8],
+ 'from_host' => $match[9]
+ );
+
+ $url .= '?' . http_build_query($get_params);
+
+ $vkimages = array();
+ foreach($this->images as $url)
+ {
+ $imgdata = file_get_contents($url);
+ $imgformat = end(explode('.', $url));
+ $imgfilename = DATA_DIR . '/' . rand(199122, 1992314) . '.' . $imgformat;
+ $imghandle = fopen($imgfilename, 'w');
+ fwrite($imghandle, $imgdata);
+ fclose($imghandle);
+
+ $post = array(
+ 'photo' => '@' . $imgfilename . ';type=image/' . $imgformat
+ );
+
+ $result = $this->minicurl->get_file($url, $post);
+ $this->sleep();
+
+ preg_match('#mid=([^&]+)&aid=([^&]+)&gid=([^&]+)&server=([^&]+)&photos=([^&]+)&hash=([^&]+)#isU', $result, $match);
+
+
+ var_dump($result);
+
+ unlink($imgfilename);
+ exit;
+ }
+ return $vkimages;
+ }
+
+/*
* private other functions
*/
View
@@ -9,7 +9,8 @@
define('SLEEPTIME', 2); // in seconds; +rand(1, 4) if this var != 0
// Files config
-define('COOKIES_FILE', SCR_DIR . '/data/cookies.txt'); // cookies
-define('LOG_FILE', SCR_DIR . '/data/logfile.txt'); // log
+define('DATA_DIR', SCR_DIR . '/data');
+define('COOKIES_FILE', DATA_DIR . '/cookies.txt'); // cookies
+define('LOG_FILE', DATA_DIR . '/logfile.txt'); // log
?>
View
@@ -28,6 +28,16 @@
exit();
}
+// добавление изображений к сообщению
+if(!$vk->attach_photos(array(
+ 'http://company.yandex.ru/i/kr7.jpg',
+ 'http://company.yandex.ru/i/datacenters/_MG_3279.jpg'
+)))
+{
+ echo $vk->print_last_error();
+ exit();
+}
+
// сообщение для публикации (обязательно в UTF-8)
$message = 'тестирование; testing';

0 comments on commit 94672bd

Please sign in to comment.