Browse Source

parse emoticons stuff in a separate function

Andrew Dolgov 5 years ago
parent
commit
f0d0b31833
2 changed files with 21 additions and 35 deletions
  1. 3 27
      backend.php
  2. 18 8
      include/functions.php

+ 3 - 27
backend.php

@@ -164,7 +164,7 @@
 				$popcon_matches = array();
 				preg_match_all("/(:[^ :]+:)/", $message, $popcon_matches);
 
-				$emoticons_map = @parse_ini_file("emoticons/emoticons.ini");
+				$emoticons_map = get_emoticons_map();
 
 				if ($emoticons_map && count($popcon_matches[0]) > 0) {
 					foreach ($popcon_matches[0] as $emoticon) {
@@ -338,18 +338,7 @@
 		$rv["theme"] = get_pref($link, "USER_THEME");
 		$rv["update_delay_max"] = UPDATE_DELAY_MAX;
 		$rv["uniqid"] = uniqid();
-
-		$emoticons_ini = @parse_ini_file("emoticons/emoticons.ini");
-		$emoticons_map = array();
-
-		if ($emoticons_ini) {
-			foreach ($emoticons_ini as $k => $v) {
-				$e = explode(",", $v);
-				$emoticons_map[$k] = $e;
-			}
-		}
-
-		$rv["emoticons"] = $emoticons_map;
+		$rv["emoticons"] = get_emoticons_map();
 
 		print json_encode($rv);
 
@@ -566,20 +555,7 @@
 		break;
 
 	case "emoticons":
-		$emoticons_ini = @parse_ini_file("emoticons/emoticons.ini");
-		$emoticons_map = array();
-
-		if ($emoticons_ini) {
-			foreach ($emoticons_ini as $k => $v) {
-				$e = explode(",", $v);
-				$emoticons_map[$k] = $e;
-			}
-
-			print json_encode($emoticons_map);
-		} else {
-			print json_encode(array());
-		}
-
+		print json_encode(get_emoticons_map());
 		break;
 
 	case "emoticons_list":

+ 18 - 8
include/functions.php

@@ -1027,9 +1027,20 @@
 		}
 	}
 
-	function render_emoticons_full() {
+	function get_emoticons_map() {
 		$ini = @parse_ini_file("emoticons/emoticons.ini");
-		if (!$ini) return false;
+		if (!$ini) return array();
+
+		$tmp = array();
+
+		foreach ($ini as $k => $v) {
+			$tmp[$k] = explode(",", $v);
+		}
+
+		return $tmp;
+	}
+
+	function render_emoticons_full() {
 
 		?>
 		<html>
@@ -1041,8 +1052,8 @@
 		<div id="emoticons_long">
 		<?php
 
-		foreach ($ini as $k => $v) {
-			$e = explode(",", $v);
+		$emoticons_map = get_emoticons_map();
+		foreach ($emoticons_map as $k => $e) {
 
 			print "<div class=\"tile\"><div class=\"wrapper\">";
 			print "<img onclick=\"window.opener.inject_text('$k')\" title=\"$k\" src=\"emoticons/$e[0]\">";
@@ -1058,8 +1069,7 @@
 	}
 
 	function render_emoticons($link) {
-		$ini = @parse_ini_file("emoticons/emoticons.ini");
-		if (!$ini) return false;
+		$emoticons_map = get_emoticons_map();
 
 		$tmp = "";
 
@@ -1071,13 +1081,13 @@
 			++$num_favs;
 
 			$k = $line["emoticon"];
-			$e = explode(",", $ini[$k])[0];
+			$e = $emoticons_map[$k][0];
 
 			$tmp .= "<div class=\"wrapper\"><img onclick=\"inject_text('$k')\" title=\"$k\" src=\"emoticons/$e\"></div>";
 
 		}
 
-		$num_more = count($ini) - $num_favs;
+		$num_more = count($emoticons_map) - $num_favs;
 
 		if ($num_more > 0) {
 			$tmp .= "<br clear='both'><p><a href=\"#\" onclick=\"return emoticons_popup()\">$num_more more...</a></p>";