491 Posts in 152 Topics by 242 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 749 Views |
-
calculated field in content

23 July 2010 at 8:57pm
Hi
I'd like the person editing the page content in TinyMce to be able to insert a calculated field, eg the next 4th Friday. I have a php function that calculates the next nth specified day, but the user needs to be able to specify the week and the day. ie something like 'The next meeting is on nextdate(4,6)'.
Is this possible to do? preferably easily!
Thanks
-
Re: calculated field in content

24 July 2010 at 1:36am Last edited: 24 July 2010 1:39am
/**
* replace string in Content
* [ Untested ]
*/
public function Content() {
$this->Content = str_replace( "nextdate(4,6)", $this->nextdate(4,6), $this->Content );
return $this->Content;
}/**
* parse next date
* [ Untested ]
*/
public function nextdate($var1,$var2) {
return "whenever";
} -
Re: calculated field in content

24 July 2010 at 3:06am
Thanks. The numbers 4 and 6 in nextdate(4,6) are parameters and may be any numbers (the 6 could go up to 12). I don't know how to pick these out.
-
Re: calculated field in content

24 July 2010 at 3:29am Last edited: 24 July 2010 3:32am
http://php.net/manual/en/function.preg-replace.php
/**
* replace string in Content
* [ Untested ]
*/
public function Content() {
//$this->Content = "The next meeting is on nextdate(4,6)";
$this->Content = preg_replace(
"#nextdate\((.+?),(.+?)\)#is",
$this->nextdate("\\1","\\2"),
$this->Content);
return $this->Content;
}/**
* parse next date
* [ Untested ]
*/
public function nextdate($var1,$var2) {
return "whenever";
} -
Re: calculated field in content

24 July 2010 at 4:06pm
Thanks for your help. I've decided that maybe it's not such a good idea to parse the content. Perhaps I'll try adding a page type with a couple of fields for the user to choose the parameters and put the call to the function in the template.
-
Re: calculated field in content

24 July 2010 at 9:09pm Last edited: 24 July 2010 9:10pm
You can also replace values with TinyMCE and the template/snippets plug in.
http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/template
| 749 Views | ||
|
Page:
1
|
Go to Top |


