/**
  * Parses perch:trans tag structure for attributes
  *
  * @param $opening_tag
  * @return array
  */
 private function parse_tags($opening_tag)
 {
     $TranslationHelper = JwTranslations_Loader::fetch();
     $Tag = new PerchXMLTag($opening_tag);
     $translation_key = $Tag->id();
     $translation_lang = strtolower($Tag->lang() ? $Tag->lang() : PERCH_TRANSLATION_LANG);
     $translation_default_message = $Tag->default() ? $Tag->default() : null;
     $value_string = $TranslationHelper->get_translation($translation_key, $translation_lang, $translation_default_message);
     return array('key' => $translation_key, 'value' => $this->parse_placeholders($value_string, $Tag));
 }
 public function get_attribute_map($attribute, $reverse_output = false)
 {
     $template = $this->_get_template_content();
     $s = '/(<perch:input[^>]* ' . $attribute . '="[^>]*>)/s';
     preg_match_all($s, $template, $matches, PREG_SET_ORDER);
     $out = array();
     if ($matches) {
         $attribute = str_replace('-', '_', $attribute);
         foreach ($matches as $match) {
             $Tag = new PerchXMLTag($match[0]);
             if ($reverse_output) {
                 $out[$Tag->{$attribute}()] = $Tag->id();
             } else {
                 $out[$Tag->id()] = $Tag->{$attribute}();
             }
         }
     }
     return $out;
 }
 protected function render_related($type, $opening_tag, $condition_contents, $exact_match, $template_contents, $content_vars, $index_in_group)
 {
     $Tag = new PerchXMLTag($opening_tag);
     $out = '';
     if ($Tag->suppress()) {
         return str_replace($exact_match, '', $template_contents);
     }
     if (is_array($content_vars) && isset($content_vars[$Tag->id()]) && PerchUtil::count($content_vars[$Tag->id()])) {
         if (!class_exists('PerchContent_Collections', false)) {
             include_once PERCH_CORE . '/runway/apps/content/PerchContent_Collections.class.php';
             include_once PERCH_CORE . '/runway/apps/content/PerchContent_Collection.class.php';
             include_once PERCH_CORE . '/runway/apps/content/PerchContent_CollectionItems.class.php';
             include_once PERCH_CORE . '/runway/apps/content/PerchContent_CollectionItem.class.php';
         }
         $Collections = $this->_get_cached_object('PerchContent_Collections');
         $value = $Collections->get_data_from_ids_runtime($Tag->collection(), $content_vars[$Tag->id()], $Tag->sort());
         $RelatedTemplate = new PerchTemplate(false, $this->namespace);
         $RelatedTemplate->load($condition_contents);
         if (PerchUtil::bool_val($Tag->scope_parent())) {
             $vars_for_cat = array();
             if (PerchUtil::count($content_vars)) {
                 foreach ($content_vars as $key => $val) {
                     if ($key != $Tag->id() && $key != 'itemJSON') {
                         $vars_for_cat['parent.' . $key] = $val;
                     }
                 }
             }
             $vars_for_cat = array_merge($vars_for_cat, $content_vars[$Tag->id()]);
             foreach ($value as &$item) {
                 $item = array_merge($item, $vars_for_cat);
             }
         }
         $out = $RelatedTemplate->render_group($value, true);
     } else {
         if (strpos($condition_contents, 'perch:noresults')) {
             $s = '/<perch:noresults[^>]*>(.*?)<\\/perch:noresults>/s';
             $count = preg_match_all($s, $condition_contents, $matches, PREG_SET_ORDER);
             if ($count > 0) {
                 foreach ($matches as $match) {
                     $out .= $match[1];
                 }
             }
         }
     }
     return str_replace($exact_match, $out, $template_contents);
 }
 private function _replace_label($full_match, $opening_tag, $label_inner, $closing_tag, $template)
 {
     $OpeningTag = new PerchXMLTag($opening_tag);
     $attrs = array();
     $attrs['id'] = $OpeningTag->id();
     $attrs['class'] = $OpeningTag->class();
     $attrs['for'] = $this->field_prefix . $OpeningTag->for();
     $new_opening_tag = PerchXMLTag::create('label', 'opening', $attrs);
     $template = str_replace($opening_tag, $new_opening_tag, $template);
     $new_closing_tag = PerchXMLTag::create('label', 'closing');
     $template = str_replace($closing_tag, $new_closing_tag, $template);
     return $template;
 }