| Server IP : 178.212.43.201 / Your IP : 10.100.0.33 Web Server : Apache/2.4.37 (Oracle Linux Server) OpenSSL/1.1.1k System : Linux spa0007.srv.paxillus.pl 5.4.17-2136.355.3.1.el8uek.x86_64 #3 SMP Sat May 9 17:11:55 PDT 2026 x86_64 User : apache ( 48) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/kontur2/vendor/evsmash/cms/libs/ |
Upload File : |
<?php
namespace Evsmash\Cms;
use Evsmash\Core\Database\Baum;
use Evsmash\Core\Database\SearchableTrait;
use Evsmash\Core\Database\SoftDeleting;
use Evsmash\Core\Dec\Dec;
use Evsmash\Core\Helpers\Str;
use Evsmash\Core\Input\Server;
use Evsmash\Core\Simpy\Element;
use Evsmash\Core\Simpy\Params;
use Evsmash\Core\System\Map;
use Evsmash\Cms\Schemas\Subpages as Schema;
class Subpage extends Baum {
use SoftDeleting;
use SearchableTrait;
protected $searchable = [
'columns' => [
'name' => 10,
'sneak' => 5,
'content' => 5,
]
];
// validate
static public function validate() {
return Schema::validate();
}
// belongs to type
public function type() {
return $this->belongsTo('Evsmash\Cms\SubpagesType');
}
// params
public function scopeParams($query, $params = false) {
$scope = new Params();
$scope->scope($query, $params);
$scope->where('published');
$scope->where('type', 'type_id');
$scope->searchable();
$scope->order(['lft' => 'asc']);
$scope->with(['type']);
return $scope->query;
}
// published
public function scopePublished($query, $params = false) {
return $query->where('published', 1);
}
// parents
static public function parents() {
// get
$root = Subpage::where('depth', 0)->first();
$elements = $root->getDescendantsAndSelf();
// output
$output = [];
foreach($elements as $row) {
// prefix
$prefix = '';
for($i = 0; $i < $row->depth; $i++) {
$prefix .= '--';
}
// output
$output[$row->id] = $prefix.' '.$row->name;
}
return collect($output);
}
// tree
static public function tree($node) {
if($node->isLeaf()) {
return Self::link($node);
} else {
$html = Self::link($node, false);
$html .= '<ul class="list-unstyled">';
foreach($node->children as $child) {
$html .= Subpage::tree($child);
}
$html .= '</ul>';
$html .= '</li>';
}
return $html;
}
// link
static public function link($node, $close = true) {
$html = '';
if($node->published == '1') {
$html .= '<li class="link-subpage-'.$node->id;
if('/'.$node->slug == Server::uri()) {
$html .= ' selected';
}
$html .= '">';
$html .= Dec::a('/'.$node->slug, $node->name);
if($close) {
$html .= '</li>';
}
}
return $html;
}
// tree sort
static public function treesort($node) {
if($node->isLeaf()) {
return '<li id="list_'.$node->id.'"><div>'.Str::words($node->name, 5, '...').'</div></li>';
} else {
$html = '<li id="list_'.$node->id.'"><div>'.Str::words($node->name, 5, '...').'</div>';
$html .= '<ol class="list-unstyled">';
foreach($node->children as $child) {
$html .= Subpage::treesort($child);
}
$html .= '</ol>';
$html .= '</li>';
}
return $html;
}
// save
public function save(array $options = array()) {
// save
parent::save($options);
// slug
if(isset(cfg('evsmash-cms-slugs')['subpages'])) {
// unique
Element::slug($this);
// map refresh
Map::refresh('routes-http');
}
}
}