1: <?php
2: /*****************************************************************************************
3: * X2Engine Open Source Edition is a customer relationship management program developed by
4: * X2Engine, Inc. Copyright (C) 2011-2016 X2Engine Inc.
5: *
6: * This program is free software; you can redistribute it and/or modify it under
7: * the terms of the GNU Affero General Public License version 3 as published by the
8: * Free Software Foundation with the addition of the following permission added
9: * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10: * IN WHICH THE COPYRIGHT IS OWNED BY X2ENGINE, X2ENGINE DISCLAIMS THE WARRANTY
11: * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12: *
13: * This program is distributed in the hope that it will be useful, but WITHOUT
14: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15: * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16: * details.
17: *
18: * You should have received a copy of the GNU Affero General Public License along with
19: * this program; if not, see http://www.gnu.org/licenses or write to the Free
20: * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21: * 02110-1301 USA.
22: *
23: * You can contact X2Engine, Inc. P.O. Box 66752, Scotts Valley,
24: * California 95067, USA. or at email address contact@x2engine.com.
25: *
26: * The interactive user interfaces in modified source and object code versions
27: * of this program must display Appropriate Legal Notices, as required under
28: * Section 5 of the GNU Affero General Public License version 3.
29: *
30: * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31: * these Appropriate Legal Notices must retain the display of the "Powered by
32: * X2Engine" logo. If the display of the logo is not reasonably feasible for
33: * technical reasons, the Appropriate Legal Notices must display the words
34: * "Powered by X2Engine".
35: *****************************************************************************************/
36:
37: /**
38: * Media Selector Widget.
39: * Pops up when the Media button is clicked on the CKEditor.
40: * The button will lazily load this widget via site/mediaSelector
41: * and append it to the dom with all JS.
42: */
43: class MediaSelector extends X2Widget {
44:
45: /**
46: * @see X2Widget::$viewFile
47: */
48: public $viewFile = 'application.components.views.mediaSelector';
49:
50: /**
51: * @see X2Widget::$JSClass
52: */
53: public $JSClass = 'MediaSelector';
54:
55: /**
56: * Flag whether or not this widget is being created
57: * just to update the Yii List View. If true, javascript will
58: * not re-register.
59: * @var boolean
60: */
61: public $update = false;
62:
63: /**
64: * @see X2Widget::init()
65: */
66: public function init (){
67: parent::init ();
68: }
69:
70: /**
71: * @see X2Widget::run()
72: */
73: public function run() {
74: $this->registerPackages ();
75:
76: // Instantiate the javascript only if
77: // the view is NOT being updated
78: if (!$this->update)
79: $this->instantiateJSClass ();
80:
81: $this->render ($this->viewFile);
82: }
83:
84: /**
85: * @see X2Widget::getPackages()
86: */
87: public function getPackages() {
88: $this->_packages = array(
89: 'MediaSelectorJS' => array(
90: 'baseUrl' => Yii::app()->baseUrl,
91: 'js' => array(
92: 'js/MediaSelector.js'
93: ),
94: 'depends' => array('Dropzone')
95: ),
96: 'MediaSelectorCSS' => array(
97: 'baseUrl' => Yii::app()->theme->baseUrl,
98: 'css' => array(
99: 'css/components/MediaSelector.css'
100: ),
101: ),
102: );
103: return $this->_packages;
104: }
105:
106: /**
107: * @see X2Widget::getTranslations()
108: */
109: public function getTranslations () {
110: return array(
111: 'title' => Yii::t('app', 'Image Gallery'),
112: 'deleteText' => Yii::t('app', 'Are you sure you want to delete this image?'),
113: 'Insert Image' => Yii::t('app', 'Insert Image'),
114: 'Close' => Yii::t('app', 'Close')
115: );
116: }
117:
118: /**
119: * Gets the dataProvider given to the list view to create
120: * the list of images
121: * @return CDataProvider Data provider for Yii List View.
122: * @todo Tweak to shopw other peoples
123: */
124: public function getDataProvider () {
125: $criteria = new CDbCriteria;
126:
127: $criteria->addInCondition ('associationType',
128: array ('none', 'docs'));
129:
130: $criteria->addSearchCondition('mimetype', 'image');
131: $criteria->addCondition ('uploadedBy="'.Yii::app()->user->name.'"');
132: $criteria->addCondition ('drive!=1');
133:
134: $dataProvider = new CActiveDataProvider('Media', array(
135: 'criteria' => $criteria,
136: 'sort' => array (
137: 'defaultOrder' => 't.createDate DESC'
138: ),
139: 'pagination' => array (
140: 'pageSize' => 20,
141: ),
142: ));
143: return $dataProvider;
144: }
145: }
146: ?>