From 6729a2d0d2faeb07ca8e79b5162c3be269e01b66 Mon Sep 17 00:00:00 2001 From: brettp Date: Sat, 16 Apr 2011 22:10:52 +0000 Subject: Fixes #3310. Applied lie2815's patch to use activate.php and deactivate.php instead of manifest on_de/activate fields in plugins. git-svn-id: http://code.elgg.org/elgg/trunk@9002 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/classes/ElggPlugin.php | 86 ++++++++++++--------------- engine/classes/ElggPluginManifest.php | 30 ---------- engine/classes/ElggPluginManifestParser18.php | 6 +- 3 files changed, 39 insertions(+), 83 deletions(-) (limited to 'engine') diff --git a/engine/classes/ElggPlugin.php b/engine/classes/ElggPlugin.php index 55be2b887..34e8e6732 100644 --- a/engine/classes/ElggPlugin.php +++ b/engine/classes/ElggPlugin.php @@ -639,24 +639,14 @@ class ElggPlugin extends ElggObject { // if there are any on_enable functions, start the plugin now and run them // Note: this will not run re-run the init hooks! - $functions = $this->manifest->getOnActivate(); - if ($return && $functions) { - $flags = ELGG_PLUGIN_INCLUDE_START | ELGG_PLUGIN_REGISTER_CLASSES - | ELGG_PLUGIN_REGISTER_LANGUAGES | ELGG_PLUGIN_REGISTER_VIEWS; - - $this->start($flags); - foreach ($functions as $function) { - if (!is_callable($function)) { - $return = false; - } else { - $result = call_user_func($function); - // allow null to mean "I don't care" like other subsystems - $return = ($result === false) ? false: true; - } - - if ($return === false) { - break; - } + if ($return) { + if ($this->canIncludeFile('activate.php')) { + $flags = ELGG_PLUGIN_INCLUDE_START | ELGG_PLUGIN_REGISTER_CLASSES + | ELGG_PLUGIN_REGISTER_LANGUAGES | ELGG_PLUGIN_REGISTER_VIEWS; + + $this->start($flags); + + $return = $this->includeFile('activate.php'); } } @@ -690,27 +680,10 @@ class ElggPlugin extends ElggObject { $return = elgg_trigger_event('deactivate', 'plugin', $params); - // run any deactivate functions - // check for the manifest in case we haven't fully loaded the plugin. - if ($this->manifest) { - $functions = $this->manifest->getOnDeactivate(); - } else { - $functions = array(); - } - - if ($return && $functions) { - foreach ($functions as $function) { - if (!is_callable($function)) { - $return = false; - } else { - $result = call_user_func($function); - // allow null to mean "I don't care" like other subsystems - $return = ($result === false) ? false : true; - } - - if ($return === false) { - break; - } + // run any deactivate code + if ($return) { + if ($this->canIncludeFile('deactivate.php')) { + $return = $this->includeFile('deactivate.php'); } } @@ -736,7 +709,7 @@ class ElggPlugin extends ElggObject { // include start file if ($flags & ELGG_PLUGIN_INCLUDE_START) { - $this->includeStart(); + $this->includeFile('start.php'); } // include views @@ -761,24 +734,39 @@ class ElggPlugin extends ElggObject { // start helpers /** - * Includes the plugin's start file + * Includes one of the plugins files + * + * @param string $filename The name of the file * * @throws PluginException - * @return true + * @return mixed The return value of the included file (or 1 if there is none) */ - protected function includeStart() { + protected function includeFile($filename) { // This needs to be here to be backwards compatible for 1.0-1.7. // They expect the global config object to be available in start.php. - global $CONFIG; + if ($filename == 'start.php') { + global $CONFIG; + } + + $filepath = "$this->path/$filename"; - $start = "$this->path/start.php"; - if (!include($start)) { - $msg = elgg_echo('ElggPlugin:Exception:CannotIncludeStart', - array($this->getID(), $this->guid, $this->path)); + if (!$this->canIncludeFile($filename)) { + $msg = elgg_echo('ElggPlugin:Exception:CannotIncludeFile', + array($filename, $this->getID(), $this->guid, $this->path)); throw new PluginException($msg); } - return true; + return include $filepath; + } + + /** + * Checks whether a plugin file with the given name exists + * + * @param string $filename The name of the file + * @return bool + */ + protected function canIncludeFile($filename) { + return file_exists($this->path.'/'.$filename); } /** diff --git a/engine/classes/ElggPluginManifest.php b/engine/classes/ElggPluginManifest.php index a0ec478a9..0f3b1d7a8 100644 --- a/engine/classes/ElggPluginManifest.php +++ b/engine/classes/ElggPluginManifest.php @@ -576,36 +576,6 @@ class ElggPluginManifest { return $normalized; } - /** - * Returns the functions to run upon activation - * - * @return array - */ - public function getOnActivate() { - $functions = $this->parser->getAttribute('on_activate'); - - if (!$functions) { - $functions = array(); - } - - return $functions; - } - - /** - * Returns the functions to run upon deactivation - * - * @return array - */ - public function getOnDeactivate() { - $functions = $this->parser->getAttribute('on_deactivate'); - - if (!$functions) { - $functions = array(); - } - - return $functions; - } - /** * Returns the admin interface to use. * diff --git a/engine/classes/ElggPluginManifestParser18.php b/engine/classes/ElggPluginManifestParser18.php index 38734f6b4..db8b3dc6a 100644 --- a/engine/classes/ElggPluginManifestParser18.php +++ b/engine/classes/ElggPluginManifestParser18.php @@ -15,8 +15,8 @@ class ElggPluginManifestParser18 extends ElggPluginManifestParser { protected $validAttributes = array( 'name', 'author', 'version', 'blurb', 'description', 'website', 'copyright', 'license', 'requires', 'suggests', - 'screenshot', 'category', 'conflicts', 'provides', 'on_activate', - 'on_deactivate', 'admin_interface', 'activate_on_install' + 'screenshot', 'category', 'conflicts', 'provides', + 'admin_interface', 'activate_on_install' ); /** @@ -52,8 +52,6 @@ class ElggPluginManifestParser18 extends ElggPluginManifestParser { break; // arrays - case 'on_activate': - case 'on_deactivate': case 'category': $parsed[$element->name][] = $element->content; break; -- cgit v1.2.3 From e18e17ef647e7faf4563bb8ce77ffe448bc929cb Mon Sep 17 00:00:00 2001 From: brettp Date: Mon, 18 Apr 2011 18:15:14 +0000 Subject: Fixes #3365. Pulled in blacktooth's patch. git-svn-id: http://code.elgg.org/elgg/trunk@9003 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/cache.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'engine') diff --git a/engine/lib/cache.php b/engine/lib/cache.php index 8529ae7fa..11c95e78a 100644 --- a/engine/lib/cache.php +++ b/engine/lib/cache.php @@ -163,13 +163,15 @@ function elgg_register_simplecache_view($viewname) { function elgg_get_simplecache_url($type, $view) { global $CONFIG; $lastcache = (int)$CONFIG->lastcache; - + $viewtype = elgg_get_viewtype(); if (elgg_is_simplecache_enabled()) { - $viewtype = elgg_get_viewtype(); $url = elgg_get_site_url() . "cache/$type/$viewtype/$view.$lastcache.$type"; } else { $url = elgg_get_site_url() . "$type/$view.$lastcache.$type"; + $elements = array("view" => $viewtype); + $url = elgg_http_add_url_query_elements($url, $elements); } + return $url; } -- cgit v1.2.3 From 2408cc5c69209350a350246e260de494720eb773 Mon Sep 17 00:00:00 2001 From: brettp Date: Mon, 18 Apr 2011 18:47:17 +0000 Subject: Fixes #2046. Applied Franz' patch for sanitize_int(). git-svn-id: http://code.elgg.org/elgg/trunk@9004 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/database.php | 21 +++++++++++++++------ engine/lib/entities.php | 2 +- engine/lib/metastrings.php | 4 ++-- engine/lib/river.php | 4 ++-- 4 files changed, 20 insertions(+), 11 deletions(-) (limited to 'engine') diff --git a/engine/lib/database.php b/engine/lib/database.php index a9c4017a0..6b1b494b9 100644 --- a/engine/lib/database.php +++ b/engine/lib/database.php @@ -680,22 +680,31 @@ function sanitize_string($string) { * Sanitises an integer for database use. * * @param int $int Integer - * + * @param bool[optional] $signed Whether negative values should be allowed (true) * @return int Sanitised integer */ -function sanitise_int($int) { +function sanitise_int($int, $signed = true) { + $int = (int) $int; + + if ($signed === false) { + if ($int < 0) { + $int = 0; + } + } + return (int) $int; } /** - * Wrapper function for alternate English spelling + * Sanitises an integer for database use. + * Wrapper function for alternate English spelling (@see sanitise_int) * * @param int $int Integer - * + * @param bool[optional] $signed Whether negative values should be allowed (true) * @return int Sanitised integer */ -function sanitize_int($int) { - return (int) $int; +function sanitize_int($int, $signed = true) { + return sanitise_int($int, $signed); } /** diff --git a/engine/lib/entities.php b/engine/lib/entities.php index 685c68a5b..cb197b569 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -922,7 +922,7 @@ function elgg_get_entities(array $options = array()) { if ($options['limit']) { $limit = sanitise_int($options['limit']); - $offset = sanitise_int($options['offset']); + $offset = sanitise_int($options['offset'], false); $query .= " LIMIT $offset, $limit"; } diff --git a/engine/lib/metastrings.php b/engine/lib/metastrings.php index 604c7f765..655617ac6 100644 --- a/engine/lib/metastrings.php +++ b/engine/lib/metastrings.php @@ -319,7 +319,7 @@ function elgg_get_metastring_based_objects($options) { 'metastring_owner_guid', 'metastring_id', 'select', 'where', 'join' ); - + $options = elgg_normalise_plural_options_array($options, $singulars); if (!$options) { @@ -456,7 +456,7 @@ function elgg_get_metastring_based_objects($options) { if ($options['limit']) { $limit = sanitise_int($options['limit']); - $offset = sanitise_int($options['offset']); + $offset = sanitise_int($options['offset'], false); $query .= " LIMIT $offset, $limit"; } diff --git a/engine/lib/river.php b/engine/lib/river.php index 55d1c783a..80f285e50 100644 --- a/engine/lib/river.php +++ b/engine/lib/river.php @@ -302,7 +302,7 @@ function elgg_get_river(array $options = array()) { if ($options['limit']) { $limit = sanitise_int($options['limit']); - $offset = sanitise_int($options['offset']); + $offset = sanitise_int($options['offset'], false); $query .= " LIMIT $offset, $limit"; } @@ -375,7 +375,7 @@ function elgg_row_to_elgg_river_item($row) { function elgg_river_get_access_sql() { // rewrite default access where clause to work with river table return str_replace("and enabled='yes'", '', - str_replace('owner_guid', 'rv.subject_guid', + str_replace('owner_guid', 'rv.subject_guid', str_replace('access_id', 'rv.access_id', get_access_sql_suffix()))); } -- cgit v1.2.3 From d928588805375e7190ab393e2def555b39701a27 Mon Sep 17 00:00:00 2001 From: brettp Date: Mon, 18 Apr 2011 21:11:00 +0000 Subject: Fixes #3358. Renamed menu's class to link_class and documented possible problems with passing tags in the text option. git-svn-id: http://code.elgg.org/elgg/trunk@9005 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/classes/ElggMenuItem.php | 8 ++++---- engine/lib/navigation.php | 11 +++++++++-- views/default/page/layouts/content/header.php | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) (limited to 'engine') diff --git a/engine/classes/ElggMenuItem.php b/engine/classes/ElggMenuItem.php index bf6cf2edc..61dbf539e 100644 --- a/engine/classes/ElggMenuItem.php +++ b/engine/classes/ElggMenuItem.php @@ -123,9 +123,9 @@ class ElggMenuItem { unset($options['context']); } - if (isset($options['class'])) { - $item->setLinkClass($options['class']); - unset($options['class']); + if (isset($options['link_class'])) { + $item->setLinkClass($options['link_class']); + unset($options['link_class']); } if (isset($options['item_class'])) { @@ -459,7 +459,7 @@ class ElggMenuItem { if ($this->href) { $vars['href'] = $this->href; } - + if ($this->linkClass) { $vars['class'] = $this->getLinkClass(); } diff --git a/engine/lib/navigation.php b/engine/lib/navigation.php index 953bbe59a..b51c63b49 100644 --- a/engine/lib/navigation.php +++ b/engine/lib/navigation.php @@ -61,12 +61,19 @@ * @param mixed $menu_item A ElggMenuItem object or an array of options in format: * name => STR Menu item identifier (required) * text => STR Menu item display text (required) - * href => STR Menu item URL (required) (false for non-links) + * href => STR Menu item URL (required) (false for non-links. + * @warning If you disable the href the tag will + * not appear, so the link_class will not apply. If you + * put tags in manually through the 'text' option + * the default CSS selector .elgg-menu-$menu > li > a + * may affect formatting. Wrap in a if it does.) * contexts => ARR Page context strings * section => STR Menu section identifier * title => STR Menu item tooltip * selected => BOOL Is this menu item currently selected * parent_name => STR Identifier of the parent menu item + * link_class => STR A class or classes for the tag + * item_class => STR A class or classes for the
  • tag * * Custom options can be added as key value pairs. * @@ -269,7 +276,7 @@ function elgg_river_menu_setup($hook, $type, $return, $params) { 'href' => "#comments-add-$object->guid", 'text' => elgg_view_icon('speech-bubble'), 'title' => elgg_echo('comment:this'), - 'class' => "elgg-toggler", + 'link_class' => "elgg-toggler", 'priority' => 50, ); $return[] = ElggMenuItem::factory($options); diff --git a/views/default/page/layouts/content/header.php b/views/default/page/layouts/content/header.php index 4c63009f4..403da8a0a 100644 --- a/views/default/page/layouts/content/header.php +++ b/views/default/page/layouts/content/header.php @@ -37,7 +37,7 @@ if ($context) { 'name' => 'add', 'href' => elgg_extract('new_link', $vars, "$context/add/$guid"), 'text' => elgg_echo("$context:add"), - 'class' => 'elgg-button elgg-button-action', + 'link_class' => 'elgg-button elgg-button-action', )); } } -- cgit v1.2.3