예제 #1
0
 public function replace_content_tags($namespace, $content_vars, $contents)
 {
     if (is_array($content_vars)) {
         // Find all matching tags
         $s = '#<perch:' . $namespace . '[^>]*/>#';
         $count = preg_match_all($s, $contents, $matches, PREG_SET_ORDER);
         if ($count) {
             foreach ($matches as $match) {
                 $match = $match[0];
                 $tag = new PerchXMLTag($match);
                 if ($tag->suppress) {
                     $contents = str_replace($match, '', $contents);
                 } else {
                     if (isset($content_vars[$tag->id])) {
                         $value = $content_vars[$tag->id];
                     } else {
                         $replacement = '';
                         if ($tag->else()) {
                             $replacement = $tag->else();
                         }
                         $contents = str_replace($match, $replacement, $contents);
                         continue;
                     }
                     $field_is_markup = false;
                     if ($tag->type) {
                         $FieldType = PerchFieldTypes::get($tag->type, false, $tag);
                         $modified_value = $FieldType->get_processed($value);
                         $field_is_markup = $FieldType->processed_output_is_markup;
                     } else {
                         $modified_value = $value;
                     }
                     // check for 'rewrite' attribute
                     if ($tag->rewrite) {
                         $modified_value = $this->_rewrite($tag, $modified_value);
                     }
                     // check for 'format' attribute
                     if ($tag->format) {
                         $modified_value = $this->_format($tag, $modified_value);
                     }
                     // check for 'replace' strings
                     if ($tag->replace) {
                         $pairs = explode(',', $tag->replace);
                         if (PerchUtil::count($pairs)) {
                             foreach ($pairs as $pair) {
                                 $pairparts = explode('|', $pair);
                                 if (isset($pairparts[0]) && isset($pairparts[1])) {
                                     $modified_value = str_replace(trim($pairparts[0]), trim($pairparts[1]), $modified_value);
                                 }
                             }
                         }
                     }
                     // Urlify
                     if ($tag->urlify) {
                         $modified_value = PerchUtil::urlify($modified_value);
                     }
                     // Trim by chars
                     if ($tag->chars) {
                         if (strlen($modified_value) > (int) $tag->chars) {
                             $modified_value = PerchUtil::excerpt_char($modified_value, (int) $tag->chars, false, true, $tag->append);
                         }
                     }
                     // Trim by words
                     if ($tag->words) {
                         $modified_value = PerchUtil::excerpt($modified_value, (int) $tag->words, false, true, $tag->append);
                     }
                     // Hash
                     if ($tag->hash == 'md5') {
                         $modified_value = md5($modified_value);
                     }
                     // check that what we've got isn't an array. If it is, try your best to get a good string.
                     if (is_array($modified_value)) {
                         if (isset($modified_value['_default'])) {
                             $modified_value = (string) $modified_value['_default'];
                         } else {
                             if (isset($modified_value['processed'])) {
                                 $modified_value = (string) $modified_value['processed'];
                             } else {
                                 $modified_value = (string) array_shift($modified_value);
                             }
                         }
                     }
                     // Strip tags
                     if ($tag->striptags) {
                         $modified_value = strip_tags($modified_value);
                     }
                     // Append
                     if (!$tag->words && !$tag->chars && $tag->append) {
                         $modified_value .= $tag->append;
                     }
                     // URL Encode
                     if ($tag->urlencode) {
                         $modified_value = rawurlencode($modified_value);
                     }
                     // Escape quotes
                     if ($tag->escape) {
                         $modified_value = PerchUtil::html($modified_value, true, false);
                         $field_is_markup = true;
                     }
                     // check encoding
                     if ($this->autoencode && !$field_is_markup) {
                         if (!$tag->textile && !$tag->markdown) {
                             if ((!$tag->is_set('encode') || $tag->encode == true) && (!$tag->is_set('html') || $tag->html == false)) {
                                 $modified_value = PerchUtil::html($modified_value);
                             }
                         }
                     }
                     // JSON encoding
                     if ($tag->jsonencode) {
                         $modified_value = json_encode($modified_value);
                     }
                     $contents = str_replace($match, $modified_value, $contents);
                 }
             }
         }
     }
     return $contents;
 }
예제 #2
0
        ?>
/responses/detail/?id=<?php 
        echo $HTML->encode(urlencode($Response->id()));
        ?>
"><?php 
        echo $HTML->encode(strftime('%d %b %Y %H:%M', strtotime($Response->responseCreated())));
        ?>
</a></td>
                <td>
                    <?php 
        $details = PerchUtil::json_safe_decode($Response->responseJSON(), true);
        $out = array();
        if (PerchUtil::count($details)) {
            foreach ($details['fields'] as $item) {
                if (isset($item['attributes']['label'])) {
                    $out[] = '<strong>' . $HTML->encode($item['attributes']['label']) . ':</strong> ' . $HTML->encode(PerchUtil::excerpt($item['value'], 10));
                }
            }
            echo implode('<br />', $out);
        }
        ?>
                </td>
                <td><a href="<?php 
        echo $API->app_path();
        ?>
/responses/delete/?id=<?php 
        echo $HTML->encode(urlencode($Response->id()));
        ?>
" class="delete inline-delete"><?php 
        echo $Lang->get('Delete');
        ?>
예제 #3
0
                <a class="sub" href="<?php 
    echo PERCH_LOGINPATH . '/core/apps/content/edit/?id=' . PerchUtil::html($Region->id());
    ?>
"><?php 
    echo PerchUtil::html($Region->regionKey());
    ?>
</a>
                <span class="sep icon"></span> 
                <a href="<?php 
    echo PERCH_LOGINPATH . '/core/apps/content/edit/?id=' . PerchUtil::html($Region->id()) . '&amp;itm=' . $details[0]['itemID'];
    ?>
"><?php 
    $item = $details[0];
    $id = $item['itemID'];
    if (isset($item['perch_' . $id . '__title'])) {
        echo PerchUtil::html(PerchUtil::excerpt($item['perch_' . $id . '__title'], 10));
    } else {
        if (isset($item['itemOrder'])) {
            echo PerchLang::get('Item') . ' ' . PerchUtil::html($item['itemOrder'] - 999);
        } else {
            echo PerchLang::get('New Item');
        }
    }
    ?>
</a>
                <?php 
} else {
    ?>
                    <a href="<?php 
    echo PERCH_LOGINPATH . '/core/apps/content/edit/?id=' . PerchUtil::html($Region->id());
    ?>