/** * Adds a simple single-line text form element at this time. */ function add_elements_to_form($attributes) { $attributes = array_merge($attributes, array('rows' => $this->height, 'cols' => $this->width, 'class' => "codemirror {$this->language}", 'id' => "{$this->_namespace}{$this->name}")); if (!$this->enabled) { $attributes['class'] = 'longtext'; } $this->_form->addElement('textarea', $this->name, $this->_translate($this->_field['title']), $attributes); $this->_form->applyFilter($this->name, 'trim'); $config = midcom_helper_misc::get_snippet_content_graceful($this->_config->get('codemirror_config_snippet')); $config = str_replace('{$id}', $attributes['id'], $config); $config = str_replace('{$read_only}', 'false', $config); midcom::get('head')->add_jquery_state_script($config); }
/** * Adds a simple single-line text form element at this time. */ function add_elements_to_form($attributes) { $elements = array(); $attributes = array_merge($attributes, array('class' => 'captcha', 'id' => "{$this->_namespace}{$this->name}")); $static_html = recaptcha_get_html($this->_public_key); $static_html = midcom_helper_misc::get_snippet_content_graceful('/sitegroup-config/midcom.helper.datamanager2/recaptcha') . $static_html; $this->_element = HTML_QuickForm::createElement('static', "{$this->name}_captcha", '', $static_html); $elements[] = $this->_element; $elements[] = HTML_QuickForm::createElement('hidden', $this->name, '', $attributes); $this->_form->applyFilter($this->name, 'trim'); $this->_form->addGroup($elements, "{$this->name}_group", $this->_translate($this->_field['title']), '<br />', false); $this->_form->addFormRule(array(&$this, 'validate')); }
/** * Load a language database * * - Leading and trailing whitespace will be eliminated */ private function _load_language($lang) { $this->_stringdb[$lang] = array(); $filename = "{$this->_library_filename}.{$lang}.txt"; if ($GLOBALS['midcom_config']['cache_module_memcache_backend'] != 'flatfile') { $stringtable = midcom::get('cache')->memcache->get('L10N', $filename); if (is_array($stringtable)) { $this->_stringdb[$lang] = $stringtable; return; } } if (!empty(midcom::get('componentloader')->manifests[$this->_component_name]->extends)) { $parent_l10n = new self(midcom::get('componentloader')->manifests[$this->_component_name]->extends, 'default'); $this->_stringdb[$lang] = $parent_l10n->get_stringdb($lang); } if (!file_exists($filename)) { return; } $data = file($filename); // get site-specific l10n $component_locale = midcom_helper_misc::get_snippet_content_graceful($GLOBALS['midcom_config']['midcom_sgconfig_basedir'] . "/" . $this->_component_name . "/l10n/" . $lang); if (!empty($component_locale)) { $data = array_merge($data, explode("\n", $component_locale)); } // Parse the Array $stringtable = array(); $version = ''; $language = ''; $instring = false; $string_data = ''; $string_key = ''; foreach ($data as $line => $string) { // Kill any excess whitespace first. $string = trim($string); if (!$instring) { // outside of a string value if ($string == '') { // Do nothing } else { if (substr($string, 0, 3) == '---') { // this is a command if (strlen($string) < 4) { $line++; // Array is 0-indexed throw new midcom_error("L10n DB SYNTAX ERROR: An incorrect command was detected at {$filename}:{$line}"); } $pos = strpos($string, ' '); if ($pos === false) { $command = substr($string, 3); } $command = substr($string, 3, $pos - 3); switch ($command) { case '#': // Skip break; case 'VERSION': if ($version != '') { $line++; // Array is 0-indexed throw new midcom_error("L10n DB SYNTAX ERROR: A second VERSION tag has been detected at {$filename}:{$line}"); } $version = substr($string, 11); break; case 'LANGUAGE': if ($language != '') { $line++; // Array is 0-indexed throw new midcom_error("L10n DB SYNTAX ERROR: A second LANGUAGE tag has been detected at {$filename}:{$line}"); } $language = substr($string, 12); break; case 'STRING': $string_data = ''; $string_key = substr($string, 10); $instring = true; break; default: $line++; // Array is 0-indexed throw new midcom_error("L10n DB SYNTAX ERROR: Unknown command '{$command}' at {$filename}:{$line}"); } } else { $line++; // Array is 0-indexed throw new midcom_error("L10n DB SYNTAX ERROR: Invalid line at {$filename}:{$line}"); } } } else { // Within a string value if ($string == '---STRINGEND') { $instring = false; $stringtable[$string_key] = $string_data; } else { if ($string_data == '') { $string_data .= $string; } else { $string_data .= "\n{$string}"; } } } } if ($instring) { throw new midcom_error("L10n DB SYNTAX ERROR: String constant exceeds end of file."); } if (version_compare($version, $this->_version, "<")) { throw new midcom_error("L10n DB ERROR: File format version of {$filename} is too old, no update available at the moment."); } if ($lang != $language) { throw new midcom_error("L10n DB ERROR: The DB language version {$language} did not match the requested {$lang}."); } ksort($stringtable, SORT_STRING); $this->_stringdb[$lang] = array_merge($this->_stringdb[$lang], $stringtable); if ($GLOBALS['midcom_config']['cache_module_memcache_backend'] != 'flatfile') { midcom::get('cache')->memcache->put('L10N', $filename, $this->_stringdb[$lang]); } }
/** * This helper will construct the TinyMCE initscript based on the specified configuration. */ function _add_initscript($mode = 'exact') { $config = midcom_helper_misc::get_snippet_content_graceful($this->mce_config_snippet); if (!$config) { $config = $this->_get_configuration(); } else { $popup = $this->_get_imagepopup_jsstring(); $config = str_replace('{$popup}', $popup, $config); } $language = midcom::get('i18n')->get_current_language(); // fix to use the correct langcode for norwegian. if ($language == 'no') { $language = 'nb'; } $imagepopup_url = ''; if ($this->use_imagepopup) { $prefix = midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ANCHORPREFIX); $imagepopup_url = "plugin_imagepopup_popupurl: \"{$prefix}__ais/imagepopup/"; if ($this->_type->storage->object) { // We have an existing object, link to "page attachments" $imagepopup_url .= "{$this->_schema->name}/{$this->_type->storage->object->guid}\","; } else { // No object has been created yet, link to "folder attachments" without page specified $imagepopup_url .= "folder/{$this->_schema->name}\","; } } if ($this->_config->get('tinymce_use_compressor')) { $gz_config = preg_replace("/^theme\\s*?:/", "themes :", $config); $script_gz = <<<EOT tinyMCE_GZ.init({ {$gz_config} {$this->local_config} languages : "{$language}", {$imagepopup_url} disk_cache : true, debug : false }); EOT; midcom::get('head')->add_jscript($script_gz); } // Compute the final script: $script = <<<EOT tinyMCE.init({ {$config} {$this->local_config} mode : "{$mode}", convert_urls : false, relative_urls : false, remove_script_host : true, elements : "{$this->_namespace}{$this->name}", language : "{$language}", {$imagepopup_url} docs_language : "{$language}", browsers : "msie,gecko,opera,safari" }); EOT; midcom::get('head')->add_jscript($script); }
/** * This helper function reads a snippet and evaluates its content as array. * This is essentially a simple Array($data\n) eval construct. * * If the snippet does not exist, false is returned. * * This function may be called statically. * * @param string $snippetpath The full path to the snippet that should be returned. * @return Array The read data or false on failure. * @see read_array_from_file() */ public static function read_array_from_snippet($snippetpath) { $code = midcom_helper_misc::get_snippet_content_graceful($snippetpath); return midcom_helper_misc::parse_config($code); }
function convert_to_html() { if (!$this->enabled) { return highlight_string((string) $this->value, true); } $html = "<textarea rows=\"30\" cols=\"100%\" class=\"codemirror php\" id=\"codemirror_{$this->name}\" name=\"codemirror_{$this->name}\">{$this->value}</textarea>"; $config = midcom_helper_misc::get_snippet_content_graceful($this->_config->get('codemirror_config_snippet')); $config = str_replace('{$id}', 'codemirror_' . $this->name, $config); $config = str_replace('{$read_only}', '"nocursor"', $config); midcom::get('head')->add_jquery_state_script($config); return $html; }