public
Description: Git mirror of the CMS Made Simple 2.0 rewrite
Homepage: http://cmsmadesimple.org
Clone URL: git://github.com/tedkulp/cmsmadesimple-2-0.git
Basic multilanguage content editing.  Still not working for add yet.
Rewrote CmsDateTime a bit to be properly serializable.

Signed-off-by: Ted Kulp <tedkulp@bootcamp.(none)>


git-svn-id: http://svn.cmsmadesimple.org/svn/cmsmadesimple/trunk@4239 
3d254a34-79dc-0310-9e5f-be208747d8a0
tedkulp (author)
Mon Oct 29 19:25:40 -0700 2007
commit  e93c6bb6c7041210948b9a69851d7ab8b171ab0a
tree    60c9f888cdb3dd1f6f105abfee1744b309ca9552
parent  dc5c52787587f24c177e99e213f8d29df811e494
...
43
44
45
 
 
46
47
48
...
98
99
100
101
 
102
103
104
...
107
108
109
110
 
111
112
113
...
151
152
153
 
154
155
156
157
158
159
 
160
161
162
...
180
181
182
 
183
184
185
186
187
 
188
189
190
...
203
204
205
206
 
207
208
209
...
223
224
225
226
227
 
 
228
229
230
...
273
274
275
 
 
 
 
 
276
277
278
...
291
292
293
294
295
 
 
296
297
298
...
300
301
302
303
 
304
305
306
...
43
44
45
46
47
48
49
50
...
100
101
102
 
103
104
105
106
...
109
110
111
 
112
113
114
115
...
153
154
155
156
157
158
159
160
161
 
162
163
164
165
...
183
184
185
186
187
188
189
190
 
191
192
193
194
...
207
208
209
 
210
211
212
213
...
227
228
229
 
 
230
231
232
233
234
...
277
278
279
280
281
282
283
284
285
286
287
...
300
301
302
 
 
303
304
305
306
307
...
309
310
311
 
312
313
314
315
0
@@ -43,6 +43,8 @@ $smarty->assign('action', 'editcontent.php');
0
 $content_id = coalesce_key($_REQUEST, 'content_id', '-1');
0
 $page_type = coalesce_key($_REQUEST, 'page_type', 'content');
0
 $orig_page_type = coalesce_key($_POST, 'orig_page_type', 'content');
0
+$current_language = coalesce_key($_POST, 'current_language', 'en_US');
0
+$orig_current_language = coalesce_key($_POST, 'orig_current_language', 'en_US');
0
 $preview = array_key_exists('previewbutton', $_POST);
0
 $submit = array_key_exists('submitbutton', $_POST);
0
 $apply = array_key_exists('applybutton', $_POST);
0
@@ -98,7 +100,7 @@ function copycontentobj(&$page_object, $page_type)
0
   $page_object = $tmpobj;
0
 }
0
 
0
-function &get_page_object(&$page_type, &$orig_page_type, $userid, $content_id, $params)
0
+function &get_page_object(&$page_type, &$orig_page_type, $userid, $content_id, $params, $lang = 'en_US')
0
 {
0
   global $gCms;
0
 
0
@@ -107,7 +109,7 @@ function &get_page_object(&$page_type, &$orig_page_type, $userid, $content_id, $
0
   if (isset($params["serialized_content"]))
0
   {
0
     $page_object = unserialize_object($params["serialized_content"]);
0
- $page_object->update_parameters($params['content']);
0
+ $page_object->update_parameters($params['content'], $lang);
0
     if (strtolower(get_class($page_object)) != $page_type)
0
     {
0
       copycontentobj($page_object, $page_type);
0
@@ -151,12 +153,13 @@ function change_block_type($params, $block_id, $new_block_type)
0
   $content_id = coalesce_key($params, 'content_id', '-1');
0
   $page_type = coalesce_key($params, 'page_type', 'content');
0
   $orig_page_type = coalesce_key($params, 'orig_page_type', 'content');
0
+ $orig_current_language = coalesce_key($params, 'orig_current_language', 'en_US');
0
   
0
   $userid = get_userid();
0
   $config = cms_config();
0
   $smarty = cms_smarty();
0
 
0
- $page_object = get_page_object($page_type, $orig_page_type, $userid, $content_id, $params);
0
+ $page_object = get_page_object($page_type, $orig_page_type, $userid, $content_id, $params, $orig_current_language);
0
   $type_param = $block_id . '-block-type';
0
   $div_id = 'content-form-' . $block_id;
0
   $page_object->$type_param = $new_block_type;
0
@@ -180,11 +183,12 @@ function ajaxpreview($params)
0
   $content_id = coalesce_key($params, 'content_id', '-1');
0
   $page_type = coalesce_key($params, 'page_type', 'content');
0
   $orig_page_type = coalesce_key($params, 'orig_page_type', 'content');
0
+ $orig_current_language = coalesce_key($params, 'orig_current_language', 'en_US');
0
   $userid = get_userid();
0
   
0
   $config =& cmsms()->GetConfig();
0
 
0
- $page_object = get_page_object($page_type, $orig_page_type, $userid, $content_id, $params);
0
+ $page_object = get_page_object($page_type, $orig_page_type, $userid, $content_id, $params, $orig_current_language);
0
   $tmpfname = create_preview($page_object);
0
   $url = $config["root_url"] . '/index.php?tmpfile=' . urlencode(basename($tmpfname));
0
   
0
@@ -203,7 +207,7 @@ function ajaxpreview($params)
0
 }
0
 
0
 //Get a working page object
0
-$page_object = get_page_object($page_type, $orig_page_type, $userid, $content_id, $_REQUEST);
0
+$page_object = get_page_object($page_type, $orig_page_type, $userid, $content_id, $_REQUEST, $orig_current_language);
0
 
0
 //Preview?
0
 $smarty->assign('showpreview', false);
0
@@ -223,8 +227,8 @@ else if ($access)
0
 {
0
   if ($submit || $apply)
0
   {
0
- $page_object->set_property_value('name', $_REQUEST['name'], 'en_US');
0
- $page_object->set_property_value('menu_text', $_REQUEST['menu_text'], 'en_US');
0
+ $page_object->set_property_value('name', $_REQUEST['name'], $orig_current_language);
0
+ $page_object->set_property_value('menu_text', $_REQUEST['menu_text'], $orig_current_language);
0
     if ($page_object->save())
0
     {
0
       $contentops->SetAllHierarchyPositions();
0
@@ -273,6 +277,11 @@ $smarty->assign_by_ref('page_object', $page_object);
0
 $smarty->assign('serialized_object', serialize_object($page_object));
0
 $smarty->assign('orig_page_type', $orig_page_type);
0
 
0
+//Language related stuff
0
+$smarty->assign('languages', CmsLanguage::get_language_list(true));
0
+$smarty->assign('current_language', $current_language);
0
+$smarty->assign('orig_current_language', $current_language); //orig_current_language should match current_language now that saves and stuff are done
0
+
0
 //Can we preview?
0
 $smarty->assign('can_preview', $page_object->preview);
0
 
0
@@ -291,8 +300,8 @@ $smarty->assign('parent_dropdown', $contentops->CreateHierarchyDropdown($page_ob
0
 $smarty->assign('template_names', $templateops->TemplateDropdown('content[template_id]', $page_object->template_id, 'onchange="document.contentform.submit()"'));
0
 
0
 //Name and menu text are multilang, use the parameters
0
-$smarty->assign('name', $page_object->get_property_value('name'), 'en_US');
0
-$smarty->assign('menu_text', $page_object->get_property_value('menu_text'), 'en_US');
0
+$smarty->assign('name', $page_object->get_property_value('name', $current_language));
0
+$smarty->assign('menu_text', $page_object->get_property_value('menu_text', $current_language));
0
 
0
 //Set the users
0
 $userops =& $gCms->GetUserOperations();
0
@@ -300,7 +309,7 @@ $smarty->assign('show_owner_dropdown', false);
0
 $smarty->assign('owner_dropdown', $userops->GenerateDropdown($page_object->owner_id, 'content[owner_id]'));
0
 
0
 //Any included smarty templates for this page type?
0
-$smarty->assign('include_templates', $page_object->edit_template($smarty));
0
+$smarty->assign('include_templates', $page_object->edit_template($smarty, $current_language));
0
 
0
 //Other fields that aren't easily done with smarty
0
 $smarty->assign('metadata_box', create_textarea(false, $page_object->metadata, 'content[metadata]', 'pagesmalltextarea', 'content_metadata', '', '', '80', '6'));
...
33
34
35
 
36
37
38
...
43
44
45
 
 
 
 
 
 
 
 
 
 
46
47
48
...
33
34
35
36
37
38
39
...
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
0
@@ -33,6 +33,7 @@
0
       <div id="content">
0
         {html_hidden id='serialized_content' name='serialized_content' value=$serialized_object}
0
         {html_hidden id='orig_page_type' name='orig_page_type' value=$orig_page_type}
0
+ {html_hidden id='orig_current_language' name='orig_current_language' value=$orig_current_language}
0
 
0
         {* Page Type *}
0
         <div class="pageoverflow">
0
@@ -43,6 +44,16 @@
0
          </select>
0
           </p>
0
         </div>
0
+
0
+ {* Language *}
0
+ <div class="pageoverflow">
0
+ <p class="pagetext">{tr}Language{/tr}:</p>
0
+ <p class="pageinput">
0
+ <select name="current_language" onchange="document.contentform.submit()" class="standard">
0
+ {html_options options=$languages selected=$orig_current_language}
0
+ </select>
0
+ </p>
0
+ </div>
0
 
0
         {* Page Title *}
0
         {if $page_object->field_used('name')}
...
35
36
37
38
 
39
40
 
41
42
43
 
44
45
 
46
47
48
49
50
51
 
52
53
54
55
56
 
 
 
57
58
59
60
61
 
62
63
 
64
65
66
...
35
36
37
 
38
39
 
40
41
42
 
43
44
 
45
46
47
48
49
50
 
51
52
53
 
 
 
54
55
56
57
58
59
60
 
61
62
 
63
64
65
66
0
@@ -35,32 +35,32 @@ class BlockHtml extends CmsObject
0
     return 'HTML Text';
0
   }
0
   
0
- function show(&$page, $block_name)
0
+ function show(&$page, $block_name, $lang = 'en_US')
0
   {
0
- return $page->get_property_value($block_name . '-content');
0
+ return $page->get_property_value($block_name . '-content', $lang);
0
   }
0
   
0
- function validate(&$page, $block_name)
0
+ function validate(&$page, $block_name, $lang = 'en_US')
0
   {
0
- if ($page->get_property_value($block_name . '-content') == '')
0
+ if ($page->get_property_value($block_name . '-content', $lang) == '')
0
     {
0
       $page->add_validation_error(lang('nofieldgiven', array(lang('content'))));  
0
     }
0
   }
0
   
0
- function block_add_template(&$page, $block_name, &$template)
0
+ function block_add_template(&$page, $block_name, &$template, $lang = 'en_US')
0
   {
0
     return "
0
- <p class=\"pagetext\">".lang('content').":</p>
0
- <p class=\"pageinput\">
0
- {literal}" . create_textarea(true, $page->get_property_value($block_name . '-content'), 'content[property][' . $block_name . '-content]', '', 'content_' . $block_name . '_block', '', '', '80', '15', '') . "{/literal}
0
+ <p>".lang('content').":</p>
0
+ <p>
0
+ {literal}" . create_textarea(true, $page->get_property_value($block_name . '-content', $lang), 'content[property][' . $block_name . '-content]', '', 'content_' . $block_name . '_block', '', '', '80', '12', '') . "{/literal}
0
     </p>  
0
     ";
0
   }
0
   
0
- function block_edit_template(&$page, $block_name, &$template)
0
+ function block_edit_template(&$page, $block_name, &$template, $lang = 'en_US')
0
   {
0
- return $this->block_add_template($page, $block_name, $template);
0
+ return $this->block_add_template($page, $block_name, $template, $lang);
0
   }
0
 }
0
 
...
229
230
231
232
 
233
234
235
...
244
245
246
 
247
248
249
...
300
301
302
303
 
304
305
306
...
311
312
313
314
 
315
316
317
...
321
322
323
324
 
325
326
327
328
329
 
330
331
332
...
229
230
231
 
232
233
234
235
...
244
245
246
247
248
249
250
...
301
302
303
 
304
305
306
307
...
312
313
314
 
315
316
317
318
...
322
323
324
 
325
326
327
328
329
 
330
331
332
333
0
@@ -229,7 +229,7 @@ class CmsContentBase extends CmsObjectRelationalMapping
0
 
0
     foreach ($this->mProperties as &$prop)
0
     {
0
- if ($prop->prop_name == $name)
0
+ if ($prop->prop_name == $name && $prop->language == $lang)
0
       {
0
         $prop->content = $value;
0
 
0
@@ -244,6 +244,7 @@ class CmsContentBase extends CmsObjectRelationalMapping
0
     $newprop = new CmsContentProperty();
0
     $newprop->prop_name = $name;
0
     $newprop->content = $value;
0
+ $newprop->language = $lang;
0
     $this->mProperties[] = $newprop;
0
     
0
     if (!$this->has_property($name))
0
@@ -300,7 +301,7 @@ class CmsContentBase extends CmsObjectRelationalMapping
0
       //Loop through and see if it's loaded
0
       foreach ($this->mProperties as &$prop)
0
       {
0
- if ($prop->prop_name == $name)
0
+ if ($prop->prop_name == $name && $prop->language == $lang)
0
         {
0
           return $prop->content;
0
         }
0
@@ -311,7 +312,7 @@ class CmsContentBase extends CmsObjectRelationalMapping
0
       //Loop through and see if it's loaded now
0
       foreach ($this->mProperties as &$prop)
0
       {
0
- if ($prop->prop_name == $name)
0
+ if ($prop->prop_name == $name && $prop->language == $lang)
0
         {
0
           return $prop->content;
0
         }
0
@@ -321,12 +322,12 @@ class CmsContentBase extends CmsObjectRelationalMapping
0
     return '';
0
   }
0
   
0
- function add_template(&$smarty)
0
+ function add_template(&$smarty, $lang = 'en_US')
0
   {
0
     return array();
0
   }
0
   
0
- function edit_template(&$smarty)
0
+ function edit_template(&$smarty, $lang = 'en_US')
0
   {
0
     return array();
0
   }
...
27
28
29
30
 
31
32
 
 
 
33
34
35
36
37
 
 
38
39
 
 
 
 
 
 
 
 
40
41
42
43
44
45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
47
48
...
59
60
61
62
 
63
64
65
...
27
28
29
 
30
31
 
32
33
34
35
 
 
 
 
36
37
38
 
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
...
83
84
85
 
86
87
88
89
0
@@ -27,22 +27,46 @@
0
  * @since 2.0
0
  * @author Ted Kulp
0
  **/
0
-class CmsDateTime extends DateTime
0
+class CmsDateTime extends CmsObject
0
 {
0
- function __construct($datetime = null)
0
+ private $datetime = null;
0
+
0
+ function __construct($curtime = 'now')
0
   {
0
- if ($datetime == null)
0
- $datetime = strftime('%x %X', time());
0
- else if (is_int($datetime))
0
- $datetime = strftime('%x %X', $datetime);
0
+ if (is_int($curtime))
0
+ $curtime = strftime('%x %X', $curtime);
0
 
0
- parent::__construct($datetime);
0
+ try
0
+ {
0
+ $this->datetime = date_create($curtime);
0
+ }
0
+ catch (Exception $e)
0
+ {
0
+ $this->datetime = date_create('now');
0
+ }
0
   }
0
   
0
   function __toString()
0
   {
0
     return $this->to_format_string();
0
   }
0
+
0
+ function modify($modify)
0
+ {
0
+ date_modify($this->datetime, $modify);
0
+ }
0
+
0
+ function format($format)
0
+ {
0
+ try
0
+ {
0
+ return @date_format($this->datetime, $format);
0
+ }
0
+ catch (Exception $e)
0
+ {
0
+ return '';
0
+ }
0
+ }
0
 
0
   /**
0
    * Returns a formatted string based on the individual user's settings.
0
@@ -59,7 +83,7 @@ class CmsDateTime extends DateTime
0
     if ($user != null)
0
       $format = get_preference($user->id, 'date_format_string', $format);
0
 
0
- return strftime($format, $this->format('U'));
0
+ return strftime($format, $this->format('U'));
0
   }
0
   
0
   /**
...
90
91
92
93
 
94
95
96
...
145
146
147
148
 
149
150
151
...
169
170
171
172
173
174
 
 
 
 
 
175
176
177
 
178
179
180
...
200
201
202
203
 
204
205
206
...
223
224
225
226
 
227
228
229
...
90
91
92
 
93
94
95
96
...
145
146
147
 
148
149
150
151
...
169
170
171
 
 
 
172
173
174
175
176
177
178
 
179
180
181
182
...
202
203
204
 
205
206
207
208
...
225
226
227
 
228
229
230
231
0
@@ -90,7 +90,7 @@ class Content extends CmsContentBase
0
     }
0
   }
0
   
0
- function add_template(&$smarty)
0
+ function add_template(&$smarty, $lang = 'en_US')
0
   {
0
     $template = null;
0
     if ($this->template_id == '' || $this->template_id == -1)
0
@@ -145,7 +145,7 @@ class Content extends CmsContentBase
0
     return array(cms_join_path(dirname(__FILE__), 'Content.tpl'));
0
   }
0
   
0
- function edit_template(&$smarty)
0
+ function edit_template(&$smarty, $lang = 'en_US')
0
   {
0
     $template = null;
0
     if ($this->template_id == '' || $this->template_id == -1)
0
@@ -169,12 +169,14 @@ class Content extends CmsContentBase
0
         <div class="accordion_content">
0
           <div class="pageoverflow">
0
             <p class="pagetext">'.lang('blocktype').':</p>
0
- <select name="content[property]['.$block['id'].'-block-type]" id="'.$block['id'].'-block-type" onchange="xajax_change_block_type(xajax.getFormValues(\'contentform\'), \''.$block['id'].'\', \'\' + $(\'#'.$block['id'].'-block-type\').val()); return false;">
0
- '.$this->create_block_type_options($type).'
0
- </select>
0
+ <p class="pageinput">
0
+ <select name="content[property]['.$block['id'].'-block-type]" id="'.$block['id'].'-block-type" onchange="xajax_change_block_type(xajax.getFormValues(\'contentform\'), \''.$block['id'].'\', \'\' + $(\'#'.$block['id'].'-block-type\').val()); return false;">
0
+ '.$this->create_block_type_options($type).'
0
+ </select>
0
+ </p>
0
           </div>
0
           <div class="pageoverflow" id="content-form-' . $block['id'] . '">
0
- '.$this->create_block_type($block['id']).'
0
+ '.$this->create_block_type($block['id'], $lang).'
0
          </div>
0
         </div>
0
       ';
0
@@ -200,7 +202,7 @@ class Content extends CmsContentBase
0
     return array(cms_join_path(dirname(__FILE__), 'Content.tpl'));
0
   }
0
   
0
- public function create_block_type($block_id)
0
+ public function create_block_type($block_id, $lang = 'en_US')
0
   {
0
     $template = null;
0
     if ($this->template_id == '' || $this->template_id == -1)
0
@@ -223,7 +225,7 @@ class Content extends CmsContentBase
0
       $class_name = camelize('block_' . $block_type_obj->type);
0
       $class = new $class_name;
0
 
0
- return $class->block_edit_template($this, $block_id, $template);
0
+ return $class->block_edit_template($this, $block_id, $template, $lang);
0
     }
0
     
0
     return '';
...
795
796
797
 
798
799
800
...
843
844
845
846
 
847
848
849
...
996
997
998
999
 
1000
1001
1002
...
795
796
797
798
799
800
801
...
844
845
846
 
847
848
849
850
...
997
998
999
 
1000
1001
1002
1003
0
@@ -795,6 +795,7 @@ abstract class CmsObjectRelationalMapping extends CmsObject implements ArrayAcce
0
           {
0
             if ($this->params[$localname] instanceof CmsDateTime)
0
             {
0
+ var_dump($this->params[$localname]);
0
               $midpart .= "{$onefield} = " . $this->params[$localname]->to_sql_string() . ", ";
0
             }
0
             else
0
@@ -843,7 +844,7 @@ abstract class CmsObjectRelationalMapping extends CmsObject implements ArrayAcce
0
       $midpart = '';
0
       $queryparams = array();
0
       
0
- foreach($fields as $onefield)
0
+ foreach($fields as $onefield=>$obj)
0
       {
0
         $localname = $onefield;
0
         if (array_key_exists($localname, $this->field_maps)) $localname = $this->field_maps[$localname];
0
@@ -996,7 +997,7 @@ abstract class CmsObjectRelationalMapping extends CmsObject implements ArrayAcce
0
 
0
       if ($datetime)
0
       {
0
- $object->params[$k] = new CmsDateTime($v);
0
+ $object->params[$k] = new CmsDateTime(cms_db()->UnixTimeStamp($v));
0
       }
0
       else
0
       {
...
83
84
85
 
86
87
88
...
91
92
93
 
94
95
96
...
83
84
85
86
87
88
89
...
92
93
94
95
96
97
98
0
@@ -83,6 +83,7 @@ function load_all_permissions($userid)
0
   try
0
   {
0
     $query = "SELECT DISTINCT permission_name FROM ".cms_db_prefix()."user_groups ug INNER JOIN ".cms_db_prefix()."group_perms gp ON gp.group_id = ug.group_id INNER JOIN ".cms_db_prefix()."permissions p ON p.permission_id = gp.permission_id WHERE ug.user_id = ?";
0
+ /*
0
     $result = &$db->Execute($query, array($userid));
0
     while ($result && !$result->EOF)
0
     {
0
@@ -91,6 +92,7 @@ function load_all_permissions($userid)
0
     }
0
   
0
     if ($result) $result->Close();
0
+ */
0
   }
0
   catch (exception $e)
0
   {
0
tmp/translations/languages.xml 100644 → 100755

Comments

    No one has commented yet.