aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/social.php
blob: 80dbafee4327b9fc38c577e0f4cd9ffbd3fbd7be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?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-2009
	 * @link http://elgg.org/
	 
	 /**
      * Filters a string into an array of significant words
      *
      * @param string $string
      * @return array
      */
        function filter_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 (!is_array($CONFIG->wordblacklist))
        		return $input;
        	
        	if (strlen($input) < 3 || in_array($input,$CONFIG->wordblacklist))
        	   return false;
        	
            return true;        	
        	
        }
        

        /**
         * Initialise.
         *
         * Sets a blacklist of words in the current language. This is a comma separated list in word:blacklist.
         */       
        function social_init() {
            global $CONFIG;
            
            	$CONFIG->wordblacklist = array();
            	
            	$list = explode(',', elgg_echo('word:blacklist'));
            	if ($list)
            	{
            		foreach ($list as $l)
            			$CONFIG->wordblacklist[] = trim($l);
            	}
            	else	
            	{	            
            		// Fallback - shouldn't happen
					$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',
			        );
            	}
        }

        register_elgg_event_handler("init","system","social_init");
	 
?>