Построение ветки меню

@param int $ownerId  идентификатор родительского раздела
@param string $path     URL родительского раздела
@param int $level    Уровень вложенности

@return string  HTML

@uses Eresus
@uses TClientUI
15387
protected function renderBranch($ownerId = 0, $path = '', $level = 1)
    {
        $sections = $this->Eresus->sections;

        if (strpos($path, $this->Eresus->root) !== false)
        {
            $path = substr($path, strlen($this->Eresus->root));
        }
        if ($ownerId == -1)
        {
            $ownerId = $this->ui->id;
        }
        $rootItem = $sections->get($ownerId);
        if ($rootItem && 0 == $rootItem['owner'] && 'main' == $rootItem['name'])
        {
            $path = 'main/';
        }

        $vars = array('menuName' => $this->menu->name, 'level' => $level);
        $vars['isDropDown'] = $this->menu->dropDown > 1 && $level >= $this->menu->dropDown;
        $vars['items'] = $sections->children($ownerId, $this->accessThreshold, $this->sectionsFilter);

        $html = '';
        if (count($vars['items']))
        {

            foreach ($vars['items'] as &$item)
            {
                $section = new Menus_Site_Section($item);
                $item['level'] = $level;
                $item['url'] = $section->getUrl();
                $item['isCurrent'] = $item['id'] == $this->ui->id;
                $item['isOpened'] = !$item['isCurrent'] && in_array($item['id'], $this->ids);

                // true если раздел находится в выбранной ветке
                $inSelectedBranch = $item['isOpened'] || $item['isCurrent'];
                // true если не достигнут максимальный уровень ручного развёртывания
                $notMaxExpandLevel = !$this->menu->expandLevelMax ||
                    $item['level'] < $this->menu->expandLevelMax;
                // true если не достигнут максимальный уровень автоматического развёртывания
                $notMaxAutoExpandLevel = !$this->menu->expandLevelAuto ||
                    $item['level'] < $this->menu->expandLevelAuto;

                if ($notMaxAutoExpandLevel || ($inSelectedBranch && $notMaxExpandLevel))
                {
                    $item['submenu'] =
                        $this->renderBranch($item['id'], $path . $item['name'] . '/', $item['level'] + 1);
                }
            }
            $html = $this->template->compile($vars);
        }
        return $html;
    }
772439
public function getThumbPath($path, $width, $height)
    {

        // 尺寸限制
        $allowSizeList = [0, 50, 100, 150, 200, 300, 400, 500, 640, 720, 800, 1000, 1200, 1680, 1920];
        $resetW = !in_array($width, $allowSizeList);
        $resetH = !in_array($height, $allowSizeList);

        if ($resetW || $resetH) {
            foreach ($allowSizeList as $size) {
                if ($resetW && $size > $width) {
                    $width = $size;
                    $resetW = false;
                }

                if ($resetH && $size > $height) {
                    $height = $size;
                    $resetH = false;
                }

                if (!$resetH && !$resetW) {
                    break;
                }
            }
        }

        $path = $this->getPathFromUrl($path);
        $path .= ".thumb.{$width}x{$height}.jpg";
        
        return $path;
    }
808098
public function issueAuthCode($ownerType, $ownerId, $params = [])
    {
        $params = array_merge($this->authCodeRequestParams, $params);

        return $this->issuer->getGrantType('authorization_code')->newAuthorizeRequest($ownerType, $ownerId, $params);
    }
518969
public function getSignedDownloadUrl($path, $expires = 3600, $host_name = '', $use_ssl = false)
    {
        $object = $this->applyPathPrefix($path);
        $url = $this->client->signUrl($this->bucket, $object, $expires);

        if (! empty($host_name) || $use_ssl) {
            $parse_url = parse_url($url);
            if (! empty($host_name)) {
                $parse_url['host'] = $this->bucket.'.'.$host_name;
            }
            if ($use_ssl) {
                $parse_url['scheme'] = 'https';
            }

            $url = (isset($parse_url['scheme']) ? $parse_url['scheme'].'://' : '')
                   .(
                   isset($parse_url['user']) ?
                       $parse_url['user'].(isset($parse_url['pass']) ? ':'.$parse_url['pass'] : '').'@'
                       : ''
                   )
                   .(isset($parse_url['host']) ? $parse_url['host'] : '')
                   .(isset($parse_url['port']) ? ':'.$parse_url['port'] : '')
                   .(isset($parse_url['path']) ? $parse_url['path'] : '')
                   .(isset($parse_url['query']) ? '?'.$parse_url['query'] : '');
        }

        return $url;
    }
1623
public function get_view(string $path, string $mode = 'html', array $data=null){
    if ( !router::is_mode($mode) ){
      die("Incorrect mode $path $mode");
    }
    $view = null;
    if ( $this->has_view($path, $mode) ){
      $view = self::$loaded_views[$mode][$path];
    }
    else if ( $info = $this->router->route($path, $mode) ){
      $view = new mvc\view($info);
      $this->add_to_views($path, $mode, $view);
    }
    if ( \is_object($view) && $view->check() ){
      return \is_array($data) ? $view->get($data) : $view->get();
    }
    return '';
  }
1273992
public function getAvatarHome($userId)
    {
        $id = sprintf("%09d", $userId);
        $dir1 = substr($id, 0, 3);
        $dir2 = substr($id, 3, 2);
        $dir3 = substr($id, 5, 2);
        return $dir1 . '/' . $dir2 . '/' . $dir3 . '/';
    }
1013887
public static function getUserMenuTreeByParentId($userId = 0, $parentId, $order = 'display_order asc')
    {
        $data = static::find()
            ->normal()
            ->findByParentId($parentId)
            ->active()
            ->orderBy($order)
            ->asArray()
            ->all();
        $tree = [];
        if ($data) {
            foreach ($data as $item) {
                $text = $item['text'];
                if ($item['is_hide']) {
                    $text .= ' -- [菜单中隐藏]';
                }
                $node = [
                    'menu_id' => $item['menu_id'],
                    'parent_id' => $item['parent_id'],
                    'tab_id' => 'tab_' . $item['menu_id'],
                    'text' => $text,
                    'origin_text' => $text,
                    'title' => $item['title'],
                    'url' => $item['url'],
                    'view_package' => $item['view_package'],
                    'expanded' => (bool) $item['expanded'],
                    'is_expand' => (bool) $item['expanded'],
                    'closable' => (bool) $item['closable'],
                    'is_open_url' => (bool) $item['is_open_url'],
                    'is_open_target' => (bool) $item['is_open_target'],
                    'is_every_open' => (bool) $item['is_every_open'],
                    'is_hide' => (bool) $item['is_hide'],
                    'display_order' => $item['display_order'],
                    'note' => $item['note'],
                    'status' => intval($item['status']),
                    'checked' => DpAdminUserMenuRelation::find()
                        ->findByUserId($userId)
                        ->findByMenuId($item['menu_id'])
                        ->exists()
                ];
                $children = static::getUserMenuTreeByParentId($userId, $item['menu_id'], $order);
                if ($children) {
                    $node['leaf'] = false;
                    $node['children'] = $children;
                } else {
                    $node['leaf'] = true;
                }
                $tree[] = $node;
            }
        }

        return $tree;
    }
1007654
public static function getAvatarPath($userId)
    {
        $id = sprintf("%09d", $userId);
        $dir1 = substr($id, 0, 3);
        $dir2 = substr($id, 3, 2);
        $dir3 = substr($id, 5, 2);
        return 'avatar' . '/' . $dir1 . '/' . $dir2 . '/' . $dir3 . '/' . substr($userId, -2);
    }
779334
protected function url($path, $label, $parent = null)
    {
        if ($this->config['generate_url']) {
            if ($this->route) {
                if (array_has($this->route, 'callback')) {
                    if(is_array($parent)) $parent = (object)$parent;
                    return call_user_func_array($this->route['callback'], [$path, $label, $parent]);
                } else {
                    end($this->route);
                    $param = current($this->route);
                    $name = key($this->route);
                    return URL::route($name, [$param => $path]);
                }
            }

            return URL::to($path);
        }

        return '/'.$path;
    }
1199785
public function getPageByOwnerId( $ownerId, $config = [] ) {

		$owner		= $config[ 'owner' ] ?? false;
		$modelTable	= $this->getModelTable();

		if( $owner ) {

			$config[ 'conditions' ][ "$modelTable.holderId" ] = $ownerId;
		}
		else {

			$config[ 'conditions' ][ "$modelTable.createdBy" ] = $ownerId;
		}

		return $this->getPage( $config );
	}
1081703
public function useFiles($path, $level = 'debug')
	{
		$level = $this->parseLevel($level);

		$this->monolog->pushHandler(new StreamHandler($path, $level));
	}
159804
public static function a($path, $text = NULL, $base_path = true, array $attrs = array())
    {
        if($base_path)
            $path = self::getBaseSite() . ltrim($path, '/');
        $attrs['href'] = $path;
            
        return self::tag('a', $text, false, false, $attrs);
    }
613725
public static function getFull($path = NULL, $front = '')
    {
        if($path){
            $hostInfo = Yii::$app->request->getHostInfo();
            $hostInfo = parse_url($hostInfo);
            $scheme =  $hostInfo['scheme'];
            $host =  $hostInfo['host'];
            if($front){
                $host = explode(".", $host);
                $host[0] = $front;
                $host = join(".", $host);
            }
            $path = $scheme . '://' . $host . '/' . ltrim($path, '/');
        }

        return $path;
    }
1179312
function ensureDirExists($path, $owner = null, $mode = 0755)
    {
        if (! $this->isDir($path)) {
            $this->mkdir($path, $owner, $mode);
        }
    }
1052124
function touch($path, $owner = null)
    {
        touch($path);

        if ($owner) {
            $this->chown($path, $owner);
        }

        return $path;
    }
552998
public function generateDirectoryIndex($path)
    {
        $html = $this->generateHeader($path ? $path : '/', $path);

        $node = $this->server->tree->getNodeForPath($path);
        if ($node instanceof DAV\ICollection) {
            $html .= "<section><h1>Nodes</h1>\n";
            $html .= '<table class="nodeTable">';

            $subNodes = $this->server->getPropertiesForChildren($path, [
                '{DAV:}displayname',
                '{DAV:}resourcetype',
                '{DAV:}getcontenttype',
                '{DAV:}getcontentlength',
                '{DAV:}getlastmodified',
            ]);

            foreach ($subNodes as $subPath => $subProps) {
                $subNode = $this->server->tree->getNodeForPath($subPath);
                $fullPath = $this->server->getBaseUri().HTTP\encodePath($subPath);
                list(, $displayPath) = Uri\split($subPath);

                $subNodes[$subPath]['subNode'] = $subNode;
                $subNodes[$subPath]['fullPath'] = $fullPath;
                $subNodes[$subPath]['displayPath'] = $displayPath;
            }
            uasort($subNodes, [$this, 'compareNodes']);

            foreach ($subNodes as $subProps) {
                $type = [
                    'string' => 'Unknown',
                    'icon' => 'cog',
                ];
                if (isset($subProps['{DAV:}resourcetype'])) {
                    $type = $this->mapResourceType($subProps['{DAV:}resourcetype']->getValue(), $subProps['subNode']);
                }

                $html .= '<tr>';
                $html .= '<td class="nameColumn"><a href="'.$this->escapeHTML($subProps['fullPath']).'"><span class="oi" data-glyph="'.$this->escapeHTML($type['icon']).'"></span> '.$this->escapeHTML($subProps['displayPath']).'</a></td>';
                $html .= '<td class="typeColumn">'.$this->escapeHTML($type['string']).'</td>';
                $html .= '<td>';
                if (isset($subProps['{DAV:}getcontentlength'])) {
                    $html .= $this->escapeHTML($subProps['{DAV:}getcontentlength'].' bytes');
                }
                $html .= '</td><td>';
                if (isset($subProps['{DAV:}getlastmodified'])) {
                    $lastMod = $subProps['{DAV:}getlastmodified']->getTime();
                    $html .= $this->escapeHTML($lastMod->format('F j, Y, g:i a'));
                }
                $html .= '</td><td>';
                if (isset($subProps['{DAV:}displayname'])) {
                    $html .= $this->escapeHTML($subProps['{DAV:}displayname']);
                }
                $html .= '</td>';

                $buttonActions = '';
                if ($subProps['subNode'] instanceof DAV\IFile) {
                    $buttonActions = '<a href="'.$this->escapeHTML($subProps['fullPath']).'?sabreAction=info"><span class="oi" data-glyph="info"></span></a>';
                }
                $this->server->emit('browserButtonActions', [$subProps['fullPath'], $subProps['subNode'], &$buttonActions]);

                $html .= '<td>'.$buttonActions.'</td>';
                $html .= '</tr>';
            }

            $html .= '</table>';
        }

        $html .= '</section>';
        $html .= '<section><h1>Properties</h1>';
        $html .= '<table class="propTable">';

        // Allprops request
        $propFind = new PropFindAll($path);
        $properties = $this->server->getPropertiesByNode($propFind, $node);

        $properties = $propFind->getResultForMultiStatus()[200];

        foreach ($properties as $propName => $propValue) {
            if (!in_array($propName, $this->uninterestingProperties)) {
                $html .= $this->drawPropertyRow($propName, $propValue);
            }
        }

        $html .= '</table>';
        $html .= '</section>';

        /* Start of generating actions */

        $output = '';
        if ($this->enablePost) {
            $this->server->emit('onHTMLActionsPanel', [$node, &$output, $path]);
        }

        if ($output) {
            $html .= '<section><h1>Actions</h1>';
            $html .= "<div class=\"actions\">\n";
            $html .= $output;
            $html .= "</div>\n";
            $html .= "</section>\n";
        }

        $html .= $this->generateFooter();

        $this->server->httpResponse->setHeader('Content-Security-Policy', "default-src 'none'; img-src 'self'; style-src 'self'; font-src 'self';");

        return $html;
    }
1168595
public static function getRoutesByUser($userId)
    {
        if (!isset(self::$_userRoutes[$userId])) {
            $manager = self::getAuthManager();
            if ($manager->cache && ($routes = $manager->cache->get([__METHOD__, $userId])) !== false) {
                self::$_userRoutes[$userId] = $routes;
            } else {
                $routes = static::getDefaultRoutes();
                foreach ($manager->getPermissionsByUser($userId) as $item) {
                    if ($item->name[0] === '/') {
                        $routes[$item->name] = true;
                    }
                }
                self::$_userRoutes[$userId] = $routes;
                if ($manager->cache) {
                    $manager->cache->set([__METHOD__, $userId], $routes, $manager->cacheDuration, new TagDependency([
                        'tags' => $manager->cacheTag
                    ]));
                }
            }
        }
        return self::$_userRoutes[$userId];
    }