*/
-// block non-admin users
+// block non-admin users - require since this action is not registered
admin_gatekeeper();
// Get the user
$guid = get_input('guid');
$obj = get_entity($guid);
+$name = $obj->name;
+$username = $obj->username;
+
if (($obj instanceof ElggUser) && ($obj->canEdit())) {
if ($obj->delete()) {
- system_message(elgg_echo('admin:user:delete:yes'));
+ system_message(sprintf(elgg_echo('admin:user:delete:yes'), $name));
} else {
register_error(elgg_echo('admin:user:delete:no'));
}
register_error(elgg_echo('admin:user:delete:no'));
}
-forward($_SERVER['HTTP_REFERER']);
-exit;
+// forward to user administration if on a user's page as it no longer exists
+$forward = REFERER;
+if (strpos($_SERVER['HTTP_REFERER'], $username) != FALSE) {
+ $forward = "pg/admin/user/";
+}
+
+forward($forward);
function elgg_normalise_plural_options_array($options, $singulars) {
foreach ($singulars as $singular) {
$plural = $singular . 's';
-
+
if (array_key_exists($singular, $options)) {
if ($options[$singular] === ELGG_ENTITIES_ANY_VALUE) {
$options[$plural] = $options[$singular];
$options[$plural] = array($options[$singular]);
}
}
-
+
unset($options[$singular]);
}
function elgg_init() {
global $CONFIG;
+ // Actions
+ register_action('comments/add');
+ register_action('comments/delete');
+ register_action('likes/add');
+ register_action('likes/delete');
+
// Page handler for JS
register_page_handler('js','js_page_handler');
$login = elgg_view('account/forms/login_walled_garden');
page_draw('', $login, 'page_shells/walled_garden');
-
+
// @hack Index must exit to keep plugins from continuing to extend
exit;
}
-/**
- * Boot Elgg
- * @return unknown_type
- */
-function elgg_boot() {
- global $CONFIG;
-
- // Actions
- register_action('comments/add');
- register_action('comments/delete');
- register_action('likes/add');
- register_action('likes/delete');
-
- elgg_view_register_simplecache('css');
- elgg_view_register_simplecache('js/friendsPickerv1');
- elgg_view_register_simplecache('js/initialise_elgg');
-
- // discover the built-in view types
- // @todo cache this
- $view_path = $CONFIG->viewpath;
- $CONFIG->view_types = array();
-
- $views = scandir($view_path);
-
- foreach ($views as $view) {
- if ('.' !== substr($view, 0, 1) && is_dir($view_path . $view)) {
- $CONFIG->view_types[] = $view;
- }
- }
-
-}
-
/**
* Runs unit tests for the API.
*/
*/
function elgg_sort_3d_array_by_value(&$array, $element, $sort_order = SORT_ASC, $sort_type = SORT_LOCALE_STRING) {
$sort = array();
-
+
foreach ($array as $k => $v) {
if (isset($v[$element])) {
$sort[] = strtolower($v[$element]);
$sort[] = NULL;
}
};
-
+
return array_multisort($sort, $sort_order, $sort_type, $array);
}
define('REFERER', -1);
register_elgg_event_handler('init', 'system', 'elgg_init');
-register_elgg_event_handler('boot', 'system', 'elgg_boot', 1000);
register_plugin_hook('unit_test', 'system', 'elgg_api_test');
register_elgg_event_handler('init', 'system', 'add_custom_menu_items', 1000);
* @param string $name Name of the metadata
* @param mixed $value Value of the metadata
* @param string $value_type Types supported: integer and string. Will auto-identify if not set
- * @param bool $multiple
+ * @param bool $multiple (does not support associative arrays)
* @return bool
*/
public function setMetaData($name, $value, $value_type = "", $multiple = false) {
}
}
- // If parameters loaded then create new filestore
- if (count($parameters)!=0) {
- // Create new filestore object
- if ((!isset($parameters['filestore'])) || (!class_exists($parameters['filestore']))) {
- throw new ClassNotFoundException(elgg_echo('ClassNotFoundException:NotFoundNotSavedWithFile'));
+ if (isset($parameters['filestore'])) {
+ if (!class_exists($parameters['filestore'])) {
+ $msg = sprintf(elgg_echo('ClassNotFoundException:NotFoundNotSavedWithFile'),
+ $parameters['filestore'],
+ $this->guid);
+ throw new ClassNotFoundException($msg);
}
+ // Create new filestore object
$this->filestore = new $parameters['filestore']();
- // Set parameters
$this->filestore->setParameters($parameters);
+ } else {
+ // @todo - should we log error if filestore not set
}
if (isset($_FILES[$input_name]) && $_FILES[$input_name]['error'] == 0) {
return get_resized_image_from_existing_file($_FILES[$input_name]['tmp_name'], $maxwidth, $maxheight, $square);
}
-
return false;
}
return FALSE;
}
- // Get width and height
$width = $imgsizearray[0];
$height = $imgsizearray[1];
- // make sure we can read the image
$accepted_formats = array(
'image/jpeg' => 'jpeg',
'image/pjpeg' => 'jpeg',
return FALSE;
}
+ // get the parameters for resizing the image
+ $options = array(
+ 'maxwidth' => $maxwidth,
+ 'maxheight' => $maxheight,
+ 'square' => $square,
+ 'upscale' => $upscale,
+ 'x1' => $x1,
+ 'y1' => $y1,
+ 'x2' => $x2,
+ 'y2' => $y2,
+ );
+ $params = get_image_resize_parameters($width, $height, $options);
+ if ($params == FALSE) {
+ return FALSE;
+ }
+
+ // load original image
+ $original_image = $load_function($input_name);
+ if (!$original_image) {
+ return FALSE;
+ }
+
+ // allocate the new image
+ $new_image = imagecreatetruecolor($params['newwidth'], $params['newheight']);
+ if (!$new_image) {
+ return FALSE;
+ }
+
+ $rtn_code = imagecopyresampled( $new_image,
+ $original_image,
+ 0,
+ 0,
+ $params['xoffset'],
+ $params['yoffset'],
+ $params['newwidth'],
+ $params['newheight'],
+ $params['selectionwidth'],
+ $params['selectionheight']);
+ if (!$rtn_code) {
+ return FALSE;
+ }
+
+ // grab a compressed jpeg version of the image
+ ob_start();
+ imagejpeg($new_image, NULL, 90);
+ $jpeg = ob_get_clean();
+
+ imagedestroy($new_image);
+ imagedestroy($original_image);
+
+ return $jpeg;
+}
+
+/**
+ * Calculate the parameters for resizing an image
+ *
+ * @param int $width Width of the original image
+ * @param int $height Height of the original image
+ * @param array $options See $defaults for the options
+ * @return array or FALSE
+ * @since 1.7.2
+ */
+function get_image_resize_parameters($width, $height, $options) {
+
+ $defaults = array(
+ 'maxwidth' => 100,
+ 'maxheight' => 100,
+
+ 'square' => FALSE,
+ 'upscale' => FALSE,
+
+ 'x1' => 0,
+ 'y1' => 0,
+ 'x2' => 0,
+ 'y2' => 0,
+ );
+
+ $options = array_merge($defaults, $options);
+
+ extract($options);
+
// crop image first?
$crop = TRUE;
if ($x1 == 0 && $y1 == 0 && $x2 == 0 && $y2 == 0) {
// how large a section of the image has been selected
if ($crop) {
- $region_width = $x2 - $x1;
- $region_height = $y2 - $y1;
+ $selection_width = $x2 - $x1;
+ $selection_height = $y2 - $y1;
} else {
// everything selected if no crop parameters
- $region_width = $width;
- $region_height = $height;
+ $selection_width = $width;
+ $selection_height = $height;
}
// determine cropping offsets
// asking for a square image back
// detect case where someone is passing crop parameters that are not for a square
- if ($crop == TRUE && $region_width != $region_height) {
+ if ($crop == TRUE && $selection_width != $selection_height) {
return FALSE;
}
$new_width = $new_height = min($maxwidth, $maxheight);
// find largest square that fits within the selected region
- $region_width = $region_height = min($region_width, $region_height);
+ $selection_width = $selection_height = min($selection_width, $selection_height);
// set offsets for crop
if ($crop) {
$height = $width;
} else {
// place square region in the center
- $widthoffset = floor(($width - $region_width) / 2);
- $heightoffset = floor(($height - $region_height) / 2);
+ $widthoffset = floor(($width - $selection_width) / 2);
+ $heightoffset = floor(($height - $selection_height) / 2);
}
} else {
// non-square new image
-
$new_width = $maxwidth;
$new_height = $maxwidth;
// maintain aspect ratio of original image/crop
- if (($region_height / (float)$new_height) > ($region_width / (float)$new_width)) {
- $new_width = floor($new_height * $region_width / (float)$region_height);
+ if (($selection_height / (float)$new_height) > ($selection_width / (float)$new_width)) {
+ $new_width = floor($new_height * $selection_width / (float)$selection_height);
} else {
- $new_height = floor($new_width * $region_height / (float)$region_width);
+ $new_height = floor($new_width * $selection_height / (float)$selection_width);
}
// by default, use entire image
} elseif ($width < $new_width) {
$ratio = $new_height / $height;
}
- $region_height = $height;
- $region_width = $width;
+ $selection_height = $height;
+ $selection_width = $width;
$new_height = floor($height * $ratio);
$new_width = floor($width * $ratio);
}
- // load original image
- $orig_image = $load_function($input_name);
- if (!$orig_image) {
- return FALSE;
- }
-
- // allocate the new image
- $newimage = imagecreatetruecolor($new_width, $new_height);
- if (!$newimage) {
- return FALSE;
- }
-
- // create the new image
- $rtn_code = imagecopyresampled( $newimage,
- $orig_image,
- 0,
- 0,
- $widthoffset,
- $heightoffset,
- $new_width,
- $new_height,
- $region_width,
- $region_height );
- if (!$rtn_code) {
- return FALSE;
- }
-
- // grab contents for return
- ob_start();
- imagejpeg($newimage, null, 90);
- $jpeg = ob_get_clean();
-
- imagedestroy($newimage);
- imagedestroy($orig_image);
+ $params = array(
+ 'newwidth' => $new_width,
+ 'newheight' => $new_height,
+ 'selectionwidth' => $selection_width,
+ 'selectionheight' => $selection_height,
+ 'xoffset' => $widthoffset,
+ 'yoffset' => $heightoffset,
+ );
- return $jpeg;
+ return $params;
}
/**
* Create a new metadata object, or update an existing one.
*
+ * Metadata can be an array by setting allow_multiple to TRUE, but it is an
+ * indexed array with no control over the indexing.
+ *
* @param int $entity_guid The entity to attach the metadata to
* @param string $name Name of the metadata
- * @param string $value Value of the metadata (cannot be associative array)
+ * @param string $value Value of the metadata
* @param string $value_type 'text', 'integer', or '' for automatic detection
* @param int $owner_guid GUID of entity that owns the metadata
* @param int $access_id Default is ACCESS_PRIVATE
/**
* This function creates metadata from an associative array of "key => value" pairs.
*
+ * To achieve an array for a single key, pass in the same key multiple times with
+ * allow_multiple set to TRUE. This creates an indexed array. It does not support
+ * associative arrays and there is no guarantee on the ordering in the array.
+ *
* @param int $entity_guid The entity to attach the metadata to
- * @param string $name_and_values Associative array
+ * @param string $name_and_values Associative array - a value can be a string, number, bool
* @param string $value_type 'text', 'integer', or '' for automatic detection
* @param int $owner_guid GUID of entity that owns the metadata
* @param int $access_id Default is ACCESS_PRIVATE
* @return string
* @since 1.7.2
*/
-function elgg_make_excerpt($text, $num_chars = 250) {
+function elgg_get_excerpt($text, $num_chars = 250) {
$text = trim(elgg_strip_tags($text));
$string_length = elgg_strlen($text);
/**
* When given a title, returns a version suitable for inclusion in a URL
*
- * @todo add plugin hook so that developers can provide their own friendly title
* @param string $title The title
* @return string The optimised title
* @since 1.7.2
*/
function elgg_get_friendly_title($title) {
+
+ // return a URL friendly title to short circuit normal title formatting
+ $params = array('title' => $title);
+ $result = trigger_plugin_hook('format', 'friendly:title', $params, NULL);
+ if ($result) {
+ return $result;
+ }
+
//$title = iconv('UTF-8', 'ASCII//TRANSLIT', $title);
$title = preg_replace("/[^\w ]/","",$title);
$title = str_replace(" ","-",$title);
}
/**
- * Displays a UNIX timestamp in a friendly way (eg "less than a minute ago")
+ * Formats a UNIX timestamp in a friendly way (eg "less than a minute ago")
*
- * @todo add plugin hook so that developers can provide their own friendly time
* @param int $time A UNIX epoch timestamp
- * @return string The friendly time
+ * @return string The friendly time string
* @since 1.7.2
*/
function elgg_get_friendly_time($time) {
+
+ // return a time string to short circuit normal time formatting
+ $params = array('time' => $time);
+ $result = trigger_plugin_hook('format', 'friendly:time', $params, NULL);
+ if ($result) {
+ return $result;
+ }
+
$diff = time() - (int)$time;
$minute = 60;
*
*/
function version_upgrade() {
+ // It's possible large upgrades could exceed the max execution time.
+ set_time_limit(0);
+
$dbversion = (int) datalist_get('version');
// No version number? Oh snap...this is an upgrade from a clean installation < 1.7.
global $CONFIG;
return in_array($view_type, $CONFIG->view_types);
-}
\ No newline at end of file
+}
+
+
+/**
+ * Initialize viewtypes on system boot event
+ * This ensures simplecache is cleared during upgrades. See #2252
+ */
+function elgg_views_boot() {
+ global $CONFIG;
+
+ elgg_view_register_simplecache('css');
+ elgg_view_register_simplecache('js/friendsPickerv1');
+ elgg_view_register_simplecache('js/initialise_elgg');
+
+ // discover the built-in view types
+ // @todo cache this
+ $view_path = $CONFIG->viewpath;
+ $CONFIG->view_types = array();
+
+ $views = scandir($view_path);
+
+ foreach ($views as $view) {
+ if ('.' !== substr($view, 0, 1) && is_dir($view_path . $view)) {
+ $CONFIG->view_types[] = $view;
+ }
+ }
+}
+
+register_elgg_event_handler('boot', 'system', 'elgg_views_boot', 1000);
# License http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
# Link http://elgg.org/
-<IfModule !mod_rewrite.c>
- # ugly ugly hack to detect missing mod_rewrite
- # RedirectMatch must be to an absolute destination, so forces 500 error...
- ErrorDocument 500 "Elgg error: Apache does not have mod_rewrite loaded. Please check your Apache setup."
- RedirectMatch 302 .* index.php
-</IfModule>
-
<Files "htaccess_dist">
order allow,deny
deny from all
ExpiresDefault "access plus 10 years"
</IfModule>
-# php 4, apache 1.x
-<IfModule mod_php4.c>
- ErrorDocument 500 "Elgg error: Elgg does not support PHP 4."
- RedirectMatch 302 .* index.php
-</IfModule>
-
-# php 4, apache 2
-<IfModule sapi_apache2.c>
- ErrorDocument 500 "Elgg error: Elgg does not support PHP 4."
- RedirectMatch 302 .* index.php
-</IfModule>
-
# php 5, apache 1 and 2
<IfModule mod_php5.c>
# default memory limit to 64Mb
'InvalidParameterException:MissingOwner' => "File %s (file guid:%d) (owner guid:%d) is missing an owner!",
'IOException:CouldNotMake' => "Could not make %s",
'IOException:MissingFileName' => "You must specify a name before opening a file.",
- 'ClassNotFoundException:NotFoundNotSavedWithFile' => "Filestore not found or class not saved with file!",
+ 'ClassNotFoundException:NotFoundNotSavedWithFile' => "Unable to load filestore class %s for file %u",
'NotificationException:NoNotificationMethod' => "No notification method specified.",
'NotificationException:NoHandlerFound' => "No handler found for '%s' or it was not callable.",
'NotificationException:ErrorNotifyingGuid' => "There was an error while notifying %d",
'admin:user:unban:no' => "Can not unban user",
'admin:user:unban:yes' => "User un-banned.",
'admin:user:delete:no' => "Can not delete user",
- 'admin:user:delete:yes' => "User deleted",
+ 'admin:user:delete:yes' => "The user %s has been deleted",
'admin:user:resetpassword:yes' => "Password reset, user notified.",
'admin:user:resetpassword:no' => "Password could not be reset.",
$blog->access_id = ACCESS_PRIVATE;
$blog->title = $title;
$blog->description = $description;
- $blog->excerpt = elgg_make_excerpt($excerpt);
+ $blog->excerpt = elgg_get_excerpt($excerpt);
// must be present or doesn't show up when metadata sorting.
$blog->publish_date = time();
$blog = get_entity($blog_guid);
if (elgg_instanceof($blog, 'object', 'blog') && $blog->canEdit()) {
+ $container = get_entity($blog->container_guid);
if ($blog->delete()) {
system_message(elgg_echo('blog:message:deleted_post'));
+ forward("pg/blog/$container->username/read/");
} else {
register_error(elgg_echo('blog:error:cannot_delete_post'));
}
case 'excerpt':
if ($value) {
- $value = elgg_make_excerpt($value);
+ $value = elgg_get_excerpt($value);
} else {
- $value = elgg_make_excerpt($values['description']);
+ $value = elgg_get_excerpt($values['description']);
}
$values[$name] = $value;
break;
<?php
/**
* Elgg bookmarks delete action
- *
+ *
* @package ElggBookmarks
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
* @author Curverider <info@elgg.com>
$guid = get_input('bookmark_guid',0);
if ($entity = get_entity($guid)) {
if ($entity->canEdit()) {
+ $container = get_entity($entity->container_guid);
if ($entity->delete()) {
system_message(elgg_echo("bookmarks:delete:success"));
- forward($_SERVER['HTTP_REFERER']);
+ forward("pg/bookmarks/$container->username/");
}
}
}
-
+
register_error(elgg_echo("bookmarks:delete:failed"));
forward($_SERVER['HTTP_REFERER']);
\ No newline at end of file
// different entity types have different title attribute names.
$title = isset($item->name) ? $item->name : $item->title;
// don't let it be too long
-$title = elgg_make_excerpt($title);
+$title = elgg_get_excerpt($title);
// @todo you can disable plugins that are required by other plugins
// (embed requires ecml) so fallback to a hard-coded check to see if ecml is enabled.
// different entity types have different title attribute names.
$title = isset($item->name) ? $item->name : $item->title;
// don't let it be too long
-$title = elgg_make_excerpt($title);
+$title = elgg_get_excerpt($title);
// @todo you can disable plugins that are required by other plugins
// (embed requires ecml) so fallback to a hard-coded check to see if ecml is enabled.
}
- forward("pg/file/" . $_SESSION['user']->username);
+ forward("pg/file/$container->username/");
?>
\ No newline at end of file
$string .= elgg_view('likes/forms/link', array('entity' => $object));
$string .= "</span>";
$string .= "<div class=\"river_content_display\">";
- $string .= elgg_make_excerpt($contents, 200);
+ $string .= elgg_get_excerpt($contents, 200);
$string .= "</div>";
echo $string;
}
$string .= "</span>";
$string .= "<div class=\"river_content_display\">";
- $string .= elgg_make_excerpt($contents, 200);
+ $string .= elgg_get_excerpt($contents, 200);
$string .= "</div>";
echo $string;
\ No newline at end of file
if ($page->canEdit()) {
+ $container = get_entity($page->container_guid);
+
// Bring all child elements forward
$parent = $page->parent_guid;
if ($children = elgg_get_entities_from_metadata(array('metadata_name' => 'parent_guid', 'metadata_value' => $page->getGUID()))) {
if ($parent) {
if ($parent = get_entity($parent)) {
forward($parent->getURL());
- exit;
}
}
- forward('pg/pages/owned/' . $_SESSION['user']->username);
- exit;
+ forward("pg/pages/owned/$container->username/");
}
}
$string .= elgg_echo("pages:river:create") . " <a href=\"" . $object->getURL() . "\">" . $object->title . "</a> <span class='entity_subtext'>". elgg_view_friendly_time($object->time_created) ."</span> <a class='river_comment_form_button link'>Comment</a>";
$string .= elgg_view('likes/forms/link', array('entity' => $object));
$string .= "<div class=\"river_content_display\">";
-$string .= elgg_make_excerpt($contents, 200);
+$string .= elgg_get_excerpt($contents, 200);
$string .= "</div>";
echo $string;
* @link http://elgg.com/
*/
-// Set admin user for user block
-set_page_owner($_SESSION['guid']);
-
$title = elgg_view_title(elgg_echo('reportedcontent'));
$reported = elgg_get_entities(array('types' => 'object', 'subtypes' => 'reported_content', 'limit' => 9999));
echo "</span>";
//truncate comment to 150 characters and strip tags
- $contents = elgg_make_excerpt($comment->value, 150);
+ $contents = elgg_get_excerpt($comment->value, 150);
echo "<div class='river_comment_contents'>";
echo "<a href=\"{$comment_owner_url}\">" . $comment_owner->name . '</a> <span class="twitter_anywhere">' . parse_urls($contents) . '</span>';
echo "</span>";
//truncate comment to 150 characters and strip tags
- $contents = elgg_make_excerpt($comment->value, 150);
+ $contents = elgg_get_excerpt($comment->value, 150);
echo "<div class='river_comment_contents'>";
echo "<a href=\"{$comment_owner_url}\">" . $comment_owner->name . '</a> <span class="elgg_excerpt">' . parse_urls($contents) . '</span>';
// ignores the label (because it's just the index) and sets the value ($option)
// as the label.
// Wow.
- $labelint = (int) $label;
-
- if ("{$label}" == "{$labelint}") {
+ // @todo deprecate in Elgg 1.8
+ if (is_integer($label)) {
$label = $option;
}
} else {
$selected = "checked = \"checked\"";
}
- $labelint = (int) $label;
- if ("{$label}" == "{$labelint}") {
+
+ // handle indexed array where label is not specified
+ // @todo deprecate in Elgg 1.8
+ if (is_integer($label)) {
$label = $option;
}
-
+
if (isset($vars['internalid'])) {
$id = "id=\"{$vars['internalid']}\"";
}
$selected = "checked = \"checked\"";
}
}
- $labelint = (int) $label;
- if ("{$label}" == "{$labelint}") {
+
+ // handle indexed array where label is not specified
+ // @todo deprecate in Elgg 1.8
+ if (is_integer($label)) {
$label = $option;
}