OSDN Git Service

add ACS webapp, sql, htdocs
[acs/acs.git] / webapp / lib / class / ACSCss.class.php
diff --git a/webapp/lib/class/ACSCss.class.php b/webapp/lib/class/ACSCss.class.php
new file mode 100644 (file)
index 0000000..0ee23a6
--- /dev/null
@@ -0,0 +1,142 @@
+<?php
+/**
+ * ACS Css
+ *
+ * @author  z-satosi
+ * @version $Revision: 1.1 $ $Date: 2007/03/27 02:12:31 $
+ */
+class ACSCss 
+{
+       /* css¥Õ¥¡¥¤¥ë */
+       var $css_file_path;
+
+       /* css¥Õ¥¡¥¤¥ëÆâÍÆ */
+       var $css_file_contents;
+
+       /**
+        * ¥³¥ó¥¹¥È¥é¥¯¥¿
+        *
+        * @param string $css_file_path css¥Õ¥¡¥¤¥ë¥Ñ¥¹
+        */
+       function ACSCss ($css_file_path) {
+               $this->set_css_contents ($css_file_path);
+       }
+
+       /**
+        * css¥Õ¥¡¥¤¥ë¤Î¼è¤ê¹þ¤ß (¼«Æ°´Á»úÊÑ´¹Âбþ)
+        *
+        * @param string $css_file_path css¥Õ¥¡¥¤¥ë¥Ñ¥¹
+        * @return mixed Àµ¾ï»þ...¥Õ¥¡¥¤¥ëÆâÍÆ/¥¨¥é¡¼»þ...FALSE
+        */
+       function set_css_contents ($css_file_path) {
+               $this->css_file_path = $css_file_path;
+               $contents =& implode(NULL, file($css_file_path));
+               $this->css_file_contents = mb_convert_encoding(
+                               $contents, mb_internal_encoding(), mb_detect_encoding($contents) ) ;
+               return $this->css_file_contents;
+       }
+
+       /**
+        * acs¥¹¥¿¥¤¥ëÁªÂò¾ðÊó¤Î¼èÆÀ
+        *
+        * @param string $lang ¸À¸ì¼ïÊÌ
+        * @param string $encoding Ê¸»ú¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°
+        */
+       function get_style_selection_info_array ($lang,$encoding='') {
+
+               if ($encoding != '') {
+                       mb_regex_encoding($encoding);
+               }
+
+               $pattern = 'acs_style_selection[ \t]*\{([^\}]+)\}';
+
+               $result = mb_ereg($pattern, $this->css_file_contents, $regs);
+
+               if ($result != FALSE) {
+
+                       $styles = trim($regs[1]);
+                       $pattern_fmt = '.*%s[ \t\n\r\f\v]*:*([^;]+);';
+
+                       $result = array();
+
+                       // ³Æ¥Ñ¥é¥á¡¼¥¿¤Î¼èÆÀ
+                       mb_ereg(sprintf($pattern_fmt, 'show_list'), $styles, $regs);
+                       $result['show_list'] = trim($regs[1]);
+
+                       mb_ereg(sprintf($pattern_fmt, 'display_order'), $styles, $regs);
+                       $result['display_order'] = trim($regs[1]);
+
+                       // ¸À¸ì°Í¸¥Ñ¥é¥á¡¼¥¿¤Î¼èÆÀ
+                       mb_ereg(sprintf($pattern_fmt, 'name\.'.$lang), $styles, $regs);
+                       $result['name'] = trim($regs[1]);
+
+                       mb_ereg(sprintf($pattern_fmt, 'description\.'.$lang), $styles, $regs);
+                       $result['description'] = trim($regs[1]);
+
+                       mb_ereg(sprintf($pattern_fmt, 'thumbnail\.'.$lang), $styles, $regs);
+                       $result['thumbnail'] = trim($regs[1]);
+
+                       $result['filename'] = basename($this->css_file_path);
+               }
+
+               return $result;
+       }
+
+       /* Static functions */
+
+       /**
+        * acs¥¹¥¿¥¤¥ëÁªÂò¾ðÊó¤Î¼èÆÀ
+        *
+        * @param string $lang ¼èÆÀ¤¹¤ë¾ðÊó¤Î¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°
+        * @param string $styles_dir_path css¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤¹¤ë¥Ç¥£¥ì¥¯¥È¥ê¥Ñ¥¹
+        * @param string $match_pattern Âоݥե¡¥¤¥ë¤Î¥Þ¥Ã¥Á¥Ñ¥¿¡¼¥ó
+        * @return array ¥¹¥¿¥¤¥ë¾ðÊó¤ÎÇÛÎó
+        */
+       static function get_style_selection_list_array($lang, $styles_dir_path, $match_pattern='/.*\.css/') {
+
+               $d = dir($styles_dir_path);
+
+               $styles_array = array();
+
+               while (false !== ($file_entry = $d->read())) {
+                       //if (fnmatch($match_pattern, $file_entry)) {
+                       if (preg_match($match_pattern, $file_entry)) {
+                               $css = new ACSCss($styles_dir_path.'/'.$file_entry);
+                               $styles_array[$file_entry] =& $css->get_style_selection_info_array($lang);
+                       }
+               }
+               $d->close();
+
+               // display_order
+               $order_index = array();
+               foreach ($styles_array as $key => $value) {
+                       $order_index[$key] = $value['display_order'];
+               }
+               asort($order_index);
+               $sort_styles_array = array();
+               foreach ($order_index as $key => $value) {
+                       $sort_styles_array[] = $styles_array[$key];
+               }
+
+               return $sort_styles_array;
+       }       
+       
+       
+       /**
+        * ¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°¼ïÎà¤Î¼èÆÀ
+        *
+        * @param string $data Ê¸»úÎó
+        */
+       function getEncodingType($data){
+               $encodingArray = array("ISO-2022-JP","UTF-8","Shift-JIS","EUC-JP","ASCII");
+               $n = 0;
+       
+               while($focusEncoding = $encodingArray[$n]){
+                       if(mb_check_encoding($data,$focusEncoding)) return $focusEncoding;
+                       $n++;
+               }
+               return "nil";
+       }
+}
+
+?>