/** * */ public function generateUrls($fields = array()) { global $DB; $id = $this->id(); if (empty($id)) { return; } if (empty($fields)) { $fields = $this->fieldsData; } $DB->Query("DELETE FROM tao_urls WHERE item_id='{$id}'"); $site = ''; $sites = $this->infoblock()->sites(); if (count($sites) == 1) { $site = array_pop($sites); } $icode = $this->infoblock()->getMnemocode(); $time = time(); $modes = array(); foreach ($this->infoblock()->urls() as $mode => $data) { $url = trim($this["url_{$mode}"]->value()); if (empty($url)) { if (isset($data['generate'])) { $generate = $data['generate']; if (is_callable($generate)) { $url = call_user_func($generate, $this, $mode); } else { $url = str_replace('{id}', $this->id(), $generate); $url = str_replace('{title}', strtolower(\TAO::translit($this->title())), $url); } } if (!empty($url)) { $this->saveProperty("url_{$mode}", $url); } } if (!empty($url)) { $DB->Query("INSERT INTO tao_urls SET url='{$url}', infoblock='{$icode}', item_id={$id}, mode='{$mode}', site='{$site}', time_update='{$time}'"); $modes[$mode] = true; } } $mode = \TAO::getOption("infoblock.{$icode}.route_detail"); if ($mode === true) { $mode = 'full'; } if (is_string($mode) && !isset($modes[$mode])) { $ut = $this->infoblock()->getData('DETAIL_PAGE_URL'); $sites = $this->infoblock()->sites(); $fields['IBLOCK_CODE'] = $icode; foreach ($sites as $site) { $siteData = \TAO::getSiteData($site); $fields['LID'] = $site; $fields['LANG_DIR'] = $siteData['DIR']; $url = \CIBlock::ReplaceDetailUrl($ut, $fields, false, 'E'); if (!empty($url)) { $DB->Query("INSERT INTO tao_urls SET url='{$url}', infoblock='{$icode}', item_id={$id}, mode='{$mode}', site='{$site}', time_update='{$time}'"); } } } }
/** * @param $dirs * @param $file * @param bool|false $extra * @return bool|string */ public static function filePath($dirs, $file, $extra = false) { static $paths = array(); $cache = \TAO::getOption('cache.template.paths'); $key = md5(serialize(func_get_args())); if ($cache && !is_int($cache)) { $cache = 3600; } if ($cache) { $key = "tplpath/{$key}"; $path = \TAO::cache()->get($key, $cache); if ($path) { return $path; } } if (isset($paths[$key])) { return $paths[$key]; } if (preg_match('{^(.+)\\.(css|js|phtml|less|scss)$}', $file, $m)) { $base = $m[1]; $ext = $m[2]; $site = SITE_ID; $files = $extra ? array("{$base}-{$extra}-{$site}.{$ext}", "{$base}-{$extra}.{$ext}") : array(); $files[] = "{$base}-{$site}.{$ext}"; $files[] = "{$base}.{$ext}"; foreach ($files as $fn) { foreach ($dirs as $dir) { $path = "{$dir}/{$fn}"; if (is_file($path)) { $paths[$key] = $path; if ($cache) { \TAO::cache()->set($key, $path, $cache); } return $path; } } } } return false; }
/** * @param $uri * @return bool */ public static function routeElement($uri) { global $DB; $site = SITE_ID; $uri = str_replace("'", '', $uri); $res = $DB->Query("SELECT * FROM tao_urls WHERE url='{$uri}' AND (site='' OR site='{$site}') ORDER BY time_update DESC LIMIT 1"); while ($row = $res->Fetch()) { $id = $row['item_id']; $mode = $row['mode']; $code = $row['infoblock']; $infoblock = \TAO::getInfoblock($code); if ($infoblock) { $imode = \TAO::getOption("infoblock.{$code}.route_detail"); if ($imode === true) { $imode = 'full'; } $urls = $infoblock->urls(); if ($mode == $imode || isset($urls[$mode])) { return self::dispatchElement(array('id' => $id, 'element_of' => $code, 'mode' => $mode)); } } } }
<?php if ($_SERVER['HTTP_X_REQUESTED_WITH'] != 'XMLHttpRequest') { die('This page is for XMLHttpRequest only!'); } require_once $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_before.php'; $args = $_GET; $infoblock = false; if (isset($args['infoblock'])) { $code = htmlspecialcharsbx(trim($args['infoblock'])); if (!\TAO::getOption("infoblock.{$code}.elements.ajax")) { die('Access denied!'); } if (!empty($code)) { $infoblock = \TAO::infoblock($code); } } if (empty($infoblock)) { print "Infoblock {$code} not found!"; } else { $innerMode = 'ajax-inner'; if (isset($args['list_mode_inner'])) { $innerMode = trim($args['list_mode_inner']); } $args['list_mode'] = $innerMode; print $infoblock->render($args); }
protected function officeAuthUrl() { return $this->officeAuthUrl ?: ($this->officeAuthUrl = \TAO::getOption('auth')); }
/** * @return bool|null */ public function getMnemocodeForPaths() { $code = $this->getMnemocode(); $pathsCode = \TAO::getOption("infoblock.{$code}.paths_code"); return empty($pathsCode) ? $code : $pathsCode; }
public function getFromConfig($name) { return \TAO::getOption('env') ?: 'prod'; }