Get private nodes, assuming SilverStripe's default perm structure
@return SS_Query
547346
protected function getPrivateNodes() {
		if (!Member::currentUserID()) {
			return array();
		}
		$groups = Member::currentUser()->Groups()->column();

		if (!count($groups)) {
			return $groups;
		}

		$fields = $this->queryFields();
		$query = new SQLQuery($fields, '"'.$this->baseClass.'"');
		$query = $query->setOrderBy($this->itemSort);
		$query->addWhere('"CanViewType" IN (\'OnlyTheseUsers\')');
		if (Permission::check('ADMIN')) {
			// don't need to restrict the canView by anything
		} else {
			$query->addInnerJoin('SiteTree_ViewerGroups', '"SiteTree_ViewerGroups"."SiteTreeID" = "SiteTree"."ID"');
			$query->addWhere('"SiteTree_ViewerGroups"."GroupID" IN (' . implode(',', $groups) . ')');
		}

		$this->adjustPrivateNodeQuery($query);
		$this->adjustForVersioned($query);
		$sql = $query->sql();

		$results = $query->execute();
		return $results;
	}
526530
public static function getAllElementsByXpath($node, $xpath_query, $namespaces = array())
    {
        if(is_a($node, 'DOMDocument'))
        {
            $xpath = new DOMXPath($node);
        }
        elseif(is_a($node, 'DOMNode'))
        {
            $xpath = new DOMXPath($node->ownerDocument);
        }
        else
        {
            return null;
        }

        foreach($namespaces as $prefix => $namespaceURI)
        {
            $xpath->registerNamespace($prefix, $namespaceURI);
        }

        $node_list = $xpath->query($xpath_query, $node);

        return $node_list;
    }
1021542
public function getList()
    {
        //ACCESS CHECK
        if (!$this->isAllowed(
            ResourceName::RESOURCE_SITES,
            'admin'
        )
        ) {
            $this->getResponse()->setStatusCode(Response::STATUS_CODE_401);

            return $this->getResponse();
        }

        /** @var \Doctrine\ORM\EntityManagerInterface $entityManager */
        $entityManager = $this->getEntityManager();

        /** @var \Rcm\Repository\Site $siteRepo */
        $siteRepo = $entityManager->getRepository(\Rcm\Entity\Site::class);
        $createQueryBuilder = $siteRepo->createQueryBuilder('site')
            ->select('site')
            ->leftJoin('site.domain', 'domain')
            ->leftJoin('site.country', 'country')
            ->leftJoin('site.language', 'language');
        // @todo This is broken in doctrine 1.* with MySQL 5.7
        //->orderBy('domain.domain', 'ASC');

        $query = $createQueryBuilder->getQuery();

        $searchQuery = $this->params()->fromQuery('q');

        if ($searchQuery) {
            $createQueryBuilder->where(
                $createQueryBuilder->expr()->like(
                    'domain.domain',
                    ':searchQuery'
                )
            );
            $query = $createQueryBuilder->getQuery();
            $query->setParameter('searchQuery', $searchQuery . '%');
        }

        $adaptor = new DoctrinePaginator(
            new ORMPaginator($query)
        );
        $paginator = new Paginator($adaptor);
        $paginator->setDefaultItemCountPerPage(10);

        $page = (int)$this->params()->fromQuery('page');

        if ($page) {
            $paginator->setCurrentPageNumber($page);
        }

        $pageSize = (int)$this->params()->fromQuery('page_size');
        if ($pageSize) {
            $paginator->setItemCountPerPage($pageSize);
        }

        $sitesObjects = $paginator->getCurrentItems();

        $sites = [];

        /** @var \Rcm\Entity\Site $site */
        foreach ($sitesObjects as $site) {
            $sites[] = $site->toArray();
        }

        $list['items'] = $sites;
        $list['itemCount'] = $paginator->getTotalItemCount();
        $list['pageCount'] = $paginator->count();
        $list['currentPage'] = $paginator->getCurrentPageNumber();

        return new ApiJsonModel($list, 0, 'Success');
    }
719089
public function getSocialPage(){
		$result = null;
		if (isset($this->userInfo[$this->socialFieldsMap['socialPage']])) {
			$result = $this->userInfo[$this->socialFieldsMap['socialPage']];
			}
		return $result;
		}
956491
public function getCurrentUserPrivilegeSet($node)
    {
        if (is_string($node)) {
            $node = $this->server->tree->getNodeForPath($node);
        }

        $acl = $this->getACL($node);

        $collected = [];

        $isAuthenticated = null !== $this->getCurrentUserPrincipal();

        foreach ($acl as $ace) {
            $principal = $ace['principal'];

            switch ($principal) {
                case '{DAV:}owner':
                    $owner = $node->getOwner();
                    if ($owner && $this->principalMatchesPrincipal($owner)) {
                        $collected[] = $ace;
                    }
                    break;

                // 'all' matches for every user
                case '{DAV:}all':
                    $collected[] = $ace;
                    break;

                case '{DAV:}authenticated':
                    // Authenticated users only
                    if ($isAuthenticated) {
                        $collected[] = $ace;
                    }
                    break;

                case '{DAV:}unauthenticated':
                    // Unauthenticated users only
                    if (!$isAuthenticated) {
                        $collected[] = $ace;
                    }
                    break;

                default:
                    if ($this->principalMatchesPrincipal($ace['principal'])) {
                        $collected[] = $ace;
                    }
                    break;
            }
        }

        // Now we deduct all aggregated privileges.
        $flat = $this->getFlatPrivilegeSet($node);

        $collected2 = [];
        while (count($collected)) {
            $current = array_pop($collected);
            $collected2[] = $current['privilege'];

            if (!isset($flat[$current['privilege']])) {
                // Ignoring privileges that are not in the supported-privileges list.
                $this->server->getLogger()->debug('A node has the "'.$current['privilege'].'" in its ACL list, but this privilege was not reported in the supportedPrivilegeSet list. This will be ignored.');
                continue;
            }
            foreach ($flat[$current['privilege']]['aggregates'] as $subPriv) {
                $collected2[] = $subPriv;
                $collected[] = $flat[$subPriv];
            }
        }

        return array_values(array_unique($collected2));
    }
690216
function nodeByName( $params )
    {
        $node = false;

        $contentObject = $this->contentObjectByName( $params );
        if( is_object( $contentObject ) )
            $node = $contentObject->attribute( 'main_node' );

        return $node;
    }
1067177
public function getNodePartials()
    {
        if(!array_key_exists('NodePartials', $this->fields) || is_null($this->fields['NodePartials']))
            $this->fields['NodePartials'] = new NodePartials();

        return $this->fields['NodePartials'];
    }
20311
protected function items()
    {
        // check permissions
        // $siteIDs = $this->checkItemsPermission();

        $dto = new NodeQuery();
        $this->buildLimitOffset($dto);

        $this->passthruTemplateVariable($dto, 'Elements.in');
        $this->passthruTemplateVariable($dto, 'Sites.in');
        //$this->passthruTemplateVariable($dto, 'SiteIDs.in');
        $this->passthruTemplateVariable($dto, 'Slugs.in');

        $this->passthruTemplateVariable($dto, 'Meta.select');
        $this->passthruTemplateVariable($dto, 'OutTags.select');
        $this->passthruTemplateVariable($dto, 'InTags.select');
//        $this->passthruTemplateVariable($dto, 'Sections.select');
        $this->passthruTemplateVariable($dto, 'OrderByInTag');
        $this->passthruTemplateVariable($dto, 'OrderByOutTag');

        $this->passthruTemplateVariable($dto, 'Title.like');
        $this->passthruTemplateVariable($dto, 'Title.ieq');
        $this->passthruTemplateVariable($dto, 'Title.eq');
        $this->passthruTemplateVariable($dto, 'Title.firstChar');
        $this->passthruTemplateVariable($dto, 'Status.isActive');
        $this->passthruTemplateVariable($dto, 'Status.all');
        $this->passthruTemplateVariable($dto, 'Status.eq');
        $this->passthruTemplateVariable($dto, 'TreeID.childOf');
        $this->passthruTemplateVariable($dto, 'TreeID.eq');

        $this->passthruTemplateVariable($dto, 'ActiveDate.before');
        $this->passthruTemplateVariable($dto, 'ActiveDate.after');
        $this->passthruTemplateVariable($dto, 'ActiveDate.start');
        $this->passthruTemplateVariable($dto, 'ActiveDate.end');

        $this->passthruTemplateVariable($dto, 'CreationDate.before');
        $this->passthruTemplateVariable($dto, 'CreationDate.after');
        $this->passthruTemplateVariable($dto, 'CreationDate.start');
        $this->passthruTemplateVariable($dto, 'CreationDate.end');

        $this->passthruTemplateVariable($dto, 'OutTags.exist');
        $this->passthruTemplateVariable($dto, 'InTags.exist');
        $this->passthruTemplateVariable($dto, 'Meta.exist');
//        $this->passthruTemplateVariable($dto, 'Sections.exist');

        foreach ($this->templateVars as $name => $value) {
            if (strpos($name, '#') === 0)
                $dto->setParameter($name, $value);
        }

        $this->buildFilters($dto);

        $dto->isRetrieveTotalRecords(true);

        $dto->setOrderBy($this->getTemplateVariable('OrderBy'));
        $this->buildSorts($dto);

        $this->Events->trigger('NodeCmsController.items', $dto);

        try {
            $dto = $this->RegulatedNodeService->findAll($dto,
                    (($frw = $this->getTemplateVariable('ForceReadWrite'))!=null?StringUtils::strToBool($frw):false));
            return $this->readNodeQuery($dto);
        } catch (NoElementsException $e) {
            throw new NotFoundException('No elements were found for this request.');
        }

    }
530316
public function permissionTree()
  {
    $permtree = array();

    foreach($this->permissionCats() as $key => $val)
    {
      $permtree[$val]["permcatid"]      = $val;
      $permtree[$val]["permcathex"]     = "0x" . dechex($val);
      $permtree[$val]["permcatname"]    = TeamSpeak3_Helper_String::factory(TeamSpeak3_Helper_Convert::permissionCategory($val));
      $permtree[$val]["permcatparent"]  = $permtree[$val]["permcathex"]{3} == 0 ? 0 : hexdec($permtree[$val]["permcathex"]{2} . 0);
      $permtree[$val]["permcatchilren"] = 0;
      $permtree[$val]["permcatcount"]   = 0;

      if(isset($permtree[$permtree[$val]["permcatparent"]]))
      {
        $permtree[$permtree[$val]["permcatparent"]]["permcatchilren"]++;
      }

      if($permtree[$val]["permcatname"]->contains("/"))
      {
        $permtree[$val]["permcatname"] = $permtree[$val]["permcatname"]->section("/", 1)->trim();
      }

      foreach($this->permissionList() as $permission)
      {
        if($permission["permid"]["permcatid"] == $val)
        {
          $permtree[$val]["permcatcount"]++;
        }
      }
    }

    return $permtree;
  }
285286
public function getTopNodeTranslations()
    {
        $qb = $this->createQueryBuilder('b')
            ->select('b', 'v')
            ->innerJoin('b.node', 'n', 'WITH', 'b.node = n.id')
            ->leftJoin(
                'b.publicNodeVersion',
                'v',
                'WITH',
                'b.publicNodeVersion = v.id'
            )
            ->where('n.parent IS NULL')
            ->andWhere('n.deleted != 1');

        return $qb->getQuery()->getResult();
    }
426504
private function getRestNode()
    {
        $node = $this->createRootNode('rest');
        return $node
            ->addDefaultsIfNotSet()
            ->children()
                ->scalarNode('root_endpoint')->isRequired()->cannotBeEmpty()->defaultValue('modlr/api')
                    ->validate()
                        ->always(function($v) {
                            $v = $this->formatRestEndpoint($v);
                            return $v;
                        })
                    ->end()
                ->end()
                ->booleanNode('debug')->defaultValue(false)->end()
            ->end()

        ;
    }
992411
public function ListSubsites()
    {
        $list = $this->Subsites();
        $currentSubsiteID = SubsiteState::singleton()->getSubsiteId();

        if ($list == null || $list->count() == 1 && $list->first()->DefaultSite == true) {
            return false;
        }

        Requirements::javascript('silverstripe/subsites:javascript/LeftAndMain_Subsites.js');

        $output = ArrayList::create();

        foreach ($list as $subsite) {
            $currentState = $subsite->ID == $currentSubsiteID ? 'selected' : '';

            $output->push(ArrayData::create([
                'CurrentState' => $currentState,
                'ID' => $subsite->ID,
                'Title' => $subsite->Title,
            ]));
        }

        return $output;
    }
391628
public function getFilterDescription()
    {
        $items = [];

        $list = $this->PaginatedList();
        $currentPage = $list->CurrentPage();

        if ($currentPage > 1) {
            $items[] = _t(
                'SilverStripe\\Blog\\Model\\Blog.FILTERDESCRIPTION_PAGE',
                'Page {page}',
                null,
                [
                    'page' => $currentPage
                ]
            );
        }

        if ($author = $this->getCurrentProfile()) {
            $items[] = _t(
                'SilverStripe\\Blog\\Model\\Blog.FILTERDESCRIPTION_AUTHOR',
                'By {author}',
                null,
                [
                    'author' => $author->Title
                ]
            );
        }

        if ($tag = $this->getCurrentTag()) {
            $items[] = _t(
                'SilverStripe\\Blog\\Model\\Blog.FILTERDESCRIPTION_TAG',
                'Tagged with {tag}',
                null,
                [
                    'tag' => $tag->Title
                ]
            );
        }

        if ($category = $this->getCurrentCategory()) {
            $items[] = _t(
                'SilverStripe\\Blog\\Model\\Blog.FILTERDESCRIPTION_CATEGORY',
                'In category {category}',
                null,
                [
                    'category' => $category->Title
                ]
            );
        }

        if ($this->owner->getArchiveYear()) {
            if ($this->owner->getArchiveDay()) {
                $date = $this->owner->getArchiveDate()->Nice();
            } elseif ($this->owner->getArchiveMonth()) {
                $date = $this->owner->getArchiveDate()->format('MMMM, y');
            } else {
                $date = $this->owner->getArchiveDate()->format('y');
            }

            $items[] = _t(
                'SilverStripe\\Blog\\Model\\Blog.FILTERDESCRIPTION_DATE',
                'In {date}',
                null,
                [
                    'date' => $date,
                ]
            );
        }

        $result = '';

        if ($items) {
            $result = implode(', ', $items);
        }

        $this->extend('updateFilterDescription', $result);

        return $result;
    }
1281232
public function findAllNodes($context = NULL) {
    $qb = $this->createQueryBuilder('node');
    $qb->addSelect('page');
    $qb->leftJoin('node.page', 'page');
    $qb->andWhere($qb->expr()->eq('node.context', ':context'));
    
    $query = $qb->getQuery();
    $query->setParameter('context', $context ?: $this->context);
    
    return $query->getResult();
  }
369196
public function getFieldList()
    {
        $fields = new FieldList();

        // tabbed or untabbed
        if ($this->tabbed) {
            $fields->push(new TabSet("Root", $mainTab = new Tab("Main")));
            $mainTab->setTitle(_t(__CLASS__ . '.TABMAIN', 'Main'));
        }

        // Add logical fields directly specified in db config
        foreach ($this->obj->config()->get('db') as $fieldName => $fieldType) {
            // Skip restricted fields
            if ($this->restrictFields && !in_array($fieldName, $this->restrictFields)) {
                continue;
            }

            // @todo Pass localized title
            if ($this->fieldClasses && isset($this->fieldClasses[$fieldName])) {
                $fieldClass = $this->fieldClasses[$fieldName];
                $fieldObject = new $fieldClass($fieldName);
            } else {
                $fieldObject = $this
                    ->obj
                    ->dbObject($fieldName)
                    ->scaffoldFormField(null, $this->getParamsArray());
            }
            // Allow fields to opt-out of scaffolding
            if (!$fieldObject) {
                continue;
            }
            $fieldObject->setTitle($this->obj->fieldLabel($fieldName));
            if ($this->tabbed) {
                $fields->addFieldToTab("Root.Main", $fieldObject);
            } else {
                $fields->push($fieldObject);
            }
        }

        // add has_one relation fields
        if ($this->obj->hasOne()) {
            foreach ($this->obj->hasOne() as $relationship => $component) {
                if ($this->restrictFields && !in_array($relationship, $this->restrictFields)) {
                    continue;
                }
                $fieldName = $component === 'SilverStripe\\ORM\\DataObject'
                    ? $relationship // Polymorphic has_one field is composite, so don't refer to ID subfield
                    : "{$relationship}ID";
                if ($this->fieldClasses && isset($this->fieldClasses[$fieldName])) {
                    $fieldClass = $this->fieldClasses[$fieldName];
                    $hasOneField = new $fieldClass($fieldName);
                } else {
                    $hasOneField = $this->obj->dbObject($fieldName)->scaffoldFormField(null, $this->getParamsArray());
                }
                if (empty($hasOneField)) {
                    continue; // Allow fields to opt out of scaffolding
                }
                $hasOneField->setTitle($this->obj->fieldLabel($relationship));
                if ($this->tabbed) {
                    $fields->addFieldToTab("Root.Main", $hasOneField);
                } else {
                    $fields->push($hasOneField);
                }
            }
        }

        // only add relational fields if an ID is present
        if ($this->obj->ID) {
            // add has_many relation fields
            if ($this->obj->hasMany()
                && ($this->includeRelations === true || isset($this->includeRelations['has_many']))
            ) {
                foreach ($this->obj->hasMany() as $relationship => $component) {
                    if ($this->tabbed) {
                        $fields->findOrMakeTab(
                            "Root.$relationship",
                            $this->obj->fieldLabel($relationship)
                        );
                    }
                    $fieldClass = (isset($this->fieldClasses[$relationship]))
                        ? $this->fieldClasses[$relationship]
                        : 'SilverStripe\\Forms\\GridField\\GridField';
                    /** @var GridField $grid */
                    $grid = Injector::inst()->create(
                        $fieldClass,
                        $relationship,
                        $this->obj->fieldLabel($relationship),
                        $this->obj->$relationship(),
                        GridFieldConfig_RelationEditor::create()
                    );
                    if ($this->tabbed) {
                        $fields->addFieldToTab("Root.$relationship", $grid);
                    } else {
                        $fields->push($grid);
                    }
                }
            }

            if ($this->obj->manyMany()
                && ($this->includeRelations === true || isset($this->includeRelations['many_many']))
            ) {
                foreach ($this->obj->manyMany() as $relationship => $component) {
                    static::addManyManyRelationshipFields(
                        $fields,
                        $relationship,
                        (isset($this->fieldClasses[$relationship]))
                            ? $this->fieldClasses[$relationship] : null,
                        $this->tabbed,
                        $this->obj
                    );
                }
            }
        }

        return $fields;
    }
468481
private function findNodesWithoutParents()
    {
        // get nodes that have no parent but depth > 0
        $qb = $this->accountRepository->createQueryBuilder('c2')
            ->select('count(c2.id)')
            ->leftJoin('c2.parent', 'c1')
            ->where('c2.depth <> 0 AND c2.parent IS NULL');

        return $qb->getQuery()->getSingleScalarResult();
    }
766393
private function getFilters()
    {
        $filters = new Collection;

        foreach ($this->getCachedPermissionGroups() as $group) {
            /** @var  \Arcanesoft\Auth\Models\PermissionsGroup  $group */
            $filters->push([
                'name'   => $group->name,
                'params' => [$group->hashed_id],
            ]);
        }

        // Custom Permission group
        //----------------------------------
        if (Permission::where('group_id', 0)->count()) {
            $filters->push([
                'name'   => trans('auth::permission-groups.custom'),
                'params' => [hasher()->encode(0)],
            ]);
        }

        return $filters;
    }