/** * Calls default action * * @access public * @return string XHTML template content */ function DefaultAction() { $gadgetsections = array(); $cmpModel = Jaws_Gadget::getInstance('Components')->model->load('Gadgets'); $gadgets = $cmpModel->GetGadgetsList(null, true, true); unset($gadgets['ControlPanel']); foreach ($gadgets as $gadget => $gInfo) { if ($this->gadget->GetPermission('default_admin', '', $gadget)) { $section = $gInfo['section']; if (!isset($gadgetsections[$section])) { $gadgetsections[$section] = array(); } $gadgetsections[$section][] = array('name' => $gadget, 'tname' => $gInfo['title'], 'desc' => $gInfo['description']); } } if ($this->gadget->registry->fetch('show_viewsite', 'Settings') == 'true') { $gadgetsections['general'][] = array('name' => 'Index', 'tname' => _t('GLOBAL_VIEW_SITE'), 'desc' => _t('GLOBAL_VIEW_SITE')); } // Load the template $tpl = $this->gadget->template->loadAdmin('ControlPanel.html'); $this->AjaxMe('script.js'); foreach ($gadgetsections as $section => $gadgets) { $tpl->SetBlock('main'); $tpl->SetVariable('title', _t('GLOBAL_GI_' . strtoupper($section))); foreach ($gadgets as $gadget) { $tpl->SetBlock('main/item'); $tpl->SetVariable('name', $gadget['tname']); $tpl->SetVariable('desc', $gadget['desc']); if ($gadget['name'] === 'Index') { $tpl->SetVariable('icon', Jaws::CheckImage('gadgets/ControlPanel/Resources/images/view_site.png')); $tpl->SetVariable('url', $GLOBALS['app']->getSiteURL('/')); } else { $tpl->SetVariable('icon', Jaws::CheckImage('gadgets/' . $gadget['name'] . '/Resources/images/logo.png')); $tpl->SetVariable('url', BASE_SCRIPT . '?gadget=' . $gadget['name']); } $tpl->ParseBlock('main/item'); } $tpl->ParseBlock('main'); } if ($this->gadget->GetPermission('default_admin', '', 'Components')) { //Count non-installed gadgets $noninstalled = $cmpModel->GetGadgetsList(null, false); if (count($noninstalled) > 0) { $tpl->SetBlock('notifybox'); $tpl->SetVariable('title', _t('COMPONENTS_GADGETS_NOTINSTALLED')); foreach ($noninstalled as $key => $gadget) { $tpl->SetBlock('notifybox/item'); $gadgetCompleteDesc = $gadget['title'] . ' - ' . $gadget['description']; $icon = Jaws::CheckImage('gadgets/' . $key . '/Resources/images/logo.png'); $tpl->SetVariable('title', $gadgetCompleteDesc); $tpl->SetVariable('name', $gadget['title']); $tpl->SetVariable('icon', $icon); $tpl->SetVariable('url', BASE_SCRIPT . '?gadget=Components&action=InstallGadget&comp=' . $key); $tpl->SetVariable('install', _t('COMPONENTS_INSTALL')); $tpl->ParseBlock('notifybox/item'); } $tpl->ParseBlock('notifybox'); } //Count out date gadgets $nonupdated = $cmpModel->GetGadgetsList(null, true, false); if (count($nonupdated) > 0) { $tpl->SetBlock('notifybox'); $tpl->SetVariable('title', _t('COMPONENTS_GADGETS_OUTDATED')); foreach ($nonupdated as $key => $gadget) { $tpl->SetBlock('notifybox/item'); $gadgetCompleteDesc = $gadget['title'] . ' - ' . $gadget['description']; $icon = Jaws::CheckImage('gadgets/' . $key . '/Resources/images/logo.png'); $tpl->SetVariable('title', $gadgetCompleteDesc); $tpl->SetVariable('name', $gadget['title']); $tpl->SetVariable('icon', $icon); $tpl->SetVariable('url', BASE_SCRIPT . '?gadget=Components&action=UpgradeGadget&comp=' . $key); $tpl->SetVariable('install', _t('COMPONENTS_UPDATE')); $tpl->ParseBlock('notifybox/item'); } $tpl->ParseBlock('notifybox'); } } // login history if (Jaws_Gadget::IsGadgetInstalled('Logs')) { $logModel = Jaws_Gadget::getInstance('Logs')->model->load('Logs'); $logs = $logModel->GetLogs(array('gadget' => 'Users', 'action' => 'Login', 'user' => $GLOBALS['app']->Session->GetAttribute('user')), 10); if (!Jaws_Error::IsError($logs) && !empty($logs)) { $tpl->SetBlock('login_history'); $date = Jaws_Date::getInstance(); $tpl->SetVariable('title', _t('LOGS_LOGIN_HISTORY')); foreach ($logs as $log) { $tpl->SetBlock('login_history/item'); $tpl->SetVariable('ip', long2ip($log['ip'])); $tpl->SetVariable('agent', $log['agent']); $tpl->SetVariable('status_code', $log['status']); $tpl->SetVariable('status_title', _t('GLOBAL_HTTP_ERROR_TITLE_' . $log['status'])); $tpl->SetVariable('icon', 'images/stock/' . ($log['status'] == 200 ? 'info.png' : 'stop.png')); $tpl->SetVariable('date', $date->Format($log['insert_time'], 'd MN Y H:i')); $tpl->ParseBlock('login_history/item'); } $tpl->ParseBlock('login_history'); } } $last_checking = unserialize($this->gadget->registry->fetch('update_last_checking')); $do_checking = time() - $last_checking['time'] > 86400; // lesser do checking if need check $do_checking = $do_checking && mt_rand(1, 10) == mt_rand(1, 10); $tpl->SetBlock('versionbox'); $tpl->SetVariable('do_checking', (int) $do_checking); $tpl->SetVariable('jaws_version', JAWS_VERSION); $tpl->SetVariable('latest_jaws_version', $last_checking['version']); $tpl->SetVariable('lbl_latest_jaws_version', _t('CONTROLPANEL_LATEST_JAWS_VERSION')); $tpl->ParseBlock('versionbox'); return $tpl->Get(); }
/** * Returns an URL to the gadget icon * * @access public * @return string Icon URL * @param string $name Name of the gadget, if no name is provided use instanced gadget */ function GetIconURL($name = null) { if (empty($name)) { $name = $this->name; } $image = Jaws::CheckImage('gadgets/' . $name . '/Resources/images/logo.png'); return $image; }
/** * 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); }
/** * Gets EXIF thumbnail * * @access public * @param string $source Image path * @param string $unkown Unknown image to return if image doesn't have a thumb * @return binary Exif thumbnail */ static function get_exif_thumbnail($source, $unknown) { if (strpos($source, '../')) { return false; } $ext = strtolower(substr($source, strrpos($source, '.') + 1)); $valid_ext = array('jpg', 'jpeg'); if (in_array($ext, $valid_ext)) { if (function_exists('exif_thumbnail') && filesize($source) > 0) { $image = exif_thumbnail($source, $width, $height, $type); if ($image !== false) { header('Content-type: ' . image_type_to_mime_type($type)); return $image; } } } $unknown = Jaws::CheckImage($unknown); $ext = strtolower(substr($unknown, strrpos($unknown, '.') + 1)); header('Content-type: image/' . $ext); return file_get_contents($unknown); }