Example #1
0
$data = array_filter($data, function ($row) {
    global $filter;
    foreach ($filter as $field => $val) {
        if ($row[$field] != $val) {
            return false;
        }
    }
    return true;
});
$recordsFiltered = count($data);
// Slice data based of start and limit
$data = array_slice($data, $start, $limit);
$recordsReturned = count($data);
// Replace picture property with holder.js
foreach ($data as &$row) {
    list($fg, $bg) = randColor($row['id']);
    $row['picture'] = "holder.js/80x80/#{$fg}:#{$bg}";
}
// delay if requested, to simulate database overhead
if (isset($_GET['delay'])) {
    if (empty($_GET['delay'])) {
        // random delay
        $delay = $randDelays[array_rand($randDelays)];
    } else {
        $delay = min(intval($_GET['delay']), 5000);
    }
    usleep($delay * 1000);
}
// Output data as JSON
header('Content-Type: application/json');
header('X-Request-Input: ' . json_encode($_REQUEST));
Example #2
0
    $green = hexdec(substr($color, 2, 2));
    $blue = hexdec(substr($color, 4, 2));
    $out = ImageColorAllocate($image, $red, $green, $blue);
    return $out;
}
$wordBox = imageftbbox($fontSize, 0, $font, $verify_string);
$wordBoxWidth = $wordBox[2];
$wordBoxHeight = $wordBox[1] + abs($wordBox[7]);
$containerWidth = $wordBoxWidth + $padding * 2;
$containerHeight = $wordBoxHeight + $padding * 2;
$textX = $padding;
$textY = $containerHeight - $padding;
$captchaImage = imagecreate($containerWidth, $containerHeight);
$red = randColor();
$green = randColor();
$blue = randColor();
$backgroundColor = ImageColorAllocate($captchaImage, $red, $green, $blue);
$rred = 255 - $red;
$rgreen = 255 - $green;
$rblue = 255 - $blue;
$textColor = ImageColorAllocate($captchaImage, $rred, $rgreen, $rblue);
imagefttext($captchaImage, $fontSize, 0, $textX, $textY, $textColor, $font, $verify_string);
$angle = mt_rand(-3, 3);
$captchaImage = imagerotate($captchaImage, $angle, $backgroundColor);
$line = ImageColorAllocate($captchaImage, $rred, $rgreen, $rblue);
for ($i = 0; $i < 10; $i++) {
    $xStart = mt_rand(0, $containerWidth);
    $yStart = mt_rand(0, $containerHeight);
    $xEnd = mt_rand(0, $containerWidth);
    $yEnd = mt_rand(0, $containerHeight);
    imageline($captchaImage, $xStart, $yStart, $xEnd, $yEnd, $line);
Example #3
0
/**
 * 显示标签
 * @param string $parse 解析模版
 * @param number $limit 显示条数 为0时表示显示全部
 * @param string $sort 排序字段
 * @param number $desc 默认为0,表示倒序
 * @return void
 */
function showTagCloud($parse = null, $limit = 30, $sort = 'mid', $desc = 0)
{
    $parse = is_null($parse) ? '<li><a href="{permalink}" title="{count}个话题" style="{background}">{name}({count})</a></li>' : $parse;
    Typecho_Widget::widget('Widget_Metas_Tag_Cloud', 'sort=' . $sort . '&ignoreZeroCount=1&desc=' . $desc . '&limit=' . $limit)->to($tags);
    $output = '';
    if ($tags->have()) {
        while ($tags->next()) {
            $color = 'color: rgb(' . randColor() . ');';
            $background = 'background-' . $color;
            $output .= str_replace(array('{permalink}', '{count}', '{name}', '{background}', '{color}'), array($tags->permalink, $tags->count, $tags->name, $background, $color), $parse);
        }
    }
    echo $output;
}
    <body>
        <table 
            <tbody>
                <?php 
for ($tr = 0; $tr < 10; $tr++) {
    ?>
 
                 <?php 
    echo $tr;
    ?>
                 <?php 
    for ($i = 0; $i < 10; $i++) {
        ?>
 
                    <?php 
        echo '<td style="background-color:#' . randColor() . ';">' . randColor() . '<br /><span style="color:#ffffff;">' . randColor() . '</span></td>';
        ?>
                <?php 
    }
    ?>
                <?php 
    echo '</tr>';
    ?>
                <?php 
}
?>
            </tbody>
        
            
    </body>
</html>
Example #5
0
    $thumb = thumbnail($this, null, true);
    if ($thumb) {
        ?>
			<a href="<?php 
        $this->permalink();
        ?>
" class="post-thumb" style="background-image:url('<?php 
        echo $thumb;
        ?>
');"></a>
			<div class="post-body">
			<?php 
    } else {
        ?>
			<div class="post-body post-text" style="background-color:#<?php 
        echo randColor();
        ?>
">
			<?php 
    }
    ?>
				<div class="post-category"><?php 
    $this->category(',');
    ?>
</div>
				<h2 class="post-title" itemprop="name headline"><a itemtype="url" href="<?php 
    $this->permalink();
    ?>
"><?php 
    $this->title();
    ?>
Example #6
0
/**
 * 标签云
 * @params string 配置字符串
 * @format string 格式化输出
 * @return void
 */
function tagCloud($params = null, $format = '<a href="{permalink}" style="{fontsize};{color};" title="{count}篇文章">{name}</a>')
{
    Typecho_Widget::widget('Widget_Metas_Tag_Cloud', $params)->to($tags);
    $list = $counts = array();
    while ($tags->next()) {
        $list[] = array('mid' => $tags->mid, 'name' => $tags->name, 'permalink' => $tags->permalink, 'count' => $tags->count);
        $counts[] = $tags->count;
    }
    if (empty($counts)) {
        echo '暂无标签';
        return;
    }
    $min_count = min($counts);
    $spread = max($counts) - $min_count;
    $params = new Typecho_Config($params);
    $params->setDefault(array('smallest' => 8, 'largest' => 22, 'unit' => 'pt'));
    if ($spread <= 0) {
        $spread = 1;
    }
    $font_spread = $params->largest - $params->smallest;
    if ($font_spread < 0) {
        $font_spread = 1;
    }
    $font_step = $font_spread / $spread;
    $html = '';
    foreach ($list as $tag) {
        $color = 'color:#' . randColor();
        $fontsize = 'font-size:' . ($params->smallest + ($tag['count'] - $min_count) * $font_step) . $params->unit;
        $html .= str_replace(array('{name}', '{permalink}', '{count}', '{fontsize}', '{color}'), array($tag['name'], $tag['permalink'], $tag['count'], $fontsize, $color), $format);
    }
    echo $html;
}
Example #7
0
<?php

/**
 * Created by PhpStorm.
 * User: just
 * Date: 19.01.16
 * Time: 11:03
 */
function randColor()
{
    $red = dechex(rand(0, 255));
    $green = dechex(rand(0, 255));
    $blue = dechex(rand(0, 255));
    $color = '#' . $red . $green . $blue;
    return ['color' => $color];
}
$test = [randColor(), randColor(), randColor()];