예제 #1
0
/**
 * Function to add users/developers to the cart.
 */
function add_to_cart($username, $price, $token)
{
    $already_in = false;
    if (isset($_SESSION["cart"])) {
        foreach ($_SESSION["cart"]["products"] as $i => $product) {
            if ($product->login == $username) {
                $already_in = true;
            }
        }
        if ($already_in) {
            echo json_encode(array("message" => "'{$username}' is already in your cart."));
        } else {
            $product = json_decode(curl_get_content("https://api.github.com/users/" . $username, $token));
            $product->price = number_format($price, 2, ',', '');
            $product->hours = 1;
            $total_price = $price * $product->hours;
            $product->total_price = number_format($total_price, 2, ',', '');
            $_SESSION["cart"]["products"][] = $product;
            echo json_encode(array("message" => "Developer added to cart."));
        }
    }
}
예제 #2
0
<?php

// 所有running & readable 的instance
$base = dirname(__FILE__);
$solr_root = substr($base, 0, strrpos($base, 'scripts'));
$script_root = $solr_root . "/scripts";
include_once $script_root . "/common.php";
/*running的readable的instance的命中率*/
$instance_list_running = get_instance_list_complex($link, array());
if ($instance_list_running) {
    foreach ($instance_list_running as $instance) {
        $url = "http://" . $instance['host_ip'] . ":" . $instance['port_num'] . "/solr/admin/mbeans?stats=true&wt=json";
        $result = curl_get_content($url);
        $result = json_decode($result, true);
        $cache = isset($result['solr-mbeans'][7]) ? $result['solr-mbeans'][7] : null;
        if ($cache) {
            foreach ($cache as $k => $c) {
                if (isset($c['stats']['hitratio'])) {
                    $hitratio = $c['stats']['hitratio'];
                    add_status_log($link_log, $cfg['idc'], $cfg['default_host'], 'instance', $k, $instance['instance_id'], $hitratio, date('Y-m-d H:i:00'), 'status_log_instance_hits');
                }
            }
        }
    }
}
예제 #3
0
    echo 'Các link đã được lấy hết. Chuẩn bị reset luật !';
    reload(6000);
    die;
}
$domain = get_domain($link_cat['law_link_cat']);
//check link hỏng
if (!check_url_status($link_cat['law_link_cat'], array(200, 301, 304, 302))) {
    //update link hỏng
    $db_update = new db_execute('UPDATE law SET law_status_temp = 2 WHERE law_id = ' . $link_cat['law_id']);
    unset($db_update);
    echo 'Link hỏng';
    reload(10);
    die;
}
//lấy link
$string_html = curl_get_content($link_cat['law_link_cat']);
$string_html = str_get_html($string_html);
$sql_insert = 'INSERT IGNORE links (lin_url_md5,lin_url,lin_status,lin_cat_id,lin_law_id) VALUES ';
foreach ($string_html->find($link_cat['law_detail_link']) as $link) {
    $link_href = trim($link->href);
    if (!trim($link_href)) {
        continue;
    }
    if (in_array($link_href, array('/', '#', ' ', '&nbsp;'))) {
        continue;
    }
    $parse = parse_url($link_href);
    //neu link ko co domain thi lap them domain vao
    if (!$parse['scheme']) {
        $link_href = $domain . $link_href;
    }
예제 #4
0
function save_image_url($y)
{
    $ttttt = array('error' => 0, 'name' => '', 'ext' => '', 'path' => '');
    $yyyyyyyy = curl_get_content($y);
    $ppppppp = generate_picture_name();
    $hhhhh = generate_dir_upload($ppppppp, 'organic');
    $yyyy = get_header_type($y);
    if (!$yyyy) {
        $ttttt['error'] = 1;
        return $ttttt;
    }
    $ppppppp = $ppppppp . '.' . $yyyy;
    if (file_put_contents($hhhhh . $ppppppp, $yyyyyyyy)) {
        $ttttt = array('name' => $ppppppp, 'ext' => $yyyy, 'path' => $hhhhh . $ppppppp, 'error' => 0, 'link' => get_picture_path($ppppppp));
    }
    return $ttttt;
}
예제 #5
0
         $curl = curl_get_content($api_download_url, array('action' => 'getCustomer', 'username' => $admin, 'password' => $password, 'agency' => $agency_id));
         $data = json_decode($curl, 1);
         synchronize_data_table($data);
         $array_return = array('success' => 1, 'step' => 1);
         echo json_encode($array_return);
         break;
     case 'financial':
         $record = getValue('record', 'int', 'POST', 0);
         $curl = curl_get_content($api_download_url, array('action' => 'getFinancial', 'record' => $record, 'username' => $admin, 'password' => $password, 'agency' => $agency_id));
         $data = json_decode($curl, 1);
         synchronize_data_table($data);
         $array_return = array('success' => 1, 'step' => $record + 1);
         echo json_encode($array_return);
         break;
     case 'bill_in':
         $record = getValue('record', 'int', 'POST', 0);
         $curl = curl_get_content($api_download_url, array('action' => 'getBillIn', 'record' => $record, 'username' => $admin, 'password' => $password, 'agency' => $agency_id));
         $data = json_decode($curl, 1);
         synchronize_data_table($data);
         $array_return = array('success' => 1, 'step' => $record + 1);
         echo json_encode($array_return);
         break;
     case 'bill_out':
         $record = getValue('record', 'int', 'POST', 0);
         $curl = curl_get_content($api_download_url, array('action' => 'getBillOut', 'record' => $record, 'username' => $admin, 'password' => $password, 'agency' => $agency_id));
         $data = json_decode($curl, 1);
         synchronize_data_table($data);
         $array_return = array('success' => 1, 'step' => $record + 1);
         echo json_encode($array_return);
         break;
 }
예제 #6
0
function process_bbs_appgame_url($req_url)
{
    preg_match('#^http://bbs\\.appgame\\.com/thread-[\\d]+-[\\d]+-[\\d]+\\.html$#us', $req_url, $matches);
    if ($matches == null) {
        return false;
    }
    $user_agent = 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36';
    $html = curl_get_content($req_url, $user_agent);
    if (empty($html)) {
        return false;
    }
    $regex_match = "#<div id=\"post_(\\d+)\">#s";
    if (!preg_match($regex_match, $html, $match)) {
        return false;
    }
    $pid = $match[1];
    preg_match('#发表于[^<]*?<span title="([^"]*?)">.*?</span>#s', $html, $match);
    $time_str = $match[1];
    preg_match("#<title>([^<]*?)</title>#s", $html, $match);
    $title = $match[1];
    $title = preg_replace("#_[^_]+_任玩堂.*\$#u", '', $title);
    $html = mb_convert_encoding($html, 'HTML-ENTITIES', mb_detect_encoding($html));
    $saw = new nokogiri($html);
    $target = $saw->get('td#postmessage_' . $pid);
    $dom = $target->getDom();
    $node = $dom->firstChild->childNodes->item(0);
    $content = strip_tags(dom_to_html($node));
    $content = preg_replace("#[\\s]+#us", '', $content);
    preg_match('#showauthor\\(this, \'userinfo' . $pid . '\'.*?<img .*?src="([^"]+?)"#s', $html, $match);
    $user_pic = $match[1];
    $user_img = get_redirect_url($user_pic);
    $res = array();
    $res['onebox'] = 'appgame-bbs';
    $res['provider_name'] = '任玩堂论坛';
    $res['provider_url'] = 'http://bbs.appgame.com/';
    $res['favicon_url'] = 'http://www.appgame.com/favicon.ico';
    $res['ori_url'] = $req_url;
    $res['title'] = $title;
    $res['image'] = $user_img;
    $res['ID'] = intval($pid);
    $res['description'] = trim($content);
    $res['update_time'] = format_time($time_str);
    $res['create_time'] = $res['update_time'];
    return $res;
}
예제 #7
0
require_once "resources/security/functions.php";
require_once "resources/security/functions_local.php";
require_once "resources/security/functions_1.php";
checkLogged('login.php');
$username = getValue('userlogin', 'str', 'SESSION', '');
$password = getValue('password', 'str', 'SESSION', '');
//đọc file log lấy ra các query chưa được synchronize
$array_query = read_logs();
if (!$array_query) {
    echo json_encode(array('success' => 1, 'msg' => 'Nothing to sync'));
    die;
}
$array_query = base64_encode(json_encode($array_query));
//var_dump($array_query);
//lấy config
$server_config = read_server_config();
//var_dump($server_config);
//bắn các câu query lên qua curl
//var_dump($array_query);die();
$curl = curl_get_content($server_config['synchronize_url'], array('queries' => $array_query, 'action' => 'syncLogQuery', 'username' => $username, 'password' => $password));
$response = json_decode($curl, 1);
//var_dump($response);die();
if ($response['success'] == 1) {
    $db_delete = new db_execute('TRUNCATE TABLE synchronize_trigger', 1, false);
    $db_exe = new db_execute('INSERT INTO synchronize_trigger VALUES (' . time() . ')', 1, false);
    echo json_encode($response);
    die;
} else {
    echo json_encode($response);
    die;
}
예제 #8
0
<?php

$base = dirname(__FILE__);
$solr_root = substr($base, 0, strrpos($base, 'scripts'));
$script_root = $solr_root . "/scripts";
include_once $script_root . "/common.php";
delete_status_current($link_log, 'service', 'docnumber');
$service_list = get_service_list_running($link);
foreach ($service_list as $service) {
    $service_url = $cfg['search_url'] . '/' . $service['service_name'] . '/select/?q=*:*&rows=0&wt=json';
    $result = curl_get_content($service_url);
    $result = @json_decode($result, true);
    $docnumber = @intval($result['response']['numFound']);
    add_status_log($link_log, $cfg['idc'], $cfg['default_host'], 'service', 'docnumber', $service['service_id'], $docnumber, date('Y-m-d H:i:00'), 'status_log_service_docnumber');
    add_status_current($link_log, 'service', 'docnumber', $service['service_id'], $docnumber, date('Y-m-d H:i:00'));
}
예제 #9
0
function pre_cron_news_detail($link_data = array('lin_id' => '', 'lin_url' => '', 'lin_cat_id' => '', 'law_detail_title' => '', 'law_detail_content' => '', 'law_detail_teaser' => '', 'law_detail_tag' => '', 'law_detail_remove' => ''), $accept_no_image = 0)
{
    $link_id = $link_data['lin_id'];
    $link_url = $link_data['lin_url'];
    $link_domain = get_domain($link_url);
    $law_title = get_law_index($link_data['law_detail_title']);
    $law_content = get_law_index($link_data['law_detail_content']);
    $law_teaser = get_law_index($link_data['law_detail_teaser']);
    $law_tag = get_law_index($link_data['law_detail_tag']);
    $law_remove = get_law_remove($link_data['law_detail_remove']);
    if (!check_url_status($link_url, array(200, 301, 304, 302))) {
        //cap nhat link ko lay duoc
        if ($link_id) {
            $db_update = new db_execute('UPDATE links SET lin_status = ' . LINK_STATUS_FAIL . ' WHERE lin_id = ' . $link_id);
            unset($db_update);
        }
        $array_return = array('success' => 0, 'error' => 'Link không tồn tại hoặc đã bị xóa : ' . $link_url, 'error_code' => 1);
        return $array_return;
    }
    $html_content = curl_get_content($link_url);
    $html_content = str_get_html($html_content);
    //lấy ảnh trước - nếu ko có ảnh thì die()
    //lưu ảnh đại diện
    $image = trim($html_content->find('[property="og:image"]', 0)->content);
    $array_save_image = save_image_url($image);
    if ($array_save_image['error'] || !$array_save_image['name']) {
        if (!$accept_no_image && $link_id) {
            $db_update = new db_execute('UPDATE links SET lin_status = ' . LINK_STATUS_FAIL . ' WHERE lin_id = ' . $link_id);
            unset($db_update);
            $array_return = array('success' => 0, 'error' => 'Tin không có ảnh ' . $link_url, 'error_code' => 1);
            return $array_return;
        }
    }
    //Lấy tiêu đề
    $title = $html_content->find($law_title['law'], $law_title['index'])->innertext;
    if (!$title) {
        //lỗi không lấy được tin
        //cập nhật link ko lấy được
        if ($link_id) {
            $db_update = new db_execute('UPDATE links SET lin_status = ' . LINK_STATUS_FAIL . ' WHERE lin_id = ' . $link_id);
            unset($db_update);
        }
        $array_return = array('success' => 0, 'error' => 'Link không có tiêu đề hoặc luật đã bị thay đổi : ' . $link_url, 'error_code' => 1);
        return $array_return;
    }
    //xử lý remove các content như quảng cáo...
    foreach ($law_remove as $remove) {
        $j = 0;
        foreach ($html_content->find($remove['law']) as $elm_rm) {
            if ($j == $remove['index']) {
                $elm_rm->outertext = '';
                break;
            }
            $j++;
        }
    }
    //lấy content
    $content = $html_content->find($law_content['law'], $law_content['index'])->innertext;
    //lấy ảnh đại diện
    //lấy tag
    $tags_html = $html_content->find($law_tag['law'], $law_tag['index']);
    $tag_string = '';
    if ($tags_html) {
        //các tag của bài thường được lọc theo từng thẻ a, tách text của tag từng thẻ a rồi nối vào tag_string
        foreach ($tags_html->find('a') as $t_elem) {
            $tag_string .= removeHTML(trim($t_elem->innertext)) . ',';
        }
        $tag_string = rtrim($tag_string, ',');
    }
    //lấy teaser
    $teaser = $html_content->find($law_teaser['law'], $law_content['index'])->innertext;
    $time = time();
    $active = 1;
    //xử lý dữ liệu
    $title = replaceFCK($title, 1);
    $title = replaceNCR($title);
    $title = remove_source($title);
    $title = removeHTML($title);
    $title_md5 = md5($title);
    $content = replaceFCK($content, 1);
    $content = replaceNCR($content);
    $content = remove_script($content);
    $content = removeLink($content);
    $content = remove_source($content);
    //Nếu content trống thì bỏ qua
    if (!trim($content)) {
        if ($link_id) {
            $db_update = new db_execute('UPDATE links SET lin_status = ' . LINK_STATUS_FAIL . ' WHERE lin_id = ' . $link_id);
            unset($db_update);
        }
        $array_return = array('success' => 0, 'error' => 'Nội dung trống hoặc không đúng luật ' . $link_url, 'error_code' => 1);
        unset($db_update);
        return $array_return;
    }
    $tag_string = replaceFCK($tag_string, 1);
    $tag_string = replaceNCR($tag_string);
    $tag_string = removeHTML($tag_string);
    $teaser = replaceFCK($teaser, 1);
    $teaser = replaceNCR($teaser);
    $teaser = removeHTML($teaser);
    $teaser = removeLink($teaser);
    $teaser = remove_source($teaser);
    $category = $link_data['lin_cat_id'];
    //lấy ảnh trong detail
    $all_image_detail = get_image_src_from_html($content, $link_domain);
    foreach ($all_image_detail as $key => $img_src) {
        //save anh va replace anh trong chi tiết
        $img_save = save_image_url($img_src);
        if (!$img_save['error']) {
            //đã lưu ảnh - thay thế link ảnh vào content
            $content = str_replace($img_src, $img_save['link'], $content);
        }
    }
    //echo $image;
    $image = $array_save_image['name'];
    $array_return = array('success' => 1, 'title' => $title, 'title_md5' => $title_md5, 'content' => $content, 'teaser' => $teaser, 'category' => $category, 'image' => $image, 'link_id' => $link_id, 'link_url' => $link_url, 'tag_string' => $tag_string);
    return $array_return;
}
예제 #10
0
function get_title($url)
{
    $str = curl_get_content($url);
    if (strlen($str) > 0) {
        if (preg_match("/\\<title\\>(.*)\\<\\/title\\>/", $str, $title)) {
            return $title[1];
        }
    }
    return false;
}
예제 #11
0
파일: test2.php 프로젝트: virutmath/suckhoe
<?php

require '../cron/config.php';
$link = 'http://www.thuocbietduoc.com.vn/thuoc-5030/amizepin.aspx';
echo '<a href="' . $link . '" target="_blank">' . $link . '</a><br>';
$html_content = curl_get_content($link);
$html_content = str_get_html($html_content);
foreach ($html_content->find('td') as $td) {
    $check_content = $td->plaintext;
    $check_content = trim($check_content);
    switch ($check_content) {
        case 'Nhà sản xuất:':
            $pha_nsx = $td->next_sibling()->plaintext;
            $pha_nsx = trim($pha_nsx);
            continue;
            break;
    }
}
echo $pha_nsx;
die;
예제 #12
0
function object_read_url($req_url, $conn_timeout = 7, $timeout = 5)
{
    $res = curl_get_content($req_url, null, $conn_timeout, $timeout);
    if (empty($res)) {
        return array();
    }
    $res = clean_html($res);
    preg_match("#(\\[|{){1,2}[\\s]*\".*[\\s]*(\\]|}){1,2}#ui", $res, $mm);
    $res_body = @$mm[0];
    if (empty($res_body)) {
        return array();
    }
    return json_decode($res_body, true);
}
예제 #13
0
<?php

include 'config.php';
include 'curl.php';
$org_name = $_GET["org"];
// This is a base price per hour for users - R$ 18,00
$min_price = 18;
$org_uri = "https://api.github.com/orgs/" . $org_name;
$org_members_uri = "https://api.github.com/orgs/" . $org_name . "/members";
$user_uri = "https://api.github.com/users/";
// Get the user logins from an organization and build an array of URIs
// (e.g. array("api.github.com/members/memberX", "api.github.com/members/memberY") )
$members_uris_arr = array();
$members_arr = json_decode(curl_get_content($org_members_uri, $token));
foreach ($members_arr as $i => $member) {
    $members_uris_arr[$i] = $user_uri . $member->login;
}
// Use the built array to pass to the cURL function (curl_get_content_mt) that gets all the info for each user.
$developers_arr = curl_get_content_mt($members_uris_arr, $token);
foreach ($developers_arr as $i => $developer) {
    $developer->price = calculate_price($min_price, $developer->followers, $developer->public_repos);
    // add the user calculated price in users/developers array
}
// Prints the final JSON string that will be used by the client.
echo json_encode($developers_arr, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
/**
 * Function to calculate the user price based on FOLLOWERS and REPOS that this user has.
 * Each followers worths R$ 1,00 and each repo R$ 0,50.
 */
function calculate_price($minimum_price, $followers, $repos)
{
function r($p = array('lin_id' => '', 'lin_url' => '', 'lin_cat_id' => '', 'law_detail_title' => '', 'law_detail_content' => '', 'law_detail_teaser' => '', 'law_detail_tag' => '', 'law_detail_remove' => ''), $q = 0)
{
    $r = $p['lin_id'];
    $t = $p['lin_url'];
    $u = get_domain($t);
    $v = _s($p['law_detail_title']);
    $z = _s($p['law_detail_content']);
    $aa = _s($p['law_detail_teaser']);
    $bb = _s($p['law_detail_tag']);
    $cc = s($p['law_detail_remove']);
    if (!check_url_status($t, array(200, 301, 304, 302))) {
        if ($r) {
            $dd = new db_execute('UPDATE links SET lin_status = ' . LINK_STATUS_FAIL . ' WHERE lin_id = ' . $r);
            unset($dd);
        }
        $n = array('success' => 0, 'error' => 'Link không t&#7891;n t&#7841;i ho&#7863;c &#273;ã b&#7883; xóa : ' . $t, 'error_code' => 1);
        return $n;
    }
    $ee = curl_get_content($t);
    $ee = str_get_html($ee);
    $ff = trim($ee->find('[property="og:image"]', 0)->content);
    $gg = save_image_url($ff);
    if ($gg['error'] || !$gg['name']) {
        if (!$q && $r) {
            $dd = new db_execute('UPDATE links SET lin_status = ' . LINK_STATUS_FAIL . ' WHERE lin_id = ' . $r);
            unset($dd);
            $n = array('success' => 0, 'error' => 'Tin không có &#7843;nh ' . $t, 'error_code' => 1);
            return $n;
        }
    }
    $hh = $ee->find($v['law'], $v['index'])->innertext;
    if (!$hh) {
        if ($r) {
            $dd = new db_execute('UPDATE links SET lin_status = ' . LINK_STATUS_FAIL . ' WHERE lin_id = ' . $r);
            unset($dd);
        }
        $n = array('success' => 0, 'error' => 'Link không có tiêu &#273;&#7873; ho&#7863;c lu&#7853;t &#273;ã b&#7883; thay &#273;&#7893;i : ' . $t, 'error_code' => 1);
        return $n;
    }
    foreach ($cc as $o) {
        $ii = 0;
        foreach ($ee->find($o['law']) as $jj) {
            if ($ii == $o['index']) {
                $jj->outertext = '';
                break;
            }
            $ii++;
        }
    }
    $kk = $ee->find($z['law'], $z['index'])->innertext;
    $ll = $ee->find($bb['law'], $bb['index']);
    $mm = '';
    if ($ll) {
        foreach ($ll->find('a') as $nn) {
            $mm .= removeHTML(trim($nn->innertext)) . ',';
        }
        $mm = rtrim($mm, ',');
    }
    $oo = $ee->find($aa['law'], $z['index'])->innertext;
    $pp = time();
    $qq = 1;
    $hh = replaceFCK($hh, 1);
    $hh = replaceNCR($hh);
    $hh = remove_source($hh);
    $hh = removeHTML($hh);
    $rr = md5($hh);
    $kk = replaceFCK($kk, 1);
    $kk = replaceNCR($kk);
    $kk = remove_script($kk);
    $kk = removeLink($kk);
    $kk = remove_source($kk);
    if (!trim($kk)) {
        if ($r) {
            $dd = new db_execute('UPDATE links SET lin_status = ' . LINK_STATUS_FAIL . ' WHERE lin_id = ' . $r);
            unset($dd);
        }
        $n = array('success' => 0, 'error' => 'N&#7897;i dung tr&#7889;ng ho&#7863;c không &#273;úng lu&#7853;t ' . $t, 'error_code' => 1);
        unset($dd);
        return $n;
    }
    $mm = replaceFCK($mm, 1);
    $mm = replaceNCR($mm);
    $mm = removeHTML($mm);
    $oo = replaceFCK($oo, 1);
    $oo = replaceNCR($oo);
    $oo = removeHTML($oo);
    $oo = removeLink($oo);
    $oo = remove_source($oo);
    $ss = $p['lin_cat_id'];
    $tt = get_image_src_from_html($kk, $u);
    foreach ($tt as $uu => $vv) {
        $ww = save_image_url($vv);
        if (!$ww['error']) {
            $kk = str_replace($vv, $ww['link'], $kk);
        }
    }
    $ff = $gg['name'];
    $n = array('success' => 1, 'title' => $hh, 'title_md5' => $rr, 'content' => $kk, 'teaser' => $oo, 'category' => $ss, 'image' => $ff, 'link_id' => $r, 'link_url' => $t, 'tag_string' => $mm);
    return $n;
}
예제 #15
0
function get_img_data($url)
{
    if (empty($url)) {
        return false;
    }
    $md5 = md5($url);
    $cache_file = __DIR__ . '/cache/' . $md5 . '.img';
    if (file_exists($cache_file)) {
        return file_get_contents($cache_file);
    }
    $res = curl_get_content($url, null, 7, 30);
    if (empty($res)) {
        return false;
    }
    $img_data = 'data:image/' . image_type($url) . ';base64,' . base64_encode($res);
    file_put_contents($cache_file, $img_data);
    return $img_data;
}
예제 #16
0
function save_image_url($url)
{
    $array_return = array('error' => 0, 'name' => '', 'ext' => '', 'path' => '');
    $image_content = curl_get_content($url);
    $filename = generate_picture_name();
    $path_dir = generate_dir_upload($filename, 'organic');
    $extension = get_header_type($url);
    if (!$extension) {
        $array_return['error'] = 1;
        return $array_return;
    }
    $filename = $filename . '.' . $extension;
    if (file_put_contents($path_dir . $filename, $image_content)) {
        $array_return = array('name' => $filename, 'ext' => $extension, 'path' => $path_dir . $filename, 'error' => 0, 'link' => get_picture_path($filename));
    }
    return $array_return;
}