aboutsummaryrefslogtreecommitdiff
path: root/engine/classes
diff options
context:
space:
mode:
authorBrett Profitt <brett.profitt@gmail.com>2011-06-18 19:56:33 -0400
committerBrett Profitt <brett.profitt@gmail.com>2011-06-18 19:56:33 -0400
commitec7b94a64aef23b85866ecdac8e8acc712d29bb6 (patch)
treea108205c3fa0b694d8ce0ebaafd259480d6b530a /engine/classes
parentc80ba5aa03264dd64c20ed8ae222e87f9371a44d (diff)
parent2b68a4d217c35a5587c462620789493cf2804ba2 (diff)
downloadelgg-ec7b94a64aef23b85866ecdac8e8acc712d29bb6.tar.gz
elgg-ec7b94a64aef23b85866ecdac8e8acc712d29bb6.tar.bz2
Merge branch 'master' of github.com:Elgg/Elgg
Diffstat (limited to 'engine/classes')
-rw-r--r--engine/classes/ElggEntity.php7
-rw-r--r--engine/classes/ElggMenuItem.php22
-rw-r--r--engine/classes/ElggPlugin.php81
-rw-r--r--engine/classes/ElggPluginPackage.php28
-rw-r--r--engine/classes/ElggSite.php11
5 files changed, 97 insertions, 52 deletions
diff --git a/engine/classes/ElggEntity.php b/engine/classes/ElggEntity.php
index 79b8c2a4e..8fc1e46cb 100644
--- a/engine/classes/ElggEntity.php
+++ b/engine/classes/ElggEntity.php
@@ -850,12 +850,11 @@ abstract class ElggEntity extends ElggData implements
* @since 1.8.0
*/
function countComments() {
- $type = $this->getType();
$params = array('entity' => $this);
- $number = elgg_trigger_plugin_hook('comments:count', $type, $params, false);
+ $num = trigger_plugin_hook('comments:count', $this->getType(), $params);
- if ($number) {
- return $number;
+ if (is_int($num)) {
+ return $num;
} else {
return $this->getAnnotationCalculation('generic_comment', 'count');
}
diff --git a/engine/classes/ElggMenuItem.php b/engine/classes/ElggMenuItem.php
index 61dbf539e..157ed9ceb 100644
--- a/engine/classes/ElggMenuItem.php
+++ b/engine/classes/ElggMenuItem.php
@@ -325,7 +325,16 @@ class ElggMenuItem {
* @return string
*/
public function getItemClass() {
- return implode(' ', $this->itemClass);
+ //allow people to specify name with underscores and colons
+ $name = str_replace('_', '-', $this->getName());
+ $name = str_replace(':', '-', $name);
+
+ $class = implode(' ', $this->itemClass);
+ if ($class) {
+ return "elgg-menu-item-$name $class";
+ } else {
+ return "elgg-menu-item-$name";
+ }
}
/**
@@ -420,6 +429,17 @@ class ElggMenuItem {
}
/**
+ * Set the menu item's children
+ *
+ * @param array $children Array of ElggMenuItems
+ *
+ * @return void
+ */
+ public function setChildren($children) {
+ $this->children = $children;
+ }
+
+ /**
* Get the children menu items
*
* @return array
diff --git a/engine/classes/ElggPlugin.php b/engine/classes/ElggPlugin.php
index 20a8673de..95a7362e2 100644
--- a/engine/classes/ElggPlugin.php
+++ b/engine/classes/ElggPlugin.php
@@ -9,8 +9,8 @@
* @subpackage Plugins.Settings
*/
class ElggPlugin extends ElggObject {
- public $package;
- public $manifest;
+ private $package;
+ private $manifest;
private $path;
private $pluginID;
@@ -76,18 +76,6 @@ class ElggPlugin extends ElggObject {
// load the rest of the plugin
parent::__construct($existing_guid);
}
-
- // We have to let the entity load so we can manipulate it with the API.
- // If the path is wrong or would cause an exception, catch it,
- // disable the plugin, and emit an error.
- try {
- $this->package = new ElggPluginPackage($this->path, false);
- $this->manifest = $this->package->getManifest();
- } catch (Exception $e) {
- // we always have to allow the entity to load.
- elgg_log("Failed to load $this->guid as a plugin. " . $e->getMessage(), 'WARNING');
- $this->errorMsg = $e->getmessage();
- }
}
/**
@@ -152,7 +140,7 @@ class ElggPlugin extends ElggObject {
* @return array
*/
public function getAvailableTextFiles() {
- $filenames = $this->package->getTextFilenames();
+ $filenames = $this->getPackage()->getTextFilenames();
$files = array();
foreach ($filenames as $filename) {
@@ -562,13 +550,13 @@ class ElggPlugin extends ElggObject {
return false;
}
- if (!$this->package instanceof ElggPluginPackage) {
+ if (!$this->getPackage() instanceof ElggPluginPackage) {
$this->errorMsg = elgg_echo('ElggPlugin:NoPluginPackagePackage', array($this->getID(), $this->guid));
return false;
}
- if (!$this->package->isValid()) {
- $this->errorMsg = $this->package->getError();
+ if (!$this->getPackage()->isValid()) {
+ $this->errorMsg = $this->getPackage()->getError();
return false;
}
@@ -607,8 +595,8 @@ class ElggPlugin extends ElggObject {
* @return bool
*/
public function canActivate($site_guid = null) {
- if ($this->package) {
- return $this->package->isValid() && $this->package->checkDependencies();
+ if ($this->getPackage()) {
+ return $this->getPackage()->isValid() && $this->getPackage()->checkDependencies();
}
return false;
@@ -708,9 +696,9 @@ class ElggPlugin extends ElggObject {
* @throws PluginException
*/
public function start($flags) {
- if (!$this->canActivate()) {
- return false;
- }
+// if (!$this->canActivate()) {
+// return false;
+// }
// include start file
if ($flags & ELGG_PLUGIN_INCLUDE_START) {
@@ -851,12 +839,7 @@ class ElggPlugin extends ElggObject {
return true;
}
- // but need to have working ones.
- if (!elgg_register_classes($classes_path)) {
- $msg = elgg_echo('ElggPlugin:Exception:CannotRegisterClasses',
- array($this->getID(), $this->guid, $classes_path));
- throw new PluginException($msg);
- }
+ elgg_register_classes($classes_path);
return true;
}
@@ -958,4 +941,44 @@ class ElggPlugin extends ElggObject {
public function getError() {
return $this->errorMsg;
}
+
+ /**
+ * Returns this plugin's ElggPluginManifest object
+ *
+ * @return ElggPluginManifest
+ */
+ public function getManifest() {
+ if ($this->manifest instanceof ElggPluginManifest) {
+ return $this->manifest;
+ }
+
+ try {
+ $this->manifest = $this->getPackage()->getManifest();
+ } catch (Exception $e) {
+ elgg_log("Failed to load manifest for plugin $this->guid. " . $e->getMessage(), 'WARNING');
+ $this->errorMsg = $e->getmessage();
+ }
+
+ return $this->manifest;
+ }
+
+ /**
+ * Returns this plugin's ElggPluginPackage object
+ *
+ * @return ElggPluginPackage
+ */
+ public function getPackage() {
+ if ($this->package instanceof ElggPluginPackage) {
+ return $this->package;
+ }
+
+ try {
+ $this->package = new ElggPluginPackage($this->path, false);
+ } catch (Exception $e) {
+ elgg_log("Failed to load package for $this->guid. " . $e->getMessage(), 'WARNING');
+ $this->errorMsg = $e->getmessage();
+ }
+
+ return $this->package;
+ }
}
diff --git a/engine/classes/ElggPluginPackage.php b/engine/classes/ElggPluginPackage.php
index 4daab381e..977b72d76 100644
--- a/engine/classes/ElggPluginPackage.php
+++ b/engine/classes/ElggPluginPackage.php
@@ -334,13 +334,13 @@ class ElggPluginPackage {
// first, check if any active plugin conflicts with us.
foreach ($enabled_plugins as $plugin) {
- $temp_conflicts = $plugin->manifest->getConflicts();
+ $temp_conflicts = $plugin->getManifest()->getConflicts();
foreach ($temp_conflicts as $conflict) {
if ($conflict['type'] == 'plugin' && $conflict['name'] == $this_id) {
$result = $this->checkDepPlugin($conflict, $enabled_plugins, false);
// rewrite the conflict to show the originating plugin
- $conflict['name'] = $plugin->manifest->getName();
+ $conflict['name'] = $plugin->getManifest()->getName();
if (!$full_report && !$result['status']) {
return $result['status'];
@@ -455,19 +455,13 @@ class ElggPluginPackage {
*/
private function checkDepPriority(array $dep, array $plugins, $inverse = false) {
// grab the ElggPlugin using this package.
- $this_plugin = elgg_get_plugin_from_id($this->getID());
- $this_priority = $this_plugin->getPriority();
+ $plugin_package = elgg_get_plugin_from_id($this->getID());
+ $plugin_priority = $plugin_package->getPriority();
+ $test_plugin = elgg_get_plugin_from_id($dep['plugin']);
- foreach ($plugins as $test_plugin) {
- if ($test_plugin->getID() == $dep['plugin']) {
- break;
- }
- }
-
- // If this isn't a plugin or there are no active plugins,
- // we can't satisfy this dep.
- // Assume everything is ok. See #2946.
- if (!$this->plugin || !$plugins) {
+ // If this isn't a plugin or the plugin isn't installed or active
+ // priority doesn't matter. Use requires to check if a plugin is active.
+ if (!$plugin_package || !$test_plugin || !$test_plugin->isActive()) {
return array(
'status' => true,
'value' => 'uninstalled'
@@ -478,11 +472,11 @@ class ElggPluginPackage {
switch ($dep['priority']) {
case 'before':
- $status = $this_priority < $test_plugin_priority;
+ $status = $plugin_priority < $test_plugin_priority;
break;
case 'after':
- $status = $this_priority > $test_plugin_priority;
+ $status = $plugin_priority > $test_plugin_priority;
break;
default;
@@ -490,7 +484,7 @@ class ElggPluginPackage {
}
// get the current value
- if ($this_priority < $test_plugin_priority) {
+ if ($plugin_priority < $test_plugin_priority) {
$value = 'before';
} else {
$value = 'after';
diff --git a/engine/classes/ElggSite.php b/engine/classes/ElggSite.php
index d3cb0d488..e3b8b8f1a 100644
--- a/engine/classes/ElggSite.php
+++ b/engine/classes/ElggSite.php
@@ -148,11 +148,20 @@ class ElggSite extends ElggEntity {
* @return bool
*/
public function save() {
+ global $CONFIG;
+
// Save generic stuff
if (!parent::save()) {
return false;
}
+ // make sure the site guid is set (if not, set to self)
+ if (!$this->get('site_guid')) {
+ $guid = $this->get('guid');
+ update_data("UPDATE {$CONFIG->dbprefix}entities SET site_guid=$guid
+ WHERE guid=$guid");
+ }
+
// Now save specific stuff
return create_site_entity($this->get('guid'), $this->get('name'),
$this->get('description'), $this->get('url'));
@@ -400,7 +409,7 @@ class ElggSite extends ElggEntity {
'action/login',
'register',
'action/register',
- 'pages/account/forgotten_password\.php',
+ 'forgotpassword',
'action/user/requestnewpassword',
'resetpassword',
'upgrade\.php',