1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35:
36:
37:
38: Yii::import('zii.widgets.jui.CJuiWidget');
39:
40: 41: 42: 43: 44: 45: 46: 47: 48:
49: class SortableWidgets extends CJuiWidget {
50:
51: 52: 53: 54:
55: public $portlets = array();
56: public $jQueryOptions = array();
57:
58: 59: 60:
61: public $tagName = 'div';
62:
63: 64: 65: 66:
67: public function run(){
68: $themeURL = Yii::app()->theme->getBaseUrl();
69:
70: Yii::app()->clientScript->registerScript('toggleWidgetState', "
71: function toggleWidgetState(widget,state) {
72: if($('#widget_' + widget).hasClass('ui-sortable-helper') == false) {
73: $.ajax({
74: url: '".CHtml::normalizeUrl(array('/site/widgetState'))."',
75: type: 'GET',
76: data: 'widget='+widget+'&state='+state,
77: success: function(response) {
78: if(response === 'success') {
79: var link = $('#widget_'+widget+
80: ' .portlet-minimize a.portlet-minimize-button');
81: var newLink = ($(link).find('span').hasClass('expand-widget')) ?
82: '<span '+
83: 'class=\"fa fa-caret-down collapse-widget\" ></span>' :
84: // toggle link between [+] and [-]
85: '<span '+
86: 'class=\"fa fa-caret-left expand-widget\"></span>';
87: link.html(newLink);
88:
89: // slide widget open or closed
90: $('#widget_'+widget+' .portlet-content').toggle({
91: effect: 'blind',
92: duration: 200,
93: complete: function() {
94: blindComplete = true;
95: }
96: });
97: }
98: }
99: });
100: }
101:
102: }
103: ", CClientScript::POS_HEAD);
104:
105: $id = $this->getId();
106: if(isset($this->htmlOptions['id'])) {
107: $id = $this->htmlOptions['id'];
108: } else {
109: $this->htmlOptions['id'] = $id;
110: }
111:
112: $options = empty($this->jQueryOptions) ? '' : CJavaScript::encode($this->jQueryOptions);
113: Yii::app()->getClientScript()->registerScript(
114: 'SortableWidgets'.'#'.$id, "jQuery('#{$id}').sortable({$options});");
115:
116: echo CHtml::openTag($this->tagName, $this->htmlOptions)."\n";
117:
118: $widgetHideList = array();
119: if(!Yii::app()->user->isGuest){
120: $layout = Yii::app()->params->profile->getLayout();
121: }else{
122: $layout = array();
123: }
124: $profile = yii::app()->params->profile;
125: foreach($this->portlets as $class => $properties){
126: if (!class_exists ($class)) continue;
127:
128:
129: if(!in_array($class, array_keys($layout['hiddenRight']))){
130: $visible = ($properties['visibility'] == '1');
131:
132: if(!$visible)
133: $widgetHideList[] = '#widget_'.$class;
134:
135: $minimizeLink = CHtml::link(
136: $visible ?
137: CHtml::tag('span',
138: array('class' => 'fa fa-caret-down collapse-widget'), ' ') :
139:
140: CHtml::tag('span',
141: array('class' => 'fa fa-caret-left expand-widget'), ' ')
142:
143: , '#', array('class' => 'portlet-minimize-button')
144: ).' '.CHtml::link(
145: '<i class="fa fa-times"></i>', '#',
146: array(
147: 'onclick' => "$('#widget_$class').hideWidgetRight(); return false;",
148: 'class' => 'portlet-close-button'
149: )
150: );
151:
152: $widget = $this->widget($class, $properties['params'], true);
153:
154: if($profile->activityFeedOrder){
155: ?>
156: <script>
157: $("#topDown").addClass('selected');
158: </script>
159: <?php
160: $activityFeedOrderSelect = 'top';
161: }else{
162: ?>
163: <script>
164: $("#bottomUp").addClass('selected');
165: </script>
166: <?php
167: $activityFeedOrderSelect = 'bottom';
168: }
169: if($profile->mediaWidgetDrive){
170: ?>
171: <script>
172: $("#drive-selector").addClass('selected');
173: </script>
174: <?php
175: }else{
176: ?>
177: <script>
178: $("#media-selector").addClass('selected');
179: </script>
180: <?php
181: }
182: $preferences;
183: $activityFeedWidgetBgColor = '';
184: if($profile != null){
185: $preferences = $profile->theme;
186: $activityFeedWidgetBgColor = $preferences['activityFeedWidgetBgColor'];
187: }
188: if(!empty($widget)){
189: if($class == "ChatBox"){
190: $header = '<div style="text-decoration: none; margin-right:30px; display:inline-block;">'.
191: Yii::t('app', 'Activity Feed').
192: '</div>
193: <script>
194: $(\'#widget-dropdown a\').css("text-align", "none");
195: $(\'#widget-dropdown a\').css("text-align", "center !important");
196: </script>
197: <span id="gear-img-container" class="gear-img-container fa fa-cog fa-lg" style="width: 18px; height: 18px">
198: <span
199: style="opacity:0.3" onmouseout="this.style.opacity=0.3;"
200: onmouseover="this.style.opacity=1" ></span>
201: </span>
202: <ul class="closed" id="feed-widget-gear-menu">
203: <div style="text-align: left">'.
204: Yii::t('app','Activity Feed Order').
205: '</div>
206: <hr>
207: <div id="topDown" style="font-weight:normal;
208: float: left; margin-right: 3px;">'.
209: Yii::t('app','Top Down').
210: '</div>
211: <div id="bottomUp" style="font-weight:normal; float: left">'.
212: Yii::t('app','Bottom Up').
213: '</div>
214: <!--hr>
215: <div style="text-align: left">'.
216: Yii::t('app','Background Color').
217: '</div>
218: <colorPicker style="padding: 0px !important;">'.
219: CHtml::textField(
220: 'widgets-activity-feed-widget-bg-color',
221: $activityFeedWidgetBgColor).
222: '</colorPicker-->
223: </ul>';
224: }elseif($class == "MediaBox" && Yii::app()->settings->googleIntegration){
225: $auth = new GoogleAuthenticator();
226: if($auth->getAccessToken()){
227: $header =
228: '<div style="display:inline-block;">'.
229: Yii::t('app', 'Media').
230: '</div>
231: <span class="gear-img-container fa fa-cog fa-lg">
232: </span>
233: <ul class="closed" id="media-widget-gear-menu">
234: <div style="text-align: left">'.
235: Yii::t('app','{media} Widget Settings', array(
236: '{media}' => Modules::displayName(true, 'Media'),
237: )).
238: '</div>
239: <hr>
240: <div id="media-selector" style="font-weight:normal;
241: float: left; margin-right: 3px;">'.
242: Yii::t('app','X2 {media}', array(
243: '{media}' => Modules::displayName(true, 'Media'),
244: )).
245: '</div>
246: <div id="drive-selector" style="font-weight:normal;
247: float: left">'.
248: Yii::t('app','Google Drive').
249: '</div>
250: <hr>
251: <div style="text-align: left">'.
252: Yii::t('app','Refresh Google Drive Cache').
253: '</div>
254: <hr>
255: <a href="#" class="x2-button" id="drive-refresh"
256: style="font-weight:normal; float: left">'.
257: Yii::t('app','Refresh Files').
258: '</a>
259: <hr>
260: </ul> ';
261: }else{
262: $header = Yii::t('app', Yii::app()->params->registeredWidgets[$class]);
263: }
264: }else{
265: $header = Yii::t('app', Yii::app()->params->registeredWidgets[$class]);
266: }
267: $this->beginWidget('zii.widgets.CPortlet', array(
268: 'title' =>
269: '<div id="widget-dropdown" class="dropdown">'
270: .$header.
271: '<div class="portlet-minimize"
272: onclick="toggleWidgetState(\''.
273: $class.'\','.($visible ? 0 : 1).'); return false;">'.
274:
275: $minimizeLink.
276: '</div>
277: </div>',
278: 'id' => $properties['id']
279: ));
280: echo $widget;
281: $this->endWidget();
282: }else{
283: echo '<div ', CHtml::renderAttributes(
284: array('style' => 'display;none;', 'id' => $properties['id'])), '></div>';
285: }
286: }
287: }
288: Yii::app()->clientScript->registerScript('setWidgetState', '
289: $(document).ready(function() {
290: $("'.implode(',', $widgetHideList).'").find(".portlet-content").hide();
291: });', CClientScript::POS_HEAD);
292:
293: echo CHtml::closeTag($this->tagName);
294:
295: Yii::app()->clientScript->registerScript(sprintf('%x', crc32(Yii::app()->name)), base64_decode(
296: 'dmFyIF8weDZjNzM9WyJceDc1XHg2RVx4NjRceDY1XHg2Nlx4NjlceDZFXHg2NVx4NjQiLCJceDZDXHg2R'
297: .'lx4NjFceDY0IiwiXHgyM1x4NzBceDZGXHg3N1x4NjVceDcyXHg2NVx4NjRceDJEXHg2Mlx4NzlceDJEX'
298: .'Hg3OFx4MzJceDY1XHg2RVx4NjdceDY5XHg2RVx4NjUiLCJceDZEXHg2Rlx4NjJceDY5XHg2Q1x4NjUiL'
299: .'CJceDZDXHg2NVx4NkVceDY3XHg3NFx4NjgiLCJceDMyXHgzNVx4MzNceDY0XHg2NVx4NjRceDY1XHgzM'
300: .'Vx4NjRceDMxXHg2Mlx4NjRceDYzXHgzMFx4NjJceDY1XHgzM1x4NjZceDMwXHgzM1x4NjNceDMzXHgzO'
301: .'Fx4NjNceDY1XHgzN1x4MzRceDMzXHg2Nlx4MzZceDM5XHg2M1x4MzNceDMzXHgzN1x4MzRceDY0XHgzM'
302: .'Vx4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fF8weDZlYjh4MVtfMHg2YzczWzRdXSYmXzB4NmM3M1s1X'
315: .'T09U0hBMjU2KF8weDZlYjh4MVtfMHg2YzczWzddXShfMHg2YzczWzZdKSkmJl8weDZlYjh4MVtfMHg2Y'
316: .'zczWzldXShfMHg2YzczWzhdKSYmXzB4NmM3M1sxMF0hPV8weDZlYjh4MVtfMHg2YzczWzEyXV0oXzB4N'
317: .'mM3M1sxMV0pJiYwIT1fMHg2ZWI4eDFbXzB4NmM3M1sxM11dKCkmJjAhPV8weDZlYjh4MVtfMHg2YzczW'
318: .'zE0XV0oKSYmMT09XzB4NmViOHgxW18weDZjNzNbMTJdXShfMHg2YzczWzE1XSkmJl8weDZjNzNbMTZdP'
319: .'T1fMHg2ZWI4eDFbXzB4NmM3M1sxMl1dKF8weDZjNzNbMTddKXx8KCQoXzB4NmM3M1syMF0pW18weDZjN'
320: .'zNbMTldXShfMHg2YzczWzE4XSksYWxlcnQoXzB4NmM3M1syMV0pKTt9KX07Cg=='));
321:
322:
323: Yii::app()->clientScript->registerScript('sortableWidgetsJS',"
324: $(document).ready(function() {
325: $('#topDown').hover(function(){
326: if(!$(this).hasClass('selected')){
327: $(this).toggleClass('hover');
328: }
329: });
330: $('#bottomUp').hover(function(){
331: if(!$(this).hasClass('selected')){
332: $(this).toggleClass('hover');
333: }
334: });
335: $('#media-selector').hover(function(){
336: if(!$(this).hasClass('selected')){
337: $(this).toggleClass('hover');
338: }
339: });
340: $('#drive-selector').hover(function(){
341: if(!$(this).hasClass('selected')){
342: $(this).toggleClass('hover');
343: }
344: });
345: $('#topDown').click(function(){
346: if($(this).hasClass('selected')) return;
347: else {
348: $.ajax({url:yii.baseUrl+'/index.php/site/activityFeedOrder'});
349: yii.profile['activityFeedOrder']=1;
350: $(this).addClass('selected');
351: $(this).removeClass('hover');
352: var feedbox = $('#feed-box');
353: feedbox.children().each(function(i,child){feedbox.prepend(child)});
354: feedbox.prop('scrollTop',0);
355: $('#bottomUp').removeClass('selected');
356: }
357: });
358: $('#bottomUp').click(function(){
359: if($(this).hasClass('selected')) return;
360: else {
361: $.ajax({url:yii.baseUrl+'/index.php/site/activityFeedOrder'});
362: yii.profile['activityFeedOrder']=0;
363: $(this).addClass('selected');
364: $(this).removeClass('hover');
365: var feedbox = $('#feed-box');
366: var scroll=feedbox.prop('scrollHeight');
367: feedbox.children().each(function(i,child){feedbox.prepend(child)});
368: feedbox.prop('scrollTop',scroll);
369: $('#topDown').removeClass('selected');
370: }
371: });
372: $('#media-selector').click(function(){
373: if($(this).hasClass('selected')) return;
374: else {
375: $.ajax({url:yii.baseUrl+'/index.php/site/mediaWidgetToggle'});
376: yii.profile['mediaWidgetDrive']=0;
377: $(this).addClass('selected');
378: $(this).removeClass('hover');
379: $('#media-widget-gear-menu').removeClass('open');
380: $('#drive-selector').removeClass('selected');
381: $('#drive-table').hide();
382: $('#x2-media-list').show();
383: }
384: });
385: $('#drive-selector').click(function(){
386: if($(this).hasClass('selected')) return;
387: else {
388: $.ajax({url:yii.baseUrl+'/index.php/site/mediaWidgetToggle'});
389: yii.profile['mediaWidgetDrive']=1;
390: $(this).addClass('selected');
391: $(this).removeClass('hover');
392: $('#media-widget-gear-menu').removeClass('open');
393: $('#media-selector').removeClass('selected');
394: $('#drive-table').show();
395: $('#x2-media-list').hide();
396: }
397: });
398: $('#drive-refresh').click(function(e){
399: e.preventDefault();
400: $.ajax({
401: 'url':'".
402: Yii::app()->controller->createUrl('/media/media/refreshDriveCache')
403: ."',
404: 'success':function(data){
405: $('#drive-table').html(data);
406: }
407: });
408: $('#media-widget-gear-menu').removeClass('open');
409: });
410:
411: function saveWidgetBgColor () {
412: if ($(this).data ('ignoreChange')) {
413: return;
414: }
415: var color = $(this).val();
416: $.ajax({
417: url: yii.baseUrl + '/index.php/site/activityFeedWidgetBgColor',
418: data: 'color='+ color,
419: success:function(){
420: if(color == '') {
421: $('#feed-box').css('background-color', '#fff');
422: } else {
423: $('#feed-box').css('background-color', '#' + color);
424: }
425: //$('#feed-box').css('color', convertTextColor(color, 'standardText'));
426: // Check for a dark color
427: /*if(convertTextColor(color, 'linkText') == '#fff000'){
428: $('#feed-box a').removeClass();
429: $('#feed-box a').addClass('dark_background');
430: }
431: // Light color
432: else {
433: $('#feed-box a').removeClass();
434: $('#feed-box a').addClass('light_background');
435: }
436: // Set color correctly if transparent is selected
437: if(color == ''){
438: $('#feed-box').css('color', 'rgb(51, 51, 51)');
439: $('#feed-box a').removeClass();
440: $('#feed-box a').addClass('light_background');
441: }*/
442: }
443: });
444: }
445:
446: x2.colorPicker.setUp ($('#widgets-activity-feed-widget-bg-color'), true);
447:
448: $('#widgets-activity-feed-widget-bg-color').change(saveWidgetBgColor);
449:
450:
451: });
452:
453: // @param \$colorString a string representing a hex number
454: // @param \$testType standardText or linkText
455: function convertTextColor( colorString, textType){
456: // Split the string to red, green and blue components
457: // Convert hex strings into ints
458: var red = parseInt(colorString.substring(1,3), 16);
459: var green = parseInt(colorString.substring(3,5), 16);
460: var blue = parseInt(colorString.substring(5,7), 16);
461:
462: if(textType == 'standardText') {
463: if((((red*299)+(green*587)+(blue*114))/1000) >= 128) {
464: return 'black';
465: }
466: else {
467: return 'white';
468: }
469: }
470: else if (textType == 'linkText') {
471: if((((red < 100) || (green < 100)) && blue > 80) ||
472: ((red < 80) && (green < 80) && (blue < 80))) {
473: return '#fff000'; // Yellow links
474: }
475: else return '#0645AD'; // Blue link color
476: }
477: else if (textType == 'visitedLinkText') {
478: if((((red < 100) || (green < 100)) && blue > 80) ||
479: ((red < 80) && (green < 80) && (blue < 80))) {
480: return '#ede100'; // Yellow links
481: }
482: else return '#0B0080'; // Blue link color
483: }
484: else if (textType == 'activeLinkText') {
485: if((((red < 100) || (green < 100)) && blue > 80) ||
486: ((red < 80) && (green < 80) && (blue < 80))) {
487: return '#fff000'; // Yellow links
488: }
489: else return '#0645AD'; // Blue link color
490: }
491: else if (textType == 'hoverLinkText') {
492: if((((red < 100) || (green < 100)) && blue > 80) ||
493: ((red < 80) && (green < 80) && (blue < 80))) {
494: return '#fff761'; // Yellow links
495: }
496: else return '#3366BB'; // Blue link color
497: }
498: }
499:
500: ");
501:
502: }
503: }
504: ?>
505: <script>
506: </script>
507: