diff options
Diffstat (limited to 'engine')
-rw-r--r-- | engine/lib/elgglib.php | 49 | ||||
-rw-r--r-- | engine/lib/entities.php | 2 | ||||
-rw-r--r-- | engine/lib/filestore.php | 170 | ||||
-rw-r--r-- | engine/lib/metadata.php | 11 | ||||
-rw-r--r-- | engine/lib/output.php | 24 | ||||
-rw-r--r-- | engine/lib/version.php | 3 | ||||
-rw-r--r-- | engine/lib/views.php | 30 |
7 files changed, 184 insertions, 105 deletions
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 3d08227e4..1d52c0534 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -1624,7 +1624,7 @@ function is_not_null($string) { 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]; @@ -1632,7 +1632,7 @@ function elgg_normalise_plural_options_array($options, $singulars) { $options[$plural] = array($options[$singular]); } } - + unset($options[$singular]); } @@ -2167,6 +2167,12 @@ function __elgg_shutdown_hook() { 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'); @@ -2181,44 +2187,12 @@ function elgg_walled_garden_index() { $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_api_test($hook, $type, $value, $params) { @@ -2420,7 +2394,7 @@ function elgg_get_array_value($key, array $array, $default = NULL) { */ 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]); @@ -2428,7 +2402,7 @@ function elgg_sort_3d_array_by_value(&$array, $element, $sort_order = SORT_ASC, $sort[] = NULL; } }; - + return array_multisort($sort, $sort_order, $sort_type, $array); } @@ -2454,7 +2428,6 @@ define('REFERRER', -1); 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); diff --git a/engine/lib/entities.php b/engine/lib/entities.php index c34aea550..b684ae822 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -300,7 +300,7 @@ abstract class ElggEntity implements * @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) { diff --git a/engine/lib/filestore.php b/engine/lib/filestore.php index d131154c6..4e92fee21 100644 --- a/engine/lib/filestore.php +++ b/engine/lib/filestore.php @@ -663,17 +663,20 @@ class ElggFile extends ElggObject { } } - // 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 } @@ -756,7 +759,6 @@ function get_resized_image_from_uploaded_file($input_name, $maxwidth, $maxheight 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; } @@ -786,11 +788,9 @@ function get_resized_image_from_existing_file($input_name, $maxwidth, $maxheight 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', @@ -805,6 +805,87 @@ function get_resized_image_from_existing_file($input_name, $maxwidth, $maxheight 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) { @@ -813,12 +894,12 @@ function get_resized_image_from_existing_file($input_name, $maxwidth, $maxheight // 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 @@ -826,7 +907,7 @@ function get_resized_image_from_existing_file($input_name, $maxwidth, $maxheight // 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; } @@ -834,7 +915,7 @@ function get_resized_image_from_existing_file($input_name, $maxwidth, $maxheight $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) { @@ -844,20 +925,19 @@ function get_resized_image_from_existing_file($input_name, $maxwidth, $maxheight $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 @@ -888,48 +968,22 @@ function get_resized_image_from_existing_file($input_name, $maxwidth, $maxheight } 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; } diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php index 3ad774ad2..4d489178f 100644 --- a/engine/lib/metadata.php +++ b/engine/lib/metadata.php @@ -183,9 +183,12 @@ function remove_metadata($entity_guid, $name, $value = "") { /** * 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 @@ -343,8 +346,12 @@ function update_metadata($id, $name, $value, $value_type, $owner_guid, $access_i /** * 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 diff --git a/engine/lib/output.php b/engine/lib/output.php index 3280517b0..3d08f2a28 100644 --- a/engine/lib/output.php +++ b/engine/lib/output.php @@ -97,7 +97,7 @@ function autop($pee, $br = 1) { * @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); @@ -148,12 +148,19 @@ function friendly_title($title) { /** * 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); @@ -176,14 +183,21 @@ function friendly_time($time) { } /** - * 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; diff --git a/engine/lib/version.php b/engine/lib/version.php index 5322e5afa..011fdaa7b 100644 --- a/engine/lib/version.php +++ b/engine/lib/version.php @@ -103,6 +103,9 @@ function version_upgrade_check() { * */ 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. diff --git a/engine/lib/views.php b/engine/lib/views.php index d946e159d..68ddf49e1 100644 --- a/engine/lib/views.php +++ b/engine/lib/views.php @@ -1062,4 +1062,32 @@ function elgg_is_valid_view_type($view_type) { 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); |