display qr code in-place, doesn't require writeable dir and saves space

This commit is contained in:
Claude 2014-01-30 16:14:58 +01:00
parent a06480d248
commit 63b8233d0c
6 changed files with 24 additions and 28 deletions

View File

@ -46,6 +46,7 @@ $route['cron/:any'] = "main/cron";
$route['view/raw/:any'] = 'main/raw'; $route['view/raw/:any'] = 'main/raw';
$route['view/rss/:any'] = 'main/rss'; $route['view/rss/:any'] = 'main/rss';
$route['view/embed/:any'] = 'main/embed'; $route['view/embed/:any'] = 'main/embed';
$route['view/qr/:any'] = 'main/qr';
$route['view/download/:any'] = 'main/download'; $route['view/download/:any'] = 'main/download';
$route['view/captcha'] = 'main/captcha'; $route['view/captcha'] = 'main/captcha';
$route['view/:any'] = 'main/view'; $route['view/:any'] = 'main/view';

View File

@ -8,6 +8,7 @@
* - raw() * - raw()
* - rss() * - rss()
* - embed() * - embed()
* - qr()
* - download() * - download()
* - lists() * - lists()
* - trends() * - trends()
@ -472,6 +473,13 @@ class Main extends CI_Controller
} }
} }
function qr()
{
$this->load->model('pastes');
$data = $this->pastes->getPaste(3);
$this->load->view('view/qr', $data);
}
function download() function download()
{ {
$this->_valid_authentication(); $this->_valid_authentication();

View File

@ -127,16 +127,6 @@ class Pastes extends CI_Model
} }
$data['ip_address'] = $this->input->ip_address(); $data['ip_address'] = $this->input->ip_address();
$this->db->insert('pastes', $data); $this->db->insert('pastes', $data);
$pngPath = dirname(dirname(dirname(__FILE__))) . '/static/qr/' . $data['pid'] . '.png';
if (!file_exists($pngPath)) {
require_once(dirname(dirname(__FILE__)) . '/libraries/phpqrcode/qrlib.php');
$qrurl = $this->_get_url($data['pid']);
if ( $data['snipurl'] !== false ) {
$qrurl = $data['snipurl'];
}
QRcode::png($qrurl, $pngPath);
}
return 'view/' . $data['pid']; return 'view/' . $data['pid'];
} }
private private
@ -250,16 +240,6 @@ class Pastes extends CI_Model
$data['hits_updated'] = $row['hits_updated']; $data['hits_updated'] = $row['hits_updated'];
$data['snipurl'] = $row['snipurl']; $data['snipurl'] = $row['snipurl'];
$inreply = $row['replyto']; $inreply = $row['replyto'];
$pngPath = dirname(dirname(dirname(__FILE__))) . '/static/qr/' . $data['pid'] . '.png';
if (!file_exists($pngPath)) {
require_once(dirname(dirname(__FILE__)) . '/libraries/phpqrcode/qrlib.php');
$qrurl = $this->_get_url($data['pid']);
if ( $data['snipurl'] != false ) {
$qrurl = $data['snipurl'];
}
QRcode::png($qrurl, $pngPath);
}
} }
if ($inreply) if ($inreply)
@ -597,10 +577,6 @@ class Pastes extends CI_Model
{ {
$this->db->where('pid', $pid); $this->db->where('pid', $pid);
$this->db->delete('pastes'); $this->db->delete('pastes');
$pngPath = dirname(dirname(dirname(__FILE__))) . '/static/qr/' . $pid . '.png';
if (file_exists($pngPath)) {
unlink($pngPath);
}
return; return;
} }

View File

@ -1,3 +0,0 @@
<?php
/* This file prevents Apache from listing the files located in the "qr" folder */
?>

View File

@ -0,0 +1,14 @@
<?php
/**
* Class and Function List:
* Function list:
* Classes list:
*/
require_once ('./application/libraries/phpqrcode/qrlib.php');
$qrurl = $url;
if ($snipurl != false)
{
$qrurl = $snipurl;
}
QRcode::png($qrurl);

View File

@ -44,7 +44,7 @@ if(isset($insert)){
</span> </span>
</div> </div>
<div class="qr"> <div class="qr">
<img src="<?php echo site_url('static/qr/' . $pid . '.png'); ?>"> <img src="<?php echo site_url('view/qr/' . $pid); ?>">
</div> </div>
</div> </div>
</div> </div>