Patch for lib\contenttypes\Content.inc.php : content and content_en
Posted: Fri Sep 22, 2006 10:22 pm
While trying to have 1 only raw Content block, I found that:
- you can't set 'wysiwyg="false"' for the standard Content box.
- having both {content} and {content block="content_en"} in the template duplicates the edit box.
- if you have {content block="content_fr"}, then {content}, standard Content will always appear first
This patch works for me on my 0.13 ... Sorry, but I'm not familiar enough with Diff to post a real Patch here. Hope it won't be too hard to see my modifs (I just "signed" it so you can see changes... plz remove my name !!!).
This goes in lib\contenttypes\Content.inc.php, function EditAsArray, in tab==0 section :
And here is my GetAdditionalContentBlocks function, which implements a new 'Label' parameter:
I'd suggest this corrected content for Help:
What parameters does it take?
* (optional)block - Allows you to have more than one content block per page. When multiple content tags are put on a template, that number of edit boxes will be displayed when the page is edited. Standard block is called 'content_en' : {content block="content_en"}
* (optional)wysiwyg (true/false) - If set to false, then a wysiwyg will never be used while editing this block. If true, then it acts as normal. Only works when block parameter is used.
* (optional)oneline (true/false) - If set to true, then only one edit line will be shown while editing this block. If false, then it acts as normal. Only works when block parameter is used.
* (optional)assign - Assigns the content to a smarty parameter, which you can then use in other areas of the page, or use to test whether content exists in it or not.
* (optional)label - Sets the label appearing next to the edit box.
HTH...
FredT
- you can't set 'wysiwyg="false"' for the standard Content box.
- having both {content} and {content block="content_en"} in the template duplicates the edit box.
- if you have {content block="content_fr"}, then {content}, standard Content will always appear first
This patch works for me on my 0.13 ... Sorry, but I'm not familiar enough with Diff to post a real Patch here. Hope it won't be too hard to see my modifs (I just "signed" it so you can see changes... plz remove my name !!!).
This goes in lib\contenttypes\Content.inc.php, function EditAsArray, in tab==0 section :
Code: Select all
array_push($ret, array(lang('template').':',TemplateOperations::TemplateDropdown('template_id', $this->mTemplateId, 'onchange="document.contentform.submit()"')));
//fredt : moved from here to #CREATE2 below //array_push($ret, array(lang('content').':',create_textarea(true, $this->GetPropertyValue('content_en'), 'content_en', '', 'content_en', '', $stylesheet)));
// add additional content blocks if required
$this->GetAdditionalContentBlocks(); // this is needed as this is the first time we get a call to our class when editing.
if(!array_key_exists('content_en', $this->additionalContentBlocks))
{ //Original line - #CREATE2 - Now we create content_en only if it hasn't been defined explicitly & it will obey order defined in the template
array_push($ret, array(lang('content').':',create_textarea(true, $this->GetPropertyValue('content_en'), 'content_en', '', 'content_en', '', $stylesheet)));
}
foreach($this->additionalContentBlocks as $blockName => $blockNameId)
{
if ($blockNameId['oneline'] == 'true')
{ //label added fredt
array_push($ret, array(ucwords($blockNameId['label']).':','<input type="text" name="'.$blockNameId['id'].'" value="'.$this->GetPropertyValue($blockNameId['id']).'" />'));
}
else
{ //label added fredt
array_push($ret, array(ucwords($blockNameId['label']).':',create_textarea(($blockNameId['usewysiwyg'] == 'false'?false:true), $this->GetPropertyValue($blockNameId['id']), $blockNameId['id'], '', $blockNameId['id'], '', $stylesheet)));
}
}
Code: Select all
function GetAdditionalContentBlocks()
{
$result = false;
if ($this->addtContentBlocksLoaded == false)
{
$this->additionalContentBlocks = array();
if ($this->TemplateId() && $this->TemplateId() > -1)
$template = TemplateOperations::LoadTemplateByID($this->TemplateId()); /* @var $template Template */
else
$template = TemplateOperations::LoadDefaultTemplate();
if($template !== false)
{
$content = $template->content;
$pattern = '/{content([^}]*)}/';
$pattern2 = '/([a-zA-z0-9]*)=["\']([^"\']+)["\']/';
$matches = array();
$result = preg_match_all($pattern, $content, $matches);
if ($result && count($matches[1]) > 0)
{
foreach ($matches[1] as $wholetag)
{
$morematches = array();
$result2 = preg_match_all($pattern2, $wholetag, $morematches);
if ($result2)
{
$keyval = array();
for ($i = 0; $i < count($morematches[1]); $i++)
{
$keyval[$morematches[1][$i]] = $morematches[2][$i];
}
$id = '';
$name = '';
$usewysiwyg = 'true';
$oneline = 'false';
$field_label = ''; //added by fredt
foreach ($keyval as $key=>$val)
{
switch($key)
{
case 'block':
$id = str_replace(' ', '_', $val);
$name = $val;
$field_label = $name; //added by fredt
if(!array_key_exists($val, $this->mProperties->mPropertyTypes))
{
$this->mProperties->Add("string", $id);
};
break;
case 'wysiwyg':
$usewysiwyg = $val;
break;
case 'oneline':
$oneline = $val;
break;
//Added by fredt
case 'label':
$field_label = $val;
break; //end addition fredt
default:
break;
}
}
$this->additionalContentBlocks[$name]['id'] = $id;
$this->additionalContentBlocks[$name]['usewysiwyg'] = $usewysiwyg;
$this->additionalContentBlocks[$name]['oneline'] = $oneline;
$this->additionalContentBlocks[$name]['label'] = $field_label; //added by fredt
}
}
// force a load
$this->mProperties->Load($this->mId);
$result = true;
}
}
$this->addtContentBlocksLoaded = true;
}
return $result;
}
What parameters does it take?
* (optional)block - Allows you to have more than one content block per page. When multiple content tags are put on a template, that number of edit boxes will be displayed when the page is edited. Standard block is called 'content_en' : {content block="content_en"}
* (optional)wysiwyg (true/false) - If set to false, then a wysiwyg will never be used while editing this block. If true, then it acts as normal. Only works when block parameter is used.
* (optional)oneline (true/false) - If set to true, then only one edit line will be shown while editing this block. If false, then it acts as normal. Only works when block parameter is used.
* (optional)assign - Assigns the content to a smarty parameter, which you can then use in other areas of the page, or use to test whether content exists in it or not.
* (optional)label - Sets the label appearing next to the edit box.
HTH...
FredT