Skip to content

Instantly share code, notes, and snippets.

@katzueno
Last active January 9, 2016 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katzueno/146261d07111ad23fe44 to your computer and use it in GitHub Desktop.
Save katzueno/146261d07111ad23fe44 to your computer and use it in GitHub Desktop.
concrete5.7 Theme Page Template file sample which just redirect to another page

concrete5.7.x Page Template sample which just to redirect for rich attributes in Page List or Autonav blocks / ページリストで追加の属性情報を表示させる時とかに使える、シンプルにリダイレクトをするためのページテンプレート

Sometime, "external link" doesn't fulfill your requirement for the page. You may want to display thumbnail image, additional page attribute such as topic and selector attributes to display the categories of the page.

This tutorial explains how to set-up redirect-only page with more page attributes option by creating redirect-only page template and page type in your theme.

(You may also want to customize your Page List and/or Autonav Blocks if you want to avoid additional redirect requests)

Disclaimer

I hold no responsibility over any damages caused by using this script.

Requirement

This uses Page Selector Attribute

https://www.concrete5.org/marketplace/addons/page-selector-attribute1/

How to set-it up

Currently, if you are the site editor who can see the concrete5 toolbar on top, you won't get redirected but stayed on the page so that you'll be able to edit.

Basic Set-ups

  • Copy and paste redirect.php below and create a page template under your theme.
  • Create a page type. Add composer elements to enter page name, url and the following page attributes.

external_page Page Selector Attribute

Create a page selector attribute called "external_page"

Or comment out or delete from line 6-10.

external_link Text Attribute

Create a text page attribute called external_link, which you enter URL.

If both externap_page and external_link was entered, externap_page will be used.

Hint: You could add File Attributes

You could add File Attribute to have them download the file.

Credit

concrete5 Japan, Inc. is helping various company's concrete5 project. Please feel free to contact us at any time for your project needs. We can work internationally.

http://concrete5.co.jp/

日本語

concrete5 のデフォルトの外部リンクは、ページリストやオートナビブロックで属性情報を追加できません。なので、リダイレクト専用のページテンプレートを作成するといいかもです。

(このカスタマイズは余分なリダイレクトリクエストを増やすので、それを好まない方は Page List や オートナビブロックより直接外部リンクに飛ぶように設定されるのも推奨します。)

免責

このコードは無保証です。

必須アドオン

「Page Selector Attribute」という無料アドオンを使用します。 https://www.concrete5.org/marketplace/addons/page-selector-attribute1/

使用方法

セットアップ

  • redirect.php ファイルを自分のテーマファイルにコピーし redirect というハンドルでページテンプレートを作成してください。。
  • ページタイプを作成し、コンポーザーで、ページ名、URLや属性を追加できるように設定しておきましょう。

このページテンプレートで作成するページは、フルサイトマップでのみ使える想定です。

「external_page」 ページ選択 ページ属性

アドオンをインストールして作った、「external_page」属性を作成してください。

必要に応じて、Line 6-10 を削除したりコメントアウトしてください。

「external_link」 テキスト ページ属性

「external_link」というテキスト (1行) のページ属性を入れてください。

現在のコードでは、「external_page」 と「external_link」両方に入力されている場合、「external_page」が優先されて表示するようになっています。

ヒント: ファイル属性を作ると

ファイル属性を課金コードに追加すると、ニュースリリースで PDF だけをダウンロードさせたい時とかに使えます。試してみてください。

宣伝

コンクリートファイブジャパン株式会社では、企業・団体様の concrete5 サイト制作や制作会社様のプロジェクトのサポートを行っています。また制作会社様向けに「インテグレートパートナー制度」を設け、印刷物では通常は使用禁止している concrete5 のロゴが使えるパートナー制度の運営も行っています。

http://concrete5.co.jp/

<?php defined('C5_EXECUTE') or die(_("Access Denied."));
$c = Page::getCurrentPage();
$nh = Core::make('helper/navigation');
$cp = new Permissions($c);
if ($c->getAttribute("external_page")) {
$redirect = $c->getAttribute("external_page");
$externalPage = Page::getByID($redirect);
$redirectURL = ($externalPage->getCollectionPointerExternalLink() != '') ? $externalPage->getCollectionPointerExternalLink() : $nh->getLinkToCollection($externalPage);
}
if ($c->getAttribute("external_link"))
{
$redirect = $c->getAttribute("external_link");
if (preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$redirect))
{
$redirectURL = $redirect;
} else {
$redirect = null;
}
}
if (!$redirect) {
if ($c->getCollectionParentID() > 0) {
$parentCID = $c->getCollectionParentID();
} else {
$parentCID = 1;
}
$parentC = Page::getByID($parentCID);
$redirectURL = $nh->getCollectionURL($parentC);
}
$u = new User();
if (!$cp->canViewToolbar())
{
$response = new \Concrete\Core\Routing\RedirectResponse($redirectURL);
$response->send();
exit;
} else {
// The people with Edit Permission can view this section.
?>
<!DOCTYPE html>
<html>
<head>
<?php Loader::element('header_required);?>
</head>
<body>
<div class="<?php echo $c->getPageWrapperClass()?>">
</div>
<?php Loader::element('footer_required'); ?>
</body>
</html>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment