set_time_limit(60); // 60 , . require_once ROOT_DIR.'/libs/MadelineProto/vendor/autoload.php'; // , - . C ReadMe github. $settings = [ 'authorization' => [ 'default_temp_auth_key_expires_in' => 315576000, // 10 , . ], 'app_info' => [ // https://my.telegram.org 'api_id' => XXXXX, 'api_hash' => XXXXXXXXXX ], 'logger' => [ // 'logger' => 3, // echo 'logger_level' => 'FATAL ERROR', // . ], 'max_tries' => [ // . , 'query' => 5, 'authorization' => 5, 'response' => 5, ], 'updates' => [ // , . 'handle_updates' => false, 'handle_old_updates' => false, ], ]; $MadelineProto = new \danog\MadelineProto\API($settings); $MadelineProto->phone_login(readline('Enter your phone number: ')); // $authorization = $MadelineProto->complete_phone_login(readline('Enter the code you received: ')); // , if ($authorization['_'] === 'account.noPassword') { throw new \danog\MadelineProto\Exception('2FA is enabled but no password is set!'); } if ($authorization['_'] === 'account.password') { $authorization = $MadelineProto->complete_2fa_login(readline('Please enter your password (hint '.$authorization['hint'].'): ')); // , . } if ($authorization['_'] === 'account.needSignup') { $authorization = $MadelineProto->complete_signup(readline('Please enter your first name: '), readline('Please enter your last name (can be empty): ')); } $MadelineProto->session = 'session.madeline'; $MadelineProto->serialize(); // , .
require_once ROOT_DIR.'/libs/MadelineProto/vendor/autoload.php'; $MadelineProto = new \danog\MadelineProto\API('session.madeline'); $settings = array( 'peer' => '@'.$val['url'], //_, @, @breakingmash, , limit, 0 'offset_id' => $val['offset_id']?:0, 'offset_date' => $val['offset_date']?:0, 'add_offset' => $val['add_offset']?:0, 'limit' => $val['limit']?:10, // , 'max_id' => $val['max_id']?:0, // id 'min_id' => $val['min_id']?:0, // id - , 0 . 'hash' => 0 ); $data = $MadelineProto->messages->getHistory($settings);
if (!is_array($url)){ if (mb_strpos($url,',')!==false){ $url = explode(',',$url); }else{ $url = [$url]; } } if (!empty($url)) { require_once ROOT_DIR.'/libs/MadelineProto/vendor/autoload.php'; $file_contents = []; foreach ($url as $val){ if (!is_array($val)){ $val = array( 'url' => $val ); } $settings = array( 'peer' => '@'.$val['url'], 'offset_id' => $val['offset_id']?:0, 'offset_date' => $val['offset_date']?:0, 'add_offset' => $val['add_offset']?:0, 'limit' => $val['limit']?:10, 'max_id' => $val['max_id']?:0, 'min_id' => $val['min_id']?:0, 'hash' => 0 ); $file_contents[$val['url']] = $MadelineProto->messages->getHistory($settings); } }
private function telegram_media_parse($posts_data, $source){ include_once(ROOT_DIR.'/libs/phpQuery.php'); // html phpQuery foreach ($posts_data as &$post_data) { if (!empty($post_data['media'])){ $file_contents = self::loader($post_data['post_url'],'site');// curl html . $document = phpQuery::newDocumentHTML($file_contents); // dom- html $post_data['post_image'] = preg_replace('/[\s\S]*background-image:[ ]*url\(["\']*([\s\S]*[^"\'])["\']*\)[\s\S]*/u','$1',$document->find($source['rules']['post_img_path'])->eq(0)->attr('style')); // background-image . $post_data['post_description'] = $document->find($source['rules']['post_text_path'])->eq(0)->text(); // caption . } unset($post_data['media']); } unset($post_data); return $posts_data; }
Source: https://habr.com/ru/post/349942/