Beispiel #1
0
 /**
  * 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 = get_config('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 (!update_data($q)) {
             return false;
         }
         // set this priority
         if ($this->set($name, $priority)) {
             return true;
         } else {
             return false;
         }
     }
     return false;
 }
Beispiel #2
0
 * 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
 */
$plugin = $vars['entity'];
$reordering = elgg_extract('display_reordering', $vars, false);
$priority = $plugin->getPriority();
$active = $plugin->isActive();
$name = $plugin->getManifest()->getName();
$can_activate = $plugin->canActivate();
$max_priority = elgg_get_max_plugin_priority();
$actions_base = '/action/admin/plugins/';
$ts = time();
$token = generate_action_token($ts);
// build reordering links
$links = '';
if ($reordering) {
    $draggable = '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