public function get_page($request_uri = false, $hide_default_doc = false) { if ($request_uri) { if (PERCH_RUNWAY && $this->admin == false) { $Runway = PerchRunway::fetch(); $out = $Runway->get_page(true); } else { $out = str_replace(PERCH_DEFAULT_DOC, '', strtolower($_SERVER['SCRIPT_NAME'])); if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != '') { $out .= '?' . $_SERVER['QUERY_STRING']; } $out = preg_replace('/(\\/)\\1+/', '/', $out); } return $out; } if ($this->page === false) { $this->page = strtolower($_SERVER['SCRIPT_NAME']); } if ($this->page != false) { $this->page = preg_replace('/(\\/)\\1+/', '/', $this->page); } if ($hide_default_doc) { return str_replace(PERCH_DEFAULT_DOC, '', $this->page); } return $this->page; }
public function find_installed_apps($CurrentUser) { $this->apps = array(); if (!$CurrentUser->logged_in()) { return; } $a = array(); foreach ($this->core_apps as $core_app) { $a[] = array('filename' => $core_app, 'path' => PerchUtil::file_path(PERCH_CORE . '/apps/' . $core_app)); } if (is_dir(PerchUtil::file_path(PERCH_PATH . '/addons/apps'))) { if ($dh = opendir(PerchUtil::file_path(PERCH_PATH . '/addons/apps'))) { while (($file = readdir($dh)) !== false) { if (substr($file, 0, 1) != '.' && !preg_match($this->ignore_pattern, $file) && substr($file, 0, 1) != '_') { if (is_dir(PerchUtil::file_path(PERCH_PATH . '/addons/apps/' . $file))) { $a[] = array('filename' => $file, 'path' => PerchUtil::file_path(PERCH_PATH . '/addons/apps/' . $file)); } } } closedir($dh); } } if (is_array($a)) { foreach ($a as &$app) { $file = PerchUtil::file_path($app['path'] . '/admin.php'); if (file_exists($file)) { include $file; } } } if (PERCH_RUNWAY) { $Runway = PerchRunway::fetch(); $Runway->find_collections_for_app_menu($CurrentUser); } $this->apps = PerchUtil::super_sort($this->apps, 'priority', 'label'); }
private function _replace_form_tags($template, $opening_tag, $closing_tag) { $Perch = Perch::fetch(); $OpeningTag = new PerchXMLTag($opening_tag); if ($OpeningTag->prefix()) { if ($OpeningTag->prefix() == 'none') { $this->field_prefix = ''; } else { $this->field_prefix = $OpeningTag->prefix() . '_'; } } else { $Perch->form_count++; $this->field_prefix = 'form' . $Perch->form_count . '_'; } $attrs = array(); $attrs['id'] = $this->field_prefix . $OpeningTag->id(); $attrs['class'] = $OpeningTag->class(); $attrs['action'] = $OpeningTag->action(); $attrs['method'] = $OpeningTag->method(); $attrs['role'] = $OpeningTag->role(); $attrs['name'] = $OpeningTag->name(); $attrs['autocomplete'] = $OpeningTag->autocomplete(); $aria = $OpeningTag->search_attributes_for('aria-'); if (PerchUtil::count($aria)) { $attrs = array_merge($attrs, $aria); } $html5data = $OpeningTag->search_attributes_for('data-'); if (PerchUtil::count($html5data)) { $attrs = array_merge($attrs, $html5data); } $this->form_id = $OpeningTag->id(); $this->handling_app = $OpeningTag->app(); $this->template_path = $OpeningTag->template(); $this->action = $OpeningTag->action(); $this->app = $OpeningTag->app(); $this->method = $OpeningTag->method(); if (PERCH_HTML5 && $OpeningTag->novalidate()) { $attrs['novalidate'] = 'novalidate'; } if (PERCH_RUNWAY) { if (!$attrs['action']) { $Runway = PerchRunway::fetch(); $attrs['action'] = $Runway->get_page(); } } else { if (!$attrs['action']) { $attrs['action'] = $Perch->get_page_as_set(true); } } // submit via ssl? if (PERCH_SSL && $OpeningTag->ssl() && PerchUtil::bool_val($OpeningTag->ssl())) { $attrs['action'] = PerchUtil::url_to_ssl($attrs['action']); } if (!$attrs['method']) { $attrs['method'] = 'post'; } $this->form_key = base64_encode($this->form_id . ':' . $this->handling_app . ':' . $this->template_path . ':' . time()); // Does it have file fields? $s = '/(<perch:input[^>]*type="(file|image)"[^>]*>)/s'; if (preg_match($s, $template)) { $attrs['enctype'] = 'multipart/form-data'; } $new_opening_tag = PerchXMLTag::create('form', 'opening', $attrs); $template = str_replace($opening_tag, $new_opening_tag, $template); $new_closing_tag = PerchXMLTag::create('form', 'closing'); $template = str_replace($closing_tag, $new_closing_tag, $template); return $template; }