Giter VIP home page Giter VIP logo

cakephp-tools's Introduction

CakePHP Tools Plugin

CI Coverage Status Latest Stable Version Minimum PHP Version License Total Downloads Coding Standards

A CakePHP plugin containing several useful tools that can be used in many projects.

Version notice

This master branch only works for CakePHP 5.0+. See version map for details.

What is this plugin for?

Enhancing the core

  • Auto-trim on POST (to make - especially notEmpty/notBlank - validation working properly).
  • Disable cache also works for older IE versions.
  • Provide enum support as "static enums"
  • Default settings for Paginator, ... can be set using Configure.
  • Provided a less error-prone inArray() method via Utility class and other usefulness.
  • TestSuite enhancements
  • A few more Database Type classes

Additional features

  • Passwordable behavior allows easy to use password functionality for frontend and backend.
  • MultiColumnAuthenticate for log-in with e.g. "email or username".
  • Slugged, Reset and other behaviors
  • Tree helper for working with (complex) trees and their output.
  • Progress and Meter helper for progress bar and meter bar elements (HTML5 and textual).
  • Text, Time, Number libs and helpers etc provide extended functionality if desired.
  • Icon helper for displaying all kind of font icons.
  • QrCode, Gravatar and other useful small helpers
  • Timeline, Typography, etc provide additional helper functionality.
  • Email as a wrapper for core's Email adding some more usefulness and making debugging/testing easier.
  • I18n language detection and switching

Providing 4.x shims

This plugin for CakePHP 5 also contains some 4.x shims to ease migration of existing applications from 4.x to 5.x:

  • See Shim plugin for details on most of the provided shims.

Installation & Docs

cakephp-tools's People

Contributors

admad avatar bancer avatar challgren avatar dereuromark avatar eymen-elkum avatar frandss avatar inoas avatar ishan-biztech avatar jadb avatar lordsimal avatar lorro avatar mp-network-development avatar pavel-dovgoshiya avatar ravage84 avatar repher avatar saeideng avatar sandra88vr avatar sdevore avatar steinkel avatar vankizmann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cakephp-tools's Issues

Map doesn`t appear if use '<?php' server tag

I`m a cakephp beginner and not sure if this is a real issue... but, map only appears if I use "<?=" instead of "<?php"

GoogleMap->map($map_options); ?> //it works GoogleMap->map($map_options); ?> //it doesn`t work.

I`m using cakephp 2.5.5

Soft Delete interferes with PHPUnit Testing

Running my tests, I get the following error:

Missing Database Table
Error: Table device for model Device was not found in datasource test.

Notice: If you want to customize this error message, create app/View/Errors/missing_table.ctp

Stack Trace
CORE/Cake/Model/Model.php line 3640 → Model->setSource(string)
CORE/Cake/Model/Model.php line 1387 → Model->getDataSource()
CORE/Cake/Model/Model.php line 1479 → Model->schema()
APP/Model/Behavior/SoftDeleteBehavior.php line 63 → Model->hasField(string)
CORE/Cake/Model/BehaviorCollection.php line 145 → SoftDeleteBehavior->setup(Device, array)

If I comment out the actsAs => SoftDelete line, it works fine.

Any ideas? Thanks much for all your work.

Logable autoRelation

Hi Mark

"autoRelation" in Logable behavior is not implemented yet, isn't it? Do you have any plans to do this? The setting exists though ;)

Thanks,
Frank

Undefined index in GeocodeLib

I'm not sure if Google changed the API output but I'm getting on results that don't have a match. But I keep getting Notice (8): Undefined index: accuracy [APP\Plugin\Tools\Lib\GeocodeLib.php, line 427] I've set the option to allow inconclusive to true and false and the error is still outputted.

The response I'm getting from Google is

    'valid_results' => (int) 0,
    'all' => array(
        (int) 0 => array(
            'formatted_address' => 'West Avenue Elementary School, 3915 West Avenue, San Antonio, TX 78213, USA',
            'country' => 'USA',
            'country_code' => 'US',
            'country_province' => 'Texas',
            'country_province_code' => 'TX',
            'postal_code' => '78213',
            'locality' => 'San Antonio',
            'sublocality' => '',
            'route' => 'West Avenue 3915',
            'types' => array(
                (int) 0 => 'point_of_interest',
                (int) 1 => 'establishment'
            ),
            'lat' => (float) 29.500983,
            'lng' => (float) -98.52708,
            'location_type' => 'APPROXIMATE',
            'viewport' => array(
                'sw' => array(
                    'lat' => (float) 29.499634019708,
                    'lng' => (float) -98.528428980292
                ),
                'ne' => array(
                    'lat' => (float) 29.502331980292,
                    'lng' => (float) -98.525731019708
                )
            ),
            'address_components' => array(
                (int) 0 => array(
                    'long_name' => 'West Avenue Elementary School',
                    'short_name' => 'West Avenue Elementary School',
                    'types' => array(
                        (int) 0 => 'point_of_interest',
                        (int) 1 => 'establishment'
                    )
                ),
                (int) 1 => array(
                    'long_name' => '3915',
                    'short_name' => '3915',
                    'types' => array(
                        (int) 0 => 'street_number'
                    )
                ),
                (int) 2 => array(
                    'long_name' => 'West Avenue',
                    'short_name' => 'West Ave',
                    'types' => array(
                        (int) 0 => 'route'
                    )
                ),
                (int) 3 => array(
                    'long_name' => 'North Central',
                    'short_name' => 'North Central',
                    'types' => array(
                        (int) 0 => 'neighborhood',
                        (int) 1 => 'political'
                    )
                ),
                (int) 4 => array(
                    'long_name' => 'San Antonio',
                    'short_name' => 'San Antonio',
                    'types' => array(
                        (int) 0 => 'locality',
                        (int) 1 => 'political'
                    )
                ),
                (int) 5 => array(
                    'long_name' => 'Bexar County',
                    'short_name' => 'Bexar County',
                    'types' => array(
                        (int) 0 => 'administrative_area_level_2',
                        (int) 1 => 'political'
                    )
                ),
                (int) 6 => array(
                    'long_name' => 'Texas',
                    'short_name' => 'TX',
                    'types' => array(
                        (int) 0 => 'administrative_area_level_1',
                        (int) 1 => 'political'
                    )
                ),
                (int) 7 => array(
                    'long_name' => 'USA',
                    'short_name' => 'US',
                    'types' => array(
                        (int) 0 => 'country',
                        (int) 1 => 'political'
                    )
                ),
                (int) 8 => array(
                    'long_name' => '78213',
                    'short_name' => '78213',
                    'types' => array(
                        (int) 0 => 'postal_code'
                    )
                )
            ),
            'valid_type' => false,
            'accuracy' => (int) 7,
            'accuracy_name' => 'route'
        )
    )
)```

SluggedBehavior broke model baking

When i try to bake model for plugin i get fatal error from SluggedBehavior. I have table with same name at default connection, but this behavior does not loaded in this table.

root@vagrant-ubuntu-trusty-64:/vagrant/supplier# bin/cake bake model Tags -c my_connection --plugin MyPlugin

Welcome to CakePHP v3.2.6 Console
---------------------------------------------------------------
App : src
Path: /vagrant/supplier/src/
PHP : 5.5.32-1+deb.sury.org~trusty+1
---------------------------------------------------------------
One moment while associations are detected.
PHP Fatal error:  Class 'Tools\Model\Behavior\Exception' not found in /vagrant/supplier/vendor/dereuromark/cakephp-tools/src/Model/Behavior/SluggedBehavior.php on line 133
PHP Stack trace:
PHP   1. {main}() /vagrant/supplier/bin/cake.php:0
PHP   2. Cake\Console\ShellDispatcher::run() /vagrant/supplier/bin/cake.php:33
PHP   3. Cake\Console\ShellDispatcher->dispatch() /vagrant/supplier/vendor/cakephp/cakephp/src/Console/ShellDispatcher.php:127
PHP   4. Cake\Console\ShellDispatcher->_dispatch() /vagrant/supplier/vendor/cakephp/cakephp/src/Console/ShellDispatcher.php:181
PHP   5. Cake\Console\Shell->runCommand() /vagrant/supplier/vendor/cakephp/cakephp/src/Console/ShellDispatcher.php:217
PHP   6. Cake\Console\Shell->runCommand() /vagrant/supplier/vendor/cakephp/cakephp/src/Console/Shell.php:450
PHP   7. call_user_func_array:{/vagrant/supplier/vendor/cakephp/cakephp/src/Console/Shell.php:456}() /vagrant/supplier/vendor/cakephp/cakephp/src/Console/Shell.php:456
PHP   8. Bake\Shell\Task\ModelTask->main() /vagrant/supplier/vendor/cakephp/cakephp/src/Console/Shell.php:456
PHP   9. Bake\Shell\Task\ModelTask->bake() /vagrant/supplier/vendor/cakephp/bake/src/Shell/Task/ModelTask.php:96
PHP  10. Bake\Shell\Task\ModelTask->getTableContext() /vagrant/supplier/vendor/cakephp/bake/src/Shell/Task/ModelTask.php:109
PHP  11. Bake\Shell\Task\ModelTask->getAssociations() /vagrant/supplier/vendor/cakephp/bake/src/Shell/Task/ModelTask.php:124
PHP  12. Bake\Shell\Task\ModelTask->findHasMany() /vagrant/supplier/vendor/cakephp/bake/src/Shell/Task/ModelTask.php:216
PHP  13. Bake\Shell\Task\ModelTask->getTableObject() /vagrant/supplier/vendor/cakephp/bake/src/Shell/Task/ModelTask.php:336
PHP  14. Cake\ORM\TableRegistry::get() /vagrant/supplier/vendor/cakephp/bake/src/Shell/Task/ModelTask.php:182
PHP  15. Cake\ORM\Locator\TableLocator->get() /vagrant/supplier/vendor/cakephp/cakephp/src/ORM/TableRegistry.php:111
PHP  16. Cake\ORM\Locator\TableLocator->_create() /vagrant/supplier/vendor/cakephp/cakephp/src/ORM/Locator/TableLocator.php:175
PHP  17. Cake\ORM\Table->__construct() /vagrant/supplier/vendor/cakephp/cakephp/src/ORM/Locator/TableLocator.php:207
PHP  18. App\Model\Table\ProductsTable->initialize() /vagrant/supplier/vendor/cakephp/cakephp/src/ORM/Table.php:288
PHP  19. Cake\ORM\Table->addBehavior() /vagrant/supplier/src/Model/Table/ProductsTable.php:54
PHP  20. Cake\Core\ObjectRegistry->load() /vagrant/supplier/vendor/cakephp/cakephp/src/ORM/Table.php:603
PHP  21. Cake\ORM\BehaviorRegistry->_create() /vagrant/supplier/vendor/cakephp/cakephp/src/Core/ObjectRegistry.php:93
PHP  22. Tools\Model\Behavior\SluggedBehavior->__construct() /vagrant/supplier/vendor/cakephp/cakephp/src/ORM/BehaviorRegistry.php:129
PHP  23. Cake\ORM\Behavior->__construct() /vagrant/supplier/vendor/dereuromark/cakephp-tools/src/Model/Behavior/SluggedBehavior.php:100
PHP  24. Tools\Model\Behavior\SluggedBehavior->initialize() /vagrant/supplier/vendor/cakephp/cakephp/src/ORM/Behavior.php:166

Bitmasked behavior multiple fields

I cound not find a way to use 2 bitmasked columns in the same table, f.ex. status and tag. It seems that Bitmasked behavior works only with one column per table.

Raise test coverage - and release stable 1.0

I would like to raise the test coverage to at least 75%.
And then release 1.0.0 stable and use sem var from there on.

See https://coveralls.io/r/dereuromark/tools

Mainly some of the tests are skipped in CLI due to session internal stuff.
That can sort out a lot. So we should start with all files that have 0-10 coverage.
And move on from there to reach the goal.

Also see https://scrutinizer-ci.com/g/dereuromark/tools/
Maybe quite a few of those issues can be resolved, as well.

Details: https://github.com/dereuromark/tools/wiki/TODOs

Any help is REALLY appreciated.
Thank you!

cake3 SluggedBehavior init problem

In initialize method you use

$this->_table->behaviors()->loaded('Translate');

Latest commit of cake 3.0-dev does not support argumnets for loaded() and i got error:
Cake\ORM\BehaviorRegistry::loaded() doesn't take object name as argument any more

Solution:

$this->_table->behaviors()->has('Translate');

I review all Behaviors code and this is only one place where you use loaded() method

Add support for an API key in GeocoderBehavior

Some of the limits in the Google Maps API are too low for some developers and Google supports Google Maps API for Work that requires an API key parameter. However the GeocoderBehavior doesn't support adding a key parameter.

Library for you tool Plugin

Sir, I am using your queued email plugin. For this I want Tool plugin lib. I downloaded your Tool plugin but I didn't find lib folder.What should I do

New SpellLib Engine hunspell

Hunspell is the best Spell Checker out there. It is used by OpenOffice, Mozilla, Google Chrome, Emacs, Opera, Mac OSX.

cake3 change password requirement in controller

In my admin prefixed controller i try to change config value 'require' to flase

$this->Users->behaviors()->Passwordable->config('require', false);

but it does not take any effect.
I try to disable new password requirement in user edit mode without PasswordableBehavior reinitialisation. As i see this config option used in initialize method and when PasswordableBehavior initialized changes for this option does not make any effect.

Is it reasonable to change code for possibility to dynamically disable password requirement?

SoftDelete messes with counter cache

I've just run into a situation where a model uses SoftDelete as well as counter caching for its belongsTo associated model, and I've noticed something odd.

When soft deleting a record, the model layer tries to update the counter cache afterwards, so far so good. Now the problem is that it's not possible for Model::updateCounterCache() to grab the the affected records foreign key value, as the SoftDelete behavior injects the deleted = false condition, resulting in false being returned by Model::field() as it won't find the record.

Finally this ends up with a counter cache update query like this being fired:

UPDATE
    `db`.`models` AS `Model`
SET
    `Model`.`associated_model_count` = 0
WHERE
    `Model`.`id` = ''

This will do no harm, but for sure it's a little ugly, and what I'd actually like to see would be a proper counter update where the soft deleted records are not being counted.

A possible fix might be to disable counter cache when updating the fields, and invoking Model::updateCounterCache() manually afterwards with the foreign key values for the current record queried beforehand, just like Model::delete() does. I guess something similar would then be necessary for undelete too.

However, while this seems kinda logical to me, I'm pretty sure not everyone will conform to it... so, any thoughts on this?

cake3 Docs for PasswordableBehavior missing

You need to modify docs for this info
In CakePHP 3.x entity for passwordable model needs for modification like

<?php
namespace App\Model\Entity;

use Cake\ORM\Entity;

/**
 * User Entity.
 */
class User extends Entity {

/**
 * Fields that can be mass assigned using newEntity() or patchEntity().
 *
 * @var array
 */
    protected $_accessible = [
        'username' => true,
        'password' => true,
        'password_new' => true,
        'password_confirm' => true,
        'password_current' => true,
        'email' => true,
        'active' => true,
    ];

}

Without this modification entity does not keep additional fields and data does not pass validation process in save process.
I got this error only in add user controller.

URL cache of tools plugin

Hi, Mark.
I'm trying to use url cache of tools plugin. Have you tested it with pagination links? It seems it doesn't work with pagination links.
Here's the code I'm using:

In core.php

Cache::config('cake_core', array(
'engine' => $engine,
'prefix' => $prefix . 'cake_core_',
'path' => CACHE . 'persistent' . DS,
'serialize' => ($engine === 'File'),
'duration' => $duration,
'lock' => true
));

In bootstrap

Configure::write('UrlCache.active', true);
Configure::write('UrlCache.pageFiles', true);
Configure::write('UrlCache.verbosePrefixes', true);

In AppHelper.php

App::uses('MyHelper', 'Tools.View/Helper');

class AppHelper extends MyHelper {

}

I can write the test if you want.

SoftDelete interferes with Logable/Revision-Behaviour Again

Mark,
As mentioned in issue #4, I have the following $actsAs in a "Story" model:

public $actsAs = array(
    'Tools.Revision' => array(
        'ignore' => array( 'updated', 'comment_count', 'order', 'task_count' )
    ),
    'Tools.Logable' => array(
        'change' => 'full',
    ),
    'Tools.SoftDelete',
);

and a delete action in the StoriesController:

public function admin_delete($id = null) {
    $this->Story->id = $id;
    if (!$this->Story->exists()) {
        throw new NotFoundException(__('Invalid story'));
    }

    $story = $this->Story->read(); // needed for slugs for redirect arrays

    if ($this->Story->delete()) {
        $this->Session->setFlash(__('Story deleted'));
        $this->redirect(array( 'controller' => 'projects', 'action' => 'view', 'project_slug' => $story['Project']['slug']));
    } else {
        $this->Session->setFlash(__('Story was not deleted'));
        $this->redirect(array( 'action' => 'view', 'project_slug' => $story['Project']['slug'], 'story_slug' => $story['Story']['slug'] ));
    }
}

After hitting "delete", it redirects to the "story page" (else branch), and the flash message says "Story was not deleted", but the browser says "Cannot find story".

In addition, the log table records an "edit" in the action field, with the "change" field recording deleted () => (1), deleted_date () => (2013...), updated (2013...) => (2013...)

Any ideas?
Thanks

Fix for undelete error in RevisionBehavior

When i want to undelete a record with RevisionBehavior, I have an error for an ambiguous 'id'.

This is the patch :
$Model -> updateAll(array($Model -> primaryKey => $modelId), array($Model -> alias.'.'.$Model -> primaryKey => $Model -> id));

instead of :
$Model -> updateAll(array($Model -> primaryKey => $modelId), array($Model -> primaryKey => $Model -> id));

Sorry i don't know how to use PR :(
Have a nice day
Best regards.
Cyb

SoftDelete interferes with Logable/Revision-Behaviour

Hi Mark

Today I've started to use your toolbox for Cake. Nice work! :)

One thing Ive noticed is, that the SoftDelete brings some errors in combination with the Revision and Logable-Behaviour when deleting an item. It seems all db-entries are correctly set, but Cake give me some errors:

Notice (8): Undefined index: Company [APP\Plugin\Tools\Model\Behavior\RevisionBehavior.php, line 835]

Warning (2): Invalid argument supplied for foreach() [APP\Plugin\Tools\Model\Behavior\RevisionBehavior.php, line 835]

Notice (8): Undefined index: Company [APP\Plugin\Tools\Model\Behavior\LogableBehavior.php, line 503]

Company is the related model. The order in actsAs is as "'Tools.SoftDelete','Tools.Revision','Tools.Logable','Tools.WhoDidIt'".

What Ive done wrong? Could you give me a hint please?

By the way: Is there any complete documentation for the toolbox?

Thanks for your help,
Frank

P.S. - Du kannst auch gerne in deutsch antworten ;)

Another layout structure of the TreeHelper

Is not possible to create a new structure layout for the menu that is rendered,
now the layout is like this:

  • Main root
    • subMenu1
    • subMenu2
    • submenu3
      • sub-submenu1
      • sub-submenu2

a new structure also compatible with twitter bootstrap is:

  • mainRoot
  • submenu1
  • submenu2
  • submenu3
    • sub-submenu1
    • sub-submenu2

is posibile something like this?

Add a new function for Revision Behavior

Hi,
your behavior is really a great things !!!! thanks you so much to share your code.
I coded a little function inside Behavior : getlast, this function is necessary for my webapp because i need to know which are the last revisions written, so i wrote this :

/**
 * Retourne les 5 (par défaut) dernières révisions enregistrées dans la base
 * 
 * @example $lastrevisions = $this->Post->getlast();
 * @param object $Model
 * @param int $limit
 * @return array
 */
public function getlast(Model $Model, $limit = 5) {
    $conditions = array(
        'order' => array('version_id DESC'),
        'limit' => $limit
    );
    return $Model -> ShadowModel -> find('all', $conditions);
}

maybe you can use it if you want.
Best regards.
Cyb

Multiple Roles + Contained Auth param doesn't work with Auth class

Currently the Auth class checks roles by using PHPs in_array but this doesn't work when using the contained auth param with multiple roles as the array will be indexed like so:

array(
    (int) 0 => array(
        'id' => '1',
        'name' => 'Staff',
        'alias' => 'staff'
    ),
    (int) 1 => array(
        'id' => '2',
        'name' => 'Admin',
        'alias' => 'admin'
    ),
    (int) 2 => array(
        'id' => '3',
        'name' => 'API',
        'alias' => 'api'
    )
)

Upgrade to be CakePHP3.x ready

The plugin needs to be updated from 2.x to 3.x (cake3 branch).
I will need some help here.

Also, I want to split up the plugin into smaller packages/plugins. This is now possible with composer (and wasnt really with git submodules back in the day).
Maybe you can help me here, as well, defining useful sub-plugins and groups maybe.

My proposal so far for new 3.x standalone plugins:

  • TinyAuth (Authenication - static and db driven) - DONE
  • Geo (Geocoder behavior and GoogleMaps helper etc) - DONE
  • Ajax - DONE
  • Rss - DONE
  • Shim - DONE (All 3.x shims etc - same in the other direction as well)
  • Flash? (Multi-flash messages - stackable)
  • TestSuite?
  • Tools (the rest)

Any feedback?

Why i am Getting " Map cannot be displayed! ".

Hello
Why i am Getting " Map cannot be displayed! ".

Placed GoogleMapV3Helper.php in app/View/Helper.

In Controller:

public $helpers = array('Html', 'Form', 'Session', 'Js', 'Paginator', 'Common', 'Time','GoogleMapV3');

In View/map.ctp

<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> GoogleMapV3->map(array('div'=>array('height'=>'400', 'width'=>'100%'))); // add markers $options = array( 'lat' => 48.95145, 'lng' => 11.6981 ); // tip: use it inside a for loop for multiple markers $this->GoogleMapV3->addMarker($options); $this->GoogleMapV3->finalize(); ?>

Issue with WhoDidIt when using a plugin for Users

I am using the CakeDC USers plugin alongside the Tools plugin and there is an issue with your WhoDidIt behaviour.

In the before save it uses the user_model to access the user id from the session - if the user_model is in a plugin it doesn't find the session key correctly.
I have fixed it in my clone by doing:

list($plugin, $UserSession) = pluginSplit($this->settings[$Model->alias]['user_model']);

Feature for GoogleMapHelper

Auto open info window when the map displays.
Marker option:

        'autoopen' => false,

@535 line

        $this->addCustomEvent(self::$MARKER_COUNT, $event);

        if($options['autoopen'])
        {
            $this->map.="
            gInfoWindows".self::$MAP_COUNT."[".$this->_currentOptions['marker']['infoWindow']."].setContent(gWindowContents".self::$MAP_COUNT."[".self::$MARKER_COUNT."]);
            gInfoWindows".self::$MAP_COUNT."[".$this->_currentOptions['marker']['infoWindow']."].open(".$this->name().", gMarkers".self::$MAP_COUNT."[".self::$MARKER_COUNT."]);";
        }  

And rendering map at the end of the html like this:

$this->Html->scriptBlock( $this->GoogleMapV3->script(false), array('inline'=>false));

scripts parameter should tell the function to return without < script > tags, only with javascript.

Full code:

public function script($inline = true) {
    $script='
    '.$this->_arrayToObject('matching', $this->matching, false, true).'
    '.$this->_arrayToObject('gIcons'.self::$MAP_COUNT, $this->icons, false, false).'

jQuery(function(){
    ';

    $script .= $this->map;
    if ($this->_currentOptions['geolocate']) {
        $script .= $this->_geolocate();
    }

    if ($this->_currentOptions['showMarker'] && !empty($this->markers) && is_array($this->markers)){
        $script .= implode($this->markers, " ");
    }

    if ($this->_currentOptions['autoCenter']) {
        $script .= $this->_autoCenter();
    }    
    $script .= '

});
';
    self::$MAP_COUNT++;
    if ($inline) {
        echo $this->Html->scriptBlock($script);
    } else {
        return $script;     
    }
}

Thanks.

Model aliases with Linkable behavior

Trying to use a model alias with the Linkable behavior but getting an error message saying it cannot find the table. Of course it is looking for a table name that doesn't exist but it is trying to find a table name based on the alias, not the actual model.

Any fixes or work arounds?

Lib/Error/MyErrorHandler.php


  public static function handleFatalError($code, $description, $file, $line) {
        $logMessage = 'Fatal Error (' . $code . '): ' . $description . ' in [' . $file . ', line ' . $line . ']';
        CakeLog::write(LOG_ERR, $logMessage);
        $exceptionHandler = Configure::read('Exception.handler');
        if (!is_callable($exceptionHandler)) {
            return false;
        }

        if (Configure::read('debug')) {
            return false;
        }

        if (ob_get_level()) {
            ob_end_clean();
        }

        if (Configure::read('debug')) {
            call_user_func($exceptionHandler, new FatalErrorException($description, 500, $file, $line));
        } else {
            call_user_func($exceptionHandler, new InternalErrorException());
        }
        return false;
    }

I think this if block is never going to be executed:

if (Configure::read('debug')) {
call_user_func($exceptionHandler, new FatalErrorException($description, 500, $file, $line));
}

because of this if block:

if (Configure::read('debug')) {
return false;
}

Overwrite 'type' in NamedScopeBehavior::scopedFind() doesn't work properly

As it states in wiki: https://github.com/dereuromark/cakephp-tools/wiki/Model-Behavior-NamedScope

$activeAdminList = $this->User->scopedFind('activeAdmins', array('type' => 'list'));
$activeAdminCount = $this->User->scopedFind('activeAdmins', array('type' => 'count'));

When 'activeAdmins' scope has pre defined 'type' => 'all' (as in wiki example) overwriting results in:
'type' => ['all', 'list']

This is probably the reason of array_merge_recursive in scopedFind() method.

Jsonable: Error when find list

Hi @dereuromark , I had an error when I tried to run list finder on my model witch has a Jsonable Behavior, in Cakephp 3.x.
The error is in the line 100, I tried to correct it but I couldn't, it seems we have to check the finder name before format the the results.

Note: the $row in line 102 is just a string in my list finder case and not Entity, I hoped to make a PR
thanks again for this awesome plugin.

WhoDidItBehavior does not work with Basic Auth

The following error is the result of add() action:

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (my_db.my_table, CONSTRAINT my_foreign_key FOREIGN KEY (created_by) REFERENCES users (id) ON DELETE NO ACTION ON UPDATE NO ACTION)"

And SQL:

INSERT INTO my_db.my_table (column_one, column_two, column_three, column_four, modified, created) VALUES (0, 0, 5.67, 128, '2015-11-25 09:55:55', '2015-11-25 09:55:55')

So, 'created_by' value is missing probably because WhoDidItBehavior uses sessions to get the authenticated user. Wouldn't it be better to use AuthComponent instead?

calculateDrivingTime() function

Is there any plans for this? Or do you have any ideas about how I could implement this? I imagine it could work similarly to the distance() function, where it simply returns a value.

Any direction would be appreciated.

SluggedBehavior - "display", "url" and "class" modes broken due to regex compilation failure on surrogates

This was mentioned in a comment sime time ago, but somehow slipped through: #13 (comment)

I'm seeing the same behaviour here with PHP 5.4.18 and PCRE 8.32. The problem is the surrogates range (\x{d800}-\x{dfff}) in the following expression: \x00-\x1f\x26\x3c\x7f-\x9f\x{d800}-\x{dfff}\x{fffe}-\x{ffff}

I'm not 100% sure whether this is actually a PCRE bug as some people claim, it might as well be the indended behaviour in newer versions, at least I couldn't find anything their bug tracker.

Anyways, according to RFC-3629, U+D800 to U+DFFF are invalid in UTF-8, and a quick test shows that the regex fails and causes an error:

$regex = '@[\x{d800}-\x{dfff}]@Su';
var_dump(preg_replace($regex, '-', json_decode('"\ud800"')));
var_dump(preg_last_error() === PREG_BAD_UTF8_ERROR);

Result:

NULL
bool(true)

And as of PHP 5.4.9/5.3.19 which ship with PCRE 8.31, it fails hard:

$regex = '@[\x00-\x1f\x26\x3c\x7f-\x9f\x{d800}-\x{dfff}\x{fffe}-\x{ffff}]@Su';
var_dump(preg_replace($regex, '-', "foo\x00bar"));

Expected:

string(7) "foo-bar"

Result:

Warning:  preg_replace(): Compilation failed: disallowed Unicode code point (>= 0xd800 && <= 0xdfff) at offset 34 in [...][...] on line 2
NULL

So, in case I understood that correctly and these ranges can never appear anyways, it should be safe to simply remove \x{d800}-\x{dfff}, shouldn't it?

Problem with the SluggedBehavior and the (core) Translate behavior

Hello,

I'm running cakephp v2.3.8 and the latest vesion of your tools available at the time of writing this report.

In my back office I'm editing some articles in several different languages, french, english and italian. Each article is edited, on the same screen, in the 3 languages.
I call the slug behavior in the beforeSave event ('run' => 'beforeSave').

The creation of the slug is based on a field called "title".

When the form is submited I don't have "Article.title" in the request but:
Article.title.eng
Article.title.fra
Article.title.ita

In the code of your behavior, in the method generateSlug(), from lines 201 to 209 you are searching for a field that does not exist and so the slug is generated from the Model's name.

Another problem related to this one, the model's name is taken but without using the case option (in my case 'low'), so my slug is Article instead of "article"

Bye

Redclaring slug

I'm using Titon/Utility and when using dereuromark/cakephp-tools causes a redclaration of slug. It would be better to wrap slug in a function_exists so dereuromark doesn't cause issues with other packages.

AuthUserHelper

How can I install just the AuthUserHelper to use with tinyauth as a standalone. I don't need the other tools. Can you please advise what is required to code in.

Revision Behavior interferes with validation error messages

I'm not sure if you are aware of this:

http://stackoverflow.com/questions/8949538/cakephp-revision-behavior-hurdles-validation-error

On that thread, nobody figured out why this is happening. Today, I spent many hours troubleshooting this, and I figured out why this is happening.

In Cake's Controller->render() [line 937], there is a loop that iterates through an array of classes that have been registered into ClassRegistry. This loop uses object aliases as the keys for the validationErrors array. Like this:

$this->View->validationErrors[$currentObject->alias]

When you get a list of revisions by calling revisions() method, RevisionBehavior registers a duplicate of your model. So, if your model is "Post", RevisionBehavior ends up registering another one called "Post" when it instantiates the shadow Model at line 973. The actual error message is stored under the first instance, but this gets overwritten when Cake loops one more time. This is why the error message disappears.

So, to get around this, this is the line I added immediately after RevisionBehavior instantiates a shadow model. At line 975:

ClassRegistry::removeObject(Inflector::singularize($fullTableName));

This would de-register (remove) the shadow class from the registry, and the conflict with the validation errors would be resolved.

TinyAuthorize with Cake 2.3.0

Hello,

I have upgraded my app to CakePHP 2.3 and TinyAuthorize doesn't seems to work anymore.
When I login, all actions are denied, even if I allow all with: $this->Auth->allow().
If I comment 'authorize' => array('Tools.Tiny'), all works fine.

Any one experienced this with Cake 2.3 ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.