/** * Get style info * * @param array $element * @param type $output * @return type */ static function getStyle($element, $output) { $style = !empty($element['style']) ? $element['style'] : ''; if (is_array($element['style'])) { $styles = array(); foreach ($element['style'] as $att_name => $att_value) { $styles[] = "{$att_name} : {$att_value}"; } $styles = "style = '" . implode(';', $styles) . "'"; } else { $styles = ''; } $output = JSNTplMMHelperPlaceholder::removePlaceholder($output, 'custom_style', $styles); return $output; }
/** * Generate options list of shortcode (from $this->items array) OR get value of a option * @param array $arr ($this->items) * @param string|null $paramID (get std of a option by ID) * @param array $new_values (set std for some options ( "pram id" => "new std value" ) ) * @param bool $assign_content (set $option['std'] = $new_values['_shortcode_content'] of option which has role = 'content' ) * @param bool $extract_content (get $option['std'] of option which has role = 'content' ) * @param string $extract_title (get $option['std'] of option which has role|role_2 = 'title' ) * @return array */ static function generateShortcodeParams(&$arr, $paramID = NULL, $new_values = NULL, $assign_content = FALSE, $extract_content = FALSE, $extract_title = '') { $params = array(); if ($arr) { foreach ($arr as $tab => &$options) { foreach ($options as &$option) { $type = isset($option['type']) ? $option['type'] : ''; $option['std'] = !isset($option['std']) ? '' : $option['std']; // option has role = 'content' if (isset($option['role']) && $option['role'] == 'content') { // set std of this option if ($assign_content) { if (!empty($new_values) && isset($new_values['_shortcode_content'])) { $option['std'] = $new_values['_shortcode_content']; } } // get std of this option if ($extract_content) { $params['extract_shortcode_content'][$option['id']] = $option['std']; } else { // remove option which role = content from shortcode structure ( except option which has another role: title ) if (!(isset($option['role']) && $option['role'] == 'title' || isset($option['role_2']) && $option['role_2'] == 'title' || isset($option['role']) && $option['role'] == 'title_prepend')) { unset($option); continue; } } } if ($type != 'preview') { // single option : $option['type'] => string if (!is_array($type)) { // if is not parent/nested shortcode if (!in_array($type, self::$groupShortcodes)) { // default content if (empty($new_values)) { if (!empty($paramID)) { if ($option['id'] == $paramID) { return $option['std']; } } else { if (isset($option['id'])) { $params[$option['id']] = $option['std']; } } } else { if (isset($option['id']) && array_key_exists($option['id'], $new_values)) { $option['std'] = $new_values[$option['id']]; } } // extract title for element like Table if (!empty($extract_title)) { // default std if (strpos($option['std'], JSNTplMMHelperPlaceholder::getPlaceholder('index')) !== false) { $option['std'] = ''; $params['extract_title'] = JText::_('Untitled'); } else { if (isset($option['role']) && $option['role'] == 'title' || isset($option['role_2']) && $option['role_2'] == 'title') { if ($option['role'] == 'title') { $params['extract_title'] = $option['std']; } else { $params['extract_title'] = JSNTplMMHelperCommon::sliceContent($option['std']); } } else { if (isset($option['role']) && $option['role'] == 'title_prepend' && !empty($option['title_prepend_type']) && !empty($option['std'])) { $params['extract_title'] = JSNTplMMHelperPlaceholder::removePlaceholder(self::$item_html_template[$option['title_prepend_type']], 'standard_value', $option['std']) . $params['extract_title']; } } } } } else { // default content if (empty($new_values)) { foreach ($option['sub_items'] as &$sub_items) { $sub_items['std'] = !isset($sub_items['std']) ? '' : $sub_items['std']; if (!empty($paramID)) { if ($sub_items['id'] == $paramID) { return $sub_items['std']; } } else { $params['sub_items_content'][$option['sub_item_type']][] = $sub_items; } } } else { $count_default = count($option['sub_items']); $count_real = isset($new_values['sub_items_content'][$option['sub_item_type']]) ? count($new_values['sub_items_content'][$option['sub_item_type']]) : 0; if ($count_real > 0) { // there are new sub items if ($count_default < $count_real) { for ($index = $count_default; $index < $count_real; $index++) { $option['sub_items'][$index] = array('std' => ''); } } else { if ($count_default > $count_real) { for ($index = $count_real; $index < $count_default; $index++) { unset($option['sub_items'][$index]); } } } // update content for sub items array_walk($option['sub_items'], array('self', 'arrWalkSubsc'), $new_values['sub_items_content'][$option['sub_item_type']]); } } } } else { // default content if (empty($new_values)) { foreach ($option['type'] as &$sub_options) { $sub_options['std'] = !isset($sub_options['std']) ? '' : $sub_options['std']; if (!empty($paramID)) { if ($sub_options['id'] == $paramID) { return $sub_options['std']; } } else { $params[$sub_options['id']] = $sub_options['std']; } } } else { array_walk($option['type'], array('self', 'arrWalk'), $new_values); } } if (isset($option['extended_ids'])) { foreach ($option['extended_ids'] as $_id) { $params[$_id] = isset($option[$_id]['std']) ? $option[$_id]['std'] : ''; } } } } } } return $params; }