From: rabuzarus <> Date: Fri, 5 Feb 2016 13:26:22 +0000 (+0100) Subject: rework autocomplete: polishing class and methods naming X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=30c375d238af79795937b8df046abe9f0ee63db9;p=friendica.git rework autocomplete: polishing class and methods naming --- diff --git a/include/DirSearch.php b/include/DirSearch.php new file mode 100644 index 0000000000..a6a0b59fcb --- /dev/null +++ b/include/DirSearch.php @@ -0,0 +1,58 @@ + 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND + ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)))) AND + (`gcontact`.`name` REGEXP '%s' OR `gcontact`.`nick` REGEXP '%s') $extra_sql + GROUP BY `gcontact`.`nurl` + ORDER BY `gcontact`.`updated` DESC ", + intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND), + dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora), + dbesc(escape_tags($search)), dbesc(escape_tags($search))); + return $results; + } + + } +} diff --git a/include/Smilies.php b/include/Smilies.php new file mode 100644 index 0000000000..193f3b555d --- /dev/null +++ b/include/Smilies.php @@ -0,0 +1,179 @@ + smilie shortcut + * 'icons' => icon in html + * + * @hook smilie ('texts' => smilies texts array, 'icons' => smilies html array) + */ + public static function get_list() { + + $texts = array( + '<3', + '</3', + '<\\3', + ':-)', + ';-)', + ':-(', + ':-P', + ':-p', + ':-"', + ':-"', + ':-x', + ':-X', + ':-D', + '8-|', + '8-O', + ':-O', + '\\o/', + 'o.O', + 'O.o', + 'o_O', + 'O_o', + ":'(", + ":-!", + ":-/", + ":-[", + "8-)", + ':beer', + ':homebrew', + ':coffee', + ':facepalm', + ':like', + ':dislike', + '~friendica', + 'red#', + 'red#matrix' + + ); + + $icons = array( + '<3', + '</3', + '<\\3', + ':-)', + ';-)', + ':-(', + ':-P', + ':-p', + ':-\', + ':-\', + ':-x', + ':-X', + ':-D', + '8-|', + '8-O', + ':-O', + '\\o/', + 'o.O', + 'O.o', + 'o_O', + 'O_o', + ':\'(', + ':-!', + ':-/', + ':-[', + '8-)', + ':beer', + ':homebrew', + ':coffee', + ':facepalm', + ':like', + ':dislike', + '~friendica ~friendica', + 'redredmatrix', + 'redredmatrix' + ); + + $params = array('texts' => $texts, 'icons' => $icons); + call_hooks('smilie', $params); + + return $params; + + } + + /** + * @brief Replaces text emoticons with graphical images + * + * It is expected that this function will be called using HTML text. + * We will escape text between HTML pre and code blocks from being + * processed. + * + * At a higher level, the bbcode [nosmile] tag can be used to prevent this + * function from being executed by the prepare_text() routine when preparing + * bbcode source for HTML display + * + * @param string $s + * @param boolean $sample + * + * @return string + */ + public static function replace($s, $sample = false) { + if(intval(get_config('system','no_smilies')) + || (local_user() && intval(get_pconfig(local_user(),'system','no_smilies')))) + return $s; + + $s = preg_replace_callback('/
(.*?)<\/pre>/ism','self::encode',$s);
+		$s = preg_replace_callback('/(.*?)<\/code>/ism','self::encode',$s);
+
+		$params = self::get_list();
+		$params['string'] = $s;
+
+		if($sample) {
+			$s = '
'; + for($x = 0; $x < count($params['texts']); $x ++) { + $s .= '
' . $params['texts'][$x] . '
' . $params['icons'][$x] . '
'; + } + } + else { + $params['string'] = preg_replace_callback('/<(3+)/','self::preg_heart',$params['string']); + $s = str_replace($params['texts'],$params['icons'],$params['string']); + } + + $s = preg_replace_callback('/
(.*?)<\/pre>/ism','self::decode',$s);
+		$s = preg_replace_callback('/(.*?)<\/code>/ism','self::decode',$s);
+
+		return $s;
+	}
+
+	private function encode($m) {
+		return(str_replace($m[1],base64url_encode($m[1]),$m[0]));
+	}
+
+	private function decode($m) {
+		return(str_replace($m[1],base64url_decode($m[1]),$m[0]));
+	}
+
+
+	/**
+	 * @brief expand <3333 to the correct number of hearts
+	 *
+	 * @param string $x
+	 * @return string
+	 */
+	private function preg_heart($x) {
+		if(strlen($x[1]) == 1)
+			return $x[0];
+		$t = '';
+		for($cnt = 0; $cnt < strlen($x[1]); $cnt ++)
+			$t .= '<3';
+		$r =  str_replace($x[0],$t,$x[0]);
+		return $r;
+	}
+
+}
diff --git a/include/acl_selectors.php b/include/acl_selectors.php
index 99848aa193..4a35fd0f08 100644
--- a/include/acl_selectors.php
+++ b/include/acl_selectors.php
@@ -6,7 +6,7 @@
 
 require_once("include/contact_selectors.php");
 require_once("include/contact_widgets.php");
-require_once("include/dir_fns.php");
+require_once("include/DirSearch.php");
 require_once("include/features.php");
 require_once("mod/proxy.php");
 
@@ -687,7 +687,7 @@ function navbar_complete(&$a) {
 		$search = substr($search,1);
 
 	if($localsearch) {
-		$x = dir::global_search_by_name($search, $mode);
+		$x = DirSearch::global_search_by_name($search, $mode);
 		return $x;
 	}
 
diff --git a/include/dir_fns.php b/include/dir_fns.php
deleted file mode 100644
index 5f018ed8cf..0000000000
--- a/include/dir_fns.php
+++ /dev/null
@@ -1,58 +0,0 @@
- 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND
-						((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)))) AND
-						(`gcontact`.`name` REGEXP '%s' OR `gcontact`.`nick` REGEXP '%s') $extra_sql
-							GROUP BY `gcontact`.`nurl`
-							ORDER BY `gcontact`.`updated` DESC ",
-						intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),
-						dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora),
-						dbesc(escape_tags($search)), dbesc(escape_tags($search)));
-			return $results;
-		}
-
-	}
-}
diff --git a/include/smilies.php b/include/smilies.php
deleted file mode 100644
index 7b3feefca8..0000000000
--- a/include/smilies.php
+++ /dev/null
@@ -1,179 +0,0 @@
- smilie shortcut
-	 *	'icons' => icon in html
-	 * 
-	 * @hook smilie ('texts' => smilies texts array, 'icons' => smilies html array)
-	 */
-	public static function list_smilies() {
-
-		$texts =  array(
-			'<3',
-			'</3',
-			'<\\3',
-			':-)',
-			';-)',
-			':-(',
-			':-P',
-			':-p',
-			':-"',
-			':-"',
-			':-x',
-			':-X',
-			':-D',
-			'8-|',
-			'8-O',
-			':-O',
-			'\\o/',
-			'o.O',
-			'O.o',
-			'o_O',
-			'O_o',
-			":'(",
-			":-!",
-			":-/",
-			":-[",
-			"8-)",
-			':beer',
-			':homebrew',
-			':coffee',
-			':facepalm',
-			':like',
-			':dislike',
-			'~friendica',
-			'red#',
-			'red#matrix'
-
-		);
-
-		$icons = array(
-			'<3',
-			'</3',
-			'<\\3',
-			':-)',
-			';-)',
-			':-(',
-			':-P',
-			':-p',
-			':-\',
-			':-\',
-			':-x',
-			':-X',
-			':-D',
-			'8-|',
-			'8-O',
-			':-O',
-			'\\o/',
-			'o.O',
-			'O.o',
-			'o_O',
-			'O_o',
-			':\'(',
-			':-!',
-			':-/',
-			':-[',
-			'8-)',
-			':beer',
-			':homebrew',
-			':coffee',
-			':facepalm',
-			':like',
-			':dislike',
-			'~friendica ~friendica',
-			'redredmatrix',
-			'redredmatrix'
-		);
-
-		$params = array('texts' => $texts, 'icons' => $icons);
-		call_hooks('smilie', $params);
-
-		return $params;
-
-	}
-
-	/**
-	 * @brief Replaces text emoticons with graphical images
-	 *
-	 * It is expected that this function will be called using HTML text.
-	 * We will escape text between HTML pre and code blocks from being
-	 * processed.
-	 *
-	 * At a higher level, the bbcode [nosmile] tag can be used to prevent this
-	 * function from being executed by the prepare_text() routine when preparing
-	 * bbcode source for HTML display
-	 *
-	 * @param string $s
-	 * @param boolean $sample
-	 * 
-	 * @return string
-	 */
-	public static function replace($s, $sample = false) {
-		if(intval(get_config('system','no_smilies'))
-			|| (local_user() && intval(get_pconfig(local_user(),'system','no_smilies'))))
-			return $s;
-
-		$s = preg_replace_callback('/
(.*?)<\/pre>/ism','self::smile_encode',$s);
-		$s = preg_replace_callback('/(.*?)<\/code>/ism','self::smile_encode',$s);
-
-		$params = self::list_smilies();
-		$params['string'] = $s;
-
-		if($sample) {
-			$s = '
'; - for($x = 0; $x < count($params['texts']); $x ++) { - $s .= '
' . $params['texts'][$x] . '
' . $params['icons'][$x] . '
'; - } - } - else { - $params['string'] = preg_replace_callback('/<(3+)/','self::preg_heart',$params['string']); - $s = str_replace($params['texts'],$params['icons'],$params['string']); - } - - $s = preg_replace_callback('/
(.*?)<\/pre>/ism','self::smile_decode',$s);
-		$s = preg_replace_callback('/(.*?)<\/code>/ism','self::smile_decode',$s);
-
-		return $s;
-	}
-
-	private function smile_encode($m) {
-		return(str_replace($m[1],base64url_encode($m[1]),$m[0]));
-	}
-
-	private function smile_decode($m) {
-		return(str_replace($m[1],base64url_decode($m[1]),$m[0]));
-	}
-
-
-	/**
-	 * @brief expand <3333 to the correct number of hearts
-	 *
-	 * @param string $x
-	 * @return string
-	 */
-	private function preg_heart($x) {
-		if(strlen($x[1]) == 1)
-			return $x[0];
-		$t = '';
-		for($cnt = 0; $cnt < strlen($x[1]); $cnt ++)
-			$t .= '<3';
-		$r =  str_replace($x[0],$t,$x[0]);
-		return $r;
-	}
-
-}
diff --git a/include/text.php b/include/text.php
index eb8dde40cb..e14930b102 100644
--- a/include/text.php
+++ b/include/text.php
@@ -2,7 +2,7 @@
 
 require_once("include/template_processor.php");
 require_once("include/friendica_smarty.php");
-require_once("include/smilies.php");
+require_once("include/Smilies.php");
 require_once("include/map.php");
 require_once("mod/proxy.php");
 
@@ -1396,7 +1396,7 @@ function prepare_text($text) {
 	if(stristr($text,'[nosmile]'))
 		$s = bbcode($text);
 	else
-		$s = smilies::replace(bbcode($text));
+		$s = Smilies::replace(bbcode($text));
 
 	return trim($s);
 }}
diff --git a/mod/smilies.php b/mod/smilies.php
index 5a157e3686..b3d86cb3fe 100644
--- a/mod/smilies.php
+++ b/mod/smilies.php
@@ -4,11 +4,11 @@
  * @file mod/smilies.php
  */
 
-require_once("include/smilies.php");
+require_once("include/Smilies.php");
 
 function smilies_content(&$a) {
 	if ($a->argv[1]==="json"){
-		$tmp = smilies::list_smilies();
+		$tmp = Smilies::get_list();
 		$results = array();
 		for($i = 0; $i < count($tmp['texts']); $i++) {
 			$results[] = array('text' => $tmp['texts'][$i], 'icon' => $tmp['icons'][$i]);