/** * @param $data * @param $path */ protected static function mergeLangData(&$data, $path) { if (is_file($path)) { $messages = (include $path); $data = \TAO::mergeArgs($data, $messages); } }
/** * @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; } } } }
public function items() { $catalogProductSet = new CCatalogProductSet(); $arSets = $catalogProductSet->getAllSetsByProduct($this->id(), CCatalogProductSet::TYPE_SET); /** @var Bundle $shop */ $shop = \TAO::bundle('Shop'); $items = array(); foreach ($arSets as $arSet) { $items[] = $shop->getProductById($arSet['ID']); } return $items; }
/** * */ public static final function run() { $c = 0; self::$actions = array(); self::$options = array(); $argv = $GLOBALS['argv']; foreach ($argv as $arg) { $arg = trim($arg); if (preg_match('{^--([^\\s=]+)=(.*)}', $arg, $m)) { self::$options[$m[1]] = $m[2]; } else { if (preg_match('{^--([^\\s=]+)}', $arg, $m)) { self::$options[$m[1]] = true; } else { if ($c == 0) { self::$script = $arg; } else { self::$actions[$c - 1] = $arg; } $c++; } } } foreach (self::$actions as $action) { $dir = \TAO::localDir('lib/CLI'); if (is_dir($dir)) { $dir = dir($dir); while ($entry = $dir->read()) { if (preg_match('{^(.+)\\.php$}', $entry, $m)) { $class = '\\App\\CLI\\' . $m[1]; $object = new $class(); $object->runAction($action); } } } foreach (\TAO::bundles() as $bundle) { $bundle->cli($action, self::$options); } if (isset(self::$handlers[$action])) { $cb = self::$handlers[$action]; if (is_string($cb)) { $cb = array($cb, $action); } if (is_callable($cb)) { call_user_func($cb, self::$options); } } } }
private function addProduct($data) { /** @var \TAO\Bundle\Shop\Bundle $shop */ $shop = \TAO::bundle('Shop'); foreach ($data as $productData) { $isProductSet = !empty($productData['items']); if ($isProductSet) { $items = array(); foreach ($productData['items'] as $itemData) { $items[] = $shop->getProduct($itemData['name'], $itemData['price'], isset($itemData['description']) ? $itemData['description'] : '', $itemData['parameters']); } $product = $shop->getProductSet($productData['name'], $productData['price'], isset($productData['description']) ? $productData['description'] : '', $items); } else { $product = $shop->getProduct($productData['name'], $productData['price'], isset($productData['description']) ? $productData['description'] : '', $productData['parameters']); } $shop->addProductToCart($product, $productData['quantity']); } }
public static function canonizeData($type, $data) { if (!$data) { $data = $type; } if (is_string($data)) { $data = array('NAME' => $data); } if (!isset($data['ID'])) { $data['ID'] = $type; } if (!isset($data['NAME'])) { $data['NAME'] = $type; } if (!isset($data['IN_RSS'])) { $data['IN_RSS'] = 'N'; } if (!isset($data['SORT'])) { $data['SORT'] = '500'; } if (!isset($data['EDIT_FILE_BEFORE'])) { $data['EDIT_FILE_BEFORE'] = ''; } if (!isset($data['EDIT_FILE_AFTER'])) { $data['EDIT_FILE_AFTER'] = ''; } $ldata = isset($data['LANG']) ? $data['LANG'] : array(); foreach (array_keys(\TAO::getLangs()) as $lang) { $ld = isset($ldata[$lang]) ? $ldata[$lang] : array(); if (!isset($ld['NAME'])) { $ld['NAME'] = isset($data["NAME_{$lang}"]) ? $data["NAME_{$lang}"] : $data["NAME"]; } $ldata[$lang] = $ld; } $data['LANG'] = $ldata; unset($data['NAME']); return $data; }
/** * @return string */ public function path() { return \TAO::rootDir(\CFile::GetPath($this->id)); }
/** * */ 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; } } } } }
<?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); }
/** * @return string */ private function subdir() { return \TAO::unchunkCap($this->name); }
} } ?> <h2>Экспорт типа "<?php echo $name; ?> "</h2> Мнемокод: <b><?php echo $code; ?> </b>, файл: <b>local/schema/types/<?php echo $code; ?> .php</b><br> <?php $className = \TAO::chunkCap($code); ob_start(); include \TAO::taoDir() . '/views/template-type.phtml'; $content = "<?php\n" . ob_get_clean(); ?> <textarea wrap="off" style="width:90%; height: 400px; padding: 10px; border: 1px solid #888; background-color: white; font-family: monospace; font-size: 10px;"><?php echo str_replace('<', '<', $content); ?> </textarea> <?php include $_SERVER['DOCUMENT_ROOT'] . '/local/vendor/techart/bitrix.tao/include/epilog_admin.php'; ?>
/** * @param $page * @param $numPages * @return string */ public function render($page, $numPages) { $path = \TAO::filePath($this->dirs('views'), 'page-navigator.phtml', $this->type); $style = \TAO::filePath($this->dirs('styles'), 'pager.css', $this->type); ob_start(); include $path; $content = ob_get_clean(); return $content; }
<?php include $_SERVER['DOCUMENT_ROOT'] . '/local/vendor/techart/bitrix.tao/include/prolog_admin.php'; $id = $_GET['id']; $data = CIBlock::GetByID($id)->Fetch(); if ($data) { $code = $data['CODE']; $name = $data['NAME']; ?> <h2>Экспорт схемы инфоблока "<?php echo $name; ?> "</h2> <?php \TAO::load('infoblock_export'); $content = \TAO\InfoblockExport::run($id); } ?> <textarea wrap="off" style="width:90%; height: 400px; padding: 10px; border: 1px solid #888; background-color: white; font-family: monospace; font-size: 10px;"><?php echo str_replace('<', '<', $content); ?> </textarea> <?php include $_SERVER['DOCUMENT_ROOT'] . '/local/vendor/techart/bitrix.tao/include/epilog_admin.php';
/** * @param $file * @return bool|string */ public function staticPagePath($file) { $path = \TAO::localDir("pages/{$file}"); return is_file($path) ? $path : false; }
/** * */ protected function noLayout() { \TAO::$layout = false; }
private function addCatalogSetProperties($productId, $products) { $parameters = array('TYPE' => CCatalogProductSet::TYPE_SET, 'SET_ID' => 0, 'ID' => $productId, 'ITEM_ID' => $productId, 'ITEMS' => array_map(function ($product) { /** @var Product $product */ return array('ACTIVE' => 'Y', 'ITEM_ID' => $product->id(), 'QUANTITY' => 1); }, $products)); if (!$this->sets->add($parameters)) { throw new \Exception('Cant create product set ' . \TAO::app()->getException()->GetString()); } return true; }
<?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";
} if ($row['Key'] == 'MUL') { $type .= ' index'; $indexes[$name] = true; } $columns[$name] = $type; } } foreach ($fields as $field => $type) { if ($field == 'id') { continue; } list($column, $index) = self::parseField($table, $field, $type); if (isset($columns[$field]) && $column) { $query = "ALTER TABLE {$table} CHANGE `{$field}` {$column}"; $DB->Query($query); } else { $query = "ALTER TABLE {$table} ADD {$column}"; $DB->Query($query); } if ($index && !isset($indexes[$field])) { $index = preg_replace('{^KEY }', 'INDEX ', $index); $query = "ALTER TABLE {$table} ADD {$index}"; $DB->Query($query); } } } } if (\TAO::cache()->fileUpdated(__FILE__)) { TablesSchema::process(); }
protected function officeAuthUrl() { return $this->officeAuthUrl ?: ($this->officeAuthUrl = \TAO::getOption('auth')); }
chdir($_SERVER['DOCUMENT_ROOT']); \TAO\Urls::processVars(); $content = \TAO\Bundle::routeBundles(); if (is_string($content)) { if (is_string(\TAO::$layout)) { $prolog = $_SERVER["DOCUMENT_ROOT"] . BX_ROOT . "/modules/main/include/prolog_after.php"; $epilog = $_SERVER["DOCUMENT_ROOT"] . "/bitrix/footer.php"; if (\TAO::$layout == 'admin') { $prolog = $_SERVER["DOCUMENT_ROOT"] . BX_ROOT . "/modules/main/include/prolog_admin.php"; $epilog = $_SERVER["DOCUMENT_ROOT"] . BX_ROOT . "/modules/main/include/epilog_admin.php"; } require $prolog; if (\TAO::$compositeContent) { $frame = \TAO::compositeFrame(\TAO::$compositeContent); $stub = trim(\TAO::$compositeStub); $stub = strlen($stub) > 0 ? $stub : \TAO::t('composite_loading'); $frame->begin($stub); } print $content; if (\TAO::$compositeContent) { $frame->end(); } require $epilog; die; } print $content; die; } $nativeScript = '/bitrix/urlrewrite.php'; $_SERVER['SCRIPT_FILENAME'] = $_SERVER['DOCUMENT_ROOT'] . $nativeScript; $_SERVER['SCRIPT_NAME'] = $_SERVER['DOCUMENT_URI'] = $_SERVER['PHP_SELF'] = $nativeScript;
/** * @return array|string */ public static function processPost() { if ($_SERVER['REQUEST_METHOD'] != 'POST') { return 'ERROR: Invalid request!'; } if (!isset($_POST['taoform'])) { return 'ERROR: Form not defined!'; } $name = trim($_POST['taoform']); $form = \TAO::form($name); if (!$form) { return 'ERROR: Unknown form!'; } return $form->process(); }
/** * @param bool|false $navigation * @return $this */ public function addNavigation($navigation = false) { if (!$navigation) { $navigation = \TAO::navigation(); } $navigation->sitemap($this); return $this; }
/** * @param $id * @param bool|false $forCache * @return bool|string */ public static function run($id, $forCache = false) { $data = \CIBlock::GetByID($id)->Fetch(); if ($data) { $code = $data['CODE']; $name = $data['NAME']; $isactive = $data['ACTIVE'] == 'Y'; $sort = $data['SORT']; $description = (string) $data['DESCRIPTION']; $descriptionType = $data['DESCRIPTION_TYPE']; $className = $forCache ? \TAO::normalizeMnemocode($code) : \TAO::chunkCap($code); unset($data['ID']); unset($data['TIMESTAMP_X']); unset($data['IBLOCK_TYPE_ID']); unset($data['CODE']); unset($data['NAME']); unset($data['LANG_DIR']); unset($data['SERVER_NAME']); unset($data['LID']); unset($data['ACTIVE']); unset($data['SORT']); unset($data['DESCRIPTION']); unset($data['DESCRIPTION_TYPE']); $defs = array('RSS_ACTIVE' => 'Y', 'RSS_TTL' => '24', 'RSS_FILE_ACTIVE' => 'N', 'RSS_YANDEX_ACTIVE' => 'N', 'INDEX_ELEMENT' => 'Y', 'INDEX_SECTION' => 'N', 'WORKFLOW' => 'Y', 'VERSION' => '1', 'BIZPROC' => 'N', 'SECTION_CHOOSER' => 'L', 'RIGHTS_MODE' => 'S', 'SECTION_PROPERTY' => 'N', 'PROPERTY_INDEX' => 'N'); foreach (array_keys($data) as $k) { if (empty($data[$k])) { unset($data[$k]); } if (isset($defs[$k]) && $defs[$k] == $data[$k]) { unset($data[$k]); } } $sites = ''; $res = \CIBlock::GetSite($id); while ($row = $res->Fetch()) { $sites .= $sites != '' ? ',' : ''; $sites .= "'" . $row['SITE_ID'] . "'"; } unset($data['ELEMENTS_NAME']); unset($data['ELEMENT_NAME']); $sData = self::generateArrayExport($data, ' '); $sDescription = self::generateSimpleStringFunctionText('description', $description, ''); $sDescriptionType = self::generateSimpleStringFunctionText('descriptionType', $descriptionType, 'text'); $sIsActive = self::generateSimpleStringFunctionText('isActive', $isactive, true); $sSort = self::generateSimpleStringFunctionText('sort', $sort, '500'); $sSites = "\n\n public function sites()\n {\n return array({$sites});\n }"; $properties = array(); $result = \CIBlockProperty::GetList(array(), array('IBLOCK_ID' => $id, 'CHECK_PERMISSIONS' => 'N')); $defs = array('VERSION' => '1', 'FILTRABLE' => 'N', 'SEARCHABLE' => 'N', 'LIST_TYPE' => 'L', 'COL_COUNT' => '30', 'ROW_COUNT' => '1', 'MULTIPLE' => 'N', 'SORT' => '500', 'IS_REQUIRED' => 'N', 'WITH_DESCRIPTION' => 'N', 'MULTIPLE_CNT' => '5'); while ($row = $result->Fetch()) { $code = trim($row['CODE']); if ($code == '') { $code = 'PROP_' . $row['ID']; } $pid = $row['ID']; unset($row['ID']); unset($row['TIMESTAMP_X']); unset($row['IBLOCK_ID']); unset($row['ACTIVE']); unset($row['CODE']); foreach (array_keys($row) as $k) { if (empty($row[$k])) { unset($row[$k]); } if (isset($defs[$k]) && $defs[$k] == $row[$k]) { unset($row[$k]); } } if ($row['PROPERTY_TYPE'] == 'L') { $items = array(); $res = \CIBlockPropertyEnum::GetList(array(), array('PROPERTY_ID' => $pid, 'CHECK_PERMISSIONS' => 'N')); while ($lrow = $res->Fetch()) { $iid = $lrow['ID']; $eid = $lrow['EXTERNAL_ID']; unset($lrow['ID']); unset($lrow['EXTERNAL_ID']); unset($lrow['XML_ID']); unset($lrow['TMP_ID']); unset($lrow['PROPERTY_ID']); unset($lrow['PROPERTY_NAME']); unset($lrow['PROPERTY_CODE']); unset($lrow['PROPERTY_SORT']); if ($lrow['SORT'] == '500') { unset($lrow['SORT']); } if ($lrow['DEF'] == 'N') { unset($lrow['DEF']); } if (count($lrow) == 1 && isset($lrow['VALUE'])) { $lrow = $lrow['VALUE']; } $items[$eid] = $lrow; } $row['ITEMS'] = $items; } if (isset($row['LINK_IBLOCK_ID']) && !$forCache) { $row['LINK_IBLOCK_CODE'] = \TAO::getInfoblockCode($row['LINK_IBLOCK_ID']); unset($row['LINK_IBLOCK_ID']); } $properties[$code] = $row; } $sProperties = self::generateArrayExport($properties, ' '); $messages = \CIBlock::GetMessages($id); $sMessages = self::generateArrayExport($messages, ' '); $fields = self::trimArrayValues(\CIBlock::GetFields($id)); $defFields = self::defaultFields(); foreach (array_keys($fields) as $field) { if (isset($defFields[$field])) { $md5 = md5(serialize($fields[$field])); $def = md5(serialize($defFields[$field])); if ($md5 == $def) { //unset($fields[$field]); } else { //var_dump($fields[$field], $defFields[$field]); } } } $sFields = self::generateArrayExport($fields, ' '); $permissions = \CIBlock::GetGroupPermissions($id); $sPermissions = self::generateArrayExport($permissions, ' '); ob_start(); include \TAO::taoDir() . '/views/template-iblock.phtml'; $content = "<?php\n" . ob_get_clean(); return $content; } return false; }
/** * @param array $args * @return string */ public function render($args = array()) { if (is_string($args)) { $args = array('mode' => $args); } $mode = isset($args['mode']) ? $args['mode'] : (isset($args['page_mode']) ? $args['page_mode'] : 'section-page'); $path = $this->viewPath($mode); $args['section'] = $this; if (!isset($args['page_class'])) { $icode = $this->infoblock()->getMnemocode(); $id = $this->id(); $code = trim($this['CODE']); $args['page_class'] = "infoblock-section-page infoblock-{$icode}-section-page infoblock-{$icode}-section-{$code}-page infoblock-{$icode}-section-{$id}-page section-{$id}-page section-{$code}-page"; } $APPLICATION = \TAO::app(); ob_start(); include $path; $content = ob_get_clean(); return $content; }
/** * @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(); }
/** * @param $script */ protected function useScript($script) { return \TAO::useStyle($script); }
/** * @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']); }
<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_before.php'; $result = \TAO::processForm(); if (is_array($result)) { $form = $result['form']; if ($form->isValid()) { $url = $form->option('return_url'); if (!$url) { $url = '/local/vendor/techart/bitrix.tao/api/form-ok.php'; } \LocalRedirect($url); } else { require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/header.php"; $APPLICATION->SetTitle($form->option('error_title')); print $form->render(); require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/footer.php"; } } elseif (is_string($r)) { print $r; die; } else { var_dump($r); die; }
/** * @param bool|true $name * @return \Bitrix\Main\Page\FrameHelper */ public static function compositeFrame($name = true) { $name = is_string($name) && strlen($name) > 0 ? $name : \TAO::randString(); return new Bitrix\Main\Page\FrameHelper($name, true); }
public function js($name, $additional = false) { if ($file = $this->file('js', $name)) { \TAO::app()->AddHeadScript($file, $additional); } }