<?php /** * Insert a plugin into a location (socket). */ // save typing below $typef_app_dir = Typeframe::CurrentPage()->applicationUri(); // requires POST if ('POST' != $_SERVER['REQUEST_METHOD']) { Bam_Json::FailureOrRedirect('Nothing to do.', $typef_app_dir); } // Do not display the plugin by default $rules = 'url:*;!url:*'; // append plugin into location; get and check location id $locid = Model_PlugLoc::Append($_POST['plugid'], $_POST['skin'], $_POST['socket'], $rules); if (is_null($locid)) { Bam_Json::FailureOrRedirect('Error adding plugin to skin.', $typef_app_dir); } // build HTML if request is AJAX if (requestIsAjax()) { $pm->setVariable('skin', $_POST['skin']); $pm->setVariable('p', new Plug_Loc($locid)); $html = $pm->writeText('<pm:include template="admin/plugins/socket-plugin.inc.html" />'); } else { $html = null; } // done; return result Bam_Json::SuccessOrRedirect('Plugin added to skin.', "{$typef_app_dir}?skin={$_POST['skin']}", array('html' => $html));
<?php /** * Manage the pages where a plugin appears. */ // validate plugin location id $plug_loc = Model_PlugLoc::Get($_REQUEST['locid']); if (!$plug_loc->exists()) { Bam_Json::FailureOrRedirect('Invalid socket plugin id.', $typef_app_dir); } // process form if ('POST' == $_SERVER['REQUEST_METHOD']) { // TODO: Handle empty rules array (assuming "all" for now) $rules = ''; if (empty($_POST['allpages']) && isset($_POST['rules'])) { $allExcludes = true; foreach ($_POST['rules'] as $rule) { if (substr($rule, 0, 1) != '!') { $allExcludes = false; } } $rules = implode(';', $_POST['rules']); if ($allExcludes) { $rules = "url:*;{$rules}"; } } else { $rules = 'url:*'; } $plug_loc = Model_PlugLoc::Get($_POST['locid']); $plug_loc->set('rules', $rules); $plug_loc->save();