Пример #1
0
 /**
  * Get Menu name
  *
  * @param $value
  * @param $skipMenuItems
  * @return bool|string
  */
 static function getMenuName(&$value, &$skipMenuItems)
 {
     // we need to localise the menu labels (CRM-5456) and don’t
     // want to use ts() as it would throw the ts-extractor off
     $i18n = CRM_Core_I18n::singleton();
     $name = $i18n->crm_translate($value['attributes']['label'], array('context' => 'menu'));
     $url = $value['attributes']['url'];
     $permission = $value['attributes']['permission'];
     $operator = $value['attributes']['operator'];
     $parentID = $value['attributes']['parentID'];
     $navID = $value['attributes']['navID'];
     $active = $value['attributes']['active'];
     $menuName = $value['attributes']['name'];
     $target = CRM_Utils_Array::value('target', $value['attributes']);
     if (in_array($parentID, $skipMenuItems) || !$active) {
         $skipMenuItems[] = $navID;
         return FALSE;
     }
     //we need to check core view/edit or supported acls.
     if (in_array($menuName, array('Search...', 'Contacts'))) {
         if (!CRM_Core_Permission::giveMeAllACLs()) {
             $skipMenuItems[] = $navID;
             return FALSE;
         }
     }
     $config = CRM_Core_Config::singleton();
     $makeLink = FALSE;
     if (isset($url) && $url) {
         if (substr($url, 0, 4) === 'http') {
             $url = $url;
         } else {
             //CRM-7656 --make sure to separate out url path from url params,
             //as we'r going to validate url path across cross-site scripting.
             $urlParam = CRM_Utils_System::explode('&', str_replace('?', '&', $url), 2);
             $url = CRM_Utils_System::url($urlParam[0], $urlParam[1], FALSE, NULL, TRUE);
         }
         $makeLink = TRUE;
     }
     static $allComponents;
     if (!$allComponents) {
         $allComponents = CRM_Core_Component::getNames();
     }
     if (isset($permission) && $permission) {
         $permissions = explode(',', $permission);
         $hasPermission = FALSE;
         foreach ($permissions as $key) {
             $key = trim($key);
             $showItem = TRUE;
             //get the component name from permission.
             $componentName = CRM_Core_Permission::getComponentName($key);
             if ($componentName) {
                 if (!in_array($componentName, $config->enableComponents) || !CRM_Core_Permission::check($key)) {
                     $showItem = FALSE;
                     if ($operator == 'AND') {
                         $skipMenuItems[] = $navID;
                         return $showItem;
                     }
                 } else {
                     $hasPermission = TRUE;
                 }
             } elseif (!CRM_Core_Permission::check($key)) {
                 $showItem = FALSE;
                 if ($operator == 'AND') {
                     $skipMenuItems[] = $navID;
                     return $showItem;
                 }
             } else {
                 $hasPermission = TRUE;
             }
         }
         if (!$showItem && !$hasPermission) {
             $skipMenuItems[] = $navID;
             return FALSE;
         }
     }
     if ($makeLink) {
         if ($target) {
             $name = "<a href=\"{$url}\" target=\"{$target}\">{$name}</a>";
         } else {
             $name = "<a href=\"{$url}\">{$name}</a>";
         }
     }
     return $name;
 }
Пример #2
0
 /**
  *  Get Menu name
  */
 function getMenuName(&$value, &$skipMenuItems)
 {
     // we need to localise the menu labels (CRM-5456) and don’t
     // want to use ts() as it would throw the ts-extractor off
     $i18n =& CRM_Core_I18n::singleton();
     $name = $i18n->crm_translate($value['attributes']['label'], array('context' => 'menu'));
     $url = str_replace('&', '&amp;', $value['attributes']['url']);
     $permission = $value['attributes']['permission'];
     $operator = $value['attributes']['operator'];
     $parentID = $value['attributes']['parentID'];
     $navID = $value['attributes']['navID'];
     $active = $value['attributes']['active'];
     $menuName = $value['attributes']['name'];
     if (in_array($parentID, $skipMenuItems) || !$active) {
         $skipMenuItems[] = $navID;
         return false;
     }
     //we need to check core view/edit or supported acls.
     require_once 'CRM/Core/Permission.php';
     if (in_array($menuName, array('Search...', 'Contacts'))) {
         if (!CRM_Core_Permission::giveMeAllACLs()) {
             $skipMenuItems[] = $navID;
             return false;
         }
     }
     $config = CRM_Core_Config::singleton();
     $makeLink = false;
     if (isset($url) && $url) {
         if (substr($url, 0, 4) === 'http') {
             $url = $url;
         } else {
             $url = CRM_Utils_System::url($url);
         }
         $makeLink = true;
     }
     static $allComponents;
     if (!$allComponents) {
         $allComponents = CRM_Core_Component::getNames();
     }
     if (isset($permission) && $permission) {
         $permissions = explode(',', $permission);
         $hasPermission = false;
         foreach ($permissions as $key) {
             $key = trim($key);
             $showItem = true;
             //get the component name from permission.
             $componentName = CRM_Core_Permission::getComponentName($key);
             if ($componentName) {
                 if (!in_array($componentName, $config->enableComponents) || !CRM_Core_Permission::check($key)) {
                     $showItem = false;
                     if ($operator == 'AND') {
                         $skipMenuItems[] = $navID;
                         return $showItem;
                     }
                 } else {
                     $hasPermission = true;
                 }
             } else {
                 if (!CRM_Core_Permission::check($key)) {
                     $showItem = false;
                     if ($operator == 'AND') {
                         $skipMenuItems[] = $navID;
                         return $showItem;
                     }
                 } else {
                     $hasPermission = true;
                 }
             }
         }
         if (!$showItem && !$hasPermission) {
             $skipMenuItems[] = $navID;
             return false;
         }
     }
     if ($makeLink) {
         return $name = "<a href=\"{$url}\">{$name}</a>";
     }
     return $name;
 }