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]; // @todo Check permissions here? if ('POST' == $_SERVER['REQUEST_METHOD']) { if (isset($_POST['action']) && 'Cancel' != $_POST['action']) { $content = array(); foreach ($group['members'] as $member) { $key = $member['name']; if ('image' == $member['type']) { $value = basename(FileManager::GetPostedOrUploadedFile($key, TYPEF_DIR . '/files/public/content')); } elseif (isset($_POST[$key])) { $value = $_POST[$key]; } else { $value = null; } $content[$key] = $value;
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); $content_plug->save();
public static function GroupsFrom($template, $groupMap = null, $skin = 'default') { $groups = array(); if (file_exists($template) && is_file($template)) { $source = file_get_contents($template); foreach (get_html_translation_table() as $character => $entity) { if ($entity != '&' && $entity != '"' && $entity != '>' && $entity != '<') { $source = str_replace($entity, ' ', $source); } } $xml = Pagemill_SimpleXmlElement::LoadString($source); if ($groupMap) { if (is_array($groupMap)) { $xpath = '//*[name() != \'pm:group\']'; foreach ($groupMap as $g) { $xpath .= '/pm:group[@name=\'' . $g . '\']'; } $elements = $xml->xpath($xpath); } else { $elements = $xml->xpath('//*[name() != \'pm:group\']/pm:group[name=\'' . $groupMap . '\']'); } } else { $elements = $xml->xpath('//*[name() != \'pm:group\']/pm:group | //*[name() != \'pm:group\']/pm:include'); } foreach ($elements as $e) { if ($e->getName() == 'group') { $groups[] = self::RecurseGroups($e, $xml, $skin); } else { $included = Insertable::GroupsFrom(TYPEF_DIR . '/source/templates/' . $e['template'], $groupMap, $skin); if (is_array($included)) { $groups = array_merge($groups, $included); } } } } else { trigger_error("File '{$template}' does not exist"); } return $groups; }