Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
close #55; use modern tt-rss DB interface (also makes it possible to …
…use driveby-sharing with Postgres I believe), bumping required version of tt-rss to 1.7.9
  • Loading branch information
nhoening committed Jun 29, 2013
1 parent 0a5d6e0 commit dab82f2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 47 deletions.
9 changes: 5 additions & 4 deletions driveby-sharing/README.md
@@ -1,15 +1,16 @@
# A Drive-by sharing widget (share any web page in your tt-rss)

[Requirement: tt-rss version >= 1.7.9]

1. Make sure a dedicated feed exists in your tt-rss<br/>
You can insert it via executing the SQL in the file `create-gritttt-feed`, which you can find in the main directory. After creating the dedicated feed, look up the table `ttrss_feeds` and take note of the feed's ID.
You can insert it via executing the SQL in the file `create-gritttt-feed`, which you can find in the main directory. After creating the dedicated feed, look up the table `ttrss_feeds` and take note of the ID of the newly-created feed.

2. Create a configuration file `config.js` as a copy of `config.js.template`.
Enter your settings in `config.js`:<br/>
As `gritttt_url`, set the URL at which you will put the `driveby-sharing` folder later (see step 5).<br/>
As `path_to_ttrss`, set the relative path from `gritttt_url` to the folder containing your tt-rss instance.<br/>
The feed ID (`feed_id`) is the ID of the feed you created in step 1. For `user_id`, the user is the tt-rss user, and his ID is most likely `1`, if you log in with the user `admin`.
That is the standard case - if you run a multi-user tt-rss, fill in the ID you want to use in that context of sharing.<br/>
Change the next setting to `false` if your tt-rss instance has a version lower than `1.5.10.` (you can see the version on the login screen).
That is the standard case - if you run a multi-user tt-rss, fill in the ID you want to use in that context of sharing.

3. Adjust the URL at which the `driveby-sharing` folder will be in `bookmarklet.js`:<br/>
Replace `http://www.example.com/gritttt/driveby-sharing` with whereever you put that folder later, in step 5 (you also edited this in `config.js` in step 2).
Expand All @@ -19,4 +20,4 @@
5. Put this directory on your webserver, according to the settings you made in step 2 and 3. The example made a folder called `gritttt`,
and put the `driveby-sharing` folder in there (the `gritttt` folder is also useful to put the `shared-widget` folder in there, should you use that feature).

6. Share!
6. Start sharing - on any website, click the bookmarklet, fill in title and possibly a note and hit `Share`!
1 change: 0 additions & 1 deletion driveby-sharing/config.js.template
Expand Up @@ -3,5 +3,4 @@ var config = {
"path_to_ttrss": "../../tt-rss",
"feed_id": 183,
"user_id": 1,
"ttrss_version_above_1.5.10": true
};
17 changes: 4 additions & 13 deletions driveby-sharing/form.php
Expand Up @@ -10,21 +10,12 @@
$config = json_decode('{' . $matches[1], true);
$gritttt_url = $config['gritttt_url'];
$path_to_ttrss = $config['path_to_ttrss'];
$ttrss_above_1510 = $config['ttrss_version_above_1.5.10'];

if ($ttrss_above_1510) {
set_include_path(get_include_path() . PATH_SEPARATOR . $path_to_ttrss);
require_once($path_to_ttrss . "/include/functions.php");
require_once($path_to_ttrss . "/include/sessions.php");
} else {
require_once($path_to_ttrss . "/functions.php");
require_once($path_to_ttrss . "/sessions.php");
}
set_include_path(get_include_path() . PATH_SEPARATOR . $path_to_ttrss);
require_once($path_to_ttrss . "/classes/idb.php");
require_once($path_to_ttrss . "/include/sessions.php");

ini_set('default_charset', 'utf-8');

$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
init_connection($link);
?>

<html>
Expand All @@ -49,7 +40,7 @@ function getParameterByName(name)

<?
// Logged in?
if ($_SESSION["uid"] && validate_session($link)) {
if ($_SESSION["uid"] && validate_session()) {
?>
<!-- Show form -->
<form id="gritttt-form" method="post" action="">
Expand Down
46 changes: 17 additions & 29 deletions driveby-sharing/share.php
Expand Up @@ -11,43 +11,31 @@
$feed_id = $config['feed_id'];
$user_id = $config['user_id'];
$path_to_ttrss = $config['path_to_ttrss'];
$ttrss_above_1510 = $config['ttrss_version_above_1.5.10'];

header('Content-Type: text/html; charset=utf-8');
if ($ttrss_above_1510) {
set_include_path(get_include_path() . PATH_SEPARATOR . $path_to_ttrss);
require_once($path_to_ttrss . "/include/functions.php");
require_once($path_to_ttrss . "/include/sessions.php");
} else {
require_once($path_to_ttrss . "/functions.php");
require_once($path_to_ttrss . "/sessions.php");
}

$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
init_connection($link);

if (1 == 1) { // if mysql
mysql_set_charset('utf8', $link);
}
set_include_path(get_include_path() . PATH_SEPARATOR . $path_to_ttrss);
require_once($path_to_ttrss . "/classes/idb.php");
require_once($path_to_ttrss . "/include/sessions.php");

$MSG = 'success';

if ($_SESSION["uid"] && validate_session($link)) {
if ($_SESSION["uid"] && validate_session()) {
try{
$t = mysql_real_escape_string($_POST['gritttt-title']);
$url = mysql_real_escape_string($_POST['gritttt-url']);
$t = Db::get()->escape_string($_POST['gritttt-title']);
$url = Db::get()->escape_string($_POST['gritttt-url']);
$uid = $url.',imported:'.time();
$c = mysql_real_escape_string($_POST['gritttt-comment']);
// Make new entry in ttrss_entries, set (title, link, content) from request, Remember new-id
db_query($link, "INSERT into ttrss_entries (title, link, guid, date_entered, date_updated, updated) VALUES ('$t', '$url', '$uid', NOW(), NOW(), NOW());");
if (1 == 1) {
$last_id = mysql_insert_id();
} else {
// TODO: find ttrss_entry id for non-MySQL DBs (e.g. postgres)
}
// Make new entry in ttrss_user_entries
db_query($link, "INSERT into ttrss_user_entries (ref_id, feed_id, owner_uid, note, published, unread) VALUES ($last_id, $feed_id, $user_id, '$c', 1, 0);");
db_query($link, "UPDATE ttrss_feeds SET last_updated = NOW() WHERE id = $feed_id;");
$c = Db::get()->escape_string($_POST['gritttt-comment']);
// 1. Make new entry in ttrss_entries, set (title, link, content) from request, Remember new-id
Db::get()->query("INSERT into ttrss_entries (title, link, guid, date_entered, date_updated, updated) VALUES ('$t', '$url', '$uid', NOW(), NOW(), NOW());");
// 2. Make new entry in ttrss_user_entries
// We have to do this SELECT instead of using a function like mysqli_insert_id bcs tt-rss doesn't
// expose that functionality via its iDB interface
$res = Db::get()->query('SELECT MAX(id) as maxid FROM ttrss_entries;');
$last_id = Db::get()->fetch_result($res, 0, 'maxid');
Db::get()->query("INSERT into ttrss_user_entries (ref_id, feed_id, owner_uid, note, published, unread, last_published) VALUES ($last_id, $feed_id, $user_id, '$c', 1, 0, NOW());");
// 3. tell everyone that the gritttt-feed has been updated
Db::get()->query("UPDATE ttrss_feeds SET last_updated = NOW() WHERE id = $feed_id;");
} catch (Exception $e) { // does not catch DB errors yet ?
$MSG = 'failure:'.$e->getMessage();
}
Expand Down

0 comments on commit dab82f2

Please sign in to comment.