diff --git a/driveby-sharing/README.md b/driveby-sharing/README.md index 9b3625f..b626259 100644 --- a/driveby-sharing/README.md +++ b/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
- 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`:
As `gritttt_url`, set the URL at which you will put the `driveby-sharing` folder later (see step 5).
As `path_to_ttrss`, set the relative path from `gritttt_url` to the folder containing your tt-rss instance.
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.
- 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`:
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). @@ -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`! diff --git a/driveby-sharing/config.js.template b/driveby-sharing/config.js.template index 7f9507c..19be44f 100644 --- a/driveby-sharing/config.js.template +++ b/driveby-sharing/config.js.template @@ -3,5 +3,4 @@ var config = { "path_to_ttrss": "../../tt-rss", "feed_id": 183, "user_id": 1, - "ttrss_version_above_1.5.10": true }; diff --git a/driveby-sharing/form.php b/driveby-sharing/form.php index 0e38356..9d80ae7 100755 --- a/driveby-sharing/form.php +++ b/driveby-sharing/form.php @@ -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); ?> @@ -49,7 +40,7 @@ function getParameterByName(name)
diff --git a/driveby-sharing/share.php b/driveby-sharing/share.php index 7c1a087..a56b939 100644 --- a/driveby-sharing/share.php +++ b/driveby-sharing/share.php @@ -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(); }