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:
- The Download Code link was not working properly
- 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.
<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&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->config->item('snipr_user'); // YOUR USER ID REQUIRED + $snipapi = $this->config->item('snipr_apikey'); // FIND IN YOUR "SETTINGS" 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 "simple" + // FOR JUST THE SNIPURL + $snipformat_includepk = ""; // SET TO "Y" 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 . '&' . + 'snipnick=' . $snipnick . '&' . + 'snipuser=' . $snipuser . '&' . + 'snipapi=' . $snipapi . '&' . + 'sniptitle=' . $sniptitle . '&' . + 'snipowner=' . $snipowner . '&' . + 'snipformat='. $snipformat. '&' . + 'snippk=' . $snippk + ; + + + $target = $this->config->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->uri->segment($seg) == "") { 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'] = "main/cron"; $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'] = ''; + ?> \ 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 @@ <?php -header('Content-disposition: attachment'); +header('Content-disposition: attachment;filename='.$title.'.'.$lang_code); echo html_entity_decode($raw); ?> \ 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->config->item('permitted_uri_chars') != '') { - if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str)) + $matches = array(); + $pattern = "|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i"; + if ( ! preg_match($pattern, $str, $matches)) { + echo '<pre><em>'.$str.'</em><br>'; + echo 'allowed: '.$pattern.'<br>'; + var_dump($matches); + var_dump(debug_backtrace()); + echo '</pre>'; exit('The URI you submitted has disallowed characters.'); } }
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?
I don’t think there is, although I haven’t used it in awhile. You may be interested in the author’s ruby version of Stikked, here: https://github.com/benofsky/Stikked
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/
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?
Can you post the full page? I don’t understand what i must do!