/** * Get checkbox html * * @param int $menuId * @param string $uri * @return string */ private static function getCheckboxHtml($menuId, $uri) { $routesData = Di::getDefault()->get('router')->getRoutes(); $str = "<span class=\"nestable_cb\">"; $cbArray = array(); foreach ($routesData as $data) { if (strstr($data['route'], $uri) && $data['acl']) { $cbArray[$data['acl']] = true; } } $acldata = 0; if (isset(self::$aclmenudata[$menuId])) { $acldata = self::$aclmenudata[$menuId]; } $tmp = "<span class=\"acl_cb\">%s <input type=\"checkbox\" name=\"acl_%s[{$menuId}]\" %s></input></span>"; if (isset($cbArray[Acl::ADD])) { $checked = Acl::isFlagSet($acldata, Acl::ADD) ? 'checked' : ''; $str .= sprintf($tmp, _('Create'), 'create', $checked); } if (isset($cbArray[Acl::DELETE])) { $checked = Acl::isFlagSet($acldata, Acl::DELETE) ? 'checked' : ''; $str .= sprintf($tmp, _('Delete'), 'delete', $checked); } if (isset($cbArray[Acl::UPDATE])) { $checked = Acl::isFlagSet($acldata, Acl::UPDATE) ? 'checked' : ''; $str .= sprintf($tmp, _('Update'), 'update', $checked); } if (isset($cbArray[Acl::VIEW])) { $checked = Acl::isFlagSet($acldata, Acl::VIEW) ? 'checked' : ''; $str .= sprintf($tmp, _('View'), 'view', $checked); } if (isset($cbArray[Acl::ADVANCED])) { $checked = Acl::isFlagSet($acldata, Acl::ADVANCED) ? 'checked' : ''; $str .= sprintf($tmp, _('Advanced'), 'advanced', $checked); } $str .= "</span>"; return $str; }
/** * Get routes * * @return array */ public static function getRoutes() { $tempo = array(); $obj = get_called_class(); $ref = new \ReflectionClass(get_called_class()); foreach ($ref->getMethods() as $method) { $methodName = $method->getName(); if (substr($methodName, -6) == 'Action') { foreach (explode("\n", $method->getDocComment()) as $line) { $str = trim(str_replace("* ", '', $line)); if (substr($str, 0, 6) == '@route') { $route = substr($str, 6); $objExp = explode('\\', $obj); $nbOcc = count($objExp) - 1; $finalName = substr($objExp[$nbOcc], 0, strlen($objExp[$nbOcc]) - 3); $route = str_replace('{object}', strtolower($finalName), $route); $tempo[$methodName]['route'] = trim($route); } elseif (substr($str, 0, 7) == '@method') { $method_type = strtoupper(substr($str, 7)); $tempo[$methodName]['method_type'] = trim($method_type); } elseif (substr($str, 0, 4) == '@acl') { $aclFlags = explode(",", trim(substr($str, 4))); $tempo[$methodName]['acl'] = Acl::convertAclFlags($aclFlags); } elseif (substr($str, 0, 5) == '@auth') { $tempo[$methodName]['auth'] = true; } elseif (substr($str, 0, 4) == '@api') { $route = substr($str, 4); /* @todo better */ $objExp = explode('\\', $obj); $nbOcc = count($objExp) - 1; $finalName = substr($objExp[$nbOcc], 0, strlen($objExp[$nbOcc]) - 3); $route = str_replace('{object}', strtolower($finalName), $route); $tempo[$methodName]['api_route'] = trim($route); } elseif (substr($str, 0, 6) == '@since') { $version = substr($str, 6); $tempo[$methodName]['api_version'] = trim($version); } } if (isset($tempo[$methodName]['auth']) && $tempo[$methodName]['auth']) { if (isset($tempo[$methodName]['route'])) { static::$routeAuth[] = '\\' . $obj . '::' . $methodName; } } } } return $tempo; }
/** * Get routes * * @return array */ public static function getRoutes() { $tempo = array(); $className = get_called_class(); $ref = new \ReflectionClass($className); foreach ($ref->getMethods() as $method) { $methodName = $method->getName(); if (substr($methodName, -6) == 'Action') { foreach (explode("\n", $method->getDocComment()) as $line) { $str = trim(str_replace("* ", '', $line)); if (substr($str, 0, 6) == '@route') { $route = substr($str, 6); if (isset($className::$objectName)) { $route = str_replace("{object}", $className::$objectName, $route); } $tempo[$methodName]['route'] = trim($route); } elseif (substr($str, 0, 7) == '@method') { $method_type = strtoupper(substr($str, 7)); $tempo[$methodName]['method_type'] = trim($method_type); } elseif (substr($str, 0, 4) == '@acl') { $aclFlags = explode(",", trim(substr($str, 4))); $tempo[$methodName]['acl'] = Acl::convertAclFlags($aclFlags); } } } } return $tempo; }