public function __construct($u = "") { $C = 'd_' . sha1(url() . '/' . Core::$user->id . '/' . Core::$client->lang); $data = Cache::get($C); try { if (empty($data['id'])) { DS::ds(0); if (empty($u)) { $u = Core::$core->url; } $data = DS::fetch("a.*,b.ctrl", "pages a LEFT JOIN views b ON a.template=b.id", "(a.id=? OR ? LIKE a.id||'/%') AND " . "(a.lang='' OR a.lang=?) AND " . (ClassMap::has("PHPPE\\CMS") && get_class(View::getval('app')) == "PHPPE\\Content" && Core::$user->has("siteadm|webadm") ? "" : "a.publishid!=0 AND ") . "a.pubd<=CURRENT_TIMESTAMP AND (a.expd='' OR a.expd=0 OR a.expd>CURRENT_TIMESTAMP)", "", "a.id DESC,a.created DESC", [$u, $u, Core::$client->lang]); if (!empty($data['id'])) { Cache::set($C, $data); } else { return; } } if (!empty($data['filter']) && !Core::cf($data['filter'])) { Core::$core->template = '403'; return; } Core::$core->template = $data['template']; Core::$core->title = $data['name']; $o = json_decode($data['data'], true); if (is_array($o)) { foreach ($o as $k => $v) { if (substr($k, 0, 4) == "app.") { $k = substr($k, 4); } $this->{$k} = $v; } } foreach (['id', 'name', 'lang', 'modifyd', 'ctrl', 'publishid'] as $k) { $this->{$k} = $data[$k]; } $E = json_decode($data['dds'], true); if (is_array($E)) { self::$dds += $E; } } catch (\Exception $e) { } }
/** * Execute a query and return number of affected rows (commands) or data set (select query). * * @param array arguments array, values for placeholders * @param integer data source selector * * @return integer/array number of affected rows or result set (array of assoc arrays) */ public function execute($arguments = [], $ds = -1) { //! set data source if requested if ($ds != -1) { $old_ds = DS::ds(); DS::ds($ds); } //! get sql sentance $sql = $this->sql(); if (strpos($sql, '?') !== false && empty($arguments)) { throw new DBException(L('Placeholder(s) in SQL without argument') . ': ' . $sql); } //! execute the query with PHPPE Core try { $ret = DS::exec($sql, $arguments); // @codeCoverageIgnoreStart } catch (\Exception $e) { throw new DBException(L($e->getMessage()) . ': ' . $sql); // @codeCoverageIgnoreEnd } //! restore data source if changed if ($ds != -1) { DS::ds($old_ds); } //! return result return $ret; }