PHP : Twitter 検索テンプレート

  twitter_search.php



<?php
require_once("common.php");

$result = '';
if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
	$result = twitter_search(
		$_SESSION['consumer_key'],
		$_SESSION['consumer_secret'],
		$_SESSION['access_token'],
		$_SESSION['access_token_secret'],
		$_POST['text']
	);
	if ( $result != '' ) {
		file_put_contents("json.txt", $result );
		$obj = json_decode($result);
		file_put_contents("json.php", "<" . "?php header(\"Content-type: text/plain; charset=utf-8\");  ?>" . print_r( $obj, true ) );

		$_SESSION['twitter_error'] = "";
		if ( $obj->error != '' ) {
			$_SESSION['twitter_error'] = $obj->error;
		}
		else {
			$cnt = count($obj->statuses);
			$search_result = "";
			for( $i = 0; $i < $cnt; $i++ ) {
				$search_result .= "<div class='entry'>";
				$search_result .= "<table><tr>";
				// 画像
				$search_result .= "<td><a href='https://twitter.com/{$obj->statuses[$i]->user->screen_name}/status/{$obj->statuses[$i]->id_str}' target='_blank' style='border:0'><img src='{$obj->statuses[$i]->user->profile_image_url}'></a></td>";
				// URL をアンカーに変換
				// テキスト
				$search_result .= "<td><pre style='margin-top:0'>" . url2a($obj->statuses[$i]->text) . "</pre></td>";
				$search_result .= "</tr></table>";
	
				// ***************************************************
				// 画像がある場合
				// ***************************************************
				if ( $obj->statuses[$i]->entities->media ) {
					$search_result .= "<img src='{$obj->statuses[$i]->entities->media[0]->media_url}' style='width:200px;'>";
				}
	
				$search_result .= "</div>";
			}

			$regex_result = "";

			$result = file_get_contents("json.php");
			preg_match_all("|(https?://.+?)[\"']?[;)>\\s]|u", $result, $matches, PREG_PATTERN_ORDER );
			$regex_result .= "<pre>";
			foreach( $matches[1] as $value ) {
				$regex_result .= (url2a( $value ) . "\n");
			}
			$regex_result .=  "</pre>";

		}



	}


}

require_once("view.php");



?>











  infoboard   管理者用   
このエントリーをはてなブックマークに追加





フリーフォントWEBサービス
SQLの窓WEBサービス

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ