Returns the SQL condition used to find successfully completed archives that
this instance is querying for.

@param array $plugins
@param Segment $segment
@return string
514817
private static function getNameCondition(array $plugins, Segment $segment)
    {
        // the flags used to tell how the archiving process for a specific archive was completed,
        // if it was completed
        $doneFlags    = Rules::getDoneFlags($plugins, $segment);
        $allDoneFlags = "'" . implode("','", $doneFlags) . "'";

        $possibleValues = Rules::getSelectableDoneFlagValues();

        // create the SQL to find archives that are DONE
        return "((name IN ($allDoneFlags)) AND (value IN (" . implode(',', $possibleValues) . ")))";
    }
780337
public static function root($segments = null): string
    {
        $path = __DIR__;
        for ($c1 = 0; $c1 < 4; $c1++) {
            $path = dirname($path);
        }
        $path = str_replace('\\', '/', $path);
        $path = self::addSegmentsToPath($path, $segments);
        return $path;
    }
901522
public function get_segment($segment, $default = null)
	{
		if (isset($this->segments[$segment - 1]))
		{
			return $this->segments[$segment - 1];
		}

		return \Fuel::value($default);
	}
617811
public static function getKnownSegmentsToArchive()
    {
        $cacheId = 'KnownSegmentsToArchive';
        $cache   = PiwikCache::getTransientCache();
        if ($cache->contains($cacheId)) {
            return $cache->fetch($cacheId);
        }

        $segments = Config::getInstance()->Segments;
        $segmentsToProcess = isset($segments['Segments']) ? $segments['Segments'] : array();

        /**
         * Triggered during the cron archiving process to collect segments that
         * should be pre-processed for all websites. The archiving process will be launched
         * for each of these segments when archiving data.
         *
         * This event can be used to add segments to be pre-processed. If your plugin depends
         * on data from a specific segment, this event could be used to provide enhanced
         * performance.
         *
         * _Note: If you just want to add a segment that is managed by the user, use the
         * SegmentEditor API._
         *
         * **Example**
         *
         *     Piwik::addAction('Segments.getKnownSegmentsToArchiveAllSites', function (&$segments) {
         *         $segments[] = 'country=jp;city=Tokyo';
         *     });
         *
         * @param array &$segmentsToProcess List of segment definitions, eg,
         *
         *                                      array(
         *                                          'browserCode=ff;resolution=800x600',
         *                                          'country=jp;city=Tokyo'
         *                                      )
         *
         *                                  Add segments to this array in your event handler.
         */
        Piwik::postEvent('Segments.getKnownSegmentsToArchiveAllSites', array(&$segmentsToProcess));

        $segmentsToProcess = array_unique($segmentsToProcess);

        $cache->save($cacheId, $segmentsToProcess);
        return $segmentsToProcess;
    }
595381
public function segment($segment)
    {
        $segments = $this->segments;

        return isset($segments[$segment - 1]) ? $segments[$segment - 1] : false;
    }
67425
protected function joinSegment(Model $parent, $segment, $type)
    {
        $relation = $parent->{$segment}();
        $related  = $relation->getRelated();
        $table    = $related->getTable();

        if ($relation instanceof BelongsToMany || $relation instanceof HasManyThrough) {
            $this->joinIntermediate($parent, $relation, $type);
        }

        if (!$this->alreadyJoined($join = $this->getJoinClause($parent, $relation, $table, $type))) {
            $this->query->joins[] = $join;
        }

        return $related;
    }
1092754
public static function getSegmentRegExp($segment)
        {
            if (($pos = mb_strpos($segment, '|')) !== false) {
                $regexp = mb_substr($segment, $pos + 1);

                if (!mb_strlen($regexp)) return false;

                return '/'.$regexp.'/';
            }

            return false;
        }
626676
public static function createConditionals(array $tokens) {
        if(!isset($tokens['WHERE'])) return '';

        $tableAlias = Table::alias($tokens);
        $primaryKeyColumn = sprintf('%s.%s', $tableAlias, Identifier::column($tokens, new MetaData));

        // Get WHERE conditions as string including table alias and primary key column if present
        $sqlWhereString = array_reduce($tokens['WHERE'], function($query, $token) use ($tableAlias) {
            return $query . str_replace(['"', '\''], '', str_replace('OR', '|', str_replace('AND', '&', $token['base_expr'])));
        });

        // Remove primary key column before removing table alias and returning
        return str_replace($tableAlias . '.', '', preg_replace('/' . preg_quote($primaryKeyColumn) . '=[\w\d]*&*/', '', $sqlWhereString));
    }
142520
private function getTableName($segments)
    {
        $tableName = [];

        foreach ($segments as $segment) {
            if ($this->isConnectingWord($segment)) {
                break;
            }

            $tableName[] = $segment;
        }

        return implode('_', array_reverse($tableName));
    }
1096644
protected function buildJsonPath(array $segments): string
	{
		$path = '';

		foreach($segments as $segment)
		{
			if(is_numeric($segment))
			{
				$path .= '[' . $segment . ']';
			}
			else
			{
				$path .= '.' . '"' . str_replace(['"', "'"], ['\\\"', "''"], $segment) . '"';
			}
		}

		return '$' . $path;
	}
1332036
public function getSqlSegment()
    {
        if (!empty($this->sqlSegment)) {
            return $this->sqlSegment;
        }

        if ($this->dbTableName && $this->columnName) {
            return $this->dbTableName . '.' . $this->columnName;
        }
    }
1266461
public static String getLastSegment(final List<PathSegment> segments) {
        if (segments.isEmpty()) {
            return "";
        }
        return segments.get(segments.size() - 1).getPath();
    }
585704
protected function _validate_request($segments)
    {
        if (count($segments) == 0) {
            return $segments;
        }

        // Locate the controller with modules support
        if ($located = $this->locate($segments)) {
            return $located;
        }

        // Is there a 404 override?
        if (!empty($this->routes['404_override'])) {
            $segments = explode('/', $this->routes['404_override']);
            if ($located = $this->locate($segments)) {
                return $located;
            }
        }

        // Nothing else to do at this point but show a 404
        return parent::_validate_request($segments);
    }
1287741
public function parse(&$segments)
    {
        $query = array('view' => 'page');

        if (!empty($segments)) {
            $query['layout'] = str_replace('-', '_', implode('/', $segments));
        }

        return $query;
    }
1038520
private function checkId(Segment $segment, $id)
    {
        $user = $this->usersRepository->find($id);
        if (!$user) {
            return false;
        }
        return $segment->isIn('id', $id);
    }
695904
public function parse(&$segments)
    {
        $vars = array();

        if (empty($segments)) {
            $vars['view'] = $this->getIdentifier()->package;
        } elseif (count($segments) == 1) {
            $identifier = array_pop($segments);

            if (is_numeric($identifier)) {
                $vars['id'] = (int) $identifier;
            } else {
                $vars['alias'] = $identifier;
            }

            $vars['view'] = AnInflector::singularize($this->getIdentifier()->package);
        }

        return $vars;
    }
498078
public static function handleStream($segments) {

		$page = array_shift($segments);
		$guid = array_shift($segments);

		switch ($page) {

			case 'comments' :

				$comment_guid = array_shift($segments);
				set_input('entity_guid', $guid);
				set_input('comment_guid', $comment_guid);
				echo elgg_view_resource('interactions/comments', [
					'guid' => $guid,
					'comment_guid' => $comment_guid
				]);
				return true;

			case 'likes' :
				set_input('guid', $guid);
				echo elgg_view_resource('interactions/likes', [
					'guid' => $guid,
				]);
				return true;

			case 'edit' :
				set_input('guid', $guid);
				echo elgg_view_resource('interactions/edit', [
					'guid' => $guid,
				]);
				return true;

			case 'view' :
				set_input('guid', $guid);
				echo elgg_view_resource('interactions/view', [
					'guid' => $guid,
				]);
				return true;
		}

		return false;
	}