Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
810
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.67 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3.  
  4. class facebook_accounts extends MX_Controller {
  5.  
  6. public function __construct(){
  7. parent::__construct();
  8. $this->load->model(get_class($this).'_model', 'model');
  9. }
  10.  
  11. public function index(){
  12. $data = array(
  13. "result" => $this->model->getAccounts()
  14. );
  15. $this->template->title(l('Facebook accounts'));
  16. $this->template->build('index', $data);
  17. }
  18.  
  19. public function update(){
  20. $accounts = $this->model->fetch("*", FACEBOOK_ACCOUNTS, getDatabyUser(0));
  21. $account = $this->model->get("*", FACEBOOK_ACCOUNTS, "id = '".get("id")."'".getDatabyUser());
  22. $data = array(
  23. 'result' => $account,
  24. 'count' => count($accounts)
  25. );
  26. $this->template->title(l('Facebook accounts'));
  27. $this->template->build('update', $data);
  28. }
  29.  
  30. public function ajax_get_page_token(){
  31. $username = post('username');
  32. $password = post('password');
  33. $app = post('app');
  34.  
  35. if($username == "" && $password == "" && $app == ""){
  36. ms(array(
  37. "st" => "error",
  38. "label" => "bg-red",
  39. "txt" => l('Please input all fields')
  40. ));
  41. }
  42.  
  43. if(strlen($password) < 6){
  44. ms(array(
  45. "st" => "error",
  46. "label" => "bg-red",
  47. "txt" => l('Passwords must be at least 6 characters long')
  48. ));
  49. }
  50. $url = GET_PAGE_ACCESS_TOKEN($username, $password, $app);
  51.  
  52. ms(array(
  53. "st" => "success",
  54. "label" => "bg-light-green",
  55. "txt" => l('Update successfully'),
  56. "url" => $url
  57. ));
  58. }
  59.  
  60. public function ajax_update(){
  61. $username = post('username');
  62. $password = post('password');
  63. $access_token = $this->input->post('access_token');
  64. $access_token_parse = json_decode($access_token);
  65. if(is_object($access_token_parse)){
  66. if(isset($access_token_parse->access_token)){
  67. $access_token = $access_token_parse->access_token;
  68. }
  69. }
  70.  
  71. if($access_token == ""){
  72. ms(array(
  73. "st" => "error",
  74. "label" => "bg-red",
  75. "txt" => l('Please enter access token')
  76. ));
  77. }
  78.  
  79. $FbOAuth_App = FbOAuth_Info_App($access_token);
  80.  
  81. if(!empty($FbOAuth_App) && isset($FbOAuth_App['error'])){
  82. ms(array(
  83. "st" => "error",
  84. "label" => "bg-red",
  85. "txt" => l($FbOAuth_App['error']['message'])
  86. ));
  87. }
  88.  
  89. $FbOAuth_User = FbOAuth_User($access_token);
  90. $fid = $FbOAuth_User['id'];
  91. $data = array(
  92. "uid" => session("uid"),
  93. "fid" => $fid,
  94. "username" => (isset($FbOAuth_User['email']))?$FbOAuth_User['email']:$fid,
  95. "fullname" => $FbOAuth_User['name'],
  96. //"password" => $password,
  97. "token_name" => $FbOAuth_App['name'],
  98. "access_token" => $access_token
  99. );
  100.  
  101. $id = (int)post("id");
  102. $accounts = $this->model->fetch("*", FACEBOOK_ACCOUNTS, getDatabyUser(0));
  103. if($id == 0){
  104. if(count($accounts) < getMaximumAccount()){
  105. $checkAccount = $this->model->get("*", FACEBOOK_ACCOUNTS, "fid = '".$fid."'".getDatabyUser());
  106. if(!empty($checkAccount)){
  107. ms(array(
  108. "st" => "error",
  109. "label" => "bg-red",
  110. "txt" => l('This facebook account already exists')
  111. ));
  112. }
  113.  
  114. $this->db->insert(FACEBOOK_ACCOUNTS, $data);
  115. $id = $this->db->insert_id();
  116. $this->getPages($id, $access_token);
  117. $this->getGroups($id, $access_token);
  118. $this->getFriends($id, $username, $password, $fid, $access_token);
  119. }else{
  120. ms(array(
  121. "st" => "error",
  122. "label" => "bg-orange",
  123. "txt" => l('Oh sorry! You have exceeded the number of accounts allowed, You are only allowed to update your account')
  124. ));
  125. }
  126. }else{
  127. $checkAccount = $this->model->get("*", FACEBOOK_ACCOUNTS, "fid = '".$fid."' AND id != '".$id."'".getDatabyUser());
  128. if(!empty($checkAccount)){
  129. ms(array(
  130. "st" => "error",
  131. "label" => "bg-red",
  132. "txt" => l('This facebook account already exists')
  133. ));
  134. }
  135.  
  136. $this->db->update(FACEBOOK_ACCOUNTS, $data, array("id" => post("id")));
  137. }
  138.  
  139. ms(array(
  140. "st" => "success",
  141. "label" => "bg-light-green",
  142. "txt" => l('Update successfully')
  143. ));
  144. }
  145.  
  146. public function getFriends($id, $username, $password = "", $fid = "", $access_token = ""){
  147. $fiends = FbOAuth_Friends($username, $password, $fid, $access_token);
  148. //pr($fiends,1);
  149. if(!empty($fiends)) {
  150. $count=0;
  151. $insert_string = "INSERT INTO `".FACEBOOK_GROUPS."` (`account_id`,`type`,`uid`,`pid`,`name`,`privacy`,`category`,`status`) VALUES ";
  152. $this->db->delete(FACEBOOK_GROUPS,"account_id = '".$id."' AND type = 'friend'");
  153. foreach ($fiends as $row) {
  154. if(isset($row['name'])){
  155. $insert_string .= "('".$id."','friend','".session("uid")."','".$row['id']."','".clean($row['name'])."','','','1')";
  156. $insert_string .= ",";
  157. $count++;
  158. }
  159. }
  160.  
  161. if($count != 0){
  162. $insert_string=substr($insert_string,0,-1);
  163. $this->db->query($insert_string);
  164. }
  165. }
  166. }
  167.  
  168. public function getPages($id, $access_token){
  169. $pages = FbOAuth_Pages($access_token);
  170. if(isset($pages["data"]) && !empty($pages["data"])) {
  171. $count=0;
  172. $insert_string = "INSERT INTO `".FACEBOOK_GROUPS."` (`account_id`,`type`,`uid`,`pid`,`name`,`privacy`,`category`,`status`) VALUES ";
  173. $this->db->delete(FACEBOOK_GROUPS,"account_id = '".$id."' AND type = 'page'");
  174. foreach ($pages["data"] as $row) {
  175. if(isset($row['name'])){
  176. $insert_string .= "('".$id."','page','".session("uid")."','".$row['id']."','".clean($row['name'])."','','".clean($row['category'])."','1')";
  177. $insert_string .= ",";
  178. $count++;
  179. }
  180. }
  181.  
  182. if($count != 0){
  183. $insert_string=substr($insert_string,0,-1);
  184. $this->db->query($insert_string);
  185. }
  186. }
  187. }
  188.  
  189. public function getGroups($id, $access_token){
  190. $groups_filters = array('comércio', 'usados', 'usado', '0800', 'catira', 'catiras', 'feirão', 'classificados', 'classificado', 'vendas', 'venda', 'olx', 'vende', 'gambiras', 'gambira', 'compra', 'compras', 'compre', 'feira', 'brique', 'brick', 'bricks', 'brik', 'troca', 'trocas', 'desapego', 'desapegos', 'troque', 'desapega', 'joga', 'rolo', 'bazar', 'mercado', 'vende-se', '44', 'mercadão', 'negócio', 'negócios', 'negocios', 'negocio', 'barganha', 'barganhas', 'shop', 'free shop', 'freeshop', 'galinha morta', 'enjoei', 'desapeguei', 'topa tudo', 'torra', 'festa infantil', 'pos festa');
  191.  
  192. $groups = FbOAuth_Groups($access_token);
  193. if(isset($groups["data"]) && !empty($groups["data"])) {
  194. $count=0;
  195. $insert_string = "INSERT INTO `".FACEBOOK_GROUPS."` (`account_id`,`type`,`uid`,`pid`,`name`,`privacy`,`category`,`status`) VALUES ";
  196. $this->db->delete(FACEBOOK_GROUPS,"account_id = '".$id."' AND type = 'group'");
  197. foreach ($groups["data"] as $row) {
  198.  
  199. if(isset($row['name'])){
  200. if(isset($row['name'])){
  201. $found = count(array_intersect($groups_filters, explode(" ", strtolower($row['name']))));
  202. }
  203. if($found >= 1) {
  204. $insert_string .= "('".$id."','group','".session("uid")."','".$row['id']."','".clean($row['name'])."','".$row['privacy']."','','1')";
  205. $insert_string .= ",";
  206. }
  207. $count++;
  208. }
  209. }
  210.  
  211. if($count != 0){
  212. $insert_string=substr($insert_string,0,-1);
  213. $this->db->query($insert_string);
  214. }
  215. }
  216. }
  217.  
  218. public function ajax_get_groups(){
  219. $account = $this->model->get("*", FACEBOOK_ACCOUNTS, "id = '".post("id")."'".getDatabyUser());
  220. if(!empty($account)){
  221. switch (post("type")) {
  222. case 'group':
  223. $this->getGroups($account->id, $account->access_token);
  224. break;
  225.  
  226. case 'page':
  227. $this->getPages($account->id, $account->access_token);
  228. break;
  229.  
  230. case 'friend':
  231. $this->getFriends($account->id, $account->username, $account->password, $account->fid, $account->access_token);
  232. break;
  233. }
  234. ms(array(
  235. 'st' => 'success',
  236. "label" => "bg-light-green",
  237. 'txt' => l('Successfully')
  238. ));
  239. }else{
  240. ms(array(
  241. 'st' => 'error',
  242. "label" => "bg-red",
  243. 'txt' => l('Update failure')
  244. ));
  245. }
  246. }
  247.  
  248. public function ajax_action_item(){
  249. $id = (int)post('id');
  250. $POST = $this->model->get('*', FACEBOOK_ACCOUNTS, "id = '{$id}'".getDatabyUser());
  251. if(!empty($POST)){
  252. switch (post("action")) {
  253. case 'delete':
  254. $this->db->delete(FACEBOOK_GROUPS,"account_id = '".$id."'");
  255. $this->db->delete(FACEBOOK_ACCOUNTS, "id = '{$id}'".getDatabyUser());
  256. break;
  257.  
  258. case 'active':
  259. $this->db->update(FACEBOOK_ACCOUNTS, array("status" => 1), "id = '{$id}'".getDatabyUser());
  260. break;
  261.  
  262. case 'disable':
  263. $this->db->update(FACEBOOK_ACCOUNTS, array("status" => 0), "id = '{$id}'".getDatabyUser());
  264. break;
  265. }
  266. }
  267.  
  268. ms(array(
  269. 'st' => 'success',
  270. 'txt' => l('Successfully')
  271. ));
  272. }
  273.  
  274. public function ajax_action_multiple(){
  275. $ids =$this->input->post('id');
  276. if(!empty($ids)){
  277. foreach ($ids as $id) {
  278. $POST = $this->model->get('*', FACEBOOK_ACCOUNTS, "id = '{$id}'".getDatabyUser());
  279. if(!empty($POST)){
  280. switch (post("action")) {
  281. case 'delete':
  282. $this->db->delete(FACEBOOK_GROUPS,"account_id = '".$id."'");
  283. $this->db->delete(FACEBOOK_ACCOUNTS, "id = '{$id}'".getDatabyUser());
  284. break;
  285. case 'active':
  286. $this->db->update(FACEBOOK_ACCOUNTS, array("status" => 1), "id = '{$id}'".getDatabyUser());
  287. break;
  288.  
  289. case 'disable':
  290. $this->db->update(FACEBOOK_ACCOUNTS, array("status" => 0), "id = '{$id}'".getDatabyUser());
  291. break;
  292. }
  293. }
  294. }
  295. }
  296.  
  297. print_r(json_encode(array(
  298. 'st' => 'success',
  299. 'txt' => l('Successfully')
  300. )));
  301. }
  302. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement