* Typeframe Content application * * admin-side groups form controller */ // save typing below $typef_app_dir = Typeframe::CurrentPage()->applicationUri(); // break up incoming base $base = $_REQUEST['base']; if (preg_match_all('/\\[?([a-z0-9_]*)\\]?\\[[\\d]*\\]/i', $base, $matches)) { // use the matches to shape an xpath query identifying the group $full_template = TYPEF_SOURCE_DIR . '/templates/' . $_REQUEST['template']; //$skin = Typeframe_Skin::At(TYPEF_WEB_DIR . $page['uri']); if (!empty($_REQUEST['pageid'])) { $page = Model_Page::Get($_REQUEST['pageid']); if ($page->exists()) { $skin = Typeframe_Skin::At(TYPEF_WEB_DIR . $page['uri']); if (CONTENT_USE_PAGE_STYLE) { //$stylesheets = Pagemill_Tag_Stylesheets::GetStylesheetsAt(TYPEF_WEB_DIR . $page['uri']); $stylesheets = array(); if (!empty($stylesheets)) { $pm->setVariable('editor_stylesheets', "['" . implode("','", $stylesheets) . "']"); } } } else { $skin = 'default'; } } else { $skin = 'default'; } $groups = Insertable::GroupsFrom($full_template, $matches[1], $skin); $group = $groups[0];
* client-side index controller */ // save typing below $pathinfo = Typeframe::CurrentPage()->pathInfo(); $settings = Typeframe::CurrentPage()->settings(); $typef_app_dir = Typeframe::CurrentPage()->uri(); // set template if (empty($settings['template'])) { $settings['template'] = 'generic.html'; } Typeframe::SetPageTemplate("/content/{$settings['template']}"); // if given path information if ($pathinfo) { $pm->setVariable('pathinfo', $pathinfo); // find out which skin to use; derive appropriate template from that $skin = Typeframe_Skin::At($typef_app_dir); $skin_template = TYPEF_DIR . "/skins/{$skin}/templates/content/" . $settings['template']; $base_template = TYPEF_DIR . "/source/templates/content/" . $settings['template']; $source = file_get_contents(file_exists($skin_template) ? $skin_template : $base_template); // look for groups and subpages if (is_int(strpos($source, 'pm:group')) && is_int(strpos($source, 'subpage'))) { // convert all entities in source into spaces, except for &, ", >, and < //$invalidEntities = array_diff(array_values(Pagemill::GetExtendedEntityTable()), // array('&', '"', '>', '<')); //$source = str_replace($invalidEntities, ' ', $source); // get page id $pageid = Typeframe::CurrentPage()->pageid(); // load groups from source as XML; loop over them $xml = Pagemill_SimpleXmlElement::LoadString($source); $groups = $xml->xpath('//pm:group'); foreach ($groups as $group) {
if (!file_exists($full_template)) { Typeframe::Redirect("Unable to find page template ({$template}).", $typef_app_dir, -1); return; } $skin = Typeframe_Skin::At(TYPEF_WEB_DIR . $page['uri']); $stylesheets = Typeframe_Skin::StylesheetsFor($template, TYPEF_WEB_DIR . $page['uri']); $pm->setVariable('stylesheets', $stylesheets); // load inserts and groups for template $inserts = Insertable::ElementsFrom($full_template, TYPEF_WEB_DIR . $page['uri']); $groups = Insertable::GroupsFrom($full_template, null, $skin); // get revision id, if any $revisionid = @$_REQUEST['revisionid']; // process form if ('POST' == $_SERVER['REQUEST_METHOD']) { if (!empty($_POST['cmd']) && $_POST['cmd'] == 'Preview') { Typeframe_Skin::Set(Typeframe_Skin::At(TYPEF_WEB_DIR . $page['uri'])); Typeframe::CurrentPage()->setPageTemplate('/content/' . $page['settings']['template']); return; } // build content array from post $content = Content::ProcessPost($inserts, $groups); // add/edit content //$content_page = new Content_Page($pageid, $revisionid); $content_page = Model_Content_Page::Get($pageid); if (!$content_page->exists()) { $content_page = Model_Content_Page::Create(); $content_page['pageid'] = $pageid; } $content_page['content'] = $content; //$content_page->set('content', json_encode($content)); $content_page->save();
public static function ElementsFrom($template, $uri = null) { /*if (!is_null($uri)) { $skin = Typeframe_Skin::At($uri); $stylesheets = Typeframe_Tag_Stylesheets::GetStylesheetsAt($uri); } else { $skin = 'default'; $stylesheets = Typeframe_Tag_Stylesheets::GetStylesheetsAt(TYPEF_WEB_DIR . '/'); }*/ $skin = Typeframe_Skin::At($uri); $array = null; if (file_exists($template) && is_file($template)) { $source = file_get_contents($template); /*foreach (Pagemill::GetExtendedEntityTable() as $character => $entity) { if ( ($entity != '&') && ($entity != '"') && ($entity != '>') && ($entity != '<') ) { $source = str_replace($entity, ' ', $source); } }*/ $xml = Pagemill_SimpleXmlElement::LoadString($source); $array = array(); $elements = $xml->xpath('//pm:insert|//pm:include'); foreach ($elements as $e) { if ($e->getName() == 'insert') { $name = Insertable::_NameToSymbol((string) $e['name']); if ($name !== (string) $e['name']) { trigger_error("Insertable element name '{$e['name']}' has invalid characters (should be letters, numbers, and underscores only) in template '{$template}'"); return null; } $label = (string) $e['label']; if (!$label) { $label = $name; } $type = (string) $e['type']; $admin = (string) $e['admin']; $selector = ''; if ($type == 'html') { if (count($e->children())) { foreach ($e->children() as $c) { if (preg_match('/@{[\\w\\W\\s\\S]*?' . $name . '[\\w\\W\\s\\S]*?}@/', $c->asXml())) { $selector = Insertable::_InsertSelector($c, $skin); break; } } } else { $stack = $e->xpath('parent::*'); if (count($stack)) { $element = array_pop($stack); $selector = Insertable::_InsertSelector($element, $skin); } } } else { if ($type == 'select') { $options = array(); foreach ($e->option as $option) { $options[] = array('label' => "{$option}", 'value' => !is_null($option['value']) ? "{$option['value']}" : "{$option}"); } } else { if ($type == 'model') { $options = array(); if (class_exists($e['model'])) { $model = (string) $e['model']; $values = new $model(); foreach ($values->getAll() as $value) { $options[] = array('label' => $value->get((string) $e['modellabel']), 'value' => $model . ':' . $value->get('id')); } } $type = 'select'; } } } $i = array('name' => $name, 'label' => $label, 'type' => $type, 'admin' => $admin, 'selector' => $selector); if ($type == 'select') { $i['options'] = $options; } $array[] = $i; } else { $included = Insertable::ElementsFrom(TYPEF_DIR . '/source/templates/' . $e['template']); if (is_array($included)) { $array = array_merge($array, $included); } } } } else { trigger_error("File '{$template}' does not exist"); } return $array; }