From 9cffea9ec31fa49e518090a82f9b208c1aac551f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Sat, 6 Sep 2014 15:39:39 +0200 Subject: [PATCH] Added Disqus Widget to [programs/view] and [blog/view] --- www/css/styles.css | 10 ++++ www/protected/config/env/dev.php | 3 - .../extensions/YiiDisqusWidget/.gitignore | 13 +++++ .../extensions/YiiDisqusWidget/LICENSE | 27 +++++++++ .../extensions/YiiDisqusWidget/README.md | 48 ++++++++++++++++ .../YiiDisqusWidget/YiiDisqusWidget.php | 56 +++++++++++++++++++ .../YiiDisqusWidget/views/yiidisqus.php | 39 +++++++++++++ www/protected/models/BlogPost.php | 7 +++ www/protected/models/Program.php | 7 +++ www/protected/views/blogpost/view.php | 15 +++++ www/protected/views/programs/view.php | 14 +++++ 11 files changed, 236 insertions(+), 3 deletions(-) create mode 100644 www/protected/extensions/YiiDisqusWidget/.gitignore create mode 100644 www/protected/extensions/YiiDisqusWidget/LICENSE create mode 100644 www/protected/extensions/YiiDisqusWidget/README.md create mode 100644 www/protected/extensions/YiiDisqusWidget/YiiDisqusWidget.php create mode 100644 www/protected/extensions/YiiDisqusWidget/views/yiidisqus.php diff --git a/www/css/styles.css b/www/css/styles.css index 3ba9dde..3aefaa8 100644 --- a/www/css/styles.css +++ b/www/css/styles.css @@ -682,6 +682,16 @@ ul.nav li.dropdown-append:hover > ul.dropdown-menu { font-weight: 900; } +/* disqus +-------------------------------------------------- */ + +.disqus_owner { + border-radius: 6px; + border: 1px solid #D7E0E2; + padding: 10px; + background-color: #ECF0F1; +} + /* blog/view -------------------------------------------------- */ diff --git a/www/protected/config/env/dev.php b/www/protected/config/env/dev.php index 9f42143..0a7711f 100644 --- a/www/protected/config/env/dev.php +++ b/www/protected/config/env/dev.php @@ -1,8 +1,5 @@ [ diff --git a/www/protected/extensions/YiiDisqusWidget/.gitignore b/www/protected/extensions/YiiDisqusWidget/.gitignore new file mode 100644 index 0000000..710d905 --- /dev/null +++ b/www/protected/extensions/YiiDisqusWidget/.gitignore @@ -0,0 +1,13 @@ +.orig +.orig.* +.chg.* +.rej +.conflict~ +.idea/ +nbproject/ +.DS_Store + +!.gitignore +assets/ +protected/runtime/ +themes/classic/views/ \ No newline at end of file diff --git a/www/protected/extensions/YiiDisqusWidget/LICENSE b/www/protected/extensions/YiiDisqusWidget/LICENSE new file mode 100644 index 0000000..c76ac1f --- /dev/null +++ b/www/protected/extensions/YiiDisqusWidget/LICENSE @@ -0,0 +1,27 @@ +Copyright (c) 2013, Anton Kucherov +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, this + list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + + Neither the name of the {organization} nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/www/protected/extensions/YiiDisqusWidget/README.md b/www/protected/extensions/YiiDisqusWidget/README.md new file mode 100644 index 0000000..f6dce8f --- /dev/null +++ b/www/protected/extensions/YiiDisqusWidget/README.md @@ -0,0 +1,48 @@ +YiiDisqusWidget +=============== + +This is sample widget wich can help you to add DISQUS +support in to your Yii site. + +##Requirements + +You must be registered on [DISQUS](http://disqus.com/) + +##Installation + +Copy `YiiDisqusWidget` folder in you `protected/extensions` folder. + +##Usage + +Just add this code on your page where you need to include DISQUS. +Simple usage: +```php +// DISQUS_SHORTNAME - You disqus_shortname from DISQUS. +$this->widget('ext.YiiDisqusWidget.YiiDisqusWidget',array('shortname'=>'DISQUS_SHORTNAME')); +``` + +You can change all off `disqus_` parameters in options array: +```javascript +var disqus_shortname; +var disqus_identifier; +var disqus_title; +var disqus_url; +``` +Just add it in option array: +```php +$this->widget( + 'ext.YiiDisqusWidget.YiiDisqusWidget', + array( + 'shortname' => 'DISQUS_SHORTNAME', + 'identifier' => 'DISQUS_IDENTIFIER', + 'title' => 'DISQUS_TITLE', + 'url' => 'DISQUS_URL', + 'category_id' => 'DISQUS_CATEGORY_ID', + ) +); +``` +More information about DISQUS variables on [http://help.disqus.com/](http://help.disqus.com/customer/portal/articles/472098-javascript-configuration-variables#disqus_shortname) + +##Resources + + * [GitHub](https://github.com/DexterHD/YiiDisqusWidget) diff --git a/www/protected/extensions/YiiDisqusWidget/YiiDisqusWidget.php b/www/protected/extensions/YiiDisqusWidget/YiiDisqusWidget.php new file mode 100644 index 0000000..f46e74d --- /dev/null +++ b/www/protected/extensions/YiiDisqusWidget/YiiDisqusWidget.php @@ -0,0 +1,56 @@ + +* @link http://idexter.ru/ +* @copyright 2013 idexter.ru +*/ + +/** + * YiiDisqusWidget + * @author Anton Kucherov + */ +class YiiDisqusWidget extends CWidget +{ + /** + * @var string disqus_shortname + */ + public $shortname; + /** + * @var string disqus_identifier + */ + public $identifier; + /** + * @var string disqus_title + */ + public $title; + /** + * @var string disqus_url + */ + public $url; + /** + * @var string disqus_category_id + */ + public $category_id; + + /** + * @throws CHttpException + */ + public function init() + { + parent::init(); + if (empty($this->shortname)) { + throw new CHttpException(500, Yii::t('YiiDisqusWidget', 'Parameter "disqus_shortname" is not set')); + } + + $params = array(); + $params['shortname'] = $this->shortname; + $params['identifier'] = $this->identifier; + $params['title'] = $this->title; + $params['url'] = $this->url; + $params['category_id'] = $this->category_id; + + $this->render('yiidisqus',$params); + } +} \ No newline at end of file diff --git a/www/protected/extensions/YiiDisqusWidget/views/yiidisqus.php b/www/protected/extensions/YiiDisqusWidget/views/yiidisqus.php new file mode 100644 index 0000000..87f9347 --- /dev/null +++ b/www/protected/extensions/YiiDisqusWidget/views/yiidisqus.php @@ -0,0 +1,39 @@ + + * @link http://idexter.ru/ + * @copyright 2013 idexter.ru + */ +?> +
+ + +comments powered by Disqus \ No newline at end of file diff --git a/www/protected/models/BlogPost.php b/www/protected/models/BlogPost.php index 121a36f..c26012f 100644 --- a/www/protected/models/BlogPost.php +++ b/www/protected/models/BlogPost.php @@ -120,6 +120,13 @@ class BlogPost extends CActiveRecord return '/blog/' . $this->ID . '/' . rawurlencode($name); } + /** + * @return string + */ + public function getAbsoluteLink() { + return 'http://www.mikescher.de' . $this->getLink(); + } + /** * @param $search string[] * @return array() diff --git a/www/protected/models/Program.php b/www/protected/models/Program.php index 76df131..cdcc9e2 100644 --- a/www/protected/models/Program.php +++ b/www/protected/models/Program.php @@ -176,6 +176,13 @@ class Program extends CActiveRecord return '/programs/view/' . rawurlencode($this->Name); } + /** + * @return string + */ + public function getAbsoluteLink() { + return 'http://www.mikescher.de' . $this->getLink(); + } + /** * @return string */ diff --git a/www/protected/views/blogpost/view.php b/www/protected/views/blogpost/view.php index e7a93fb..adcafa8 100644 --- a/www/protected/views/blogpost/view.php +++ b/www/protected/views/blogpost/view.php @@ -30,4 +30,19 @@ $this->breadcrumbs = array( +
+ widget( + 'ext.YiiDisqusWidget.YiiDisqusWidget', + [ + 'shortname' => 'mikescher-de', + 'identifier' => 'blog/view/' + $model->ID, + 'title' => $model->Title, + 'url' => $model->getAbsoluteLink(), + 'category_id' => '3253401', // = blog/view + ] + ); + ?> +
+ diff --git a/www/protected/views/programs/view.php b/www/protected/views/programs/view.php index db751d4..aec3f98 100644 --- a/www/protected/views/programs/view.php +++ b/www/protected/views/programs/view.php @@ -82,6 +82,20 @@ if (!$model->visible && Yii::app()->user->name != 'admin') { ] ); ?> +
+ widget( + 'ext.YiiDisqusWidget.YiiDisqusWidget', + [ + 'shortname' => 'mikescher-de', + 'identifier' => 'programs/view/' + $model->ID, + 'title' => $model->Name, + 'url' => $model->getAbsoluteLink(), + 'category_id' => '3253400', // = programs/view + ] + ); + ?> +