18 require_once SQ_CORE_PACKAGE_PATH.
'/content_type/content_type_edit_fns.inc';
41 parent::__construct();
57 if ($asset->writeAccess(
'attributes')) {
58 $size = $GLOBALS[
'SQ_SYSTEM']->getUserPrefs($asset->type(),
'SQ_MARKDOWN_SIZE');
59 $markdown = $asset->attr(
'markdown');
60 $markdownify_not_configured_message =
'';
61 if ($markdown ==
'') {
62 $html = $asset->attr(
'html');
63 if (trim($html) !=
'') {
64 $is_markdownified = FALSE;
65 require_once SQ_DATA_PATH.
'/private/conf/tools.inc';
66 require_once SQ_FUDGE_PATH.
'/general/text.inc';
67 if (SQ_TOOL_MARKDOWNIFY_ENABLED && is_file(SQ_TOOL_MARKDOWNIFY_PATH)) {
68 require_once SQ_TOOL_MARKDOWNIFY_PATH;
69 $class_name = basename(SQ_TOOL_MARKDOWNIFY_PATH,
'.php');
70 if (method_exists($class_name,
'parseString')) {
71 $markdownify =
new $class_name;
77 $keywords = retrieve_keywords_replacements($html);
78 foreach ($keywords as $keyword) {
79 $safe_keyword =
'%'.str_replace(
'_',
'[MY3SEP]', $keyword).
'%';
80 $safe_html = str_replace(
'%'.$keyword.
'%', $safe_keyword, $safe_html);
84 $markdown = $markdownify->parseString($safe_html);
87 foreach ($keywords as $keyword) {
88 $safe_keyword =
'%'.str_replace(
'_',
'[MY3SEP]', $keyword).
'%';
89 $markdown = str_replace($safe_keyword,
'%'.$keyword.
'%', $markdown);
91 $is_markdownified = TRUE;
96 if (!$is_markdownified) {
98 $markdownify_not_configured_message = translate(
'cms_content_type_markdown_markdownify_tool_not_configured');
105 $em = $GLOBALS[
'SQ_SYSTEM']->getEventManager();
107 $prepared_keywords = Array();
108 $keyword_vars = Array(
'keywords' => &$keywords);
109 $em->broadcastEvent($asset,
'requestKeywords', $keyword_vars);
110 if (!empty($keywords)) {
111 foreach ($keywords as $key => $name) {
112 $prepared_keywords[
'%'.$key.
'%'] = $name;
114 keyword_selector($prepared_keywords, $prefix.
'_markdown');
118 if ($markdownify_not_configured_message !=
'') {
119 echo
'<span class="sq-backend-warning">'.$markdownify_not_configured_message.
'</span><br />';
123 $markdown_configured = FALSE;
124 if (SQ_TOOL_MARKDOWN_ENABLED && is_file(SQ_TOOL_MARKDOWN_PATH)) {
125 require_once SQ_TOOL_MARKDOWN_PATH;
126 if (function_exists(
'Markdown')) {
127 $markdown_configured = TRUE;
130 if (!$markdown_configured) {
131 echo
'<span class="sq-backend-warning">'.translate(
'cms_content_type_markdown_markdown_tool_not_configured').
'</span><br />';
135 text_area($prefix.
'_markdown', $markdown,
'',
'', 0,
'style="width: '.$size[
'width'].
'; height: '.$size[
'height'].
'; font-family: \'Courier New\', Courier, monospace; display: block"');
154 if ($asset->writeAccess(
'attributes')) {
155 if (isset($_POST[$prefix.
'_markdown'])) {
156 $markdown = $_POST[$prefix.
'_markdown'];
157 $current_markdown = $asset->attr(
'markdown');
158 if ($markdown != $current_markdown) {
159 require_once SQ_DATA_PATH.
'/private/conf/tools.inc';
160 require_once SQ_FUDGE_PATH.
'/general/text.inc';
161 if (SQ_TOOL_MARKDOWN_ENABLED && is_file(SQ_TOOL_MARKDOWN_PATH)) {
162 require_once SQ_TOOL_MARKDOWN_PATH;
163 if (function_exists(
'Markdown')) {
165 $safe_markdown = $markdown;
168 $keywords = retrieve_keywords_replacements($markdown);
169 foreach ($keywords as $keyword) {
170 $safe_keyword =
'%'.str_replace(
'_',
'[MY3SEP]', $keyword).
'%';
171 $safe_markdown = str_replace(
'%'.$keyword.
'%', $safe_keyword, $safe_markdown);
175 $html = Markdown($safe_markdown);
178 foreach ($keywords as $keyword) {
179 $safe_keyword =
'%'.str_replace(
'_',
'[MY3SEP]', $keyword).
'%';
180 $html = str_replace($safe_keyword,
'%'.$keyword.
'%', $html);
184 if ($asset->setAttrValue(
'markdown', $markdown) && $asset->setAttrValue(
'html', $html)) {
189 trigger_localised_error(
'CMS0107', E_USER_WARNING);