aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authordave <dave@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-05-27 10:22:41 +0000
committerdave <dave@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-05-27 10:22:41 +0000
commiteaf2ab7fcf4a915443d3890d98e1d4049e65be64 (patch)
tree18d3d0a78c7c8d1832cd7c6d97bf9b285857e5b5 /engine
parent4baed40f5e6288778670ccd2a37047aefba82faa (diff)
downloadelgg-eaf2ab7fcf4a915443d3890d98e1d4049e65be64.tar.gz
elgg-eaf2ab7fcf4a915443d3890d98e1d4049e65be64.tar.bz2
create a new social library in the engine. Moved string parsing for links to input.php and removed converting strings to tags from the shouts plugin and added them to the social library.
git-svn-id: https://code.elgg.org/elgg/trunk@723 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine')
-rw-r--r--engine/lib/input.php73
-rw-r--r--engine/lib/social.php103
2 files changed, 149 insertions, 27 deletions
diff --git a/engine/lib/input.php b/engine/lib/input.php
index 8cbea6986..9244c16f3 100644
--- a/engine/lib/input.php
+++ b/engine/lib/input.php
@@ -1,37 +1,37 @@
-<?php
- /**
- * Parameter input functions.
- * This file contains functions for getting input from get/post variables.
- *
- * @package Elgg
- * @subpackage Core
- * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
- * @author Marcus Povey <marcus@dushka.co.uk>
- * @copyright Curverider Ltd 2008
- * @link http://elgg.org/
- */
-
- /**
- * Get some input from variables passed on the GET or POST line.
- *
- * @param $variable string The variable we want to return.
- * @param $default mixed A default value for the variable if it is not found.
- */
- function get_input($variable, $default = "")
- {
-
+<?php
+ /**
+ * Parameter input functions.
+ * This file contains functions for getting input from get/post variables.
+ *
+ * @package Elgg
+ * @subpackage Core
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Marcus Povey <marcus@dushka.co.uk>
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.org/
+ */
+
+ /**
+ * Get some input from variables passed on the GET or POST line.
+ *
+ * @param $variable string The variable we want to return.
+ * @param $default mixed A default value for the variable if it is not found.
+ */
+ function get_input($variable, $default = "")
+ {
+
if (isset($_REQUEST[$variable])) {
- $value = $_REQUEST[$variable];
+ $value = $_REQUEST[$variable];
return trim($_REQUEST[$variable]);
}
global $CONFIG;
if (isset($CONFIG->input[$variable]))
- return $CONFIG->input[$variable];
-
+ return $CONFIG->input[$variable];
+
return $default;
-
+
}
/**
@@ -49,5 +49,24 @@
}
-
+ /**
+ * This is a function to make url clickable
+ * @param string text
+ * @return string text
+ **/
+
+ function parse_urls($text) {
+
+ if (preg_match_all('/(?<!href=["\'])((ht|f)tps?:\/\/[^\s\r\n\t<>"\'\!\(\)]+)/ie', $text, $urls)) {
+
+ foreach (array_unique($urls[1]) AS $url){
+ $urltext = $url;
+ $text = str_replace($url, '<a href="'. $url .'" style="text-decoration:underline;">view link</a>', $text);
+ }
+ }
+
+ return $text;
+ }
+
+
?> \ No newline at end of file
diff --git a/engine/lib/social.php b/engine/lib/social.php
new file mode 100644
index 000000000..bc66c0466
--- /dev/null
+++ b/engine/lib/social.php
@@ -0,0 +1,103 @@
+<?php
+
+ /**
+ * Elgg Social
+ * Functions and objects which provide powerful social aspects within Elgg
+ *
+ * @package Elgg
+ * @subpackage Core
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Curverider
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.org/
+
+ /**
+ * Filters a string into an array of significant words
+ *
+ * @param string $string
+ * @return array
+ */
+ function filter_string(string $string) {
+
+ // Convert it to lower and trim
+ $string = strtolower($string);
+ $string = trim($string);
+
+ // Remove links and email addresses
+ // match protocol://address/path/file.extension?some=variable&another=asf%
+ $string = preg_replace("/\s([a-zA-Z]+:\/\/[a-z][a-z0-9\_\.\-]*[a-z]{2,6}[a-zA-Z0-9\/\*\-\?\&\%\=]*)([\s|\.|\,])/iu"," ", $string);
+ // match www.something.domain/path/file.extension?some=variable&another=asf%
+ $string = preg_replace("/\s(www\.[a-z][a-z0-9\_\.\-]*[a-z]{2,6}[a-zA-Z0-9\/\*\-\?\&\%\=]*)([\s|\.|\,])/iu"," ", $string);
+ // match name@address
+ $string = preg_replace("/\s([a-zA-Z][a-zA-Z0-9\_\.\-]*[a-zA-Z]*\@[a-zA-Z][a-zA-Z0-9\_\.\-]*[a-zA-Z]{2,6})([\s|\.|\,])/iu"," ", $string);
+
+ // Sanitise the string; remove unwanted characters
+ $string = preg_replace('/\W/ui', ' ', $string);
+
+ // Explode it into an array
+ $terms = explode(' ',$string);
+
+ // Remove any blacklist terms
+ $terms = array_filter($terms, 'remove_blacklist');
+
+ return $terms;
+
+ }
+
+ /**
+ * Returns true if the word in $input is considered significant
+ *
+ * @param string $input
+ * @return true|false
+ */
+ function remove_blacklist($input) {
+
+ global $CONFIG;
+
+ if (strlen($input) < 3 || in_array($input,$CONFIG->wordblacklist))
+ return false;
+
+ return true;
+
+ }
+
+ // Set the shout words blacklist, these do not become tags when the string is converted
+ GLOBAL $CONFIG;
+ $CONFIG->wordblacklist = array(
+ 'and',
+ 'the',
+ 'then',
+ 'but',
+ 'she',
+ 'his',
+ 'her',
+ 'him',
+ 'one',
+ 'not',
+ 'also',
+ 'about',
+ 'now',
+ 'hence',
+ 'however',
+ 'still',
+ 'likewise',
+ 'otherwise',
+ 'therefore',
+ 'conversely',
+ 'rather',
+ 'consequently',
+ 'furthermore',
+ 'nevertheless',
+ 'instead',
+ 'meanwhile',
+ 'accordingly',
+ 'this',
+ 'seems',
+ 'what',
+ 'whom',
+ 'whose',
+ 'whoever',
+ 'whomever',
+ );
+
+?> \ No newline at end of file