Actyal reply publishing on twitter
This commit is contained in:
parent
d01c1d6f5d
commit
ceff58103d
2
TODO.md
2
TODO.md
|
@ -8,6 +8,7 @@
|
||||||
- Individual reply pages
|
- Individual reply pages
|
||||||
- ~~Twitter login~~
|
- ~~Twitter login~~
|
||||||
- Twitter post publication
|
- Twitter post publication
|
||||||
|
- Toggle Twitter posting
|
||||||
- Mastodon login
|
- Mastodon login
|
||||||
- Add various language support.
|
- Add various language support.
|
||||||
|
|
||||||
|
@ -19,6 +20,7 @@
|
||||||
- Styling:
|
- Styling:
|
||||||
- Basic theme styling
|
- Basic theme styling
|
||||||
- Relative time
|
- Relative time
|
||||||
|
- Single line long phrases break the page
|
||||||
|
|
||||||
- Bugs:
|
- Bugs:
|
||||||
- ~~Login redirection is broken~~
|
- ~~Login redirection is broken~~
|
||||||
|
|
|
@ -28,6 +28,46 @@ else{
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$db->exec("UPDATE questions SET answer = '" . htmlspecialchars($_POST["answer_body"], ENT_QUOTES) . "', a_date = " . strtotime("now") . " WHERE id = " . $_GET["q"] . ";");
|
$db->exec("UPDATE questions SET answer = '" . htmlspecialchars($_POST["answer_body"], ENT_QUOTES) . "', a_date = " . strtotime("now") . " WHERE id = " . $_GET["q"] . ";");
|
||||||
|
|
||||||
|
$question = $db->query("SELECT * FROM questions WHERE id = '" . $_GET["q"] . "';")->fetchArray(SQLITE3_ASSOC);
|
||||||
|
$user = $db->query("SELECT * FROM users WHERE id = '" . $_SESSION["uid"] . "';")->fetchArray(SQLITE3_ASSOC);
|
||||||
|
|
||||||
|
// Writing the tweet text
|
||||||
|
|
||||||
|
$separator = " - ";
|
||||||
|
$tw_url_length = 23;
|
||||||
|
$max_length = 280 - strlen($separator) - strlen(" ") - $tw_url_length;
|
||||||
|
$ellipsis = "...";
|
||||||
|
|
||||||
|
if(strlen($question["question"]) >= $max_length/2 - strlen($separator)){
|
||||||
|
if(strlen($question["answer"]) >= $max_length/2 - strlen($separator)){
|
||||||
|
$tweet = substr($question["question"],0,$max_length/2 - strlen($ellipsis)) . $ellipsis;
|
||||||
|
$tweet = $tweet . $separator . substr($question["answer"],0,$max_length/2 - strlen($ellipsis)) . $ellipsis;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$tweet = substr($question["question"],0,$max_length - strlen($question["answer"]) - strlen($ellipsis)) . $ellipsis;
|
||||||
|
$tweet = $tweet . $separator . $question["answer"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if(strlen($question["answer"]) >= $max_length/2 - strlen($separator)){
|
||||||
|
$tweet = $question["question"] . $separator;
|
||||||
|
$tweet = $tweet . substr($question["answer"],0,$max_length - strlen($question["question"]) - strlen($ellipsis)) . $ellipsis;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$tweet = $question["question"] . $separator . $question["answer"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$tweet = $tweet . " https://ask.fai.su/user/" . $user["username"];
|
||||||
|
|
||||||
|
// echo strlen($tweet) . " - " . strlen($question["answer"]) . "<br/><br/>\n";
|
||||||
|
// echo $tweet;
|
||||||
|
|
||||||
|
if($user["tw_oauth_token"] && $user["tw_oauth_verify"]){
|
||||||
|
include("../include/tw-post.php");
|
||||||
|
post_tweet(htmlspecialchars_decode($tweet, ENT_QUOTES));
|
||||||
|
}
|
||||||
|
|
||||||
if($pretty_urls){
|
if($pretty_urls){
|
||||||
header("Location: /user/" . $db->querySingle("SELECT username FROM users WHERE id = " . $question["user"] . ";"));
|
header("Location: /user/" . $db->querySingle("SELECT username FROM users WHERE id = " . $question["user"] . ";"));
|
||||||
die();
|
die();
|
||||||
|
@ -48,6 +88,8 @@ else{
|
||||||
<?php include("../themes/$theme_name/reply.php"); ?>
|
<?php include("../themes/$theme_name/reply.php"); ?>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<?php
|
||||||
|
?>
|
||||||
<div class="main-container">
|
<div class="main-container">
|
||||||
<h3 class="question"><?= $question["question"] ?></h3>
|
<h3 class="question"><?= $question["question"] ?></h3>
|
||||||
<form action="" method="post">
|
<form action="" method="post">
|
||||||
|
|
Loading…
Reference in New Issue