tpl->addBlock('Attachments', ['attachmentTpl', 'Attachments']); $core->tpl->addBlock('AttachmentsHeader', ['attachmentTpl', 'AttachmentsHeader']); $core->tpl->addBlock('AttachmentsFooter', ['attachmentTpl', 'AttachmentsFooter']); $core->tpl->addValue('AttachmentMimeType', ['attachmentTpl', 'AttachmentMimeType']); $core->tpl->addValue('AttachmentType', ['attachmentTpl', 'AttachmentType']); $core->tpl->addValue('AttachmentFileName', ['attachmentTpl', 'AttachmentFileName']); $core->tpl->addValue('AttachmentSize', ['attachmentTpl', 'AttachmentSize']); $core->tpl->addValue('AttachmentTitle', ['attachmentTpl', 'AttachmentTitle']); $core->tpl->addValue('AttachmentThumbnailURL', ['attachmentTpl', 'AttachmentThumbnailURL']); $core->tpl->addValue('AttachmentURL', ['attachmentTpl', 'AttachmentURL']); $core->tpl->addValue('MediaURL', ['attachmentTpl', 'MediaURL']); $core->tpl->addBlock('AttachmentIf', ['attachmentTpl', 'AttachmentIf']); $core->tpl->addValue('EntryAttachmentCount', ['attachmentTpl', 'EntryAttachmentCount']); $core->addBehavior('tplIfConditions', ['attachmentBehavior', 'tplIfConditions']); class attachmentTpl { /*dtd */ public static function Attachments($attr, $content) { $res = "posts !== null && $core->media) {' . "\n" . '$_ctx->attachments = new ArrayObject($core->media->getPostMedia($_ctx->posts->post_id,null,"attachment"));' . "\n" . "?>\n" . 'attachments as $attach_i => $attach_f) : ' . '$GLOBALS[\'attach_i\'] = $attach_i; $GLOBALS[\'attach_f\'] = $attach_f;' . '$_ctx->file_url = $attach_f->file_url; ?>' . $content . 'attachments = null; unset($attach_i,$attach_f,$_ctx->file_url); ?>' . "\n"; return $res; } /*dtd */ public static function AttachmentsHeader($attr, $content) { return "" . $content . ""; } /*dtd */ public static function AttachmentsFooter($attr, $content) { return "attachments)) : ?>" . $content . ""; } /*dtd */ public static function AttachmentIf($attr, $content) { $if = []; $operator = isset($attr['operator']) ? dcTemplate::getOperator($attr['operator']) : '&&'; if (isset($attr['is_image'])) { $sign = (boolean) $attr['is_image'] ? '' : '!'; $if[] = $sign . '$attach_f->media_image'; } if (isset($attr['has_thumb'])) { $sign = (boolean) $attr['has_thumb'] ? '' : '!'; $if[] = $sign . 'isset($attach_f->media_thumb[\'sq\'])'; } if (isset($attr['is_mp3'])) { $sign = (boolean) $attr['is_mp3'] ? '==' : '!='; $if[] = '$attach_f->type ' . $sign . ' "audio/mpeg3"'; } if (isset($attr['is_flv'])) { $sign = (boolean) $attr['is_flv'] ? '==' : '!='; $if[] = '$attach_f->type ' . $sign . ' "video/x-flv"'; } if (isset($attr['is_audio'])) { $sign = (boolean) $attr['is_audio'] ? '==' : '!='; $if[] = '$attach_f->type_prefix ' . $sign . ' "audio"'; } if (isset($attr['is_video'])) { $sign = (boolean) $attr['is_video'] ? '==' : '!='; $if[] = '$attach_f->type_prefix ' . $sign . ' "video"'; } if (count($if) != 0) { return '' . $content . ''; } else { return $content; } } /*dtd */ public static function AttachmentMimeType($attr) { $f = $GLOBALS['core']->tpl->getFilters($attr); return 'type') . '; ?>'; } /*dtd */ public static function AttachmentType($attr) { $f = $GLOBALS['core']->tpl->getFilters($attr); return 'media_type') . '; ?>'; } /*dtd */ public static function AttachmentFileName($attr) { $f = $GLOBALS['core']->tpl->getFilters($attr); return 'basename') . '; ?>'; } /*dtd */ public static function AttachmentSize($attr) { $f = $GLOBALS['core']->tpl->getFilters($attr); if (!empty($attr['full'])) { return 'size') . '; ?>'; } return 'size)') . '; ?>'; } /*dtd */ public static function AttachmentTitle($attr) { $f = $GLOBALS['core']->tpl->getFilters($attr); return 'media_title') . '; ?>'; } /*dtd */ public static function AttachmentThumbnailURL($attr) { $f = $GLOBALS['core']->tpl->getFilters($attr); return 'media_thumb[\'sq\'])) {' . 'echo ' . sprintf($f, '$attach_f->media_thumb[\'sq\']') . ';' . '}' . '?>'; } /*dtd */ public static function AttachmentURL($attr) { $f = $GLOBALS['core']->tpl->getFilters($attr); return 'file_url') . '; ?>'; } public static function MediaURL($attr) { $f = $GLOBALS['core']->tpl->getFilters($attr); return 'file_url') . '; ?>'; } /*dtd */ public static function EntryAttachmentCount($attr) { global $core; return $core->tpl->displayCounter( '$_ctx->posts->countMedia(\'attachment\')', [ 'none' => 'no attachments', 'one' => 'one attachment', 'more' => '%d attachments' ], $attr, false ); } } class attachmentBehavior { public static function tplIfConditions($tag, $attr, $content, $if) { if ($tag == "EntryIf" && isset($attr['has_attachment'])) { $sign = (boolean) $attr['has_attachment'] ? '' : '!'; $if[] = $sign . '$_ctx->posts->countMedia(\'attachment\')'; } } }