Jump to content

Pages Web Service (ServicePages)


ryan

Recommended Posts

After 2.5.0 update, Service Pages stopped working for guests.

The 2.4.5 Fix did not work. It´s not bypassing permissions right now in 2.5.0.

The problem comes from ProcessPageSearch.module, used by Service Pages, as it has page-edit permissions.

Quick FIx: Editing the core  [>_<] ProcessPageSearch.module: As you may notice, this is not desirable, but it works.

'permission' => 'page-view', instead of 'permission' => 'page-edit',
 
How can we try to fix this in the ServicePages.module?
 
Thanks in advance.
Link to comment
Share on other sites

  • 2 weeks later...

I've tried the quick fix mentionned above by jiobazzard but it didn't work :( I still have to login as admin to be able to use ServicePages as expected (with PW 2.5.3 on localhost). I've tried emptying my cache too.

Here's the error I get :

Error: 	Exception: You do not have permission to execute this module - ProcessPageSearch (in /home/celfred/PlanetAlert/wire/core/Modules.php line 840)

If anyone has another suggestion...

Link to comment
Share on other sites

Hello all,

Sorry to come back on this issue, but I have upgraded just about everything on my site and the only thing that prevents me from putting it online is this issue about being logged in as 'admin' to be able to use the ServicePages module :(

I keep trying to understand, but I must admit this is (again...) way over my head, and I can't find a hack to this. If you're a 'guest', you just don't get to see anything on my site, which is a little dissatisfying :( As I said, I've tried the 'page-edit' to 'page-view' switch in ProcessPageSearch, but it didn't work and I can't firgue out what else to try. I've tried to understand the getModule call with the 'noPermissionCheck' option, but it's over my skills...

So if anyone has a little time to help me, I would greatly appreciate!

Thanks in advance.

Link to comment
Share on other sites

If you're in a rush, try this in Modules.php at line 837

Note: Fully untested :)

if($info['name'] != 'ServicePages') is the new bit.

if($module && empty($options['noPermissionCheck'])) {
    $info = $this->getModuleInfo($key);
    if(!empty($info['permission']) && !$this->wire('user')->hasPermission($info['permission'])) {
        if($info['name'] != 'ServicePages') throw new WirePermissionException($this->_('You do not have permission to execute this module') . ' - ' . $class);
    }
}
Link to comment
Share on other sites

Thanks for the help.

Actually, after testing it didn't work. So here's what I did : I checked the $info['name'] content and it returned 'ProcessPageSearch', so I changed your line with

if($info['name'] != 'ProcessPageSearch') throw new WirePermissionException($this->_('You do not have permission to execute this module') . ' - ' . $class);

It works now! But maybe I've broken something doing this ?

Link to comment
Share on other sites

  • 1 month later...

I'm trying to access subfields like Brent here, but I don't understand how you're supposed to do it. For example, something like parent.title=MyTitle does not seem to work. Nor can I access page references like number_of_stars.title=1 (one star, two stars, etc. : options stored as pages somewhere else in the tree). Can anyone help me out?

Link to comment
Share on other sites

Hi there,

I'm still facing a little issue with the new updated version of this module.

If I set NO limit when fetching data, I have an automatic limit set to 25, although my maximum amount in the configuration page is set to 50. If I set 'limit=0' in my request, it 'works', it fetches ALL data (event though I set my maximum amount to 5, for example).

So it's not a big problem since I can manage my limit manually so it is consistent, but I wonder if that's the expected behavior...

To me, the maximum amount should override any manually set limit, and if no limit is set, then the maximum should be the limit.

I mention it since it caused me a little trouble on my site. Maybe someone will find this useful :)

  • Like 1
Link to comment
Share on other sites

Hi there,

I'm still facing a little issue with the new updated version of this module.

If I set NO limit when fetching data, I have an automatic limit set to 25, although my maximum amount in the configuration page is set to 50. 

Celfred, I noticed the same thing yesterday when testing the module. It looks to me that it's a bug. Ryan? 

Link to comment
Share on other sites

  • 4 weeks later...

The automatic limit comes from the ProcessPageSearch module.

wire ▸ modules ▸ Process ▸ ProcessPageSearch Line 55

protected $resultLimit = 25;

ServicePages calls $process->executeFor(); and in that function the limit is set.

$limit = $this->resultLimit;
Setting the limit via URL (see code below [Line 200]) works fine for me but the input field has no effect at all.
if($name == 'limit') {
  $limit = (int) $value;
  $this->input->whitelist('limit', $value);
  continue;
}
 
Btw: I get the limit parameter two times:
{"selector":"template=cranach-house, limit=25","total":2,"limit":25,"start":0,"matches":[{" ...

EDIT: ok, I guess there is a mixing up.

In the module settings you enter the maxLimit value the url parameter is allowed to be.

Example.

Maximum pages to match per request is set to 20.

http://.../service-pages/?...&limit=12 => WORKS

http://.../service-pages/?...&limit=22 => DOES NOT WORK {"errors":["Out of bounds limit setting (max=20)"]}

maxLimit != limit

The limit parameter can only be overwritten by URL parameter.

  • Like 1
Link to comment
Share on other sites

I need to output the content of a repeater field.

Logged in as a super user everything works as expected:

.. "matches":[{"id":1,"parent_id":1,"template":"repeater_example","path":"..","name":"..","content":"lorem ipsum dolor sit"," ..

But when I'm not logged in, I get nothing.


.. "matches":[]}

Every other "normal" template works as expected, I guess the problem is the repeater template

which has not the access to be viewed by guest users.

The selector include=all is automatically added for superusers (wire ▸ modules ▸ Process ▸ ProcessPageSearch Line 271).

include=hidden is not enough.

Is there a way to enable repeater templates to be viewed by guest users?

For now I use single pages instead of the repeater. But I need just one value per page.

Any help would be appreciated :)

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

I want to use this to add events to a calendar using FullCalendar.js... and eventually other items of different templates...

The initialization goes like so:

	jq111("#calendar").fullCalendar({
	    header: {
	      left: 'prev,next today',
	      center: 'title',
	      right: 'month,agendaWeek,agendaDay'
	    },
	    //defaultDate: '2010-01-01',
	    editable: true,
	    eventLimit: true, // allow "more" link when too many events
	    events: '<?php echo $pages->get(1373)->url ?>?template=events'
	});

Obviously that doesn't work though since the JSON needs to be outputted in this format:

[{"id":830,"start":1262279460000,"end":1262281260000,"title":"this is a long event isnt that right?","body":"","multi":0,"allDay":false,"extension_id":2},{"id":831,"start":1262282052000,"end":1262283852000,"title":"830","body":"","multi":0,"allDay":false,"extension_id":2},{"id":832,"start":1262284644000,"end":1262286444000,"title":"831","body":"","multi":0,"allDay":false,"extension_id":2}]

Is there any way to change the format of the output..?

Link to comment
Share on other sites

I needed another structure as well. Therefore I built another litte module which rewrites the structure due to my needs.

This module contains a function in which the content is loaded using ServicePages module (in my case via curl).

Rewrite and output the result.

Or maybe you could use TemplateDataProvider Module to handle this (I needed a lot more so I decided to build my own module).

Link to comment
Share on other sites

  • 1 month later...
  • 3 months later...

Hi All,

If I activate the debug mode then the web service search failed. The error is "field submit1 is not allowed ... If I turn off debug mode, then it back to normal again.

Is it something wrong in my part or an error since I upgraded the core to 2.6?

Thank you ...

Link to comment
Share on other sites

  • 1 month later...

Tried it now for the first time - the query "service-pages/?template=mf_termin" shows the following:

{"selector":"template=mf_termin, limit=25","total":1,"limit":25,"start":0,"matches":[{"id":1018,"parent_id":1016,"template":"mf_termin","path":"/termine\/lorem-ipsum-dolor-sit-amet-consetetur-sadipscing\/","name":"lorem-ipsum-dolor-sit-amet-consetetur-sadipscing","created":1437313802,"modified":1438870554,"created_users_id":41,"modified_users_id":41,"title":"Lorem ipsum dolor sit amet consetetur sadipscing","mf_termin_datum":"31.07.2015","mf_termin_image":{"basename":"mf_termin_blank.png","description":"","tags":"","formatted":false,"modified":1437315061,"created":1437315061},"mf_termin_info":"","mf_termin_kurzinfo":"<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.<\/p>","mf_termin_ort":{"lat":"0.000000","lng":"0.000000","address":"Musterstrasse 1, 12345 Musterstadt","status":0,"zoom":12,"skipGeocode":false}}]}

So that seems to be fine i guess.

But with the query "service-pages/?template=mf_termin&field=mf_termin_kurzinfo" I receive the following error:

{"errors":["Field 'field' is not allowed in queries"]}

What am I doing wrong? How can I access specific values / fields?

Link to comment
Share on other sites

But - I have another question:

When I want to display an image through the JSON service page, how can I do this?

The Service page displays just the basename, not the path of the image - is there a way to show the path somewhow by adding "->url" like shown below (which does not work)?

<?php
$json_file = file_get_contents('http://xyz.de/service-pages/?template=mf_termin');
$jfo = json_decode($json_file);
$posts = $jfo->matches;
foreach ($posts as $post) {
?>
<li>
<h2><?php echo $post->title; ?></h2>
<img src="<?php echo $post->mf_termin_image->basename->url; ?>">
</a>
</li>
<?php
?>
Link to comment
Share on other sites

@doolak:

It is important to realize that the JSON-data returned by the module will be decoded into a "dummy" PHP object (an instance of stdClass), based purely on the raw information that can be seen in the JSON-representation. Such an object has nothing to do with ProcessWire's objects/classes. So the consuming service has absolutely no idea of any other properties other than those that are given to it by the module. You can basically compare it to an array. Hence you cannot use any properties related to a ProcessWire class, such as FieldtypeImage.

The simplest option is to build the URL manually, e.g.

<img src="http://xyz.de/site/assets/<?php echo ($post->id . '/' . $post->mf_termin_image->basename); ?>">
  • Like 4
Link to comment
Share on other sites

  • 4 weeks later...

I have another problem...

I am trying to access the value of an options field through the Webservice - the returned JSON is this:

"mf_termin_schwerpunkt":{"1":{"id":1,"sort":0,"title":"black","value":""

and, if multiple options are selected:

"mf_termin_schwerpunkt":{"3":{"id":3,"sort":2,"title":"blue","value":""},"2":{"id":2,"sort":1,"title":"green","value":""

I want to show the result just if the selected option matches "black" and tried already:

if($mf_termin->termin_schwerpunkt == 1) {

...

}
if($mf_termin->termin_schwerpunkt->id == 1) {

...

}
if($mf_termin->termin_schwerpunkt->title == "black") {

...

} 

But none of them worked.

The problem seems to be that an option field is again an array and I cannot manage to access the values:

post-107-0-76465400-1441188151_thumb.png

Would be great if someone could help me with this problem!

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.
  • Similar Content

    • By monollonom
      (once again I was surprised to see a work of mine pop up in the newsletter, this time without even listing the module on PW modules website 😅. Thx @teppo !)
      FieldtypeQRCode
      Github: https://github.com/romaincazier/FieldtypeQRCode
      Modules directory: https://processwire.com/modules/fieldtype-qrcode/
      A simple fieldtype generating a QR Code from the public URL of the page, and more.
      Using the PHP library QR Code Generator by Kazuhiko Arase.

      Options
      In the field’s Details tab you can change between .gif or .svg formats. If you select .svg you will have the option to directly output the markup instead of a base64 image. SVG is the default.
      You can also change what is used to generate the QR code and even have several sources. The accepted sources (separated by a comma) are: httpUrl, editUrl, or the name of any text/URL/file/image field.
      If LanguageSupport is installed the compatible sources (httpUrl, text field, ...) will return as many QR codes as there are languages. Note however that when outputting on the front-end, only the languages visible to the user will be generated.
      Formatting
      Unformatted value
      When using $page->getUnformatted("qrcode_field") it returns an array with the following structure:
      [ [ "label" => string, // label used in the admin "qr" => string, // the qrcode image "source" => string, // the source, as defined in the configuration "text" => string // and the text used to generate the qrcode ], ... ] Formatted value
      The formatted value is an <img>/<svg> (or several right next to each other). There is no other markup.
      Should you need the same markup as in the admin you could use:
      $field = $fields->get("qrcode_field"); $field->type->markupValue($page, $field, $page->getUnformatted("qrcode_field")); But it’s a bit cumbersome, plus you need to import the FieldtypeQRCode's css/js. Best is to make your own markup using the unformatted value.
      Static QR code generator
      You can call FieldtypeQRCode::generateQRCode to generate any QR code you want. Its arguments are:
      string $text bool $svg Generate the QR code as svg instead of gif ? (default=true) bool $markup If svg, output its markup instead of a base64 ? (default=false) Hooks
      Please have a look at the source code for more details about the hookable functions.
      Examples
      $wire->addHookAfter("FieldtypeQRCode::getQRText", function($event) { $page = $event->arguments("page"); $event->return = $page->title; // or could be: $event->return = "Your custom text"; }) $wire->addHookAfter("FieldtypeQRCode::generateQRCodes", function($event) { $qrcodes = $event->return; // keep everything except the QR codes generated from editUrl foreach($qrcodes as $key => &$qrcode) { if($qrcode["source"] === "editUrl") { unset($qrcodes[$key]); } } unset($qrcode); $event->return = $qrcodes; })
    • By Sebi
      AppApiFile adds the /file endpoint to the AppApi routes definition. Makes it possible to query files via the api. 
      This module relies on the base module AppApi, which must be installed before AppApiFile can do its work.
      Features
      You can access all files that are uploaded at any ProcessWire page. Call api/file/route/in/pagetree?file=test.jpg to access a page via its route in the page tree. Alternatively you can call api/file/4242?file=test.jpg (e.g.,) to access a page by its id. The module will make sure that the page is accessible by the active user.
      The GET-param "file" defines the basename of the file which you want to get.
      The following GET-params (optional) can be used to manipulate an image:
      width height maxwidth maxheight cropX cropY Use GET-Param format=base64 to receive the file in base64 format.
    • By MarkE
      This fieldtype and inputfield bundle was built for storing measurement values within a field, rendering them in a variety of formats and converting them to other units or otherwise modifying them via the API.
      The API consists of a number of predefined functions, some of which include...
      render() for rendering the measurement object, valueAs() for converting the value to another unit value, convertTo() for converting the whole measurement object to different units, and add() and subtract() for for modifying the stored value by the value (converted as required) in another measurement. In the admin the inputfield includes a checkbox (which can be optionally disabled) for converting values on page save. For an example if a value was typed in as centimeters, the unit was changed to metres, and the page saved with this checkbox selected, said value would be automatically converted so that e.g. 170 cm becomes 1.7 m.

      A simple length field using Fieldtype Measurement and Inputfield Measurement.
      Combination units (e.g. feet and inches) are also supported.
      Please note that this module is 'proof of concept' at the moment - there are limited units available and quite a lot of code tidying to do. More units will be added shortly.
      See the GitHub at https://github.com/MetaTunes/FieldtypeMeasurement for full details and updates.
    • By tcnet
      File Manager for ProcessWire is a module to manager files and folders from the CMS backend. It supports creating, deleting, renaming, packing, unpacking, uploading, downloading and editing of files and folders. The integrated code editor ACE supports highlighting of all common programming languages.
      https://github.com/techcnet/ProcessFileManager

      Warning
      This module is probably the most powerful module. You might destroy your processwire installation if you don't exactly know what you doing. Be careful and use it at your own risk!
      ACE code editor
      This module uses ACE code editor available from: https://github.com/ajaxorg/ace

      Dragscroll
      This module uses the JavaScript dragscroll available from: http://github.com/asvd/dragscroll. Dragscroll adds the ability to drag the table horizontally with the mouse pointer.
      PHP File Manager
      This module uses a modified version of PHP File Manager available from: https://github.com/alexantr/filemanager
       
    • By tcnet
      This module implements the website live chat service from tawk.to. Actually the module doesn't have to do much. It just need to inserted a few lines of JavaScript just before the closing body tag </body> on each side. However, the module offers additional options to display the widget only on certain pages.
      Create an account
      Visit https://www.tawk.to and create an account. It's free! At some point you will reach a page where you can copy the required JavaScript-code.

      Open the module settings and paste the JavaScript-code into the field as shown below. Click "Submit" and that's all.

      Open the module settings
      The settings for this module are located int the menu Modules=>Configure=>LiveChatTawkTo.

       
×
×
  • Create New...