owncloud源码分析 修改界面

来源:互联网 发布:学办公软件 编辑:程序博客网 时间:2024/06/18 08:42

今天对owncloud的页面的显示方式感兴趣,简单来说就是对界面上的相关按钮或者内容进行修改,已达到了解他是如何布局和显示按钮功能的。总体上来说是通过模版加载,调用模版类如下代码:

$tmpl = new OCP\Template('files', 'index', 'user');


上述代码调用了Template类进行相关文件的加载,第一个参数是$app名字,这里边是files,index是要加载到的页面,比如我要在index.php中加载一个页面,就写index,其实是在index.php中,他默认将后缀省略了。最后一个user是在上述方法内又调用了一个renderLayout方法,加载的是真正的模版页面,也就是显示的HTML页面。今天研究的是用户登录后,不同的角色有不同的功能,比如管理员登录后,右上角有五个功能:个人、用户、管理、帮助、注销这5个功能,我们找到他的模版页面,layout_user.php看到里边的代码如下:

<!DOCTYPE html><!--[if lte IE 8]><html class="ng-csp ie ie8 lte9 lte8" data-placeholder-focus="false" lang="<?php p($_['language']); ?>" ><![endif]--><!--[if IE 9]><html class="ng-csp ie ie9 lte9" data-placeholder-focus="false" lang="<?php p($_['language']); ?>" ><![endif]--><!--[if (gt IE 9)|!(IE)]><!--><html class="ng-csp" data-placeholder-focus="false" lang="<?php p($_['language']); ?>" ><!--<![endif]--><head data-user="<?php p($_['user_uid']); ?>" data-requesttoken="<?php p($_['requesttoken']); ?>"<?php if ($_['updateAvailable']): ?>data-update-version="<?php print($_['updateVersion']); ?>" data-update-link="<?php print_unescaped($_['updateLink']); ?>"<?php endif; ?>><meta charset="utf-8"><title><?phpp(!empty($_['application'])?$_['application'].' - ':'');p($theme->getTitle());?></title><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="apple-itunes-app" content="app-id=<?php p($theme->getiTunesAppId()); ?>"><meta name="apple-mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-status-bar-style" content="black"><meta name="apple-mobile-web-app-title" content="<?php p((!empty($_['application']) && $_['appid']!='files')? $_['application']:'ownCloud'); ?>"><meta name="mobile-web-app-capable" content="yes"><link rel="shortcut icon" type="image/png" href="<?php print_unescaped(image_path($_['appid'], 'favicon.png')); ?>"><link rel="apple-touch-icon-precomposed" href="<?php print_unescaped(image_path($_['appid'], 'favicon-touch.png')); ?>"><?php foreach($_['cssfiles'] as $cssfile): ?><link rel="stylesheet" href="<?php print_unescaped($cssfile); ?>" media="screen"><?php endforeach; ?><?php foreach($_['jsfiles'] as $jsfile): ?><script src="<?php print_unescaped($jsfile); ?>"></script><?php endforeach; ?><?php print_unescaped($_['headers']); ?></head><body id="<?php p($_['bodyid']);?>"><?php include('layout.noscript.warning.php'); ?><div id="notification-container"><div id="notification"></div></div><header role="banner"><div id="header"><a href="<?php print_unescaped(link_to('', 'index.php')); ?>"id="owncloud" tabindex="1"><div class="logo-icon svg"><h1 class="hidden-visually"><?php p($theme->getName()); ?></h1></div></a><a href="#" class="header-appname-container menutoggle" tabindex="2"><h1 class="header-appname"><?phpif(OC_Util::getEditionString() === '') {p(!empty($_['application'])?$_['application']: $l->t('Apps'));} else {print_unescaped($theme->getHTMLName());}?></h1><div class="icon-caret svg"></div></a><div id="logo-claim" style="display:none;"><?php p($theme->getLogoClaim()); ?></div><div id="settings" class="svg"><div id="expand" tabindex="6" role="link"><?php if ($_['enableAvatars']): ?><div class="avatardiv<?php if ($_['userAvatarSet']) { print_unescaped(' avatardiv-shown'); } else { print_unescaped('" style="display: none'); } ?>"><?php if ($_['userAvatarSet']): ?><img src="<?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 32]));?>?requesttoken=<?php p(urlencode($_['requesttoken'])); ?>"alt=""><?php endif; ?></div><?php endif; ?><span id="expandDisplayName"><?php  p(trim($_['user_displayname']) != '' ? $_['user_displayname'] : $_['user_uid']) ?></span><img class="svg" alt="" src="<?php print_unescaped(image_path('', 'actions/caret.svg')); ?>"></div><div id="expanddiv"><ul><?php foreach($_['settingsnavigation'] as $entry):?><li><a href="<?php print_unescaped($entry['href']); ?>"<?php if( $entry["active"] ): ?> class="active"<?php endif; ?>><img class="svg" alt="" src="<?php print_unescaped($entry['icon']); ?>"><?php p($entry['name']) ?></a></li><?php endforeach; ?><li><a id="logout" <?php print_unescaped(OC_User::getLogoutAttribute()); ?>><img class="svg" alt="" src="<?php print_unescaped(image_path('', 'actions/logout.svg')); ?>"><?php p($l->t('Log out'));?></a></li></ul></div></div><form class="searchbox" action="#" method="post" role="search"><label for="searchbox" class="hidden-visually"><?php p($l->t('Search'));?></label><input id="searchbox" class="svg" type="search" name="query"value="<?php if(isset($_POST['query'])) {p($_POST['query']);};?>"autocomplete="off" tabindex="5"></form></div></header><nav role="navigation"><div id="navigation"><div id="apps" class="svg"><ul><?php foreach($_['navigation'] as $entry): ?><li data-id="<?php p($entry['id']); ?>"><a href="<?php print_unescaped($entry['href']); ?>" tabindex="3"<?php if( $entry['active'] ): ?> class="active"<?php endif; ?>><img class="app-icon svg" alt="" src="<?php print_unescaped($entry['icon']); ?>"><div class="icon-loading-dark" style="display:none;"></div><span><?php p($entry['name']); ?></span></a></li><?php endforeach; ?><?php/* show "More apps" link to app administration directly in app navigation, as last entry */if(OC_User::isAdminUser(OC_User::getUser())):?><li id="apps-management"><a href="<?php print_unescaped(\OC::$server->getURLGenerator()->linkToRoute('settings.AppSettings.viewApps')); ?>" tabindex="4"<?php if( $_['appsmanagement_active'] ): ?> class="active"<?php endif; ?>><img class="app-icon svg" alt="" src="<?php print_unescaped(OC_Helper::imagePath('settings', 'apps.svg')); ?>"><div class="icon-loading-dark" style="display:none;"></div><span><?php p($l->t('Apps')); ?></span></a></li><?php endif; ?></ul></div></div></nav><div id="content-wrapper"><div id="content" class="app-<?php p($_['appid']) ?>" role="main"><?php print_unescaped($_['content']); ?></div></div></body></html>


 

我们对照页面。分析出,注销这一功能是单独写出来的,而其他四个功能是存放在$_[settingsnavigation]变量中的,接下来看下摘录的代码:

<?php foreach($_['settingsnavigation'] as $entry):?><li><a href="<?php print_unescaped($entry['href']); ?>"<?php if( $entry["active"] ): ?> class="active"<?php endif; ?>><img class="svg" alt="" src="<?php print_unescaped($entry['icon']); ?>"><?php p($entry['name']) ?></a></li><?php endforeach; ?>

开始找了半天也没发现在哪里设置的这个变量,后来经过一天的查找,发先在lib/private/app.php中有获取这个变量的方法,虽然没找到在哪里调用,但是修改他原来的方法一定就可以增加或者删除相应的功能:我们接下来看下这段代码:

public static function getSettingsNavigation() {$l = \OC::$server->getL10N('lib');$settings = array();// by default, settings only contain the help menuif (OC_Util::getEditionString() === '' &&OC_Config::getValue('knowledgebaseenabled', true) == true) {$settings = array(array("id" => "help","order" => 1000,"href" => OC_Helper::linkToRoute("settings_help"),"name" => $l->t("Help"),"icon" => OC_Helper::imagePath("settings", "help.svg")));}// if the user is logged-inif (OC_User::isLoggedIn()) {// personal menu$settings[] = array("id" => "personal","order" => 1,"href" => OC_Helper::linkToRoute("settings_personal"),"name" => $l->t("Personal"),"icon" => OC_Helper::imagePath("settings", "personal.svg"));//SubAdmins are also allowed to access user managementif (OC_SubAdmin::isSubAdmin(OC_User::getUser())) {// admin users menu$settings[] = array("id" => "core_users","order" => 2,"href" => OC_Helper::linkToRoute("settings_users"),"name" => $l->t("Users"),"icon" => OC_Helper::imagePath("settings", "users.svg"));}// if the user is an adminif (OC_User::isAdminUser(OC_User::getUser())) {// admin settings$settings[] = array("id" => "admin","order" => 1000,"href" => OC_Helper::linkToRoute("settings_admin"),"name" => $l->t("Admin"),"icon" => OC_Helper::imagePath("settings", "admin.svg"));}}$navigation = self::proceedNavigation($settings);return $navigation;}


这里边都是先做出判断,根据权限是否是管理员,是否是普通用户等,然后进行不同的显示。如果我们想添加管理源功能,就根据上述代码修改就行。

第一个默认显示帮助功能。第二个如果用户登录了,显示个人功能。第三个如果是子管理员或者是超级管理员,都可以进行用户管理等。

0 0