<commit_before><?php
/* 
 * justask
 * © 2013 nilsding
 * License: AGPLv3, read the LICENSE file for the license text.
 */

include_once('fixDir.php');

session_start();

if (file_exists('config.php')) {
  require_once('config.php');
} else {
  header('Location: install.php');
  exit();
}

if (!isset($_SESSION['logged_in'])) { 
  header('Location: ucp.php');
  exit();
}
else if ($_SESSION['logged_in'] !== true) { 
  header('Location: ucp.php');
  exit();
}

if (!isset($_POST['action']) || !isset($_POST['question_id'])) {
  echo "Listen. <br />\n";
  echo "I hate you.";
  exit();
}

$action = $_POST['action'];
$question_id = $_POST['question_id'];

if (!is_numeric($question_id)) {
  echo "?SYNTAX ERROR";
  exit();
}

function generate_tweet_text(MySQLi $sql, $MYSQL_TABLE_PREFIX) {
  $sql_str = "SELECT * FROM `" . $MYSQL_TABLE_PREFIX . "answers` ORDER BY `answer_id` DESC LIMIT 1"; /* we need the latest answer here... */
  $res = $sql->query($sql_str);
  $res = $res->fetch_assoc();
  $answer_id = $res['answer_id'];
  $question_content = $res['question_content'];
  $answer = $res['answer_text'];
  $url = 'http';
  if ($_SERVER["HTTPS"] == "on") {
    $url .= "s";
  }
  $url .= "://";
  if ($_SERVER["SERVER_PORT"] != "80") {
    $url .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
  } else {
    $url .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
  }
  $url = substr($url, 0, (strlen($url) - strlen($_SERVER['SCRIPT_NAME'])));
  $url .= fixDir();
  $url .= "/view_answer.php?id=" . $answer_id;
  if (strlen($question_content) > 56) {
    $question_content = substr($question_content, 0, 55) . '…'; 
  }
  if (strlen($answer) > 56) {
    $answer = substr($answer, 0, 55) . '…'; 
  }
  return $question_content . " — " . $answer . ' · ' . $url;
}

$sql = mysqli_connect($MYSQL_SERVER, $MYSQL_USER, $MYSQL_PASS, $MYSQL_DATABASE);

$res = $sql->query('SELECT `config_value` FROM `' . $MYSQL_TABLE_PREFIX . 'config` WHERE `config_id`=\'cfg_twitter\'');
$res = $res->fetch_assoc();
$twitter_on = ($res['config_value'] === "true" ? true : false);

if ($twitter_on) {
  include_once 'include/oauth/twitteroauth.php';
  $res = $sql->query('SELECT `config_value` FROM `' . $MYSQL_TABLE_PREFIX . 'config` WHERE `config_id`=\'cfg_twitter_ck\'');<commit_msg>The link to the answer<commit_after><?php
/* 
 * justask
 * © 2013 nilsding
 * License: AGPLv3, read the LICENSE file for the license text.
 */

include_once('fixDir.php');

session_start();

if (file_exists('config.php')) {
  require_once('config.php');
} else {
  header('Location: install.php');
  exit();
}

if (!isset($_SESSION['logged_in'])) { 
  header('Location: ucp.php');
  exit();
}
else if ($_SESSION['logged_in'] !== true) { 
  header('Location: ucp.php');
  exit();
}

if (!isset($_POST['action']) || !isset($_POST['question_id'])) {
  echo "Listen. <br />\n";
  echo "I hate you.";
  exit();
}

$action = $_POST['action'];
$question_id = $_POST['question_id'];

if (!is_numeric($question_id)) {
  echo "?SYNTAX ERROR";
  exit();
}

function generate_tweet_text(MySQLi $sql, $MYSQL_TABLE_PREFIX) {
  $sql_str = "SELECT * FROM `" . $MYSQL_TABLE_PREFIX . "answers` ORDER BY `answer_id` DESC LIMIT 1"; /* we need the latest answer here... */
  $res = $sql->query($sql_str);
  $res = $res->fetch_assoc();
  $answer_id = $res['answer_id'];
  $question_content = $res['question_content'];
  $answer = $res['answer_text'];
  $url = 'http';
  if ($_SERVER["HTTPS"] == "on") {
    $url .= "s";
  }
  $url .= "://";
  if ($_SERVER["SERVER_PORT"] != "80") {
    $url .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
  } else {
    $url .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
  }
  $url = substr($url, 0, (strlen($url) - strlen($_SERVER['SCRIPT_NAME'])));
  $url .= fixDir();
  $url .= "view_answer.php?id=" . $answer_id;
  if (strlen($question_content) > 56) {
    $question_content = substr($question_content, 0, 55) . '…'; 
  }
  if (strlen($answer) > 56) {
    $answer = substr($answer, 0, 55) . '…'; 
  }
  return $question_content . " — " . $answer . ' · ' . $url;
}

$sql = mysqli_connect($MYSQL_SERVER, $MYSQL_USER, $MYSQL_PASS, $MYSQL_DATABASE);

$res = $sql->query('SELECT `config_value` FROM `' . $MYSQL_TABLE_PREFIX . 'config` WHERE `config_id`=\'cfg_twitter\'');
$res = $res->fetch_assoc();
$twitter_on = ($res['config_value'] === "true" ? true : false);

if ($twitter_on) {
  include_once 'include/oauth/twitteroauth.php';
  $res = $sql->query('SELECT `config_value` FROM `' . $MYSQL_TABLE_PREFIX . 'config` WHERE `config_id`=\'cfg_twitter_ck\'');
{'fraction_non_alphanumeric': 0.22297003907946158, 'fraction_numerical': 0.008250108554059922, 'mean_word_length': 4.42, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1712427', 'n_tokens_mistral': 1763, 'n_tokens_neox': 1734, 'n_words': 341}