Example #1
0
function do_fetch($formatter, $params = array())
{
    global $Config;
    $value = $params['value'];
    $url = !empty($params['url']) ? $params['url'] : $value;
    if (!empty($Config['fetch_ignore_re']) and preg_match('/' . $Config['fetch_ignore_re'] . '/i', $url)) {
        $redirect_url = true;
    }
    if (!empty($Config['fetch_url_re']) and !preg_match('/' . $Config['fetch_url_re'] . '/i', $url)) {
        $redirect_url = true;
    }
    if (isset($redirect_url)) {
        $formatter->send_header(array("Status: 302", "Location: " . $url));
        return;
    }
    $ret = array();
    $params['retval'] =& $ret;
    $params['call'] = true;
    if ($formatter->refresh) {
        $params['refresh'] = 1;
    }
    macro_Fetch($formatter, $url, $params);
    if (!empty($ret['error'])) {
        if (!empty($ret['mimetype']) and preg_match('/^image\\//', $ret['mimetype'])) {
            $is_image = true;
        } else {
            $is_image = preg_match('/\\.(png|jpe?g|gif)(&|\\?)?/i', $url);
        }
        if ($is_image) {
            require_once dirname(__FILE__) . '/../lib/mediautils.php';
            $font_face = !empty($Config['fetch_font']) ? $Config['fetch_font'] : '';
            $font_size = !empty($Config['fetch_font_size']) ? $Config['fetch_font_size'] : 2;
            $str = 'ERROR: ' . $ret['error'];
            $im = image_msg($font_size, $font_face, $str);
            if (function_exists("imagepng")) {
                header("Content-Type: image/png");
                imagepng($im);
            } else {
                if (function_exists("imagegif")) {
                    header("Content-Type: image/gif");
                    imagegif($im);
                } else {
                    if (function_exists("imagejpeg")) {
                        $jpeg_quality = 5;
                        header("Content-Type: image/jpeg");
                        imagejpeg($im, null, $jpeg_quality);
                    }
                }
            }
            ImageDestroy($im);
            return;
        }
    }
    echo $ret['error'];
}
Example #2
0
function do_fetch($formatter, $params = array())
{
    global $Config;
    // $formatter->refresh = 1;
    $value = $params['value'];
    $url = !empty($params['url']) ? $params['url'] : $value;
    if (!empty($Config['fetch_ignore_re']) and preg_match('/' . $Config['fetch_ignore_re'] . '/i', $url)) {
        $redirect_url = true;
    }
    if (!empty($Config['fetch_url_re']) and !preg_match('/' . $Config['fetch_url_re'] . '/i', $url)) {
        $redirect_url = true;
    }
    if (isset($redirect_url)) {
        $formatter->send_header(array("Status: 301", "Location: " . $url));
        return;
    }
    $ret = array();
    $params['retval'] =& $ret;
    $params['call'] = true;
    if ($formatter->refresh) {
        $params['refresh'] = 1;
    } else {
        if (!empty($params['apikey']) and !empty($Config['apikey']) and $Config['apikey'] == $params['apikey']) {
            $params['refresh'] = 1;
        }
    }
    if (!empty($params['refresh'])) {
        if (empty($_SERVER['HTTP_REFERER']) and !empty($params['refresh'])) {
            $params['.localrefresh'] = 1;
        } else {
            if (strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST']) !== false) {
                $params['.localrefresh'] = 1;
            }
        }
    }
    macro_Fetch($formatter, $url, $params);
    if (!empty($ret['error'])) {
        if (!empty($ret['mimetype']) and preg_match('/^image\\//', $ret['mimetype'])) {
            $is_image = true;
        } else {
            $is_image = preg_match('/\\.(png|jpe?g|gif)(&|\\?)?/i', $url);
        }
        if ($is_image and !empty($_SERVER['HTTP_REFERER'])) {
            require_once dirname(__FILE__) . '/../lib/mediautils.php';
            $formatter->header('Status: 500');
            $font_face = !empty($Config['fetch_font']) ? $Config['fetch_font'] : '';
            $font_size = !empty($Config['fetch_font_size']) ? $Config['fetch_font_size'] : 2;
            $str = 'ERROR: ' . $ret['error'];
            $im = image_msg($font_size, $font_face, $str);
            if (function_exists("imagepng")) {
                header("Content-Type: image/png");
                imagepng($im);
            } else {
                if (function_exists("imagegif")) {
                    header("Content-Type: image/gif");
                    imagegif($im);
                } else {
                    if (function_exists("imagejpeg")) {
                        $jpeg_quality = 5;
                        header("Content-Type: image/jpeg");
                        imagejpeg($im, null, $jpeg_quality);
                    }
                }
            }
            ImageDestroy($im);
            return;
        }
        $formatter->header('Status: 500');
        echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">';
        echo '<html><head><title>' . $Config['sitename'] . '</title>';
        echo "<meta name='viewport' content='width=device-width' />";
        echo '</head><body>';
        echo '<h1>500 Internal Server Error</h1>';
        echo '<div><a href="' . $url . '">Original source</a> : ';
        echo $url, '</div>';
        echo '<h2>Error Message</h2>';
        echo '<pre>', $ret['error'] . '</pre>';
        echo '<hr>';
        echo '<div>', 'You can <a href="?action=fetch&amp;refresh=1&amp;url=' . $url . '">refresh</a>';
        echo ' this URL manually</div>';
        echo '</body></html>';
        return;
    }
}
Example #3
0
function do_avatar($formatter, $params = array())
{
    global $DBInfo;
    $is_anonymous = empty($params['user']) || strtolower($params['user']) == 'anonymous';
    if (empty($DBInfo->use_avatar) && $is_anonymous) {
        // 43byte 1x1 transparent gif
        // http://stackoverflow.com/questions/2933251/code-golf-1x1-black-pixel
        // http://www.perlmonks.org/?node_id=7974
        $maxage = 60 * 60 * 24;
        $gif = base64_decode('R0lGODlhAQABAJAAAAAAAAAAACH5BAUQAAAALAAAAAABAAEAAAICBAEAOw');
        Header("Content-type: image/gif");
        Header("Content-length: " . strlen($gif));
        Header("Cache-Control: public, max-age=" . $maxage . ", length: " . strlen($gif));
        header('Connection: Close');
        echo $gif;
        flush();
        return;
    }
    if (is_int($DBInfo->use_avatar) || $DBInfo->use_avatar == 'avatar') {
        $avatar = 'identicon';
    } else {
        $avatar = $DBInfo->use_avatar;
    }
    $udb =& $DBInfo->udb;
    if (!$is_anonymous) {
        $user = $udb->getUser($params['user']);
        if ($user->id == 'Anonymous') {
            $is_anonymous = true;
        }
        if (!$is_anonymous) {
            if (!empty($user->info['avatar']) && strtolower($user->info['avatar']) != 'avatar') {
                $avatar = $user->info['avatar'];
            }
        }
    }
    if (!preg_match('@^https?://@', $avatar)) {
        require_once dirname(__FILE__) . '/' . $avatar . '.php';
        $act = 'do_' . $avatar;
        $act($formatter, $params);
        return;
    }
    require_once dirname(__FILE__) . '/fetch.php';
    $url = $avatar;
    $ret = array();
    $params['retval'] =& $ret;
    $params['call'] = true;
    $params['images_only'] = true;
    if ($formatter->refresh) {
        $params['refresh'] = 1;
    }
    macro_Fetch($formatter, $url, $params);
    $is_image = preg_match('/\\.(png|jpe?g|gif)(&|\\?)?/i', $url);
    if (!$is_image || !empty($ret['error'])) {
        if (!empty($ret['mimetype']) and preg_match('/^image\\//', $ret['mimetype'])) {
            $is_image = true;
        }
        if (!empty($ret['error']) && $is_image) {
            require_once dirname(__FILE__) . '/../lib/mediautils.php';
            $font_face = !empty($Config['fetch_font']) ? $Config['fetch_font'] : '';
            $font_size = !empty($Config['fetch_font_size']) ? $Config['fetch_font_size'] : 2;
            $str = 'ERROR: ' . $ret['error'];
            $im = image_msg($font_size, $font_face, $str);
            if (function_exists("imagepng")) {
                header("Content-Type: image/png");
                imagepng($im);
            } else {
                if (function_exists("imagegif")) {
                    header("Content-Type: image/gif");
                    imagegif($im);
                } else {
                    if (function_exists("imagejpeg")) {
                        $jpeg_quality = 5;
                        header("Content-Type: image/jpeg");
                        imagejpeg($im, null, $jpeg_quality);
                    }
                }
            }
            ImageDestroy($im);
            return;
        }
    }
    echo $ret['error'];
    return;
}