/[drupal]/contributions/modules/jcss/jcss.module
ViewVC logotype

Contents of /contributions/modules/jcss/jcss.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Thu Mar 22 23:26:54 2007 UTC (2 years, 8 months ago) by avior
Branch: MAIN
CVS Tags: DRUPAL-5--1-5, HEAD
Changes since 1.2: +74 -73 lines
File MIME type: text/x-php
another try for the module
version 1.3 added new functionalty
1 <?php
2 /* $Id: jcss.module,v 1.3 23/3/2007 By Avior Nissim http://dev-art.net
3 *
4 * This module will do the following replacments
5 * margin-right <==> margin-left
6 * padding-right <==> padding-left
7 * margin and padding with 4 elements => replace the second and the forth so
8 * margin : 1 2 3 4; will become margin 1 4 3 2;
9 *
10 * version :1.3
11 * ==================
12 * added float : swap right and left
13 * added text-align : swap right and left,
14 * added all left to right swap i.e. left, margin-left, padding-left, border-left
15 * backgound or backgroung-position : will swap left and right,
16 *
17 * did you used the module to RTL themes ?
18 * please upload the theme to drupal site so everyone can use it
19 */
20
21 define("JCSS_TMP_VALUE","jcss_tmp_value");
22
23 function jcss_help($section){
24 switch($section){
25 case 'admin/modules#description':
26 return t('Regex engine to convert css file to RTL.');
27 break;
28 }
29 }
30
31 function jcss_menu($may_cache){
32 $items = array();
33 if ($may_cache){
34 $items[] = array('path'=>'jcss', 'title'=> t('jcss '), 'access' => user_access('access content'), 'callback' => 'jcss_page');
35 }
36 return $items;
37 }
38
39 function jcss_page(){
40 $output = drupal_get_form('jcss_page_form');
41 return $output;
42 }
43
44 function jcss_page_form() {
45 $form = array();
46 $form['help'] = array('#type' => 'markup', '#value' => t('<p>paste in the LTR CSS field the original Css you wish to RTL<p>'));
47 $form['ltrcss'] = array('#type' => 'textarea', '#title'=> t('LTR Css'), '#rows' =>5,'#default_value' => $_SESSION['jcss']['ltrcss']);
48 $form['rtlcss'] = array('#type' => 'textarea', '#title'=> t('RTL Css (coverted Version)'), '#rows' => 10,'#default_value' => $_SESSION['jcss']['rtlcss']);
49 $form['submit'] = array('#type' => 'submit', '#value' => t('submit'));
50 return $form;
51 }
52
53
54 function jcss_page_form_validate($form_id, $form_values,$form) {
55
56 }
57
58 function jcss_page_form_submit($form_id, $form_values) {
59 $_SESSION['jcss']['ltrcss'] = $form_values['ltrcss'];
60 $_SESSION['jcss']['rtlcss'] = get_rtl_css($form_values['ltrcss']);
61 drupal_set_message(t('Done'));
62 }
63
64
65 function get_rtl_css($s){
66
67 //$m = '/body\s{0,}\{(.+)\}/i';
68 //$r = "body { $1 direction : rtl;} /* JCss.Add direction right to left */";
69 //$s = preg_replace($m,$r,$s);
70
71 // margin or padding 4 parameters
72 $m = '/((margin|padding)\s{0,}:\s{0,}(.+) (.+) (.+) (.+));/i';
73 $r = "$2: $3 $6 $5 $4; /* JCss.Old $1 */";
74 $s = preg_replace($m,$r,$s);
75
76
77 // match items with left word:
78 // left, margin-left, padding-left, border-left
79 // <Text>left : XX <==> <Text>right :XX
80 $m = '/((left)\s{0,}:\s{0,}(.+));/i';
81 $r = "JCSS_TMP_VALUE: $3;";
82 $s = preg_replace($m,$r,$s);
83
84 //right => left
85 $m = '/((right)\s{0,}:\s{0,}(.+));/i';
86 $r = "left: $3; /* JCss.Old right $1 */";
87 $s = preg_replace($m,$r,$s);
88
89 //tmp-left => right
90 $m = '/((JCSS_TMP_VALUE)\s{0,}:\s{0,}(.+));/i';
91 $r = "right: $3; /* JCss.Old left $1 */";
92 $s = preg_replace($m,$r,$s);
93
94
95
96 $s = swap_elements('text-align\s:\sleft\s;','text-align\s:\sright\s;',$s);
97 $s = swap_elements('float\s:\sleft\s;','float\s:\sright\s;',$s);
98
99 //background & background-position Right <==> Left
100
101 // Left => tmp
102 $m = '/((background|background-position)\s{0,}:\s{0,}(.+)(left)(.+));/i';
103 $r = "$2: $3JCSS_TMP_VALUE$5;";
104 $s = preg_replace($m,$r,$s);
105
106 //Right => Left
107 $m = '/((background|background-position)\s{0,}:\s{0,}(.+)(right)(.+));/i';
108 $r = "$2: $3left$5; /* JCss.Old $1 */";
109 $s = preg_replace($m,$r,$s);
110
111 //tmp => Right
112 $m = '/((background|background-position)\s{0,}:\s{0,}(.+)(JCSS_TMP_VALUE)(.+));/i';
113 $r = "$2: $3right$5; /* JCss.Old $2:$3left$5 */";
114 $s = preg_replace($m,$r,$s);
115
116
117 // check background X and Y is not so simple...
118 //$m = '/((background|background-position)\s{0,}:\s{0,}(.+)(.+%)(.+)(.+%));/i';
119 // $4 is the X 0,1 should become 100%
120 // 100% should become 0
121 //$r = "$2: $3$4$5$6; /* JCss.Old $1 */";
122 //$s = preg_replace($m,$r,$s);
123
124
125 return $s;
126 }
127
128
129 // $e1 sample : text-align\s:\s left\s;
130 // $e2 sample : text-align\s:\s right\s;
131 // "\s" stands for any spaces will become \s{0,}
132 function swap_elements($e1, $e2,$s){
133 $m1 = str_replace('\s','\s{0,}',$e1);
134 $r1 = str_replace('\s','',$e1);
135 $r1 = str_replace(':',': ',$r1); //add space after :
136
137 $m2 = str_replace('\s','\s{0,}',$e2);
138 $r2 = str_replace('\s','',$e2);
139 $r2 = str_replace(':',': ',$r2); //add space after :
140
141 //text-align:left ==> text-align:tmp-left
142 $m = '/'.$m1.'/i';
143 $r = JCSS_TMP_VALUE; //'jcss.tmp.value';
144 $s = preg_replace($m,$r,$s);
145
146 //text-align: right=> text-align: left
147 $m = '/'.$m2.'/i';
148 $r = $r1 .' /* JCss.Old '.$r2.' */';
149 $s = preg_replace($m,$r,$s);
150
151 //text-align:tmp-left => text-align: right
152 $m = JCSS_TMP_VALUE; //'jcss.tmp.value';
153 $r = $r2 .' /* JCss.Old '.$r1.' */';
154 $s = str_replace($m,$r,$s);
155
156 return $s;
157 }
158
159
160
161 ?>

  ViewVC Help
Powered by ViewVC 1.1.2