1.0.14J-r9
php 5.5.19
mysql 5.0.95
apache 2.2
----------------
phxを調べています。
isinrole(ir,memberof,mo)とinroleが機能していないようなので、
phx.parser.class.inc.phpをいじって動くようにしみましたので報告です。
変更はしてみましたが、
実際の動作がそのようなものなのか、またPHP自体がよくわからないので変更後が合っているのかわかりません。
最初はエラーがでていました。
Error : array_key_exists() expects parameter 2 to be array, null given
変更後の挙動
変数が「&_PHX_INTERNAL_&」の場合、ウェブユーザーのIDを取得して判定
指定のウェブユーザーIDが指定のグループに所属していたらtrue、していなければfalse
コード: 全て選択
[*phx:if(&_PHX_INTERNAL_&):isinrole(ウェブユーザーのグループ名1,ウェブユーザーのグループ名2):then(true):else(false)*]
[*phx:if(ウェブユーザーID):isinrole(ウェブユーザーのグループ名):then(true):else(false)*]
指定のユーザーIDが指定のグループに所属していたら1、していなければ0を出力
コード: 全て選択
[*phx:if(ウェブユーザーID):inrole(ウェブユーザーのグループ名1,ウェブユーザーのグループ名2)*]
変更箇所
214〜222行目くらい
$modifier_valueが指定されていなかったみたいなので$optに変更してみました。
if ($value == '&_PHX_INTERNAL_&') $value = $this->user['id'];が何かわからなかったので、
ウェブログインした時の判定だと思ってみました。
変更前
コード: 全て選択
case 'isinrole':
case 'ir':
case 'memberof':
case 'mo':
// Is Member Of (same as inrole but this one can be stringed as a conditional)
if ($value == '&_PHX_INTERNAL_&') $value = $this->user['id']; //変更箇所ここから
$grps = ($this->strlen($modifier_value) > 0 ) ? explode(',',$opt) :array(); //変更箇所ここまで
$condition[] = intval($this->isMemberOfWebGroupByUserId($value,$grps));
break;
コード: 全て選択
case 'isinrole':
case 'ir':
case 'memberof':
case 'mo':
// Is Member Of (same as inrole but this one can be stringed as a conditional)
if ($value == '&_PHX_INTERNAL_&') $value = $modx->getLoginUserID('web'); //変更箇所ここから
if (empty($value)){ $condition[] = intval(false);
return $conditional;
}
$grps = ($this->strlen($opt) > 0 ) ? explode(',', $opt) :array(); //変更箇所ここまで
$condition[] = intval($this->isMemberOfWebGroupByUserId($value,$grps));
break;
713〜740行目くらい
変更したら先のエラーは出なくなりました。
$this->cache['mo']が何かよくわかりませんがnullっぽいです。
ユーザーの配列とoptの配列を比較しているところまではわかりました。
変更前
コード: 全て選択
function isMemberOfWebGroupByUserId($userid=0,$groupNames=array()) {
global $modx;
// if $groupNames is not an array return false
if(!is_array($groupNames)) return false;
// if the user id is a negative number make it positive
if (intval($userid) < 0) { $userid = -($userid); }
// Creates an array with all webgroups the user id is in
if (!array_key_exists($userid, $this->cache['mo'])) //変更箇所ここから
{
$tbl_webgroup_names = $modx->getFullTableName('webgroup_names');
$tbl_web_groups = $modx->getFullTableName('web_groups');
$sql = "SELECT wgn.name FROM {$tbl_webgroup_names} wgn INNER JOIN {$tbl_web_groups} wg ON wg.webgroup=wgn.id AND wg.webuser='{$userid}'";
$this->cache['mo'][$userid] = $grpNames = $modx->db->getColumn('name',$sql);
}
else $grpNames = $this->cache['mo'][$userid]; //変更箇所ここまで
// Check if a supplied group matches a webgroup from the array we just created
foreach($groupNames as $k=>$v)
{
if(in_array(trim($v),$grpNames)) return true;
}
// If we get here the above logic did not find a match, so return false
return false;
}
コード: 全て選択
function isMemberOfWebGroupByUserId($userid=0,$groupNames=array()) {
global $modx;
// if $groupNames is not an array return false
if(!is_array($groupNames)) return false;
// if the user id is a negative number make it positive
if (intval($userid) < 0) { $userid = -($userid); }
// Creates an array with all webgroups the user id is in
$tbl_webgroup_names = $modx->getFullTableName('webgroup_names');//変更箇所ここから
$tbl_web_groups = $modx->getFullTableName('web_groups');
$sql = "SELECT wgn.name FROM {$tbl_webgroup_names} wgn INNER JOIN {$tbl_web_groups} wg ON wg.webgroup=wgn.id AND wg.webuser='{$userid}'";
$grpNames = $modx->db->getColumn('name',$sql);//変更箇所ここまで
// Check if a supplied group matches a webgroup from the array we just created
foreach($groupNames as $k=>$v)
{
if(in_array(trim($v),$grpNames)) return true;
}
// If we get here the above logic did not find a match, so return false
return false;
}