Jump to content

Skyscrapers Profile


ryan

Recommended Posts

ProcessWire Skyscrapers Site Profile

This is the profile for the skyscrapers demo site as seen at: http://processwire.com/skyscrapers/.

This site profile release also coincides with some upgrades to the Skyscrapers site. The updates were to re-do many of the template files to make them easier to read, convert some classes to functions (easier for folks to understand), and convert the maps to use the FieldtypeMapMarker module.

The main differences from the live site are that this profile excludes most of the photos and skyscraper text. Only the photos taken by me are included. This is to ensure we aren’t distributing any text or photos in case the license ever changes to something other than Wikimedia Commons. I can change the text/photos on my skyscrapers site, but can’t on any sites someone else sets up with this profile, so figure it’s better to play it safe.

Requirements

  • ProcessWire 2.3
  • OR ProcessWire 2.2 dev branch (2.2.12 or newer) ZIP

How to install

  • Get the latest version of ProcessWire 2.3. At the time this text was written, ProcessWire 2.3 wasn’t yet released, so if that is still the case you’ll want to get version 2.2.12 or newer from the dev branch.
  • Before running the installer, replace all the files/directories in the /site-default/ directory of ProcessWire with those from this site profile. This includes the following:
    • /site-default/config.php
    • /site-default/install/
    • /site-default/modules/
    • /site-default/templates/

    [*]Now run the installer to complete the installation.

Template details

The template files in the profile take the approach of populating variables that are output within a main/shared markup file. This is different from the basic profile that ProcessWire comes with. Specifically, make note of the following files:

  • /site/templates/_init.php – This file is automatically included before any template file is executed. We use it to initialize the variables we populate and include a shared library of functions.
  • /site/templates/_out.php – This file is automatically included after any template file is executed. In our case, we use it to contain our main markup that also outputs the variables we populated.
  • /site/templates/includes/functions.php – This is where we are keeping a shared library of functions, most for generating skyscraper list markup.
  • /site/templates/*.php – These are the site’s template files, each named consistently with the page(s) they represent. The primary focus of these files is to populate the $content variable that is output by _out.php.

The use of _init.php and _out.php are something new to ProcessWire 2.3. These are specified in the /site/config.php:

$config->prependTemplateFile = '_init.php';
$config->appendTemplateFile = '_out.php';

Use of this new feature is optional. We’ve used it in this profile because it reduces the amount of redundant include() code necessary in each of our template files.

Download

skyscrapers-screenshot.jpg

  • Like 19
Link to comment
Share on other sites

Greetings Ryan,

Since it's not possible to "multi-like" a post, I'll just unofficially add them here...

Like Like Like Like Like Like Like Like Like Like Like Like

I've been waiting for the Skyscraper profile to be available for the newest version ProcessWire. There is a lot in that profile that is extremely valuable.

Thank you again for all your amazing work.

Matthew

  • Like 1
Link to comment
Share on other sites

  • 1 month later...
  • 4 months later...

Hello Ryan,

I tried to install yout theme exactly as described.

But after the installation I only see iun the front page a 500 error and in the backend it looks like I have the standard theme installed.

Can you help me figure out what went wrong so maybe I can make my site with PW.


Roelof

Link to comment
Share on other sites

  • 2 months later...

I would really like to get a detailed understanding of the Skyscraper profile functions file. These particular questions are in regards to the following two functions

1. 

function getValidSkyscraperSorts() {
return array(
  // field => label
  'images' => 'Images',
  'title' => 'Title',
  'parent' => 'City',
  'height' => 'Height',
  'floors' => 'Floors',
  'year' => 'Year',
  );
}

The above returns and array of fields and their labels, but what if you just had one field and label. No need for an arrary, so how would that look?

2. 

function renderSkyscraperListHeader() {

// get the 'sort' property, if it's been used
$sort = wire('input')->whitelist('sort');
if(!$sort) $sort = 'title';

// query string that will be used to retain GET variables in table header sort links
$queryString = '';

// make a query string from variables that have been stuffed into $input->whitelist
// to use with the table header sort links
foreach(wire('input')->whitelist as $key => $value) {
  if($key == 'sort') continue;
  $queryString .= "&$key=" . urlencode($value);
}
$out = "\n\t<thead>\n\t<tr>";

// build the table header with sort links
foreach(getValidSkyscraperSorts() as $key => $value) {

  // check if they want to reverse the sort
  if($key == $sort) {
   $key = "-$sort";
   $value = "<strong>$value »</strong>";
  } else if("-$key" == $sort) {
   $key = ltrim($sort, '-');
   $value = "<strong>$value «</strong>";
  }
  $out .= "<th><a href='./?sort=$key$queryString'>$value</a></th>";
}
$out .= "\n\t</tr>\n\t</thead>";
return $out;
}

The above is very well explained, but lets say that you do not want to output the header sort links because you already have the header labels elsewhere. Or lets say you only want to be able to sort 2 of the 6 fields instead. Whats the best approach to sort just one or two of the 6 fields without outputting them all in the above function? For example, I would like to sort Height and Year only.

Link to comment
Share on other sites

The above returns and array of fields and their labels, but what if you just had one field and label. No need for an arrary, so how would that look?

In that case, you would't need the function at all. Your code could just do something like this:

if($input->get->sort == 'floors') {
  $sort = 'floors';
} else {
  $sort = 'title';
} 
Whats the best approach to sort just one or two of the 6 fields without outputting them all in the above function? For example, I would like to sort Height and Year only.

I think that putting them in a select box is a good way to go. See the modules site for an example: http://modules.processwire.com/modules/?sort=-created

  • Like 1
Link to comment
Share on other sites

  • 7 months later...

I noticed in the files architect.php and city.php these minor difference in code:

$content = renderSkyscraperList(findSkyscrapers("architects=$page"));
$content = renderSkyscraperList(findSkyscrapers("parent=$page"));

But if I a not mistaking, they are basically telling the same thing, one explicitly and the other dynamically. Hope I am right?

Link to comment
Share on other sites

I haven't ever looked at the skyscrapers profile, but the first is listing skyscrapers where the name of the architect is the same as the name of the current page (so finding anything to do with that particular architect)

Whereas the second is listing the skyscrapers who's parent page is the same as the current page. 

So they are both explicit statements but looking for different criteria 

Link to comment
Share on other sites

That's funny :)

I think I came along your unbuild skyscraper:

https://processwire.com/talk/topic/5925-trying-to-expand-search-form/#entry57888

but in other words:

considering architects (parent) > architect (child)

$content = renderSkyscraperList(findSkyscrapers("architects=$page"));

current page is architect (child) will give me items by architect (child).

considering cities (parent) > city (child) > item-name (child)

$content = renderSkyscraperList(findSkyscrapers("parent=$page"));

current page is city (child) will give me the item-name (child) that has the parent city (child).

I had to go through explanations several times. lol

Link to comment
Share on other sites

I am playing with the selector from skyscrapers - in the following code from the file:

includes/functions.php

function makePrettySelector($selector) {
    if(preg_match('/(architects|parent)=(\d+)/', $selector, $matches)) {
        if($page = wire('pages')->get($matches[2]))
            $selector = str_replace($matches[0], "$matches[1]={$page->path}", $selector);
        if($matches[1] == 'parent') $selector = str_replace("template=skyscraper, ", "", $selector); // template not necessary here
    }
    return $selector;
}

the selector returns output, explaining what was selected (to search).

But what if I wanted to output anything what could be searched or selected? This code puzzles me :

if(preg_match('/(architects|specialties|materials|parent)=(\d+)/', $selector, $matches)) {

Is there no wildcard to use for this?

Link to comment
Share on other sites

  • 1 month later...
  • 5 months later...
  • 2 weeks later...

After I connect to database and then click continue this is what i see ... nothing than happens 

Test Database and Save Configuration
  •  Database connection successful to pw_sky4
  •  Saved configuration to ./site/config.php
Link to comment
Share on other sites

  • 3 weeks later...

I also cannot get it to install on a 2.5 installation.  I have copied the files to site-default folder and when I go to install page the default is not showing, only the other profiles.

sky-install.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...