/** * @param $uri * @return array */ public function route($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']; $infoblock = \TAO::getInfoblock($row['infoblock']); if ($infoblock) { $urls = $infoblock->urls(); if (isset($urls[$mode])) { $data = $urls[$mode]; $route = isset($data['route']) ? $data['route'] : array(); if (!isset($route['action'])) { $route['bundle'] = 'Elements'; $route['controller'] = 'Index'; $route['action'] = 'index'; } $route['item_id'] = $id; $route['mode'] = $mode; $route['infoblock'] = $infoblock; return $route; } } } }
/** * @param $fields * @return bool|mixed */ protected static function getInfoblock(&$fields) { if (isset($fields['FROM_TAO_API']) && $fields['FROM_TAO_API']) { return false; } if (!isset($fields['IBLOCK_ID'])) { return false; } return \TAO::getInfoblock((int) $fields['IBLOCK_ID']); }
/** * @return array */ public function getItems() { if ($this->multiple() && isset($this->data['LINK_IBLOCK_ID'])) { $ib = \TAO::getInfoblock($this->data['LINK_IBLOCK_ID']); if ($ib) { $out = array(); foreach ($this->valueData() as $data) { $value = $this->valueFromData($data); $item = $ib->loadItem($value); if ($item) { $out[$item->id()] = $item; } } return $out; } } return array(); }
<?php require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/header.php"; $code = trim($_GET['infoblock']); $mode = isset($_GET['mode']) ? trim($_GET['mode']) : 'full'; $id = (int) $_GET['id']; $infoblock = TAO::getInfoblock($code); $item = $infoblock->loadItem($id); if ($item) { $item->preparePage($mode); print $item->render($mode); } else { LocalRedirect('/404.php'); } require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/footer.php";
/** * @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)); } } } }
/** * */ public static function findPage() { global $DB; $uri = self::cleanUri(); $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']; $infoblock = \TAO::getInfoblock($row['infoblock']); if ($infoblock) { $urls = $infoblock->urls(); if (isset($urls[$mode])) { $data = $urls[$mode]; var_dump($data); die; if (isset($data['page'])) { $page = $data['page']; $path = self::uriToFile($page); if ($path) { self::processElement($id, $infoblock->getMnemocode(), $mode, $page, $path); return; } } } } } foreach (self::$defaultUrls as $regexp => $data) { if (preg_match($regexp, $uri, $m)) { if (isset($m['id'])) { $id = $m['id']; $page = $data['page']; $path = self::uriToFile($page); if ($path) { self::processElement($id, $data['infoblock'], $data['mode'], $page, $path); return; } } } } }
/** * @param $data */ protected function elementTypePreprocess(&$data) { $infoblock = false; if (isset($data['LINK_IBLOCK_ID'])) { $infoblock = \TAO::getInfoblock((int) $data['LINK_IBLOCK_ID']); } elseif (isset($data['LINK_IBLOCK_CODE'])) { $infoblock = \TAO::getInfoblock($data['LINK_IBLOCK_CODE']); } if ($infoblock) { $items = array(); foreach ($infoblock->getRows() as $row) { $items[$row['ID']] = $row['NAME']; } $data['ITEMS'] = $items; } }
private function getRepository() { if (!$this->repository) { $this->repository = new ProductRepository(\TAO::getInfoblock('shop')); } return $this->repository; }