hypejunction / group_subtypes
此包已废弃,不再维护。未建议替代包。
Elgg 的分组子类型
1.0.5
2017-01-08 08:53 UTC
Requires
- php: >=5.5
- composer/installers: ~1.0
This package is auto-updated.
Last update: 2020-01-29 03:42:12 UTC
README
功能
- 引入新分组子类型的 API
- 将现有分组升级到引入的子类型之一的工具
- 配置根级别和子分组子类型的管理员界面
- 创建具有固定工具预设的分组的管理员界面
描述
此插件提供高级钩子和一些初步的用户界面,用于引入分组子类型,将分组分散到多个页面处理程序,使用上下文特定语言字符串等。插件不提供实际翻译,也不更改现有的资源视图 - 这些视图是在姐妹插件(group_lists、group_membership、group_profiles)中完成的。
请注意,该插件覆盖了一些常见的分组视图,这些视图通常被其他插件(例如 group_tools)覆盖,因此如果您依赖这两个功能,您可能需要将它们集成在一起。
使用
钩子
'list_subtypes',$identifier
- 过滤显示在$identifier
页面上的分组子类型'page_identifier',"$type:$subtype"
- 过滤给定类型和子类型的分组路由页面标识符'permissions_check:parent','group'
- 过滤父实体拥有作为子组的权限
翻译
设置子类型后,将有大量的未翻译语言键。我还没有编写一个插件来自动化此过程。在此期间,您可以执行以下操作:
- 为您的翻译创建一个新插件
- 将您的语言文件添加到
/languages/
,例如/languages/en.php
- 为每个子类型添加两个翻译,例如,如果您的子类型是 school
// /languages/en.php return [ 'group:school' => 'School', 'item:group:school' => 'Schools', ];
- 在您的
start.php
中添加以下内容:
elgg_register_event_handler('ready', 'system', 'group_subtypes_register_translations'); /** * Use groups plugin translations for group subtypes * @global type $GLOBALS */ function group_subtypes_register_translations() { global $GLOBALS; $conf = group_subtypes_get_config(); $identifiers = array(); foreach ($conf as $subtype => $options) { $identifier = elgg_extract('identifier', $options); if ($identifier && $identifier !== 'groups') { $identifiers[$subtype] = $identifier; } } $languages = array_keys(get_installed_translations()); foreach ($languages as $language) { $translations = $GLOBALS['_ELGG']->translations[$language]; $to_translate = array(); if (file_exists(__DIR__ . "/languages/$language.php")) { $to_translate = include_once __DIR__ . "/languages/$language.php"; } $original_str = $translations["groups:group"]; $original_str_plural = $translations["groups"]; foreach ($identifiers as $subtype => $identifier) { $subtype_str = $original_str; if (isset($translations["group:$subtype"])) { $subtype_str = $translations["group:$subtype"]; } $to_translate["group:$subtype"] = $subtype_str; $subtype_str_plural = $original_str_plural; if (isset($translations["item:group:$subtype"])) { $subtype_str_plural = $translations["item:group:$subtype"]; } $to_translate["item:group:$subtype"] = $subtype_str_plural; foreach ($translations as $key => $translation) { $identifier_key = preg_replace("/^(groups)/", $identifier, $key); if ($identifier_key == $key) { continue; } if (!empty($translations[$identifier_key])) { continue; } $translation = str_replace(strtolower($original_str), strtolower($subtype_str), $translation); $translation = str_replace(ucfirst($original_str), ucfirst($subtype_str), $translation); $translation = str_replace(strtolower($original_str_plural), strtolower($subtype_str_plural), $translation); $translation = str_replace(ucfirst($original_str_plural), ucfirst($subtype_str_plural), $translation); $to_translate[$identifier_key] = $translation; } } $file = fopen(__DIR__ . "/languages/$language.php", 'w'); $contents = var_export($to_translate, true); fwrite($file, "<?php\r\n\r\nreturn $contents;\r\n"); fclose($file); } }
- 加载网站
- 现在您将在
/languages/
中看到新的语言文件,例如/languages/en.schools.php
- 编辑新文件以满足您的需求。您不需要复制任何内容,这些文件将像其他翻译文件一样被加载。
- 从
start.php
中删除所有代码,因为您不希望一直运行该代码 - 刷新缓存并享受!
致谢
本插件由 IvyTies.com 赞助 - 一家大学入学社交网络平台。