Advertisement
Guest User

Job

a guest
Dec 8th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 14.25 KB | None | 0 0
  1. <?php
  2.  
  3. class Job
  4. {
  5.     private $db;
  6.     public  $account;
  7.     private $proc_pid;
  8.     private $likes_count;
  9.     private $comments_count;
  10.     private $follows_count;
  11.     private $unfollows_count;
  12.     private $uploads_count;
  13.     private $follow_cycle;
  14.     private $unfollow_cycle;
  15.     private $start_time;
  16.     private $time_used;
  17.     private $purchased_time;
  18.     private $last_proc_time;
  19.     public $instagram;
  20.  
  21.     function __construct()
  22.     {
  23.         $this->db = MyDb::getInstance()->getConnection();
  24.     }
  25.  
  26.     public function setAccount($acc)
  27.     {
  28.         $this->account = $acc;
  29.     }
  30.  
  31.     private function setStatus($md5id)
  32.     {
  33.         $status_row = $this->db->queryFirstRow("select activity_status,likes,comments,follows,unfollows,uploads,time_used,last_proc_time,reg_days as purchased_time from accounts where md5id = %s", $md5id);
  34.         $this->activity_status = $status_row['activity_status'];
  35.         $this->likes_count = $status_row['likes'];
  36.         $this->comments_count = $status_row['comments'];
  37.         $this->follows_count = $status_row['follows'];
  38.         $this->unfollows_count = $status_row['unfollows'];
  39.         $this->uploads_count = $status_row['uploads'];
  40.         $this->start_time = time();
  41.         $this->time_used = $status_row['time_used'];
  42.         $this->purchased_time = $status_row['purchased_time'];
  43.         $this->last_proc_time = strtotime($status_row['last_proc_time']);
  44.  
  45.     }
  46.  
  47.     private function verifyJob() //-> check for AutoStop
  48.     {
  49.         //helper::manageInstagramResponse('checkpoint_required',$this);
  50.  
  51.         $verify['activityStatusNotRunning']['value'] = $this->account->getSettings()->getActivityStatus();
  52.         $verify['activityStatusNotRunning']['limit'] = '1';
  53.         $verify['activityStatusNotRunning']['condition'] = '!=';
  54.         $verify['activityStatusNotRunning']['message'] = '';
  55.         $verify['activityStatusNotRunning']['messageType'] = '';
  56.  
  57.         $verify['activityStatusPauseMode']['value'] = $this->account->getSettings()->getActivityStatus();
  58.         $verify['activityStatusPauseMode']['limit'] = '2';
  59.         $verify['activityStatusPauseMode']['condition'] = '==';
  60.         $verify['activityStatusPauseMode']['message'] = '';
  61.         $verify['activityStatusPauseMode']['messageType'] = '';
  62.  
  63.         $verify['noPurchasedTime']['value'] = $this->getPurchasedTime();
  64.         $verify['noPurchasedTime']['limit'] = $this->getTimeUsed();
  65.         $verify['noPurchasedTime']['condition'] = '<=';
  66.         $verify['noPurchasedTime']['message'] = 'Activity has been stopped : No more time avalable in your activity account';
  67.         $verify['noPurchasedTime']['messageType'] = 'purchasMoreTime';
  68.  
  69.         $verify['noActivity']['value'] = time();
  70.         $verify['noActivity']['limit'] = @strtotime("+" . $this->account->getSettings()->getAutostopNoActivity(), $this->getLastProcTime());
  71.         $verify['noActivity']['condition'] = '>=';
  72.         $verify['noActivity']['message'] = 'Activity has been stopped , No activity since :' . $this->account->getSettings()->getAutostopNoActivity();
  73.         $verify['noActivity']['messageType'] = 'autostop';
  74.  
  75.         $verify['activitySchedule']['value'] = helper::isScheduleOff($this->account);
  76.         $verify['activitySchedule']['limit'] = false;
  77.         $verify['activitySchedule']['condition'] = '==';
  78.         $verify['activitySchedule']['message'] = "Activity in (Pause Mode) due your schedule setting";
  79.         $verify['activitySchedule']['messageType'] = 'autostop';
  80.  
  81.         $verify['likesCount']['value'] = $this->getLikesCount();
  82.         $verify['likesCount']['limit'] = $this->account->getSettings()->getAutostopLikesCount();
  83.         $verify['likesCount']['condition'] = '>=';
  84.         $verify['likesCount']['message'] = 'Activity has been stopped , Likes limit reached :' . $this->account->getSettings()->getAutostopLikesCount() . ' likes';
  85.         $verify['likesCount']['messageType'] = 'autostop';
  86.  
  87.         $verify['commentsCount']['value'] = $this->getCommentsCount();
  88.         $verify['commentsCount']['limit'] = $this->account->getSettings()->getAutostopCommentsCount();
  89.         $verify['commentsCount']['condition'] = '>=';
  90.         $verify['commentsCount']['message'] = 'Activity has been stopped ,Comments limit reached :' . $this->account->getSettings()->getAutostopLikesCount() . ' comments';
  91.         $verify['commentsCount']['messageType'] = 'autostop';
  92.  
  93.         $verify['followsCount']['value'] = $this->getFollowersCount();
  94.         $verify['followsCount']['limit'] = $this->account->getSettings()->getAutostopFollowCount();
  95.         $verify['followsCount']['condition'] = '>=';
  96.         $verify['followsCount']['message'] = 'Activity has been stopped ,Follow limit reached :' . $this->account->getSettings()->getAutostopFollowCount() . ' follow';
  97.         $verify['followsCount']['messageType'] = 'autostop';
  98.  
  99.         $verify['unfollowsCount']['value'] = $this->getUnFollowersCount();
  100.         $verify['unfollowsCount']['limit'] = $this->account->getSettings()->getAutostopFollowCount();
  101.         $verify['unfollowsCount']['condition'] = '>=';
  102.         $verify['unfollowsCount']['message'] = 'Activity has been stopped , Unfollow limit reached :' . $this->account->getSettings()->getAutostopFollowCount() . ' unfollow';
  103.         $verify['unfollowsCount']['messageType'] = 'autostop';
  104.  
  105.         $verify['autoStopTimer']['value'] = time();
  106.         $verify['autoStopTimer']['limit'] = @strtotime("+" . @explode(":", $this->account->getSettings()->getAutostopTimer())[0] . " hours " . @explode(":", $this->account->getSettings()->getAutostopTimer())[1] .
  107.             " minutes", $this->getStartTime());
  108.         $verify['autoStopTimer']['condition'] = '>=';
  109.         $verify['autoStopTimer']['message'] = 'Activity has been stopped , Time limit reached :<b>' . @explode(":", $this->account->getSettings()->getAutostopTimer())[0] . " hours " . @explode(":", $this->account->getSettings
  110.             ()->getAutostopTimer())[1] . " minutes</b>";
  111.         $verify['autoStopTimer']['messageType'] = 'autostop';
  112.  
  113.  
  114.         foreach ($verify as $key => $val)
  115.         {
  116.             if ($verify[$key]['limit'] && helper::evaluate($verify[$key]['value'], $verify[$key]['condition'], $verify[$key]['limit']))
  117.             {
  118.                 if ($verify[$key]['message'])
  119.                 {
  120.                     print $message = helper::getMessageTxt($verify[$key]['messageType'], $verify[$key]['message'], $this->account->getUserName(), $this->account->getSettings()->getInstagramUsername());
  121.                     //helper::sendEmail($this->account()->getEmail(),$message);
  122.                     //helper::stopActivity($this->db, $verify[$key]['message'], $this->account->getSettings()->getmd5id(), $key);
  123.                 }
  124.                 return false;
  125.                 break;
  126.             }
  127.         }
  128.         return true;
  129.     }
  130.  
  131.     public function startJob()
  132.     {
  133.  
  134.         $this->setProcPid();
  135.         $this->setStatus($this->account->getSettings()->getmd5id());
  136.         $verifyJob = $this->verifyJob();
  137.        
  138.         if ($verifyJob == false) return true;
  139.         // Search for Syria Tag        
  140.         $this->instagramLogin();
  141.        
  142.         foreach($this->SearchByUser("1010315471") as $item)
  143.         {
  144.              $media = new media($item);
  145.              $media->setInstagram($this->instagram);
  146.              $media->setAccount($this->account);
  147.              $media->setSearchType('tag');
  148.              
  149.              foreach($media->getCommenters() as $user){
  150.                 var_dump($user->getPk());
  151.                 exit();
  152.              }
  153.              //$media->setDontVerifyMediaAge();
  154.              //$media->likeMedia();
  155.              exit();
  156.         }
  157.        
  158.     }
  159.  
  160.     private function setProcPid()
  161.     {
  162.         $this->proc_pid = getmypid();
  163.         $this->db->update('accounts', array('pid' => getmypid()), "md5id=%s", $this->account->getSettings()->getmd5id());
  164.  
  165.     }
  166.  
  167.     private function getProcPid()
  168.     {
  169.         return $this->proc_pid;
  170.     }
  171.  
  172.     public function SearchByTags($tag)
  173.     {
  174.         try
  175.         {
  176.             $helper = null;
  177.             do
  178.             {
  179.                 if (is_null($helper))
  180.                 {
  181.                     $helper = $this->instagram->getHashtagFeed($tag);
  182.                 }
  183.                 else
  184.                 {
  185.                     $helper = $this->instagram->getHashtagFeed($tag, $helper->getNextMaxId());
  186.                 }
  187.                 foreach ($helper->getItems() as $item)
  188.                 {
  189.                   yield $item;
  190.                 }
  191.             } while (!is_null($helper->getNextMaxId()));
  192.  
  193.         }
  194.         catch (exception $e)
  195.         {
  196.             helper::manageInstagramResponse($e->getMessage());
  197.         }
  198.     }
  199.  
  200.  
  201.    
  202.       public function SearchByUser($user_id)
  203.     {
  204.         try
  205.         {
  206.             $helper = null;
  207.             do
  208.             {
  209.                 if (is_null($helper))
  210.                 {
  211.                     $helper = $this->instagram->getUserFeed($user_id);
  212.                 }
  213.                 else
  214.                 {
  215.                     $helper = $this->instagram->getUserFeed($user_id, $helper->getNextMaxId());
  216.                 }
  217.                 foreach ($helper->getItems() as $item)
  218.                 {
  219.                   yield $item;
  220.                 }
  221.             } while (!is_null($helper->getNextMaxId()));
  222.  
  223.         }
  224.         catch (exception $e)
  225.         {
  226.             helper::manageInstagramResponse($e->getMessage());
  227.         }
  228.     }
  229.  
  230.  
  231.  
  232.  public function SearchByLocation($location_id)
  233.     {
  234.         try
  235.         {
  236.             $helper = null;
  237.             do
  238.             {
  239.                 if (is_null($helper))
  240.                 {
  241.                     $helper = $this->instagram->getLocationFeed($location_id);
  242.                 }
  243.                 else
  244.                 {
  245.                     $helper = $this->instagram->getLocationFeed($location_id, $helper->getNextMaxId());
  246.                 }
  247.                 foreach ($helper->getItems() as $item)
  248.                 {
  249.                   yield $item;
  250.                 }
  251.             } while (!is_null($helper->getNextMaxId()));
  252.  
  253.         }
  254.         catch (exception $e)
  255.         {
  256.             helper::manageInstagramResponse($e->getMessage());
  257.         }
  258.     }    
  259.    
  260.    
  261.  
  262.     private function getLikesCount()
  263.     {
  264.         return $this->likes_count;
  265.     }
  266.  
  267.     private function setLikesCount()
  268.     {
  269.         $this->db->query('update accounts set likes=likes+1,tlikes=tlikes+1,last_proc_time=%s where md5id=%s', hleper::getDate(), $this->account->getSettings()->getmd5id());
  270.         $this->likes_count += 1;
  271.     }
  272.  
  273.     private function getCommentsCount()
  274.     {
  275.         return $this->comments_count;
  276.     }
  277.  
  278.     private function setCommentsCount()
  279.     {
  280.         $this->db->query('update accounts set comments=comments+1,tcomments=tcomments+1,last_proc_time=%s where md5id=%s', helper::getDate(), $this->account->getSettings()->getmd5id());
  281.         $this->comments_count += 1;
  282.     }
  283.  
  284.  
  285.     private function getUploadsCount()
  286.     {
  287.         return $this->uploads_count;
  288.     }
  289.  
  290.     private function setUploadsCount()
  291.     {
  292.         $this->db->query('update accounts set uploads=uploads+1,tuploads=tuploads+1,last_proc_time=%s where md5id=%s', helper::getDate(), $this->account->getSettings()->getmd5id());
  293.         $this->uploads_count += 1;
  294.     }
  295.  
  296.     private function getFollowersCount()
  297.     {
  298.         return $this->follows_count;
  299.     }
  300.  
  301.  
  302.     private function setFollowersCount()
  303.     {
  304.         $this->db->query('update accounts set tfollows=tfollows+1,follows=follows+1,last_proc_time=%s where md5id=%s', helper::getDate(), $this->account->getSettings()->getmd5id());
  305.         $this->follows_count += 1;
  306.     }
  307.  
  308.  
  309.     private function getUnFollowersCount()
  310.     {
  311.         return $this->unfollows_count;
  312.  
  313.     }
  314.  
  315.     private function setUnFollowersCount()
  316.     {
  317.         $this->db->query('update accounts set tunfollows=tunfollows+1,unfollows=unfollows+1,last_proc_time=%s where md5id=%s', helper::getDate(), $this->account->getSettings()->getmd5id());
  318.         $this->unfollows_count += 1;
  319.     }
  320.  
  321.     private function getStartTime()
  322.     {
  323.         return $this->start_time;
  324.     }
  325.  
  326.     private function getTimeUsed()
  327.     {
  328.         return $this->time_used;
  329.     }
  330.  
  331.     private function setTimeUsed($time)
  332.     {
  333.         $this->db->query('update accounts set time_used = time_used + %s ,a_time_used = a_time_used + %s where md5id=%s', $time, $time, $this->account->getSettings()->getmd5id());
  334.     }
  335.  
  336.     private function getPurchasedTime()
  337.     {
  338.         return $this->purchased_time;
  339.     }
  340.  
  341.     private function getLastProcTime()
  342.     {
  343.         return $this->last_proc_time;
  344.     }
  345.  
  346.  
  347.     private function instagramLogin($force = false)
  348.     {
  349.         $debug = false;
  350.         $max_attempts = 4;
  351.         $attempts = 0;
  352.         $this->instagram = new \InstagramAPI\Instagram($debug);
  353.         $this->instagram->setUser($this->account->getSettings()->getInstagramUsername(), $this->account->getSettings()->getInstagramPassword());
  354.         $user_cookies_dir = str_replace('\\', '/', dirname(__file__)) . "/../vendor/mgp25/instagram-php/src/data/" . $this->account->getSettings()->getInstagramUsername();
  355.         if (!file_exists($user_cookies_dir)) $force = true;
  356.         if ($force)
  357.         {
  358.             do
  359.             {
  360.                 try
  361.                 {
  362.  
  363.                     $this->instagram->login($force);
  364.                     if ($this->instagram->settings->isLogged())
  365.                     {
  366.                         break;
  367.                     }
  368.                 }
  369.                 catch (exception $e)
  370.                 {
  371.                     $attempts++;
  372.                     $message = $e->getMessage();
  373.                     helper::manageInstagramResponse($message, $this);
  374.                     print "\n" . 'Login #' . $attempts . "\n" . $message;
  375.                     if ($attempts >= $max_attempts)
  376.                     {
  377.                         print $alert_tip = "Login 4 times with no luck , please contact support\n";
  378.                         helper::stopActivity($this->db, $alert_tip, $this->account->getSettings()->getmd5id(), 'login_4times');
  379.                         exit(0);
  380.                     }
  381.                 }
  382.  
  383.             } while ($attempts < $max_attempts);
  384.         }
  385.     }
  386.  
  387. }
  388.  
  389. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement