in Software

Stikked Patch

We’ve been using Stikked for an internal pastebin. The current version on Google Code has a few bugs. I modified this code to fix two problems specifically:

  1. The Download Code link was not working properly
  2. The Short URL functionality was not working, as Snipr had deprecated the version of the API that the program was using

Below is a consolidated diff of the changes. You should be able to use it to apply a patch to 0.5.4 if you are having these issues.

stikked.diff


<h1>Index: trunk/system/application/models/pastes.php</h1>

--- trunk/system/application/models/pastes.php  (revision 1)
+++ trunk/system/application/models/pastes.php  (revision 2)
@@ -156,14 +156,55 @@
            $data['snipurl'] = false;
        }
        else
-       {
-           $target = '//snipr.com/site/snip?r=simple&amp;link='.site_url('view/'.$data['pid']);
+       {
+           // this next blob just copied from snipr's examples,
+           // with some modifications of course
+
+           // REQUIRED FIELDS
+           $sniplink  = site_url('view/'.$data['pid']);
+           $snipuser  = $this-&gt;config-&gt;item('snipr_user');            // YOUR USER ID REQUIRED
+           $snipapi   = $this-&gt;config-&gt;item('snipr_apikey');               // FIND IN YOUR &quot;SETTINGS&quot; PAGE
+
+           // OPTIONAL FIELDS
+           $snipnick   = '';            // MEANINGFUL NICKNAME FOR SNIPURL
+           $sniptitle  = $data['title'];  // TITLE IF ANY
+           $snippk     = '';                      // PRIVATE KEY IF ANY
+           $snipowner  = '';                      // IF THE SNIP OWNER IS SOMEONE ELSE
+           $snipformat = 'simple';                      // DEFAULT RESPONSE IS IN XML, SEND &quot;simple&quot;
+                                                  // FOR JUST THE SNIPURL
+           $snipformat_includepk = &quot;&quot;;            // SET TO &quot;Y&quot; IF YOU WANT THE PRIVATE KEY
+                                                  // RETURNED IN THE SNIPURL ALONG WITH THE ALIAS
+
+           //----------------------------------
+           // NO NEED TO EDIT BEYOND THIS POINT
+           //----------------------------------
+           $URL        = '//snipr.com/site/getsnip';
+           $sniplink   = rawurlencode($sniplink);
+           $snipnick   = rawurlencode($snipnick);
+           $sniptitle  = rawurlencode($sniptitle);
+
+
+           $post_data =  'sniplink='  . $sniplink  . '&amp;' .
+                         'snipnick='  . $snipnick  . '&amp;' .
+                         'snipuser='  . $snipuser  . '&amp;' .
+                         'snipapi='   . $snipapi   . '&amp;' .
+                         'sniptitle=' . $sniptitle . '&amp;' .
+                         'snipowner=' . $snipowner . '&amp;' .
+                         'snipformat='. $snipformat. '&amp;' .
+                         'snippk='    . $snippk
+             ;
+
+
+           $target = $this-&gt;config-&gt;item('snipr_link');
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $target);
+           curl_setopt($ch, CURLOPT_POST, true);
+           curl_setopt($ch, CURLOPT_HEADER, 0);
+           curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

<h2>            $data['snipurl'] = curl_exec($ch);</h2>

+
            curl_close($ch);

        if(empty($data['snipurl']))


@@ -189,6 +230,7 @@

function checkPaste($seg=2)
{


+
        if($this-&gt;uri-&gt;segment($seg) == &quot;&quot;)
        {
            return false;

<h1>Index: trunk/system/application/config/routes.php</h1>

--- trunk/system/application/config/routes.php  (revision 1)
+++ trunk/system/application/config/routes.php  (revision 2)
@@ -46,6 +46,7 @@
 $route['cron/:any'] = &quot;main/cron&quot;;

$route['view/raw/:any'] = 'main/raw/';
+$route['view/download/:any'] = 'main/download/';
 $route['view/options'] = 'main/view_options';
 $route['view/:any'] = 'main/view';
 $route['lists'] = 'main/lists';

<h1>Index: trunk/system/application/config/config.php</h1>

--- trunk/system/application/config/config.php  (revision 1)
+++ trunk/system/application/config/config.php  (revision 2)
@@ -308,4 +308,16 @@
 $config['rewrite_short_tags'] = FALSE;

+/*
+|--------------------------------------------------------------------------
+| Snipr Settings - Used for short URL
+|--------------------------------------------------------------------------
+|
+| Settings for Snipr API
+|
+*/
+$config['snipr_link'] = '//snipurl.com/site/getsnip';
+$config['snipr_user'] = ''; // snipr user name
+$config['snipr_apikey'] = '';
+
 ?&gt;
\ No newline at end of file

<h1>Index: trunk/system/application/views/view/download.php</h1>

--- trunk/system/application/views/view/download.php    (revision 1)
+++ trunk/system/application/views/view/download.php    (revision 2)
@@ -1,6 +1,6 @@
 &lt;?php

-header('Content-disposition: attachment');
+header('Content-disposition: attachment;filename='.$title.'.'.$lang_code);
 echo html_entity_decode($raw);

?&gt;
\ No newline at end of file

<h1>Index: trunk/system/libraries/URI.php</h1>

--- trunk/system/libraries/URI.php  (revision 1)
+++ trunk/system/libraries/URI.php  (revision 2)
@@ -186,8 +186,15 @@
    {
        if ($str != '' AND $this-&gt;config-&gt;item('permitted_uri_chars') != '')
        {
-           if ( ! preg_match(&quot;|^[&quot;.preg_quote($this-&gt;config-&gt;item('permitted_uri_chars')).&quot;]+$|i&quot;, $str))
+           $matches = array();
+           $pattern = &quot;|^[&quot;.preg_quote($this-&gt;config-&gt;item('permitted_uri_chars')).&quot;]+$|i&quot;;
+           if ( ! preg_match($pattern, $str, $matches))
            {
+               echo '&lt;pre&gt;<em>'.$str.'</em>&lt;br&gt;';
+               echo 'allowed: '.$pattern.'&lt;br&gt;';
+               var_dump($matches);
+               var_dump(debug_backtrace());
+               echo '&lt;/pre&gt;';
                exit('The URI you submitted has disallowed characters.');
            }
        }

  1. Thanks Jamie this solved some of the problems I was having with stikked. Do you know if there is an admin interface out there that will allow removal of links/users or if I’ll have to create a backend?

  2. Thanks Jamie, That would require me to learn ruby 😉 I don’t want to spam your blog but I found a basic auth model that was easy to intergrate with stikked so i’m bulding my own backend for anyone intrested tank_auth is the name of the basic auth (you’ll need to use an older version as the newest one is for CI 2.0+) //www.konyukhov.com/soft/tank_auth/

  3. thanks, i applied the patch but got several failed chunks. I manually applied the rejects but get an error using the url shortener (api key and username are set)

    Snipurl ERROR: PLEASE SPECIFY THE ACTION. CHECK <a href="//snipurl.

    Can you help?

  4. Can you post the full page? I don’t understand what i must do!

Comments are closed.