|
|
7d7c2bb |
From 79c2f64b46450eca76fd307759055e5ded2cd94f Mon Sep 17 00:00:00 2001
|
|
|
7d7c2bb |
From: Athmane Madjoudj <athmane@fedoraproject.org>
|
|
|
7d7c2bb |
Date: Sun, 14 Apr 2013 08:57:13 +0100
|
|
|
7d7c2bb |
Subject: [PATCH] Add support for an URL shortener (ur1.ca used by Identi.ca)
|
|
|
7d7c2bb |
|
|
|
7d7c2bb |
---
|
|
|
7d7c2bb |
api/api_show.json | 5 +++--
|
|
|
7d7c2bb |
api/api_show.xml | 3 ++-
|
|
|
7d7c2bb |
classes/class_urlshort.php | 38 ++++++++++++++++++++++++++++++++++++++
|
|
|
7d7c2bb |
init.php | 3 ++-
|
|
|
7d7c2bb |
install.php | 2 +-
|
|
|
7d7c2bb |
show.php | 6 ++++++
|
|
|
7d7c2bb |
skins/bootstrap/html/tpl_show.html | 3 ++-
|
|
|
7d7c2bb |
7 files changed, 54 insertions(+), 6 deletions(-)
|
|
|
7d7c2bb |
create mode 100644 classes/class_urlshort.php
|
|
|
7d7c2bb |
|
|
|
7d7c2bb |
diff --git a/api/api_show.json b/api/api_show.json
|
|
|
7d7c2bb |
index d73eac1..cf2dbf8 100755
|
|
|
7d7c2bb |
--- a/api/api_show.json
|
|
|
7d7c2bb |
+++ b/api/api_show.json
|
|
|
7d7c2bb |
@@ -5,6 +5,7 @@
|
|
|
7d7c2bb |
"author": "[[paste_user]]",
|
|
|
7d7c2bb |
"timestamp": "[[paste_timestamp]]",
|
|
|
7d7c2bb |
"language": "[[paste_lang]]",
|
|
|
7d7c2bb |
- "data": "[[paste_data]]"
|
|
|
7d7c2bb |
+ "data": "[[paste_data]]",
|
|
|
7d7c2bb |
+ "short_url": "[[short_url]]"
|
|
|
7d7c2bb |
}
|
|
|
7d7c2bb |
-}
|
|
|
7d7c2bb |
\ No newline at end of file
|
|
|
7d7c2bb |
+}
|
|
|
7d7c2bb |
diff --git a/api/api_show.xml b/api/api_show.xml
|
|
|
7d7c2bb |
index 24a70c5..931bff1 100755
|
|
|
7d7c2bb |
--- a/api/api_show.xml
|
|
|
7d7c2bb |
+++ b/api/api_show.xml
|
|
|
7d7c2bb |
@@ -5,4 +5,5 @@
|
|
|
7d7c2bb |
<timestamp>[[paste_timestamp]]</timestamp>
|
|
|
7d7c2bb |
<language>[[paste_lang]]</language>
|
|
|
7d7c2bb |
<data>[[paste_data]]</data>
|
|
|
7d7c2bb |
-</result>
|
|
|
7d7c2bb |
\ No newline at end of file
|
|
|
7d7c2bb |
+ <shorturl>[[short_url]]</shorturl>
|
|
|
7d7c2bb |
+</result>
|
|
|
7d7c2bb |
diff --git a/classes/class_urlshort.php b/classes/class_urlshort.php
|
|
|
7d7c2bb |
new file mode 100644
|
|
|
7d7c2bb |
index 0000000..0d83b9b
|
|
|
7d7c2bb |
--- /dev/null
|
|
|
7d7c2bb |
+++ b/classes/class_urlshort.php
|
|
|
7d7c2bb |
@@ -0,0 +1,38 @@
|
|
|
7d7c2bb |
+
|
|
|
7d7c2bb |
+/**
|
|
|
7d7c2bb |
+* Sticky Notes pastebin
|
|
|
7d7c2bb |
+* @ver 0.3
|
|
|
7d7c2bb |
+* @license BSD License - www.opensource.org/licenses/bsd-license.php
|
|
|
7d7c2bb |
+*
|
|
|
7d7c2bb |
+* Copyright (c) 2012 Sayak Banerjee <sayakb@kde.org>
|
|
|
7d7c2bb |
+* Copyright (c) 2013 Athmane Madjoudj <athmane@fedoraproject.org>
|
|
|
7d7c2bb |
+* All rights reserved. Do not remove this copyright notice.
|
|
|
7d7c2bb |
+*/
|
|
|
7d7c2bb |
+
|
|
|
7d7c2bb |
+/**
|
|
|
7d7c2bb |
+ * URL shortener using ur1.ca from Indenti.ca
|
|
|
7d7c2bb |
+ **/
|
|
|
7d7c2bb |
+class URLShortener
|
|
|
7d7c2bb |
+{
|
|
|
7d7c2bb |
+ public function shorten($long_url)
|
|
|
7d7c2bb |
+ {
|
|
|
7d7c2bb |
+ $ch = curl_init();
|
|
|
7d7c2bb |
+ curl_setopt($ch, CURLOPT_URL,"http://ur1.ca/");
|
|
|
7d7c2bb |
+ curl_setopt($ch, CURLOPT_POST, 1);
|
|
|
7d7c2bb |
+ curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('longurl' => $long_url)));
|
|
|
7d7c2bb |
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
7d7c2bb |
+ $result = curl_exec($ch);
|
|
|
7d7c2bb |
+ curl_close($ch);
|
|
|
7d7c2bb |
+ preg_match( '/Your ur1 is: (.+)<\/a><\/p>/', $result, $match );
|
|
|
7d7c2bb |
+ if (!empty($match))
|
|
|
7d7c2bb |
+ return $match[1];
|
|
|
7d7c2bb |
+ else
|
|
|
7d7c2bb |
+ return false;
|
|
|
7d7c2bb |
+
|
|
|
7d7c2bb |
+ }
|
|
|
7d7c2bb |
+}
|
|
|
7d7c2bb |
+
|
|
|
7d7c2bb |
+//$u2 = new URLShortener();
|
|
|
7d7c2bb |
+//print $u2->shorten("http://google.com/");
|
|
|
7d7c2bb |
+
|
|
|
7d7c2bb |
+?>
|
|
|
7d7c2bb |
diff --git a/init.php b/init.php
|
|
|
7d7c2bb |
index 285c976..075f22a 100755
|
|
|
7d7c2bb |
--- a/init.php
|
|
|
7d7c2bb |
+++ b/init.php
|
|
|
7d7c2bb |
@@ -24,6 +24,7 @@ include_once('classes/class_skin.php');
|
|
|
7d7c2bb |
include_once('classes/class_api.php');
|
|
|
7d7c2bb |
include_once('classes/class_nav.php');
|
|
|
7d7c2bb |
include_once('classes/class_spamguard.php');
|
|
|
7d7c2bb |
+include_once('classes/class_urlshort.php');
|
|
|
7d7c2bb |
include_once('addons/geshi/geshi.php');
|
|
|
7d7c2bb |
|
|
|
7d7c2bb |
// We need to instantiate the GSoD class first, just in case!
|
|
|
7d7c2bb |
@@ -88,4 +89,4 @@ if (!defined('IN_INSTALL') && !defined('IN_ADMIN'))
|
|
|
7d7c2bb |
include_once('cron.php');
|
|
|
7d7c2bb |
}
|
|
|
7d7c2bb |
|
|
|
7d7c2bb |
-?>
|
|
|
7d7c2bb |
\ No newline at end of file
|
|
|
7d7c2bb |
+?>
|
|
|
7d7c2bb |
diff --git a/install.php b/install.php
|
|
|
7d7c2bb |
index 9536460..2f57720 100755
|
|
|
7d7c2bb |
--- a/install.php
|
|
|
7d7c2bb |
+++ b/install.php
|
|
|
7d7c2bb |
@@ -133,4 +133,4 @@ $gsod->trigger(
|
|
|
7d7c2bb |
"the admin panel."
|
|
|
7d7c2bb |
);
|
|
|
7d7c2bb |
|
|
|
7d7c2bb |
-?>
|
|
|
7d7c2bb |
\ No newline at end of file
|
|
|
7d7c2bb |
+?>
|
|
|
7d7c2bb |
diff --git a/show.php b/show.php
|
|
|
7d7c2bb |
index 1ffa885..a31a750 100755
|
|
|
7d7c2bb |
--- a/show.php
|
|
|
7d7c2bb |
+++ b/show.php
|
|
|
7d7c2bb |
@@ -5,6 +5,7 @@
|
|
|
7d7c2bb |
* @license BSD License - www.opensource.org/licenses/bsd-license.php
|
|
|
7d7c2bb |
*
|
|
|
7d7c2bb |
* Copyright (c) 2012 Sayak Banerjee <sayakb@kde.org>
|
|
|
7d7c2bb |
+* Copyright (c) 2013 Athmane Madjoudj <athmane@fedoraproject.org>
|
|
|
7d7c2bb |
* All rights reserved. Do not remove this copyright notice.
|
|
|
7d7c2bb |
*/
|
|
|
7d7c2bb |
|
|
|
7d7c2bb |
@@ -227,6 +228,10 @@ $code_data = (empty($mode) ? $geshi->parse_code() : htmlspecialchars($row['data'
|
|
|
7d7c2bb |
$lang->escape($code_data);
|
|
|
7d7c2bb |
$skin->escape($code_data);
|
|
|
7d7c2bb |
|
|
|
7d7c2bb |
+// Shorten the current URL
|
|
|
7d7c2bb |
+$url_shortener = new URLShortener();
|
|
|
7d7c2bb |
+$short_url = $url_shortener->shorten($nav->get_paste($row['id'], $hash, $project, true, ''));
|
|
|
7d7c2bb |
+
|
|
|
7d7c2bb |
// Assign template variables
|
|
|
7d7c2bb |
$skin->assign(array(
|
|
|
7d7c2bb |
'paste_id' => $row['id'],
|
|
|
7d7c2bb |
@@ -240,6 +245,7 @@ $skin->assign(array(
|
|
|
7d7c2bb |
'share_title' => urlencode($lang->get('paste') . ' #' . $row['id']),
|
|
|
7d7c2bb |
'error_visibility' => 'hidden',
|
|
|
7d7c2bb |
'geshi_stylesheet' => $geshi->get_stylesheet(),
|
|
|
7d7c2bb |
+ 'short_url' => $short_url,
|
|
|
7d7c2bb |
));
|
|
|
7d7c2bb |
|
|
|
7d7c2bb |
// Let's output the page now
|
|
|
7d7c2bb |
diff --git a/skins/bootstrap/html/tpl_show.html b/skins/bootstrap/html/tpl_show.html
|
|
|
7d7c2bb |
index a58386b..c6776bc 100755
|
|
|
7d7c2bb |
--- a/skins/bootstrap/html/tpl_show.html
|
|
|
7d7c2bb |
+++ b/skins/bootstrap/html/tpl_show.html
|
|
|
7d7c2bb |
@@ -34,6 +34,7 @@
|
|
|
7d7c2bb |
|
|
|
7d7c2bb |
|
|
|
7d7c2bb |
|
|
|
7d7c2bb |
+ Shortened URL: [[short_url]]
|
|
|
7d7c2bb |
|
|
|
7d7c2bb |
|
|
|
7d7c2bb |
|
|
|
7d7c2bb |
@@ -51,4 +52,4 @@
|
|
|
7d7c2bb |
|
|
|
7d7c2bb |
[[error_text]]
|
|
|
7d7c2bb |
|
|
|
7d7c2bb |
-
|
|
|
7d7c2bb |
\ No newline at end of file
|
|
|
7d7c2bb |
+
|
|
|
7d7c2bb |
--
|
|
|
7d7c2bb |
1.8.1.4
|
|
|
7d7c2bb |
|