[dev] [commit] r1000 - templates/diacritics_fix wwwbase wwwbase/styles

automailer at dexonline.ro automailer at dexonline.ro
Sun Sep 22 03:23:34 EEST 2013


Author: alinu
Date: Sun Sep 22 03:23:34 2013
New Revision: 1000

Log:
Contine un mecanism functional (cu dropdown select) de inserare diacritice intr-un text, template-ul si fisierul css asociat.

Added:
   templates/diacritics_fix/
   templates/diacritics_fix/diacritics_fix.ihtml
   wwwbase/styles/diacritics_fix.css
Modified:
   wwwbase/diacritice.php

Added: templates/diacritics_fix/diacritics_fix.ihtml
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ templates/diacritics_fix/diacritics_fix.ihtml	Sun Sep 22 03:23:34 2013	(r1000)
@@ -0,0 +1,30 @@
+<html>
+	<head>
+
+		<title>{$page_title}</title>
+
+		
+		<link rel="StyleSheet" type="text/css" href="/DEX/wwwbase/styles/diacritics_fix.css"/>
+
+
+
+
+	</head>
+	<body>
+		
+		<div id="textarea_subtitle">
+			<center><span>Corector diacritice</span></center>
+		</div>
+
+		<form id="textarea_form" action="" method="POST">
+			<div id="textarea_div" align="center">
+				{$textarea}
+				{$hiddenText}
+				<input type="submit" name="ok" value="ok">
+
+			</div>
+
+		</form>
+		
+	</body>
+</html>

Modified: wwwbase/diacritice.php
==============================================================================
--- wwwbase/diacritice.php	Sun Sep 22 00:51:50 2013	(r999)
+++ wwwbase/diacritice.php	Sun Sep 22 03:23:34 2013	(r1000)
@@ -25,6 +25,8 @@
 
 	private $resultText;
 	private $lastOffset;
+	private $hiddenText;
+	private $selectCount;
 
 
 	protected $currOffset;
@@ -32,7 +34,8 @@
 	protected $fileEndOffset;
 
 	protected static $diacritics;
-	protected static $nonDiacritics;
+	protected static $nonLowerDiacritics;
+	protected static $nonUpperDiacritics;
 	protected static $paddingNumber;
 	protected static $paddingChar;
 	/*
@@ -42,9 +45,11 @@
 		crawlerLog("INSIDE " . __FILE__ . ' - ' . __CLASS__ . '::' . __FUNCTION__ . '() - ' . 'line '.__LINE__ );
 
 		self::$diacritics = pref_getSectionPreference("crawler", "diacritics");
-		self::$nonDiacritics = pref_getSectionPreference("crawler", "non_diacritics");
+		self::$nonLowerDiacritics = pref_getSectionPreference("crawler", "non_lower_diacritics");
+		self::$nonUpperDiacritics = pref_getSectionPreference("crawler", "non_upper_diacritics");
 		self::$paddingNumber = pref_getSectionPreference('crawler', 'diacritics_padding_length');
 		self::$paddingChar = pref_getSectionPreference('crawler', 'padding_char');
+		$this->selectCount = 0;
  	}
 
 	/* returneaza urmatorul index in fisier care contine
@@ -64,7 +69,7 @@
 
 	static function isSeparator($ch) {
 		crawlerLog("INSIDE " . __FILE__ . ' - ' . __CLASS__ . '::' . __FUNCTION__ . '() - ' . 'line '.__LINE__ );
-		return !(ctype_lower($ch) || $ch == '-');
+		return !(ctype_alpha($ch) || $ch == '-');
 	}
 
 
@@ -76,6 +81,7 @@
 		$this->lastOffset = 0;
 
 		$this->resultText = '';
+		$this->hiddenText = '';
 		$this->text = $text;
 
 		$this->textEndOffset = mb_strlen($text) - 1;
@@ -86,6 +92,7 @@
 		}
 		//copiem de la ultimul posibil diacritic pana la final
 		$this->resultText .= mb_substr($this->text, $this->lastOffset, $this->textEndOffset - $this->lastOffset + 1);
+		$this->hiddenText .= mb_substr($this->text, $this->lastOffset, $this->textEndOffset - $this->lastOffset + 1);
 	}
 
 
@@ -104,7 +111,8 @@
 
 	static function isPossibleDiacritic($ch) {
 		crawlerLog("INSIDE " . __FILE__ . ' - ' . __CLASS__ . '::' . __FUNCTION__ . '() - ' . 'line '.__LINE__ );
-		return strstr(self::$nonDiacritics, $ch);
+		return strstr(self::$nonLowerDiacritics, $ch) ||
+			strstr(self::$nonUpperDiacritics, $ch);
 	}
 
 
@@ -156,19 +164,31 @@
 
 		crawlerLog("IN TEXT " . $before .'|' . $middle . '|' . $after);
 
-		$tableObj = Diacritics::entryExists(self::toLower($before),
-					self::toLower($middle), self::toLower($after));
+		$tableObj = Diacritics::entryExists($before, $middle, $after);
 		if ($tableObj != null) {
 			crawlerLog("Entry Exists");
 			$ch = $this->getAllCharForms($tableObj, $middle);
 
 			$this->resultText .= mb_substr($this->text, $this->lastOffset, $offset - $this->lastOffset);
 
+			$this->hiddenText .= mb_substr($this->text, $this->lastOffset, $offset - $this->lastOffset);
+
 			$this->resultText .= $ch;
+
+			if (mb_strlen($ch) == 1) {
+				$this->hiddenText .= $ch;
+			}
+			else {
+				$this->hiddenText .= "@@".($this->selectCount - 1)."@@";
+			}
+
+
 		}
 		else {
 
-			$this->resultText .= mb_substr($this->text, $this->lastOffset, $offset - $this->lastOffset + 1);			
+			$this->resultText .= mb_substr($this->text, $this->lastOffset, $offset - $this->lastOffset + 1);
+
+			$this->hiddenText .= mb_substr($this->text, $this->lastOffset, $offset - $this->lastOffset + 1);			
 		}
 
 		$this->lastOffset = $this->currOffset;
@@ -189,36 +209,44 @@
 		//crawlerLog("WTF " . $key);
 		//$ch = $charArray[$key];
 
-		$ch = $this->dropDownSelect($sortedSet, $charArray, $middle);
-
+		if (self::hasMoreVariants($sortedSet)) {
+			$ch = $this->dropDownSelect($sortedSet, $charArray, $middle);
+		}
+		else {
+			$ch  = self::getToUpperOrToLower($charArray[key($sortedSet)], $middle);
+		}
 		return $ch;
 	}
 
 	private function dropDownSelect($forms, $charArray, $middle) {
 
-		$buffer = '<select>';
-
-		$i = 0;
+		$buffer = '<select name="'.$this->selectCount++.'">';
 
 		foreach($forms as $form => $value) {
 
 			if ($value > 0) {
-
-				$buffer .= "<option value=\"".$charArray[$form]."\">".self::getToUpperOrToLower($charArray[$form], $middle)."</option>";
-			}
-			else {
-				$i ++;
+				$ch = self::getToUpperOrToLower($charArray[$form], $middle);
+				$buffer .= "<option value=\"".$ch."\">".$ch."</option>";
 			}
 		}
 
 		$buffer .= '</select>';
+		return $buffer;
+	}
 
-		if ($i > 1) {
-			return self::getToUpperOrToLower($charArray[key($forms)], $middle);
-		}
-		else {
-			return $buffer;
+	static function hasMoreVariants($forms) {
+
+		$i = 0;
+
+		foreach($forms as $form => $value) {
+
+			if ($value > 0) {
+
+				$i++;
+			}
 		}
+
+		return ($i > 1);
 	}
 
 	static function getToUpperOrToLower($val, $middle) {
@@ -248,6 +276,35 @@
 		return $array;
 	}
 
+	function getHiddenText() {
+
+		return $this->hiddenText;
+	}
+
+	function replaceDiacritics() {
+
+		if (isset($_POST['hiddenText'])) {
+			if ($_POST['hiddenText'] == '')
+			return '';
+			else {
+				$search = array();
+				$replace = array();
+
+				$buffer = $_POST['hiddenText'];
+				foreach($_POST as $key => $value) {
+
+					if (is_numeric($key)) {
+						$search[] = '/@@'.$key.'@@/i';
+						$replace[] = $value;
+					}
+				}
+				return preg_replace($search, $replace, $buffer);
+			}
+		}
+		else {
+			return '';
+		}
+	}
 
 }
 
@@ -258,16 +315,17 @@
 
 	SmartyWrap::assign('page_title', 'Corector diacritice');
 
+	$obj = new DiacriticsFixer();
 
 	if (isset($_POST['text']) && $_POST['text'] != '') {
 
-		$obj = new DiacriticsFixer();
-
 		SmartyWrap::assign('textarea', '<div id="text_input">'.$obj->fix($_POST['text']).'</div>');
+		SmartyWrap::assign('hiddenText', '<input type="hidden" name="hiddenText" value="'.$obj->getHiddenText().'">');
 	}
 	else {
 
-		SmartyWrap::assign('textarea', '<textarea name="text" id="text_input" placeholder="introduceți textul aici"></textarea>');
+		SmartyWrap::assign('textarea', '<textarea name="text" id="text_input" placeholder="introduceți textul aici">'.$obj->replaceDiacritics().'</textarea>');
+		SmartyWrap::assign('hiddenText', '<input type="hidden" name="hiddenText" value="">');
 	}
 
 

Added: wwwbase/styles/diacritics_fix.css
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ wwwbase/styles/diacritics_fix.css	Sun Sep 22 03:23:34 2013	(r1000)
@@ -0,0 +1,37 @@
+#textarea_subtitle {
+
+	position: relative;
+	width: 100%;
+}
+
+#textarea_subtitle span {
+
+	color: blue;
+	font-size: 20px;
+	font-family: serif;
+	font-weight: 900;
+}
+
+
+#textarea_div {
+
+	position: relative;
+	width: 600px;
+	margin: 0 auto;
+}
+
+
+textarea {
+
+	position: relative;
+
+	width: 580px;
+	height: 250px;
+
+	resize: none;
+
+	margin: 10px;
+
+	border:1px solid gray;
+	background-color:#EEEEF6;
+}
\ No newline at end of file


More information about the Dev mailing list