Recent Topics

Option to activate / deactivate a widget

Started by on Jun 09, 2008 – Contents updated: Jun 09, 2008

Jun 09, 2008 14:11    

Hello,

I prepared a widget base on free html widget. I do not want to display it now, but this evening when I will be at home and have time to test it.

It will be great if we have an option to activate / deactivate a widget like on plugin page.

Jun 13, 2008 15:31

Tblue

I would be very interested.
Never saw your original post... sorry
My mind thinks teh same as yours and I have the same concerns (me tech guy of the group blog and the others are technical netwits (but they can write like hell)

Jun 13, 2008 17:42

Great. :) So here it is:


diff -ur a/inc/widgets/model/_widget.class.php blogs/inc/widgets/model/_widget.class.php
--- a/inc/widgets/model/_widget.class.php	2008-04-27 22:09:28.000000000 +0200
+++ blogs/inc/widgets/model/_widget.class.php	2008-06-12 18:18:50.000000000 +0200
@@ -41,6 +41,10 @@
 	var $sco_name;
 	var $order;
 	/**
+	 * @var bool Whether to show the widget or not.
+	 */
+    var $show;
+	/**
 	 * @var string Type of the plugin ("core" or "plugin")
 	 */
 	var $type;
@@ -92,6 +96,7 @@
 			$this->code     = $db_row->wi_code;
 			$this->params   = $db_row->wi_params;
 			$this->order    = $db_row->wi_order;
+			$this->show     = $db_row->wi_show;
 		}
 	}
 
@@ -723,4 +728,4 @@
 
 
 
-?>
\ Kein Zeilenumbruch am Dateiende.
+?>
diff -ur a/inc/widgets/views/_widget_list.view.php blogs/inc/widgets/views/_widget_list.view.php
--- a/inc/widgets/views/_widget_list.view.php	2008-04-27 22:09:28.000000000 +0200
+++ blogs/inc/widgets/views/_widget_list.view.php	2008-06-12 17:54:02.000000000 +0200
@@ -104,6 +104,10 @@
 			{	// The name is customized and the short desc may be relevant additional info
 				$widget_name .= ' ('.$ComponentWidget->get_short_desc().')';
 			}
+			if (!$ComponentWidget->get('show')) // widget is hidden...
+			{
+                $widget_name .= ' ['.T_('Hidden').']'; // ...so let's show this in the widget title.
+            }
 			echo '<a href="'.regenerate_url( 'blog', 'action=edit&amp;wi_ID='.$ComponentWidget->ID).'">'.$widget_name.'</a>';
 			$Table->display_col_end();
 
@@ -135,6 +139,7 @@
 
 			// Actions
 			$Table->display_col_start();
+			echo $ComponentWidget->get('show') ? action_icon( T_('Hide this widget!'), 'deactivate', regenerate_url( 'blog', 'action=toggle&amp;wi_ID='.$ComponentWidget->ID )) : action_icon( T_('Show this widget!'), 'activate', regenerate_url( 'blog', 'action=toggle&amp;wi_ID='.$ComponentWidget->ID ));
 			echo action_icon( T_('Edit widget settings!'), 'edit', regenerate_url( 'blog', 'action=edit&amp;wi_ID='.$ComponentWidget->ID ) );
 			echo action_icon( T_('Remove this widget!'), 'delete', regenerate_url( 'blog', 'action=delete&amp;wi_ID='.$ComponentWidget->ID ) );
 			$Table->display_col_end();
@@ -173,4 +178,4 @@
 echo '<script type="text/javascript">addEvent( window, "load", Fat.fade_all, false);</script>';
 
 
-?>
\ Kein Zeilenumbruch am Dateiende.
+?>
diff -ur a/inc/widgets/widgets.ctrl.php blogs/inc/widgets/widgets.ctrl.php
--- a/inc/widgets/widgets.ctrl.php	2008-04-27 22:09:28.000000000 +0200
+++ blogs/inc/widgets/widgets.ctrl.php	2008-06-12 17:58:45.000000000 +0200
@@ -53,6 +53,7 @@
 	case 'delete':
 	case 'move_up':
 	case 'move_down':
+	case 'toggle':
 		param( 'wi_ID', 'integer', true );
 		$WidgetCache = & get_Cache( 'WidgetCache' );
 		$edited_ComponentWidget = & $WidgetCache->get_by_ID( $wi_ID );
@@ -126,6 +127,7 @@
 
 		$edited_ComponentWidget->set( 'coll_ID', $Blog->ID );
 		$edited_ComponentWidget->set( 'sco_name', $container );
+		$edited_ComponentWidget->set('show', 1);
 
 		// INSERT INTO DB:
 		$edited_ComponentWidget->dbinsert();
@@ -229,6 +231,21 @@
  	case 'list':
 		break;
 
+    case 'toggle':
+        if ($edited_ComponentWidget->get('show') == 1)
+        {
+            $Messages->add(T_('Widget has been hidden'), 'success');
+            $edited_ComponentWidget->set('show', 0);
+        }
+        else
+        {
+            $Messages->add(T_('Widget has been shown'), 'success');
+            $edited_ComponentWidget->set('show', 1);
+        }
+        $edited_ComponentWidget->dbupdate();
+        $action = 'list';
+        break;
+
 	default:
 		debug_die( 'Action: unhandled action' );
 }
@@ -303,4 +320,4 @@
 
 
 
-?>
\ Kein Zeilenumbruch am Dateiende.
+?>
diff -ur a/inc/skins/model/_skin.class.php blogs/inc/skins/model/_skin.class.php
--- a/inc/skins/model/_skin.class.php	2008-04-27 22:09:28.000000000 +0200
+++ blogs/inc/skins/model/_skin.class.php	2008-06-12 17:49:42.000000000 +0200
@@ -164,6 +164,8 @@
 		{
 			foreach( $Widget_array as $ComponentWidget )
 			{
+			    // skip this widget if it's hidden
+			    if (!$ComponentWidget->get('show')) continue;
 				// Let the Widget display itself (with contextual params):
 				$ComponentWidget->display( $params );
 			}
@@ -428,4 +430,4 @@
 
 
 
-?>
\ Kein Zeilenumbruch am Dateiende.
+?>


Simply patch in your b2evo root directory (the blogs folder) with: patch -p1 < path/to/patchfile
You will have to modify your database:

ALTER TABLE `evo_widget` ADD `wi_show` BOOL NOT NULL DEFAULT '1' AFTER `wi_order`;

Have fun. ;)

Tblue

Jun 13, 2008 18:01

ok, I must confess, I'm not that tech after all ;)
I have no clue what you are saying...

Jun 13, 2008 18:48

Ok then. ;) I zipped the modified files for you, simply replace your old ones (don't forget to back them up).
http://files.ax86.net/b2evo/b2evo-widgets.zip

If you've the phpMyAdmin tool installed, log in, select your b2evo database, click on the SQL tab and enter the SQL command from my previous post (if your table prefix is not 'evo' replace it with your prefix). That's it... If you've another MySQL administration tool, it should by similiar to use. :)

Jun 13, 2008 20:38

Thanks tblue, I will test it

Jun 13, 2008 21:29

wonderfull!
wonderfull!
wonderfull!

(btw it works ;))

Jun 21, 2008 18:55

awesome , thank you, worked out pretty well, very useful, i see no harm of suggesting this being included in the core next time :roll:

great :( another reason not to upgrade :/

Jun 22, 2008 09:23

tilqicom wrote:

awesome , thank you, worked out pretty well, very useful, i see no harm of suggesting this being included in the core next time :roll

I asked F. Planque about how to integrate bugs or features coming from the forum to the core. I guess the problem is to not create regression bug when doing this.


Form is loading...

Forums software – This forum is powered by b2evolution CMS, a complete engine for your website.