/** * Add menu items to the filter menu * * @param string $hook 'cron' * @param string $type 'daily' * @param string $return_value optional output * @param array $params supplied params * * @return void */ public static function daily($hook, $type, $return_value, $params) { if (!static_out_of_date_enabled()) { return; } $time = elgg_extract('time', $params, time()); $days = (int) elgg_get_plugin_setting('out_of_date_days', 'static'); $site = elgg_get_site_entity(); $options = ['type' => 'object', 'subtype' => \StaticPage::SUBTYPE, 'limit' => false, 'modified_time_upper' => $time - $days * 24 * 60 * 60, 'modified_time_lower' => $time - ($days + 1) * 24 * 60 * 60, 'order_by' => 'e.time_updated DESC']; // ignore access $ia = elgg_set_ignore_access(true); $batch = new \ElggBatch('elgg_get_entities', $options); $users = []; foreach ($batch as $entity) { $last_editors = $entity->getAnnotations(['annotation_name' => 'static_revision', 'limit' => 1, 'order_by' => 'n_table.time_created DESC']); if (empty($last_editors)) { continue; } $users[$last_editors[0]->getOwnerGUID()] = $last_editors[0]->getOwnerEntity(); } // restore access elgg_set_ignore_access($ia); if (empty($users)) { return; } foreach ($users as $user) { $subject = elgg_echo('static:out_of_date:notification:subject'); $message = elgg_echo('static:out_of_date:notification:message', [$user->name, elgg_normalize_url('static/out_of_date/' . $user->username)]); notify_user($user->getGUID(), $site->getGUID(), $subject, $message, [], 'email'); } }
<?php elgg_gatekeeper(); if (!static_out_of_date_enabled()) { forward(REFERER); } $page_owner = elgg_get_page_owner_entity(); if (!$page_owner instanceof ElggUser) { register_error(elgg_echo('pageownerunavailable', [elgg_get_page_owner_guid()])); forward(REFERER); } if (!$page_owner->canEdit()) { register_error(elgg_echo('limited_access')); forward(REFERER); } $dbprefix = elgg_get_config('dbprefix'); $static_revision_id = elgg_get_metastring_id('static_revision'); $days = (int) elgg_get_plugin_setting('out_of_date_days', 'static'); $options = ['type' => 'object', 'subtype' => StaticPage::SUBTYPE, 'modified_time_upper' => time() - $days * 24 * 60 * 60, 'wheres' => ["e.guid IN (\n\t\t\tSELECT entity_guid\n\t\t\tFROM (\n\t\t\t\tSELECT *\n\t\t\t\tFROM (\n\t\t\t\t\tSELECT *\n\t\t\t\t\tFROM {$dbprefix}annotations\n\t\t\t\t\tWHERE name_id = {$static_revision_id}\n\t\t\t\t\tORDER BY entity_guid, time_created DESC) a1\n\t\t\t\tGROUP BY a1.entity_guid) a2\n\t\t\tWHERE a2.owner_guid = {$page_owner->getGUID()})\n\t\t"], 'order_by' => 'e.time_updated DESC', 'no_results' => elgg_echo('static:out_of_date:none'), 'item_view' => 'object/static/simple']; $title_text = elgg_echo('static:out_of_date:owner:title', [$page_owner->name]); $filter = elgg_view('page/layouts/elements/filter'); $body = elgg_list_entities($options); // build page $page_data = elgg_view_layout('one_column', ['title' => $title_text, 'content' => $filter . $body]); // draw page echo elgg_view_page($title_text, $page_data);
/** * Add menu items to the filter menu * * @param string $hook 'register' * @param string $type 'menu:filter' * @param ElggMenuItem[] $return_value the menu items * @param array $params supplied params * * @return ElggMenuItem[] */ public static function filterMenuRegister($hook, $type, $return_value, $params) { if (!static_out_of_date_enabled()) { return; } if (!elgg_in_context('static')) { return; } $current_page = current_page_url(); $out_of_date_selected = false; $page_owner = elgg_get_page_owner_entity(); if (elgg_instanceof($page_owner, 'group')) { $return_value[] = \ElggMenuItem::factory(['name' => 'all', 'text' => elgg_echo('all'), 'href' => "static/group/{$page_owner->getGUID()}", 'is_trusted' => true, 'priority' => 100]); if ($page_owner->canEdit()) { $url = "static/group/{$page_owner->getGUID()}/out_of_date"; if (strpos($current_page, elgg_normalize_url($url)) === 0) { $out_of_date_selected = true; } $return_value[] = \ElggMenuItem::factory(['name' => 'out_of_date_group', 'text' => elgg_echo('static:menu:filter:out_of_date:group'), 'href' => $url, 'is_trusted' => true, 'priority' => 250, 'selected' => $out_of_date_selected]); } } else { $return_value[] = \ElggMenuItem::factory(['name' => 'all', 'text' => elgg_echo('all'), 'href' => 'static/all', 'is_trusted' => true, 'priority' => 100]); } $user = elgg_get_logged_in_user_entity(); if (!empty($user)) { $url = "static/out_of_date/{$user->username}"; if (strpos($current_page, elgg_normalize_url($url)) === 0) { $out_of_date_selected = true; } $return_value[] = \ElggMenuItem::factory(['name' => 'out_of_date_mine', 'text' => elgg_echo('static:menu:filter:out_of_date:mine'), 'href' => $url, 'is_trusted' => true, 'priority' => 300, 'selected' => $out_of_date_selected]); } if (elgg_is_admin_logged_in()) { $url = 'static/out_of_date'; if (!$out_of_date_selected && strpos($current_page, elgg_normalize_url($url)) === 0) { $out_of_date_selected = true; } else { $out_of_date_selected = false; } $return_value[] = \ElggMenuItem::factory(['name' => 'out_of_date', 'text' => elgg_echo('static:menu:filter:out_of_date'), 'href' => $url, 'is_trusted' => true, 'priority' => 200, 'selected' => $out_of_date_selected]); } return $return_value; }