· 7 years ago · Oct 31, 2018, 03:32 PM
1<?php
2namespace Plugins\AutoFollow;
3const IDNAME = "auto-follow";
4
5// Disable direct access
6if (!defined('APP_VERSION'))
7 die("Yo, what's up?");
8
9
10/**
11 * Event: plugin.install
12 */
13function install($Plugin)
14{
15 if ($Plugin->get("idname") != IDNAME) {
16 return false;
17 }
18
19 $sql = "CREATE TABLE IF NOT EXISTS `".TABLE_PREFIX."auto_follow_schedule` (
20 `id` INT NOT NULL AUTO_INCREMENT ,
21 `user_id` INT NOT NULL ,
22 `account_id` INT NOT NULL ,
23 `target` TEXT NOT NULL ,
24 `speed` VARCHAR(20) NOT NULL ,
25 `daily_pause` BOOLEAN NOT NULL,
26 `daily_pause_from` TIME NOT NULL,
27 `daily_pause_to` TIME NOT NULL,
28 `is_active` BOOLEAN NOT NULL ,
29 `schedule_date` DATETIME NOT NULL ,
30 `end_date` DATETIME NOT NULL ,
31 `last_action_date` DATETIME NOT NULL ,
32 `data` TEXT NOT NULL,
33 PRIMARY KEY (`id`),
34 INDEX (`user_id`),
35 INDEX (`account_id`)
36 ) ENGINE = InnoDB;";
37
38 $sql .= "CREATE TABLE IF NOT EXISTS `".TABLE_PREFIX."auto_follow_log` (
39 `id` INT NOT NULL AUTO_INCREMENT ,
40 `user_id` INT NOT NULL ,
41 `account_id` INT NOT NULL ,
42 `status` VARCHAR(20) NOT NULL,
43 `followed_user_pk` VARCHAR(50) NOT NULL,
44 `data` TEXT NOT NULL ,
45 `date` DATETIME NOT NULL ,
46 PRIMARY KEY (`id`),
47 INDEX (`user_id`),
48 INDEX (`account_id`),
49 INDEX (`followed_user_pk`)
50 ) ENGINE = InnoDB;";
51
52 $sql .= "ALTER TABLE `".TABLE_PREFIX."auto_follow_schedule`
53 ADD CONSTRAINT `".uniqid("ibfk_")."` FOREIGN KEY (`user_id`)
54 REFERENCES `".TABLE_PREFIX."users`(`id`)
55 ON DELETE CASCADE ON UPDATE CASCADE;";
56
57 $sql .= "ALTER TABLE `".TABLE_PREFIX."auto_follow_schedule`
58 ADD CONSTRAINT `".uniqid("ibfk_")."` FOREIGN KEY (`account_id`)
59 REFERENCES `".TABLE_PREFIX."accounts`(`id`)
60 ON DELETE CASCADE ON UPDATE CASCADE;";
61
62 $sql .= "ALTER TABLE `".TABLE_PREFIX."auto_follow_log`
63 ADD CONSTRAINT `".uniqid("ibfk_")."` FOREIGN KEY (`user_id`)
64 REFERENCES `".TABLE_PREFIX."users`(`id`)
65 ON DELETE CASCADE ON UPDATE CASCADE;";
66
67 $sql .= "ALTER TABLE `".TABLE_PREFIX."auto_follow_log`
68 ADD CONSTRAINT `".uniqid("ibfk_")."` FOREIGN KEY (`account_id`)
69 REFERENCES `".TABLE_PREFIX."accounts`(`id`)
70 ON DELETE CASCADE ON UPDATE CASCADE;";
71
72 $pdo = \DB::pdo();
73 $stmt = $pdo->prepare($sql);
74 $stmt->execute();
75}
76\Event::bind("plugin.install", __NAMESPACE__ . '\install');
77
78
79
80/**
81 * Event: plugin.remove
82 */
83function uninstall($Plugin)
84{
85 if ($Plugin->get("idname") != IDNAME) {
86 return false;
87 }
88
89 // Remove plugin settings
90 $Settings = \Controller::model("GeneralData", "plugin-auto-follow-settings");
91 $Settings->remove();
92
93 // Remove plugin tables
94 $sql = "DROP TABLE `".TABLE_PREFIX."auto_follow_schedule`;";
95 $sql .= "DROP TABLE `".TABLE_PREFIX."auto_follow_log`;";
96
97 $pdo = \DB::pdo();
98 $stmt = $pdo->prepare($sql);
99 $stmt->execute();
100}
101\Event::bind("plugin.remove", __NAMESPACE__ . '\uninstall');
102
103
104/**
105 * Add module as a package options
106 * Only users with correct permission
107 * Will be able to use module
108 *
109 * @param array $package_modules An array of currently active
110 * modules of the package
111 */
112function add_module_option($package_modules)
113{
114 $config = include __DIR__."/config.php";
115 ?>
116 <div class="mt-15">
117 <label>
118 <input type="checkbox"
119 class="checkbox"
120 name="modules[]"
121 value="<?= IDNAME ?>"
122 <?= in_array(IDNAME, $package_modules) ? "checked" : "" ?>>
123 <span>
124 <span class="icon unchecked">
125 <span class="mdi mdi-check"></span>
126 </span>
127 <?= __('Auto Follow') ?>
128 </span>
129 </label>
130 </div>
131 <?php
132}
133\Event::bind("package.add_module_option", __NAMESPACE__ . '\add_module_option');
134
135
136
137
138/**
139 * Map routes
140 */
141function route_maps($global_variable_name)
142{
143 // Settings (admin only)
144 $GLOBALS[$global_variable_name]->map("GET|POST", "/e/".IDNAME."/settings/?", [
145 PLUGINS_PATH . "/". IDNAME ."/controllers/SettingsController.php",
146 __NAMESPACE__ . "\SettingsController"
147 ]);
148
149 // Index
150 $GLOBALS[$global_variable_name]->map("GET|POST", "/e/".IDNAME."/?", [
151 PLUGINS_PATH . "/". IDNAME ."/controllers/IndexController.php",
152 __NAMESPACE__ . "\IndexController"
153 ]);
154
155 // Index
156 $GLOBALS[$global_variable_name]->map("GET|POST", "/e/".IDNAME."/sort/[:action]?", [
157 PLUGINS_PATH . "/". IDNAME ."/controllers/IndexController.php",
158 __NAMESPACE__ . "\IndexController"
159 ]);
160
161 // Schedule
162 $GLOBALS[$global_variable_name]->map("GET|POST", "/e/".IDNAME."/[i:id]/?", [
163 PLUGINS_PATH . "/". IDNAME ."/controllers/ScheduleController.php",
164 __NAMESPACE__ . "\ScheduleController"
165 ]);
166
167 // Log
168 $GLOBALS[$global_variable_name]->map("GET|POST", "/e/".IDNAME."/[i:id]/log/?", [
169 PLUGINS_PATH . "/". IDNAME ."/controllers/LogController.php",
170 __NAMESPACE__ . "\LogController"
171 ]);
172}
173\Event::bind("router.map", __NAMESPACE__ . '\route_maps');
174
175
176
177/**
178 * Event: navigation.add_special_menu
179 */
180function navigation($Nav, $AuthUser)
181{
182 $idname = IDNAME;
183 include __DIR__."/views/fragments/navigation.fragment.php";
184}
185\Event::bind("navigation.add_special_menu", __NAMESPACE__ . '\navigation');
186
187
188
189/**
190 * Add cron task to follow new users
191 */
192function addCronTask()
193{
194 require_once __DIR__."/models/SchedulesModel.php";
195 require_once __DIR__."/models/LogModel.php";
196
197
198 // Get auto follow schedules
199 $Schedules = new SchedulesModel;
200 $Schedules->where("is_active", "=", 1)
201 ->where("schedule_date", "<=", date("Y-m-d H:i:s"))
202 ->where("end_date", ">=", date("Y-m-d H:i:s"))
203 ->orderBy("last_action_date", "ASC")
204 ->setPageSize(10) // required to prevent server overload
205 ->setPage(1)
206 ->fetchData();
207
208 if ($Schedules->getTotalCount() < 1) {
209 return false;
210 }
211
212 $settings = namespace\settings();
213 $default_speeds = [
214 "very_slow" => 1,
215 "slow" => 2,
216 "medium" => 3,
217 "fast" => 4,
218 "very_fast" => 5,
219 ];
220 $speeds = $settings->get("data.speeds");
221 if (empty($speeds)) {
222 $speeds = [];
223 } else {
224 $speeds = json_decode(json_encode($speeds), true);
225 }
226 $speeds = array_merge($default_speeds, $speeds);
227
228 $as = [__DIR__."/models/ScheduleModel.php", __NAMESPACE__."\ScheduleModel"];
229 foreach ($Schedules->getDataAs($as) as $sc) {
230 $Log = new LogModel;
231 $Account = \Controller::model("Account", $sc->get("account_id"));
232 $User = \Controller::model("User", $sc->get("user_id"));
233
234 // Calculate next schedule datetime...
235 if (isset($speeds[$sc->get("speed")]) && (int)$speeds[$sc->get("speed")] > 0) {
236 $speed = (int)$speeds[$sc->get("speed")];
237 $delta = round(3600/$speed);
238
239 if ($settings->get("data.random_delay")) {
240 $delay = rand(0, 300);
241 $delta += $delay;
242 }
243 } else {
244 $delta = rand(720, 7200);
245 }
246
247 $next_schedule = date("Y-m-d H:i:s", time() + $delta);
248 if ($sc->get("daily_pause")) {
249 $pause_from = date("Y-m-d")." ".$sc->get("daily_pause_from");
250 $pause_to = date("Y-m-d")." ".$sc->get("daily_pause_to");
251 if ($pause_to <= $pause_from) {
252 // next day
253 $pause_to = date("Y-m-d", time() + 86400)." ".$sc->get("daily_pause_to");
254 }
255
256 if ($next_schedule > $pause_to) {
257 // Today's pause interval is over
258 $pause_from = date("Y-m-d H:i:s", strtotime($pause_from) + 86400);
259 $pause_to = date("Y-m-d H:i:s", strtotime($pause_to) + 86400);
260 }
261
262 if ($next_schedule >= $pause_from && $next_schedule <= $pause_to) {
263 $next_schedule = $pause_to;
264 }
265 }
266 $sc->set("schedule_date", $next_schedule)
267 ->set("last_action_date", date("Y-m-d H:i:s"))
268 ->save();
269
270
271 // Set default values for the log...
272 $Log->set("user_id", $User->get("id"))
273 ->set("account_id", $Account->get("id"))
274 ->set("status", "error");
275
276
277 // Check account
278 if (!$Account->isAvailable() || $Account->get("login_required")) {
279 // Account is either removed (unexected, external factors)
280 // Or login required for this account
281 // Deactivate schedule
282 $sc->set("is_active", 0)->save();
283
284 // Log data
285 $Log->set("data.error.msg", "Activity has been stopped")
286 ->set("data.error.details", "Re-login is required for the account.")
287 ->save();
288 continue;
289 }
290
291 // Check user account
292 if (!$User->isAvailable() || !$User->get("is_active") || $User->isExpired()) {
293 // User is not valid
294 // Deactivate schedule
295 $sc->set("is_active", 0)->save();
296
297 // Log data
298 $Log->set("data.error.msg", "Activity has been stopped")
299 ->set("data.error.details", "User account is either disabled or expred.")
300 ->save();
301 continue;
302 }
303
304 if ($User->get("id") != $Account->get("user_id")) {
305 // Unexpected, data modified by external factors
306 // Deactivate schedule
307 $sc->set("is_active", 0)->save();
308 continue;
309 }
310
311 // Check targets
312 $targets = @json_decode($sc->get("target"));
313 if (!$targets) {
314 // Unexpected, data modified by external factors
315 // Deactivate schedule
316 $sc->set("is_active", 0)->save();
317 continue;
318 }
319
320 // Select random target
321 $i = rand(0, count($targets) - 1);
322 $target = $targets[$i];
323
324 // Check selected target
325 if (empty($target->type) ||
326 empty($target->id) ||
327 !in_array($target->type, ["hashtag", "location", "people"]))
328 {
329 // Unexpected, data modified by external factors
330 continue;
331 }
332
333 try {
334 $Instagram = \InstagramController::login($Account);
335 } catch (\Exception $e) {
336 // Couldn't login into the account
337 $Account->refresh();
338
339 // Log data
340 if ($Account->get("login_required")) {
341
342 $error_count = $sc->get("data.error_count");
343
344 if($error_count == null){
345 $error_count = 0;
346 }
347
348 $error_count++;
349 $sc->set("data.error_count", $error_count);
350 if($error_count >= 3){
351 $sc->set("is_active", 0)->save();
352 $sc->set("data.error_count", 0);
353 }
354 $Log->set("data.error.msg", "Activity Relogin/Connection Problems " . $error_count ."/3");
355 } else {
356 $Log->set("data.error.msg", "Action re-scheduled");
357 }
358
359 $Log->set("data.error.details", $e->getMessage())
360 ->save();
361
362 continue;
363 }
364
365 // Logged in successfully
366 // Now script will try to get feed and follow new user
367 // And will log result
368 $Log->set("data.trigger", $target);
369
370
371 // Find username to follow
372 $follow_pk = null;
373 $follow_username = null;
374 $follow_full_name = null;
375 $follow_profile_pic_url = null;
376
377 $turns = 1;
378
379 $rank_token = \InstagramAPI\Signatures::generateUUID();
380
381 if ($target->type == "hashtag") {
382 try {
383 $feed = $Instagram->hashtag->getFeed(
384 str_replace("#", "", $target->id),
385 $rank_token);
386 } catch (\Exception $e) {
387 // Couldn't get instagram feed related to the hashtag
388
389 // Log data
390 $Log->set("data.error.msg", "Couldn't get the feed")
391 ->set("data.error.details", $e->getMessage())
392 ->save();
393 continue;
394 }
395
396 if (count($feed->getItems()) < 1) {
397 // Invalid
398 continue;
399 }
400
401 foreach ($feed->getItems() as $item) {
402 if (empty($item->getUser()->getFriendshipStatus()->getFollowing()) &&
403 empty($item->getUser()->getFriendshipStatus()->getOutgoingRequest()) &&
404 $item->getUser()->getPk()!= $Account->get("instagram_id"))
405 {
406
407 $_log = new LogModel([
408 "user_id" => $User->get("id"),
409 "account_id" => $Account->get("id"),
410 "followed_user_pk" => $item->getUser()->getPk(),
411 "status" => "success"
412 ]);
413
414 if (!$_log->isAvailable()) {
415
416 $filter1 = namespace\customFilterFast($item->getUser()->getPk(),$item->getUser()->getFullName(),$item->getUser()->getProfilePicUrl(),(bool)$item->getUser()->getIsPrivate(),$sc,$User,$Account);
417
418 if(!$filter1){
419 continue;
420 }
421 $filter = namespace\customFilter($Instagram, $item->getUser()->getPk(), $sc, $User,$Account);
422
423 if(!$filter && $turns <= 3){
424 $turns++;
425 continue;
426 }
427
428 // Found new user
429 $follow_pk = $item->getUser()->getPk();
430 $follow_username = $item->getUser()->getUsername();
431 $follow_full_name = $item->getUser()->getFullName();
432 $follow_profile_pic_url = $item->getUser()->getProfilePicUrl();
433 $follow_is_private = (bool)$item->getUser()->getIsPrivate();
434 break;
435 }
436 }
437 }
438 } else if ($target->type == "location") {
439 try {
440 $feed = $Instagram->location->getFeed($target->id, $rank_token);
441 } catch (\Exception $e) {
442 // Couldn't get instagram feed related to the location id
443
444 // Log data
445 $Log->set("data.error.msg", "Couldn't get the feed")
446 ->set("data.error.details", $e->getMessage())
447 ->save();
448 continue;
449 }
450
451 if (count($feed->getItems()) < 1) {
452 // Invalid
453 continue;
454 }
455
456 foreach ($feed->getItems() as $item) {
457 if (empty($item->getUser()->getFriendshipStatus()->getFollowing()) &&
458 empty($item->getUser()->getFriendshipStatus()->getOutgoingRequest()) &&
459 $item->getUser()->getPk() != $Account->get("instagram_id"))
460 {
461 $_log = new LogModel([
462 "user_id" => $User->get("id"),
463 "account_id" => $Account->get("id"),
464 "followed_user_pk" => $item->getUser()->getPk(),
465 "status" => "success"
466 ]);
467
468 if (!$_log->isAvailable()) {
469
470 // Codingmatter Modification
471 // Lets get all user related data for filtering.
472
473 $filter1 = namespace\customFilterFast($item->getUser()->getPk(),$item->getUser()->getFullName(),$item->getUser()->getProfilePicUrl(),(bool)$item->getUser()->getIsPrivate(),$sc,$User,$Account);
474
475 if(!$filter1){
476 continue;
477 }
478
479 //filter
480 $filter = namespace\customFilter($Instagram, $item->getUser()->getPk(), $sc, $User,$Account);
481
482 if(!$filter && $turns <= 3){
483 $turns++;
484 continue;
485 }
486
487 // Found new user
488 $follow_pk = $item->getUser()->getPk();
489 $follow_username = $item->getUser()->getUsername();
490 $follow_full_name = $item->getUser()->getFullName();
491 $follow_profile_pic_url = $item->getUser()->getProfilePicUrl();
492 $follow_is_private = (bool)$item->getUser()->getIsPrivate();
493 break;
494 }
495 }
496 }
497 } else if ($target->type == "people") {
498 $round = 1;
499 $loop = true;
500 $next_max_id = null;
501
502 while ($loop) {
503 try {
504 $feed = $Instagram->people->getFollowers($target->id, $rank_token, null, $next_max_id);
505 } catch (\Exception $e) {
506 // Couldn't get instagram feed related to the user id
507 $loop = false;
508
509 if ($round == 1) {
510 // Log data
511 $Log->set("data.error.msg", "Couldn't get the feed")
512 ->set("data.error.details", $e->getMessage())
513 ->save();
514 }
515
516 continue 2;
517 }
518
519 if (count($feed->getUsers()) < 1) {
520 // Invalid
521 $loop = false;
522 continue 2;
523 }
524
525 foreach ($feed->getUsers() as $user) {
526 if (empty($user->getFriendshipStatus()) &&
527 $user->getPk() != $Account->get("instagram_id"))
528 {
529 $_log = new LogModel([
530 "user_id" => $User->get("id"),
531 "account_id" => $Account->get("id"),
532 "followed_user_pk" => $user->getPk(),
533 "status" => "success"
534 ]);
535
536 if (!$_log->isAvailable()) {
537
538 $filter1 = namespace\customFilterFast($user->getPk(),$user->getFullName(),$user->getProfilePicUrl(),(bool)$user->getIsPrivate(),$sc,$User,$Account);
539
540 if(!$filter1){
541 continue;
542 }
543
544 $filter = namespace\customFilter($Instagram, $user->getPk(), $sc, $User,$Account);
545
546 if(!$filter && $turns <= 3){
547 $turns++;
548 continue;
549 }
550
551 // Found new user
552 $follow_pk = $user->getPk();
553 $follow_username = $user->getUsername();
554 $follow_full_name = $user->getFullName();
555 $follow_profile_pic_url = $user->getProfilePicUrl();
556 $follow_is_private = (bool)$user->getIsPrivate();
557 break 2;
558 }
559 }
560 }
561
562 $round++;
563 $next_max_id = empty($feed->getNextMaxId()) ? null : $feed->getNextMaxId();
564 if ($round >= 5 || !empty($follow_pk) || $next_max_id) {
565 $loop = false;
566 }
567 }
568 }
569
570 if (empty($follow_pk)) {
571 $Log->set("data.error.msg", "Couldn't find new user to follow")
572 ->save();
573 continue;
574 }
575
576
577 // New user found to follow
578 try {
579
580 // MODIFICATION by Codingmatters.
581 // https://www.facebook.com/CodingMatters-945340885622490/
582 // We want a Powerlike feature.
583 // pull the timeline of the getFollower
584 // and get last 3 posts to like.
585
586 $power_count = $sc->get("data.powerlike_count");
587 $power_like = $sc->get("data.powerlike");
588 $power_random = $sc->get("data.powerlike_random");
589 $likedmedia = [];
590
591 if($power_count > 3){
592 $power_count = 3; //max value
593 };
594
595 if($power_like && !$follow_is_private){
596 try {
597 $feed = $Instagram->timeline->getUserFeed($follow_pk);
598
599 $items = $feed->getItems();
600
601 if($power_random){
602 $power_count = mt_rand(1, intval($power_count));
603 }
604
605 $temp_count = $power_count;
606
607 foreach ($items as $item) {
608
609 $media = new \stdClass();
610
611 if (!empty($item->getId()) && !$item->getHasLiked()) {
612
613 if($temp_count== 0){
614 break;
615 }else{
616 $temp_count = $temp_count - 1;
617 }
618
619 $media->media_id = $item->getId();
620 $media->media_code = $item->getCode();
621 $media->media_type = $item->getMediaType();
622 $media->media_thumb = namespace\_get_media_thumb_igitem($item);
623 $media->user_pk = $item->getUser()->getPk();
624 $media->user_username = $item->getUser()->getUsername();
625 $media->user_full_name = $item->getUser()->getFullName();
626
627 try {
628 $resp = $Instagram->media->like($item->getId());
629 } catch (\Exception $e) {
630 continue;
631 }
632
633 if (!$resp->isOk()) {
634 continue;
635 }else{
636 array_push($likedmedia, $media);
637 }
638 }
639 }
640
641 } catch (\Exception $e) {
642 // Couldn't get instagram feed related to the hashtag
643 }
644
645 }else{
646 $power_count = 0;
647 }
648
649 $resp = $Instagram->people->follow($follow_pk);
650
651 } catch (\Exception $e) {
652 $Log->set("data.error.msg", "Couldn't follow the user")
653 ->set("data.error.details", $e->getMessage())
654 ->save();
655 continue;
656 }
657
658
659 if (!$resp->isOk()) {
660 $Log->set("data.error.msg", "Couldn't follow the user")
661 ->set("data.error.details", "Something went wrong")
662 ->save();
663 continue;
664 }
665
666
667 // Followed new user successfully
668 $Log->set("status", "success")
669 ->set("data.followed", [
670 "pk" => $follow_pk,
671 "username" => $follow_username,
672 "full_name" => $follow_full_name,
673 "profile_pic_url" => $follow_profile_pic_url
674 ])
675 ->set("data.powerlike", [
676 "count" => count($likedmedia),
677 "posts" => $likedmedia
678 ])
679 ->set("followed_user_pk", $follow_pk)
680 ->save();
681 }
682}
683\Event::bind("cron.add", __NAMESPACE__."\addCronTask");
684
685
686/**
687 * Get Plugin Settings
688 * @return \GeneralDataModel
689 */
690function settings()
691{
692 $settings = \Controller::model("GeneralData", "plugin-auto-follow-settings");
693 return $settings;
694}
695
696function _get_media_thumb_igitem($item)
697{
698 $media_thumb = null;
699
700 $media_type = empty($item->getMediaType()) ? null : $item->getMediaType();
701
702 if ($media_type == 1 || $media_type == 2) {
703 // Photo (1) OR Video (2)
704 $candidates = $item->getImageVersions2()->getCandidates();
705 if (!empty($candidates[0]->getUrl())) {
706 $media_thumb = $candidates[0]->getUrl();
707 }
708 } else if ($media_type == 8) {
709 // ALbum
710 $carousel = $item->getCarouselMedia();
711 $candidates = $carousel[0]->getImageVersions2()->getCandidates();
712 if (!empty($candidates[0]->getUrl())) {
713 $media_thumb = $candidates[0]->getUrl();
714 }
715 }
716
717
718
719 return $media_thumb;
720}
721
722function customFilterFast($user_pk,$fullname,$picture,$private,$sc,$User,$Account){
723
724
725 $filter_dont_follow_twice = (bool)$sc->get("data.filter_unfollowed");
726 $filter_gender = $sc->get("data.filter_gender");
727 $filter_profil_private = (bool)$sc->get("data.filter_privat");
728 $filter_profil_picture = (bool)$sc->get("data.filter_picture");
729
730 if($filter_dont_follow_twice){
731 $q4 = "SELECT * FROM ".TABLE_PREFIX."auto_unfollow_log WHERE user_id = " . intval($User->get("id")) . " AND account_id = " . intval($Account->get("id")) . " AND unfollowed_user_pk = " . intval($user_pk) . " AND status = 'success'";
732 $query = \DB::query($q4);
733 $logs = $query->get();
734
735 if (count($logs) > 0) {
736 //echo "<br> ## Filter - Follow twice Triggered <br>";
737 return false;
738 }
739 }
740
741 if($filter_gender == "male" || $filter_gender == "female"){
742 //$gender_check = namespace\Gender($userinfo->getUser()>getFullName(), $Account->get("proxy"));
743 $gender_check = namespace\Gender2($filter_gender, $fullname);
744 if(!$gender_check){
745 //echo "<br> ## Filter - Gender not match <br>";
746 return false;
747 }
748 //echo "<br> ++ Filter - Gender match <br>";
749 }
750
751 if($filter_profil_private){
752 if($private){
753 //echo "<br> ## Filter - Private Profil Triggered <br>";
754 return false;
755 }
756 }
757
758 if($filter_profil_picture){
759 if($picture == ""){
760 //echo "<br> ## Filter - Profil Picture Tiggered <br>";
761 return false;
762 }
763 }
764
765 return true;
766
767}
768
769
770function customFilter($Instagram,$user_pk,$sc,$User,$Account){
771
772 $validation = false;
773
774 $filter_profil_business = (bool)$sc->get("data.filter_business");
775
776 $filter_media_min = (int)$sc->get("data.filter_media_min");
777 $filter_follower_min = (int)$sc->get("data.filter_followed_min");
778 $filter_follower_max = (int)$sc->get("data.filter_followed_max");
779 $filter_following_min = (int)$sc->get("data.filter_following_min");
780 $filter_following_max = (int)$sc->get("data.filter_following_max");
781 $filter_blacklist = explode(",",$sc->get("data.filter_blacklist"));
782
783 $userinfo = $Instagram->people->getInfoById($user_pk);
784
785 if($userinfo->getUser()->getIsBusiness()){
786
787 if($userinfo->getUser()->getPublicEmail() != ""){
788 $info_mail = $userinfo->getUser()->getPublicEmail();
789 }else{$info_mail = "NO MAIL";}
790
791 if($userinfo->getUser()->getContactPhoneNumber()!= ""){
792 $info_phone = $userinfo->getUser()->getContactPhoneNumber();
793 }else{$info_phone = "NO NUMBER";}
794
795 if($userinfo->getUser()->getCityName() != ""){
796 $info_cname = $userinfo->getUser()->getCityName();
797 }else{$info_cname = "NO CITY";}
798
799 if($userinfo->getUser()->getAddressStreet() != ""){
800 $info_street = trim(preg_replace('/\s\s+/', ' ', $userinfo->getUser()->getAddressStreet()));
801 }else{$info_street = "NO STREET";}
802
803 if($userinfo->getUser()->getExternalUrl() != ""){
804 $info_eurl = $userinfo->getUser()->getExternalUrl();
805 }else{$info_eurl = "NO URL";}
806
807 if($userinfo->getUser()->getCategory() != ""){
808 $info_category = $userinfo->getUser()->getCategory();
809 }else{$info_category = "NO Category";}
810
811 if($userinfo->getUser()->getProfilePicUrl() != ""){
812 $info_ppic = $userinfo->getUser()->getProfilePicUrl();
813 }else{$info_ppic = "NO Picture";}
814
815 if($userinfo->getUser()->getBiography() != ""){
816 $info_bio = str_replace(";" , " ", $userinfo->getUser()->getBiography());
817 $info_bio = str_replace("\n", " ", $info_bio);
818 $info_bio = str_replace("\r", " ", $info_bio);
819 }else{$info_bio = "NO Biotext";}
820
821 }
822
823 if(count($filter_blacklist) > 0){
824 //echo "<br> ## Filter - Blacklist check <br>";
825 $tempString = $userinfo->getUser()->getUsername() . " ";
826 $tempString .= $userinfo->getUser()->getFullName() . " ";
827 $tempString .= $userinfo->getUser()->getBiography() . " ";
828
829 foreach ($filter_blacklist as $key => $value){
830 //echo "<br> ## Filter - Blacklist keyword : ".$value."<br>";
831 if (strpos($value, $tempString) !== false) {
832 //echo "<br> ## Filter - Blacklist keyword found : ".$value."<br>";
833 return $validation;
834 }
835
836 }
837
838 }
839
840 if($filter_profil_business){
841 if($userinfo->getUser()->getIsBusiness() == 1){
842 //echo "<br> ## Filter - Business Tiggered <br>";
843 return $validation;
844 }
845 }
846
847 // Media
848
849 if($filter_media_min > 0){
850 if($userinfo->getUser()->getMediaCount() <= $filter_media_min){
851 //echo "<br> ## Filter - Media count Tiggered <br>";
852 return $validation;
853 }
854 }
855
856 // Followers
857
858 if($filter_follower_max > 0){
859 if($userinfo->getUser()->getFollowerCount() >= $filter_follower_max){
860 //echo "<br> ## Filter - Followers Max <br>";
861 return $validation;
862 }
863 }
864
865 if($filter_follower_min > 0){
866 if($userinfo->getUser()->getFollowerCount() <= $filter_follower_min){
867 //echo "<br> ## Filter - Followers Min <br>";
868 return $validation;
869 }
870 }
871
872 //Followings
873
874 if($filter_following_max > 0){
875 if($userinfo->getUser()->getFollowingCount() >= $filter_following_max){
876 //echo "<br> ## Filter - Following Max <br>";
877 return $validation;
878 }
879 }
880
881 if($filter_following_min > 0){
882 if($userinfo->getUser()->getFollowingCount() <= $filter_following_min){
883 //echo "<br> ## Filter - Following Min <br>";
884 return $validation;
885 }
886 }
887
888 return true;
889}
890
891function Gender2($gender,$fullname){
892
893 if($fullname == ""){
894 return false;
895 }
896
897 $firstname = strtolower(explode(" ", $fullname)[0]);
898
899 $firstname = preg_replace('~[^a-zA-Z]+~', '', $firstname);
900
901 if(strlen($firstname) <= 2){
902 return false;
903 }
904
905
906 if($gender == "female"){
907 $names = file_get_contents(PLUGINS_PATH."/".IDNAME."/assets/female.json");
908
909 $array_names = json_decode($names, true);
910
911 if (in_array($firstname, array_map('strtolower', $array_names['female']))) {
912 return true;
913 }
914
915 }else{
916 $names = file_get_contents(PLUGINS_PATH."/".IDNAME."/assets/male.json");
917
918 $array_names = json_decode($names, true);
919
920 if (in_array($firstname, array_map('strtolower', $array_names['male']))) {
921 return true;
922 }
923
924 }
925
926 // lets save names we could not resolve and add them later
927 $file = PLUGINS_PATH."/".IDNAME."/assets/".$gender.'_fails.txt';
928 $myfile = file_put_contents($file, $firstname.PHP_EOL , FILE_APPEND | LOCK_EX);
929
930 return false;
931}
932
933function Gender($fullname,$proxy){
934 $app_url = "https://api.genderize.io/?name=";
935
936 //$loginpassw = 'username:password';
937 //$proxy_ip = '192.168.1.1';
938 //$proxy_port = '12345';
939 //$url = 'http://www.domain.com';
940 $proxy = "https://188.39.20.136:8080";
941
942 if($fullname != ""){
943 $loginpassw = false;
944
945 if($proxy != ""){
946 $foo = explode(":",$proxy);
947
948 if(count($foo) == 3){
949 //ohne password
950 $proxy_type = $foo[0];
951 $proxy_ip = $foo[0] .":". $foo[1];
952 $proxy_port = $foo[2];
953 $loginpassw = false;
954 //echo "<br>".$proxy_ip."<br>";
955 }
956
957 }
958 $url = $app_url . urldecode(explode(" ", $fullname)[0]);
959 //echo "<br>".$url."<br>";
960 try{
961 $curl = curl_init();
962 curl_setopt($curl, CURLOPT_URL, $url);
963 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
964 curl_setopt($curl, CURLOPT_HEADER, false);
965
966 if($proxy != ""){
967 //curl_setopt($curl, CURLOPT_PROXYPORT, $proxy_port);
968 //curl_setopt($curl, CURLOPT_PROXYTYPE, strtoupper($proxy_type));
969 curl_setopt($curl, CURLOPT_PROXY, $proxy);
970 if($loginpassw != false){
971 curl_setopt($curl, CURLOPT_PROXYUSERPWD, $loginpassw);
972 }
973 }
974 //curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
975 //curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
976 $data = curl_exec($curl);
977
978 if(curl_errno($curl))
979 //echo 'Curl error: '.curl_error($curl);
980
981 curl_close($curl);
982 //echo "<br> Gender Lookup Proxy Error <br>";
983
984 $data = json_decode($data);
985 if(!empty($data) && isset($data->gender)){
986 return $data->gender;
987 }else{
988 return false;
989 }
990 }catch(\Exception $e){
991 //echo "<br> Gender Lookup Proxy Error <br>";
992 return false;
993 }
994 }else{
995 return false;
996 }
997}