readonly) { array_push($actions, array(__("edit"), "?action=edit&target={$barrel['alias']}")); } array_push($actions, array(__("admin"), $page->urlBarrel($barrel['alias'],$barrel['vhost'],"admin/"))); if (!$this->readonly) { $flags = new flagset($barrel['flags']); if ($flags->hasFlag('plug')) { array_push($actions, array(__("plugins"), "plugins?plug_barrel={$barrel['alias']}")); } array_push($actions, array(__("delete"), "javascript:del('{$barrel['alias']}');")); } $page->append('sites',array( 'alias' => $barrel['alias'], 'title' => array( $barrel['title'], $page->urlBarrel($barrel['alias'],$barrel['vhost']) ), 'description' => $barrel['description'], 'actions' => $actions ) ); } /** Run the Barrel editor. * * @param $page * @param $outputvar */ function run(&$page, $outputvar = '') { global $globals; $page->assign('post',$page->script_self()); $action = isset($_REQUEST["action"]) ? $_REQUEST["action"] : "list"; switch($action) { case "create": if ($this->readonly) die("Sorry, this barrel editor is read-only."); if (isset($_REQUEST["target"])) { Diogenes_Barrel::create($_REQUEST["target"], $page); } $action="list"; break; case "update": if ($this->readonly) die("Sorry, this barrel editor is read-only."); if (isset($_REQUEST["target"])) { // build flags $flags = isset($_REQUEST['flags']) ? implode(",",array_values($_REQUEST['flags'])) : ""; $globals->db->query("update diogenes_site set vhost='{$_REQUEST['vhost']}',flags='$flags' where alias='{$_REQUEST['target']}'"); $opts = new Diogenes_Barrel_Options($_REQUEST['target']); $opts->updateOption('description', $_REQUEST['description']); $opts->updateOption('title', $_REQUEST['title']); $opts->updateOption('keywords', $_REQUEST['keywords']); } $action="list"; break; case "edit": if ($this->readonly) die("Sorry, this barrel editor is read-only."); if (isset($_REQUEST["target"])) { $res = $globals->db->query("select alias,vhost,flags from diogenes_site where alias='{$_REQUEST['target']}'"); if (!list($target,$vhost,$flags) = mysql_fetch_row($res)) { $page->info("Could not find specified site!"); $action = "list"; break; } mysql_free_result($res); $page->assign('target',$target); $page->assign('v_vhost',$vhost); $flags = new flagset($flags); $flag_opts = array('tpl' => __("custom templates"), 'plug' => __("plugins")); $page->assign('v_flag_opts', $flag_opts); foreach($flag_opts as $key=>$val) { if ($flags->hasFlag($key)) $page->append('v_flags', $key); } $opts = new Diogenes_Barrel_Options($target); $page->assign('v_desc',$opts->description); $page->assign('v_title',$opts->title); $page->assign('v_keywords',$opts->keywords); } break; case "delete": if ($this->readonly) die("Sorry, this barrel editor is read-only."); if (isset($_REQUEST["target"])) { Diogenes_Barrel::destroy($_REQUEST["target"], $page); } $action="list"; break; default: $action="list"; } if ($action == "list") { $res = $globals->db->query("select s.alias,s.vhost,s.flags,o.name,o.value from diogenes_site as s left join diogenes_option as o on s.alias=o.barrel order by s.alias"); $barrel = array('alias' => ''); while (list($s_alias,$s_vhost,$s_flags,$o_name,$o_value) = mysql_fetch_row($res)) { if ($s_alias != $barrel['alias']) { if ($barrel['alias']) $this->addBarrel($page, $barrel); $barrel = array('alias' => $s_alias,'vhost' => $s_vhost, 'flags' => $s_flags, 'title' => '','description' => ''); } $barrel[$o_name] = $o_value; } mysql_free_result($res); if ($barrel['alias']) $this->addBarrel($page, $barrel); } // $action == "list" // values $page->assign('action',$action); $page->assign('readonly', $this->readonly); // translations $page->assign('msg_alias',__("alias")); $page->assign('msg_title',__("site")); $page->assign('msg_desc',__("description")); $page->assign('msg_keywords',__("keywords")); $page->assign('msg_create',__("Create a new site")); $page->assign('msg_create_note',__("The site alias may only contain letters, numbers and underscores.")); $page->assign('msg_submit',__("Submit")); $page->assign('msg_no_barrels', __("no barrels available")); $page->assign('msg_vhost',__("vhost (see note)")); $page->assign('msg_vhost_note', __("vhost note: If you intend to serve this site from a virtualhost, you should enter the name of the virtualhost in this field.")); $page->assign('msg_flags',__("flags")); // if requested, assign the content to be displayed if (!empty($outputvar)) { $page->assign($outputvar, $page->fetch('barrel-editor.tpl')); } } } ?>