75 } |
76 } |
76 if(file_exists(dirname(__FILE__)."/$req_rep/traduction.php")) { |
77 if(file_exists(dirname(__FILE__)."/$req_rep/traduction.php")) { |
77 include_once dirname(__FILE__)."/$req_rep/traduction.php"; |
78 include_once dirname(__FILE__)."/$req_rep/traduction.php"; |
78 } |
79 } |
79 |
80 |
|
81 $appCacheHandle = new SQLite3(dirname(__FILE__)."/data/app_cache.db"); |
|
82 $appCacheHandle->query("CREATE TABLE IF NOT EXISTS apps (id INTEGER PRIMARY KEY, domain TEXT UNIQUE NOT NULL, app_key TEXT UNIQUE NOT NULL, app_secret TEXT NOT NULL)"); |
|
83 |
|
84 |
80 |
85 |
81 /** |
86 /** |
82 * Start up the ol' session engine |
87 * Start up the ol' session engine |
83 */ |
88 */ |
84 session_start(); |
89 session_start(); |
87 * Include the configuration data for our OAuth Client (array $configuration) |
92 * Include the configuration data for our OAuth Client (array $configuration) |
88 */ |
93 */ |
89 include_once dirname(__FILE__).'/config.php'; |
94 include_once dirname(__FILE__).'/config.php'; |
90 |
95 |
91 |
96 |
92 $get_twitter_request_token = function () use ($req_rep) { |
97 $get_social_request_token = function ($loginDomain, $config) use ($req_rep, $appCacheHandle) { |
93 |
98 |
94 $twitterClient = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET); |
99 $socialNetwork = $config['social_network']; |
95 $token = $twitterClient->oauth('oauth/request_token', array('oauth_callback' => URL_ROOT."callback.php?rep=$req_rep")); |
100 |
96 |
101 if($socialNetwork == "Twitter") { |
97 $_SESSION['TWITTER_REQUEST_TOKEN'] = serialize($token); |
102 |
98 |
103 $twitterClient = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET); |
99 /** |
104 $token = $twitterClient->oauth('oauth/request_token', array('oauth_callback' => URL_ROOT."callback.php?rep=$req_rep")); |
100 * Now redirect user to Twitter site so they can log in and |
105 |
101 * approve our access |
106 $_SESSION['TWITTER_REQUEST_TOKEN'] = serialize($token); |
102 */ |
107 |
103 $url = $twitterClient->url('oauth/authorize', array('oauth_token' => $token['oauth_token'])); |
108 /** |
104 header("Location: ".$url); |
109 * Now redirect user to Twitter site so they can log in and |
105 die(); |
110 * approve our access |
|
111 */ |
|
112 |
|
113 $url = $twitterClient->url('oauth/authorize', array('oauth_token' => $token['oauth_token'])); |
|
114 header("Location: ".$url); |
|
115 die(); |
|
116 } else if($socialNetwork == "Mastodon") { |
|
117 $mastodonApi = new Api($loginDomain); |
|
118 |
|
119 $cachedApp = $appCacheHandle->querySingle(""); |
|
120 $statement = $cachedApp->prepare('SELECT * FROM apps WHERE domain = :domain;'); |
|
121 $statement->bindValue(':domain', $loginDomain); |
|
122 |
|
123 $result = $statement->execute(); |
|
124 // Create app |
|
125 $appsDef = $mastodonApi->apps()->create("PolemicToot", URL_ROOT."callback.php?rep=$req_rep", 'read write push'); |
|
126 var_dump($appsDef); |
|
127 //$mastodonApi->logIn(); |
|
128 } |
106 }; |
129 }; |
107 |
130 |
108 /** |
131 /** |
109 * TRADUCTION |
132 * TRADUCTION |
110 **/ |
133 **/ |