Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Commit

Permalink
Merge pull request #74 from Jorenm/master
Browse files Browse the repository at this point in the history
Block grid fix
  • Loading branch information
bensternthal committed Jan 1, 2015
2 parents baeada1 + 3df5bf5 commit 1a6265a
Show file tree
Hide file tree
Showing 119 changed files with 32,217 additions and 76 deletions.
2 changes: 1 addition & 1 deletion plugins/the-open-standard-modals/js/modals.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function ModalsClass() {
$('body').on('click', 'a[data-modal]', function() {
var modalUrl = $(this).attr('data-modal-content');
var modalQuery = $(this).attr('data-modal-query');

Modals.open(modalUrl || null, modalQuery, true);
return false;
});
Expand Down
104 changes: 29 additions & 75 deletions themes/theopenstandard/content-filters.php
Original file line number Diff line number Diff line change
@@ -1,96 +1,50 @@
<?php
// The content from the wysiwyg has empty text nodes between tags and I want to ignore them.
function get_real_previous_sibling($node) {
if ($node->previousSibling && $node->previousSibling->nodeName == '#text' && ctype_space($node->previousSibling->nodeValue)) {
return $node->previousSibling->previousSibling;
}
return $node->previousSibling;
}
require 'vendor/querypath/src/qp.php';

function inner_html(DOMNode $element) {
$innerHTML = "";
$children = $element->childNodes;
foreach ($children as $child) {
$innerHTML .= $element->ownerDocument->saveHTML($child);
}

return $innerHTML;
}

function fragment_from_html($doc, $html) {
$fragment = $doc->createDocumentFragment();
$fragment->appendXML($html);
return $fragment;
function startsWith($haystack, $needle) {
$length = strlen($needle);
return (substr($haystack, 0, $length) === $needle);
}

// Parse out consequtive p::content and put them into block grids.
function add_block_grids($content) {
// DOMDocument seems to have problems with the long dash, this fixes it.
$content = mb_convert_encoding($content, 'utf-8', mb_detect_encoding($content));
$content = mb_convert_encoding($content, 'html-entities', 'utf-8');

$document = new DOMDocument('1.0', 'utf-8');

set_error_handler(function() { /* ignore errors */ });
if (phpversion() >= 5.4) {
$document->loadHTML($content, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
} else {
$document->loadHTML($content);

}
restore_error_handler();

$xpath = new DOMXpath($document);

$blocks = $xpath->query("//p[starts-with(.,'::')]");
$content = qp($content);
$blocks = $content->xpath("//p[starts-with(.,'::')]");

$block_groups = array();
$block_group = null;

$last_block = null;
foreach ($blocks as $block) {
$previous_sibling = get_real_previous_sibling($block);
if ($last_block && $previous_sibling && $previous_sibling->isSameNode($last_block)) {
// We're still in the same block group.
$block_group[] = $block;
$prev = $block->branch()->prev();
$next = $block->branch()->next();

$innerHTML = str_replace('::', '', $block->html());

if ($block_group
&& (
count($prev)
&& startsWith($prev->text(), '::')
)
) {
$block_group->append('<li></li>')->find('li:last-child')->html($innerHTML)->end();
$block->remove();
} else {
if ($block_group) {
// We've found a new series of blocks, so start a new array for them.
$block_groups[] = $block_group;
$block_group = array($block);
} else {
// It's our first group
$block_group = array($block);
$block_groups[] = &$block_group;
}
$block_group = qp('<ul></ul>', 'ul');
$block_group->append('<li></li>')->find('li:last-child')->html($innerHTML)->end();
$block_groups[] = $block_group;
}

$last_block = $block;
}

foreach ($block_groups as $block_group) {
$ul = $document->createElement('ul');
$blocks = $content->xpath("//p[starts-with(.,'::')]");

$count = count($block_group);
$ul->setAttribute('class', "medium-block-grid-$count takeaways innovate");

// Insert the UL before the block group p tags
$block_group[0]->parentNode->insertBefore($ul, $block_group[0]);

foreach ($block_group as $block) {
$li = $document->createElement('li');
$inner_html = inner_html($block);
$inner_html = str_replace('::', '', $inner_html);
// Erase current contents
$block->nodeValue = '';
// Append contents with '::' replaced
$block->appendChild(fragment_from_html($document, $inner_html));
$li->appendChild($block);
$ul->appendChild($li);
}
foreach ($blocks as $block) {
$block_grid = array_shift($block_groups);
$count = count($block_grid->branch()->find('li'));
$block_grid->find('ul')->attr('class', "medium-block-grid-$count takeaways innovate");
$block->replaceWith($block_grid);
}

return preg_replace("~<(?:!DOCTYPE|/?(?:html|head|body))[^>]*>\s*~i", '', $document->saveHTML());
return $content->html();
}

add_filter('the_content', 'add_block_grids');
Expand Down
14 changes: 14 additions & 0 deletions themes/theopenstandard/vendor/querypath/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
bin/build
bin/local
bin/*.tgz
bin/*.zip
*.tmproj
releases
dist
test/coverage
test/reports
test/db
docs/*
doc/*
bin/querypath-200x333.png
test/fakepear
61 changes: 61 additions & 0 deletions themes/theopenstandard/vendor/querypath/API
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
API Changes in 3.0.0

This is a major update. See the main changes for details.

API Changes in 2.1.1

* NEW METHOD: document() returns the DOMDocument
* BUG FIX: Issue #10 has been re-fixed to correctly collapse certain empty tags.
* BUG FIX: Issue #10 has been re-fixed to correctly escape JavaScript for browsers.
* BUG FIX: Issue #47 has been fixed to only remove XML declaration, but leave DOCTYPE.
* NEW ARGUMENT: xpath() now supports $options, which includes the ability to set a namespace.

API Changes in 2.1

All changes are documented in their respective doc blocks. So take a
look at http://api.querypath.org to learn more.

New Functions
* The `htmlqp()` method has been added for parsing icky HTML. Use
this for web scraping.

Altered Functions
* The qp() function now supports the following new options:
- convert_to_encoding
- convert_from_encoding
- strip_low_ascii
- use_parser

New Methods
* attach()/detach()
* has()
* emptyElement()
* even()/odd()
* first()/last()
* firstChild()/lastChild()
* nextUntil()/prevUntil()
* parentsUntil()
* encodeDataURL()
* dataURL()
* filterPreg()
* textBefore()/textAfter()

Altered Methods
* css() has been changed to allow subsequent calls
to modify the style attribute (issue #28)
* attr() has been changed. If it is called with no
arguments, it now returns all attributes.

New CSS Selectors Behavior

* :contains-exactly() performs as :contains() used to perform.

Altered CSS Selectors Behavior

* The star operator (*) is now non-greedy, per spec. Before, the star would match
any descendants. Now it will only match children.
* :contains() now does substring matching instead of exact matching. This conforms
to jQuery's behavior.
* Quotes are now checked carefully before being stripped from pseudo-class values.
* Issue #40 identified a potential infinite looping problem on poorly formed selectors.
This was fixed.
18 changes: 18 additions & 0 deletions themes/theopenstandard/vendor/querypath/COPYING-LGPL.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
QueryPath: Find Your Way
Matt Butcher <mbutcher@aleph-null.tv>
Copyright (C) 2009 Matt Butcher

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

21 changes: 21 additions & 0 deletions themes/theopenstandard/vendor/querypath/COPYING-MIT.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
QueryPath: Find your way
Matt Butcher <mbutcher@aleph-null.tv>
Copyright (C) 2009 Matt Butcher

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
12 changes: 12 additions & 0 deletions themes/theopenstandard/vendor/querypath/CREDITS
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Matt Butcher [technosophos] <matt@aleph-null.tv> (lead)
Emily Brand [eabrand] <emily@example.com> (developer)
Woody Gilk [shadowhand] <woody@wingsc.com> (contributor)
Xandar Guzman [theshadow] <theshadow@shadowpedia.info> (contributor)
Bobby Jack [fiveminuteargument] <editor@fiveminuteargument.com> (contributor)
Steven Lischer [TomorrowToday] <xcpostman06@gmail.com> (contributor)
GDMac [GDMac] <gdmac@example.com> (contributor)
Bill Ortell [billortell] <allthingsweb20@gmail.com> (contributor)
hakre [hakre] <http://hakre.wordpress.com/credits/> (contributor)
katzwebservices [katzwebservices] <katzwebservices@example.com> (contributor)
Markus Kalkbrenner [mkalkbrenner] <mkalkbrenner@users.sourceforge.net> (contributor)
Akihiro Yamanoi [noisan] <akihiro.yamanoi@gmail.com> (contributor)
80 changes: 80 additions & 0 deletions themes/theopenstandard/vendor/querypath/INSTALL
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
INSTALLING QUERYPATH
==============================

There are two distributions of QueryPath:

1. The full version, which includes source, documentation, unit tests,
and examples.

2. The minimal version, which includes only the source code in
compacted form.

INSTALLING THE MINIMAL VERSION
==============================
To install QueryPath-minimal:
- Extract the contents of the archive:

tar -zxvf QueryPath-2.0-minimal.tgz

- Move the extracted directory to the desired location. Generally,
it is best to rename this folder 'QueryPath'.

mv QueryPath-2.0-minimal myproject/QueryPath

(Alternately, you may wish to install QueryPath in a location available on
you PHP library path for use in all applications on your system.)

- Include QueryPath in your scripts:

require 'QueryPath/QueryPath.php';

- The minimal package does not contain any documentation. To view
the documentation online, go to http://api.querypath.org.

INSTALLING THE FULL VERSION
==============================
To install QueryPath:

- Extract the contents of the archive.

tar -zxvf QueryPath-2.0.tgz

- Copy the src/QueryPath directory to the desired location.

cp QueryPath-2.0/src/QueryPath myproject

- Include QueryPath/QueryPath.php in your PHP scripts

require 'QueryPath/QueryPath.php';

The structure of the full version:

/ -- Base information about the library
src/ -- The source (PHP) code. Include the contents of this directory in your
applications.
test/ -- Unit tests for QueryPath. You can run these with PHPUnit.
examples/ -- Examples scripts written with QueryPath.
docs/ -- Full API documentation in HTML format. You can regenerate this from
the source using PHPDocumentor.
tutorials/ -- DocBook additions to the QueryPath PHPDocumentor data. An HTML
version of this is included in the docs/ directory. The files here are
probably only useful when re-generating the API documentation.


INSTALLING FROM GitHub
==============================

The complete source code and all utilities for QueryPath are located in a GitHub
repository. If you plan on contributing back to QueryPath, you will be able to
achieve the most by working from the GitHub source. Here's how:

1. Obtain the source code from here: http://github.com/technosophos/querypath

2. Install PHPDocumentor, PHPUnit, and Phing. XDebug is strongly recommended for
doing coverage analysis. These tools are used to auto-generate
documentation, run unit tests, and manage project builds.

3. Run 'phing info' from the base QueryPath checkout. This will tell you how to
perform various tasks with QueryPath.

For more information, visit http://querypath.org.

0 comments on commit 1a6265a

Please sign in to comment.