Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
956
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.52 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. public function ajax_get_groups(){
  212. $account = $this->model->get("*", FACEBOOK_ACCOUNTS, "id = '".post("id")."'".getDatabyUser());
  213. if(!empty($account)){
  214. switch (post("type")) {
  215. case 'group':
  216. $this->getGroups($account->id, $account->access_token);
  217. break;
  218.  
  219. case 'page':
  220. $this->getPages($account->id, $account->access_token);
  221. break;
  222.  
  223. case 'friend':
  224. $this->getFriends($account->id, $account->username, $account->password, $account->fid, $account->access_token);
  225. break;
  226. }
  227. ms(array(
  228. 'st' => 'success',
  229. "label" => "bg-light-green",
  230. 'txt' => l('Successfully')
  231. ));
  232. }else{
  233. ms(array(
  234. 'st' => 'error',
  235. "label" => "bg-red",
  236. 'txt' => l('Update failure')
  237. ));
  238. }
  239. }
  240.  
  241. public function ajax_action_item(){
  242. $id = (int)post('id');
  243. $POST = $this->model->get('*', FACEBOOK_ACCOUNTS, "id = '{$id}'".getDatabyUser());
  244. if(!empty($POST)){
  245. switch (post("action")) {
  246. case 'delete':
  247. $this->db->delete(FACEBOOK_GROUPS,"account_id = '".$id."'");
  248. $this->db->delete(FACEBOOK_ACCOUNTS, "id = '{$id}'".getDatabyUser());
  249. break;
  250.  
  251. case 'active':
  252. $this->db->update(FACEBOOK_ACCOUNTS, array("status" => 1), "id = '{$id}'".getDatabyUser());
  253. break;
  254.  
  255. case 'disable':
  256. $this->db->update(FACEBOOK_ACCOUNTS, array("status" => 0), "id = '{$id}'".getDatabyUser());
  257. break;
  258. }
  259. }
  260.  
  261. ms(array(
  262. 'st' => 'success',
  263. 'txt' => l('Successfully')
  264. ));
  265. }
  266.  
  267. public function ajax_action_multiple(){
  268. $ids =$this->input->post('id');
  269. if(!empty($ids)){
  270. foreach ($ids as $id) {
  271. $POST = $this->model->get('*', FACEBOOK_ACCOUNTS, "id = '{$id}'".getDatabyUser());
  272. if(!empty($POST)){
  273. switch (post("action")) {
  274. case 'delete':
  275. $this->db->delete(FACEBOOK_GROUPS,"account_id = '".$id."'");
  276. $this->db->delete(FACEBOOK_ACCOUNTS, "id = '{$id}'".getDatabyUser());
  277. break;
  278. case 'active':
  279. $this->db->update(FACEBOOK_ACCOUNTS, array("status" => 1), "id = '{$id}'".getDatabyUser());
  280. break;
  281.  
  282. case 'disable':
  283. $this->db->update(FACEBOOK_ACCOUNTS, array("status" => 0), "id = '{$id}'".getDatabyUser());
  284. break;
  285. }
  286. }
  287. }
  288. }
  289.  
  290. print_r(json_encode(array(
  291. 'st' => 'success',
  292. 'txt' => l('Successfully')
  293. )));
  294. }
  295. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement