Nucleusのif文を拡張しよう Nucleusのif文を拡張しよう パート2


///nucleus/libs/ACTIONS.phpを改造する。 //category function _ifCategory($name = '', $value='') { global $blog, $catid; $pattern= '/^'.$catid.'\||\|'.$catid.'\||\|'.$catid.'$/'; if (($name == 'catid') && ($catid != "")){ if (preg_match($pattern,$value)=='1') { return $blog->isValidCategory($catid); } } // when no parameter is defined, just check if a category is selected if (($name != 'catname' && $name != 'catid') || ($value == '')) return $blog->isValidCategory($catid); // check category name if ($name == 'catname') { $value = $blog->getCategoryIdFromName($value); if ($value == $catid) return $blog->isValidCategory($catid); } // check category id if (($name == 'catid') && ($value == $catid)) return $blog->isValidCategory($catid); return false; } これを行なうことでif,ifnotを下記のように拡張します。 先ほどの例のif文を下記のように短縮できて見やすくなります。 if文を複数並べる際に便利です。 <%if(category,catid,1)%>表示したい内容<%endif%> <%if(category,catid,3)%>表示したい内容<%endif%> <%if(category,catid,5)%>表示したい内容<%endif%> ↓ <%if(category,catid,1|3|5)%>表示したい内容<%endif%> //item 具体的にはfunction checkCondition()の3行目に「,$itemid」を追加して「case item:」のブロックを追加しただけです。 これでアイテムIDの判定が下記の書式でできるようになります。 <%if(item,itemid,アイテムID)%>