Jump to content

ngrmm

Members
  • Posts

    247
  • Joined

  • Last visited

Posts posted by ngrmm

  1. I have a page which imports external json-feed into pages and would like to run this page every day. The Problem is that the import take 10–20 seconds.

    Is there a way to trigger this import from any other page and let in run in the background? I would like to avoid slow pageloads of other pages, even if it's once a day.

  2. I use the explode function to generate a json-feed like this

    $list = $pages->get(1234)->children;
    $toJSON = $list->explode(function ($item) {			
    			return [
    				'title' => $item->title,
    				'id'    => $item->id,
    				'start' => $item->summary, 
    			]
    		  }

    But i would like to use the sanitizer on the summary field. Like this:
    Obviously this can not work. But how can sanitize the summary before the output?

    $list = $pages->get(1234)->children;
    $toJSON = $list->explode(function ($item) {
    
    		// $itemSummary = $sanitizer->truncate($item->summary, [
            //     'type' => 'punctuation',
            //    'maxLength' => 155,
            //    'visible' => true,
            //    'more' => '…'
            // ]);
    
    			return [
    				'title' => $item->title,
    				'id'    => $item->id,
    				'start' => $itemSummary, 
    			]
    		  }

     

     

  3. 1 hour ago, FireWire said:

    I haven't experienced that. I don't often use tables and can't remember if I've seen that.  Fluency wouldn't be able to change how a field is rendered. 

    Looks like it's not possible. It says:

    • settingsField: Specify a PW field that uses CKEditor to use for the settings of this column. Note that inline mode is always used, regardless of field settings.
    • …

     

  4. 10 minutes ago, Zeka said:

    @ngrmm

    By the way, you can try to use $pages->findRaw https://processwire.com/api/ref/pages/find-raw/, like 

    wireEncodeJSON($pages->findRaw('template=some-template, parent=1234,', ['id', 'title', 'tags' => ['id', 'title']);

     

    Actually this is perfect, as I don't need all the page data. But unfortunately it outputs the page ID as key, what don't want to have.
    Maybe there will be some options in the future to change this default behaviour.

    Thanks @Zeka anyway, the other solution works perfectly!

  5. 14 minutes ago, Zeka said:
    $list = $pages->get(1234)->children;
    $toJSON = $list->explode(function ($item) {
    	return [
    		'title' => $item->title,
    		'id'    => $item->id,
    		'tags'  => $item->tags->explode(['id', 'name', 'title'])
    	];
    });

     

    wow much easier than i thought. And what is the correct syntax to go more levels deeper? Let's say one my tags has also page-reference-field itself.
     

  6. 7 minutes ago, Zeka said:

    Hi @ngrmm

    $list = $pages->get(1234)->children;
    $toJSON = $list->explode(function ($item) {
    	return [
    		'title' => $item->title,
    		'id'    => $item->id,
    		'tags'  => [
    			'ids' => $item->page_field->explode('id')
    		]
    	];
    });
    
    wireEncodeJSON($toJSON);

     

    thx @Zeka

    I got it working with a temporary loop inside my foreach-loop (see update on my post). Actually I needed the tags to be arrays themself. But your method looks better. Is there a way to output the tags as arrays themself with your method?

  7. I know there are some modules (pageQueryBoss, GraphQL, …) this. But non of them outputs exactly how i would like my json to be.
    So i tried to do it manually:

    	$list = $pages->get(1234)->children;
    	$list_array = array();
    	
    	foreach($list as $listItem) {
    		$list_array[] = array(
    			'title' => $listItem->title, 
    			'id' => $listItem->id,
    			'tags' => array(
    				'ids' => $listItem->page-reference-field 
    			)
    		);
    	}
    	
    	$list_json = json_encode($list_array, true);
    	echo $list_json;
    	

    How do I loop through a page-reference-field inside an array?

     

    UPDATE:
    i think, thats the way to do it

    	$list = $pages->get(1234)->children;
    	$list_array = array();
    	
    	foreach($list as $listItem) {
    		$listItemTags = array();
    		foreach($listItem->tags as $tag) {
    			$listItemTags[] = array(
    				'id' => $tag->id,
    				'title' => $tag->title,
    			);
    		}
    		$list_array[] = array(
    			'title' => $listItem->title, 
    			'id' => $listItem->id,
    			'tags' => $listItemTags
    		);
    	}
    	
    	$list_json = json_encode($list_array, true);
    	echo $list_json;

     

  8. What ever lived before dinosaurs, I'm one of those 🙂

    I use Nova as Code Editor which has a FTP-client builtin. Most of the time I'm working on the live-server.
    ProCache takes care of my scss-files
    Modules: PrivacyWire, Jumplinks, ProtectedMode, lot of the ProModules, …
    ProfileSiteExporter for moving Sites
    I also do not offer hosting

    Even with a limited setup as mine, there is a lot possible with ProcessWire. What a great CMS and community.

    btw: Happy new year to you all!
     

     

    • Like 6
  9. On 12/21/2021 at 6:26 AM, dadish said:

    Hi @ngrmm. I suggest you to start debugging the request from your template. Depending on how you are sending the request, first try to simply echo it. In your template, simply echo back the graphql request. Could look something like this.

    <?php
    
    echo $input->post('query');
    
    // Or:
    // echo $_POST['query']
    
    // Or:
    // $rawBody     = file_get_contents('php://input');
    // $requestData = json_decode($rawBody ?: '', true);
    // echo $requestData['query']

    @dadish I tried the above code
     

    <?php namespace ProcessWire;
    
    echo $_POST['query'];

    and I'm getting this error in TracyDebugger

    PHP Notice: Undefined index: query in .../httpdocs/xxxxxxxxxxx/site/templates/graphql.php:3

    My graphi template has the forward slash activated.
    Just to understand this, is it right that I first configure the output with the GraphiQL-tool. And this output is then shown on /graphql/ as json?

     

    UPDATE: seems it has something to do with my site-settings
    I tried it in JS and it works
    However when I use /graphql/ as URL i see an object in the console. When I use /processwire/setup/graphql/ I see a json in the console
     

    	$.post(
    		'/graphql/',
    		{
    			query: "{ eventsArticle { list { id  } } }"
    		},
    		function (res) {
    			console.log(res);
    		}
    	);

     

  10. {"errors":[{"message":"Syntax Error: Unexpected \u003CEOF\u003E","extensions":{"category":"graphql"},"locations":[{"line":1,"column":1}]}]}

    I'm getting this error for the GraphQl page for domain.com/subfolder/graphql/
    GraphiQl (domain.com/subfolder/graphiql/) is working fine. Also domain.com/subfolder/processwire/setup/graphql/

    I assume this has something to do with my pw-installation inside a subfolder?
    I already saw that hint with the slash and also tried this in my graphql-template

    <?php namespace ProcessWire;
    
    header('Content-Type: application/json');
    $ProcessGraphQL = $modules->get('ProcessGraphQL');
    $ProcessGraphQL->GraphQLServerUrl = '/subfolder/graphql/';
    echo json_encode($ProcessGraphQL->executeGraphQL(), true);
    

    In my htaccess i have
    RewriteBase /subfolder/

    and in my config file I still have
    $config->httpHosts = array('domain.com', 'www.domain.com');

  11. I exported a profile and wanted to install it on another webspace. I've done this hundred times and it works always.

    But this time the install-process fails before the last step. The screen where you can enter admin name and password does not appear. The browser gives me an 200 Error for install.php

    I can not login into the backend (no user account set yet).
    At the frontend I get different errors. Looks like any functions linke css() (ProCache) and render() (Formbuilder) causes errors.

    The server is running php 7.4 and mysql 5.7
    PW is the latest masterversion

    the install.sql in my exported has a 16.4mb filesize
    the phoinfo() says 120 max time for php executions. Could this be the problem?

    the first frontend errorlogs after installation fails:

    2021-12-14 15:06:19	?	?	You must assign a template to the page before setting custom field values (name1062) [pageClass=ProcessWire\Page, template=]
    2021-12-14 15:06:19	guest	https://xxxxxxxxxx.com/_new2/	You must assign a template to the page before setting custom field values (name1062) [pageClass=ProcessWire\Page, template=]

    one after some refreshes in the browser

    2021-12-14 15:21:50	guest	https://xxxxxxx.com/_new2/	Fatal Error:  Uncaught Error: Call to a member function css() on null in /homepages/21/d521107727/htdocs/xxxxxxx/_new2/site/templates/_inc/header.php:50 Stack trace: #0 /homepages/21/d521107727/htdocs/xxxxxxx/_new2/site/assets/cache/FileCompiler/site/templates/home.php(4): include() #1 /homepages/21/d521107727/htdocs/xxxxxxx/_new2/wire/core/TemplateFile.php(327): require('/homepages/21/d...') #2 /homepages/21/d521107727/htdocs/xxxxxxx/_new2/wire/core/Wire.php(414): ProcessWire\TemplateFile->___render() #3 /homepages/21/d521107727/htdocs/xxxxxxx/_new2/wire/core/WireHooks.php(951): ProcessWire\Wire->_callMethod('___render', Array) #4 /homepages/21/d521107727/htdocs/xxxxxxx/_new2/wire/core/Wire.php(485): ProcessWire\WireHooks->runHooks(Object(ProcessWire\TemplateFile), 'render', Array) #5 /homepages/21/d521107727/htdocs/xxxxxxx/_new2/wire/modules/PageRender.module(554): ProcessWire\Wire->__call('render', Array) #6 /homepages/21/d521107727/htdocs/xxxxxxx/_new2/wire/core/Wire.php(417): ProcessWire\PageRender->___renderPage(Object(Proce (line 50 of /homepages/21/d521107727/htdocs/xxxxxxx/_new2/site/templates/_inc/header.php)




     

  12. @joshua I'm using GoogleMapsApi on a page. And did this:
     

    <?php
    
    // allow button
    echo "<a class='privacywire-consent-button' data-consent-category='external_media'>allow cookies</a>";
    
    	$address = $content->map_address->address;
    	$lat = $content->map_address->lat;
    	$lng = $content->map_address->lng;
    	echo "<script >
    		var lat,lng,zoom;
    		lat = $lat;
    		lng = $lng;
    	</script>";	
    		
    // map stylung and render function
    echo "<script type='text/plain' data-type='text/javascript' data-category='external_media'  data-src='{$templatesUrl}scripts/gmaps.js' class='require-consent'></script>";
    
    // maps API
    echo "<script type='text/plain' data-type='text/javascript' data-category='external_media' data-src='https://maps.googleapis.com/maps/api/js?key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXX&callback=initMap' class='require-consent'></script>";
    	
    // my map
    echo "<div id='map' class='wrapper'></div>";

    When I click on the allow button, all content disappear and there is a error
     

    domain.com/:1 Uncaught (in promise) Qe {message: 'Map: Expected mapDiv of type HTMLElement but was passed null …

    However the cookies are allowed. So that if refresh the page, everything is fine (cookies allowed and map is shown). What am I missing?

  13. I would like to create pages from a json feed.
    So i decode my json and create them via API.

    $jsonData = json_decode($jsonFromOtherWebsite);
    
    foreach($jsonData as $jsonDataItem) {
    	$pageTitle = $jsonDataItem->name;			
    	$p = new Page();
    	$p->template = 'import_page';
    	$p->parent = $pages->get(xxxx);
    	$p->title = $pageTitle;
    	$p->save();
    }

    Let's say the source (json) changes and i have to do another import.
    Then I want to compare the new json with the existing pages to see if there are new ones and if there some aren't there anymore.

    Is there a way to compare the new JsonData with my existing pw-pages with the API.
    Something like

    foreach($jsonData as $jsonDataItem) {
    	// check if a page with this title exist
    	if($pages->find("template=import_page, title=$jsonDataItem->name") {
    		// update existing field values
    		$getExistingPage = $pages->find("template=import_page, title=$jsonDataItem->name");
    		// update value
    		$getExistingPage->setAndSave('field', $jsonDataItem->x);
    	}
    	else {
    		// create new page
    		$pageTitle = $jsonDataItem->name;			
            $p = new Page();
            $p->template = 'import_page';
            $p->parent = $pages->get(xxxx);
            $p->title = $pageTitle;
            $p->save();	
    	}
    }
    
    // search for pages wich are not anymore in the json and hide/delete them
    // …

     

  14. 9 minutes ago, FireWire said:

    Okay now I got it. That is the URL that needs to be in the JS file I mentioned. In that JS it does it's best to parse the URL, get the admin slug, then build the request URL.

    If you revisit that code in fluency_tools.js  set the value of requestUrl to where it should be able to send requests to the module. It should look like this:

    var moduleRequest = function(requestData, callback) {
      var winLoc = window.location,
          params = [],
          requestUrl = 'https://domain.com/_tmp/processwire/fluency/data/'
          // requestUrl = winLoc.protocol + '//' +
          //              winLoc.host + '/' +
          //              winLoc.pathname.split('/')[1] + '/fluency/data/'
    
        // ... ommitted for brevity ...
    }

    If you move to production and ProcessWire is being served from the root directory then change this back.

    it works! thanks a lot

    • Like 1
  15. Thanks @FireWire
    Actually the folder is already showing up in the error message above. When i do your quick fix i get this:  

    fluency_tools.js:60 POST https://domain.com/_temp/_temp/fluency/data/ 404
    moduleRequest @ fluency_tools.js:60
    (anonymous) @ fluency.js:579
    load (async)
    (anonymous) @ fluency.js:576
    VM752:1 Uncaught SyntaxError: Unexpected token < in JSON at position 0
        at JSON.parse (<anonymous>)
        at XMLHttpRequest.xhr.onload (fluency_tools.js:53)
    xhr.onload @ fluency_tools.js:53
    load (async)
    moduleRequest @ fluency_tools.js:52
    (anonymous) @ fluency.js:579
    load (async)
    (anonymous) @ fluency.js:576

     

  16. are there any known issues with pw-installations inside a folder?

    It works for me on a website like domain.com but not on pw-installation like domain.com/_temp/
    I get this errors on a backend pageload

    fluency_tools.js:60 POST https://domain.com/_tmp/fluency/data/ 404
    moduleRequest	@	fluency_tools.js:60
    (anonymous)	@	fluency.js:579
    load (async)		
    (anonymous)	@	fluency.js:576
    VM287:1 Uncaught SyntaxError: Unexpected token < in JSON at position 0
        at JSON.parse (<anonymous>)
        at XMLHttpRequest.xhr.onload (fluency_tools.js:53)
    xhr.onload	@	fluency_tools.js:53
    load (async)		
    moduleRequest	@	fluency_tools.js:52
    (anonymous)	@	fluency.js:579
    load (async)		
    (anonymous)	@	fluency.js:576


    @FireWire you hardcoded the paypalme-PNG-Url into FluencyConfig.php (line:365). It's broken. 
    /Fluency/img/paypal_me.png  > /Fluency-Translation-main/img/paypal_me.png

  17. 3 hours ago, BitPoet said:

     

    <script>
      var ProcessWire = {config: <?= wireEncodeJSON($config->js(), true, $config->debug) ?>;
    </script>

     

    thx @BitPoet

    I guess there is Typo in your Snippet. Missing closing }?
    However I get a 500 Error.

    So I tried this:
     

    <script type="text/javascript">
    	<?php $jsConfig = $config->js(); ?>
    	var ProcessWire = {config: <?php echo json_encode($jsConfig); ?>};
    	var config = ProcessWire.config;
    </script>
     

    and

    $config->js('mySettings', [
    	'foo' => 'bar',
    ]);

    but console.log(ProcessWire.config); outputs an empty array

×
×
  • Create New...