public static function loadNsLibrary($className) { $pathParts = explode('\\', $className); self::$_lastLoadedFilename = implode(DIRECTORY_SEPARATOR, $pathParts) . '.php'; try { if (file_exists($_SERVER["DOCUMENT_ROOT"] . "/" . self::$_lastLoadedFilename)) { require_once($_SERVER["DOCUMENT_ROOT"] . "/" . self::$_lastLoadedFilename); } } catch (\Exception $e) { prent($e->getMessage()); } }
public function __construct($file, $data = null, $folder = HTMLROOT, $ext = 'html', $dev = DEV, $stag = '<!-- ', $etag = ' -->') { //global $Obfuscation; if ($folder == HTMLROOT) { $this->CSS = new View($file, $data, CSSROOT, 'css', DEV, '/*', '*/'); $this->CSS = !isset($this->CSS->Template) ? '' : $this->CSS->Template; $this->JS = new View($file, $data, JSROOT, 'js', DEV, '/*', '*/'); $this->JS = !isset($this->JS->Template) ? '' : $this->JS->Template; } if (is_array($data)) { foreach ($data as $k => $c) { if (is_object($c)) { $this->CSS .= $c->CSS; $this->JS .= $c->JS; } } } $file = "{$folder}{$file}.{$ext}"; if (!file_exists($file)) { if ($folder == HTMLROOT) { prent('ERROR: View File ' . $file . ' Does Not Exist.'); } return false; } $tpl = ''; $tpl .= !DEV ? '' : $stag . 'START /' . $file . $etag; $tpl .= file_get_contents($file); $tpl .= !DEV ? '' : $stag . 'END /' . $file . $etag; $data = self::KeysToTags($data); foreach ($GLOBALS as $key => $val) { if (substr($key, 0, 5) == 'VIEW_') { global ${$key}; $tpl = ${$key}->ReplaceTags($tpl, $file); } } $tpl = $this->ReplacePTags($tpl, $file); // Replace our normal tags $tpl = self::ViewReplaceTags($tpl, $data); // Replace all Obfuscation tags in this view if (class_exists('Obfuscation')) { $tpl = Obfuscation::ReplaceTags($tpl); } $this->Template = $tpl; }
<?php /** /Setup/index.php Controller is Included By Setup.php Provides (string)$BodyHeader - {BodyHeader} Tag Replace Data Provides & Expects (string)$BodyPage - {BodyPage} Tag Replace Data Provides (string)$BodyFooter - {BodyFooter} Tag Replace Data Provides (string)$PAGE - Control & View File Name **/ // Index PAGE Controller new Controller(Login, function ($p) use(&$BodyPage, $PAGE) { // <--- Note the use() if (isset($_POST['Submit'])) { switch ($_POST['Submit']) { case 'Login': prent($_POST); break; } } // Return our main index view, using above data to output into the views $BodyPage = new View('Body/Page/' . $PAGE, []); });
/** * This powerful function helps in many places, it handles checking a regexp against the page (PAGE) url, and returns the url, or $return, or false * @param (string) $regexp // regexp to check against the page url * @param (anything) $return // (including closures, which the $return is then passed the regexp) * @author Casey Childers */ function p($regexp, $return = null) { global $p; if (is_string($regexp)) { try { $pm = preg_match($regexp, PAGE, $m) ? PAGE : null; } catch (ErrorException $e) { prent('Caught exception: ', $e->getMessage(), "\n"); } } else { if (is_bool($regexp)) { $m = $regexp; $pm = $regexp ? PAGE : null; } } // Allows us to now do $p['name'] for regexp matches that have a named group such as (?<name>some|data) if (isset($m) && is_array($m) && !empty($m)) { foreach ($m as $key => $match) { $p[$key] = $match; } } return $return && $pm ? is_closure($return) ? $return($m) : $return : $pm; }
private function Add() { if (!$this->checker->withParams(array("NAME" => $this->arFields["PROPERTY_VALUES"]["LOCATION"], "IBLOCK_ID" => $this->arFields["IBLOCK_ID"], "SECTION_ID" => CRONSBS_SECTION_ID))->existedID()) { prent($this->arFields["PROPERTY_VALUES"]["ADDRESS"]); return false; $this->arFields["SECTION_ID"] = CRONSBS_SECTION_ID; $this->objElement->Add($this->arFields); if ($this->objElement->LAST_ERROR) { prent($this->objElement->LAST_ERROR); } } else { $this->UpdateStatus(); } return false; }
public function go() { try { $this->checker = \Ns\Bitrix\Helper::Create('iblock')->useVariant('checker'); } catch (\Exception $e) { prentExpection($e->getMessage()); } $table = \phpQuery::pq($this->dom->find("div#catalog")->find("table#tbl")); $index = 0; foreach ($table->find("tr") as $tr) { var_dump($index); if (++$index == 1) { continue; } $this->arFields = array(); $this->arFields["IBLOCK_ID"] = self::ALFATERMINALS_IBLOCK_ID; $this->arFields["IBLOCK_SECTION_ID"] = ($this->type == "alfa") ? self::ALFATERMINALS_SECTION_ID : self::SBSTERMINALS_SECTION_ID; /** * Получение информации о банкомете */ $tr = \phpQuery::pq($tr); /** * 1. Name */ $this->arFields["NAME"] = $tr->find('td:eq(0)')->find("a")->text(); $infoLink = $tr->find('td:eq(0)')->find("a")->attr("href"); /** * 2. State */ $this->arFields["PROPERTY_VALUES"]["STATE"] = $tr->find('td:eq(1)')->text(); /** * 3. City as link */ $this->arFields["PROPERTY_VALUES"]["BIND_CITY"] = $this->findCity($tr->find('td:eq(2)')->text()); /** * 4. City text */ $this->arFields["PROPERTY_VALUES"]["CITY"] = $tr->find('td:eq(2)')->text(); /** * 5. Address */ $this->arFields["PROPERTY_VALUES"]["ADDRESS"] = $tr->find('td:eq(3)')->text(); /** * 5. Operating mode */ $this->arFields["PROPERTY_VALUES"]["OPERATION_TIME"] = $tr->find('td:eq(4)')->text(); /** * Find nessesary element of link */ try { $this->arFields["PROPERTY_VALUES"]["WORK_TYPES"] = $this->findWorkType($this->arFields["PROPERTY_VALUES"]["OPERATION_TIME"]); } catch (\Exception $e) { prentExpection($e->getMessage()); } $html = file_get_contents("http://www.alfabank.by" . $infoLink); $fullInfo = \phpQuery::newDocumentHTML($html); $info = \phpQuery::pq($fullInfo->find("div.content")); /** * Compose currency string */ $info->find("div.section.s1")->find('table')->find('tr'); foreach ($info->find("div.section.s4")->find('ul')->find('li') as $li) { $li = \phpQuery::pq($li); $strCurrency .= $li->text() . " "; } $this->arFields["PROPERTY_VALUES"]["CURRENCY"] = trim($strCurrency); unset($strCurrency); /** * Lat & len of map */ // $coordinates = explode(",", $info->find("div.section:eq(5)")->find("div.ya_map_data")->text()); $coordinates = $info->find("div.section:eq(5)")->find("div.ya_map_data")->text(); $this->arFields["PROPERTY_VALUES"]["POINT"] = $coordinates; /** * Compose name for element of infoblock */ prent($this->arFields); $this->Add(); } /** * Check and add element to infoblock Terminals */ return true; }
private function findOrCreateSection($name, $parent = 0) { if (!$name) { return false; } $rs = \CIBlockSection::GetList( false, array( "IBLOCK_ID" => $this->arFields["IBLOCK_ID"], "NAME" => $name, "SECTION_ID" => $parent ), false, array("ID") ); if ($section = $rs->Fetch()) { return $section["ID"]; } else { $arFields = array( "IBLOCK_ID" => $this->arFields["IBLOCK_ID"], "NAME" => $name, "IBLOCK_SECTION_ID" => $parent, "ACTIVE" => "Y" ); $section = $this->objSection->Add($arFields); if ($this->objSection->LAST_ERROR) { prent($this->objSection->LAST_ERROR); throw new Exception("Error of adding section", 1); } else { return $section; } } }
private function Add() { if ($this->checker->withParams(array("NAME" => $this->arFields["NAME"], "IBLOCK_ID" => $this->arFields["IBLOCK_ID"]))->isUnique()) { $this->objElement->Add($this->arFields); if ($this->objElement->LAST_ERROR) { prent($this->objElement->LAST_ERROR); } } }