コード例 #1
0
ファイル: googl.php プロジェクト: recetasdemama/wordpress
function googl_shortlink( $url, $post_id = false ) {
	global $post;
	if ( ! $post_id && $post ) $post_id = $post->ID;
	elseif ( $post_id ) $post = get_post( $post_id );

	if ( $post && $post->post_status != 'publish' )
		return "";

	$shortlink = $url;

	if ( ( is_singular() || $post ) && ! is_front_page() ) {
		$shortlink = get_post_meta( $post_id, '_googl_shortlink', true );
		if ( $shortlink )
			return $shortlink;

		$permalink = get_permalink( $post_id );
		$shortlink = googl_shorten( $permalink );

		if ( $shortlink !== $url ) {
			add_post_meta( $post_id, '_googl_shortlink', $shortlink, true );
			return $shortlink;
		}
		else {
			return $url;
		}
	} elseif ( is_front_page() ) {
		$shortlink = (string) get_option( '_googl_shortlink_home' );
		if ( $shortlink )
			return $shortlink;

		$googl_shortlink = googl_shorten( home_url( '/' ) );
		if ( $googl_shortlink !== $shortlink ) {
			update_option( '_googl_shortlink_home', $googl_shortlink );
			return $googl_shortlink;
		} else {
			return home_url( '/' );
		}
	}
}
コード例 #2
0
         curl_setopt($curlObj, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
         curl_setopt($curlObj, CURLOPT_POST, 1);
         curl_setopt($curlObj, CURLOPT_POSTFIELDS, $jsonData);
         $response = curl_exec($curlObj);
         $json = json_decode($response);
         curl_close($curlObj);
         return $json->id;
     }
     //added stuff by the spt project
     include "../spt_config/mysql_config.php";
     //get API key
     $r_api = mysql_query("SELECT value FROM settings WHERE setting = 'google_api'");
     while ($ra = mysql_fetch_assoc($r_api)) {
         $apiKey = $ra['value'];
     }
     $link = googl_shorten($link, $apiKey);
 }
 if (isset($shorten) && $shorten == "tinyurl") {
     //start curl session
     $ch = curl_init();
     //set curl options
     curl_setopt($ch, CURLOPT_URL, 'http://tinyurl.com/api-create.php?url=' . $link);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     //talk to tinyurl
     $link = curl_exec($ch);
     //close session
     curl_close($ch);
 }
 //store link in database
 mysql_query("UPDATE campaigns_responses SET url = '{$link}' WHERE response_id = '{$current_response_id}'");
 $url = $link;