示例#1
0
文件: bkm.php 项目: malkazwini/phurl
                    $create = true;
                }
            }
        }
        if ($create) {
            do {
                $code = generate_code(get_last_number());
                if (!increase_last_number()) {
                    die("System error!");
                }
                if (code_exists($code) || alias_exists($code)) {
                    continue;
                }
                break;
            } while (1);
            $id = insert_url($url, $code, $alias);
        }
        if (strlen($alias) > 0) {
            $code = $alias;
        }
        $short_url = SITE_URL . "/" . $code;
        $_GET['url'] = "";
        $_GET['alias'] = "";
        echo "{$short_url}";
        echo '" >';
        //exit();
    }
}
?>
<br/>
<a id="d_clip_button" href="#" >Copy</a>&nbsp;&nbsp;<a href="<?php 
示例#2
0
文件: api.php 项目: robertalks/buh.bz
        }
        insert_url($code, $url, $ip, $uuid);
    } else {
        $code = $codes[0]->code;
    }
} else {
    if (!empty($codes)) {
        if (in_array($code, $codes)) {
            goto out;
        }
    }
    if (code_exists($code)) {
        $error = ERR_ALIAS_ALREADY_EXISTS;
        goto out;
    }
    insert_url($code, $url, $ip, $uuid);
}
out:
switch ($request_type) {
    case 'ajax':
        header('Content-type: text/html; charset=utf-8');
        echo $error;
        if ($error == 0) {
            echo SITE_URL . '/' . $code;
        } else {
            echo $errors[$error];
        }
        break;
    case 'api':
        if ($format == 'json') {
            header('Content-Type: application/json');
示例#3
0
function insert_urls_from_pool($dbh, $network_id, $channel_id, $nick_id, $message, $urls)
{
    if (!$network_id) {
        return FALSE;
    }
    if (!$channel_id) {
        return FALSE;
    }
    if (!$nick_id) {
        return FALSE;
    }
    if (!$message) {
        return FALSE;
    }
    if (!$urls) {
        return FALSE;
    }
    if (!is_numeric($network_id)) {
        return FALSE;
    }
    if (!is_numeric($channel_id)) {
        return FALSE;
    }
    if (!is_numeric($nick_id)) {
        return FALSE;
    }
    $complete_urls = array();
    foreach ($urls as $url) {
        $url_id = get_url_id($dbh, $url);
        if ($url_id === FALSE) {
            continue;
        }
        // get information about the new url
        if (!$url_id) {
            echo "url={$url}\n";
            // information gathering...
            $http_meta = get_empty_http_meta();
            if (substr($url, 0, 5) == 'http:') {
                $http_meta = get_http_meta($url, 0);
                // todo: we could choose to skip the url and the message if the state is not 1 here
                //       or we record it (as we do now) and handle it someway later
            }
            // handle redirects
            // we store the original url but with the details of the destination
            // we will also keep a copy of the destination as a seperate record
            // we could probably handle this cleaner (e.g. redirecting url doesn't have text of destination), but maybe not much need
            $redirects_to_id = 0;
            if (array_key_exists('redirect', $http_meta) and array_key_exists('location', $http_meta)) {
                $redirects_to_url = $http_meta['location'];
                $redirects_to_id = get_url_id($dbh, $redirects_to_url);
                if ($redirects_to_id === FALSE) {
                    continue;
                }
                if (!$redirects_to_id) {
                    echo "Saving redirects_to record ";
                    $redirects_to_id = insert_url($dbh, $redirects_to_url, $http_meta['state'], $http_meta['content_length'], $http_meta['content_type'], 0, $http_meta['html_title']);
                    if ($redirects_to_id === FALSE) {
                        continue;
                    }
                    // todo: do we need to do this as well for redirects?
                    //$rv = insert_url_to_message($dbh, $dst_url_id, $message_id);
                    //if (!$rv) { continue; }
                }
            }
            // store the new url
            print_r($http_meta);
            $url_id = insert_url($dbh, $url, $http_meta['state'], $http_meta['content_length'], $http_meta['content_type'], $redirects_to_id, $http_meta['html_title']);
            if ($url_id === FALSE) {
                continue;
            }
        }
        $complete_urls[$url] = $url_id;
    }
    if (count($complete_urls) != count($urls)) {
        // one or more of the urls failed to insert
        // abandon this message
        echo "\n\n<strong>complete_urls != urls - this message will be ignored but some urls may already have been inserted</strong>\n\n";
        return 0;
    }
    $message = merge_url_ids_to_message($message, $complete_urls);
    // finally record the message
    $message_id = insert_message($dbh, $channel_id, $nick_id, $message);
    if (!$message_id) {
        return 0;
    }
    foreach ($complete_urls as $url_id) {
        #print "urlid=$url_id\n";
        $rv = insert_url_to_message($dbh, $url_id, $message_id);
        if (!$rv) {
            continue;
        }
    }
    if (count($complete_urls)) {
        return $message_id;
    } else {
        return 0;
    }
}