Beispiel #1
0
 protected function _import($org, $advertisers, &$view)
 {
     if (!isset($org->meta['model']) || !isset($org->meta['rate'])) {
         return $view->set('message', 'Please update <a href="/admin/settings">Commission Settings</a>');
     }
     $a = array_values($advertisers)[0];
     $advert_id = RM::post('advert_id', $a->getMongoID());
     $advert = \User::first(['_id = ?' => $advert_id, 'type = ?' => 'advertiser']);
     if (!$advert) {
         return $view->set('message', 'Invalid Request!!');
     }
     if (!isset($advert->meta['campaign'])) {
         return $view->set('message', 'Please Update Advertiser campaign settings!!');
     }
     $csv = $_FILES['csv'];
     $tmp = $csv['tmp_name'];
     if ($csv['type'] !== 'text/csv') {
         return $view->set('message', 'Invalid CSV file!!');
     }
     $file = APP_PATH . '/uploads/' . uniqid() . '.csv';
     if ($csv['error'] > 0 || !move_uploaded_file($tmp, $file)) {
         return $view->set('message', 'Error uploading csv file!!');
     }
     $fp = fopen($file, 'r');
     $urls = [];
     while (($line = fgetcsv($fp)) !== false) {
         $link = $line[0];
         if (!$link) {
             continue;
         }
         $urls[] = $link;
     }
     fclose($fp);
     unlink($file);
     \Meta::campImport($this->user->_id, $advert_id, $urls);
     $view->set('message', 'Campaigns Imported we will process them within an hour!!');
 }
Beispiel #2
0
 /**
  * Process the RSS Feed Urls from Platforms Table and queue the AD
  * urls in the Meta Table for campaign importing
  */
 protected function _rssFeed()
 {
     // find all the platforms for the advertisers
     $orgs = \Organization::all([], ['_id']);
     foreach ($orgs as $o) {
         $platforms = \Platform::rssFeeds($o);
         // get feed for each platform
         foreach ($platforms as $p) {
             $meta = $p->meta;
             $rss = $meta['rss'];
             // parsing is stopped
             if (!$rss['parsing']) {
                 continue;
             }
             $lastCrawled = null;
             if (isset($rss['lastCrawled'])) {
                 $lastCrawled = $rss['lastCrawled'];
             }
             $result = \Shared\Rss::getFeed($rss['url'], $lastCrawled);
             $urls = $result['urls'];
             $rss['lastCrawled'] = $result['lastCrawled'];
             $meta['rss'] = $rss;
             $p->meta = $meta;
             $p->save();
             // save the lastCrawled time
             $user = \User::first(['org_id' => $o->_id, 'type' => 'admin'], ['_id']);
             \Meta::campImport($user->_id, $p->user_id, $result['urls'], $rss['campaign']);
         }
     }
 }