source: extensions/cuise/admin/admin.inc.php @ 19486

Last change on this file since 19486 was 19486, checked in by cljosse, 11 years ago

[style cuise] create cuise

File size: 12.6 KB
Line 
1<?php
2load_language('theme.lang', PHPWG_THEMES_PATH.'cuise/');
3$params = array_merge(unserialize($conf['cuise']));
4
5if (!defined('PHPWG_ROOT_PATH'))
6{
7  die ("Hacking attempt!");
8}
9
10include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
11include_once(PHPWG_ROOT_PATH.'include/template.class.php');
12include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
13
14
15check_status(ACCESS_ADMINISTRATOR); 
16global $themeconf,$parent,$user;
17 global $nb_template;
18 $nb_template=5 ;
19global $id;
20
21include_once(PHPWG_ROOT_PATH.'themes/cuise/themeconf.inc.php');
22$save_options=false ;
23
24 define ('PHPWG_THEME_PATH',PHPWG_THEMES_PATH.$themeconf['name']."/" );
25
26$my_base_url="admin.php?page=theme&amp;theme=".$themeconf['name'];
27$tabsheet = new tabsheet();
28$tabsheet->add( 'admin',
29                l10n('admin'),
30                $my_base_url.'&amp;tab=admin'
31                           );
32 
33$tabsheet->add( 'texture',
34                l10n('texture'),
35                $my_base_url.'&amp;tab=texture'
36                           );
37                           
38   
39                           
40        if (!isset($_GET['tab']))
41           $page['tab'] = 'admin';
42else
43       $page['tab'] = $_GET['tab'];     
44           
45 $tabsheet->select($page['tab']);
46 $tabsheet->assign();
47 /*************************
48 *
49 *************************/
50 if(!function_exists("cl_print_var")){
51   function cl_print_var($variables){
52    ob_start();
53    echo '<pre>';
54    print_r($variables);
55    echo '</pre>';
56    $m= ob_get_contents();
57    ob_end_clean();
58    return $m;         
59  }
60}
61
62
63if (isset($_POST['submit'])){
64 $val_id=$_POST['submit'];
65  $save_options=true ;
66}
67if (isset($_POST['compiled-templates']) ){
68      $template->delete_compiled_templates();
69      $FileCombiner = new  FileCombiner("tpl") ;
70      $FileCombiner::clear_combined_files();
71    //  array_push($page['infos'],l10n('parent') . ":" . $_POST['compiled-templates']);
72      array_push($page['infos'], l10n('delete_compiled'));
73      $parent=$_POST['compiled-templates'];
74      $save_options=true ;
75  }
76for($id=0;$id<$nb_template;$id++){
77  if (!isset($params["chk_cuise_$id"])){
78      $_POST['default']=true ;
79  }
80}
81 $id=0;
82
83
84if (isset($_POST['default']) || !isset($params['chk_cuise_0'])   ){
85 
86  $params['parent']=  $parent ;
87   $params['theme']=  'cuise' ;
88  $name=array("cbmt.gif","bpv.png","bp3.jpg","bph.png","header.png");
89  for($id=0;$id<$nb_template;$id++){
90  $params  = array_merge($params,array(                         
91                                                "bg_cuise_$id"                  => '#FFA800',
92                                                "bgho_cuise_$id"                        => '#0072FF',
93                                                "bd_cuise_$id"                  => '#4F4F4F',
94                                                "co_cuise_$id"            => '#4F4F4F',
95            "coho_cuise_$id"              => '#F4F4F4',
96            "img_cuise_$id"    =>   $name[$id],
97            "rayon_cuise_$id"    => '8px',
98            "chk_cuise_$id"      => '',
99            "chk_cuise_x_$id"      => '',
100            "chk_cuise_y_$id"      => '',
101           
102            ));
103            }
104            $id=0;
105    array_push($page['warnings'], cl_print_var($params));
106       $save_options=true ;
107
108}
109$params = array_merge(unserialize($conf['cuise']));
110
111
112if ($save_options==true) {
113  $i="0"; 
114  $New_params=array();
115  $j=$i;
116  for($i=0;$i<$nb_template;$i++){
117   if( isset($_POST["bg_cuise_$i"]) ) {
118
119   $img_src= (isset($_POST["img_cuise_$i"])&&$_POST["img_cuise_$i"]!="")?$_POST["img_cuise_$i"]:$params["img_cuise_$i"] ;
120 
121        $New_params  = array(               
122                                          "bg_cuise_$i"                 => isset($_POST["bg_cuise_$i"])?$_POST["bg_cuise_$i"]:$params["bg_cuise_$i"], 
123            "bgho_cuise_$i"                     => isset($_POST["bgho_cuise_$i"])?$_POST["bgho_cuise_$i"]:$params["bgho_cuise_$i"], 
124                                          "bd_cuise_$i"                 => isset($_POST["bd_cuise_$i"])?$_POST["bd_cuise_$i"]:$params["bd_cuise_$i"], 
125                                          "co_cuise_$i"          => isset($_POST["co_cuise_$i"])?$_POST["co_cuise_$i"]:$params["co_cuise_$i"], 
126                                          "coho_cuise_$i"                => isset($_POST["coho_cuise_$i"])?$_POST["coho_cuise_$i"]:$params["coho_cuise_$i"], 
127            "img_cuise_$i"    =>$img_src, 
128            "rayon_cuise_$i"    => isset($_POST["rayon_cuise_$i"])?$_POST["rayon_cuise_$i"]:$params["rayon_cuise_$i"],   
129            "chk_cuise_$i"    => isset($_POST["chk_cuise_$i"])?"checked":"no", 
130            "chk_cuise_x_$i"    => isset($_POST["chk_cuise_x_$i"])?"checked":"no",       
131            "chk_cuise_y_$i"    => isset($_POST["chk_cuise_y_$i"])?"checked":"no",     
132            );
133            $id=$i;
134            break;
135        }
136}
137
138 $i=$j; 
139  $params  = array_merge($params,$New_params ,array('parent' => $parent,
140  "theme" => PHPWG_THEMES_PATH.$themeconf['name']."/"
141  ));
142 
143// array_push($page['warnings'],  print_r($params,true));
144  conf_update_param('cuise', pwg_db_real_escape_string(serialize($params)));
145  array_push($page['infos'], l10n('Your configuration settings are saved'));
146  load_conf_from_db();
147  $params = array_merge(unserialize($conf['cuise']));
148  $keys=$params;
149}
150
151// array_push($page['warnings'], print_r($parent,true) );
152//  array_push($page['warnings'], print_r($params,true));
153
154$params = array_merge(unserialize($conf['cuise']));
155
156$name_tpl = array("fondBG","fondBp","fondHoriz","fondVert","Header" );
157
158
159if(isset($val_id)){
160  $ids = explode("_",$val_id) ;
161  $id= ( isset($ids[1]) ) ? $ids[1]  :0;
162 
163 }
164$id=  isset( $_POST["sel_tab"]  ) ? $_POST["sel_tab"]: $id;
165 
166 if(!isset($id)) $id=0;
167  //==============================================
168 // $list_themes = get_list_dirs("themes");
169 
170  get_list_theme();
171
172
173$template->assign(array(
174             'root' => PHPWG_ROOT_PATH,
175            'theme' => PHPWG_THEME_PATH,
176             "classeRoot" =>  PHPWG_THEMES_PATH.'cuise/admin/classes/' ,
177            'parent'            => $parent,
178             
179            'nb_template' => $nb_template,
180            'ind'                       => $id,
181            'name_tpl'                  => $name_tpl,
182                                                'selected_bg_cuise'                     => $params['bg_cuise_'.$id],
183            'selected_bgho_cuise'                       => $params['bgho_cuise_'.$id],
184                                                'selected_bd_cuise'                     => $params['bd_cuise_'.$id],
185                                                'selected_co_cuise'             => $params['co_cuise_'.$id],
186            'selected_coho_cuise'               => $params['coho_cuise_'.$id],
187            'selected_img_cuise'                => $params['img_cuise_'.$id],
188'selected_x_cuise'              => $params['chk_cuise_x_'.$id],
189'selected_y_cuise'              => $params['chk_cuise_y_'.$id],
190            'selected_rayon_cuise'              => $params['rayon_cuise_'.$id],
191
192            'selected_chk_cuise'                => ($params['chk_cuise_'.$id]=="checked")?"checked":"",
193            'params'            => pwg_db_real_escape_string(serialize($params)),
194
195                                                ));
196//===============================================
197 if (isset($_GET['hlp'])){
198   global      $BGIMGcss, $BGcolcss;
199  if ($_GET['hlp']=="1") 
200        $theme_css= "themes/".$themeconf['name']."/theme.css.css";
201    else if ($_GET['hlp']=="2") 
202        $theme_css= "themes/".$themeconf['parent']."/theme.css";
203    else if ($_GET['hlp']=="3") 
204        $theme_css= "themes/".$themeconf['name']."/theme.css.php";
205    else {
206    $path="themes/".$themeconf['name']."/";
207    $theme_css=$path."theme.css.php";
208      if(!file_exists($theme_css)){
209               $theme_css=$path."css/style.css";
210               if(!file_exists($theme_css)){             
211                  $theme_css=$path."css/theme.css";
212                  if(!file_exists($theme_css)){     
213                      $theme_css=$path."style.css";
214                      if(!file_exists($theme_css)){     
215                         $theme_css=$path."theme.css";
216                  }
217                  }
218               }
219
220         
221        }
222    }
223  $arguments = $conf['cuise'];
224
225$Css =css($theme_css); 
226
227$message  =$theme_css."<br>";
228//$message .= cl_print_var($Css)."<br>";
229//$message .= cl_print_var($BGIMGcss)."<br>";
230$message .= cl_print_var($BGcolcss)."<br>";
231
232   array_push($page['infos'], $message);
233}
234//===============================================
235
236$template->assign('options', unserialize($conf['cuise']));
237switch ($page['tab']) {
238 case 'admin':
239     $template->set_filenames(array('theme_admin_content' => dirname(__FILE__) . '/cuise_admin.tpl'));
240     $template->assign_var_from_handle('ADMIN_CONTENT', 'theme_admin_content');
241 break;
242 case 'texture':
243$template->set_filenames(array('theme_admin_content' => dirname(__FILE__) . '/cuise_texture.tpl'));
244  $template->assign_var_from_handle('ADMIN_CONTENT', 'theme_admin_content');
245  break ;
246
247}
248
249//================================================
250function css($theme_local) {   
251 global      $BGIMGcss, $BGcolcss;
252 $BGIMGcss=Array();
253     $BGcolcss=Array();
254     
255    $path = $_SERVER['DOCUMENT_ROOT'];
256    if (substr($path,-1)=='/'){
257              $path =  substr($path,0,-1);
258          }
259     if(isset($_GET['path'])) 
260              $path=$_GET['path'];
261          else
262              $path=PHPWG_ROOT_PATH."local/css/";
263
264            $path="";
265              $mycssfile=$path.$theme_local;
266
267              if(!file_exists($theme_local))
268           
269               $mycssfile=$path."default-rules.css";
270
271               if(!file_exists($mycssfile)){             
272              return Array();
273               }
274
275 
276
277function remove_comments( & $string ) { 
278    $order   = array("/}/","/\r\n/",'#/\*.*?\*/#s','/\n/','/\r/','/\s[\s]+/');
279    $replace = array('}|' ,''      ,''            ,''    ,''    ,''         );
280  $string = preg_replace($order, $replace,$string); 
281  echo  ($string)."<br>"; 
282    //  $string = preg_replace('#/\*.*?\*/#s',"",$string);
283       return $string;
284}
285   
286 $ret =   file_get_contents ($mycssfile); 
287   echo $ret;
288
289  $string= remove_comments( $ret);
290 echo  ($string);   
291
292    $newstr = explode('|',$ret);
293    $css=Array();
294     $BGIMGcss=Array();
295     $BGcolcss=Array();
296    $order   = array('/[\s]+/','/}/');
297    $replace = array(' ',"");
298
299
300  foreach ($newstr as $key => $value) {   
301   
302   $value = preg_replace($order, $replace, $value); 
303    $value = trim($value);   
304
305
306   if($value){
307echo $value."<br>";
308      $css2=Array();
309      $key = explode("{",$value); 
310      $key_id=   $key[0];
311      if(isset($key[1]))
312      $value = $key[1] ;
313     
314      $value=explode(";",$value); 
315           foreach ($value as $key2 => $value2) {   
316            if($value2){
317           
318            $value2 = str_replace(" ", '', $value2); 
319           
320
321              $key2=explode(":",$value2);   
322              if(isset($key2[1])) {       
323                $key2[0]=trim($key2[0]); 
324                $css2[$key2[0]] = trim($key2[1]) ; 
325               
326
327                if(preg_match("/url/",$key2[1])){
328                   $head = preg_replace("#(.*)url.(.*?)\)(.*)#is", '$2', $key2[1]);   
329                   echo  $head." ".$key2[0]." ".$key_id."<br>";
330                    $BGIMGcss[$head]=array_merge(array(
331                    "head" => $head,
332                    "clef" => $key_id,
333                    "val" => $key2[0],
334                    ));
335                 
336                  }elseif(preg_match("/(color)/",$key2[0])){ 
337                      $head = preg_replace("#(.*)color.(.*?);(.*)#is", '$2', $key2[1]);
338                      echo  $head." ".$key2[0]." ".$key_id."<br>";
339                     
340                   $BGcolcss[$head]=array_merge(array(
341                    "head" => $head,
342                    "clef" => $key_id,
343                    "val" => $key2[0],
344                    ));
345                 
346                  }else{
347                    // echo " no " . $key_id . "{" . $key2[0] . " : " . $key2[1] ."}<br>";
348                  }
349               }
350            }
351           }     
352         
353             
354      $css[$key_id]=$css2 ;
355     }   
356}
357echo cl_print_var($css);
358die();
359             return $css;
360        }
361
362
363function get_list_theme()
364{
365  global $user, $template, $conf,$parent; 
366  foreach (get_pwg_themes() as $id => $name) {
367    $img =  PHPWG_THEMES_PATH.$id.'/screenshot.png';         
368    if (file_exists($img)) {
369      $theme = array(
370        'id' => $id,
371        'name' => $name,
372        'url' => add_url_params( duplicate_index_url(), array('theme'=>$id) ),
373        'img' => $img,
374        );       
375      if ($id==$parent){
376        $template->assign('list_themes_active', $theme);
377      }
378     
379      $template->append('list_themes', $theme);
380    }
381  } 
382  }
383
384function get_list_dirs($path='')
385{
386  $options = array();
387 global $parent ;
388 $options= array(); 
389  if (is_dir($path)) {
390    $fh = opendir($path);
391    while ($file = readdir($fh))
392    {
393      $pathfile = $path . '/' . $file;
394      if ($file != '.' and $file != '..' and $file != '.svn' and is_dir($pathfile))
395      {
396 
397
398    $options[$file] = array(
399      'name' => $file,
400      'url' => $pathfile,
401      'select' =>  ($file==$parent) ? 'selected="selected"' :  "false",
402      );
403 
404      }
405    }
406    closedir($fh);
407  } 
408  return $options;
409}
410
411
412 ?>
Note: See TracBrowser for help on using the repository browser.