_binary From 74f295d982a646ed7c29d08d2c5752f8ed5be943 Mon Sep 17 00:00:00 2001
From: Akshat Kukreti <akshatkukreti@gmail.com>
Date: Wed, 29 Jun 2011 19:11:15 -0700
Subject: [PATCH 1/2] separate div for history feature

---
 controllers/search_controller.php | 92 ++++++++++++++++++++++++++-------------
 1 file changed, 62 insertions(+), 30 deletions(-)

diff --git a/controllers/search_controller.php b/controllers/search_controller.php
index cdbee63..940cf27 100755
--- a/controllers/search_controller.php
+++ b/controllers/search_controller.php
@@ -1292,6 +1292,8 @@ class SearchController extends Controller implements CrawlConstants
         $scriptNode = $body->insertBefore($scriptNode, $summaryNode);
         $textNode = $dom->createTextNode("var summaryShow = 'none';");
         $scriptNode->appendChild($textNode);
+        $textNode2 = $dom->createTextNode("var historyShow = 'none';");
+        $scriptNode->appendChild($textNode2);
 
         $aDivNode = $dom->createElement('div');
         $aDivNode = $body->insertBefore($aDivNode, $summaryNode);
@@ -1301,6 +1303,8 @@ class SearchController extends Controller implements CrawlConstants
         $divNode = $dom->createElement('div');
 
         $divNode = $body->insertBefore($divNode, $aDivNode);
+        $divNode->setAttributeNS("","style","position:relative");
+        $divNode->setAttributeNS("","style","zIndex:1");
         $divNode->setAttributeNS("","style", "border-color: black; ".
             "border-style:solid; border-width:3px;margin-bottom:10px;".
             "padding: 5px; background-color: white; text-align:$text_align;");
@@ -1309,6 +1313,12 @@ class SearchController extends Controller implements CrawlConstants
             "Z@url@Z", $date));
         $divNode->appendChild($textNode);
 
+        //Link for accessing history feature
+        $historyLink = $dom->createElement('a');
+        $historyLabel = $dom->createTextNode(tl('search_controller_history'));
+        $historyLink->appendChild($historyLabel);
+        $divNode->appendChild($historyLink);
+
         //Display links for all cached versions
         $time_array = array();
         $time_entry = array();
@@ -1350,6 +1360,52 @@ class SearchController extends Controller implements CrawlConstants
         $month_json = json_encode($months);
         $year_json = json_encode($years);
 
+        //Display current year, current month and their respective links
+        $current = date("F d Y g:ia",$crawl_time);
+        $current_components = explode(" ",$current);
+        $current_year = json_encode($current_components[2]);
+        $current_month = json_encode($current_components[0]);
+
+        $historyLink->setAttributeNS('','onclick','javascript:'.
+            "var m_id = document.getElementById('#month');".
+            "var y_id = document.getElementById('#year');".
+            "var cur_year = $current_year;".
+            "var cur_month = $current_month;".
+            "cur_div = 
+                document.getElementById('#'+cur_year+cur_month);".
+            "for(i=0;i<y_id.length;i++){
+                if(y_id.options[i].value==cur_year){
+                    y_id.options[i].defaultSelected=true;
+                }
+             }".
+            "document.getElementById('#month').options.length=0;".
+            "var monthjs = $month_json;".
+            "var curyearid = document.getElementById('#year');".
+            "var temp = curyearid.options[curyearid.selectedIndex].value;".
+            "for(j=0;j<monthjs.length;j++){
+                var id=document.getElementById('#'+temp+monthjs[j]);
+                if(id !== null){
+                    var opt = document.createElement('option');
+                    opt.text = monthjs[j];
+                    var m = document.getElementById('#month');
+                    m.add(opt,null);
+                }
+             }".
+            "for(i=0;i<m_id.length;i++){
+                if(m_id.options[i].value==cur_month){
+                    m_id.options[i].defaultSelected=true;
+                }
+             }".
+            "select=document.getElementById('#d1');".
+            "if(select.style.display=='none'){".
+            "select.style.display='block';".
+            "}else{select.style.display='none';}".
+            "if(cur_div.style.display=='none'){".
+            "cur_div.style.display='block';}".
+            "else{cur_div.style.display='none'}");
+        $historyLink->setAttributeNS('','style',"text-decoration: underline; ".
+            "cursor: pointer");
+
         //UI for selecting year and month
         $d1 = $dom->createElement('div');
         $d1->setAttributeNS("","id","#d1");
@@ -1451,38 +1507,14 @@ class SearchController extends Controller implements CrawlConstants
             "ldiv.style.display = 'block';}");
 
         $aNode = $dom->createElement("a");
-        $aTextNode = $dom->createTextNode('View Links to All Cached Versions,
-            Extracted Headers, and Summaries');
+        $aTextNode = 
+            $dom->createTextNode(tl('search_controller_header_summaries'));
         $aNode->setAttributeNS("","onclick", "javascript:".
-            "var m_id = document.getElementById('#month');".
-            "var y_id = document.getElementById('#year');".
-            "var cur_year = y_id.options[y_id.selectedIndex].value;".
-            "var cur_month = m_id.options[m_id.selectedIndex].value;".
-            "cur_div = document.getElementById('#'+cur_year+cur_month);".
             "summaryShow=(summaryShow!='block')?'block':'none';".
             "elt=document.getElementById('summary-page-id');".
-            "elt.style.display=summaryShow;".
-            "document.getElementById('#month').options.length=0;".
-            "var monthjs=$month_json;".
-            "var curyearid = document.getElementById('#year');".
-            "var temp = curyearid.options[curyearid.selectedIndex].value;".
-            "for(j=0;j<monthjs.length;j++){
-                var id=document.getElementById('#'+temp+monthjs[j]);
-                if(id !== null){
-                    var opt = document.createElement('option');
-                    opt.text = monthjs[j];
-                    var m = document.getElementById('#month');
-                    m.add(opt,null);
-                }
-             }".
-            "select=document.getElementById('#d1');".
-            "if(select.style.display=='none'){".
-            "select.style.display='block';".
-            "}else{select.style.display='none';}".
-            "if(cur_div.style.display=='none'){".
-            "cur_div.style.display='block';}".
-            "else{cur_div.style.display='none'}");
-        $aNode->setAttributeNS("","style","zIndex:1");
+            "elt.style.display=summaryShow;");
+        $aNode->setAttributeNS("","style","position:relative");
+        $aNode->setAttributeNS("","style","zIndex:2");
         $aNode->setAttributeNS("","style", "text-decoration: underline; ".
             "cursor: pointer");
 
@@ -1490,7 +1522,7 @@ class SearchController extends Controller implements CrawlConstants
 
         $aNode = $aDivNode->appendChild($aNode);
 
-        $d1 = $aDivNode->appendChild($d1);
+        $d1 = $divNode->appendChild($d1);
 
         /*create divs for all year.month pairs and populate with links
          */
-- 
1.7.11.msysgit.1


From e0e4ce1f6f28b106b1012c22c97d471158aca7b5 Mon Sep 17 00:00:00 2001
From: Akshat Kukreti <akshatkukreti@gmail.com>
Date: Sat, 15 Dec 2012 04:57:15 -0800
Subject: [PATCH 2/2] attempt at date localization

---
 controllers/search_controller.php |  95 ++++++++++++++++++++---
 yioopdec142012.patch              | 153 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 238 insertions(+), 10 deletions(-)
 create mode 100644 yioopdec142012.patch

diff --git a/controllers/search_controller.php b/controllers/search_controller.php
index 940cf27..ade5ff9 100755
--- a/controllers/search_controller.php
+++ b/controllers/search_controller.php
@@ -43,6 +43,9 @@ require_once BASE_DIR."/lib/utility.php";
 require_once BASE_DIR."/lib/crawl_constants.php";
 /** For getting pages from a mirror if decide not to handle ourselves*/
 require_once BASE_DIR."/lib/fetch_url.php";
+/**For guessing User's locale when displaying cached version*/
+require_once BASE_DIR."/lib/locale_functions.php";
+
 /**
  * Controller used to handle search requests to SeekQuarry
  * search site. Used to both get and display
@@ -1028,6 +1031,7 @@ class SearchController extends Controller implements CrawlConstants
    function cacheRequestAndOutput($url, $highlight = true, $terms ="", 
         $crawl_time = 0)
     {
+
         global $CACHE, $IMAGE_TYPES;
 
         $flag = 0;
@@ -1098,13 +1102,24 @@ class SearchController extends Controller implements CrawlConstants
         /*Get the nearest timestamp (future or past)
          *Check in future first and if not found, check in past
          */
-        $crawl_time = array_shift($all_future_times);
-        array_push($all_future_times,$crawl_time);
-        sort($all_future_times, SORT_STRING);
-        $this->phraseModel->index_name = $crawl_time;
-        $this->crawlModel->index_name = $crawl_time;
-        $crawl_item = $this->crawlModel->
-            getCrawlItem($url, $queue_servers);
+        if(!empty($all_future_times)){
+            $crawl_time = array_shift($all_future_times);
+            array_push($all_future_times,$crawl_time);
+            sort($all_future_times, SORT_STRING);
+            $this->phraseModel->index_name = $crawl_time;
+            $this->crawlModel->index_name = $crawl_time;
+            $crawl_item = $this->crawlModel->
+                getCrawlItem($url, $queue_servers);
+        }
+        else {
+            $crawl_time = array_pop($all_past_times);
+            array_push($all_past_times,$crawl_time);
+            sort($all_past_times, SORT_STRING);
+            $this->phraseModel->index_name = $crawl_time;
+            $this->crawlModel->index_name = $crawl_time;
+            $crawl_item = $this->crawlModel->
+                getCrawlItem($url, $queue_servers);
+        }
 
         $data = array();
 
@@ -1329,7 +1344,9 @@ class SearchController extends Controller implements CrawlConstants
         //Initialize data structure for storing all timestamp details
         if(!empty($all_crawl_times)){
             foreach($all_crawl_times as $cache_time) {
-                $date_time_string = date ("F d Y g:ia", $cache_time);
+                $locale_type = guessLocale();
+                $date_time_string = 
+                    $this->formatByLocale($cache_time,$locale_type);
                 $time_components = explode(" ",$date_time_string);
                 $time_ds[$time_components[2]][$time_components[0]] = null;
             }
@@ -1337,7 +1354,9 @@ class SearchController extends Controller implements CrawlConstants
 
         if(!empty($all_crawl_times)){
             foreach($all_crawl_times as $cache_time){
-                $date_time_string = date("F d Y g:ia", $cache_time);
+                $locale_type = guessLocale();
+                $date_time_string = 
+                    $this->formatByLocale($cache_time,$locale_type);
                 $time_components = explode(" ",$date_time_string);
                 if(!in_array($time_components[2],$years)) {
                     array_push($years, $time_components[2]);
@@ -1361,7 +1380,9 @@ class SearchController extends Controller implements CrawlConstants
         $year_json = json_encode($years);
 
         //Display current year, current month and their respective links
-        $current = date("F d Y g:ia",$crawl_time);
+        $locale_type = guessLocale();
+        $current = 
+            $this->formatByLocale($crawl_time,$locale_type);
         $current_components = explode(" ",$current);
         $current_year = json_encode($current_components[2]);
         $current_month = json_encode($current_components[0]);
@@ -1586,6 +1607,60 @@ class SearchController extends Controller implements CrawlConstants
         echo $newDoc;
         return;
     }
+    
+    /**
+     * Function for formatting the date string based on the locale.
+     * @param $timestamp is the crawl time
+     * @param $locale_tag is the tag for locale
+     * @return string formatted date string
+     */
+    function formatByLocale($timestamp,$locale_tag)
+    {
+        switch($locale_tag) {
+            case 'de':
+                setlocale(LC_ALL,'deu');
+                return strftime("%B %#d %Y %H:%M",$timestamp);
+                break;
+            case 'en-US':
+                setlocale(LC_ALL,'enu');
+                return strftime("%B %#d %Y %H:%M",$timestamp);
+                break;
+            case 'es':
+                setlocale(LC_ALL,'esp');
+                return strftime("%B %#d %Y %H:%M",$timestamp);
+                break;
+            case 'fr-FR':
+                setlocale(LC_ALL,'fra');
+                return strftime("%B %#d %Y %H:%M",$timestamp);
+                break;
+            case 'it':
+                setlocale(LC_ALL,'ita');
+                return strftime("%B %#d %Y %H:%M",$timestamp);
+                break;
+            case 'ja':
+                setlocale(LC_ALL,'jpn');
+                return strftime("%B %#d %Y %H:%M",$timestamp);
+                break;
+            case 'ko':
+                setlocale(LC_ALL,'kor');
+                return strftime("%B %#d %Y %H:%M",$timestamp);
+                break;
+            case 'pl':
+                setlocale(LC_ALL,'plk');
+                return strftime("%B %#d %Y %H:%M",$timestamp);
+                break;
+            case 'ru':
+                setlocale(LC_ALL,'rus');
+                return strftime("%B %#d %Y %H:%M",$timestamp);
+                break;
+            case 'tr':
+                setlocale(LC_ALL,'trk');
+                return strftime("%B %#d %Y %H:%M",$timestamp);
+                break;
+            default:
+                return date("F d Y H:i", intval($timestamp));
+        }
+    }
 
 }
 ?>
diff --git a/yioopdec142012.patch b/yioopdec142012.patch
new file mode 100644
index 0000000..241d8d4
--- /dev/null
+++ b/yioopdec142012.patch
@@ -0,0 +1,153 @@
+From 74f295d982a646ed7c29d08d2c5752f8ed5be943 Mon Sep 17 00:00:00 2001
+From: Akshat Kukreti <akshatkukreti@gmail.com>
+Date: Wed, 29 Jun 2011 19:11:15 -0700
+Subject: [PATCH] separate div for history feature
+
+---
+ controllers/search_controller.php | 92 ++++++++++++++++++++++++++-------------
+ 1 file changed, 62 insertions(+), 30 deletions(-)
+
+diff --git a/controllers/search_controller.php b/controllers/search_controller.php
+index cdbee63..940cf27 100755
+--- a/controllers/search_controller.php
++++ b/controllers/search_controller.php
+@@ -1292,6 +1292,8 @@ class SearchController extends Controller implements CrawlConstants
+         $scriptNode = $body->insertBefore($scriptNode, $summaryNode);
+         $textNode = $dom->createTextNode("var summaryShow = 'none';");
+         $scriptNode->appendChild($textNode);
++        $textNode2 = $dom->createTextNode("var historyShow = 'none';");
++        $scriptNode->appendChild($textNode2);
+ 
+         $aDivNode = $dom->createElement('div');
+         $aDivNode = $body->insertBefore($aDivNode, $summaryNode);
+@@ -1301,6 +1303,8 @@ class SearchController extends Controller implements CrawlConstants
+         $divNode = $dom->createElement('div');
+ 
+         $divNode = $body->insertBefore($divNode, $aDivNode);
++        $divNode->setAttributeNS("","style","position:relative");
++        $divNode->setAttributeNS("","style","zIndex:1");
+         $divNode->setAttributeNS("","style", "border-color: black; ".
+             "border-style:solid; border-width:3px;margin-bottom:10px;".
+             "padding: 5px; background-color: white; text-align:$text_align;");
+@@ -1309,6 +1313,12 @@ class SearchController extends Controller implements CrawlConstants
+             "Z@url@Z", $date));
+         $divNode->appendChild($textNode);
+ 
++        //Link for accessing history feature
++        $historyLink = $dom->createElement('a');
++        $historyLabel = $dom->createTextNode(tl('search_controller_history'));
++        $historyLink->appendChild($historyLabel);
++        $divNode->appendChild($historyLink);
++
+         //Display links for all cached versions
+         $time_array = array();
+         $time_entry = array();
+@@ -1350,6 +1360,52 @@ class SearchController extends Controller implements CrawlConstants
+         $month_json = json_encode($months);
+         $year_json = json_encode($years);
+ 
++        //Display current year, current month and their respective links
++        $current = date("F d Y g:ia",$crawl_time);
++        $current_components = explode(" ",$current);
++        $current_year = json_encode($current_components[2]);
++        $current_month = json_encode($current_components[0]);
++
++        $historyLink->setAttributeNS('','onclick','javascript:'.
++            "var m_id = document.getElementById('#month');".
++            "var y_id = document.getElementById('#year');".
++            "var cur_year = $current_year;".
++            "var cur_month = $current_month;".
++            "cur_div = 
++                document.getElementById('#'+cur_year+cur_month);".
++            "for(i=0;i<y_id.length;i++){
++                if(y_id.options[i].value==cur_year){
++                    y_id.options[i].defaultSelected=true;
++                }
++             }".
++            "document.getElementById('#month').options.length=0;".
++            "var monthjs = $month_json;".
++            "var curyearid = document.getElementById('#year');".
++            "var temp = curyearid.options[curyearid.selectedIndex].value;".
++            "for(j=0;j<monthjs.length;j++){
++                var id=document.getElementById('#'+temp+monthjs[j]);
++                if(id !== null){
++                    var opt = document.createElement('option');
++                    opt.text = monthjs[j];
++                    var m = document.getElementById('#month');
++                    m.add(opt,null);
++                }
++             }".
++            "for(i=0;i<m_id.length;i++){
++                if(m_id.options[i].value==cur_month){
++                    m_id.options[i].defaultSelected=true;
++                }
++             }".
++            "select=document.getElementById('#d1');".
++            "if(select.style.display=='none'){".
++            "select.style.display='block';".
++            "}else{select.style.display='none';}".
++            "if(cur_div.style.display=='none'){".
++            "cur_div.style.display='block';}".
++            "else{cur_div.style.display='none'}");
++        $historyLink->setAttributeNS('','style',"text-decoration: underline; ".
++            "cursor: pointer");
++
+         //UI for selecting year and month
+         $d1 = $dom->createElement('div');
+         $d1->setAttributeNS("","id","#d1");
+@@ -1451,38 +1507,14 @@ class SearchController extends Controller implements CrawlConstants
+             "ldiv.style.display = 'block';}");
+ 
+         $aNode = $dom->createElement("a");
+-        $aTextNode = $dom->createTextNode('View Links to All Cached Versions,
+-            Extracted Headers, and Summaries');
++        $aTextNode = 
++            $dom->createTextNode(tl('search_controller_header_summaries'));
+         $aNode->setAttributeNS("","onclick", "javascript:".
+-            "var m_id = document.getElementById('#month');".
+-            "var y_id = document.getElementById('#year');".
+-            "var cur_year = y_id.options[y_id.selectedIndex].value;".
+-            "var cur_month = m_id.options[m_id.selectedIndex].value;".
+-            "cur_div = document.getElementById('#'+cur_year+cur_month);".
+             "summaryShow=(summaryShow!='block')?'block':'none';".
+             "elt=document.getElementById('summary-page-id');".
+-            "elt.style.display=summaryShow;".
+-            "document.getElementById('#month').options.length=0;".
+-            "var monthjs=$month_json;".
+-            "var curyearid = document.getElementById('#year');".
+-            "var temp = curyearid.options[curyearid.selectedIndex].value;".
+-            "for(j=0;j<monthjs.length;j++){
+-                var id=document.getElementById('#'+temp+monthjs[j]);
+-                if(id !== null){
+-                    var opt = document.createElement('option');
+-                    opt.text = monthjs[j];
+-                    var m = document.getElementById('#month');
+-                    m.add(opt,null);
+-                }
+-             }".
+-            "select=document.getElementById('#d1');".
+-            "if(select.style.display=='none'){".
+-            "select.style.display='block';".
+-            "}else{select.style.display='none';}".
+-            "if(cur_div.style.display=='none'){".
+-            "cur_div.style.display='block';}".
+-            "else{cur_div.style.display='none'}");
+-        $aNode->setAttributeNS("","style","zIndex:1");
++            "elt.style.display=summaryShow;");
++        $aNode->setAttributeNS("","style","position:relative");
++        $aNode->setAttributeNS("","style","zIndex:2");
+         $aNode->setAttributeNS("","style", "text-decoration: underline; ".
+             "cursor: pointer");
+ 
+@@ -1490,7 +1522,7 @@ class SearchController extends Controller implements CrawlConstants
+ 
+         $aNode = $aDivNode->appendChild($aNode);
+ 
+-        $d1 = $aDivNode->appendChild($d1);
++        $d1 = $divNode->appendChild($d1);
+ 
+         /*create divs for all year.month pairs and populate with links
+          */
+-- 
+1.7.11.msysgit.1
+
-- 
1.7.11.msysgit.1

