public function returnImagesByTag($tag = "berrics", $limit = 100)
 {
     $token = "instagram-images-by-tag-" . md5($tag);
     if (($data = Cache::read($token, "1min")) === false) {
         $i = InstagramApi::berricsInstance();
         $images = $i->instagram->getRecentTags($tag);
         $images = json_decode($images, true);
         foreach ($images['data'] as $k => $v) {
             //check to see if there is an instagra object
             $check = $this->find("first", array("conditions" => array("InstagramImageItem.instagram_object_id" => $v['id']), "contain" => array()));
             if (!isset($check['InstagramImageItem']['id'])) {
                 $this->create();
                 $this->save(array("instagram_object_id" => $v['id'], "active" => 1));
                 $obj_id = $this->id;
             } else {
                 $obj_id = $check['InstagramImageItem']['id'];
             }
             $this->create();
             $this->id = $obj_id;
             $d = array("InstagramImageItem" => array("created_time" => date('Y-m-d H:i:s', $v['created_time']), "link" => $v['link'], "likes" => $v['likes']['count'], "instagram_object_id" => $v['id'], "caption" => $v['caption']['text'], "filter" => $v['filter'], "images" => serialize($v['images']), "instagram_account_num" => $v['user']['id']));
             $tags = implode(",", $v['tags']);
             $d['Tag'] = $this->Tag->parseTags($tags);
             $this->saveAll($d);
         }
         SysMsg::add(array("category" => "Instragram", "title" => "Retrieve Images By Tag: " . $tag, "from" => "InstagramImageItem"));
         $data = $this->Tag->find("all", array("conditions" => array(), "contain" => array("InstagramImageItem"), "limit" => $limit));
         Cache::write($token, $data, "1min");
     }
     return $data;
 }
 public function export()
 {
     SysMsg::add(array("title" => "Start La Jolla Order Send", "category" => "LjgOrderFile", "from" => "LjgShell", "crontab" => 1));
     $file_id = $this->CanteenShippingRecord->ljg_process_pending();
     $this->CanteenShippingRecord->ljg_create_orders_file($file_id);
     $this->CanteenShippingRecord->ljg_ftp_file($file_id);
     SysMsg::add(array("title" => "End La Jolla Order Send", "category" => "LjgOrderFile", "from" => "LjgShell", "crontab" => 1));
 }
Beispiel #3
0
 public function process_queue()
 {
     //grab 50 emails
     $emails = $this->EmailMessage->find("all", array("conditions" => array("EmailMessage.processed" => 0), "contain" => array()));
     SysMsg::add(array("category" => "Emailer", "from" => "MailerShell", "crontab" => 1, "title" => "Emails to processes: " . count($emails)));
     $success = 0;
     foreach ($emails as $msg) {
         $this->controller->set(compact("msg"));
     }
     SysMsg::add(array("category" => "Emailer", "from" => "MailerShell", "crontab" => 1, "title" => "Email Send Results: Success ({$success}) Total (" . count($emails) . ")"));
 }
Beispiel #4
0
 public function save_xe_currency_file()
 {
     $url = 'http://www.xe.com/dfs/datafeed2.cgi?theberricsllc';
     $ch = curl_init($url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     $file_str = curl_exec($ch);
     curl_close($ch);
     $handle = fopen("/tmp/currency.xml", "w");
     fwrite($handle, $file_str);
     fclose($handle);
     SysMsg::add(array("title" => "Downloaded XE currency XML file", "category" => "CurrencyUpdate", "from" => "Currency", "message" => $file_str));
 }
Beispiel #5
0
 public function build_facts($date = false, $hour = false)
 {
     ini_set('memory_limit', '512M');
     set_time_limit(0);
     if (isset($this->params['date'])) {
         $date = $this->params['date'];
     } else {
         $date = date("Y-m-d");
     }
     if (isset($this->params['hour'])) {
         $hour = $this->params['hour'];
     } else {
         $hour = date('H', time());
     }
     $hour = $hour . ":00:00";
     $this->out("Media View ETL: " . $date . " " . $hour);
     SysMsg::add(array("category" => "TrafficReports", "from" => "MediaEtlShell", "title" => "Processing Media View ETL: " . $date . " " . $hour, "crontab" => 1));
     //die("-stopped");
     $this->populateDimDates($date);
     $this->populateDimLocations($date, $hour);
     $loop = true;
     while ($loop) {
         $views = $this->MediaFileView->find('all', array("conditions" => array("MediaFileView.created < '{$date} {$hour}'"), "limit" => 5000, "order" => array("MediaFileView.created" => "DESC")));
         if (count($views) > 0) {
             foreach ($views as $v) {
                 $row = array();
                 $row['dim_location_id'] = $this->DimLocation->returnLocationId($v['MediaFileView']['geo_country'], $v['MediaFileView']['geo_region']);
                 $row['dim_date_id'] = $this->DimDate->returnDateId($v['MediaFileView']['created']);
                 $row['mobile'] = $v['MediaFileView']['mobile'];
                 $row['media_file_id'] = $v['MediaFileView']['media_file_id'];
                 $this->FactMediaView->create();
                 $this->FactMediaView->save($row);
                 $this->out(print_r($row));
             }
             $this->MediaFileView->query("DELETE FROM media_file_views WHERE created < '{$date} {$hour}' ORDER BY created DESC LIMIT 5000");
             unset($pageViews);
         } else {
             $loop = false;
             continue;
         }
     }
     SysMsg::add(array("category" => "TrafficReports", "from" => "MediaEtlShell", "title" => "Completed Media View ETL: " . $date . " " . $hour, "crontab" => 1));
 }
Beispiel #6
0
 public function build_facts($date = false, $hour = false)
 {
     if (isset($this->params['date'])) {
         $date = $this->params['date'];
     } else {
         $date = date("Y-m-d");
     }
     if (isset($this->params['hour'])) {
         $hour = $this->params['hour'];
     } else {
         $hour = date('H', time());
     }
     $hour = $hour . ":00:00";
     $this->hr();
     SysMsg::add(array("category" => "TrafficReports", "from" => "TrafficEtlShell", "title" => "Processing ETL for: " . $date . " " . $hour, "crontab" => 1));
     $this->out("Processing ETL for: " . $date . " " . $hour);
     $this->hr();
     $this->build_dimensions($date, $hour);
     $this->out("Fact Page Views");
     $this->populateFactPageViews($date, $hour);
     $this->out("Completed ETL for: " . $date . " " . $hour);
     SysMsg::add(array("category" => "TrafficReports", "from" => "TrafficEtlShell", "title" => "Completed ETL for: " . $date . " " . $hour, "crontab" => 1));
 }
Beispiel #7
0
 public function hit_linter()
 {
     //grab the last 20 published posts
     $msg = "";
     $posts = $this->Dailyop->find("all", array("conditions" => array("Dailyop.publish_date<NOW()", "Dailyop.active" => 1), "contain" => array("DailyopSection"), "limit" => 20, "order" => array("Dailyop.publish_date" => "DESC")));
     foreach ($posts as $post) {
         //let's make the URL
         $url = "http://theberrics.com/" . $post['DailyopSection']['uri'] . "/" . $post['Dailyop']['uri'];
         $this->out("++++++++++++++++++++++++++++++++++");
         $this->out("Linting Url: " . $url);
         $url_enc = urlencode($url);
         $c = curl_init();
         curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
         curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($c, CURLOPT_URL, "https://developers.facebook.com/tools/lint/?url={$url_enc}&format=json");
         $res = curl_exec($c);
         $this->out("Response: " . $res);
         SysMsg::add(array("category" => "Facebook", "crontab" => 1, "from" => "FacebookShell", "title" => "Linting URL: " . $url, "message" => $res));
         $this->out("++++++++++++++++++++++++++++++++++");
         $this->out("Sleeping.....zzz.z.z.z.z");
         sleep(3);
     }
 }
Beispiel #8
0
 public function mp4_to_ogv($VideoTask)
 {
     $this->create();
     $this->id = $VideoTask['VideoTask']['id'];
     $this->save(array("task_status" => "working"));
     //import objects
     $MediaFile = ClassRegistry::init("MediaFile");
     App::import("Vendor", "LLFTP", array("LLFTP.php"));
     $video = $MediaFile->find("first", array("conditions" => array("MediaFile.id" => $VideoTask['VideoTask']['foreign_key']), "contain" => array()));
     $llftp = new LLFTP();
     //let's download the video to tmp
     $tmp_file = $MediaFile->downloadVideoToTmp($VideoTask['VideoTask']['foreign_key']);
     $this->query("SET SESSION wait_timeout = 28800");
     $newFileName = str_replace(".mp4", ".ogv", $video['MediaFile']['limelight_file']);
     $newFilePath = "/home/sites/tmpfiles/" . $newFileName;
     $cmd = "/usr/bin/ffmpeg2theora {$tmp_file} -o {$newFilePath} --audioquality 5";
     SysMsg::add(array("category" => "Mp4ToOgv", "from" => "VideoTask", "crontab" => 1, "title" => $cmd));
     $this->getDatasource()->disconnect();
     $MediaFile->getDatasource()->disconnect();
     $output = `{$cmd}`;
     $this->getDatasource()->connect();
     $MediaFile->getDatasource()->connect();
     //ftp the file
     $llftp->ftpFile($newFileName, $newFilePath);
     //update the video file
     $MediaFile->create();
     $MediaFile->id = $video['MediaFile']['id'];
     $MediaFile->save(array("limelight_file_ogv" => $newFileName));
     $this->create();
     $this->id = $VideoTask['VideoTask']['id'];
     $this->save(array("task_status" => "completed"));
 }
 public function process_queue()
 {
     $this->loadModel("EmailMessage");
     //grab 50 emails
     $emails = $this->EmailMessage->find("all", array("conditions" => array("EmailMessage.processed" => 0), "contain" => array()));
     SysMsg::add(array("category" => "Emailer", "from" => "MailerShell", "crontab" => 1, "title" => "Emails to processes: " . count($emails)));
     $success = 0;
     foreach ($emails as $msg) {
         $e = $msg['EmailMessage'];
         //die(print_r($e));
         $this->Email->reset();
         $this->Email->to = "*****@*****.**";
         $this->Email->from = $e['from'];
         $this->Email->subject = $e['subject'];
         //$this->Email->cc = explode(",",$e['cc']);
         $this->Email->bcc = $e['bcc'];
         $this->Email->sendAs = $e['send_as'];
         $this->Email->template = $e['template'];
         $this->Email->smtpOptions = array('port' => '25', 'timeout' => '30', 'host' => 'smtp.com', 'username' => '*****@*****.**', 'password' => 'artosari');
         $this->Email->delivery = 'smtp';
         $this->set(compact("msg"));
         if ($this->Email->send()) {
             $this->EmailMessage->create();
             $this->EmailMessage->id = $e['id'];
             $this->EmailMessage->save(array("processed" => 1, "sent_date" => "NOW()"));
             $success++;
         } else {
             //print_r($this->Email);
             die($this->Email->smtpError);
             SysMsg::add(array("category" => "Emailer", "from" => "MailerShell", "crontab" => 1, "title" => "Email Failure - Message ID: {$e['id']}"));
         }
     }
     SysMsg::add(array("category" => "Emailer", "from" => "MailerShell", "crontab" => 1, "title" => "Email Send Results: Success ({$success}) Total (" . count($emails) . ")"));
 }
Beispiel #10
0
 public function updateInstagramDetails($User = array(), $crontab = false)
 {
     if (!isset($User['id']) || !isset($User['instagram_handle']) || (empty($User['id']) || empty($User['instagram_handle']))) {
         return false;
     }
     App::import("Vendor", "InstagramApi", array("file" => "instagram/instagram_api.php"));
     $i = InstagramApi::berricsInstance();
     $search = $i->instagram->searchUser($User['instagram_handle']);
     $insta = json_decode($search, true);
     $udata = array();
     $udata['instagram_account_num'] = $insta['data'][0]['id'];
     $udata['instagram_profile_image'] = $insta['data'][0]['profile_picture'];
     //update the users profile with the instagram info
     $this->create();
     $this->id = $User['id'];
     $this->save($udata);
     $instaData = $i->instagram->getUser($udata['instagram_account_num']);
     $instaData = json_decode($instaData, true);
     $profile = $this->ensure_user_profile($User['id']);
     $this->UserProfile->create();
     $this->UserProfile->id = $profile['UserProfile']['id'];
     $this->UserProfile->save(array("instagram_followers" => $instaData['data']['counts']['followed_by'], "instagra_last_updated" => 'NOW()'));
     SysMsg::add(array("category" => "Instagram", "from" => "UserModel", "title" => "Update Instagram: " . $User['instagram_handle'], "crontab" => $crontab));
 }
 public function ljg_ftp_file($id)
 {
     $ljg_file = ClassRegistry::init("LjgFile");
     $record = $ljg_file->findById($id);
     $conn = ftp_connect($this->ljg_ftp['ip']);
     if (ftp_login($conn, $this->ljg_ftp['login'], $this->ljg_ftp['pass'])) {
         ftp_chdir($conn, "r");
         ftp_pasv($conn, true);
         ftp_put($conn, $record['LjgFile']['file_name'], "/tmp/" . $record['LjgFile']['file_name'], FTP_BINARY);
         ftp_close($conn);
         SysMsg::add(array("category" => "LjgOrderFile", "from" => "CanteenShippingRecord", "message" => "Uploaded: " . $record['LjgFile']['file_name'], "title" => "Uploaded: " . $record['LjgFile']['file_name']));
     } else {
         SysMsg::add(array("category" => "LjgOrderFile", "from" => "CanteenShippingRecord", "message" => "Error Connecting to FTP", "title" => "Error Connecting to FTP"));
     }
 }