本文整理汇总了PHP中elgg_create_widget函数的典型用法代码示例。如果您正苦于以下问题:PHP elgg_create_widget函数的具体用法?PHP elgg_create_widget怎么用?PHP elgg_create_widget使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了elgg_create_widget函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: activate
/**
* Plugin activation
*/
static function activate()
{
//add widget on plugin activation if not added yet
if (!self::isAdded()) {
self::init();
$guid = elgg_create_widget(elgg_get_logged_in_user_guid(), 'version', 'admin');
if ($guid) {
$widget = get_entity($guid);
$widget->move(1, 0);
}
}
}
示例2: elgg_set_ignore_access
$ia = elgg_set_ignore_access(true);
foreach (array('profile', 'dashboard') as $context) {
if (isset($object->{$context})) {
elgg_push_context($context);
elgg_push_context('default_widgets');
elgg_push_context('widgets');
// deserialize the widget information
list($left, $middle, $right) = split('%%', $object->{$context});
$left_widgets = split('::', $left);
$middle_widgets = split('::', $middle);
$right_widgets = split('::', $right);
// 1st column is right column in default theme
$widgets = array(1 => array_reverse($right_widgets), 2 => array_reverse($middle_widgets), 3 => array_reverse($left_widgets));
foreach ($widgets as $column => $column_widgets) {
foreach ($column_widgets as $handler) {
$guid = elgg_create_widget($site->getGUID(), $handler, $context);
if ($guid) {
$widget = get_entity($guid);
$widget->move($column, 0);
}
}
}
elgg_pop_context();
elgg_pop_context();
elgg_pop_context();
}
}
elgg_set_ignore_access($ia);
$object->delete();
system_message(elgg_echo('upgrade:core'));
forward(REFERER);
示例3: elgg_add_admin_widgets
/**
* Adds default admin widgets to the admin dashboard.
*
* @param string $event
* @param string $type
* @param ElggUser $user
*
* @return null|true
* @access private
*/
function elgg_add_admin_widgets($event, $type, $user)
{
elgg_set_ignore_access(true);
// check if the user already has widgets
if (elgg_get_widgets($user->getGUID(), 'admin')) {
return true;
}
// In the form column => array of handlers in order, top to bottom
$adminWidgets = array(1 => array('control_panel', 'admin_welcome'), 2 => array('online_users', 'new_users', 'content_stats'));
foreach ($adminWidgets as $column => $handlers) {
foreach ($handlers as $position => $handler) {
$guid = elgg_create_widget($user->getGUID(), $handler, 'admin');
if ($guid) {
$widget = get_entity($guid);
/* @var ElggWidget $widget */
$widget->move($column, $position);
}
}
}
elgg_set_ignore_access(false);
}
示例4: get_input
$page_owner_guid = (int) get_input('page_owner_guid');
$handler = get_input('handler');
$context = get_input('context');
$show_access = (bool) get_input('show_access', true);
$column = (int) get_input('column', 1);
$default_widgets = (int) get_input('default_widgets', 0);
elgg_set_page_owner_guid($page_owner_guid);
$page_owner = elgg_get_page_owner_entity();
if (!$page_owner) {
return elgg_error_response(elgg_echo('widgets:add:failure'));
}
if (!elgg_can_edit_widget_layout($context)) {
// logged in user must be able to edit the layout to add a widget
return elgg_error_response(elgg_echo('widgets:add:failure'));
}
$guid = elgg_create_widget($page_owner->getGUID(), $handler, $context);
if (!$guid) {
return elgg_error_response(elgg_echo('widgets:add:failure'));
}
$widget = get_entity($guid);
// position the widget
$widget->move($column, 0);
$context_stack = [];
if ($default_widgets) {
$context_stack[] = 'default_widgets';
}
$context_stack[] = 'widgets';
if ($context) {
$context_stack[] = $context;
}
foreach ($context_stack as $ctx) {
示例5: widget_manager_update_group_event_handler
/**
* Sets the widget manager tool option. This is needed because in some situation the tool option is not available.
*
* And add/remove tool enabled widgets
*
* @param string $event name of the system event
* @param string $object_type type of the event
* @param mixed $object object related to the event
*
* @return void
*/
function widget_manager_update_group_event_handler($event, $object_type, $object)
{
if (!$object instanceof ElggGroup) {
return;
}
$plugin_settings = elgg_get_plugin_setting("group_enable", "widget_manager");
// make widget management mandatory
if ($plugin_settings == "forced") {
$object->widget_manager_enable = "yes";
}
// add/remove tool enabled widgets
if ($plugin_settings == "forced" || $plugin_settings == "yes" && $object->widget_manager_enable == "yes") {
$result = array("enable" => array(), "disable" => array());
$params = array("entity" => $object);
$result = elgg_trigger_plugin_hook("group_tool_widgets", "widget_manager", $params, $result);
if (empty($result) || !is_array($result)) {
return;
}
$current_widgets = elgg_get_widgets($object->getGUID(), "groups");
// disable widgets
$disable_widget_handlers = elgg_extract("disable", $result);
if (!empty($disable_widget_handlers) && is_array($disable_widget_handlers)) {
if (!empty($current_widgets) && is_array($current_widgets)) {
foreach ($current_widgets as $column => $widgets) {
if (!empty($widgets) && is_array($widgets)) {
foreach ($widgets as $order => $widget) {
// check if a widget should be removed
if (in_array($widget->handler, $disable_widget_handlers)) {
// yes, so remove the widget
$widget->delete();
unset($current_widgets[$column][$order]);
}
}
}
}
}
}
// enable widgets
$column_counts = array();
$enable_widget_handlers = elgg_extract("enable", $result);
if (!empty($enable_widget_handlers) || is_array($enable_widget_handlers)) {
// ignore access restrictions
// because if a group is created with a visibility of only group members
// the group owner is not yet added to the acl and thus can't edit the newly created widgets
$ia = elgg_set_ignore_access(true);
if (!empty($current_widgets) && is_array($current_widgets)) {
foreach ($current_widgets as $column => $widgets) {
// count for later balancing
$column_counts[$column] = count($widgets);
if (!empty($widgets) && is_array($widgets)) {
foreach ($widgets as $order => $widget) {
// check if a widget which sould be enabled isn't already enabled
$enable_index = array_search($widget->handler, $enable_widget_handlers);
if ($enable_index !== false) {
// already enabled, do add duplicate
unset($enable_widget_handlers[$enable_index]);
}
}
}
}
}
// add new widgets
if (!empty($enable_widget_handlers)) {
foreach ($enable_widget_handlers as $handler) {
$widget_guid = elgg_create_widget($object->getGUID(), $handler, "groups", $object->access_id);
if (!empty($widget_guid)) {
$widget = get_entity($widget_guid);
if ($column_counts[1] <= $column_counts[2]) {
// move to the end of the first column
$widget->move(1, 9000);
$column_counts[1]++;
} else {
// move to the end of the second
$widget->move(2, 9000);
$column_counts[2]++;
}
}
}
}
// restore access restrictions
elgg_set_ignore_access($ia);
}
}
}