Пример #1
0
         foreach ($checker as $key => $value) {
             $quest_id = str_replace("scenarquest", "", $key);
             $val = substr($value, 10);
             $twoinone = preg_split("/[\\s|]+/", $quest_id);
             $rr = mysql_fetch_array(mysql_query("  SELECT id\r\n                                                        FROM `scenario_destination`\r\n                                                        WHERE scenario_detail_id  = {$twoinone['1']} AND answer_id = {$twoinone['2']}"));
             if ($rr[0] == '') {
                 mysql_query("INSERT INTO `scenario_destination`\r\n                                 (`scenario_detail_id`, `destination`, `answer_id`)\r\n                                 VALUES\r\n                                 ( '{$twoinone['1']}', '{$val}', '{$twoinone['2']}');");
             } else {
                 mysql_query("  UPDATE `scenario_destination`\r\n                                    SET `destination`={$val}\r\n                                    WHERE `id`={$rr['0']}");
             }
         }
     }
     break;
 case 'save_answer':
     if ($_REQUEST['quest_detail_id'] == '') {
         save_answer($user_id, $quest_id1, $add_id);
     } else {
         update_answer($quest_detail_id, $quest_id1, $quest_id);
     }
     break;
 case 'disable':
     if ($quest_detail_id != '') {
         disable_det($quest_detail_id);
     } else {
         disable($quest_id);
     }
     break;
 case 'get_scen_cat':
     $data['cat'] = GetLeCat($_REQUEST['cat_id'], '');
     break;
 default:
Пример #2
0
                 $row[] = '<input type="checkbox" name="check_' . $aRow[$hidden] . '" class="check" value="' . $aRow[$hidden] . '" />';
             }
         }
         $data['aaData'][] = $row;
     }
     break;
 case 'save_quest':
     if ($quest_id == '') {
         save($user_id, $name, $note);
     } else {
         update($quest_id, $name, $note);
     }
     break;
 case 'save_answer':
     if ($quest_detail_id == '') {
         save_answer($user_id, $answer, $quest_type_id, $add_id, $hidden_product_id);
     } else {
         update_answer($quest_detail_id, $answer, $quest_type_id, $quest_id, $hidden_product_id);
     }
     break;
 case 'disable':
     if ($quest_detail_id != '') {
         disable_det($quest_detail_id);
     } else {
         disable($quest_id);
     }
     break;
 case 'get_product_info':
     $name = $_REQUEST[name];
     $res = GetProductInfo($name);
     if (!$res) {
Пример #3
0
<?php

require dirname(__DIR__) . "/vendor/autoload.php";
require __DIR__ . "/odie.php";
require __DIR__ . "/logic.php";
$username = '******';
if (isset($argv[1])) {
    $username = $argv[1];
}
$base_url = 'http://www.zhihu.com';
$url = "{$base_url}/people/{$username}/answers";
echo "fetch {$username}\n";
list($code, $content) = odie_get($url);
if ($code == 404) {
    echo "没有这个用户 {$username}\n";
    exit(1);
}
$link_list = get_answer_link_list($content);
save_answer($base_url, $username, $link_list);
$num = get_page_num($content);
if ($num > 1) {
    foreach (range(2, $num) as $i) {
        echo "fetch page {$i}\n";
        $url_page = "{$url}?page={$i}";
        list($_, $content) = odie_get($url_page);
        $link_list = get_answer_link_list($content);
        save_answer($base_url, $username, $link_list);
    }
}
Пример #4
0
<?php

// only logged in users can add blog posts
// gatekeeper
$question_id = get_input('question_id');
$endpoint = 'http://api.stackoverflow.com/1.1/questions/' . $question_id . '?type=jsontext&body=true&answers=true&comments=true';
$response = json_decode(http_inflate(file_get_contents($endpoint)));
$questions = $response->questions[0];
$question_title = $questions->title;
$question_body = add_link_to_original($questions->body, $question_id);
$answers = $questions->answers;
$elgg_question = save_question($question_title, $question_body);
foreach ($answers as $answer) {
    $answer_body = $answer->body;
    $elgg_answer = save_answer($elgg_question, $answer_body);
    $comments = $answer->comments;
    foreach ($comments as $comment) {
        $comment = $comment->body;
        save_comment($elgg_answer, $comment);
    }
}
echo json_encode(array('success' => true));
die;
function add_link_to_original($body, $question_id)
{
    $url = 'http://www.stackoverflow.com/questions/' . $question_id;
    $message = "<div style='border:2px solid green;'>See the original question at <a href='{$url}'>Stackoverflow</a></div>";
    return "{$message}{$body}";
}
function save_answer($elgg_question, $answer_body)
{