| @copyright 2007-2026 (c) AVE.cms | @link https://ave-cms.ru | @version 3.3 */ namespace App\Frontend\Sitemap; defined('BASEPATH') || die('Direct access to this location is not allowed.'); use DB; use App\Content\ContentTables; class Repository { public static function count() { return (int) DB::query(self::baseSql('COUNT(DISTINCT doc.Id) AS total'))->getValue(); } public static function page($offset, $limit) { $offset = max(0, (int) $offset); $limit = max(1, (int) $limit); return DB::query( self::baseSql( 'doc.Id, doc.document_alias, doc.document_published, doc.document_changed,' . ' doc.document_sitemap_freq, doc.document_sitemap_pr' ) . ' GROUP BY doc.Id ORDER BY doc.document_published ASC, doc.Id ASC LIMIT ' . $offset . ', ' . $limit )->getAll() ?: array(); } protected static function baseSql($select) { $documents = ContentTables::table('documents'); $rubrics = ContentTables::table('rubrics'); $templates = ContentTables::table('rubric_templates'); $permissions = ContentTables::table('rubric_permissions'); $publication = \App\Frontend\PublicSettings::get('use_doctime') ? ' AND doc.document_published <= UNIX_TIMESTAMP()' . " AND (doc.document_expire = '0' OR doc.document_expire >= UNIX_TIMESTAMP())" : ''; return 'SELECT ' . $select . ' FROM `' . $documents . '` doc' . ' INNER JOIN `' . $rubrics . '` rub ON rub.Id = doc.rubric_id' . " WHERE doc.document_status = '1' AND doc.document_deleted = '0'" . " AND doc.Id != '1' AND doc.Id != '" . (int) PAGE_NOT_FOUND_ID . "'" . " AND doc.document_meta_robots NOT LIKE '%noindex%'" . " AND (rub.rubric_template != '' OR EXISTS (SELECT 1 FROM `" . $templates . "` rt" . " WHERE rt.rubric_id = rub.Id AND rt.template != ''))" . ' AND EXISTS (SELECT 1 FROM `' . $permissions . '` rp WHERE rp.rubric_id = rub.Id' . " AND rp.user_group_id = '2' AND rp.rubric_permission LIKE '%docread%')" . $publication; } }