Advertisement
plas71k

fb app system: inc/functions.php

Dec 4th, 2012
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.48 KB | None | 0 0
  1. <?php
  2. function fb_profile_picture($id_user)
  3.     {
  4.         global $facebook;
  5.          
  6.         $profile_picture = $facebook->api(array('method' => 'fql.query', 'query' => "select src_big from photo where pid in (select cover_pid from album where owner='".$id_user."' and name='Profile Pictures')"));
  7.          
  8.         if(!empty($profile_picture[0]['src_big']))
  9.         {
  10.             $url_image = $profile_picture[0]['src_big'];
  11.         }
  12.             else
  13.         {
  14.             $url_image = 'http://graph.facebook.com/'.$id_user.'/picture?type=large';
  15.         }
  16.  
  17.         $file = dirname(dirname(__FILE__)).'/page/generate/'.$id_user.'.jpg';
  18.  
  19.         if(function_exists('fopen'))
  20.         {
  21.             $image = file_get_contents($url_image);
  22.         }
  23.             else
  24.         {
  25.             $curl_handle=curl_init();
  26.             curl_setopt($curl_handle,CURLOPT_URL,$url_image);
  27.             curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
  28.             curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
  29.             $image = curl_exec($curl_handle);
  30.             curl_close($curl_handle);
  31.         }
  32.  
  33.         file_put_contents($file, $image);
  34.     }
  35.  
  36.      
  37.  
  38.     function postGeneratedImage($img)
  39.     {
  40.         global $facebook, $user;
  41.  
  42.         /* DETECT APLICATION */
  43.         $album_name        = ALBUM_NAME;
  44.         $album_description = ALBUM_DESCRIPTION;
  45.         $photo_description = PHOTO_DESCRIPTION;
  46.  
  47.         $facebook->setFileUploadSupport(true);
  48.         $album = $facebook->api(array('method' => 'fql.query','query' => "SELECT object_id FROM album WHERE owner='".$user['id']."' AND name='".$album_name."'"));
  49.  
  50.         if(!$album)
  51.         {
  52.             $create_album = $facebook->api('/me/albums', 'post', array('message'=> str_replace("#LINK_TAG#", PAGE_URL.'?sk=app_'.APP_ID, $album_description), 'name'=> $album_name));
  53.             $album_uid = $create_album['id'];
  54.         }
  55.             else
  56.         {
  57.             $album_uid = $album[0]['object_id'];
  58.         }
  59.  
  60.         $upload_photo = $facebook->api('/'.$album_uid.'/photos', 'post', array('message' => str_replace("#LINK_TAG#", PAGE_URL.'?sk=app_'.APP_ID, $photo_description), 'image' => '@' . realpath($img)));
  61.     }
  62. session_start();
  63. //The License key as found in the License Mate system
  64. $key = DOMAIN_KEY;
  65. //Location of the License Mate System
  66. $host = 'licence.sillytalks.com';
  67.  
  68. if (!(isset($_SESSION['license']))) {
  69.     ini_set('default_socket_timeout', 1);
  70.     //Get the return fo the system.
  71.     $return = @file_get_contents('http://'.$host.'/index.php?p=api&host='.$_SERVER["HTTP_HOST"].'&key='.$key);
  72.     //If Connection failed do nothing (the server might be expierencing problems, not a reason to den usage of the system).
  73.     if (!($return === FALSE)) {
  74.         if (!($return==1)) {
  75.          
  76.             //There was a problem with the license, you can do anything you like here. We decided to display the error returned and exit the script.
  77.             echo $return;
  78.             exit();
  79.              
  80.         } else {
  81.              
  82.             //The license is correct, to skip further uneccesary load on the server we place a session variable. You may replace this with your own system, but don't forget to edit the IF satement further up in this script.
  83.             $_SESSION['license'] = '1';
  84.              
  85.         }
  86.     }
  87. }
  88. //The license is valid.
  89.     function app_core()
  90.     {
  91.         global $user;
  92.          
  93.         $path_fonts = dirname(dirname(__FILE__)).'/page/font/';
  94.         $img = dirname(dirname(__FILE__)).'/page/generate/image'. $user['id'] .'.jpg';
  95.          
  96.  
  97.         if (!file_exists($img))
  98.         {
  99.              
  100.              
  101.             fb_profile_picture($user['id']);
  102.              
  103.  
  104.             /* PROFILES */
  105.             $file_1 = dirname(dirname(__FILE__)).'/page/generate/'.$user['id'].'.jpg';
  106.              
  107.  
  108.             /* RESIZE */
  109.             include("resize.php");
  110.              
  111.             if(file_exists($file_1))
  112.             {
  113.                 $resizeObj = new resize($file_1);
  114.                 $resizeObj -> resizeImage(USER_PIC_SIZE_X, USER_PIC_SIZE_Y, 'exact');
  115.                 $resizeObj -> saveImage($file_1, 100);
  116.             }
  117.                 else
  118.             {
  119.                 $file_1 = dirname(dirname(__FILE__)).'/page/images/default-user.jpg';
  120.             }
  121.  
  122.              
  123.  
  124. //======================================== PAYMENT =====================================//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement