Textpattern | PHP Cross Reference | Content Management Systems |
Description: Template partials tags.
1 <?php 2 3 /* 4 * Textpattern Content Management System 5 * https://textpattern.com/ 6 * 7 * Copyright (C) 2020 The Textpattern Development Team 8 * 9 * This file is part of Textpattern. 10 * 11 * Textpattern is free software; you can redistribute it and/or 12 * modify it under the terms of the GNU General Public License 13 * as published by the Free Software Foundation, version 2. 14 * 15 * Textpattern is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with Textpattern. If not, see <https://www.gnu.org/licenses/>. 22 */ 23 24 /** 25 * Template partials tags. 26 * 27 * @since 4.6.0 28 */ 29 30 namespace Textpattern\Tag\Syntax; 31 32 class Partial 33 { 34 /** 35 * Returns the inner content of the enclosing <txp:output_form /> tag. 36 * 37 * @param array $atts 38 * @param string $thing 39 * @return string 40 */ 41 42 public static function renderYield($atts, $thing = null) 43 { 44 global $yield, $txp_yield, $txp_atts, $txp_item; 45 46 extract(lAtts(array( 47 'name' => '', 48 'else' => false, 49 'default' => false, 50 'item' => null 51 ), $atts)); 52 53 if (isset($item)) { 54 $inner = isset($txp_item[$item]) ? $txp_item[$item] : null; 55 } elseif ($name === '') { 56 $end = empty($yield) ? null : end($yield); 57 58 if (isset($end)) { 59 $inner = parse($end, empty($else)); 60 } 61 } elseif (!empty($txp_yield[$name])) { 62 list($inner) = end($txp_yield[$name]); 63 $txp_yield[$name][key($txp_yield[$name])][1] = true; 64 } 65 66 if (!isset($inner)) { 67 $escape = isset($txp_atts['escape']) ? $txp_atts['escape'] : null; 68 $inner = $default !== false ? 69 ($default === true ? page_url(array('type' => $name, 'escape' => $escape)) : $default) : 70 ($thing ? parse($thing) : $thing); 71 } 72 73 return $inner; 74 } 75 76 /** 77 * Conditional for yield. 78 * 79 * @param array $atts 80 * @param string $thing 81 * @return string 82 */ 83 84 public static function renderIfYield($atts, $thing = null) 85 { 86 global $yield, $txp_yield, $txp_item; 87 88 extract(lAtts(array( 89 'name' => '', 90 'else' => false, 91 'value' => null, 92 'item' => null 93 ), $atts)); 94 95 if (isset($item)) { 96 $inner = isset($txp_item[$item]) ? $txp_item[$item] : null; 97 } elseif ($name === '') { 98 $end = empty($yield) ? null : end($yield); 99 100 if (isset($end)) { 101 $inner = $value === null ? ($else ? getIfElse($end, false) : true) : parse($end, empty($else)); 102 } 103 } elseif (empty($txp_yield[$name])) { 104 $inner = null; 105 } else { 106 list($inner) = end($txp_yield[$name]); 107 } 108 109 return parse($thing, isset($inner) && ($value === null || (string)$inner === (string)$value || $inner && $value === true)); 110 } 111 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
title