//if (!$plug->exists() || ('Content' != $plug->get('plug'))) if (!$plug->exists()) { Typeframe::Redirect('Invalid plugin.', $typef_app_dir, -1); return; } // get template from settings; expand to its full value $settings = $plug['settings']; $template = isset($settings['template']) ? $settings['template'] : 'generic.plug.html'; $full_template = TYPEF_SOURCE_DIR . '/templates/content/' . $template; // cannot edit content if template does not exist if (!file_exists($full_template)) { Typeframe::Redirect("Unable to find plugin template ({$template}).", $typef_app_dir, -1); return; } // load inserts and groups for template $inserts = Insertable::ElementsFrom($full_template); $groups = Insertable::GroupsFrom($full_template); // get revision id, if any $revisionid = @$_REQUEST['revisionid']; // process form if ('POST' == $_SERVER['REQUEST_METHOD']) { // build content array from post $content = Content::ProcessPOST($inserts, $groups); // add/edit content //$content_plug = new Content_Plug($plugid, $revisionid); $content_plug = Model_Content_Plug::Get($plugid); if (!$content_plug->exists()) { $content_plug = Model_Content_Plug::Create(); $content_plug['plugid'] = $plugid; } $content_plug->set('content', $content);
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; }