Example #1
0
 /**
  * Trim script name menu path.
  *
  * @param array $scripts
  *
  * @return array
  */
 protected function trimMenuPath(array $scripts)
 {
     foreach ($scripts as &$script) {
         if (!isset($script['name'])) {
             continue;
         }
         $path = splitPath($script['name'], false);
         $script['name'] = '';
         foreach ($path as $item) {
             $script['name'] .= trim($item) . '/';
         }
         $script['name'] = substr($script['name'], 0, strlen($script['name']) - 1);
     }
     unset($script);
     return $scripts;
 }
Example #2
0
/**
 * Extracts the path of a filename.
 * For example $filename is "foo/bar/test.txt"
 * the function returns "foo/bar"
 */
function getPath($filename)
{
    $elements = splitPath($filename);
    unset($elements[count($elements) - 1]);
    $path = catArray($elements, "/");
    return $path;
}
 /**
  * Prepare data for map menu popup.
  *
  * @param string $hostId					host id
  * @param array  $scripts					host scripts (optional)
  * @param string $scripts[]['name']			script name
  * @param string $scripts[]['scriptid']		script id
  * @param string $scripts[]['confirmation']	confirmation text
  * @param array  $gotos						goto links (optional)
  * @param array  $gotos['graphs']			link to host graphs page with url parameters ("name" => "value") (optional)
  * @param array  $gotos['screens']			link to host screen page with url parameters ("name" => "value") (optional)
  * @param array  $gotos['triggerStatus']	link to trigger status page with url parameters ("name" => "value") (optional)
  * @param array  $gotos['submap']			link to submap page with url parameters ("name" => "value") (optional)
  * @param array  $gotos['events']			link to events page with url parameters ("name" => "value") (optional)
  * @param array  $urls						local and global map urls (optional)
  * @param string $urls[]['name']			url name
  * @param string $urls[]['url']				url
  *
  * @return array
  */
 public static function getMap($hostId, array $scripts = null, array $gotos = null, array $urls = null)
 {
     $data = ['type' => 'map'];
     if ($scripts) {
         foreach ($scripts as &$script) {
             $script['name'] = implode('/', splitPath($script['name'], false, true));
         }
         unset($script);
         CArrayHelper::sort($scripts, ['name']);
         $data['hostid'] = $hostId;
         foreach (array_values($scripts) as $script) {
             $data['scripts'][] = ['name' => $script['name'], 'scriptid' => $script['scriptid'], 'confirmation' => $script['confirmation']];
         }
     }
     if ($gotos) {
         $data['gotos'] = $gotos;
     }
     if ($urls) {
         foreach ($urls as $url) {
             $data['urls'][] = ['label' => $url['name'], 'url' => $url['url']];
         }
     }
     return $data;
 }
Example #4
0
/**
 * Join path components.
 *
 * @param string $base Base path.
 * @param string $path File path to join to base path.
 * @return string
 */
function joinPath($base, $path)
{
    if (substr($path, 0, 1) === '/') {
        return $path;
        // $path is absolute.
    }
    if (substr($base, 0, 1) !== '/') {
        return false;
        // $base is relative.
    }
    $pathParts = splitPath($path);
    $resultParts = splitPath($base);
    while (($part = array_shift($pathParts)) !== null) {
        switch ($part) {
            case '.':
                break;
            case '..':
                if (count($resultParts) > 1) {
                    array_pop($resultParts);
                }
                break;
            default:
                $resultParts[] = $part;
                break;
        }
    }
    return implode('/', $resultParts);
}
Example #5
0
 /**
  * Trim script name menu path.
  *
  * @param array $scripts
  *
  * @return array
  */
 protected function trimMenuPath(array $scripts)
 {
     foreach ($scripts as &$script) {
         if (!isset($script['name'])) {
             continue;
         }
         $path = splitPath($script['name'], false);
         $path = array_map('trim', $path);
         $script['name'] = implode('/', $path);
     }
     unset($script);
     return $scripts;
 }