/** * Sets the priority of the plugin * * @param mixed $priority The priority to set. One of +1, -1, first, last, or a number. * If given a number, this will displace all plugins at that number * and set their priorities +1 * @param mixed $site_guid Optional site GUID. * @return bool */ public function setPriority($priority, $site_guid = null) { if (!$this->guid) { return false; } $db_prefix = _elgg_services()->configTable->get('dbprefix'); $name = _elgg_namespace_plugin_private_setting('internal', 'priority'); // if no priority assume a priority of 1 $old_priority = (int) $this->getPriority(); $old_priority = !$old_priority ? 1 : $old_priority; $max_priority = _elgg_get_max_plugin_priority(); // can't use switch here because it's not strict and // php evaluates +1 == 1 if ($priority === '+1') { $priority = $old_priority + 1; } elseif ($priority === '-1') { $priority = $old_priority - 1; } elseif ($priority === 'first') { $priority = 1; } elseif ($priority === 'last') { $priority = $max_priority; } // should be a number by now if ($priority > 0) { if (!is_numeric($priority)) { return false; } // there's nothing above the max. if ($priority > $max_priority) { $priority = $max_priority; } // there's nothing below 1. if ($priority < 1) { $priority = 1; } if ($priority > $old_priority) { $op = '-'; $where = "CAST(value as unsigned) BETWEEN {$old_priority} AND {$priority}"; } else { $op = '+'; $where = "CAST(value as unsigned) BETWEEN {$priority} AND {$old_priority}"; } // displace the ones affected by this change $q = "UPDATE {$db_prefix}private_settings\n\t\t\t\tSET value = CAST(value as unsigned) {$op} 1\n\t\t\t\tWHERE entity_guid != {$this->guid}\n\t\t\t\tAND name = '{$name}'\n\t\t\t\tAND {$where}"; if (!$this->getDatabase()->updateData($q)) { return false; } // set this priority if ($this->setPrivateSetting($name, $priority)) { return true; } else { return false; } } return false; }
* This file renders a plugin for the admin screen, including active/deactive, * manifest details & display plugin settings. * * @uses $vars['entity'] * @uses $vars['display_reordering'] Do we display the priority reordering links? * * @package Elgg.Core * @subpackage Plugins */ /* @var ElggPlugin $plugin */ $plugin = $vars['entity']; $reordering = elgg_extract('display_reordering', $vars, false); $priority = $plugin->getPriority(); $active = $plugin->isActive(); $can_activate = $plugin->canActivate(); $max_priority = _elgg_get_max_plugin_priority(); $actions_base = '/action/admin/plugins/'; $css_id = preg_replace('/[^a-z0-9-]/i', '-', $plugin->getID()); // build reordering links $links = ''; $classes = array('elgg-plugin'); if ($reordering) { $classes[] = 'elgg-state-draggable'; // top and up link only if not at top if ($priority > 1) { $top_url = elgg_http_add_url_query_elements($actions_base . 'set_priority', array('plugin_guid' => $plugin->guid, 'priority' => 'first', 'is_action' => true)); $links .= "<li>" . elgg_view('output/url', array('href' => $top_url, 'text' => elgg_echo('top'), 'is_action' => true, 'is_trusted' => true)) . "</li>"; $up_url = elgg_http_add_url_query_elements($actions_base . 'set_priority', array('plugin_guid' => $plugin->guid, 'priority' => '-1', 'is_action' => true)); $links .= "<li>" . elgg_view('output/url', array('href' => $up_url, 'text' => elgg_echo('up'), 'is_action' => true, 'is_trusted' => true)) . "</li>"; } // down and bottom links only if not at bottom