diff options
Diffstat (limited to 'engine/classes')
-rw-r--r-- | engine/classes/ElggAnnotation.php | 2 | ||||
-rw-r--r-- | engine/classes/ElggEntity.php | 23 | ||||
-rw-r--r-- | engine/classes/ElggFile.php | 41 | ||||
-rw-r--r-- | engine/classes/ElggMemcache.php | 13 | ||||
-rw-r--r-- | engine/classes/ElggMenuItem.php | 30 | ||||
-rw-r--r-- | engine/classes/ElggMetadata.php | 6 | ||||
-rw-r--r-- | engine/classes/ElggPlugin.php | 44 | ||||
-rw-r--r-- | engine/classes/ElggPluginManifest.php | 56 | ||||
-rw-r--r-- | engine/classes/ElggPluginManifestParser18.php | 3 | ||||
-rw-r--r-- | engine/classes/ElggPluginPackage.php | 6 | ||||
-rw-r--r-- | engine/classes/ElggPriorityList.php | 2 | ||||
-rw-r--r-- | engine/classes/ElggRelationship.php | 4 | ||||
-rw-r--r-- | engine/classes/ElggRiverItem.php | 8 | ||||
-rw-r--r-- | engine/classes/ElggSite.php | 10 | ||||
-rw-r--r-- | engine/classes/Locatable.php | 2 |
15 files changed, 159 insertions, 91 deletions
diff --git a/engine/classes/ElggAnnotation.php b/engine/classes/ElggAnnotation.php index 78d29ee7f..511b5151f 100644 --- a/engine/classes/ElggAnnotation.php +++ b/engine/classes/ElggAnnotation.php @@ -78,7 +78,7 @@ class ElggAnnotation extends ElggExtender { * @return bool */ function delete() { - remove_from_river_by_annotation($this->id); + elgg_delete_river(array('annotation_id' => $this->id)); return elgg_delete_metastring_based_object_by_id($this->id, 'annotations'); } diff --git a/engine/classes/ElggEntity.php b/engine/classes/ElggEntity.php index 2fa0d7b02..fdf2a80ea 100644 --- a/engine/classes/ElggEntity.php +++ b/engine/classes/ElggEntity.php @@ -1179,16 +1179,16 @@ abstract class ElggEntity extends ElggData implements return $this->icon_override[$size]; } - $url = "_graphics/icons/default/$size.png"; - $url = elgg_normalize_url($url); - $type = $this->getType(); $params = array( 'entity' => $this, 'size' => $size, ); - $url = elgg_trigger_plugin_hook('entity:icon:url', $type, $params, $url); + $url = elgg_trigger_plugin_hook('entity:icon:url', $type, $params, null); + if ($url == null) { + $url = "_graphics/icons/default/$size.png"; + } return elgg_normalize_url($url); } @@ -1434,10 +1434,11 @@ abstract class ElggEntity extends ElggData implements * * @param string $location String representation of the location * - * @return true + * @return bool */ public function setLocation($location) { - return $this->location = $location; + $this->location = $location; + return true; } /** @@ -1446,7 +1447,7 @@ abstract class ElggEntity extends ElggData implements * @param float $lat Latitude * @param float $long Longitude * - * @return true + * @return bool * @todo Unimplemented */ public function setLatLong($lat, $long) { @@ -1459,20 +1460,20 @@ abstract class ElggEntity extends ElggData implements /** * Return the entity's latitude. * - * @return int + * @return float * @todo Unimplemented */ public function getLatitude() { - return $this->get('geo:lat'); + return (float)$this->get('geo:lat'); } /** * Return the entity's longitude * - * @return Int + * @return float */ public function getLongitude() { - return $this->get('geo:long'); + return (float)$this->get('geo: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/ElggMemcache.php b/engine/classes/ElggMemcache.php index 7d19fb2c7..1fd3be0d1 100644 --- a/engine/classes/ElggMemcache.php +++ b/engine/classes/ElggMemcache.php @@ -147,15 +147,20 @@ class ElggMemcache extends ElggSharedMemoryCache { /** * Saves a name and value to the cache * - * @param string $key Name - * @param string $data Value + * @param string $key Name + * @param string $data Value + * @param integer $expires Expires (in seconds) * * @return bool */ - public function save($key, $data) { + public function save($key, $data, $expires = null) { $key = $this->_makeMemcacheKey($key); - $result = $this->memcache->set($key, $data, null, $this->expires); + if ($expires === null) { + $expires = $this->expires; + } + + $result = $this->memcache->set($key, $data, null, $expires); if (!$result) { elgg_log("MEMCACHE: FAILED TO SAVE $key", 'ERROR'); } diff --git a/engine/classes/ElggMenuItem.php b/engine/classes/ElggMenuItem.php index f7a6b5c65..62547134a 100644 --- a/engine/classes/ElggMenuItem.php +++ b/engine/classes/ElggMenuItem.php @@ -100,6 +100,9 @@ class ElggMenuItem { if (!isset($options['name']) || !isset($options['text'])) { return NULL; } + if (!isset($options['href'])) { + $options['href'] = ''; + } $item = new ElggMenuItem($options['name'], $options['text'], $options['href']); unset($options['name']); @@ -412,6 +415,7 @@ class ElggMenuItem { * * @param int $priority The smaller numbers mean higher priority (1 before 100) * @return void + * @deprecated */ public function setWeight($priority) { $this->data['priority'] = $priority; @@ -421,12 +425,32 @@ class ElggMenuItem { * Get the priority of the menu item * * @return int + * @deprecated */ public function getWeight() { return $this->data['priority']; } /** + * Set the priority of the menu item + * + * @param int $priority The smaller numbers mean higher priority (1 before 100) + * @return void + */ + public function setPriority($priority) { + $this->data['priority'] = $priority; + } + + /** + * Get the priority of the menu item + * + * @return int + */ + public function getPriority() { + return $this->data['priority']; + } + + /** * Set the section identifier * * @param string $section The identifier of the section @@ -543,12 +567,16 @@ 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(); } } + if (!isset($vars['rel']) && !isset($vars['is_trusted'])) { + $vars['is_trusted'] = true; + } + if ($this->confirm) { $vars['confirm'] = $this->confirm; return elgg_view('output/confirmlink', $vars); diff --git a/engine/classes/ElggMetadata.php b/engine/classes/ElggMetadata.php index ed3f8614f..32e7b32f1 100644 --- a/engine/classes/ElggMetadata.php +++ b/engine/classes/ElggMetadata.php @@ -45,11 +45,13 @@ class ElggMetadata extends ElggExtender { /** * Determines whether or not the user can edit this piece of metadata * + * @param int $user_guid The GUID of the user (defaults to currently logged in user) + * * @return true|false Depending on permissions */ - function canEdit() { + function canEdit($user_guid = 0) { if ($entity = get_entity($this->get('entity_guid'))) { - return $entity->canEditMetadata($this); + return $entity->canEditMetadata($this, $user_guid); } return false; } diff --git a/engine/classes/ElggPlugin.php b/engine/classes/ElggPlugin.php index d837431fc..c4d6ec034 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 @@ -249,8 +264,6 @@ class ElggPlugin extends ElggObject { /** * Returns a plugin setting * - * @todo These need to be namespaced - * * @param string $name The setting name * @return mixed */ @@ -303,7 +316,6 @@ class ElggPlugin extends ElggObject { * Set a plugin setting for the plugin * * @todo This will only work once the plugin has a GUID. - * @todo These need to be namespaced. * * @param string $name The name to set * @param string $value The value to set @@ -314,13 +326,6 @@ class ElggPlugin extends ElggObject { if (!$this->guid) { return false; } - // Hook to validate setting - $value = elgg_trigger_plugin_hook('setting', 'plugin', array( - 'plugin_id' => $this->pluginID, - 'plugin' => $this, - 'name' => $name, - 'value' => $value - ), $value); return $this->set($name, $value); } @@ -597,7 +602,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; @@ -882,7 +892,9 @@ class ElggPlugin extends ElggObject { } /** - * Save a value to private settings. + * Save a value as private setting or attribute. + * + * Attributes include title and description. * * @param string $name Name * @param mixed $value Value @@ -900,6 +912,14 @@ class ElggPlugin extends ElggObject { return true; } else { + // Hook to validate setting + $value = elgg_trigger_plugin_hook('setting', 'plugin', array( + 'plugin_id' => $this->pluginID, + 'plugin' => $this, + 'name' => $name, + 'value' => $value + ), $value); + return $this->setPrivateSetting($name, $value); } } diff --git a/engine/classes/ElggPluginManifest.php b/engine/classes/ElggPluginManifest.php index 0f3b1d7a8..eacc16455 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; @@ -579,24 +555,6 @@ class ElggPluginManifest { /** * Returns the admin interface to use. * - * @return string simple or advanced - */ - public function getAdminInterface() { - $interface = $this->parser->getAttribute('admin_interface'); - - switch ($interface) { - case 'simple': - case 'advanced': - return $interface; - - default: - return 'advanced'; - } - } - - /** - * Returns the admin interface to use. - * * @return bool */ public function getActivateOnInstall() { diff --git a/engine/classes/ElggPluginManifestParser18.php b/engine/classes/ElggPluginManifestParser18.php index db8b3dc6a..554e28c02 100644 --- a/engine/classes/ElggPluginManifestParser18.php +++ b/engine/classes/ElggPluginManifestParser18.php @@ -16,7 +16,7 @@ class ElggPluginManifestParser18 extends ElggPluginManifestParser { 'name', 'author', 'version', 'blurb', 'description', 'website', 'copyright', 'license', 'requires', 'suggests', 'screenshot', 'category', 'conflicts', 'provides', - 'admin_interface', 'activate_on_install' + 'activate_on_install' ); /** @@ -46,7 +46,6 @@ class ElggPluginManifestParser18 extends ElggPluginManifestParser { case 'website': case 'copyright': case 'license': - case 'admin_interface': case 'activate_on_install': $parsed[$element->name] = $element->content; break; diff --git a/engine/classes/ElggPluginPackage.php b/engine/classes/ElggPluginPackage.php index 02b985285..d240af477 100644 --- a/engine/classes/ElggPluginPackage.php +++ b/engine/classes/ElggPluginPackage.php @@ -33,7 +33,9 @@ class ElggPluginPackage { */ private $textFiles = array( 'README.txt', 'CHANGES.txt', - 'INSTALL.txt', 'COPYRIGHT.txt', 'LICENSE.txt' + 'INSTALL.txt', 'COPYRIGHT.txt', 'LICENSE.txt', + + 'README', 'README.md', 'README.markdown' ); /** @@ -347,6 +349,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( @@ -399,6 +402,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 index aa33831ff..8a3b836a8 100644 --- a/engine/classes/ElggPriorityList.php +++ b/engine/classes/ElggPriorityList.php @@ -303,7 +303,7 @@ class ElggPriorityList */ public function rewind() { $this->sortIfUnsorted(); - return rewind($this->elements); + return reset($this->elements); } /** diff --git a/engine/classes/ElggRelationship.php b/engine/classes/ElggRelationship.php index a0826689d..2d9a32cbd 100644 --- a/engine/classes/ElggRelationship.php +++ b/engine/classes/ElggRelationship.php @@ -10,9 +10,9 @@ class ElggRelationship extends ElggData implements { /** - * Construct a new site object, optionally from a given id value or row. + * Create a relationship object, optionally from a given id value or row. * - * @param mixed $id ElggRelationship id + * @param mixed $id ElggRelationship id, database row, or null for new relationship */ function __construct($id = null) { $this->initializeAttributes(); diff --git a/engine/classes/ElggRiverItem.php b/engine/classes/ElggRiverItem.php index cdb22239d..fcc8f9c85 100644 --- a/engine/classes/ElggRiverItem.php +++ b/engine/classes/ElggRiverItem.php @@ -28,8 +28,14 @@ class ElggRiverItem // throw exception } + // the casting is to support typed serialization like json + $int_types = array('id', 'subject_guid', 'object_guid', 'annotation_id', 'access_id', 'posted'); foreach ($object as $key => $value) { - $this->$key = $value; + if (in_array($key, $int_types)) { + $this->$key = (int)$value; + } else { + $this->$key = $value; + } } } diff --git a/engine/classes/ElggSite.php b/engine/classes/ElggSite.php index 40bfca060..16b80b9d3 100644 --- a/engine/classes/ElggSite.php +++ b/engine/classes/ElggSite.php @@ -190,18 +190,19 @@ class ElggSite extends ElggEntity { * @note You cannot disable the current site. * * @param string $reason Optional reason for disabling + * @param bool $recursive Recursively disable all contained entities? * * @return bool * @throws SecurityException */ - public function disable($reason = "") { + public function disable($reason = "", $recursive = true) { global $CONFIG; if ($CONFIG->site->getGUID() == $this->guid) { throw new SecurityException('SecurityException:deletedisablecurrentsite'); } - return parent::disable($reason); + return parent::disable($reason, $recursive); } /** @@ -225,7 +226,7 @@ class ElggSite extends ElggEntity { 'offset' => $offset, ); } - + $defaults = array( 'relationship' => 'member_of_site', 'relationship_guid' => $this->getGUID(), @@ -371,6 +372,7 @@ class ElggSite extends ElggEntity { elgg_register_plugin_hook_handler('index', 'system', 'elgg_walled_garden_index', 1); if (!$this->isPublicPage()) { + $_SESSION['last_forward_from'] = current_page_url(); register_error(elgg_echo('loggedinrequired')); forward(); } @@ -413,6 +415,8 @@ class ElggSite extends ElggEntity { 'resetpassword', 'action/user/requestnewpassword', 'action/user/passwordreset', + 'action/security/refreshtoken', + 'ajax/view/js/languages', 'upgrade\.php', 'xml-rpc\.php', 'mt/mt-xmlrpc\.cgi', diff --git a/engine/classes/Locatable.php b/engine/classes/Locatable.php index 0977dde99..7287d9798 100644 --- a/engine/classes/Locatable.php +++ b/engine/classes/Locatable.php @@ -13,7 +13,7 @@ interface Locatable { * @param string $location Textual representation of location * * @return bool - **/ + */ public function setLocation($location); /** |