From ca07398b663b0a5cd399086ce781c62c5268832a Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sun, 18 Oct 2015 17:56:45 +0200 Subject: [PATCH] adding option to hide clone button on expiring pastes, resolves #34 --- cfg/conf.ini | 4 ++++ lib/configuration.php | 1 + lib/zerobin.php | 13 ++++++++++++- tpl/bootstrap-compact.html | 4 ++-- tpl/bootstrap-page.html | 4 ++-- tpl/bootstrap.html | 4 ++-- tpl/page.html | 4 ++-- tst/RainTPL.php | 1 + 8 files changed, 26 insertions(+), 9 deletions(-) diff --git a/cfg/conf.ini b/cfg/conf.ini index cf6f929..28476fb 100644 --- a/cfg/conf.ini +++ b/cfg/conf.ini @@ -53,6 +53,10 @@ languageselection = false ; make sure the value exists in [expire_options] default = "1week" +; optionally the "clone" button can be disabled on expiring pastes +; note that this only hides the button, copy & paste is still possible +; clone = false + [expire_options] ; Set each one of these to the number of seconds in the expiration period, ; or 0 if it should never expire diff --git a/lib/configuration.php b/lib/configuration.php index 4bb151a..11e062b 100644 --- a/lib/configuration.php +++ b/lib/configuration.php @@ -46,6 +46,7 @@ class configuration ), 'expire' => array( 'default' => '1week', + 'clone' => true, ), 'expire_options' => array( '5min' => 300, diff --git a/lib/zerobin.php b/lib/zerobin.php index edda4b6..f94bc49 100644 --- a/lib/zerobin.php +++ b/lib/zerobin.php @@ -47,6 +47,14 @@ class zerobin */ private $_data = ''; + /** + * does the paste expire + * + * @access private + * @var bool + */ + private $_doesExpire = false; + /** * formatter * @@ -354,7 +362,9 @@ class zerobin $paste = $this->_model->getPaste($dataid); if ($paste->exists()) { - $this->_data = json_encode($paste->get()); + $data = $paste->get(); + $this->_doesExpire = property_exists($data, 'meta') && property_exists($data->meta, 'expire_date'); + $this->_data = json_encode($data); } else { @@ -434,6 +444,7 @@ class zerobin $page->assign('LANGUAGES', i18n::getLanguageLabels(i18n::getAvailableLanguages())); $page->assign('EXPIRE', $expire); $page->assign('EXPIREDEFAULT', $this->_conf->getKey('default', 'expire')); + $page->assign('EXPIRECLONE', !$this->_doesExpire || ($this->_doesExpire && $this->_conf->getKey('clone', 'expire'))); $page->draw($this->_conf->getKey('template')); } diff --git a/tpl/bootstrap-compact.html b/tpl/bootstrap-compact.html index df1580e..662d538 100644 --- a/tpl/bootstrap-compact.html +++ b/tpl/bootstrap-compact.html @@ -41,10 +41,10 @@
  • + {if="$EXPIRECLONE"} + {/if} diff --git a/tpl/bootstrap-page.html b/tpl/bootstrap-page.html index ab8e1c3..69e3531 100644 --- a/tpl/bootstrap-page.html +++ b/tpl/bootstrap-page.html @@ -40,10 +40,10 @@
  • + {if="$EXPIRECLONE"} + {/if} diff --git a/tpl/bootstrap.html b/tpl/bootstrap.html index a3a82ec..57fbb45 100644 --- a/tpl/bootstrap.html +++ b/tpl/bootstrap.html @@ -40,10 +40,10 @@
  • + {if="$EXPIRECLONE"} + {/if} diff --git a/tpl/page.html b/tpl/page.html index 8071dd2..7bd7ab2 100644 --- a/tpl/page.html +++ b/tpl/page.html @@ -43,8 +43,8 @@
    - - + {if="$EXPIRECLONE"} + {/if}