script

Sunday, January 27, 2013

PHP Code to Post on facebook



<?php
/*Code start for facebook posting*/
$page_ID = 'PAGE ID IN WHICH APPLICATION RESIDES';
$FB_APPID       =    'APP ID';
$FB_SECRET       =    'APP SECRET';

$token_url       = 'https://graph.facebook.com/oauth/access_token?client_id='.$FB_APPID.'&client_secret='.$FB_SECRET.'&grant_type=client_credentials'.'&scope=publish_stream';


$response        =  file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$ACESS_TOKEN    =  $params['access_token'];

   
$data =    array( 'message'     => "MESSAGE_TEXT",
               'link'         => "LINK_TO_NEWS",
               'picture'     => "PATH_TO_IMAGE",
               'name'         => "NAME_OF_NEWS",
               'description' => "NEWS_DESCRIPTION"
             );
   

// need token
$data['access_token'] = $ACESS_TOKEN;
//$data['access_token'] = 'AAACTEbbNVLkBAG01k5U4lP4ItDhMntPZADTeSHDfZBnHAmUktBAiZAps3W2VNB0qdEyv7M4WmkhvBZCesATZCFltGXaqCPgHxKwSbssYKIgTHdqKvmEwZB';
$ch = curl_init();
//print_r($ch); exit;
curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/'.$page_ID.'/feed');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
// execute and close
$return = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);

?>

Monday, January 21, 2013

Get url in typo3

function getURL($id,$additionalParams="")
    {
        $this->fullURL = t3lib_div::getIndpEnv('TYPO3_SITE_URL');
        $cObject = t3lib_div::makeInstance('tslib_cObj');
        $configurations['additionalParams'] = $additionalParams;
        $configurations['returnLast'] = 'url'; // get it as URL
        $configurations['parameter'] =  $id;
        return $this->fullURL.htmlspecialchars($cObject->typolink(NULL, $configurations));
    }

Prevent files from being accessed by URL

Write below lines in .htaccess, It will then give message of forbidden

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost.*$ [NC]
RewriteRule \.(pdf|t3x|xps|JPG|t3x|exe|pdf|jpg|png|jpg|php|js)$ - [F]