/** * Put a gadget on the template * * @access public * @param string $gadget Gadget to put * @param string $action Action to execute * @param mixed $params Action's params */ function PutGadget($gadget, $action, $params = null, $filename = '') { $output = ''; $enabled = Jaws_Gadget::IsGadgetEnabled($gadget); if (Jaws_Error::isError($enabled) || $enabled != 'true') { $GLOBALS['log']->Log(JAWS_LOG_NOTICE, "Gadget {$gadget} is not enabled"); return $output; } if (!Jaws_Gadget::IsGadgetUpdated($gadget)) { $GLOBALS['log']->Log(JAWS_LOG_NOTICE, 'Trying to populate ' . $gadget . ' in layout, but looks that it is not installed/upgraded'); return $output; } jaws()->http_response_code(200); $goGadget = Jaws_Gadget::getInstance($gadget)->action->load($filename); if (!Jaws_Error::isError($goGadget)) { if (method_exists($goGadget, $action)) { $GLOBALS['app']->requestedGadget = $gadget; $GLOBALS['app']->requestedAction = $action; $GLOBALS['app']->requestedActionMode = ACTION_MODE_LAYOUT; if (is_null($params)) { $output = $goGadget->{$action}(); } else { $output = call_user_func_array(array($goGadget, $action), $params); } } else { $GLOBALS['log']->Log(JAWS_LOG_ERROR, "Action {$action} in {$gadget}'s Actions dosn't exist."); } } if (Jaws_Error::isError($output)) { $GLOBALS['log']->Log(JAWS_LOG_ERROR, 'In ' . $gadget . '::' . $action . ',' . $output->GetMessage()); $output = ''; } elseif (jaws()->http_response_code() !== 200) { $output = ''; } return $output; }
$IsIndex = false; $objAction = null; $IsReqActionStandAlone = false; // Only registered user can access not global website $AccessToWebsiteDenied = !$GLOBALS['app']->Session->Logged() && $GLOBALS['app']->Registry->fetch('global_website', 'Settings') == 'false'; // Get forwarded error from webserver $ReqError = jaws()->request->fetch('http_error', 'get'); if (empty($ReqError) && $GLOBALS['app']->Map->Parse()) { $ReqGadget = Jaws_Gadget::filter(jaws()->request->fetch('gadget')); $ReqAction = Jaws_Gadget_Action::filter(jaws()->request->fetch('action')); if (empty($ReqGadget)) { $IsIndex = true; $ReqGadget = $GLOBALS['app']->Registry->fetchByUser($GLOBALS['app']->Session->GetAttribute('layout'), 'main_gadget', 'Settings'); } if (!empty($ReqGadget)) { if (Jaws_Gadget::IsGadgetEnabled($ReqGadget)) { $objAction = Jaws_Gadget::getInstance($ReqGadget)->action->load(); if (Jaws_Error::IsError($objAction)) { Jaws_Error::Fatal("Error loading gadget: {$ReqGadget}"); } if (!$GLOBALS['app']->Session->GetPermission($ReqGadget, 'default')) { $ReqError = '403'; } // check referrer host for internal action if ($objAction->getAttribute($ReqAction, 'internal') && !$GLOBALS['app']->Session->extraCheck()) { $ReqError = '403'; } // set requested gadget $GLOBALS['app']->mainGadget = $ReqGadget; } else { $ReqError = '404';
/** * Executes the autoload gadgets * * @access public * @return void */ function RunAutoload() { $data = $GLOBALS['app']->Registry->fetch('gadgets_autoload_items'); $gadgets = array_filter(explode(',', $data)); foreach ($gadgets as $gadget) { if (Jaws_Gadget::IsGadgetEnabled($gadget)) { $objGadget = Jaws_Gadget::getInstance($gadget); if (Jaws_Error::IsError($objGadget)) { continue; } $objHook = $objGadget->hook->load('Autoload'); if (Jaws_Error::IsError($objHook)) { continue; } $result = $objHook->Execute(); if (Jaws_Error::IsError($result)) { //do nothing; } } } }
/** * Returns the HTML content to manage the layout in the browser * * @access public * @return string XHTML template content */ function Layout() { $rqst = jaws()->request->fetch(array('user', 'theme', 'index_layout')); // dashboard_user if (empty($rqst['user']) && $this->gadget->GetPermission('ManageLayout')) { $user = 0; } else { $GLOBALS['app']->Session->CheckPermission('Users', 'ManageDashboard'); $user = (int) $GLOBALS['app']->Session->GetAttribute('user'); } // theme @(list($rqst['theme'], $rqst['locality']) = explode(',', $rqst['theme'])); $default_theme = unserialize($this->gadget->registry->fetchByUser('theme', 'Settings', $user)); if (empty($rqst['theme']) || $rqst['locality'] == $default_theme['locality'] && $rqst['theme'] == $default_theme['name']) { $theme = $default_theme['name']; $theme_locality = $default_theme['locality']; } else { $this->gadget->CheckPermission('ManageThemes'); $this->UpdateTheme($rqst['theme'], $rqst['locality'], $user); $default_theme = unserialize($this->gadget->registry->fetchByUser('theme', 'Settings', $user)); $theme = $default_theme['name']; $theme_locality = $default_theme['locality']; } $GLOBALS['app']->SetTheme($theme, $theme_locality); // index_layout $index_layout = (bool) $rqst['index_layout']; $lModel = $this->gadget->model->loadAdmin('Layout'); $eModel = $this->gadget->model->loadAdmin('Elements'); $t_item = $this->gadget->template->load('LayoutManager.html'); $t_item->SetBlock('working_notification'); $t_item->SetVariable('loading-message', _t('GLOBAL_LOADING')); $working_box = $t_item->ParseBlock('working_notification'); $t_item->Blocks['working_notification']->Parsed = ''; $t_item->SetBlock('msgbox-wrapper'); $responses = $GLOBALS['app']->Session->PopLastResponse(); if ($responses) { foreach ($responses as $msg_id => $response) { $t_item->SetBlock('msgbox-wrapper/msgbox'); $t_item->SetVariable('text', $response['text']); $t_item->SetVariable('type', $response['type']); $t_item->SetVariable('msg-id', $msg_id); $t_item->ParseBlock('msgbox-wrapper/msgbox'); } } $msg_box = $t_item->ParseBlock('msgbox-wrapper'); $t_item->Blocks['msgbox-wrapper']->Parsed = ''; $t_item->SetBlock('drag_drop'); $t_item->SetVariable('empty_section', _t('LAYOUT_SECTION_EMPTY')); $t_item->SetVariable('display_always', _t('LAYOUT_ALWAYS')); $t_item->SetVariable('display_never', _t('LAYOUT_NEVER')); $t_item->SetVariable('displayWhenTitle', _t('LAYOUT_CHANGE_DW')); $t_item->SetVariable('actionsTitle', _t('LAYOUT_ACTIONS')); $t_item->SetVariable('confirmDelete', _t('LAYOUT_CONFIRM_DELETE')); $dragdrop = $t_item->ParseBlock('drag_drop'); $t_item->Blocks['drag_drop']->Parsed = ''; // Init layout $GLOBALS['app']->InstanceLayout(); $fakeLayout = new Jaws_Layout(); $fakeLayout->Load('', $index_layout ? 'index.html' : 'layout.html'); $fakeLayout->AddScriptLink('libraries/mootools/core.js'); $fakeLayout->AddScriptLink('libraries/mootools/more.js'); $fakeLayout->AddScriptLink('include/Jaws/Resources/Ajax.js'); $fakeLayout->AddScriptLink('gadgets/Layout/Resources/script.js'); $layoutContent = $fakeLayout->_Template->Blocks['layout']->Content; $layoutContent = preg_replace('$<body([^>]*)>$i', '<body\\1>' . $working_box . $msg_box . $this->LayoutBar($theme, $theme_locality, $user, $index_layout), $layoutContent); $layoutContent = preg_replace('$</body([^>]*)>$i', $dragdrop . '</body\\1>', $layoutContent); $fakeLayout->_Template->Blocks['layout']->Content = $layoutContent; $fakeLayout->_Template->SetVariable('site-title', $this->gadget->registry->fetch('site_name', 'Settings')); $fakeLayout->AddHeadLink(PIWI_URL . 'piwidata/css/default.css', 'stylesheet', 'text/css', 'default'); $fakeLayout->AddHeadLink('gadgets/Layout/Resources/style.css', 'stylesheet', 'text/css'); foreach ($fakeLayout->_Template->Blocks['layout']->InnerBlock as $name => $data) { if ($name == 'head') { continue; } $fakeLayout->_Template->SetBlock('layout/' . $name); $js_section_array = '<script type="text/javascript">items[\'' . $name . '\'] = new Array(); sections.push(\'' . $name . '\');</script>'; $gadgets = $lModel->GetGadgetsInSection($index_layout, $name, $user); if (!is_array($gadgets)) { continue; } foreach ($gadgets as $gadget) { if ($gadget['gadget'] == '[REQUESTEDGADGET]') { $t_item->SetBlock('item'); $t_item->SetVariable('section_id', $name); $t_item->SetVariable('item_id', $gadget['id']); $t_item->SetVariable('user', $user); $t_item->SetVariable('pos', $gadget['layout_position']); $t_item->SetVariable('gadget', _t('LAYOUT_REQUESTED_GADGET')); $t_item->SetVariable('action', ' '); $t_item->SetVariable('icon', 'gadgets/Layout/Resources/images/requested-gadget.png'); $t_item->SetVariable('description', _t('LAYOUT_REQUESTED_GADGET_DESC')); $t_item->SetVariable('lbl_display_when', _t('LAYOUT_DISPLAY_IN')); $t_item->SetVariable('display_when', _t('GLOBAL_ALWAYS')); $t_item->SetVariable('void_link', 'return;'); $t_item->SetVariable('section_name', $name); $t_item->SetVariable('delete', 'void(0);'); $t_item->SetVariable('delete-img', 'gadgets/Layout/Resources/images/no-delete.gif'); $t_item->SetVariable('lbl_delete', _t('GLOBAL_DELETE')); $t_item->SetVariable('item_status', 'none'); $t_item->ParseBlock('item'); } else { $controls = ''; $t_item->SetBlock('item'); $t_item->SetVariable('section_id', $name); $t_item->SetVariable('pos', $gadget['layout_position']); $t_item->SetVariable('item_id', $gadget['id']); $t_item->SetVariable('base_script_url', $GLOBALS['app']->getSiteURL('/' . BASE_SCRIPT)); $t_item->SetVariable('icon', Jaws::CheckImage('gadgets/' . $gadget['gadget'] . '/Resources/images/logo.png')); $t_item->SetVariable('delete', "deleteElement('{$gadget['id']}');"); $t_item->SetVariable('delete-img', 'gadgets/Layout/Resources/images/delete-item.gif'); $t_item->SetVariable('lbl_delete', _t('GLOBAL_DELETE')); $actions = $eModel->GetGadgetLayoutActions($gadget['gadget'], true); if (isset($actions[$gadget['gadget_action']]) && Jaws_Gadget::IsGadgetEnabled($gadget['gadget'])) { $t_item->SetVariable('gadget', _t(strtoupper($gadget['gadget']) . '_TITLE')); if (isset($actions[$gadget['gadget_action']]['name'])) { $t_item->SetVariable('action', $actions[$gadget['gadget_action']]['name']); } else { $t_item->SetVariable('action', $gadget['gadget_action']); } $t_item->SetVariable('description', $actions[$gadget['gadget_action']]['desc']); $t_item->SetVariable('item_status', 'none'); } else { $t_item->SetVariable('gadget', $gadget['gadget']); $t_item->SetVariable('action', $gadget['gadget_action']); $t_item->SetVariable('description', $gadget['gadget_action']); $t_item->SetVariable('item_status', 'line-through'); } unset($actions); $t_item->SetVariable('controls', $controls); $t_item->SetVariable('void_link', ''); $t_item->SetVariable('lbl_display_when', _t('LAYOUT_DISPLAY_IN')); if ($gadget['display_when'] == '*') { $t_item->SetVariable('display_when', _t('GLOBAL_ALWAYS')); } elseif (empty($gadget['display_when'])) { $t_item->SetVariable('display_when', _t('LAYOUT_NEVER')); } else { $t_item->SetVariable('display_when', str_replace(',', ', ', $gadget['display_when'])); } $t_item->ParseBlock('item'); } } $fakeLayout->_Template->SetVariable('ELEMENT', '<div id="layout_' . $name . '" class="layout-section" title="' . $name . '">' . $js_section_array . $t_item->Get() . '</div>'); $fakeLayout->_Template->ParseBlock('layout/' . $name); $t_item->Blocks['item']->Parsed = ''; } return $fakeLayout->Get(true); }
/** * Disable a gadget * * @access public * @return mixed True if success or Jaws_Error on error */ public function DisableGadget() { if (!Jaws_Gadget::IsGadgetInstalled($this->gadget->name)) { return Jaws_Error::raiseError("gadget [{$this->gadget->name}] not installed", __FUNCTION__); } if ($this->gadget->_IsCore) { return Jaws_Error::raiseError("you can't disable core gadgets", __FUNCTION__); } // check depend on gadgets status $gModel = $this->gadget->model->load(); $dependent_gadgets = $gModel->requirementfor(); if (Jaws_Error::IsError($dependent_gadgets)) { return $dependent_gadgets; } foreach ($dependent_gadgets as $idx => $gadget) { if (!Jaws_Gadget::IsGadgetEnabled($gadget)) { $dependent_gadgets[$idx] = null; } } $dependent_gadgets = implode(', ', array_filter($dependent_gadgets)); if (!empty($dependent_gadgets)) { return Jaws_Error::raiseError("you can't disable this gadget, because {$dependent_gadgets} gadget(s) is dependent on it", __FUNCTION__); } // adding gadget to disabled gadgets list $disabled_gadgets = $GLOBALS['app']->Registry->fetch('gadgets_disabled_items'); $disabled_gadgets .= $this->gadget->name . ','; $GLOBALS['app']->Registry->update('gadgets_disabled_items', $disabled_gadgets); // end disable gadget event $res = $this->gadget->event->shout('DisableGadget', $this->gadget->name); if (Jaws_Error::IsError($res)) { return $res; } return true; }