[xoops-cvslog 2646] CVS update: xoops2jp/html/class/smarty/plugins

アーカイブの一覧に戻る

Minahito minah****@users*****
2006年 4月 6日 (木) 12:38:37 JST


Index: xoops2jp/html/class/smarty/plugins/function.xoops_optionsArray.php
diff -u /dev/null xoops2jp/html/class/smarty/plugins/function.xoops_optionsArray.php:1.1.2.1
--- /dev/null	Thu Apr  6 12:38:37 2006
+++ xoops2jp/html/class/smarty/plugins/function.xoops_optionsArray.php	Thu Apr  6 12:38:37 2006
@@ -0,0 +1,47 @@
+<?php
+
+/*
+ * Smarty plugin
+ * -------------------------------------------------------------
+ * Type:     function
+ * Name:     xoops_optionsArray
+ * Version:  0.1
+ * Date:     Apr 6, 2006
+ * Author:   minahito
+ * Purpose:  Build option tags from array of object who have value and text in 
+             own properties.
+ * Input:    from = template variable that is array of object 
+ *           label = property name to get the text.
+ *           value = property name to get the value.
+ *           default = selected value. variable (include Array).
+ * 
+ * -------------------------------------------------------------
+ */
+function smarty_function_xoops_optionsArray($params, &$smarty)
+{
+	//
+	// We should check more.
+	//
+	$tags = "";
+	$objectArr =& $params['from'];
+	$default = isset($params['default']) ? $params['default'] : null;
+
+	foreach ($objectArr as $object) {
+		$value = htmlspecialchars($object->get($params['value']), ENT_QUOTES);
+		$label = htmlspecialchars($object->get($params['label']), ENT_QUOTES);
+		
+		$selected = "";
+		if (is_array($default) && in_array($default, $object->get($params['value']))) {
+			$selected = " selected";
+		}
+		elseif (!is_array($default) && $object->get($params['value']) == $default) {
+			$selected = " selected";
+		}
+		
+		$tags .= "<option value=\"${value}\"${selected}>${label}</option>\n";
+	}
+	
+	print $tags;
+}
+
+?>


xoops-cvslog メーリングリストの案内
アーカイブの一覧に戻る