วันศุกร์ที่ 28 มกราคม พ.ศ. 2554

ระบบ Build ของ LibreOffice

เนื่องจากได้ปล้ำกับ LibreOffice มาสัปดาห์นึง เพิ่งจะเข้าใจมัน(ถึงจะไม่หมดก็เหอะ) ก็เลยเอามา blog ไว้เผื่อท่านอื่นๆ จะได้เข้าใจบ้าง

ใน LibreOffice นั้นมี wiki บอกวิธีการ build อยู่ที่ http://wiki.documentfoundation.org/Development/Native_Build

โดยในส่วน getting the source นั้นเขียนไว้ดังนี้

$ mkdir git
$ cd git
$ git clone git://anongit.freedesktop.org/libreoffice/bootstrap libo
Cloning into libo...
Remote: Counting objects: 76845, done.
remote: Compressing objects: 100% (17328/17328), done.
remote: Total 76845 (delta 60786), reused 74045 (delta 58579)
Receiving objects: 100% (76845/76845), 15.82 MiB | 1.17 MiB/s, done.
Resolving deltas: 100% (60786/60786), done.
$ cd libo

ถ้าดูจาก file size ที่ได้มา 15.82 MiB นั้นดูเหมือนจะน้อยเกินไปสำหรับ source code ของ LibreOffice ซึ่งในส่วนที่ get มานั้นเป็นแค่ bootstrap ของ LibreOffice เท่านั้น

LibreOffice นั้นเก็บ source code ทั้งหมดไว้เป็น 19 repository หรือ 20 ถ้ารวมส่วนของ l10n ไปด้วยซึ่งถ้าจะ git ออกมาทีละ repo ก็สามารถทำได้ แต่ว่า LibreOffice นั้นมี shell script ที่สามารถดึง source code ทั้งหมดออกมาได้ทีเดียว เรียกว่า g

ซึ่ง g ที่ว่านั้นอยุ่ใน bootstrap ที่เพิ่ง git ออกมานั่นเอง ทั้งนี้เมื่อเรา ได้ bootstrap มาแล้วเราสั่ง ./autogen.sh มันจะ check environment ทั้งหมดของเครื่องเราว่าสามารถที่จะ build LibreOffice ได้หรือไม่ และถ้าผ่านส่วนนั้นมาแล้ว มันจะไปเรียก g เพื่อ clone repository ทั้ง 19 repo มาไว้ที่เครื่องเราต่อไป

ดังนั้น source code ทั้งหมดนั้นเราจะใช้ git ในการ checkout หรือทำงานเฉยๆ ไม่ได้เพราะว่ามันต้องทำทีละ 19 repo แต่จากที่บอกไว้ทีแรก เราใช้ g ในการทำงานแทนได้ เพราะ g จะทำงานเหมือนกับคำสั่ง git แต่ว่าทำให้ทั้ง 19 repo เลยทีเดียว
Continue Reading...

วันศุกร์ที่ 14 มกราคม พ.ศ. 2554

First child CSS Selector

วันนี้จะมาเขียนเรื่องการใช้งาน CSS Selector ในส่วนของ First child element ซึ่งหมายถึงการระบุว่าจะทำงานกับ element แรกเท่านั้นดังตัวอย่าง

<html>
  <head>
    <title>CSS Selector</title>
  </head>
  <body>
    <div>
      <p>div1 line1</p>
      <p>div1 line2</p>
      <p>div1 line3</p>
    </div>
    <div>
      <p>div2 line1</p>
      <p>div2 line2</p>
      <p>div2 line3</p>
    </div>
  </body>
</html>

หากโจทย์ต้องการให้กำหนดสีให้กับ <p> แรกของแต่ละ div จะทำได้โดยใช้ :first-child ต่อหลัง tag ดังตัวอย่าง

<style type="text/css">
  div > p:first-child { color: red;}
</style>

เท่านั้น div1 line1 และ div2 line1 ก็จะมีตัวอักษรสีแดงแล้วครับ
Continue Reading...

วันพุธที่ 12 มกราคม พ.ศ. 2554

Function Bahteng บน OpenOffice.org Calc

เห็นมีคนถามมาเยอะว่าใน OpenOffice.org Calc มีฟังก์ชัน bahttext แต่ไม่เห็นมีฟังก์ชัน bahteng เลย ใน excel ยังมีเลยทำไมใน OpenOffice.org ถึงไม่มี

คำตอบคือใน excel นั้นฟังก์ชัน bahteng เป็น add-in function ที่มีคนทำขึ้นมาเสริมเข้าไปในตัวโปรแกรมซึ่งใน excel เพียวๆ นั้นไม่มีฟังก์ชัน bahteng

ใน OpenOffice.org Calc ก็เหมือนกันกับ excel คือตัวโปรแกรมนั้นไม่ได้มีฟังก์ชัน bahteng แต่มี Extension ที่เสริมเข้าไปให้ใช้งาน bahteng ได้แต่ไม่ได้ใช้ชื่อ bahteng จะใช้ชื่อ moneytext แทน

Extension ดังกล่าวมีชื่อว่า numbertext  ซึ่งเมื่อติดตั้ง extension แล้วจะมี function โผล่มาให้ใช้งาน 2 ฟังก์ชันคือ
  1. numbertext
  2. moneytext
โดยในส่วน bahteng ที่เราจะใช้กันนั้นจะเป็นฟังก์ชัน moneytext ซึ่งถ้าจะใช้งานก็ให้พิมพ์ลงใน Cell ว่า

=MONEYTEXT(25;"THB";"en")

ฟังก์ชันจะทำเลข 25 ให้กลายเป็นคำว่า twenty-five baht

ฟังก์ชัน numbertext และ moneytext นั้นสามารถพิมพ์ออกมาเป็นตัวอักษรได้ถึง 40 กว่าภาษา ซึ่งนั่นก็เป็นสาเหตุที่ว่าทำไมต้องกำหนดภาษาและสกุลเงินในฟังก์ชันนั่นเอง

numbertext นอกจากจะเป็น extension ของ OpenOffice.org ยังมีรูปแบบ อื่นๆ ให้ใช้กันได้อีกเช่น jar เป็นต้น สามารถดูรายละเอียดเพิ่มได้ที่ http://numbertext.org
Continue Reading...

วันศุกร์ที่ 7 มกราคม พ.ศ. 2554

ใช้งาน cookie บน javascript กับภาษาไทย

เผอิญได้โจทย์มาว่าใน contact form user นั้นควรกรอกแค่ครั้งเดียว ครั้งต่อไปเข้ามาหน้า contact ก็ไม่ควรต้องกรอกอีก ซึ่งผู้ที่จะกรอกนั้นจะเป็น anonymous ดังนั้นวิธีการที่จะทำให้หน้า contact จำค่าได้ก็คงต้องใช้ cookie

ปัญหาคือหน้า contact form นั้นอยู่ใน drupal ซึ่งเมื่อเปิด page cache แล้วมันจะทำให้ใช้งาน cookie สำหรับ anonymous ไม่ได้ ดังนั้นเลยต้องเลี่ยงไปใช้ cookie ของ javascript แทน

จาก tutorial http://www.w3schools.com/JS/js_cookies.asp ก็ดูเหมือนจะทำงานได้ดีแต่พอเรานำไปใช้จริงและกรอกค่าใน form เป็นภาษาไทย ผลลัพธ์ก็คือ ภาษาไทยเละ ดังนั้นเราจึงต้อง customize code กันนิดหน่อยเพื่อให้ใช้งานภาษาไทยได้

original code

function getCookie(c_name) {
  if (document.cookie.length > 0) {
    c_start = document.cookie.indexOf(c_name + "=");
    if (c_start != -1) {
      c_start = c_start + c_name.length+1;
      c_end = document.cookie.indexOf(";", c_start);
      if (c_end == -1) 
        c_end = document.cookie.length
      return unescape(document.cookie.substring(c_start,c_end));
    }
  }
  return "";
}

function setCookie(c_name, value,expiredays) {
  var exdate = new Date();
  exdate.setDate(exdate.getDate()+expiredays);
  document.cookie = c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

customized code

function getCookie(c_name) {
  if (document.cookie.length > 0) {
    c_start = document.cookie.indexOf(c_name + "=");
    if (c_start != -1) {
      c_start = c_start + c_name.length+1;
      c_end = document.cookie.indexOf(";", c_start);
      if (c_end == -1) 
        c_end = document.cookie.length
      return decodeURIComponent(document.cookie.substring(c_start,c_end));
    }
  }
  return "";
}

function setCookie(c_name, value,expiredays) {
  var exdate = new Date();
  exdate.setDate(exdate.getDate()+expiredays);
  document.cookie = c_name+ "=" +encodeURIComponent(value)+((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

เพื่อให้ใช้งานภาษาไทยได้ ต้องใช้ function encodeURIComponent แทน function escape แต่ปัญหายังไม่หมดแค่นี้ เมื่อเรา getCookie ที่ภายใน text นั้นมี space เข้ามาใช้งาน space ที่เคยพิมพ์เข้าไปจะกลายเป็นเครื่องหมาย + แทน ดังนั้นเราต้อง replace มันก่อนที่จะนำไปใช้งานด้วย

getCookie('c_name').replace(/\+/g, " ")

ซึ่ง /\+/ นั้นหมายถึงเครื่องหมาย + และ g หมายถึงให้ replace ทั้ง string
Continue Reading...

วันพฤหัสบดีที่ 6 มกราคม พ.ศ. 2554

แก้ปัญหา warning: Attempt to assign property of non-object ใน drupal เมื่อใช้งาน Google Adwords

 เมื่อมีการเปิดการใช้งาน google adwords ในหน้าใดก็ตาม จะเกิด error  warning: Attempt to assign property of non-object in ...... theme.inc ขึ้นที่หน้าดังกล่าว พอลองไปดูที่ตำแหน่งดังกล่าวจะเป็นส่วนของ language ซึ่งไม่น่าจะเกิด error ได้เลย

ปัญหาดังกล่าวจริงๆ แล้วเกิดขึ้นที่ module google adwords ซึ่งดันไปเรียกใช้งาน global variable ชื่อว่า language ตัวเดียวกันทำให้เกิด warning ขึ้น

วิธีการแก้ไขคือให้ไปที่ module google_adwords แก้ไข google_adwords.module ใน function _google_adwords_view_adwords ให้แก้ไขตาม code ด้านล่าง โดยเปลี่ยนชื่อตัวแปร $language ให้เป็นตัวอื่นซะ

if (arg(0) != 'admin' && $track > 0) {
  if($node->google_adwords['enabled'] <> 0) { 
   
    $label = $node->google_adwords['label'];
    $id = variable_get('google_adwords_conversion_id', 0);
    $google_conversation_language = variable_get('google_adwords_conversion_language', $language->language); //change variable from $language to $google_conversation_language
    $format = variable_get('google_adwords_conversion_format', '2');
    $color = variable_get('google_adwords_conversion_color', 'FFFFFF');
    $google_js = variable_get('google_adwords_external_script', 'https://www.googleadservices.com/pagead/conversion.js');
    
    $output = '';
    
    $output .= "\n" . '<!-- Google Code for Conversion Page -->' . "\n";
    $output .= '<script language="JavaScript" type="text/javascript">' . "\n";
    $output .= '<!--' . "\n";
    $output .= '    var google_conversion_id = '. $id .';' . "\n";
    $output .= '    var google_conversion_language = "'. $google_conversation_language .'";' . "\n"; //change variable from $language to $google_conversation_language
    $output .= '    var google_conversion_format = "'. $format .'";' . "\n";
    $output .= '    var google_conversion_color = "'. $color .'";' . "\n";
    $output .= '    var google_conversion_label = "'. $label .'";' . "\n";
    $output .= '//-->' . "\n";
    $output .= '</script>' . "\n";
    $output .= '<script language="JavaScript" src="' . $google_js . '"></script>' . "\n";
    $output .= '<noscript>' . "\n";
    $output .= '    <img height="1" width="1" border="0" src="https://www.googleadservices.com/pagead/conversion/' . $id . '/?label='. $label .'&amp;guid=ON&amp;script=0"/>' . "\n";
    $output .= '</noscript>' . "\n";
       
    return $output;
    
  }
}

ที่มา http://goo.gl/EvPvO
Continue Reading...

วันพุธที่ 5 มกราคม พ.ศ. 2554

แก้ปัญหาชื่อภาษาไทยบน Alfresco เละใน Version 3.4 บน Windows

เมื่อลง Alfresco 3.4 บน Windows แล้วเมื่อสร้าง Space หรือไฟล์ที่มีชื่อภาษาไทยแล้ว ชื่อไฟล์ดังกล่าวจะกลายเป็น ????

ปัญหาดังกล่าวเกิดจาก default character set ใน MySQL ไม่ได้ถูกตั้งค่าให้เป็น UTF-8 เหมือน Version ก่อนๆ ทำให้ Table ที่สร้างขึ้นมาไม่ได้มี Collation เป็น UTF-8 เมื่อมีการ Insert ภาษาไทยเข้าไปใน Table จึงทำให้ภาษาไทยเละ

วิธีการแก้ไขคือเราต้อง alter table ให้มันกลายเป็น UTF-8 ซะก่อนซึ่งจะให้ alter ที่ละ table มันก็จะเหนื่อยไปนิด ดังนั้นก็เลยเขียน php เพื่อที่จะ alter table ให้กลายเป็น UTF-8 ทั้งหมดซะ

<?php
  $db = mysql_connect('localhost','username','password');
  if(!$db) echo "Cannot connect to the database - incorrect details";
  mysql_select_db('alfresco');
  mysql_query('ALTER DATABASE CHARACTER SET utf8');
  $result=mysql_query('show tables');
  while($tables = mysql_fetch_array($result)) {
    foreach ($tables as $key => $value) {
      mysql_query("ALTER TABLE $value CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci");
    }
  }
?>

เมื่อรันแล้วให้ลอง restart alfresco ซักทีนึงแล้วก็ลองดูว่าภาษาไทยสามารถใช้งานได้หรือยัง ถ้ายังให้ไป set default character ใน MySQL ให้เป็น UTF-8 ตาม link นี้ครับ http://www.leknarm.com/2010/01/set-mysql-utf8.html
--
Tantai Thanakanok. Open Source Development Co., Ltd.
Tel: +66 38 311816, Fax: +66 38 773128, http://www.osdev.co.th/
Continue Reading...

Blogroll

About