Permalink
Browse files

Merge branch 'master' into image-helper

  • Loading branch information...
Nomafin committed Mar 10, 2017
2 parents f90812d + 6b8bd0f commit 351f31bd673f86b0660d2a5702a189f348b6da1c
Showing with 52 additions and 10 deletions.
  1. +4 −2 README.md
  2. +27 −4 classes/model.php
  3. +1 −1 docs/helpers/image.md
  4. +20 −3 dustpress.php
View
@@ -51,7 +51,7 @@ There are several other repositories that contain DustPress material as well:
## Usage
-You need to call `dustpress();` in your `functions.php` to enable DustPress. It must be naturally be done after requiring the library itself if you haven't used Composer's autoload feature.
+You need to call `dustpress();` in your `functions.php` to enable DustPress. It must naturally be done after requiring the library itself if you haven't used Composer's autoload feature.
Within your theme there must be two directories called `models` and `partials` to use DustPress. Their purpose will be explained later in this file.
@@ -448,6 +448,8 @@ Example:
{@s s="Home page" td="my-page" /}
```
+You can use a [translation parser](https://github.com/devgeniem/dustpress/wiki/Translation-parser) to find all strings defined with {@s} and write them to a file in a format that can be scanned with POedit.
+
### sep
`sep` helper is an extension to Dust's native `sep` helper. It behaves the same, but it can also be given two extra parameters: `start` and `end`. They work as the offsets of the function. By default `start` is 0 and `end` is 1.
@@ -571,7 +573,7 @@ _the echoed output_
### json output
-DustPress can output its data instead of the rendered version if the developer enables the functionality. It is done by adding one or both of following filters into your `functions.php`:
+DustPress can output its data as JSON instead of the rendered version if the developer enables the functionality. It is done by adding one or both of following filters into your `functions.php`:
```
add_filter( 'dustpress/settings/json_url', '__return_true' );
View
@@ -37,6 +37,9 @@ class Model {
// Temporary hash key
private $hash;
+ // Is execution terminated
+ private $terminated;
+
/**
* Constructor for DustPress model class.
*
@@ -247,6 +250,10 @@ public function fetch_data( $functions = null, $tidy = false ) {
}
}
}
+
+ if ( $this->terminated == true ) {
+ break 2;
+ }
}
unset( $class_methods );
@@ -329,6 +336,10 @@ private function get_class_methods( $class_name, $methods = array() ) {
* @param $name (string), $args (array), $cache_sub (boolean)
*/
public function bind_sub( $name, $args = null, $cache_sub = true ) {
+ if ( $this->terminated == true ) {
+ return;
+ }
+
$this->class_name = get_class( $this );
if ( is_string( $name ) ) {
$model = new $name( $args, $this );
@@ -366,7 +377,7 @@ public function bind_sub( $name, $args = null, $cache_sub = true ) {
$this->submodels = (object)[];
}
- $this->submodels->{ $class_name } = $model;
+ $this->submodels->{ $name } = $model;
// Store called submodels for caching purposes.
@@ -376,6 +387,10 @@ public function bind_sub( $name, $args = null, $cache_sub = true ) {
}
$this->called_subs[] = [ 'class_name' => $name, 'args' => $args ];
}
+
+ if ( $model->terminated == true ) {
+ $this-terminate();
+ }
}
/**
@@ -642,9 +657,7 @@ private function is_cacheable_function( $m ) {
* @return $allowed (boolean)
*/
private function is_function_allowed( $function ) {
- if ( isset( $this->api ) && is_array( $this->api ) && in_array( $function, $this->api ) ) {
- return true;
- } else {
+ if ( ! defined('DOING_AJAX') ) {
$reflection = new \ReflectionMethod( $this, $function );
if ( $reflection->isPublic() ) {
return true;
@@ -653,6 +666,12 @@ private function is_function_allowed( $function ) {
return false;
}
}
+ else if ( isset( $this->api ) && is_array( $this->api ) && in_array( $function, $this->api ) ) {
+ return true;
+ }
+ else {
+ return false;
+ }
}
/**
@@ -739,4 +758,8 @@ protected function in_array_r($needle, $haystack, $strict = true) {
}
return false;
}
+
+ protected function terminate() {
+ $this->terminated = true;
+ }
}
View
@@ -56,4 +56,4 @@ class Settings extends \DustPress\Model {
],
];
}
-}
+}
View
@@ -6,7 +6,7 @@
Author: Miika Arponen & Ville Siltala / Geniem Oy
Author URI: http://www.geniem.com
License: GPLv3
-Version: 1.5.9
+Version: 1.5.13
*/
final class DustPress {
@@ -15,7 +15,7 @@
private static $instance;
// Instance of DustPHP
- private $dust;
+ public $dust;
// Main model
private $model;
@@ -144,6 +144,8 @@ public function create_instance() {
$this->model->fetch_data();
+ do_action( 'dustpress/model_list', array_keys( (array) $this->model->get_submodels() ) );
+
$template_override = $this->model->get_template();
$partial = $template_override ? $template_override : strtolower( $this->camelcase_to_dashed( $template ) );
@@ -921,6 +923,21 @@ public function create_ajax_instance() {
else {
die( json_encode( [ "error" => "Something went wrong. There was no dustpress_data present at the request." ] ) );
}
+
+ if ( isset( $request_data['token'] ) && isset( $_COOKIE['dpjs_token'] ) ) {
+ $token = ( $request_data['token'] === $_COOKIE['dpjs_token'] );
+ }
+ else {
+ $token = false;
+ }
+
+ if ( ! $token ) {
+ die( json_encode( [ "error" => "CSRF token mismatch." ] ) );
+ }
+
+ if ( ! defined( 'DOING_AJAX' ) ) {
+ define( 'DOING_AJAX', true );
+ }
$runs = [];
@@ -1272,7 +1289,7 @@ private function register_autoloaders() {
foreach ( $paths as $path ) {
if ( is_readable( $path ) ) {
- foreach ( new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $path ) ) as $file ) {
+ foreach ( new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $path ) ) as $file ) {
if ( strpos( $file, "/" . $filename ) ) {
if ( is_readable( $file ) ) {
require_once( $file );

0 comments on commit 351f31b

Please sign in to comment.