Example #1
0
 /**
  * check client province in ad's geo target
  * input array province number
  * return boolean
  */
 public function checkGeo($listCountries, $listProvinces)
 {
     if (empty($listCountries)) {
         return true;
     }
     $retval = false;
     $ip = getClientIp();
     //live
     //test tren local
     if (isLocal()) {
         $ip = '115.78.162.134';
         // test
     }
     $geoip = GeoBaseModel::getGeoByIp($ip);
     if ($geoip) {
         if (empty($listProvinces)) {
             $retval = in_array($geoip->country_code, $listCountries);
         } else {
             $province = "{$geoip->country_code}:{$geoip->region}";
             $retval = in_array($province, $listProvinces);
         }
     }
     // pr($geoip);
     // pr($retval);
     return $retval;
 }
Example #2
0
/**
 * Determines if the video is a valid YouTube link.
 * @param string $string The path to check.
 * @return boolean
 */
function isValidYouTube($string)
{
    if (isLocal($string)) {
        return false;
    }
    if (false !== stripos($string, 'youtube')) {
        return true;
    }
    if (false !== stripos($string, 'youtu.be')) {
        return true;
    }
    return false;
}
Example #3
0
 public function checkPreProcess($requestType, $hostReferer, $zoneID)
 {
     $retval = '';
     if (empty($zoneID)) {
         $retval = Delivery::RESPONSE_TYPE_INVALID;
     } elseif (empty($hostReferer) && Input::has('ec') && Input::get('ec') && !isLocal()) {
         $retval = Delivery::RESPONSE_TYPE_EMPTY_REFERRER;
     } elseif (!isLocal()) {
         $isBlocked = $this->isBlockedIp($zoneID);
         if ($isBlocked || ($this->countLatestRequest($zoneID, 1) > Delivery::ANTI_CHEAT_MAX_REQUEST_PER_1MIN || $this->countLatestRequest($zoneID, 5) > Delivery::ANTI_CHEAT_MAX_REQUEST_PER_5MIN)) {
             $retval = Delivery::RESPONSE_TYPE_ANTI_MANY_REQUEST;
             if (!$isBlocked) {
                 $this->setBlockIp($zoneID);
             }
         }
     }
     return $retval;
 }
function config_getConnection($tp = 'main')
{
    $sitehost = '127.0.0.1';
    if (isLocal()) {
        $sitehost = LOCAL_SITEHOST;
        $database = LOCAL_DATABASE;
        $username = LOCAL_USERNAME;
        $password = LOCAL_PASSWORD;
    } else {
        $sitehost = MAIN_SITEHOST;
        $database = MAIN_DATABASE;
        $username = MAIN_USERNAME;
        $password = MAIN_PASSWORD;
    }
    if ($tp == 'info') {
        $database = 'information_schema';
    }
    return new PDO("mysql:host={$sitehost};dbname={$database}", $username, $password, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
}
Example #5
0
 function connect()
 {
     if (isLocal()) {
         $config = (require "../data/oshjf_config.php");
     } else {
         $config = (require "../data/oshjf_config.php");
     }
     if (in_array(substr($_SERVER['HTTP_HOST'], 0, 5), array('local', '127.0', '192.1'))) {
         $sql = $config['local'];
     } else {
         $sql = $config['server'];
     }
     $dbc = mysql_connect($sql['host'], $sql['name'], $sql['pass']);
     mysql_select_db($sql['db']);
     return $dbc;
 }
Example #6
0
 public function getApiAd()
 {
     $this->layout = null;
     $response = null;
     $responseType = '';
     $deliveryStatus = '';
     $requestType = Input::get('rt', Delivery::REQUEST_TYPE_AD);
     $flightWebsiteID = Input::get('fpid', '');
     $zoneID = Input::get('zid', 0);
     $data = Input::all();
     $trackingModel = new Tracking();
     $deliveryModel = new Delivery();
     $isOverReport = $data['ovr'] = false;
     $showBanner = showBanner();
     if ($showBanner !== FALSE) {
         $flightWebsiteID = $showBanner;
     }
     $responseData = [];
     $hostReferer = $trackingModel->getRequestReferer();
     $responseType = $trackingModel->checkPreProcess($requestType, $hostReferer, $zoneID);
     //read redis 1
     $data['ref'] = $hostReferer;
     $adZone = $deliveryModel->getAdzone($zoneID);
     if ($adZone) {
         $platform = '';
         $flightWebsites = $deliveryModel->getAvailableAds($adZone->publisher_site_id, $adZone->ad_format_id, $flightWebsiteID, $platform);
         if ($flightWebsites) {
             //sort available flights base on priority and retargeting
             //TO DO retargeting
             $flightWebsites = $deliveryModel->sortAvailableFlightWebsites($flightWebsites);
             //lấy ad từ list thỏa điều kiện để trả về
             $deliveryInfo = $deliveryModel->getFullFlightInfo($flightWebsites, $adZone->publisher_site_id, $adZone->ad_format_id);
             $redis = new RedisBaseModel(env('REDIS_HOST', '127.0.0.1'), env('REDIS_PORT_6', '6379'), false);
             foreach ($flightWebsites as $k => $flightWebsite) {
                 if (!empty($flightWebsite) && !empty($deliveryInfo['flightDates'][$flightWebsite->flight_id]) && !empty($deliveryInfo['flights'][$flightWebsite->flight_id])) {
                     $flightDates = $deliveryInfo['flightDates'][$flightWebsite->flight_id];
                     $flight = $deliveryInfo['flights'][$flightWebsite->flight_id];
                     $ad = $deliveryInfo['ads'][$flight->ad_id];
                     $arrPlatform = json_decode($ad->platform);
                     if (!empty($arrPlatform) && in_array('mobile_app', $arrPlatform) || isLocal()) {
                         $checkFlightDate = $deliveryModel->checkFlightDate($flightDates, $flight);
                         //flight date ok
                         if ($checkFlightDate) {
                             $deliveryStatus = $deliveryModel->deliveryAd($ad, $flightWebsite, $flight, $flightDates);
                             if ($deliveryStatus == Delivery::DELIVERY_STATUS_OK || $deliveryStatus == Delivery::DELIVERY_STATUS_OVER_REPORT) {
                                 //Check retargeting
                                 if (!empty($flight->audience)) {
                                     $check = false;
                                     $audience = json_decode($flight->audience, true);
                                     if (!empty($audience['audience_id'])) {
                                         if (isset($_COOKIE["yoAu_{$audience['audience_id']}"]) && !empty($_COOKIE["uuid"])) {
                                             if ($_COOKIE["yoAu_{$audience['audience_id']}"] === '1' || substr($_COOKIE["yoAu_{$audience['audience_id']}"], 0, 2) === '1.') {
                                                 $check = true;
                                             }
                                         }
                                         if ($audience['operator'] === 'not in') {
                                             $check = !$check;
                                         }
                                     }
                                     if ($check === false) {
                                         $deliveryStatus == Delivery::RESPONSE_TYPE_AUDIENCE_LIMIT;
                                         continue;
                                     }
                                 }
                                 //trả về ad này
                                 $serveAd = $ad;
                                 $data['aid'] = $ad->id;
                                 $data['fpid'] = $flightWebsite->id;
                                 //over report
                                 if ($deliveryStatus == Delivery::DELIVERY_STATUS_OVER_REPORT) {
                                     $data['ovr'] = $isOverReport = true;
                                 }
                                 $responseType = Delivery::RESPONSE_TYPE_ADS_SUCCESS;
                                 break;
                             }
                         } else {
                             $deliveryStatus = Delivery::RESPONSE_TYPE_FLIGHTDATE_NOT_AVAILABLE;
                         }
                     } else {
                         $deliveryStatus = Delivery::PLATFORM_TYPE_INVALID;
                     }
                 }
             }
         }
         if ($responseType != Delivery::RESPONSE_TYPE_ADS_SUCCESS) {
             $responseType = Delivery::RESPONSE_TYPE_NOT_AVAILABLE;
         }
     }
     if (empty($responseType)) {
         $responseType = Delivery::RESPONSE_TYPE_INVALID;
     } elseif ($responseType == Delivery::RESPONSE_TYPE_ADS_SUCCESS) {
         (new RawTrackingSummary())->addSummary('ads_request', $data['fpid'], $adZone->id, $adZone->ad_format_id, $flightWebsite->flight_id, $flightWebsite->id, $flight->ad_id, $flight->campaign_id, $flightWebsite->publisher_base_cost, $isOverReport);
         if (!empty($serveAd)) {
             pr($serveAd);
             $responseData['w'] = intval($serveAd->width);
             $responseData['h'] = intval($serveAd->height);
             $responseData['mime'] = !empty($serveAd->mime) ? $serveAd->mime : '';
             if ($serveAd->ad_type === 'html') {
                 $responseData['adm'] = urlencode($serveAd->html_source);
             } else {
                 $responseData['adm'] = urlencode($serveAd->source_url);
             }
             $responseData['pos'] = !empty($serveAd->position) ? $serveAd->position : '';
             $arrTrackingImpression = [];
             $arrTrackingImpression[] = urlencode(urlTracking('impression', $data['aid'], $data['fpid'], $zoneID, '', '', $data['ovr'], '') . '&plf=mobile_app');
             if (!empty($serveAd->third_impression_track)) {
                 $thirdImpressionTrackArr = explode("\n", $serveAd->third_impression_track);
                 if (!empty($thirdImpressionTrackArr)) {
                     foreach ($thirdImpressionTrackArr as $item) {
                         $arrTrackingImpression[] = urlencode($this->replaceParam($item));
                     }
                 }
             }
             $responseData['nimp'] = $arrTrackingImpression;
             $arrTrackingClick = [];
             $arrTrackingClick[] = urlencode(urlTracking('click', $data['aid'], $data['fpid'], $zoneID, '', '', $data['ovr'], '') . '&plf=mobile_app');
             if (!empty($serveAd->third_click_track)) {
                 $thirdClickTrackArr = explode("\n", $serveAd->third_click_track);
                 if (!empty($thirdClickTrackArr)) {
                     foreach ($thirdClickTrackArr as $item) {
                         $arrTrackingClick[] = urlencode($this->replaceParam($item));
                     }
                 }
             }
             $responseData['nclk'] = $arrTrackingClick;
             $responseData['lpage'] = urlencode($this->replaceParam($serveAd->destination_url));
             $responseData['xml'] = null;
         }
     }
     pr($responseData);
     pr($deliveryStatus);
     pr($responseType, 1);
     return response()->json($responseData);
 }
Example #7
0
if (empty($config['api_root'])) {
    displaySetup();
}
$message = '';
$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
$accessToken = !empty($_REQUEST['access_token']) ? $_REQUEST['access_token'] : '';
switch ($action) {
    case 'callback':
        // step 3
        if (empty($_REQUEST['code'])) {
            $message = 'Callback request must have `code` query parameter!';
            break;
        }
        $tokenUrl = sprintf('%s/index.php?oauth/token', $config['api_root']);
        $postFields = array('grant_type' => 'authorization_code', 'client_id' => $config['api_key'], 'client_secret' => $config['api_secret'], 'code' => $_REQUEST['code'], 'redirect_uri' => getCallbackUrl());
        if (isLocal($config['api_root']) && !isLocal(getBaseUrl())) {
            $message = renderMessageForPostRequest($tokenUrl, $postFields);
            $message .= '<br />Afterwards, you can test JavaScript by clicking the link below.';
            break;
        }
        // step 4
        $json = makeCurlPost($tokenUrl, $postFields);
        $message = renderAccessTokenMessage($tokenUrl, $json);
        break;
    case 'refresh':
        // this is the refresh token flow
        if (empty($_REQUEST['refresh_token'])) {
            $message = 'Refresh request must have `refresh_token` query parameter!';
            break;
        }
        $tokenUrl = sprintf('%s/index.php?oauth/token', $config['api_root']);
Example #8
0
 public function render_template()
 {
     $this->default_vars();
     if (is_array($this->vars['folder'])) {
         $folder = $this->vars['folder'];
     } else {
         $folder = array($this->vars['folder']);
     }
     if (isset($this->vars['page'])) {
         if (isset($this->vars['page']['js']) && $this->vars['page']['js'] != '') {
             if (!is_array($this->vars['page']['js'])) {
                 $this->vars['page']['js'] = explode(",", $this->vars['page']['js']);
             }
         }
         if (isset($this->vars['page']['template'])) {
             $folders = $folder;
             $tfile = $this->vars['page']['template'];
             $tfile = explode(".", $tfile);
             $tfile = $tfile[0];
             $version = $this->f3->get('_v');
             foreach ($folders as $f) {
                 if (file_exists('' . $f . '' . $tfile . '.twig')) {
                     if (file_exists('' . $f . '_js/' . $tfile . '.js')) {
                         $this->vars['page']['template_js'] = '/' . $f . '_js/' . $tfile . '.' . $version . '.js';
                     }
                     if (file_exists('' . $f . '_css/' . $tfile . '.css')) {
                         $this->vars['page']['template_css'] = '/' . $f . '_css/' . $tfile . '.' . $version . '.css';
                     }
                     if (file_exists('' . $f . 'template/' . $tfile . '.jtmpl')) {
                         $this->vars['page']['template_jtmpl'] = '/' . 'template/' . $tfile . '.jtmpl';
                     }
                     break;
                 }
             }
             $this->vars['page']['template'] = $this->vars['page']['template'] . ".twig";
         }
         //test_array($this->vars['page']);
     }
     //test_array($this->vars['page']);
     if ($this->config['strictfolder']) {
         $folder = $this->vars['folder'];
     }
     $loader = new Twig_Loader_Filesystem($folder);
     $options = array();
     if (!isLocal() && $this->f3->get("CACHE")) {
         //	$options['cache'] = $this->config['cache_dir'];
     }
     $options['debug'] = true;
     //$options['cache'] = false;
     //test_array($this->vars);
     $twig = new Twig_Environment($loader, $options);
     $twig->addExtension(new Twig_Extension_Debug());
     $twig->addFilter(new Twig_SimpleFilter('toAscii', function ($string) {
         $string = toAscii($string);
         return $string;
     }));
     $twig->addFilter(new Twig_SimpleFilter('scrub', function ($string) {
         $f3 = \Base::instance();
         $string = $f3->scrub($string);
         return $string;
     }));
     //test_array(array("template"=>$this->template,"vars"=>$this->vars));
     return $twig->render($this->template, $this->vars);
 }
Example #9
0
<?php

/* @TODO JS functions for seek/start/stop to set start and stop times. */
/* @TODO JS not needed for YouTube vids, use ?start=10&end=14 */
/**
 * Warning! This is a very primitive version of the Video trial type.
 * We expect to make improvements in the future, but in the mean time,
 * try using the YouTube trial type instead, and load your videos to
 * YouTube rather than your server.
 **/
if (!isLocal($cue)) {
    // video is not a local file
    if (false !== strpos($cue, 'youtube') || false !== strpos($cue, 'youtu.be')) {
        // YouTube URL
        $vidSource = youtubeUrlCleaner($cue);
        $parameters = 'autoplay=1&modestbranding=1&controls=0&rel=0&showinfo=0&iv_load_policy=3';
    } else {
        if (strpos($cue, 'vimeo')) {
            // Vimeo URL
            $vidSource = vimeoUrlCleaner($cue);
            $parameters = 'autoplay=1&badge=0&byline=0&portrait=0&title=0';
        } else {
            // Unsupported URL
            throw new InvalidArgumentException('The given video source is not ' . 'supported. Please use Vimeo, YouTube, or a local file.');
        }
    }
    $source = $vidSource . '?' . $parameters;
} else {
    // video is a local file
    $source = "{$_PATH->experiment}/{$cue}";
}
Example #10
0
function retrieveUIDInfo($s3element, $id, $scoreTable, $s3ql, $letter, $input_ids, $user_id, $db)
{
    #echo '<pre>';print_r($db);
    if ($s3ql['where'][$id] != '') {
        $element_name = $s3element;
        $id_name = $id;
        $letterSub = strtoupper(substr($id_name, 0, 1));
        $core = $GLOBALS['s3codes'][$letterSub];
        #is this remote?
        $uid_info = uid($letterSub . $s3ql['where'][$id_name]);
        $islocal = isLocal($letterSub . $s3ql['where'][$id_name], $db);
        #echo '<pre>';print_r($uid_info);
        #try regular URI (internal)
        if ($islocal) {
            $id = strtoupper(substr($element_name, 0, 1)) . $s3ql['where'][$id_name];
            $localuid = $letterSub . $s3ql['where'][$id_name];
            $element_info = URI($localuid, $user_id, $db);
            if ($element_info['acl'] == '') {
                $element_info['acl'] = permissionOnResource(array('shared_with' => 'U' . $user_id, 'uid' => $id, 'db' => $db, 'user_id' => $user_id, 'strictuid' => 1, 'strictsharedwith' => 1));
            }
            if ($id_name == $element . "_id") {
                if (!is_array($element_info)) {
                    if ($uid_info['uid'] != '') {
                        $forbidden = array('#', ':', '/');
                        $test_str = str_split($uid_info['uid']);
                        foreach ($forbidden as $f) {
                            if (array_search($f, $test_str)) {
                                if ($s3ql['format'] == '') {
                                    return '<TABLE><TR><TD>error_code</TD><TD>message</TD></TR><TR><TD>' . ereg_replace('[^(0-9)]', '', $GLOBALS['messages']['wrong_inputs']) . '</TD><TD>Please do not use any of the following character when specifying IDs: ' . array_reduce($forbidden, "comma_split") . '</TD></TR></TABLE>';
                                } else {
                                    return $GLOBALS['messages']['wrong_inputs'] . '<message>Please do not use any of the following character when specifying IDs: ' . array_reduce($forbidden, "comma_split") . '</message>';
                                }
                            }
                        }
                    }
                    $element_info = array('to_create' => '1');
                } else {
                    #echo '<pre>';print_r($element_info);
                    $element_info['to_create'] = '0';
                    #only valid when resource being inserted in another resource.
                }
            }
        } else {
            #interpreting user input: if this is uid beloing to the object being inserted and there are literal values, assume the provided ID is a literal and is meant to create "de novo"
            $diff = array_diff(array_keys($s3ql['where']), array($GLOBALS['COREids'][$s3element]));
            if ($id_name == $GLOBALS['COREids'][$s3ql['insert']] && !empty($diff) && !ereg('^(U|G|P)$', $letter)) {
                $element_info['to_create'] = '1';
            } else {
                #when inserting a remote user, project or group - when + ids. if this is user, most liel remoteURI will return no permission on the remote deployment
                if (ereg('^(U|G|P)$', $letter)) {
                    if (count($input_ids) > 1) {
                        $element_info = URI($s3ql['where'][$id_name], $user_id, $db);
                    } elseif (ereg('^P$', $letter)) {
                        $element_info = URI($s3ql['where'][$id_name], $s3ql['key'], $user_id, $db);
                        if (is_array($element_info)) {
                            $element_info['is_remote'] = '1';
                        } else {
                            #Id does not exist. Will assume the goal is to create a new.
                            $element_info = array('to_create' => '1');
                            $diff = array_diff(array_keys($s3ql['where']), $GLOBALS['COREids'], array('permission_level'));
                        }
                    } else {
                        $element_info = array('is_remote' => '1', 'account_id' => $s3ql['where'][$id_name]);
                    }
                } else {
                    #check if is remote only if no other parameters are provided.
                    $diff = array_diff(array_keys($s3ql['where']), $GLOBALS['COREids'], array('permission_level'));
                    if (!empty($diff) && $id_name == $GLOBALS['COREids'][$s3ql['insert']]) {
                        $element_info = array('to_create' => 1);
                    } else {
                        $element_info = remoteURI($s3ql['where'][$id_name], $s3ql['key'], $user_id, $db);
                        if (is_array($element_info)) {
                            $element_info['is_remote'] = '1';
                        }
                    }
                }
            }
        }
        return $element_info;
    }
}
Example #11
0
<?php

/**
 * Not sofisticated, just straight forward
 *
 * @return bool
 */
function isLocal()
{
    $srv = filter_input(INPUT_SERVER, 'SERVER_ADDR');
    return strpos($srv, '192.168') !== false || strpos($srv, '10.') === 0 || $srv == 'localhost' || $srv == '127.0.0.1' || $srv == '::1';
}
isLocal() ? define('BASEDIR', '/esselence/public') : define('BASEDIR', '');
// Define path to application directory
defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Define application environment
defined('APPLICATION_ENV') || define('APPLICATION_ENV', getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production');
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(realpath(APPLICATION_PATH . '/../library'), get_include_path())));
/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
$application->bootstrap()->run();
Example #12
0
 /**
  * check delivery status and condition of requested flight
  */
 public function deliveredAdStatus($adID, $flightWebsite, $flight, $dateRange)
 {
     $trackingModel = new Tracking();
     //kiểm tra độ tuổi
     if ($flight->age && !$this->checkAge(json_decode($flight->age), Input::get('age')) && !isLocal()) {
         return self::RESPONSE_TYPE_AGE_LIMIT;
     }
     //kiểm tra giới tính
     if ($flight->sex && !$this->checkGender($flight->sex, Input::get('g')) && !isLocal()) {
         return self::RESPONSE_TYPE_GENDER_LIMIT;
     }
     //kiểm tra vị trí địa lí
     if ($flight->country && $flight->province && !$this->checkGeo($flight->country, $flight->province)) {
         return self::RESPONSE_TYPE_GEO_LIMIT;
     }
     //kiểm tra frequency capping
     if (!empty($dateRange) && !$this->checkFrequencyCap($flight, $dateRange, $flightWebsite->id) && !isLocal()) {
         return self::RESPONSE_TYPE_FREQUENCY_CAPPED;
     }
     //TODO : kiểm tra channel
     // to do kiểm tra theo loại campaign : CPC hay CPM
     //if( $flight->cost_type == 'cpm' || $flight->cost_type == 'cpc' ){
     $event = Tracking::getTrackingEventType($flight->cost_type);
     $overReport = FALSE;
     $checkInventory = $this->checkInventory($flight, $flightWebsite, $event, $dateRange);
     if ($checkInventory !== TRUE) {
         //full inventory trong ngày
         // $checkOverInventory = $this->checkOverInventory($flight, $flightWebsite, $event);
         // if($checkOverInventory !== TRUE){
         return $checkInventory;
         // }
         // else{
         // 	$overReport = TRUE;
         // }
     } else {
         $checkOvrInventory = $this->checkOverInventory($flight, $flightWebsite, $event);
         pr($checkOvrInventory);
         if ($checkOvrInventory === TRUE) {
             $overReport = TRUE;
         }
     }
     //}
     // WHEN READY TO DELIVERY
     //if( $flight->frequency_cap ){
     if (!empty($dateRange)) {
         $todayCapped = $trackingModel->getTodayFreCap($flight);
         $now = strtotime(date('Y-m-d H:i'));
         pr($dateRange);
         foreach ($dateRange as $date) {
             if (strtotime($date->start) <= $now && strtotime($date->end) >= $now) {
                 if ($date->frequency_cap > 0) {
                     if ($trackingModel->getTimeFreCap($flight) == 0) {
                         $redis = new RedisBaseModel(env('REDIS_HOST', '127.0.0.1'), env('REDIS_PORT_2', '6379'), false);
                         $visitorId = $trackingModel->getVisitorId();
                         $cacheKey = "Tracking:TimeFrequencyCap_{$flight->id}_{$visitorId}_{$flight->event}";
                         $cacheField = date('Y_m_d');
                         $redis->hSet($cacheKey, $cacheField, 0);
                         if ($date->frequency_cap_time > 0) {
                             $redis->expire($cacheKey, $date->frequency_cap_time * 60);
                         } else {
                             $redis->expire($cacheKey, 2);
                         }
                     }
                     if ($todayCapped >= $date->frequency_cap - 1) {
                         $time = time();
                         $expire = round((strtotime(date('Y-m-d 23:59:59', $time)) - $time) / 60);
                         $trackingModel->setTimeFreCap($flight, $expire);
                     }
                 }
             }
         }
         /*if(  $todayCapped >= $flight->frequency_cap_free &&  $flight->frequency_cap_time > 0 ){
         			$trackingModel->rememberFrequencyCap($flightWebsite->id, $flight->frequency_cap_time);
         		}*/
     }
     return $overReport ? self::DELIVERY_STATUS_OVER_REPORT : self::DELIVERY_STATUS_OK;
 }
Example #13
0
<?php

#s3dbfiles.php returns the most recent version of the requested file as stored in the local s3db
###
#Detect which file is being requested. All files are public
ini_set('display_errors', 0);
if ($_REQUEST['su3d']) {
    ini_set('display_errors', 1);
}
$fileID2get = $_REQUEST['file_id'] != '' ? $_REQUEST['file_id'] : $_REQUEST['statement_id'];
if (file_exists('config.inc.php')) {
    include 'config.inc.php';
} else {
    Header('Location: index.php');
    exit;
}
#include('updates.s3db.php');
$key = $GLOBALS['update_project']['key'];
include_once 'core.header.php';
###
#Find the corresponding file on s3db, sort by created_n and return the first one found
if ($fileID2get == '') {
    echo "Please provide a file_id in the format: s3dbfiles.php?file_id=xx";
} elseif (isLocal('S' . $fileID2get, $db)) {
    $statement_info = URI('S' . $fileID2get, $user_id, $db);
    $format = $_REQUEST['format'];
    pushDownload2Header(compact('statement_info', 'db', 'user_id', 'format'));
} else {
    echo "Echo file_id=" . $fileID2get . " is not a valid file_id";
}
exit;
Example #14
0
<?php

date_default_timezone_set('Africa/Johannesburg');
function isLocal()
{
    if (file_exists("D:/web/local.txt") || file_exists("C:/web/local.txt")) {
        return true;
    } else {
        return false;
    }
}
$cfg = array();
require_once '../config.default.inc.php';
require_once '../config.inc.php';
require_once 'update.php';
if (!isLocal()) {
    echo "Updates...<hr>";
    echo "<h3>Files</h3>";
    echo "<pre>" . update::code($cfg) . "</pre>";
}
echo "<pre>" . update::db($cfg) . "</pre>";
Example #15
0
if (empty($apiScope)) {
    $apiScope = 'read';
}
// save configuration to session
if ((empty($_SERVER['REQUEST_METHOD']) || $_SERVER['REQUEST_METHOD'] !== 'GET') && !empty($apiRoot) && !empty($apiKey) && !empty($apiSecret) && !empty($apiScope)) {
    $_SESSION['api_root'] = $apiRoot;
    $_SESSION['api_key'] = $apiKey;
    $_SESSION['api_secret'] = $apiSecret;
    $_SESSION['api_scope'] = $apiScope;
    $_SESSION['ignore_config'] = true;
    $location = 'index.php';
    if (!empty($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'HEAD') {
        // a HEAD request, redirect to setup.php with all configuration needed
        // but only after verification (!important)
        // used in the add-on installer when it issues HEAD request to verify itself
        if (isLocal($apiRoot)) {
            // accepts all local addresses
        } else {
            $ott = generateOneTimeToken($apiKey, $apiSecret);
            list(, $json) = makeRequest('', $apiRoot, $ott);
            if (empty($json['links'])) {
                header('HTTP/1.0 403 Forbidden');
                exit;
            }
        }
        $location = sprintf('%s?api_root=%s&api_key=%s&api_secret=%s&api_scope=%s', getBaseUrl(), rawurlencode($apiRoot), rawurlencode($apiKey), rawurlencode($apiSecret), rawurlencode($apiScope));
        $bitlyToken = getenv('BITLY_TOKEN');
        if (!empty($bitlyToken)) {
            $location = bitlyShorten($bitlyToken, $location);
        }
    }
Example #16
0
function retrieveUIDInfoOLD($Z)
{
    extract($Z);
    #echo '<pre>';print_r($db);
    if ($s3ql['where'][$id] != '') {
        $element_name = $s3element;
        $id_name = $id;
        $letterSub = strtoupper(substr($id_name, 0, 1));
        $core = $GLOBALS['s3codes'][$letterSub];
        #is this remote?
        $uid_info = uid($letterSub . $s3ql['where'][$id_name]);
        $islocal = isLocal($letterSub . $s3ql['where'][$id_name], $db);
        $uid = $letter . $s3ql['where'][$id_name];
        #try regular URI (internal)
        if ($islocal) {
            $id = strtoupper(substr($element_name, 0, 1)) . $s3ql['where'][$id_name];
            $localuid = $letterSub . $s3ql['where'][$id_name];
            $element_info = URI($localuid, $user_id, $db);
            if ($element_info['acl'] == '') {
                $element_info['acl'] = permission4Resource(array('shared_with' => 'U' . $user_id, 'uid' => $id, 'db' => $db, 'user_id' => $user_id, 'strictuid' => 1, 'strictsharedwith' => 1));
            }
            if ($id_name == $element . "_id") {
                if (!is_array($element_info)) {
                    if ($uid_info['uid'] != '') {
                        $forbidden = array('#', ':', '/');
                        $test_str = str_split($uid_info['uid']);
                        foreach ($forbidden as $f) {
                            if (array_search($f, $test_str)) {
                                return formatReturn($GLOBALS['error_codes']['wrong_inputs'], 'Please do not use any of the following character when specifying IDs: ' . array_reduce($forbidden, "comma_split"), $s3ql['format'], '');
                            }
                        }
                    }
                    $element_info = array('to_create' => '1');
                } else {
                    #echo '<pre>';print_r($element_info);
                    $element_info['to_create'] = '0';
                    #only valid when resource being inserted in another resource.
                }
            }
        } else {
            #This UID can only be remote if it has a Did or URL attached. Does it?
            ereg('^D|http|(s3db:|ldap:|ftp:|smtp:){0,1}(.*):(.*)', $uid_info['uid'], $try);
            if (!$try) {
                #uh ho, it's not local nor remote, this might be a uid that someone is trying to create;
                #So let's check whether there is data to create it. Diff must be empty because it's the result of the difference between what is needed and what is provided.
                if (empty($diff) && $id_name == $GLOBALS['COREids'][$s3ql['insert']]) {
                    $element_info = array('to_create' => 1);
                    return $element_info;
                } else {
                    #Problem - id cannot be found and cannot be created :-(
                    $element_info = array();
                    return $element_info;
                }
            }
            #interpreting user input: if this is uid beloing to the object being inserted and there are literal values, assume the provided ID is a literal and is meant to create "de novo"
            $diff = array_diff(array_keys($s3ql['where']), array($GLOBALS['COREids'][$s3element]));
            if ($id_name == $GLOBALS['COREids'][$s3ql['insert']] && !empty($diff) && !ereg('^(U|G|P)$', $letter)) {
                #$element_info['to_create']='1';
                $element_info = URIinfo($letter . $s3ql['where'][$id_name], $user_id, $key, $db);
                $element_info['is_remote'] = '1';
            } else {
                #when inserting a remote user, project or group - when + ids. if this is user, most liel remoteURI will return no permission on the remote deployment
                if (ereg('^(U|G|P)$', $letter)) {
                    if (count($input_ids) > 1) {
                        $element_info = URI($s3ql['where'][$id_name], $user_id, $db);
                    } elseif (ereg('^P$', $letter)) {
                        #$element_info = URI($s3ql['where'][$id_name], $s3ql['key'], $user_id, $db);
                        $element_info = URIinfo($letter . $s3ql['where'][$id_name], $user_id, $key, $db);
                        if (is_array($element_info)) {
                            $element_info['is_remote'] = '1';
                        } else {
                            #Id does not exist. Will assume the goal is to create a new.
                            $element_info = array('to_create' => '1');
                            $diff = array_diff(array_keys($s3ql['where']), $GLOBALS['COREids'], array('permission_level'));
                        }
                    } else {
                        $element_info = array('is_remote' => '1', 'account_id' => $s3ql['where'][$id_name]);
                    }
                } else {
                    #check if is remote only if no other parameters are provided.
                    $diff = array_diff(array_keys($s3ql['where']), $GLOBALS['COREids'], array('permission_level'));
                    if (!empty($diff) && $id_name == $GLOBALS['COREids'][$s3ql['insert']]) {
                        $element_info = array('to_create' => 1);
                    } else {
                        $element_info = remoteURI($s3ql['where'][$id_name], $s3ql['key'], $user_id, $db);
                        if (is_array($element_info)) {
                            $element_info['is_remote'] = '1';
                        }
                    }
                }
            }
        }
        return $element_info;
    }
}
Example #17
0
 public function trackEvent()
 {
     ignore_user_abort(true);
     $this->layout = null;
     $response = null;
     $responseType = '';
     $expandFields = array();
     $deliveryStatus = '';
     $event = strtolower(Input::get('evt', ''));
     $requestType = Input::get('rt', Delivery::REQUEST_TYPE_TRACKING_BEACON);
     $checksum = Input::get('cs', '');
     $flightWebsiteID = Input::get('fpid', 0);
     $zoneID = Input::get('zid', 0);
     $isOverReport = Input::get('ovr');
     //custom code for VIB 068 Relaunch form complete tracking
     if (Input::get('wid') == 48 && $event == 'complete') {
         $flightWebsiteID = 172;
         $event = "impression";
     }
     $trackingModel = new Tracking();
     $deliveryModel = new Delivery();
     //ghi log trước khi xử lý
     $logPreProcess = $trackingModel->logPreProcess($requestType, Input::get());
     if ($logPreProcess) {
         //kiểm tra referrer
         $hostReferer = $trackingModel->getRequestReferer();
         $responseType = $trackingModel->checkPreProcess($requestType, $hostReferer, $zoneID);
         if (empty($responseType)) {
             $adZone = $deliveryModel->getAdzone($zoneID);
             if ($adZone) {
                 if (isSameDomain($hostReferer, getWebDomain($adZone->site->url)) || isLocal()) {
                     $flightWebsite = $deliveryModel->getFullFlightWebsite($flightWebsiteID);
                     if ($flightWebsite) {
                         //checksum
                         if ($flightWebsite->flight->ad_format_id == Delivery::TRACKING_CODE_ADID) {
                             $responseType = Delivery::RESPONSE_TYPE_TRACKING_BEACON_SUCCESS;
                         } elseif ($trackingModel->isValidTrackingBeacon($checksum, $event)) {
                             $responseType = Delivery::RESPONSE_TYPE_TRACKING_BEACON_SUCCESS;
                             //set cookie for retargeting
                             $trackingModel->rememberRetarget($flightWebsite->flight->campaign_id, $event);
                         } else {
                             $responseType = Delivery::RESPONSE_TYPE_CHECKSUM_ERROR;
                         }
                     }
                     //else invalid
                 }
             }
         }
         if (empty($responseType)) {
             $responseType = Delivery::RESPONSE_TYPE_INVALID;
         } elseif ($responseType == Delivery::RESPONSE_TYPE_TRACKING_BEACON_SUCCESS) {
             $expandFields = array('flight_id' => $flightWebsite->flight_id, 'ad_format_id' => $adZone->ad_format_id, 'ad_id' => $flightWebsite->flight->ad_id, 'campaign_id' => $flightWebsite->flight->campaign_id, 'publisher_ad_zone_id' => $adZone->id, 'flight_website_id' => $flightWebsite->id, 'website_id' => $flightWebsite->website_id);
             $expandFields['checksum'] = $checksum;
             $eventChecksum = $event;
             $trackingModel->setChecksumTrackingEvent($checksum, $event);
             //udpate inventory
             //$inventoryMetric = $trackingModel->getTrackingEventType($flightWebsite->flight->cost_type);
             $inventoryMetric = $trackingModel->getTrackingEventType($flightWebsite->flight->cost_type);
             if ($event == $inventoryMetric) {
                 $trackingModel->updateInventory($flightWebsite->flight->id, $flightWebsite->id, $inventoryMetric, $isOverReport);
             }
             if (isset($flightWebsite->flight->event) && $flightWebsite->flight->event != '') {
                 $flightEvent = $flightWebsite->flight->event;
             } else {
                 // Truong hop nhung flight truoc day khong co setting event
                 $flightEvent = $inventoryMetric;
             }
             if ($event == $flightEvent) {
                 //incre today capped this ad by 1
                 $trackingModel->incFreCap($flightWebsite->flight);
             }
             //update tracking summary
             $rawTrackingSummary = new RawTrackingSummary();
             $rawTrackingSummary->addSummary($event, $flightWebsite->website_id, $adZone->id, $adZone->ad_format_id, $flightWebsite->flight_id, $flightWebsite->id, $flightWebsite->flight->ad_id, $flightWebsite->flight->campaign_id);
             $uniqueEvent = '';
             //unique impression
             if ($event == 'impression') {
                 $uniqueEvent = 'unique_impression';
                 $expandFields['unique_impression'] = $trackingModel->isUniqueImpression($flightWebsite->id);
             }
             //unique click
             if ($event == 'click') {
                 $uniqueEvent = 'unique_click';
                 $expandFields['unique_click'] = $trackingModel->isUniqueClick($flightWebsite->id);
             }
             //add summary unique click or impression
             if (!empty($expandFields[$uniqueEvent])) {
                 $rawTrackingSummary->addSummary($uniqueEvent, $flightWebsite->website_id, $adZone->id, $adZone->ad_format_id, $flightWebsite->flight_id, $flightWebsite->id, $flightWebsite->flight->ad_id, $flightWebsite->flight->campaign_id);
             }
         }
     }
     //ghi log process
     $logAfterProcess = $trackingModel->logAfterProcess($responseType, $expandFields, $logPreProcess);
     //response to client
     pr($expandFields);
     pr($responseType, 1);
     if ($event == 'click' && Input::get('to')) {
         //redirect to ad's destination url on click event
         return Redirect::to(urldecode(Input::get('to')));
     } else {
         //return 1x1 transparent GIF
         $response = $trackingModel->outputTransparentGif();
         // exit();
     }
 }
Example #18
0
        $md5 = get_par('md5');
        echo json_encode(get_test_case($cate, $md5));
    } elseif ($type == 'retest') {
        $md5 = get_par('md5');
        print_r(retest_case($cate, $md5));
    } elseif ($type == 'welefen') {
        foreach ($list as $cate => $class) {
            $file = dirname(__FILE__) . '/Case/' . $cate . '.json';
            if (file_exists($file)) {
                $content = file_get_contents($file);
                $content = json_decode($content, true);
                $result = array();
                foreach ($content as $item) {
                    $item['text'] = trim($item['text']);
                    $result[md5($item['text'])] = $item;
                }
                file_put_contents($file, json_encode($result));
            }
        }
    } else {
        $class = $list[$cate];
        $result = test_file($cate, $class);
        echo json_encode($result);
    }
} catch (Fl_Exception $e) {
    if (isLocal()) {
        print_r($e);
    } else {
        echo "Fatal Error: " . $e->message;
    }
}
Example #19
0
<?php

/**
 * Not sofisticated, just straight forward
 *
 * @return bool
 */
function isLocal()
{
    $srv = filter_input(INPUT_SERVER, 'SERVER_ADDR');
    return strpos($srv, '192.168') !== false || strpos($srv, '10.') === 0 || $srv == 'localhost' || $srv == '127.0.0.1' || $srv == '::1';
}
isLocal() ? define('BASEDIR', '/ag3/public') : define('BASEDIR', '/public');
// Define path to application directory
defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Define application environment
defined('APPLICATION_ENV') || define('APPLICATION_ENV', getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production');
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(realpath(APPLICATION_PATH . '/../library'), realpath(APPLICATION_PATH), realpath(APPLICATION_PATH . '/modules'), get_include_path())));
/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
$application->bootstrap()->run();