[Fusionforge-commits] r11033 - in trunk: src/plugins/blocks/common tests/func/PluginsBlocks

Alain Peyrat aljeux at libremir.placard.fr.eu.org
Sat Oct 16 10:27:15 CEST 2010


Author: aljeux
Date: 2010-10-16 10:27:15 +0200 (Sat, 16 Oct 2010)
New Revision: 11033

Modified:
   trunk/src/plugins/blocks/common/blocksPlugin.class.php
   trunk/tests/func/PluginsBlocks/blocksTest.php
Log:
Clean code in blocks plugin, now use methods from Plugin class

Modified: trunk/src/plugins/blocks/common/blocksPlugin.class.php
===================================================================
--- trunk/src/plugins/blocks/common/blocksPlugin.class.php	2010-10-16 08:27:08 UTC (rev 11032)
+++ trunk/src/plugins/blocks/common/blocksPlugin.class.php	2010-10-16 08:27:15 UTC (rev 11033)
@@ -58,59 +58,32 @@
 	}
 
 	function CallHook ($hookname, $params) {
-		global $use_blocksplugin,$G_SESSION,$HTML;
-		if ($hookname == "groupisactivecheckbox") {
-		    $group_id=$params['group'];
-			//Check if the group is active
-			// this code creates the checkbox in the project edit public info page to activate/deactivate the plugin
-			$group = &group_get_object($group_id);
-			echo "<tr>";
-			echo "<td>";
-			echo ' <input type="checkbox" name="use_blocksplugin" value="1" ';
-			// checked or unchecked?
-			if ( $group->usesPlugin ( $this->name ) ) {
-				echo "checked=\"checked\"";
-			}
-			echo " /><br/>";
-			echo "</td>";
-			echo "<td>";
-			echo "<strong>Use ".$this->text." Plugin</strong>";
-			echo "</td>";
-			echo "</tr>";
-		} elseif ($hookname == "groupisactivecheckboxpost") {
-		    $group_id=$params['group'];
-			// this code actually activates/deactivates the plugin after the form was submitted in the project edit public info page
-			$group = &group_get_object($group_id);
-			$use_blocksplugin = getStringFromRequest('use_blocksplugin');
-			if ( $use_blocksplugin == 1 ) {
-				$group->setPluginUse ( $this->name );
-			} else {
-				$group->setPluginUse ( $this->name, false );
-			}
-		} elseif ($hookname == "project_admin_plugins") {
+		if ($hookname == "project_admin_plugins") {
 			// this displays the link in the project admin options page to it's  blocks administration
 			$group_id = $params['group_id'];
-			$group = &group_get_object($group_id);
+			$group = group_get_object($group_id);
 			if ( $group->usesPlugin ( $this->name ) ) {
 				echo '<p><a href="/plugins/blocks/index.php?id=' . $group->getID() . '&amp;type=admin&amp;pluginname=' . $this->name . '">' . _("Blocks Admin") . '</a></p>';
 			}
-		}												    
-		elseif ($hookname == "blocks") {
-			// Check if block is active and if yes, display the block.
-			// Return true if plugin is active, false otherwise.
-			$group = &group_get_object($GLOBALS['group_id']);
-			if ( $group && $group->usesPlugin ( $this->name ) ) {
-				
-				$c = $this->renderBlock($params);
-				if ($c !== false) {
-					echo $c;
-					return true;
-				}
-			}
-			return false;
+		} elseif ($hookname == "blocks") {
+			return $this->blocks($params);
 		} 
 	}
-	
+	function blocks($params) {
+		// Check if block is active and if yes, display the block.
+		// Return true if plugin is active, false otherwise.
+		$group = group_get_object($GLOBALS['group_id']);
+		if ( $group && $group->usesPlugin ( $this->name ) ) {
+
+			$c = $this->renderBlock($params);
+			if ($c !== false) {
+				echo $c;
+				return true;
+			}
+		}
+		return false;
+	}
+
 	function renderBlock($name) {
 		$group_id = $GLOBALS['group_id'];
 		$res = db_query_params('SELECT content
@@ -135,10 +108,10 @@
 	function parseContent($t) {
 		global $HTML;
 
-		$t = preg_replace('/<p>{boxTop (.*?)}<\/p>/ie', '$HTML->boxTop("$1")', $t);
-		$t = preg_replace('/{boxTop (.*?)}/ie', '$HTML->boxTop("$1")', $t);
-		$t = preg_replace('/<p>{boxMiddle (.*?)}<\/p>/ie', '$HTML->boxMiddle("$1")', $t);
-		$t = preg_replace('/{boxMiddle (.*?)}/ie', '$HTML->boxMiddle("$1")', $t);
+		$t = preg_replace('/<p>{boxTop (.*?)}<\/p>/ie', '$HTML->boxTop(\'$1\')', $t);
+		$t = preg_replace('/{boxTop (.*?)}/ie', '$HTML->boxTop(\'$1\')', $t);
+		$t = preg_replace('/<p>{boxMiddle (.*?)}<\/p>/ie', '$HTML->boxMiddle(\'$1\')', $t);
+		$t = preg_replace('/{boxMiddle (.*?)}/ie', '$HTML->boxMiddle(\'$1\')', $t);
 		$t = preg_replace('/<p>{boxBottom}<\/p>/i', $HTML->boxBottom(), $t);
 		$t = preg_replace('/{boxBottom}/i', $HTML->boxBottom(), $t);
 

Modified: trunk/tests/func/PluginsBlocks/blocksTest.php
===================================================================
--- trunk/tests/func/PluginsBlocks/blocksTest.php	2010-10-16 08:27:08 UTC (rev 11032)
+++ trunk/tests/func/PluginsBlocks/blocksTest.php	2010-10-16 08:27:15 UTC (rev 11033)
@@ -58,7 +58,7 @@
     $this->waitForPageToLoad("30000");
     $this->click("link=Tools");
     $this->waitForPageToLoad("30000");
-    $this->click("use_blocksplugin");
+    $this->click("use_blocks");
     $this->click("submit");
     $this->waitForPageToLoad("30000");
     $this->assertTrue($this->isTextPresent("Project information updated"));




More information about the Fusionforge-commits mailing list