public function admin(\Pagemill_Data $data, \Pagemill_Stream $stream) { $this->adminTemplate = '/admin/content/settings.plug.html'; $data = $data->fork(); $data->setArray($this->attributes()); $templates = array(); $dh = opendir(self::GetTemplateDirectory()); $dh = opendir(TYPEF_SOURCE_DIR . '/templates/content'); while (($file = readdir($dh)) !== false) { if ($file != "." && $file != "..") { if (is_file(self::GetTemplateDirectory() . $file)) { if (preg_match('/.plug./', $file)) { $source = file_get_contents(TYPEF_SOURCE_DIR . '/templates/content/' . $file); preg_match('/pm:tmplname="([\\w\\W\\s\\S]*?)"/', $source, $matches); if ($matches) { $label = $matches[1]; } else { $label = $file; } $templates[] = array('template' => $file, 'label' => $label); } } } } closedir($dh); $data['templates'] = $templates; $plugin = Model_Plug::Get($_REQUEST['plugid']); if ($plugin->exists()) { $data['plugin'] = $plugin; $data['settings'] = $plugin['settings']; parent::admin($data, $stream); } }
public function output(Pagemill_Data $data, Pagemill_Stream $stream) { $db = Typeframe::Database(); if ($this->hasAttribute('rules') && !Typeframe_Tag_Socket::ProcessRules($this->getAttribute('rules'))) { return ''; } /* * Rules for loading the plugin: * 1. The plugid overrides other load settings. * 2. Load a plugin from the table if the name attribute matches an * an admin-specified name. * 3. Create a generic plugin from a signature. * 4. If the plugin was loaded from the database, attribute settings * override database settings. */ $p = null; if ($this->getAttribute('plugid')) { $plugin = Model_Plug::Get($data->parseVariables($this->getAttribute('plugid'))); if ($plugin->exists()) { $p = Typeframe::Registry()->getPluginSignature($plugin['plug']); } } else { if ($this->getAttribute('name')) { $plugins = new Model_Plug(); $plugins->where('name = ?', $data->parseVariables($this->getAttribute('name'))); $plugin = $plugins->getFirst(); if ($plugin->exists()) { $p = Typeframe::Registry()->getPluginSignature($plugin['plug']); } else { $p = Typeframe::Registry()->getPluginSignature($this->getAttribute('name')); } } } if ($p) { $cls = $p->className(); if (class_exists($cls)) { $settings = $this->settings; foreach ($this->attributes() as $k => $v) { $settings[$k] = $data->parseVariables($v); } //$obj = new $cls($settings); $obj = new $cls('plugin', $settings, null); foreach ($this->children() as $child) { $obj->appendChild($child); } $obj->process($data, $stream); foreach ($obj->children() as $child) { $this->appendChild($child); } $obj->detach(); } else { throw new Exception("Class '{$cls}' does not exist"); } } else { throw new Exception("Plugin does not have a signature"); } }
/** * Update the plugin settings. * @param array $input An associative array of settings. */ public function update(array $input) { $plugin = Model_Plug::Get($input['plugid']); if ($plugin->exists()) { $plugin['name'] = isset($input['name']) ? $input['name'] : (isset($input['settings']) && isset($input['settings']['name']) ? $input['settings']['name'] : ''); $plugin['settings'] = $input['settings']; $plugin->save(); } else { throw new Exception("Plugin not found"); } }
public function output(\Pagemill_Data $data, \Pagemill_Stream $stream) { $plugid = $data->parseVariables($this->getAttribute('plugid')); $plug = Model_Plug::Get($plugid); if ($plug->exists()) { $name = $plug['plug']; $sig = Typeframe::Registry()->getPluginSignature($name); $cls = $sig->className(); if (is_subclass_of($cls, 'Plugin')) { $plug['settings']['plugid'] = $plugid; $plug = new $cls('', $plug['settings'], $this); $plug->admin($data, $stream); } else { throw new Exception("Invalid plugin type specified"); } } else { throw new Exception("Invalid plugin specified"); } }
<?php /** * Typeframe Content application * * admin-side plug controller */ Plugin_Breadcrumbs::Add('Edit Plugin'); // save typing below $typef_app_dir = Typeframe::CurrentPage()->applicationUri(); // validate plug id (must be 'Content' plug) $plugid = @$_REQUEST['plugid']; $plug = Model_Plug::Get($plugid); //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
public function update(array $input = null) { //gimme life! //$item = isset($_POST['itemid']) ? new Navigation_Item($_POST['itemid']) : new Navigation_Item(); $item = isset($_POST['itemid']) && !is_array($_POST['itemid']) ? Model_Nav::Get($_POST['itemid']) : Model_Nav::Create(); if ($_REQUEST['cmd'] != 'delete' && $_REQUEST['cmd'] != 'name' && $_REQUEST['cmd'] != 'sort') { $item->set('pageid', 0); switch ($_POST['type']) { case 'none': // Heh, these have no extra attributes, so null just about everything. $item->set('label', $_POST['label']); $item->set('url', ''); $item->set('onclick', ''); $item->set('visibility', 'always'); $item->set('method', ''); $item->set('target', ''); break; case 'int': $item->set('label', $_POST['label']); $item->set('pageid', $_POST['pageid']); $item->set('url', ''); $item->set('onclick', ''); $item->set('visibility', 'permitted'); $item->set('method', $_POST['method']); $item->set('target', $_POST['target']); break; case 'arbint': $item->set('label', $_POST['label']); $item->set('url', $_POST['url']); $item->set('onclick', ''); $item->set('visibility', $_POST['visibility']); $item->set('method', $_POST['method']); $item->set('target', $_POST['target']); break; case 'ext': $item->set('label', $_POST['label']); $item->set('url', $_POST['url']); $item->set('onclick', ''); $item->set('visibility', $_POST['visibility']); $item->set('method', $_POST['method']); $item->set('target', $_POST['target']); break; case 'mailto': $item->set('label', $_POST['label']); $item->set('url', 'mailto:' . $_POST['url']); $item->set('onclick', ''); $item->set('visibility', $_POST['visibility']); $item->set('method', ''); $item->set('target', ''); break; } } switch ($_REQUEST['cmd']) { case 'add': $item->set('parent', $_POST['parent']); $item->set('plugid', $_POST['plugid']); $result = Typeframe::Database()->execute('SELECT MAX(sortnum) AS maxsort FROM #__nav WHERE plugid = ' . (int) $_POST['plugid']); $max = $result[0]; $item->set('sortnum', $max['maxsort'] + 1); $item->save(); $msg = " Added"; break; case 'edit': $item->save(); $msg = " Saved"; break; case 'delete': $item->delete(); $msg = " Deleted"; break; case 'name': $plug = Model_Plug::Get($_POST['plugid']); $plug['name'] = $_POST['name']; $plug->save(); Typeframe::Redirect('Name updated.', Typeframe::CurrentPage()->applicationUri() . '/edit?plugid=' . $_POST['plugid'] . '&parentid=' . (isset($_POST['parentid']) ? $_POST['parentid'] : '0')); return; case 'sort': $sortnum = 1; for ($i = 0; $i < count($_POST['itemid']); $i++) { $item = Model_Nav::Get($_POST['itemid'][$i]); $item['parent'] = $_POST['parent'][$i]; $item['sortnum'] = $sortnum; $item->save(); $sortnum++; } Typeframe::Redirect('Items sorted.', Typeframe::CurrentPage()->applicationUri() . '/edit?plugid=' . $_POST['plugid'] . '&parentid=' . (isset($_POST['parentid']) ? $_POST['parentid'] : '0')); return; } Typeframe::Redirect('Item' . $msg, Typeframe::CurrentPage()->applicationUri() . '/edit?plugid=' . $_POST['plugid'] . '&parentid=' . (isset($_POST['parentid']) ? $_POST['parentid'] : '0')); }