public function testParseXml() { $this->object->load($this->fileName, null, true); $xml = $this->object->parseXml(); $xml->formatOutput = true; echo $xml->saveXML(); }
public function runStrategy() { $fname = Helper::get('savedir') . '/schema.php'; if (!file_exists($fname)) { echo "File: {$fname} does not exist!\n"; exit; } $this->askForRewriteInformation(); require_once $fname; $sc = new Schema(); $sc->load(Helper::getDbObject()); }
protected function setUp($preset = null) { switch ($preset) { case 'pages': $this->type = 'domain'; $this->parent = null; $this->columns = array('name', 'title', 'language', 'params', 'theme'); $this->actions = array('publish', 'unpublish', 'delete'); try { $node = Node::load(array('class' => 'domain', 'deleted' => 0, 'name' => $this->subid)); $this->title = t('Страницы в домене «%name»', array('%name' => $node->name)); } catch (ObjectNotFoundException $e) { $this->title = t('Непонятный домен'); } $this->addlink = 'admin/create/domain' . '/' . $this->getParentId() . '?destination=' . urlencode(MCMS_REQUEST_URI); break; } if (!empty($this->type) and !is_array($this->type)) { $schema = Schema::load($this->ctx->db, $this->type); // Удаляем отсутствующие колонки. foreach ($this->columns as $k => $v) { if (!isset($schema[$v])) { unset($this->columns[$k]); } } // Формируем описания колонок. foreach ($schema as $k => $v) { if (!array_key_exists($k, $this->columntitles)) { $this->columntitles[$k] = $v->label; } } } }
private static function getProfileFields() { $result = array(); foreach (Schema::load(Context::last()->db, 'user') as $k => $v) { $result[$k] = $v->label; } if (isset($result['groups'])) { unset($result['groups']); } asort($result); return $result; }
/** * Возвращает форму для настройки виджета. * * @return Form вкладка для настройки виджета. */ public static function getConfigOptions(Context $ctx) { $fields = array(); $schema = Schema::load($ctx->db, 'tag'); foreach ($schema as $k => $v) { if ($v instanceof URLControl) { $fields[$k] = $v->label; } } asort($fields); $tags = array('anything' => t('Текущий, если в нём пусто — родительский'), 'parent' => t('Родительский (соседние разделы)'), 'root' => t('Из настроек страницы')); foreach (Node::getSortedList('tag') as $k => $v) { $tags[$k] = $v; } return array('fixed' => array('type' => 'EnumControl', 'label' => t('Всегда возвращать раздел'), 'description' => t("По умолчанию виджет возвращает информацию о текущем разделе. Вы можете настроить его на фиксированный раздел. Подсветка текущего раздела при этом сохранится."), 'options' => $tags, 'default' => t('Текущий (его подразделы)')), 'depth' => array('type' => 'NumberControl', 'label' => t('Глубина'), 'description' => t("Меню будет содержать столько уровней вложенности."))); }
/** * Индексация документов, отсутствующих в индексе. */ private static function reindexMissingNodes(Context $ctx, Node $type) { $schema = Schema::load($ctx->db, $type->name); foreach ($schema->getIndexes() as $fieldName) { $tableName = 'node__idx_' . $fieldName; try { $ids = $ctx->db->getResultsV("id", "SELECT `id` FROM `node` WHERE `class` = ? AND `deleted` = 0 AND `id` NOT IN (SELECT `id` FROM `{$tableName}`)", array($type->name)); $upd = $ctx->db->prepare("INSERT INTO `{$tableName}` (`id`, `value`) VALUES (?, ?)"); $count = 0; foreach ((array) $ids as $nid) { $node = Node::load($nid, $ctx->db); $upd->execute(array($nid, $schema[$fieldName]->getIndexValue($node->{$fieldName}))); } } catch (TableNotFoundException $e) { Logger::log($e->getTableName() . ': missing table.'); } } }
private static function reindexNode(Node $node) { return; $html = ''; $schema = Schema::load($node->getDB(), $node->class); foreach ($schema['fields'] as $k => $v) { if (isset($node->{$k})) { $html .= '<strong>' . html::plain($v['label']) . '</strong>'; $html .= '<div class=\'data\'>' . $node->{$k} . '</div>'; } } $lang = empty($node->lang) ? 'en' : $node->lang; $html = "HTTP/1.0 200 OK\n" . "Content-Type: text/html; charset=utf-8\n" . "Content-Language: {$lang}\n\n" . "<html><head><title>{$node->name}</title></head>" . "<body><h1>{$node->name}</h1>{$html}</body></html>"; try { $node->getDB()->exec('DELETE FROM `node__searchindex` WHERE `nid` = :nid', array(':nid' => $node->id)); $node->getDB()->exec('INSERT INTO `node__searchindex` (`nid`, `url`, `html`) ' . 'VALUES (:nid, :url, :html)', array(':nid' => $node->id, ':url' => self::getNodeUrl($node), ':html' => $html)); } catch (TableNotFoundException $e) { } }
/** * Формирование XML кода объекта. */ public final function getXML($em = 'node', $extraContent = null) { $data = array(); if (null !== $this->id and $this->getDB()) { Logger::log("node[{$this->id}]: rebuilding XML ({$this->class},{$this->name})", 'xml'); $data = array('id' => $this->id, '#text' => null); if (empty($this->data['class'])) { throw new RuntimeException(t('Не удалось определить тип ноды.')); } $schema = Schema::load($this->getDB(), $this->data['class']); $properties = array_unique(array_merge(self::getBasicFields(), $schema->getFieldNames())); $stop = $this->getXMLStopFields(); foreach ($properties as $k) { if (empty($k) or in_array($k, $stop)) { continue; } $v = $this->{$k}; if (self::isBasicField($k)) { $data[$k] = $v; continue; } if (isset($schema[$k])) { $data['#text'] .= $schema[$k]->format($this, $k); continue; } } $data['#text'] .= $this->getExtraXMLContent(); } if (null !== $extraContent) { if (!array_key_exists('#text', $data)) { $data['#text'] = $extraContent; } else { $data['#text'] .= $extraContent; } } return html::em($em, $data); }
public function formGet($id) { $form = null; $types = $this->getTypeList($this->options['root']); if ($id == 'form-create-edit') { if (empty($this->options['node'])) { throw new PageNotFoundException(); } $node = Node::load($this->options['node']); if (!$node->checkPermission(ACL::UPDATE)) { throw new ForbiddenException(); } return $node->formGet(); } elseif ($id == 'form-create') { $form = new Form(array('title' => t('Добавление объекта'))); $form->addControl(new InfoControl(array('text' => t('Выберите тип создаваемого документа. Этот список сформирован в соответствии с вашими правами.')))); $form->addControl(new EnumRadioControl(array('value' => 'class', 'label' => t('Тип создаваемого документа'), 'options' => $types))); $form->addControl(new SubmitControl(array('text' => t('Создать')))); return $form; } elseif (false !== strstr($id, 'form-create-')) { if (!array_key_exists($type = substr($id, 12), $types)) { $schema = Schema::load($this->ctx->db, $type); if (empty($schema['id'])) { throw new PageNotFoundException(t('Тип документа «%name» ' . 'мне не известен, создать его невозможно.', array('%name' => $type))); } else { throw new ForbiddenException(t('Вы не можете создать документ ' . 'типа «%name», извините.', array('%name' => $type))); } } $node = $this->getNode($type); $form = $node->formGet($this->stripped); $form->wrapper_class = 'form-create-wrapper'; $form->addControl(new HiddenControl(array('value' => 'referer'))); /* if (!empty($this->options['default'])) { foreach (array_keys($this->options['default']) as $k) { $tmp = $k; $form->replaceControl($tmp, new HiddenControl(array( 'value' => $tmp, ))); } } */ } return $form; }
protected function setUp($preset = null) { $this->deleted = 0; unset($this->title); // Некоторые заготовки. if (null !== ($this->preset = $preset)) { switch ($preset) { case 'drafts': $this->published = 0; $this->title = t('Документы в модерации'); $this->actions = array('publish', 'delete'); break; case 'trash': $this->deleted = 1; $this->title = t('Удалённые документы'); $this->actions = array('undelete', 'erase'); break; case 'groups': $this->types = array('group'); $this->title = t('Список групп'); $this->limit = null; $this->actions = array('delete'); $this->selectors = array('all' => 'все', 'none' => 'ни одной'); break; case 'users': $this->types = array('user'); $this->title = t('Список пользователей'); $this->selectors = array('all' => 'всех', 'none' => 'ни одного', 'published' => 'активных', 'unpublished' => 'заблокированных'); break; case 'files': $this->types = array('file'); $this->title = t('Файловый архив'); $this->actions = array('publish', 'unpublish', 'delete'); break; case 'comments': $this->types = array('comment'); $this->title = t('Список комментариев'); $this->sort = '-id'; break; case '404': $this->title = t('Страницы, которые не были найдены'); break; case 'fields': $this->types = array('field'); break; case 'pages': $this->types = array('domain'); $this->title = t('Домены'); $this->hidesearch = true; $this->addlink = 'admin/create/domain' . '&destination=' . urlencode(MCMS_REQUEST_URI); $this->sort = 'name'; $this->limit = null; break; } } // Подбираем заголовок. if (!isset($this->title) and count($this->types) == 1) { switch ($type = $this->types[0]) { case 'type': $this->title = t('Список типов документов'); break; case 'files': $this->title = t('Список файлов'); break; case 'user': $this->title = t('Список пользователей'); break; case 'group': $this->title = t('Список групп'); break; case 'field': $this->title = t('Список полей'); $this->limit = null; break; default: $tmp = Schema::load($this->ctx->db, $type); if (!empty($tmp['isdictionary'])) { $this->title = t('Справочник «%name»', array('%name' => mb_strtolower($tmp['title']))); } break; } } if (!isset($this->title)) { $this->title = t('Список документов'); } if (!isset($this->linkfield)) { $this->linkfield = 'name'; } if (null === $this->actions) { $this->actions = array('delete', 'publish', 'unpublish'); } }
static function loadTmpDb($db) { $fname = self::get('savedir') . '/schema.php'; if (!file_exists($fname)) { echo "File: {$fname} does not exist!\n"; exit; } require_once $fname; $sc = new Schema(); $sc->load($db); $migrations = self::getAllMigrations(); foreach ($migrations as $revision) { self::applyMigration($revision, $db); } }