aboutsummaryrefslogtreecommitdiff
path: root/engine/classes
diff options
context:
space:
mode:
Diffstat (limited to 'engine/classes')
-rw-r--r--engine/classes/ElggEntity.php18
-rw-r--r--engine/classes/ElggFile.php41
-rw-r--r--engine/classes/ElggMenuItem.php6
-rw-r--r--engine/classes/ElggPlugin.php22
-rw-r--r--engine/classes/ElggPluginManifest.php38
-rw-r--r--engine/classes/ElggPluginPackage.php8
-rw-r--r--engine/classes/ElggPriorityList.php358
-rw-r--r--engine/classes/ElggSite.php3
8 files changed, 448 insertions, 46 deletions
diff --git a/engine/classes/ElggEntity.php b/engine/classes/ElggEntity.php
index 6edc99dd4..2fa0d7b02 100644
--- a/engine/classes/ElggEntity.php
+++ b/engine/classes/ElggEntity.php
@@ -371,13 +371,18 @@ abstract class ElggEntity extends ElggData implements
* Deletes all metadata on this object (metadata.entity_guid = $this->guid).
* If you pass a name, only metadata matching that name will be deleted.
*
- * @warning Calling this with no or empty arguments will clear all metadata on the entity.
+ * @warning Calling this with no $name will clear all metadata on the entity.
*
- * @param null|string $name The metadata name to remove.
+ * @param null|string $name The name of the metadata to remove.
* @return bool
* @since 1.8
*/
public function deleteMetadata($name = null) {
+
+ if (!$this->guid) {
+ return false;
+ }
+
$options = array(
'guid' => $this->guid,
'limit' => 0
@@ -1432,11 +1437,7 @@ abstract class ElggEntity extends ElggData implements
* @return true
*/
public function setLocation($location) {
- $location = sanitise_string($location);
-
- $this->location = $location;
-
- return true;
+ return $this->location = $location;
}
/**
@@ -1449,9 +1450,6 @@ abstract class ElggEntity extends ElggData implements
* @todo Unimplemented
*/
public function setLatLong($lat, $long) {
- $lat = sanitise_string($lat);
- $long = sanitise_string($long);
-
$this->set('geo:lat', $lat);
$this->set('geo:long', $long);
diff --git a/engine/classes/ElggFile.php b/engine/classes/ElggFile.php
index fe25491a8..f21621ffd 100644
--- a/engine/classes/ElggFile.php
+++ b/engine/classes/ElggFile.php
@@ -121,6 +121,47 @@ class ElggFile extends ElggObject {
}
/**
+ * Detects mime types based on filename or actual file.
+ *
+ * @param mixed $file The full path of the file to check. For uploaded files, use tmp_name.
+ * @param mixed $default A default. Useful to pass what the browser thinks it is.
+ * @since 1.7.12
+ *
+ * @return mixed Detected type on success, false on failure.
+ */
+ static function detectMimeType($file = null, $default = null) {
+ if (!$file) {
+ if (isset($this) && $this->filename) {
+ $file = $this->filename;
+ } else {
+ return false;
+ }
+ }
+
+ $mime = false;
+
+ // for PHP5 folks.
+ if (function_exists('finfo_file') && defined('FILEINFO_MIME_TYPE')) {
+ $resource = finfo_open(FILEINFO_MIME_TYPE);
+ if ($resource) {
+ $mime = finfo_file($resource, $file);
+ }
+ }
+
+ // for everyone else.
+ if (!$mime && function_exists('mime_content_type')) {
+ $mime = mime_content_type($file);
+ }
+
+ // default
+ if (!$mime) {
+ return $default;
+ }
+
+ return $mime;
+ }
+
+ /**
* Set the optional file description.
*
* @param string $description The description.
diff --git a/engine/classes/ElggMenuItem.php b/engine/classes/ElggMenuItem.php
index cfdc2f5fa..b9c81fd78 100644
--- a/engine/classes/ElggMenuItem.php
+++ b/engine/classes/ElggMenuItem.php
@@ -59,7 +59,7 @@ class ElggMenuItem {
/**
* @var string Tooltip
*/
- protected $title = '';
+ protected $title = false;
/**
* @var string The string to display if link is clicked
@@ -543,7 +543,7 @@ class ElggMenuItem {
if ($this->data['linkClass']) {
if (isset($vars['class'])) {
- $vars['class'] += $this->getLinkClass();
+ $vars['class'] = $vars['class'] . ' ' . $this->getLinkClass();
} else {
$vars['class'] = $this->getLinkClass();
}
@@ -552,6 +552,8 @@ class ElggMenuItem {
if ($this->confirm) {
$vars['confirm'] = $this->confirm;
return elgg_view('output/confirmlink', $vars);
+ } else {
+ unset($vars['confirm']);
}
return elgg_view('output/url', $vars);
diff --git a/engine/classes/ElggPlugin.php b/engine/classes/ElggPlugin.php
index d837431fc..4aee1e898 100644
--- a/engine/classes/ElggPlugin.php
+++ b/engine/classes/ElggPlugin.php
@@ -116,6 +116,21 @@ class ElggPlugin extends ElggObject {
}
/**
+ * Returns the manifest's name if available, otherwise the ID.
+ *
+ * @return string
+ * @since 1.8.1
+ */
+ public function getFriendlyName() {
+ $manifest = $this->getManifest();
+ if ($manifest) {
+ return $manifest->getName();
+ }
+
+ return $this->getID();
+ }
+
+ /**
* Returns the plugin's full path with trailing slash.
*
* @return string
@@ -597,7 +612,12 @@ class ElggPlugin extends ElggObject {
*/
public function canActivate($site_guid = null) {
if ($this->getPackage()) {
- return $this->getPackage()->isValid() && $this->getPackage()->checkDependencies();
+ $result = $this->getPackage()->isValid() && $this->getPackage()->checkDependencies();
+ if (!$result) {
+ $this->errorMsg = $this->getPackage()->getError();
+ }
+
+ return $result;
}
return false;
diff --git a/engine/classes/ElggPluginManifest.php b/engine/classes/ElggPluginManifest.php
index 0f3b1d7a8..0e47f388d 100644
--- a/engine/classes/ElggPluginManifest.php
+++ b/engine/classes/ElggPluginManifest.php
@@ -224,20 +224,15 @@ class ElggPluginManifest {
/**
* Returns the plugin name
*
- * @param bool $elgg_echo Run the name through elgg_echo.
* @return string
*/
- public function getName($elgg_echo = true) {
+ public function getName() {
$name = $this->parser->getAttribute('name');
if (!$name && $this->pluginID) {
$name = ucwords(str_replace('_', ' ', $this->pluginID));
}
- if ($elgg_echo) {
- $name = elgg_echo($name);
- }
-
return $name;
}
@@ -245,33 +240,21 @@ class ElggPluginManifest {
/**
* Return the description
*
- * @param bool $elgg_echo Run the description through elgg_echo.
* @return string
*/
- public function getDescription($elgg_echo = true) {
- $desc = $this->parser->getAttribute('description');
-
- if ($elgg_echo) {
- return elgg_echo($desc);
- } else {
- return $desc;
- }
+ public function getDescription() {
+ return $this->parser->getAttribute('description');
}
/**
* Return the short description
*
- * @param bool $elgg_echo Run the blurb through elgg_echo.
* @return string
*/
- public function getBlurb($elgg_echo = true) {
+ public function getBlurb() {
$blurb = $this->parser->getAttribute('blurb');
- if ($blurb) {
- if ($elgg_echo) {
- $blurb = elgg_echo($blurb);
- }
- } else {
+ if (!$blurb) {
$blurb = elgg_get_excerpt($this->getDescription());
}
@@ -348,10 +331,9 @@ class ElggPluginManifest {
/**
* Return the screenshots listed.
*
- * @param bool $elgg_echo Run the screenshot's description through elgg_echo.
* @return array
*/
- public function getScreenshots($elgg_echo = true) {
+ public function getScreenshots() {
$ss = $this->parser->getAttribute('screenshot');
if (!$ss) {
@@ -360,13 +342,7 @@ class ElggPluginManifest {
$normalized = array();
foreach ($ss as $s) {
- $normalized_s = $this->buildStruct($this->screenshotStruct, $s);
-
- if ($elgg_echo) {
- $normalized_s['description'] = elgg_echo($normalized_s['description']);
- }
-
- $normalized[] = $normalized_s;
+ $normalized[] = $this->buildStruct($this->screenshotStruct, $s);
}
return $normalized;
diff --git a/engine/classes/ElggPluginPackage.php b/engine/classes/ElggPluginPackage.php
index 977b72d76..145f71fcd 100644
--- a/engine/classes/ElggPluginPackage.php
+++ b/engine/classes/ElggPluginPackage.php
@@ -334,7 +334,11 @@ class ElggPluginPackage {
// first, check if any active plugin conflicts with us.
foreach ($enabled_plugins as $plugin) {
- $temp_conflicts = $plugin->getManifest()->getConflicts();
+ $temp_conflicts = array();
+ $temp_manifest = $plugin->getManifest();
+ if ($temp_manifest instanceof ElggPluginManifest) {
+ $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);
@@ -343,6 +347,7 @@ class ElggPluginPackage {
$conflict['name'] = $plugin->getManifest()->getName();
if (!$full_report && !$result['status']) {
+ $this->errorMsg = "Conflicts with plugin \"{$plugin->getManifest()->getName()}\".";
return $result['status'];
} else {
$report[] = array(
@@ -395,6 +400,7 @@ class ElggPluginPackage {
// unless we're doing a full report, break as soon as we fail.
if (!$full_report && !$result['status']) {
+ $this->errorMsg = "Missing dependencies.";
return $result['status'];
} else {
// build report element and comment
diff --git a/engine/classes/ElggPriorityList.php b/engine/classes/ElggPriorityList.php
new file mode 100644
index 000000000..aa33831ff
--- /dev/null
+++ b/engine/classes/ElggPriorityList.php
@@ -0,0 +1,358 @@
+<?php
+/**
+ * Iterate over elements in a specific priority.
+ *
+ * $pl = new ElggPriorityList();
+ * $pl->add('Element 0');
+ * $pl->add('Element 10', 10);
+ * $pl->add('Element -10', -10);
+ *
+ * foreach ($pl as $priority => $element) {
+ * var_dump("$priority => $element");
+ * }
+ *
+ * Yields:
+ * -10 => Element -10
+ * 0 => Element 0
+ * 10 => Element 10
+ *
+ * Collisions on priority are handled by inserting the element at or as close to the
+ * requested priority as possible:
+ *
+ * $pl = new ElggPriorityList();
+ * $pl->add('Element 5', 5);
+ * $pl->add('Colliding element 5', 5);
+ * $pl->add('Another colliding element 5', 5);
+ *
+ * foreach ($pl as $priority => $element) {
+ * var_dump("$priority => $element");
+ * }
+ *
+ * Yields:
+ * 5 => 'Element 5',
+ * 6 => 'Colliding element 5',
+ * 7 => 'Another colliding element 5'
+ *
+ * You can do priority lookups by element:
+ *
+ * $pl = new ElggPriorityList();
+ * $pl->add('Element 0');
+ * $pl->add('Element -5', -5);
+ * $pl->add('Element 10', 10);
+ * $pl->add('Element -10', -10);
+ *
+ * $priority = $pl->getPriority('Element -5');
+ *
+ * Or element lookups by priority.
+ * $element = $pl->getElement(-5);
+ *
+ * To remove elements, pass the element.
+ * $pl->remove('Element -10');
+ *
+ * To check if an element exists:
+ * $pl->contains('Element -5');
+ *
+ * To move an element:
+ * $pl->move('Element -5', -3);
+ *
+ * ElggPriorityList only tracks priority. No checking is done in ElggPriorityList for duplicates or
+ * updating. If you need to track this use objects and an external map:
+ *
+ * function elgg_register_something($id, $display_name, $location, $priority = 500) {
+ * // $id => $element.
+ * static $map = array();
+ * static $list;
+ *
+ * if (!$list) {
+ * $list = new ElggPriorityList();
+ * }
+ *
+ * // update if already registered.
+ * if (isset($map[$id])) {
+ * $element = $map[$id];
+ * // move it first because we have to pass the original element.
+ * if (!$list->move($element, $priority)) {
+ * return false;
+ * }
+ * $element->display_name = $display_name;
+ * $element->location = $location;
+ * } else {
+ * $element = new stdClass();
+ * $element->display_name = $display_name;
+ * $element->location = $location;
+ * if (!$list->add($element, $priority)) {
+ * return false;
+ * }
+ * $map[$id] = $element;
+ * }
+ *
+ * return true;
+ * }
+ *
+ * @package Elgg.Core
+ * @subpackage Helpers
+ */
+class ElggPriorityList
+ implements Iterator, Countable {
+
+ /**
+ * The list of elements
+ *
+ * @var array
+ */
+ private $elements = array();
+
+ /**
+ * Create a new priority list.
+ *
+ * @param array $elements An optional array of priorities => element
+ */
+ public function __construct(array $elements = array()) {
+ if ($elements) {
+ foreach ($elements as $priority => $element) {
+ $this->add($element, $priority);
+ }
+ }
+ }
+
+ /**
+ * Adds an element to the list.
+ *
+ * @warning This returns the priority at which the element was added, which can be 0. Use
+ * !== false to check for success.
+ *
+ * @param mixed $element The element to add to the list.
+ * @param mixed $priority Priority to add the element. In priority collisions, the original element
+ * maintains its priority and the new element is to the next available
+ * slot, taking into consideration all previously registered elements.
+ * Negative elements are accepted.
+ * @return int The priority of the added element.
+ */
+ public function add($element, $priority = null, $exact = false) {
+ if ($priority !== null && !is_numeric($priority)) {
+ return false;
+ } else {
+ $priority = $this->getNextPriority($priority);
+ }
+
+ $this->elements[$priority] = $element;
+ $this->sorted = false;
+ return $priority;
+ }
+
+ /**
+ * Removes an element from the list.
+ *
+ * @warning The element must have the same attributes / values. If using $strict, it must have
+ * the same types. array(10) will fail in strict against array('10') (str vs int).
+ *
+ * @param type $element
+ * @return bool
+ */
+ public function remove($element, $strict = false) {
+ $index = array_search($element, $this->elements, $strict);
+ if ($index !== false) {
+ unset($this->elements[$index]);
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Move an existing element to a new priority.
+ *
+ * @param mixed $current_priority
+ * @param int $new_priority
+ *
+ * @return int The new priority.
+ */
+ public function move($element, $new_priority, $strict = false) {
+ $new_priority = (int) $new_priority;
+
+ $current_priority = $this->getPriority($element, $strict);
+ if ($current_priority === false) {
+ return false;
+ }
+
+ if ($current_priority == $new_priority) {
+ return true;
+ }
+
+ // move the actual element so strict operations still work
+ $element = $this->getElement($current_priority);
+ unset($this->elements[$current_priority]);
+ return $this->add($element, $new_priority);
+ }
+
+ /**
+ * Returns the elements
+ *
+ * @return array
+ */
+ public function getElements() {
+ $this->sortIfUnsorted();
+ return $this->elements;
+ }
+
+ /**
+ * Sort the elements optionally by a callback function.
+ *
+ * If no user function is provided the elements are sorted by priority registered.
+ *
+ * The callback function should accept the array of elements as the first argument and should
+ * return a sorted array.
+ *
+ * This function can be called multiple times.
+ *
+ * @param type $callback
+ * @return bool
+ */
+ public function sort($callback = null) {
+ if (!$callback) {
+ ksort($this->elements, SORT_NUMERIC);
+ } else {
+ $sorted = call_user_func($callback, $this->elements);
+
+ if (!$sorted) {
+ return false;
+ }
+
+ $this->elements = $sorted;
+ }
+
+ $this->sorted = true;
+ return true;
+ }
+
+ /**
+ * Sort the elements if they haven't been sorted yet.
+ *
+ * @return bool
+ */
+ private function sortIfUnsorted() {
+ if (!$this->sorted) {
+ return $this->sort();
+ }
+ }
+
+ /**
+ * Returns the next priority available.
+ *
+ * @param int $near Make the priority as close to $near as possible.
+ * @return int
+ */
+ public function getNextPriority($near = 0) {
+ $near = (int) $near;
+
+ while (array_key_exists($near, $this->elements)) {
+ $near++;
+ }
+
+ return $near;
+ }
+
+ /**
+ * Returns the priority of an element if it exists in the list.
+ *
+ * @warning This can return 0 if the element's priority is 0.
+ *
+ * @param mixed $element The element to check for.
+ * @param bool $strict Use strict checking?
+ * @return mixed False if the element doesn't exists, the priority if it does.
+ */
+ public function getPriority($element, $strict = false) {
+ return array_search($element, $this->elements, $strict);
+ }
+
+ /**
+ * Returns the element at $priority.
+ *
+ * @param int $priority
+ * @return mixed The element or false on fail.
+ */
+ public function getElement($priority) {
+ return (isset($this->elements[$priority])) ? $this->elements[$priority] : false;
+ }
+
+ /**
+ * Returns if the list contains $element.
+ *
+ * @param mixed $element The element to check.
+ * @param bool $strict Use strict checking?
+ * @return bool
+ */
+ public function contains($element, $strict = false) {
+ return $this->getPriority($element, $strict) !== false;
+ }
+
+
+ /**********************
+ * Interface methods *
+ **********************/
+
+ /**
+ * Iterator
+ */
+
+ /**
+ * PHP Iterator Interface
+ *
+ * @see Iterator::rewind()
+ * @return void
+ */
+ public function rewind() {
+ $this->sortIfUnsorted();
+ return rewind($this->elements);
+ }
+
+ /**
+ * PHP Iterator Interface
+ *
+ * @see Iterator::current()
+ * @return mixed
+ */
+ public function current() {
+ $this->sortIfUnsorted();
+ return current($this->elements);
+ }
+
+ /**
+ * PHP Iterator Interface
+ *
+ * @see Iterator::key()
+ * @return int
+ */
+ public function key() {
+ $this->sortIfUnsorted();
+ return key($this->elements);
+ }
+
+ /**
+ * PHP Iterator Interface
+ *
+ * @see Iterator::next()
+ * @return mixed
+ */
+ public function next() {
+ $this->sortIfUnsorted();
+ return next($this->elements);
+ }
+
+ /**
+ * PHP Iterator Interface
+ *
+ * @see Iterator::valid()
+ * @return bool
+ */
+ public function valid() {
+ $this->sortIfUnsorted();
+ $key = key($this->elements);
+ return ($key !== NULL && $key !== FALSE);
+ }
+
+ // Countable
+ public function count() {
+ return count($this->elements);
+ }
+} \ No newline at end of file
diff --git a/engine/classes/ElggSite.php b/engine/classes/ElggSite.php
index e3b8b8f1a..40bfca060 100644
--- a/engine/classes/ElggSite.php
+++ b/engine/classes/ElggSite.php
@@ -410,8 +410,9 @@ class ElggSite extends ElggEntity {
'register',
'action/register',
'forgotpassword',
- 'action/user/requestnewpassword',
'resetpassword',
+ 'action/user/requestnewpassword',
+ 'action/user/passwordreset',
'upgrade\.php',
'xml-rpc\.php',
'mt/mt-xmlrpc\.cgi',