예제 #1
0
파일: editcount.php 프로젝트: relrod/dagd
 public function render()
 {
     $query = $this->route_matches[1];
     // Default to english (en).
     $language = request_or_default('lang', 'en');
     if (!preg_match('@^[a-z]+$@i', $language)) {
         error400('`lang` should only contain letters.');
         return;
     }
     $wmprojects = array("wikipedia", "wiktionary", "wikisource", "wikiversity", "wikibooks", "wikiquote", "wikinews");
     // Default to wikipedia.org.
     $project = request_or_default('proj', 'wikipedia');
     if (!in_array($project, $wmprojects)) {
         error400('`proj` needs to be a valid Wikimedia project.');
         return;
     }
     if (!count(dns_get_record($language . '.' . $project . '.org'))) {
         error400($language . '.' . $project . '.org is not a valid wikipedia subdomain.');
         return;
     }
     $counts = file_get_contents('http://' . $language . '.' . $project . '.org/w/api.php?action=query&list=users' . '&usprop=editcount&format=json&ususers=' . urlencode($query));
     $json_counts = json_decode($counts, true);
     $json_counts = $json_counts['query']['users'];
     $total_edits = 0;
     foreach ($json_counts as $user) {
         $total_edits += (int) $user['editcount'];
     }
     return $total_edits;
 }
예제 #2
0
/** Get help for a given class. */
function help($class)
{
    $prefix = request_or_default('url_prefix', '/');
    $separator = request_or_default('url_separator', '/');
    $request_sep = request_or_default('url_request_sep', null);
    $return = '';
    $help_getter = new ReflectionClass($class);
    if ($help = $help_getter->getDefaultProperties()['__help__']) {
        $return .= '<h3>' . $help['summary'] . "</h3>\n";
        $return .= '<ul>';
        foreach ($help['examples'] as $example) {
            $return .= '<li>    ';
            if ($example['summary']) {
                $return .= $example['summary'] . ': ';
            }
            $return .= $prefix . $help['path'];
            if (array_key_exists('arguments', $example)) {
                $arguments = $example['arguments'];
                if ($arguments) {
                    if ($help['path']) {
                        $return .= $separator;
                    }
                    $return .= implode($separator, $arguments);
                }
            }
            if (array_key_exists('request', $example)) {
                $iteration = 0;
                foreach ($example['request'] as $param => $param_example) {
                    if ($request_sep) {
                        $return .= $iteration === 0 ? $request_sep : $request_sep;
                    } else {
                        $return .= $iteration === 0 ? '?' : '&';
                    }
                    $return .= $param . '=' . $param_example;
                    $iteration++;
                }
            }
            $return .= "</li>\n";
        }
        $return .= "</ul>\n";
    }
    return $return;
}
예제 #3
0
파일: image.php 프로젝트: relrod/dagd
 public function render()
 {
     $max_width = DaGdConfig::get('image.max_width');
     $max_height = DaGdConfig::get('image.max_height');
     $default_filetype = DaGdConfig::get('image.default_filetype');
     $imagetypes = DaGdConfig::get('image.imagetypes');
     $fontpath = DaGdConfig::get('image.fontpath');
     $bg_color_rgb = DaGdConfig::get('image.default_bg_rgb');
     $text_color_rgb = DaGdConfig::get('image.default_text_rgb');
     $split = preg_split('@(?:x|\\*)@', $this->route_matches[1]);
     if (count($split) !== 2) {
         error400('You must separate width and height with either * or x');
         return false;
     } else {
         $this->width = $split[0];
         $this->height = $split[1];
     }
     if ($this->width > $max_width || $this->height > $max_height) {
         error400('The generated image should be less than ' . $max_width . 'x' . $max_height . '.');
         return false;
     }
     if (count($this->route_matches) === 3) {
         if (in_array($this->route_matches[2], array_keys($imagetypes))) {
             $this->filetype = $this->route_matches[2];
         } else {
             error400('The image type you specified is not supported.');
             return false;
         }
     } else {
         $this->filetype = $default_filetype;
     }
     $r = $bg_color_rgb[0];
     $g = $bg_color_rgb[1];
     $b = $bg_color_rgb[2];
     if ($bgcolor = request_or_default('bgcolor')) {
         if (strlen($bgcolor) == 6) {
             $r = $bgcolor[0] . $bgcolor[1];
             $g = $bgcolor[2] . $bgcolor[3];
             $b = $bgcolor[4] . $bgcolor[5];
         } elseif (strlen($bgcolor) == 3) {
             $r = $bgcolor[0] . $bgcolor[0];
             $g = $bgcolor[1] . $bgcolor[1];
             $b = $bgcolor[2] . $bgcolor[2];
         }
     }
     $this->bgcolor = array(hexdec($r), hexdec($g), hexdec($b));
     $this->escape = false;
     $this->wrap_pre = false;
     $this->text_html_strip = false;
     $this->text_content_type = false;
     // Generate the image.
     header('Content-Type: ' . $imagetypes[$this->filetype]['contenttype']);
     $image = imagecreate($this->width, $this->height);
     imagecolorallocate($image, $this->bgcolor[0], $this->bgcolor[1], $this->bgcolor[2]);
     $text = request_or_default('text', $this->width . 'x' . $this->height);
     if ($text == 'off') {
         $text = '';
     }
     $positions = imagettfbbox(30, 0, $fontpath, $text);
     $center_x = ceil(($this->width - $positions[2]) / 2);
     $center_y = ceil(($this->height - $positions[5]) / 2);
     $color = imagecolorallocate($image, $text_color_rgb[0], $text_color_rgb[1], $text_color_rgb[2]);
     imagettftext($image, 30, 0, $center_x, $center_y, $color, $fontpath, $text);
     call_user_func($imagetypes[$this->filetype]['phpfunction'], $image);
     imagedestroy($image);
 }
예제 #4
0
파일: up.php 프로젝트: relrod/dagd
 public function render()
 {
     $up = new IsItUpQuery($this->route_matches[1]);
     $verbose = request_or_default('verbose', false, true, true);
     return $up->query($verbose);
 }
예제 #5
0
파일: shorten.php 프로젝트: relrod/dagd
 public function set_longurl_or_400()
 {
     if ($_REQUEST['url'] == '') {
         // If url was there but is an empty string, say so.
         error400('Error: Cannot create something out of nothing.');
         return false;
     }
     if ($long_url = request_or_default('url')) {
         // Something has at least been submitted. Is it valid?
         if (preg_match('@^https?://@', $long_url) && !$this->blacklisted($long_url)) {
             // Good enough for now...probably needs some better checks.
             $this->long_url = $long_url;
             return true;
         } else {
             error400('Malformed or blacklisted original URL. Try again (http or https ' . 'protocols only, please.).');
             return false;
         }
     } else {
         return false;
     }
 }