Jump to content

kixe

Members
  • Posts

    803
  • Joined

  • Last visited

  • Days Won

    10

Posts posted by kixe

  1. it is already activated under the following conditions:

    • not available for 'home' ($page->id == 1)
    • not available for 'admin' ($page->template == 'admin')
    • page editable status is needed
    • to show lock/unlock current user needs page-lock permission
    • trash/restore button only available for superuser
    • functionality disabled in demo mode

    If you like to have a deeper view have a look in the script: /wire/modules/Process/ProcessPageList/ProcessPageListActions.php

    • Like 1
  2. I am not sure if the following will fit your needs. I wrote a module to subscribe/ unsubscribe from mailchimp using a checkbox  in the users template + updating mailchimp if the email address has changed. User profile is provided in frontend. All changings are logged by the module. Here the snippet of the template.

    function hookAfterSave($event) {
    	$modules = wire('modules');
    	$user = wire('users')->getCurrentUser();
    	if ($event->arguments('what') == 'newsletter') {
    		if ($event->arguments('new') == 1) $modules->get('ProcessMailchimp')->subscribe($user->email,false);
    		else $modules->get('ProcessMailchimp')->unsubscribe($user->email);
    	}
    	if ($event->arguments('what') == 'email') {
    		if ($event->arguments('old') != $event->arguments('new') && $user->newsletter) $modules->get('ProcessMailchimp')->update($event->arguments('old'),$event->arguments('new'));
    	}
    }
    

    And the module (running on pw 2.5.29, not tested in 2.6 latest devs)
    ProcessMailchimp.zip

  3. Processwire does provide to add 'page-edit-created' permission. See instructions below (PagePermissions.module is a core module Installed by default)

    /* Optional special permissions that are optional (by default, not installed):
     *
     * 1. page-publish: when installed, editable() returns false, when it would otherwise return true,
     *    on published pages, if user doesn't have page-publish permission in their roles.
     *
     * 2. page-edit-created: when installed, editable() returns false, when it would otherwise
     *    return true, if user's role has this permission and they are not the $page->createdUser.
     *    This is a permission that reduces access rather than increasing it. Note that
     *    page-edit-created does nothing if the user doesn't have page-edit permission.
     *
     * 3. page-rename: when installed, user must have this permission in their role before they
     *    can change the name of a published page. They can still change the name of an unpublished
     *    page. When not installed, this permission falls back to page-edit.
     *
     * 4. page-edit-lang-default: when installed on a multi-language site, user must have this
     *    permission in order edit multi-language fields in "default" language. This permission
     *    is also required to create or delete pages (if user already has other permissions that enable
     *    them to create or delete pages).
     *
     * 5. page-edit-lang-[language_name]: when installed on a multi-language site, user must have
     *    this permission to edit multi-language fields in the [language_name] language.
     *
     * 6. page-edit-lang-none: when installed on a multi-language site, user must have this
     *    permission to edit non-multi-language fields. They must also have it to create or delete
     *    pages (if user already has other permissions that enable that).
     *
     * 7. user-admin-all: when installed, a user must have this permission in order to edit other
     *    users of all roles (except superuser of course). When installed, the regular user-admin
     *    permission only acts as a pre-requisite for editing users, and enables only listing users,
     *    and editing users that have only the 'guest' role. The user-admin-all essentially grants
     *    the same thing as user-admin permission does on a system that has no user-admin-all
     *    permission installed. That's what it does, but why is it here? The entire purpose is to
     *    support user-admin-[role] permissions, as described in the next item below:
     *
     * 8. user-admin-[role_name]: when installed on a site that also has user-admin-all permission
     *    installed, a user must have this permission (along with user-admin permission) in order
     *    to edit users in role [role_name], or to grant that role to other guest users, or to
     *    revoke it from them. Think of this permission as granting a user administrative privileges
     *    to just a specific group of users. Note that there would be no reason to combine this
     *    permission with the user-admin-all permission, as user-admin-all permission grants admin
     *    privileges to all roles.
     *
     */
  4. If somebody needs this too. I wrote a Module Fieldtype InputfieldSelect suitable to ServiceCurrencyConversion.
    It stores the 3-letter code and returns a multiple array value of all corresponding exchange rates.

        	array(
        	'code' => EUR // selected value
        	'name' => 'Euros', 
    	'symbol' => '€', 
    	'x' => [USD exhcange rate], 
    	'updated' => 2015-01-14-14:45, 
    	'AED' => array(
    		'name' => 'UAE Dirham', 
    		'symbol' => '', 
    		'x' => [EUR exchange rate], // source = selected value
    		'amount' => [your amount in UAE Dirham]
    		), 
    	'[currency code]' => array(
    		...and so on...
    		),
    		.. and so on...
    	);
    
    

    There is a small issue in the currencies.txt file. Module cannot handle double entries like:

    UYU UYI    Peso Uruguayo Uruguay Peso en Unidades Indexadas    $U

    this should be changed to

    UYU    Peso Uruguayo    $U
    UYI    Uruguay Peso en Unidades Indexadas    
    

    Other solution is to make the module able to handle this.

    Here comes the FieldtypeSelectCurrency. Have fun :)


    FieldtypeSelectCurrency.module

  5. @teppo
    I couldn't reproduce this using pw 2.6.10 and Modules Version 1.1.2.
    The sleep value is always an integer. In the field settings you can only select integer columns with unique values to populate the option values of your selectfield.

    Could you tell me some more details to reproduce your problem. Maybe an example of your database table (column settings) you took to populate the selectable options and field settings too? Thanks.

  6. Since a while I notice a problem close to yours. It happens just in case of superuser. Adding some custom fields to the user template results in inability to change the values via Admin->Access->Users as loggedin Superuser (id=41). It works with ProcessProfile. After changing values of a specific field one time in Profile it becomes possible via Admin->Access->Users too. Editing other profiles works all the time. Couldn't find the cause.

    Edit: 5.07.15
    Allowance to edit user fields of the current user is based on the cofiguration in Module settings of ProcessProfile. If you have unchecked a field, you can't edit this field. This is default for custom fields. Change the settings in the module to give edit permission for these fields.

    • Like 3
  7. This FormTemplateProcessor is older and wasn't meant to work with file/image fields, because of "you need to save page before files.."

    protected function ___savePage($form) {
    
    }

    You'd need to change how the script saves the page values to exclude file fields, save page and add files.

    I made many changes to the module. savePage method is different in my module. It is working proper with last PW Versions, even with new fields like ProfieldsTable or so.

    Apart from that I doubt the rendering of a file or even image field in the way this module is set does work, as when you render a form from a page's (input)fields will throw problems as file field in a context of a page isn't working as it needs a page that is existing and saved. It's designed for backend primarily.

    [...]

    It can get tricky to use this approach and need special workarounds to get this working. File fields need a page id to know where to store and upload the image. So after submitting and processing the form the page should already be created and the file will get uploaded no matter if the form was valid or not and so on.

    I don't want to render an image or file before page is saved. I know that an id is needed to create the assets-folder. Filefield is not rendered before page is saved. I excluded the field by skipping it in the render method. But no success. If it is part of the template the error occurs anyway.

    Found a solution by adding a hook to the render method in the module in case of new page.

             // prevent error if fieldtype file or image is assigned and page has id = 0
            $this->addHookBefore('PagefilesManager::path', function ($e) {$e->replace = true;$e->return = null;});
    
  8. I use a module FormProcessor which is a derivation of Ryans FormTemplateProcessor. This module initialize a page instance, assign a specific template to it. Then a form based on this template will be rendered in frontend. The page will be saved AFTER submission and validation. The problem is the render of the file inputfield if empty and with a page->id = 0, which is default for new page instances (unsaved pages).
    I am getting the error in the frontendform template.

    init() and set() method of module

    	/**
    	 * Initialize a web form
    	 *
    	 *
    	 */
    	public function init() {
    		// create a page for holding form fields
    		$this->page = new Page();
    		$this->page->id = 0;
    
    		// Template to use for the form fields (required).
    		// must be a Template object, it will be assigned to $this->page.
    		$this->set('template', null);
    
    	 	// Optional E-Mail address that form will get submitted to
    		$this->set('email', '');
    
    	 	// E-Mail sender
    		$this->set('fromEmail', 'noreply@example.org');
    
    		// Array of field names that are required to complete the submission
    		// if not specified, it will use the admin field settings.
    		$this->set('requiredFields', array());
    
    	 	// Array of field names that should be skipped when drawing AND processing the form, blacklist
    		$this->set('skipFields', array('title'));
    
    	 	// Array of field names that will be added to the form when drawing AND processing the form
    	 	// whitelist. If empty all fields are added
    		$this->set('showFields', array());
    
    	 	// Associated Array of fieldnames and values that should be skipped when drawing the form but will be processed if set via API in the form-template file. Set $fieldname => $value
    		// $form->hiddenFields = array('myHiddenFieldKey'=>'myHiddenFieldValue');
    		$this->set('hiddenFields', array());
    
    		// Subject of the email that will be sent 
    		$this->set('emailSubject', 'Web Form Submission'); 
    
    		// Optional parent for the page.
    		// If ommited, the page will not be saved to the DB.
    		$this->set('parent', null);
    
    		// Status of page which stores submitted form data
    		$this->set('status', 2048); //default unpublished
    
    		// message output upon successful completion of the form. You have access to all submitted values to use them with sprintf()
    		$this->set('successMessage', 'Thank you, your submission has been sent!'); 
    
    		// field from where the page name is taken 
    		$this->set('nameField', null);
    
    		// submit field name and value
    		$this->set('submitValue', 'submit');
    
    		// set to true if email is sent and to page->id if page->save()
    		// also hookable method success()
    		$this->set('success', false);
    
    	}
    
    	/**
    	 * Set properties to our Page Instance
    	 *
    	 */
    	public function set($key, $value) {
    		if($key == 'parent' && $value) {
    			if(!$value instanceof Page) throw new WireException('Parent must be a Page object');
    			$this->page->parent = $value;
    		} else if($key == 'template' && $value) {
    			if(!$value instanceof Template) throw new WireException('Template must be a Template object');
    			$this->page->template = $value;
    		}
    		return parent::set($key, $value);
    	}
    
    // ....
    
  9. Pages are created via API. The assigned template has an Image- or Filefield.
    PagefilesManager path() method throws Exception if page->id is 0 (which is default in case of instantiation of new Page object).

    Any ideas for a workaround?
    For now I changed path() method in PagefilesManager Class. Not sure if this is a good idea ...

    /**
     * Get the published path (for use with hooks)
     *
     */
    	public function ___path() {
    		if(is_null($this->path)) {
                    // if(!$this->page->id) throw new WireException("New page '{$this->page->url}' must be saved before files can be accessed from it");
    		// replacement
                    if($this->page->id === null) throw new WireException("New page '{$this->page->url}' must be saved before files can be accessed from it");
    		$this->path = self::_path($this->page);
    	}
    	return $this->path;
    }
    

    Error: Exception: New page '/admin/access/users//' must be saved before files can be accessed from it (in [...]/wire/core/PagefilesManager.php line 262)
    #0 [...]/dev/wire/core/PagefilesManager.php(253): PagefilesManager->___path()
    #1 [...]/dev/wire/core/PagefilesManager.php(213): PagefilesManager->path()
    #2 [...]/dev/wire/core/PagefilesManager.php(67): PagefilesManager->createPath()
    #3 [...]/dev/wire/core/PagefilesManager.php(55): PagefilesManager->init(Object(Page))
    #4 [...]/dev/wire/core/Page.php(1921): PagefilesManager->__construct(Object(Page))
    #5 [...]/dev/wire/core/Pagefiles.php(74): Page->filesManager()
    #6 [...]/wire/core/Pagefiles.php(58): Pagefiles->setPage(Object(Page))
    #7 [...]/dev/wire/modules/Fieldtype/FieldtypeImage.module(33): Pagefiles->__construct(Object(Page))
    #8 [...]/dev/wire/core/Fieldtype.php(479): FieldtypeImage->getBlankValue(Object(Pag

    Opened an issue here: https://github.com/ryancramerdesign/ProcessWire/issues/1259

  10. Corrected my last post. Sorry for this.

    I tried your code and everything is working like expected using single image. Please check the following:

    Selectorstring teaser=1 needs field 'teaser' having int value = 1

    If you use image arrays you need to use WireArray Api

    // will match first image of array
    if ($item->teaserimage) { 
    $thumb = $item->teaserimage->first()->size(480,323);
    $out .= '<img src="' . $thumb->url . '" alt="' . $thumb->description . '">';
    }
    
    // will match 4th image in array
    if ($item->teaserimage) { 
    $thumb = $item->teaserimage->eq(3)->size(480,323);
    $out .= '<img src="' . $thumb->url . '" alt="' . $thumb->description . '">';
    }
    
    // will match last image in array
    if ($item->teaserimage) { 
    $thumb = $item->teaserimage->last(3)->size(480,323);
    $out .= '<img src="' . $thumb->url . '" alt="' . $thumb->description . '">';
    }
    

    More about WireArrays: https://processwire.com/api/arrays/

  11. if ($item->teaserimage) { 
    $thumb = $item->teaserimage->size(480,323);
    $out .= '<img src="' . $thumb->url . '" alt="' . $item->teaserimage->description . '">';
    }
    

    $thumb is the size of the image not the image itself. Corrected code above.

    Edit bullshit: Everything fine in your code except description. :P Too late yesterday night...

    • Like 1
  12. While testing your module I found out that it doesn't work properly in some cases:

    //no need to obfuscate, since there is no E-Mail Adress
    <a href="mailto:?subject=Lorem%20Ipsum&body=Lorem%20Ipsum!">Foo</a>
    <a href="mailto:?subject=Lorem Ipsum!">Foo</a>
    
    //doesn't work with the following examples
    <a href="mailto:mail@example.org?subject=Lorem Ipsum!">Foo</a>
    <a href="mailto:mail@example.org?subject=Lorem%20Ipsum&body=Lorem%20Ipsum!">Foo</a>
    

    For the 1st Example the module should leave the code untouched. Replacement only necessary if '@' is found.

    For 2nd Example I can offer a solution

    REPLACE

    // urlencode a possible subject
    $matches[1] = preg_replace_callback("!(.*\?(subject|body)=)([^\?]*)!i",
    function ($m) { return rawurlencode($m[3]); }, $matches[1]);
    
    // the function removes the questionmark, the words 'subject' and 'body' and the equalsign from the querystring 
    
    

    WITH

    // urlencode a possible subject and body, no matter if already urlencoded
    $_matches = preg_replace_callback("!(^\?*)?((\??subject|\??body)=([^&]+)){1,2}!i",
    function ($m) { return $m[1].$m[3].'='.rawurlencode(rawurldecode($m[4])); }, $matches[1]);
    

    I tested a little bit and it worked well with my solution.
     

    • Like 3
  13. Sometimes this happens sometimes not. Sometimes a second value (multiple) is stored after changing back to the blank value in the single select. The behaviour you described happend after setting options with api. Not if I cleaned everything, saved the field and added new options. Looks a bit buggy ...

    Everything seems to work correctly if value AND title is assigned.
     

  14. Just curious really. 

    Not curious at all. You didn't define the variable $siblings.

    $siblings in the description is meant as the 2nd optional argument in the method nextAll().

    If you call the function $page->nextAll() you don't need to set an Argument. Both are optional.

    If you like to specify one or two Arguments, you should define them.

    First or single Argument should be a selector string.

    Second one should be a PageArray. If you want to set only the second Argument you have to set an empty string as first Argument.

    This should work:

    <?php
    $siblings = $pages->find('parent=1');      
    $solutions = $page->nextAll('',$siblings);
    foreach ($solutions as $solution) {
        echo "<a href='{$solution->url}'>{$solution->title}</a>";
    }
    ?>
  15. I couldn't reproduce this result (NULL) and Error. Normally you get NULL if the option doesn' exist. The Error looks strange, since 'value' has the expected type (string). How did you edit the options, via API or in the Fieldsettings? I assume your $job variable is an instance of $page?

    In the fieldsettings (options) you should find.
    6=archive|Archiv
    post-1246-0-90095000-1433834081_thumb.jp

    No idea ...

  16. If I understand you right you would like to render the field via API and manipulate some field properties (filter_column, filter_selector and filter_value).
    Following code should work. (not tested)

    $fieldtype = $modules->get('FieldtypeSelectExtOption');
    $field = $fields->get(123); // 123 is the id of the field you have assigned to your page template
    
    // set your filter options 
    $field->filter_column = 'id';
    $field->filter_selector = '<';
    $field->filter_value = 3;
    
    $inputfield = $fieldtype->getInputfield($page, $field);
    echo $inputfield->render();
    
×
×
  • Create New...