1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-31 18:31:56 +02:00

Initial commit to new repo (carried over from: https://github.com/ryancramerdesign/ProcessWire/tree/devns)

This commit is contained in:
Ryan Cramer
2016-09-02 14:55:17 -04:00
parent cfae5fc6f3
commit bac5b0de5d
1691 changed files with 279091 additions and 1 deletions

View File

@@ -0,0 +1,18 @@
MULTI-LANGUAGE DEFAULT PROFILE
Please see this HTML document for an introduction to how this
site profile works:
http://processwire.com/docs/tutorials/default-site-profile/
The files in this templates directory are largely identical to those
in the non-multi-language version except for use of these static text
translation functions in _main.php and search.php:
__('text');
_x('text', 'context label');
_n('singular', 'plural', $count);
Please see this page for more information about how these are used:
http://processwire.com/api/multi-language-support/code-i18n/

View File

@@ -0,0 +1,121 @@
<?php namespace ProcessWire;
/**
* /site/templates/_func.php
*
* Example of shared functions used by template files
*
* This file is currently included by _init.php
*
* FUN FACT: This file is identical to the one in the NON-multi-language
* version of this site profile (site-default). In fact, it's rare that
* one has to think about languages when developing a multi-language
* site in ProcessWire.
*
*/
/**
* Given a group of pages, render a simple <ul> navigation
*
* This is here to demonstrate an example of a simple shared function.
* Usage is completely optional.
*
* @param PageArray $items
* @return string
*
*/
function renderNav(PageArray $items) {
// $out is where we store the markup we are creating in this function
$out = '';
// cycle through all the items
foreach($items as $item) {
// render markup for each navigation item as an <li>
if($item->id == wire('page')->id) {
// if current item is the same as the page being viewed, add a "current" class to it
$out .= "<li class='current'>";
} else {
// otherwise just a regular list item
$out .= "<li>";
}
// markup for the link
$out .= "<a href='$item->url'>$item->title</a> ";
// if the item has summary text, include that too
if($item->summary) $out .= "<div class='summary'>$item->summary</div>";
// close the list item
$out .= "</li>";
}
// if output was generated above, wrap it in a <ul>
if($out) $out = "<ul class='nav'>$out</ul>\n";
// return the markup we generated above
return $out;
}
/**
* Given a group of pages, render a <ul> navigation tree
*
* This is here to demonstrate an example of a more intermediate level
* shared function and usage is completely optional. This is very similar to
* the renderNav() function above except that it can output more than one
* level of navigation (recursively) and can include other fields in the output.
*
* @param array|PageArray $items
* @param int $maxDepth How many levels of navigation below current should it go?
* @param string $fieldNames Any extra field names to display (separate multiple fields with a space)
* @param string $class CSS class name for containing <ul>
* @return string
*
*/
function renderNavTree($items, $maxDepth = 0, $fieldNames = '', $class = 'nav') {
// if we were given a single Page rather than a group of them, we'll pretend they
// gave us a group of them (a group/array of 1)
if($items instanceof Page) $items = array($items);
// $out is where we store the markup we are creating in this function
$out = '';
// cycle through all the items
foreach($items as $item) {
// markup for the list item...
// if current item is the same as the page being viewed, add a "current" class to it
$out .= $item->id == wire('page')->id ? "<li class='current'>" : "<li>";
// markup for the link
$out .= "<a href='$item->url'>$item->title</a>";
// if there are extra field names specified, render markup for each one in a <div>
// having a class name the same as the field name
if($fieldNames) foreach(explode(' ', $fieldNames) as $fieldName) {
$value = $item->get($fieldName);
if($value) $out .= " <div class='$fieldName'>$value</div>";
}
// if the item has children and we're allowed to output tree navigation (maxDepth)
// then call this same function again for the item's children
if($item->hasChildren() && $maxDepth) {
if($class == 'nav') $class = 'nav nav-tree';
$out .= renderNavTree($item->children, $maxDepth-1, $fieldNames, $class);
}
// close the list item
$out .= "</li>";
}
// if output was generated above, wrap it in a <ul>
if($out) $out = "<ul class='$class'>$out</ul>\n";
// return the markup we generated above
return $out;
}

View File

@@ -0,0 +1,30 @@
<?php namespace ProcessWire;
/**
* Initialize variables output in _main.php
*
* Values populated to these may be changed as desired by each template file.
* You can setup as many such variables as you'd like.
*
* This file is automatically prepended to all template files as a result of:
* $config->prependTemplateFile = '_init.php'; in /site/config.php.
*
* If you want to disable this automatic inclusion for any given template,
* go in your admin to Setup > Templates > [some-template] and click on the
* "Files" tab. Check the box to "Disable automatic prepend file".
*
*/
// Variables for regions we will populate in _main.php
// Here we also assign default values for each of them.
$title = $page->get('headline|title');
$content = $page->body;
$sidebar = $page->sidebar;
// We refer to our homepage a few times in our site, so
// we preload a copy here in $homepage for convenience.
$homepage = $pages->get('/');
// Include shared functions
include_once("./_func.php");

View File

@@ -0,0 +1,152 @@
<?php namespace ProcessWire;
/**
* _main.php
* Main markup file (multi-language)
* MULTI-LANGUAGE NOTE: Please see the README.txt file
*
* This file contains all the main markup for the site and outputs the regions
* defined in the initialization (_init.php) file. These regions include:
*
* $title: The page title/headline
* $content: The markup that appears in the main content/body copy column
* $sidebar: The markup that appears in the sidebar column
*
* Of course, you can add as many regions as you like, or choose not to use
* them at all! This _init.php > [template].php > _main.php scheme is just
* the methodology we chose to use in this particular site profile, and as you
* dig deeper, you'll find many others ways to do the same thing.
*
* This file is automatically appended to all template files as a result of
* $config->appendTemplateFile = '_main.php'; in /site/config.php.
*
* In any given template file, if you do not want this main markup file
* included, go in your admin to Setup > Templates > [some-template] > and
* click on the "Files" tab. Check the box to "Disable automatic append of
* file _main.php". You would do this if you wanted to echo markup directly
* from your template file or if you were using a template file for some other
* kind of output like an RSS feed or sitemap.xml, for example.
*
*
*/
?><!DOCTYPE html>
<html lang="<?php echo _x('en', 'HTML language code'); ?>">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title><?php echo $title; ?></title>
<meta name="description" content="<?php echo $page->summary; ?>" />
<link href="//fonts.googleapis.com/css?family=Lusitana:400,700|Quattrocento:400,700" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="<?php echo $config->urls->templates?>styles/main.css" />
<?php
// handle output of 'hreflang' link tags for multi-language
// this is good to do for SEO in helping search engines understand
// what languages your site is presented in
foreach($languages as $language) {
// if this page is not viewable in the language, skip it
if(!$page->viewable($language)) continue;
// get the http URL for this page in the given language
$url = $page->localHttpUrl($language);
// hreflang code for language uses language name from homepage
$hreflang = $homepage->getLanguageValue($language, 'name');
// output the <link> tag: note that this assumes your language names are the same as required by hreflang.
echo "\n\t<link rel='alternate' hreflang='$hreflang' href='$url' />";
}
?>
</head>
<body class="<?php if($sidebar) echo "has-sidebar"; ?>">
<!-- language switcher / navigation -->
<ul class='languages'><?php
foreach($languages as $language) {
if(!$page->viewable($language)) continue; // is page viewable in this language?
if($language->id == $user->language->id) {
echo "<li class='current'>";
} else {
echo "<li>";
}
$url = $page->localUrl($language);
$hreflang = $homepage->getLanguageValue($language, 'name');
echo "<a hreflang='$hreflang' href='$url'>$language->title</a></li>";
}
?></ul>
<!-- top navigation -->
<ul class='topnav'><?php
// top navigation consists of homepage and its visible children
foreach($homepage->and($homepage->children) as $item) {
if($item->id == $page->rootParent->id) {
echo "<li class='current'>";
} else {
echo "<li>";
}
echo "<a href='$item->url'>$item->title</a></li>";
}
// output an "Edit" link if this page happens to be editable by the current user
if($page->editable()) echo "<li class='edit'><a href='$page->editUrl'>" . __('Edit') . "</a></li>";
?></ul>
<!-- breadcrumbs -->
<div class='breadcrumbs'><?php
// breadcrumbs are the current page's parents
foreach($page->parents() as $item) {
echo "<span><a href='$item->url'>$item->title</a></span> ";
}
// optionally output the current page as the last item
echo "<span>$page->title</span> ";
?></div>
<!-- search engine -->
<form class='search' action='<?php echo $pages->get('template=search')->url; ?>' method='get'>
<input type='text' name='q' placeholder='<?php echo _x('Search', 'placeholder'); ?>' />
<button type='submit' name='submit'><?php echo _x('Search', 'button'); ?></button>
</form>
<div id='main'>
<!-- main content -->
<div id='content'>
<h1><?php echo $title; ?></h1>
<?php echo $content; ?>
</div>
<!-- sidebar content -->
<?php if($sidebar): ?>
<div id='sidebar'>
<?php echo $sidebar; ?>
</div>
<?php endif; ?>
</div>
<!-- footer -->
<footer id='footer'>
<p>
<a href='http://processwire.com'><?php echo __('Powered by ProcessWire CMS'); ?></a> &nbsp; / &nbsp;
<?php
if($user->isLoggedin()) {
// if user is logged in, show a logout link
echo "<a href='{$config->urls->admin}login/logout/'>" . sprintf(__('Logout (%s)'), $user->name) . "</a>";
} else {
// if user not logged in, show a login link
echo "<a href='{$config->urls->admin}'>" . __('Admin Login') . "</a>";
}
?>
</p>
</footer>
</body>
</html>

View File

@@ -0,0 +1,15 @@
<?php namespace ProcessWire;
/**
* Admin template just loads the admin application controller,
* and admin is just an application built on top of ProcessWire.
*
* This demonstrates how you can use ProcessWire as a front-end
* to another application.
*
* Feel free to hook admin-specific functionality from this file,
* but remember to leave the require() statement below at the end.
*
*/
require($config->paths->adminTemplates . 'controller.php');

View File

@@ -0,0 +1,21 @@
<?php namespace ProcessWire;
// basic-page.php template file
// Primary content is the page's body copy
$content = $page->body;
// If the page has children, then render navigation to them under the body.
// See the _func.php for the renderNav example function.
if($page->hasChildren) {
$content .= renderNav($page->children);
}
// if the rootParent (section) page has more than 1 child, then render
// section navigation in the sidebar (see _func.php for renderNavTree).
if($page->rootParent->hasChildren > 1) {
$sidebar = renderNavTree($page->rootParent, 3);
// make any sidebar text appear after navigation
$sidebar .= $page->sidebar;
}

View File

@@ -0,0 +1,11 @@
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
<head>
<title>500 Internal Server Error</title>
</head>
<body>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error or misconfiguration and was unable to complete your request.</p>
<p>{message}</p>
</body>
</html>

View File

@@ -0,0 +1,21 @@
When a fatal error occurs, ProcessWire displays the message:
"Unable to complete this request due to an error."
The message is intentionally vague for security purposes.
Details will be logged to /site/assets/logs/errors.txt.
When present in this directory, the file 500.html will be
displayed instead of the generic error message above. Feel
free to modify this file to show whatever you would like.
Please note the following:
* 500.html is plain HTML and has no PHP or API access.
* You may enter the tag {message} and ProcessWire will
replace this with additional details when applicable.
When not applicable, it will make it blank.
* If you are logged in as an admin, ProcessWire will
give you a detailed error message rather than 500.html.

View File

@@ -0,0 +1,35 @@
<?php namespace ProcessWire;
// home.php (homepage) template file.
// Primary content is the page body copy
$content = $page->body;
// Append navigation to child pages underneath the body copy
// See the _func.php file for the renderNav() function example
$content .= renderNav($page->children);
// if there are images, lets choose one to output in the sidebar
if(count($page->images)) {
// if the page has images on it, grab one of them randomly...
$image = $page->images->getRandom();
// resize it to 400 pixels wide
$image = $image->width(400);
// output the image at the top of the sidebar
$sidebar = "<img src='$image->url' alt='$image->description' />";
// if image has a description, display it underneath
if($image->description) $sidebar .= "<blockquote>$image->description</blockquote>";
// append sidebar text content if page has it
$sidebar .= $page->sidebar;
} else {
// no images...
// make sidebar contain text content if page has it
$sidebar = $page->sidebar;
}

View File

@@ -0,0 +1,3 @@
// Well hello there. Looks like we don't have any Javascript.
// Maybe you could help a friend out and put some in here?
// Or at least, when ready, this might be a good place for it.

View File

@@ -0,0 +1,53 @@
<?php namespace ProcessWire;
// look for a GET variable named 'q' and sanitize it
$q = $sanitizer->text($input->get->q);
// did $q have anything in it?
if($q) {
// Send our sanitized query 'q' variable to the whitelist where it will be
// picked up and echoed in the search box by _main.php file. Now we could just use
// another variable initialized in _init.php for this, but it's a best practice
// to use this whitelist since it can be read by other modules. That becomes
// valuable when it comes to things like pagination.
$input->whitelist('q', $q);
// Sanitize for placement within a selector string. This is important for any
// values that you plan to bundle in a selector string like we are doing here.
$q = $sanitizer->selectorValue($q);
// Search the title and body fields for our query text.
// Limit the results to 50 pages.
$selector = "title|body~=$q, limit=50";
// If user has access to admin pages, lets exclude them from the search results.
// Note that 2 is the ID of the admin page, so this excludes all results that have
// that page as one of the parents/ancestors. This isn't necessary if the user
// doesn't have access to view admin pages. So it's not technically necessary to
// have this here, but we thought it might be a good way to introduce has_parent.
if($user->isLoggedin()) $selector .= ", has_parent!=2";
// Find pages that match the selector
$matches = $pages->find($selector);
$cnt = $matches->count;
// did we find any matches?
if($cnt) {
// yes we did: output a headline indicating how many were found.
// note how we handle singular vs. plural for multi-language, with the _n() function
$content = "<h2>" . sprintf(_n('Found %d page', 'Found %d pages', $cnt), $cnt) . "</h2>";
// we'll use our renderNav function (in _func.php) to render the navigation
$content .= renderNav($matches);
} else {
// we didn't find any
$content = "<h2>" . __('Sorry, no results were found.') . "</h2>";
}
} else {
// no search terms provided
$content = "<h2>" . __('Please enter a search term in the search box (upper right corner)') . "</h2>";
}

View File

@@ -0,0 +1,8 @@
<?php namespace ProcessWire;
// sitemap.php template file
// Generate navigation that descends up to 4 levels into the tree.
// See the _func.php for the renderNav() function definition.
$content = renderNavTree($homepage, 4);

View File

@@ -0,0 +1,353 @@
/**
* main.css
*
* 1. General HTML tags
* 2. Masthead area
* 3. Main content and sidebar
* 4. Footer
* 5. Media queries for responsive layout
*
*/
/*********************************************************************
* 1. General HTML tags
*
*/
* {
box-sizing: border-box;
}
body {
padding: 5%;
max-width: 1600px;
margin: 0 auto;
}
body, td, input[type=text], textarea {
font-family: 'Quattrocento', serif;
font-size: 105%;
line-height: 1.8em;
color: #444;
}
img {
max-width: 100%;
}
h2 {
font-weight: normal;
}
h3 {
border-top: 1px solid #eee;
padding-top: 1em;
color: #777;
}
a {
color: #333;
text-decoration: none;
border-bottom: 1px solid #ccc;
}
a:hover,
.nav a:hover {
color: #000;
border-color: #aaa;
}
blockquote {
margin-left: 0;
padding-left: 1.5em;
padding-right: 2em;
border-left: 4px solid #ddd;
font-style: italic;
color: #777;
}
pre, code {
background: #eee;
border: 1px solid #ddd;
}
pre {
font-size: 14px;
line-height: 1.4em;
padding: 1em;
border-left: 4px solid #ddd;
}
/*********************************************************************
* 2. Masthead area
*
*/
.topnav, .topnav li {
list-style: none;
padding: 0;
margin: 0;
}
.topnav li {
float: left;
margin-right: 1em;
margin-bottom: 1em;
}
.topnav a {
padding: 0.25em 0.5em;
text-decoration: none;
display: block;
background: #eee;
color: #333;
border: 1px solid #eee;
}
.topnav a:hover {
background: #ddd;
border-color: #ddd;
}
.topnav li.current a {
background: #ddd;
border-color: #ddd;
}
.topnav li.edit a {
background: none;
}
.languages {
list-style: none;
margin: 0;
padding: 0;
float: right;
width: 30%;
font-size: 80%;
}
.languages li {
list-style: none;
display: inline-block;
margin: 0;
padding: 0;
}
.languages a {
padding: 0 0.5em;
border: none;
display: inline;
border-left: 1px solid #ccc;
}
.languages li.current a {
font-weight: bold;
}
.languages li:first-child a {
border: none;
padding-left: 0;
}
form.search {
float: right;
margin: 0;
width: 30%;
padding-bottom: 1em;
}
form.search input {
margin: 0;
padding: 0.25em 0.5em;
border: 1px solid #ccc;
width: 100%;
}
form.search button {
display: none;
}
.breadcrumbs {
font-size: 80%;
width: 70%;
float: left;
clear: both;
padding-top: 1em;
}
.breadcrumbs span:after {
content: ">";
color: #999;
padding-left: 0.5em;
padding-right: 0.25em;
}
/*********************************************************************
* 3. Main content and sidebar
*
*/
#main {
border-top: 1px solid #eee;
padding-top: 1em;
margin-top: 1em;
clear: both;
}
#content {
width: 85%;
}
#content, #sidebar {
padding-bottom: 2em;
}
body.has-sidebar #content {
width: 65%;
float: left;
}
body.has-sidebar #sidebar {
width: 35%;
padding-left: 5%;
float: left;
}
.nav {
margin-left: 0;
padding-left: 0;
list-style: none;
}
.nav .nav {
padding-left: 1.5em;
list-style: disc;
}
.nav li {
margin: 1em 0;
}
.nav-tree li {
margin-top: 0;
margin-bottom: 0;
}
.nav a {
font-weight: bold;
}
.nav-tree li a {
color: #777;
}
.nav .current > a {
color: #333;
}
#sidebar img + blockquote {
margin-top: 0;
}
.align_left {
/* for images placed in rich text editor */
float: left;
margin: 0 1em 0.5em 0;
position: relative;
top: 0.5em;
max-width: 50%;
}
.align_right {
/* for images placed in rich text editor */
float: right;
margin: 0 0 0.5em 1em;
max-width: 50%;
}
.align_center {
/* for images placed in rich text editor */
display: block;
margin: 1em auto;
position: relative;
top: 0.5em;
}
figure {
display: table;
width: 1px;
margin: 1em 0;
}
figure img {
display: table-row;
margin-bottom: 0.5em;
}
figure figcaption {
display: table-row;
font-size: smaller;
color: #777;
line-height: 1.4em;
}
/*********************************************************************
* 4. Footer
*
*/
#footer {
clear: both;
border-top: 1px solid #eee;
font-size: 80%;
}
/*********************************************************************
* 5. Media queries for responsive layout
*
*/
@media only screen and (max-width: 767px) {
/* mobile layout */
.languages {
width: 100%;
margin-bottom: 1em;
}
.topnav {
float: none;
clear: both;
width: 100%;
}
.breadcrumbs {
margin-bottom: 1em;
margin-top: 0;
}
body, td, textarea {
font-size: 100%;
}
body.has-sidebar #content,
body.has-sidebar #sidebar {
float: none;
width: 100%;
padding: 0;
}
form.search {
float: none;
width: 100%;
padding-bottom: 0;
}
#content {
width: 100%;
}
#sidebar {
border-top: 1px solid #eee;
padding-top: 1em;
}
.align_left, .align_right, .align_center {
display: block;
float: none;
margin: 1em auto;
max-width: 100%;
}
}
@media only screen and (min-width: 1200px) {
/* extra-wide desktop layout */
body, td, textarea {
font-size: 115%;
}
}