Suffix unique index to slug

@param $slug
@param $list
@return string
2304
private function generateSuffix($slug, $list)
    {
        // loop through list and get highest index number
        $index = $list->map(function ($s) use ($slug) {
            // str_replace instead of explode('-');
            return intval(str_replace($slug . '-', '', $s));
        })->sort()->last();

        return $slug . '-' . ($index + 1);
    }
91666
private static function _calendarDetail($locale, $list)
    {
        $ret = "001";
        foreach ($list as $key => $value) {
            if (strpos($locale, '_') !== false) {
                $locale = substr($locale, strpos($locale, '_') + 1);
            }
            if (strpos($key, $locale) !== false) {
                $ret = $key;
                break;
            }
        }
        return $ret;
    }
827193
public function listIndex()
    {
        $table = $this->db->quotekey($this->name);
        $cmd = array(
            'sqlite2?' =>
                "PRAGMA index_list($table);",
            'mysql' =>
                "SHOW INDEX FROM $table;",
            'mssql|sybase|dblib|sqlsrv' =>
                "select * from sys.indexes ".
                "where object_id = (select object_id from sys.objects where name = '$this->name')",
            'pgsql' =>
                "select i.relname as name, ix.indisunique as unique ".
                "from pg_class t, pg_class i, pg_index ix ".
                "where t.oid = ix.indrelid and i.oid = ix.indexrelid ".
                "and t.relkind = 'r' and t.relname = '$this->name'".
                "group by t.relname, i.relname, ix.indisunique;",
        );
        $result = $this->db->exec($this->findQuery($cmd));
        $indexes = array();
        if (preg_match('/pgsql|sqlite2?/', $this->db->driver())) {
            foreach($result as $row)
                $indexes[$row['name']] = array('unique' => $row['unique']);
        } elseif (preg_match('/mssql|sybase|dblib|sqlsrv/', $this->db->driver())) {
            foreach ($result as $row)
                $indexes[$row['name']] = array('unique' => $row['is_unique']);
        } elseif (preg_match('/mysql/', $this->db->driver())) {
            foreach($result as $row)
                $indexes[$row['Key_name']] = array('unique' => !(bool)$row['Non_unique']);
        } else
            trigger_error(sprintf(self::TEXT_ENGINE_NOT_SUPPORTED, $this->db->driver()),E_USER_ERROR);
        return $indexes;
    }
482234
public function uniqueSlug($slug_str, $tag_name)
	{
		$model = $this->tagModelString();
		if (!empty($slug_str) && $tag = $model::where('slug', $slug_str)->first()) {
			// 只有当 slug 一样但 tagname 不一样的情况下，才自动设置随机 slug 后缀
			if ($tag->name != $this->normalizeTagName($tag_name)) {
				$slug_str .= '-'. mt_rand(1000, 9999);
			}
		}
		return $slug_str;
	}
1316072
public function formatMobile(array $list)
    {
        return implode(',', array_unique(array_map(function ($value) {
            return is_array($value) ? "{$value['number']}" : $value;
        }, $list)));
    }
262911
private function slug($value = null) {
        // generate slug
        $slug = strtolower(Text::slug($value, $this->_config['replacement']));

        // unique slug?
        if($this->_config['unique']) {
            // does the slug already exist?
            $field = $this->_table->getAlias() . '.slug';
            $conditions = [$field => $slug];
            $suffix = '';
            $i = 0;

            // loop till unique slug is found
            while ($this->_table->exists($conditions)) {
                $i++;
                $suffix = $this->_config['replacement'] . $i;
                $conditions[$field] = $slug . $suffix;
            }

            // got suffix? append it
            if($suffix)
                $slug .= $suffix;
        }

        // return slug
        return $slug;
    }
844385
protected function makeSlugUnique($slug)
    {
        $i = 1;
        $slugIsUnique = false;

        // get existing slugs (1 db query)
        $list = $this->getExistingSlugs($slug);

        // slug is already unique
        if ($list->count() === 0) {
            return $slug;
        }

        // collection to array
        if (!is_array($list)) {
            $list = $list->toArray();
        }

        // loop through the list and add suffix
        while (!$slugIsUnique) {
            $uniqueSlug = $slug . $this->slugOptions->slugSeparator . ($i++);
            if (!in_array($uniqueSlug, $list)) {
                $slugIsUnique = true;
            }
        }

        return $uniqueSlug;
    }
483964
public function removeHashPrefixesFromList($list)
  {
    $this->debugLog('removeHashPrefixesFromList() list '.$list);
    $listdir=$this->getListStorageDir($list);
    if(!$listdir || strlen($listdir)<10){
      $this->warningLog('removeHashPrefixesFromList() invalid list directory for list '.$list);
      return;
    }
    if(!is_dir($listdir)){
      $this->debugLog('removeHashPrefixesFromList() no list directory for list '.$list);
      return;
    }
    if(!is_file($listdir.$this->prefixes_filename)){
      $this->debugLog('removeHashPrefixesFromList() no prefix file for list '.$list);
      return;
    }
    unlink($listdir.$this->prefixes_filename);
  }
345493
protected function createIndexName($table, array $columns, $unique = false)
    {
        $index = strtolower($table . '_' . implode('_', $columns) . '_' . ($unique ? 'unique' : 'index'));

        return str_replace(['-', '.'], '_', $index);
    }
982641
public static function unsluggify($slug)
    {
        $str = str_replace("-", " ", $slug);
        $words  = explode(" ", $str);
        $words  = array_map('ucfirst', $words);

        return implode(" ", $words);
    }
1329647
protected function getExistingSlugs($slug)
    {
        return static::where($this->slugOptions->slugField, 'LIKE', "{$slug}%")
            ->withoutGlobalScopes()// ignore scopes
            ->withTrashed()// trashed, when entry gets activated again
            ->orderBy($this->slugOptions->slugField)
            ->get()
            ->pluck($this->slugOptions->slugField);
    }
837332
public function transform($slug)
    {
        if (null === $slug) {
            return;
        }

        // If the slug ends with a slash, return just a slash
        // so the item is used as the index page of that directory
        if (substr($slug, -1) == '/') {
            return '/';
        }

        $array = explode('/', $slug);
        $slug = end($array);

        return $slug;
    }
1244958
public static function slug($text = '', $isCache = false): string
    {
        static $cache = [];

        if (!$isCache) {
            return Slug::filter($text);
        }

        if (!array_key_exists($text, $cache)) { // Not Arr::key() for performance
            $cache[$text] = Slug::filter($text);
        }

        return $cache[$text];
    }
47587
public function slug($str)
    {
        if (is_array($str)) {
            $str = implode(' ', $str);
        }

        return $this->slugify->slugify($str);
    }
95093
public function get_slug( $config_name, $suffix = '-' ) {
		if ( ! isset( self::$_slugs[ $this->app->plugin_name ][ $config_name ] ) ) {
			$default = $this->app->slug_name . $suffix;
			$slug    = $this->app->get_config( 'slug', $config_name, $default );
			if ( empty( $slug ) ) {
				$slug = $default;
			}
			self::$_slugs[ $this->app->plugin_name ][ $config_name ] = $slug;
		}

		return self::$_slugs[ $this->app->plugin_name ][ $config_name ];
	}
857811
public static function expandList($list) {
		$items = explode(',', $list);
		$list = array();
		foreach ($items as $item) {
			$range = explode('-', $item);
			if (isset($range[1])) {
				$runAwayBrake = 1000;
				for ($n = $range[0]; $n <= $range[1]; $n++) {
					$list[] = $n;

					$runAwayBrake--;
					if ($runAwayBrake <= 0) {
						break;
					}
				}
			} else {
				$list[] = $item;
			}
		}
		return implode(',', $list);
	}
713847
public function getExistingSlugs($slug)
    {
        return self::select('slug')->where('slug', 'like', $slug.'%')
            ->when($this->id, function ($query) {
                return $query->where('id', '<>', $this->id);
            })
            ->get();
    }