/**
  * Returns an array of audience objects
  *
  * @param int $dataProviderId
  * @param |DateTime $from
  * @param |DateTime $to
  * @param array $groupBy
  *
  * @throws Exception\ApiException if the API call fails
  *
  * @return DataProviderAudience[]
  */
 public function get($dataProviderId, $from, $to, $groupBy)
 {
     // Endpoint URI
     $uri = 'v1/dataproviders/' . $dataProviderId . '/audience';
     $options = ['query' => ['from' => $from->format('c'), 'to' => $to->format('c'), 'groupBy' => $groupBy]];
     $dataProviderAudiences = [];
     try {
         $data = null;
         // try to get from cache
         if ($this->cache) {
             $data = $this->cache->get($this->cachePrefix, $uri, $options);
         }
         // load from API
         if (!$data) {
             $data = $this->httpClient->get($uri, $options)->getBody()->getContents();
             if ($this->cache and $data) {
                 $this->cache->put($this->cachePrefix, $uri, $options, $data);
             }
         }
         $classArray = json_decode($data);
         foreach ($classArray as $class) {
             $dataProviderAudiences[] = DataProviderAudienceHydrator::fromStdClass($class);
         }
     } catch (ClientException $e) {
         $response = $e->getResponse();
         $responseBody = $response->getBody()->getContents();
         $responseCode = $response->getStatusCode();
         throw new Exception\ApiException($responseBody, $responseCode);
     }
     return $dataProviderAudiences;
 }
Example #2
0
/**
 * Modify a string by replacing named tokens with matching assoc. array values.
 * @param {String} string The string to modify.
 * @param {Array} assoc The template assoc. array.
 * @returns {String} The modified string.
 */
function interpolate($string, $assoc)
{
    foreach ($assoc as $key => $value) {
        $string = preg_replace("/#\\{" . $key . "\\}/", trim((string) $value), $string);
    }
    return format($string);
}
 /**
  * Returns an array of data usage objects
  *
  * @param int $dataProviderId
  * @param |DateTime $from
  * @param |DateTime $to
  * @param array $groupBy
  * @param int $limit
  * @param int $offset
  *
  * @throws Exception\ApiException if the API call fails
  *
  * @return array
  */
 public function get($dataProviderId, $from, $to, $groupBy, $limit = 1000, $offset = 0)
 {
     // Endpoint URI
     $uri = 'v1/reports/datausage';
     $options = ['query' => ['dataProviderId' => $dataProviderId, 'from' => $from->format('c'), 'to' => $to->format('c'), 'groupBy' => $groupBy, 'limit' => $limit, 'offset' => $offset]];
     $usage = [];
     try {
         $data = null;
         // try to get from cache
         if ($this->cache) {
             $data = $this->cache->get($this->cachePrefix, $uri, $options);
         }
         // load from API
         if (!$data) {
             $data = $this->httpClient->get($uri, $options)->getBody()->getContents();
             if ($this->cache and $data) {
                 $this->cache->put($this->cachePrefix, $uri, $options, $data);
             }
         }
         $usage = json_decode($data);
     } catch (ClientException $e) {
         $response = $e->getResponse();
         $responseBody = $response->getBody()->getContents();
         $responseCode = $response->getStatusCode();
         throw new Exception\ApiException($responseBody, $responseCode);
     }
     return $usage;
 }
Example #4
0
function AssertForbidden($to, $specifically = 0)
{
    global $loguser, $forbidden;
    if (!isset($forbidden)) {
        $forbidden = explode(" ", $loguser['forbiddens']);
    }
    $caught = 0;
    if (in_array($to, $forbidden)) {
        $caught = 1;
    } else {
        $specific = $to . "[" . $specifically . "]";
        if (in_array($specific, $forbidden)) {
            $caught = 2;
        }
    }
    if ($caught) {
        $not = __("You are not allowed to {0}.");
        $messages = array("addRanks" => __("add new ranks"), "blockLayouts" => __("block layouts"), "deleteComments" => __("delete usercomments"), "editCats" => __("edit the forum categories"), "editForum" => __("edit the forum list"), "editIPBans" => __("edit the IP ban list"), "editMods" => __("edit Local Moderator assignments"), "editMoods" => __("edit your mood avatars"), "editPoRA" => __("edit the PoRA box"), "editPost" => __("edit posts"), "editProfile" => __("edit your profile"), "editSettings" => __("edit the board settings"), "editSmilies" => __("edit the smiley list"), "editThread" => __("edit threads"), "editUser" => __("edit users"), "haveCookie" => __("have a cookie"), "listPosts" => __("see all posts by a given user"), "makeComments" => __("post usercomments"), "makeReply" => __("reply to threads"), "makeThread" => __("start new threads"), "optimize" => __("optimize the tables"), "purgeRevs" => __("purge old revisions"), "recalculate" => __("recalculate the board counters"), "search" => __("use the search function"), "sendPM" => __("send private messages"), "snoopPM" => __("view other users' private messages"), "useUploader" => __("upload files"), "viewAdminRoom" => __("see the admin room"), "viewAvatars" => __("see the avatar library"), "viewCalendar" => __("see the calendar"), "viewForum" => __("view fora"), "viewLKB" => __("see the Last Known Browser table"), "viewMembers" => __("see the memberlist"), "viewOnline" => __("see who's online"), "viewPM" => __("view private messages"), "viewProfile" => __("view user profiles"), "viewRanks" => __("see the rank lists"), "viewRecords" => __("see the top scores and DB usage"), "viewThread" => __("read threads"), "viewUploader" => __("see the uploader"), "vote" => __("vote"));
        $messages2 = array("viewForum" => __("see this forum"), "viewThread" => __("read this thread"), "makeReply" => __("reply in this thread"), "editUser" => __("edit this user"));
        $bucket = "forbiddens";
        include "./lib/pluginloader.php";
        if ($caught == 2 && array_key_exists($to, $messages2)) {
            Kill(format($not, $messages2[$to]), __("Permission denied."));
        }
        Kill(format($not, $messages[$to]), __("Permission denied."));
    }
}
Example #5
0
 public function send($errorCode, $data, $more = true, $extra = array(), $execute = true)
 {
     //注意要判断message是否为空。
     $arr = array('errorCode' => (string) $errorCode, 'message' => format($data, $more, $extra));
     $json = CJSON::encode($arr);
     $json = preg_replace_callback('/\\\\u([0-9a-f]{4})/i', 'unescapedUnicode', $json);
     if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'android') !== FALSE) {
         header('Content-type:application/json;charset=utf-8');
         if ($execute) {
             exit($json);
         } else {
             echo $json;
         }
     } else {
         if (empty($_SERVER['HTTP_USER_AGENT'])) {
             header('Content-type:application/json;charset=utf-8');
             if ($execute) {
                 exit($json);
             } else {
                 echo $json;
             }
         } else {
             header('Content-type:text/html;charset=utf-8');
             Yii::app()->getController()->jsonText = jsonFormat($json);
         }
     }
 }
Example #6
0
 function withHTML()
 {
     if (!$this->desc_html) {
         $this->desc_html = format('product', $this->desc);
         $this->save();
     }
     return $this;
 }
Example #7
0
function reportFix($what, $aff = -1)
{
    global $fixtime;
    if ($aff = -1) {
        $aff = affectedRows();
    }
    echo $what, " ", format(__("{0} rows affected."), $aff), " time: ", sprintf('%1.3f', usectime() - $fixtime), "<br />";
}
Example #8
0
 function withHTML()
 {
     if (!$this->html) {
         $this->html = format('post', $this->body);
         $this->save();
     }
     return $this;
 }
 private function processObject($obj)
 {
     $fa = \CLips\get_annotation(get_class($obj), 'Clips\\Formatter');
     if ($fa) {
         return $name . '="' . \format($obj, $fa->value) . '"';
     } else {
         return $this->format((array) $obj);
     }
 }
function MakeSelect($fieldName, $checkedIndex, $choicesList, $extras = "")
{
    $checks[$checkedIndex] = " selected=\"selected\"";
    foreach ($choicesList as $key => $val) {
        $options .= format("\n\t\t\t\t\t\t<option value=\"{0}\"{1}>{2}</option>", $key, $checks[$key], $val);
    }
    $result = format("\n\t\t\t\t\t<select id=\"{0}\" name=\"{0}\" size=\"1\" {1} >{2}\n\t\t\t\t\t</select>", $fieldName, $extras, $options);
    return $result;
}
Example #11
0
 function showUpdates()
 {
     $age = $this->checkAge("tweeter", 5);
     if ($age <= 0) {
         $this->gatherTweet();
     }
     $this->getAllByID("tweeter");
     $cached = $this->sql->getNextRow();
     $ret = $cached["cached_contents"];
     return format($ret);
 }
Example #12
0
function format($array)
{
    foreach ($array as $key => $item) {
        if (is_array($item)) {
            $array[$key] = format($item);
        } else {
            $array[$key] = preg_replace(array('/\\*([^*]+)\\*/', '/\\(([^_]+)\\)/', '/\\n\\s*\\n/', '/"([^"]+)"/', '/\\s{2,}/'), array('<strong>\\1</strong>', '<span>\\1</span>', "<br />\n", '<q>\\1</q>', ' '), $item);
        }
    }
    return $array;
}
Example #13
0
 function findNotPay($args)
 {
     $current = (int) $args[0];
     if ($current == 0) {
         $current = 1;
     }
     $arr = array('date_start' => '2015-09-01', 'date_end' => format(timenow(), '-') . ' 23:59:59', 'name' => '', 'pay' => 0);
     $data = $this->load->model('order')->findByPay($arr, array($current, HOSTNAME . 'admin/order/findNotPay/', 15));
     $pagination = $this->db->getPage();
     return $this->load->view('order_notPay', array('orders' => $data, 'pagination' => $pagination));
 }
Example #14
0
function buildInput($name, $title = '', $type = 'text', $data = '', $extra = '')
{
    $title = $title ? $title : format($name);
    if ($type == 'checkbox' and $data) {
        $checked = " checked='checked'";
    }
    if ($data) {
        $value = " value='{$data}'";
    }
    print "<label for='{$name}'>{$title}</label><input type='{$type}' name='{$name}' id='{$name}'" . $value . $checked . $extra . " /><br />\n";
}
Example #15
0
function err($message, $args = null, $args2 = null)
{
    $message = format(func_get_args());
    echo $message . PHP_EOL;
    $dir = 'reports';
    if (!is_dir($dir)) {
        mkdir($dir, 0777, true);
    }
    $content = $message . str_repeat(PHP_EOL, 2) . str_repeat('=', 70);
    file_put_contents($dir . '/check-coverage.txt', $content);
    return '';
}
Example #16
0
function logs($str)
{
    $file = fopen(LOGS . format(timenow(), '_') . '.txt', 'a');
    if (flock($file, LOCK_EX)) {
        //加写锁
        // fputs($file,$string);        //写文件
        fwrite($file, $str . "--" . timenow() . "\n");
        flock($file, LOCK_UN);
        //解锁
    }
    fclose($file);
}
Example #17
0
function getOnlineUsersText()
{
    global $OnlineUsersFid;
    $refreshCode = "";
    if (!isset($OnlineUsersFid)) {
        $OnlineUsersFid = 0;
    }
    if (Settings::get("ajax")) {
        $refreshCode = format("\n\t\t<script type=\"text/javascript\">\n\t\t\tonlineFID = {0};\n\t\t\twindow.addEventListener(\"load\",  startOnlineUsers, false);\n\t\t</script>\n\t", $OnlineUsersFid);
    }
    $onlineUsers = OnlineUsers($OnlineUsersFid);
    return "<div style=\"min-height:16px;\" id=\"onlineUsers\">{$onlineUsers}</div>{$refreshCode}";
}
Example #18
0
function endeach()
{
    global $each_parameter;
    global $each_param_name;
    $html = ob_get_clean();
    foreach ($each_parameter as $param) {
        if (is_array($param)) {
            echo format($html, $param);
        } else {
            echo format($html, array($each_param_name => $param));
        }
    }
}
function step0($req)
{
    set_time_limit(0);
    //this avoids timeouts
    $_SESSION["ent_checked"] = array();
    $ent = $_SESSION["ent"];
    if (isset($_SESSION["ent_old"])) {
        $ent_old = $_SESSION["ent_old"];
        $response = format($ent, $ent_old);
    } else {
        $response = format($ent);
    }
    return $response;
}
Example #20
0
function qwp_tmpl_render_sub_modules()
{
    global $MODULE, $MODULE_URI;
    $nav = C('sub_nav', array());
    $html = '';
    foreach ($nav[$MODULE[0]] as $item) {
        $active = '';
        if ($item[0] == $MODULE_URI) {
            $active = ' class="active"';
        }
        $html .= format('<li{0}><a href="{1}">{2}</a></li>', $active, qwp_uri_module($item[0]), L($item[1]));
    }
    echo $html;
}
Example #21
0
function qwp_tmpl_render_sub_modules()
{
    global $MODULE, $PAGE;
    $acls = C('acls', array());
    $pages = $acls['pages'][$MODULE[0]];
    $html = '';
    foreach ($pages as $item => $desc) {
        $active = '';
        if ($item == $PAGE) {
            $active = ' class="active"';
        }
        $html .= format('<li{0}><a href="{1}">{2}</a></li>', $active, qwp_uri_page($item), L($desc));
    }
    echo $html;
}
Example #22
0
function test_log()
{
    $iCount = 10000;
    while ($iCount-- > 0) {
        SeasLog::error(format(array('msg' => "HelloWorld", 'id' => $iCount), "__main__", '123'), array(), 'test1');
    }
    $iCount = 10000;
    while ($iCount-- > 0) {
        SeasLog::info(format(array('msg' => "HelloWorld", 'id' => $iCount), "__main__", '123'), array(), 'test2');
    }
    $iCount = 10000;
    while ($iCount-- > 0) {
        SeasLog::debug(format(array('msg' => "HelloWorld", 'id' => $iCount), "__main__", '123'));
    }
}
Example #23
0
function parseGPSCoordinates($data)
{
    if ($data->{'GPS'} === null) {
        return 'GPS Coordinates not found';
    }
    $values = [];
    $values['LAT'] = $data->{'GPS'}->{'GPSLatitudeRef'};
    $values['LONG'] = $data->{'GPS'}->{'GPSLongitudeRef'};
    $values['LAT_DEG'] = applyDivision($data->{'GPS'}->{'GPSLatitude'}[0]);
    $values['LAT_MIN'] = applyDivision($data->{'GPS'}->{'GPSLatitude'}[1]);
    $values['LAT_SEC'] = applyDivision($data->{'GPS'}->{'GPSLatitude'}[2]);
    $values['LONG_DEG'] = applyDivision($data->{'GPS'}->{'GPSLongitude'}[0]);
    $values['LONG_MIN'] = applyDivision($data->{'GPS'}->{'GPSLongitude'}[1]);
    $values['LONG_SEC'] = applyDivision($data->{'GPS'}->{'GPSLongitude'}[2]);
    return format("{LAT} {LAT_DEG}° {LAT_MIN}' {LAT_SEC}'' {LONG} {LONG_DEG}° {LONG_MIN}' {LONG_SEC}''", $values);
}
Example #24
0
 function query($query)
 {
     $argument = 0;
     for ($i = strpos($query, '%'); $i !== false; $i = strpos($query, '%', $i + strlen($replace))) {
         $value = func_get_arg(++$argument);
         switch (substr($query, $i + 1, 1)) {
             case '%':
                 $replace = '%';
                 --$argument;
                 break;
             case 's':
                 $replace = mysql_real_escape_string($value);
                 break;
             case 'S':
                 $replace = mysql_real_escape_string($value);
                 break;
             case 'q':
                 $replace = format('"%S"', $value);
                 break;
             case 'l':
                 $replace = preg_replace('/([%_\\\'"])/', '\\\\1', $value);
                 break;
             case 'd':
                 $replace = mysql_real_escape_string($value);
                 break;
             case 'n':
                 $replace = strlen($value) == 0 ? 'NULL' : format('%q', $value);
                 break;
             case 't':
                 $replace = format('FROM_UNIXTIME(%n)', $value);
                 break;
             default:
                 $replace = '';
         }
         $query = substr_replace($query, $replace, $i, 2);
     }
     $result = mysql_query($query);
     $mysql_error_num = mysql_errno(self::$conn);
     $mysql_error = mysql_error(self::$conn);
     if ($result != 'true') {
         error_log('MYSQL QUERY: ' . var_export($query, 1));
         //error_log('MYSQL ERROR: ' . var_export($mysql_error_num, 1) . ": " . var_export($mysql_error, 1). "\n");
         //error_log('MYSQL RESULT: ' . var_export($result,1));
     }
     return $result;
 }
function test($sFunction, $asValue)
{
    global $oValidatorCollection;
    echo '
	Testing method <strong>', $sFunction, '</strong>
	<ol>';
    foreach ($asValue as $amContext) {
        $sThingy = '"' . format($amContext[0]) . '" should ' . ($amContext[2] ? '' : 'not ') . 'pass ' . $sFunction;
        if (false === is_null($amContext[1])) {
            $sThingy .= ' ' . format($amContext[1]);
        }
        $bResult = $amContext[2] === $oValidatorCollection->{$sFunction}($amContext[0], $amContext[1]);
        echo '
		<li>', $sThingy, ': ', $bResult ? 'pass' : 'FAIL', '</li>';
    }
    echo '
	</ol>';
}
Example #26
0
function getLastHTTPRequest($client)
{
    $string = "";
    $string .= "<pre>\n";
    $string .= "*---------------------------------------------------------------------------------\n";
    $string .= "* request:\n";
    $string .= "*---------------------------------------------------------------------------------\n";
    $string .= htmlentities($client->__getLastRequestHeaders()) . "\n";
    $string .= htmlentities(format($client->__getLastRequest())) . "\n";
    $string .= "*---------------------------------------------------------------------------------\n";
    $string .= "* response:\n";
    $string .= "*---------------------------------------------------------------------------------\n";
    $string .= htmlentities($client->__getLastResponseHeaders()) . "\n";
    $string .= htmlentities(format($client->__getLastResponse())) . "\n";
    $string .= "*---------------------------------------------------------------------------------\n";
    $string .= "</pre>";
    return $string;
}
Example #27
0
function uploadFile($file, $cattype, $cat)
{
    global $loguserid, $uploaddirs, $goodfiles, $badfiles, $userquota, $maxSize;
    $targetdir = $uploaddirs[$cattype];
    $totalsize = foldersize($targetdir);
    $filedata = $_FILES[$file];
    $c = FetchResult("SELECT COUNT(*) FROM {uploader} WHERE filename={0} AND cattype={1} AND user={2} AND deldate=0", $filedata['name'], $cattype, $loguserid);
    if ($c > 0) {
        return "You already have a file with this name. Please delete the old copy before uploading a new one.";
    }
    if ($filedata['size'] == 0) {
        if ($filedata['tmp_name'] == '') {
            return 'No file given.';
        } else {
            return 'File is empty.';
        }
    }
    if ($filedata['size'] > $maxSize) {
        return 'File is too large. Maximum size allowed is ' . BytesToSize($maxSize) . '.';
    }
    $randomid = Shake();
    $pname = $randomid . '_' . Shake();
    $fname = $_FILES['newfile']['name'];
    $temp = $_FILES['newfile']['tmp_name'];
    $size = $_FILES['size']['size'];
    $parts = explode(".", $fname);
    $extension = end($parts);
    if ($totalsize + $size > $quot) {
        Alert(format(__("Uploading \"{0}\" would break the quota."), $fname));
    } else {
        if (in_array(strtolower($extension), $badfiles) || is_array($goodfiles) && !in_array(strtolower($extension), $goodfiles)) {
            return 'Forbidden file type.';
        } else {
            $description = $_POST['description'];
            $big_descr = $cat['showindownloads'] ? $_POST['big_description'] : '';
            Query("insert into {uploader} (id, filename, description, big_description, date, user, private, category, deldate, physicalname) values ({7}, {0}, {1}, {6}, {2}, {3}, {4}, {5}, 0, {8})", $fname, $description, time(), $loguserid, $privateFlag, $_POST['cat'], $big_descr, $randomid, $pname);
            copy($temp, $targetdir . "/" . $pname);
            Report("[b]" . $loguser['name'] . "[/] uploaded file \"[b]" . $fname . "[/]\"" . ($privateFlag ? " (privately)" : ""), $privateFlag);
            die(header("Location: " . actionLink("uploaderlist", "", "cat=" . $_POST["cat"])));
        }
    }
}
 /**
  * Create
  */
 public function actionContact()
 {
     $contactUs = new YdContactUs('create');
     if (isset($_POST['YdContactUs'])) {
         $contactUs->attributes = $_POST['YdContactUs'];
         $contactUs->ip_address = si($_SERVER, 'REMOTE_ADDR');
         $contactUs->message = format()->formatNtext($contactUs->message);
         if ($contactUs->save()) {
             EMailHelper::sendContactEmail($contactUs);
             Yii::app()->user->addFlash(Yii::t('dressing', 'Your message has been sent successfully.'), 'success');
             $this->redirect(Yii::app()->returnUrl->getUrl(array('contactUs/thankYou')));
         }
         Yii::app()->user->addFlash(Yii::t('dressing', 'Could not send the message.'), 'error');
     } else {
         if (isset($_GET['YdContactUs'])) {
             $contactUs->attributes = $_GET['YdContactUs'];
         }
     }
     $this->render('contact', array('contactUs' => $contactUs));
 }
function time_diff($time_b, $time_e)
{
    $time_b_sec = explode(':', $time_b);
    $time_e_sec = explode(':', $time_e);
    $inc_sec = intval($time_e_sec[2]) - intval($time_b_sec[2]);
    $inc_min = intval($time_e_sec[1]) - intval($time_b_sec[1]);
    $inc_hr = intval($time_e_sec[0]) - intval($time_b_sec[0]);
    if ($inc_sec < 0) {
        $inc_sec = 60 + $inc_sec;
        $inc_min = $inc_min - 1;
    }
    if ($inc_min < 0) {
        $inc_min = 60 + $inc_min;
        $inc_hr = $inc_hr - 1;
    }
    if ($inc_min < 0) {
        $inc_hr = 24 + $inc_hr;
    }
    return format($inc_hr, $inc_min, $inc_sec);
}
Example #30
0
function getHourHtml($dane, $znak)
{
    $html = '<' . $znak . '>';
    $godziny = explode(';', $dane);
    $tmp = array();
    foreach ($godziny as $godz) {
        list($h, $m) = explode(':', trim($godz));
        list($m, $p) = explode(' ', trim($m));
        $tmp[$h][] = format($m) . ' ' . $p;
    }
    foreach ($tmp as $h => $minuty) {
        $html .= '<godz h="' . format($h) . '">';
        foreach ($minuty as $m) {
            $html .= '<m>' . $m . '</m>';
        }
        $html .= '</godz>';
    }
    $html .= '</' . $znak . '>';
    return $html;
}