apeisa

Module
Multisite

239 posts in this topic

Multisite and Jumplinks

Can't remember if this was brought up before, but I think there may be a need to have Jumplinks v2 support Multisite. Besides there being two dev branches and referrals to how things can get messy, I think an implementation on the Jumplinks-side would be easy enough.

Do you think it would be simple enough to have the jumplink editor list valid domains from config so the user can select which domain(s) the jumplink belong(s) to?

Also, I'd be interested to know how many use the core multisite method (multiple site dirs sharing a single core) vs those who use this module, as I'd need a different method to obtain the valid domains for those using the core method.

Lastly, is the current dev2 going to make it to master any time soon?

Share this post


Link to post
Share on other sites

Hi, all,

we are trying to automate the module config setting for admin users that only have access to the page tree. The idea is that these admin users should be able to create new pages with the specific multisite template and the page name is automatically added to the multisite config array on page creation.

Sadly the hook does not work :-(  It is placed in the ready.php:

$this->addHookAfter('Pages::add', function($event) {
	  $page = $event->arguments[0];

    if ($page->template == 'project_home') { //check template of page added
    
      // get new domain from page name
      $new_domain = $page->name; 

      // get config data and save it to var
      $config = wire('modules')->getModuleConfigData('Multisite'); 
      $data = $config['subdomainsArray']; 
      
      // add new domain to config data and save it
      array_push($data, $new_domain);
      wire('modules')->saveModuleConfigData('Multisite', $data); 
    }
});

Any clues?

Share this post


Link to post
Share on other sites

@mikel I guess you use the current master. This version is not supported anymore.

New versions (dev, dev2)  https://github.com/somatonic/Multisite/tree/dev2#add-multisitedomains this config was changed to be in site/config.php for various reasons . So the domain array is added to $config and it doesn't matter where. it could also be in a module.

I'm not sure what doesn't work in your example, it could be that it is in ready.php or the hook ::add should be ::added. Just wanted to mention that this if you use the master version it won't be compatible in future versions.

1 person likes this

Share this post


Link to post
Share on other sites

Hi, Soma,

thanks for the quick reply. The hint (::added) was correct. It pointed me to other problems, so we could work everything out. 
Here is the working code for automating the modules config (placement in ready.php):

$this->addHookAfter('Pages::added', function($event) {
	  $page = $event->arguments[0];

    if ($page->template == 'NAME_OF_TEMPLATE') { //check template of page added
    
      // get new domain from page name
      $new_domain = $page->name; 

      // get config data and save it to var
      $config = wire('modules')->getModuleConfigData('Multisite'); 
  
      // add new domain to config data and save it
      $config['subdomains'].= "\n".$new_domain;
      wire('modules')->saveModuleConfigData('Multisite', $config); 
    }
});

I will work on Hooks for Pages::trashed and Pages::renamed.

As this is a client project, we will not upgrade unless we get paid for it, so we will stick with this solution for some time ;-)

So here are the other two mentioned hooks. Both are working:

$this->addHookBefore('Pages::renamed', function($event) {
	  $page = $event->arguments[0];

    if ($page->template == 'NAME_OF_TEMPLATE') { //check template of page added
    
      // get old domain from page name
      $old_domain = $page->namePrevious;
      
      // get new domain from page name
      $new_domain = $page->name; 

      // get config data and save it to var
      $config = wire('modules')->getModuleConfigData('Multisite'); 
      
      // replace changed domain in config data and save it
      $config['subdomains'] = str_replace($old_domain, $new_domain, $config['subdomains']);
      wire('modules')->saveModuleConfigData('Multisite', $config); 
    }
});

$this->addHookBefore('Pages::trashed', function($event) {
	  $page = $event->arguments[0];

    if ($page->template == 'NAME_OF_TEMPLATE') { //check template of page added
      
      // get domain from page name
      $domain = $page->name; 

      // get config data and save it to var
      $config = wire('modules')->getModuleConfigData('Multisite'); 
      
      // remove deleted domain from config data and save it
      $config['subdomains'] = str_replace("\n".$domain, '', $config['subdomains']);
      wire('modules')->saveModuleConfigData('Multisite', $config); 
    }
});

 

Share this post


Link to post
Share on other sites

Forked this module a few days ago and ended up in a complete rewrite. Still under development and testing but working properly here.

What is different?

  1. Do not worry about page naming. The root page is defined via ID.
  2. Full multilanguage support *
  3. take in account $template->slashUrl settings
  4. take in account LanguageSupportPagenames::useHomeSegment settings
  5. Fallback to default 404 page if custom 404 is not set
  6. Throws exception in case of misconfiguration
  7. Access of pages residing in a MultisitePageTree for other domains other than the corresponding root page is disallowed except for superuser
  8. Pages inside a MultisitePageTree accessible only via the modified url if called from the corresponding domain (throws 404 instead of unexpected redirects)
  9. Page paths are set via hook in Page::path() instead of modifying the return of Page::render()
  10. Crosslink support via the RTE (CK Editor) Link plugin
  11. Page view links in admin with correctly modified urls

* under conditions: see next post!
Feedback welcome. Have a try: https://github.com/kixe/Multisite/tree/kixe

6 people like this

Share this post


Link to post
Share on other sites

Not sure why you need to rewrite it. Current last version is the essence of 2-3 experience using it.

Just wanted to mention that for good reasons the module doesnt hook page path anymore cause it creates all sort of problem with core and other modules. Also id based root isnt tranportable thats why i have done it via config and page names.

Good luck.

Share this post


Link to post
Share on other sites

i'm trying to get the multisite module to work, but i guess there is something i am missing, i hope someone can help:

this is my page tree

-web
--www.domain1.net
---404 Domain1
--www.domain2.info
---page2
---Domain2 Not Foundffff
-Admin
-Trash

then i added this into config.php

$config->MultisiteDomains = array(
    "domain1.net" => array( 
            "root" => "www.domain1.net", 
            "http404" => 1023
        ),
    "domain2.info" => array(
            "root" => "www.domain2.info",
            "http404" => 27
        )
);

and

$config->httpHosts = array('www.domain1.net', 'domain1.net', 'www.domain2.info', 'domain2.info');

and both domains are pointing to the same directory

 

and now both www.domain1.net and www.domain2.info shows me the "-web" page

and anything else shows the Domain2 not foundffff PAge with ID 27 (www.domain2.info/web/page2, www.domain2.info/page2 and any other URL)

 

i have the module 

Multisite
MODULE VERSION SUMMARY
Multisite	0.1.0

showing up under modules page

 

I use PW under www.domain1.net/myadmin and the links-Button in the page-tree points to http://www.domain1.net/www.domain1.net and http://www.domain1.net/www.domain2.info

 

Now i tried to install the old module Multisite    0.0.1, now i have an additional settings field on the modules page which i did not have with the new module. The Domains and the subsites are working, but i cannot get to the backend anymore www.domain1.net/myadmin shows mie the 404 site... ahhhh, i'm confused :(

 

is there something missing? do i have to add anything else ?

 

Thanks for any help !!

Edited by NoremPload
adding info

Share this post


Link to post
Share on other sites

0.1.0 is the correct version I recommend. I'm not sure, looks correct except you have config "domain1.net" but you access the site with www.domain1.net? It should match I think.

Share this post


Link to post
Share on other sites

Thx Soma, this brought me one little step further, but not to the end ;)

i changed the config to

$config->MultisiteDomains = array(
    "www.domain1.net" => array( 
            "root" => "www.domain1.net", 
            "http404" => 1023
        ),
    "www.domain2.info" => array(
            "root" => "www.domain2.info",
            "http404" => 27
        )
);

and the page tree to

- web
	-- www.domain1.net
		--- 404 Domain 1
		--- page1
	-- www.domain2.info
		--- page1
		--- page2
		--- 404 domain 2
- Admin
- Trash

www.domain1.net shows me -- www.domain1.net and www.domain2.info shows -- www.domain2.info

but any subpages are showing the 404 page 

www.domain1.net/page1 => www.domain1.net/404domain1

and

www.domain2.info/page1 + www.domain2.info/page2 => www.domain2.info/404domain2

another strange thing: www.domain2.info => page1 was called calculator before and www.domain2.info/calculator/ worked, after renaming it to page1 www.domain2.info/page1/ doesn't work, going back to calculator, www.domain2.info/calculator/ works again

i really don't have any idea whats going on ;(

 

edit: i logged the modify part in the module

// we modify the GET it to tell PW what page to load
$_GET['it'] = (isset($_GET['it']))
	? "$langSegment{$domainPageName}/" . $this->it
	: "$langSegment{$domainPageName}/";

$this->log( '$_GET[it]: ' . serialize($_GET['it']));

and got this

$_GET[it]: s:28:"www.domain2.info/page1";

i guess thats what it should be, but the request does not work :( i always get the 404 page

 

Finally i solved it after a lot of try and error

the only thing i had to change was removing .info or change it to .inf 

  "www.domain2.info" => array(
            "root" => "www.domain2.inf",
            "http404" => 27
        )

in the config and in the paht, now it works.

 

other 4 letter domains are working, only info brings the error

 

Share this post


Link to post
Share on other sites

I just tried and changed my setup to a pw27.info and pw27b.info and its working fine. I don't see any reason why domain name would make a difference. I even uninstalled languages support to rule that out.

I also don't know which PW version we are talking about. Also 404 page of server or PW? 

The config is correct and works here. Also config root name doesn't have to be the domain it could be "foo" or "bar".

Only thing I can imagine is if you have a folder called "page1" in your install that would conflict with PW (nothing to do with multisite)

Share this post


Link to post
Share on other sites

Thx Soma for trying to find out what's going on.

I just tried to rename everything to

www.super.info => does not work

www.super.inf => does work

I really have no clue what's wrong, but it works with .inf, so i'll work with this ;)

 

@404, i get the correct 404 page not the server 404 page

 

Share this post


Link to post
Share on other sites

I have a couple of questions about the module,

I am using multisite 0.0.6 (unsure if this is the latest?) in conjunction with Admin Restrict Branch, in the admin area I am going to have a couple of admin listing pages that will, for example list all the pages with the template 'bob'. The admin restrict is setup so when 'user1' logs in they can only see the user1 branch, and same for 'user2' and so on. Each users domain is setup so it is 'user1.example.com'. What I am after is when a user logs in and goes to the listing page, it will find all of the template 'bob' but only in their brand. 

<?php
foreach($pages->find("template=bob") as $bob):
	echo $bob->title;
endforeach;
?>
Right now this code, displays all of the pages that have the 'bob' template not just the ones in the restricted branch.
Any ideas?
This works to find the 'user1' page if user1 is logged in. But I can't figure it out.

<?php
	// This is the variable for the root users page (i.e the users home page)
	$userroot = $pages->find("name=" . $user->name);
?>


Also, I would like the same in the frontend, so when a user goes to 'user1.example.com' and I run the same code as above it will do the same thing.
For now, I have done this, which works. I don't know if this is good practice or not?

<?php
$pages = $page->rootParent;
?>

-main
--user1
---Page1 (template=bob)
---Page2 (template=bob)
--user2
---Page3 (template=bob)
---page4 (template=bob)
-Admin
--Listing Page
-Trash

Share this post


Link to post
Share on other sites
On 6/18/2017 at 3:45 PM, xfroggy said:

I have a couple of questions about the module,

I am using multisite 0.0.6 (unsure if this is the latest?) in conjunction with Admin Restrict Branch, in the admin area I am going to have a couple of admin listing pages that will, for example list all the pages with the template 'bob'. The admin restrict is setup so when 'user1' logs in they can only see the user1 branch, and same for 'user2' and so on. Each users domain is setup so it is 'user1.example.com'. What I am after is when a user logs in and goes to the listing page, it will find all of the template 'bob' but only in their brand. 


<?php
foreach($pages->find("template=bob") as $bob):
	echo $bob->title;
endforeach;
?>

Right now this code, displays all of the pages that have the 'bob' template not just the ones in the restricted branch.
Any ideas?
This works to find the 'user1' page if user1 is logged in. But I can't figure it out.


<?php
	// This is the variable for the root users page (i.e the users home page)
	$userroot = $pages->find("name=" . $user->name);
?>

Also, I would like the same in the frontend, so when a user goes to 'user1.example.com' and I run the same code as above it will do the same thing.
For now, I have done this, which works. I don't know if this is good practice or not?


<?php
$pages = $page->rootParent;
?>

-main
--user1
---Page1 (template=bob)
---Page2 (template=bob)
--user2
---Page3 (template=bob)
---page4 (template=bob)
-Admin
--Listing Page
-Trash

I am a bit silly, 

$client = $pages->get("name=" . $user->name);

Replaced

$client = $pages->find("name=" . $user->name);

Which now means I can go

<?php
foreach($client->find("template=bob") as $bob):
	echo $bob->title;
endforeach;
?>

I feel a bit silly about that, it was a simple fix between find() and get().

Share this post


Link to post
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 bernhard
      Hi,
      just stumbled over a little module that i built for my last project. it helped me to test performance of my rockdatatables module to generate 3000 random json datasets and i want to share it with you. maybe it saves some time for someone.
      https://gitlab.com/baumrock/RockDummyData/
      easy example:
      $rdd = $modules->get('RockDummyData'); for($i=0; $i<15; $i++) { // this has to be inside the for-loop to always get a new dummy $dummy = $rdd->getDummy(); echo date("d.m.Y H:i:s", $dummy->timestamp) . "<br>"; } more advanced:
      $json = new stdClass(); $json->data = array(); $rdd = $modules->get('RockDummyData'); for($i=0; $i<3000; $i++) { // this has to be inside the for-loop to always get a new dummy $dummy = $rdd->getDummy(); $obj = new stdClass(); $obj->name = $dummy->forename . ' ' . $dummy->surname; $obj->position = $dummy->job; $obj->office = $dummy->city; $obj->color = $dummy->color; $obj->start_date = new stdClass(); $obj->start_date->display = date('d.m.Y',$dummy->timestamp); $obj->start_date->sort = $dummy->timestamp; $obj->salary = rand(0,10000); $json->data[] = $obj; } echo json_encode($json); you have to store your random datasets on your own into the /data folder. there are several services for creating all kinds of random data on the web - if you know one service that allows sharing those datasets let me know and i can include common needed data into the module
    • By AndySh
      Hello!
      I need your assistance please. I purchased the module FormBuilder. Unfortunately, the module discontinued delivering customer submissions to e-mail box specified in the module settings. Direct mailing to the e-mail box works OK. The module settings stays the same and are correct, like "Send e-mail to administrator(s) is checked. The last version of FormBuilder 3.0 has been installed. Please advise how to resolve the issue becase I cannot get orders from customers anymore (((
    • By kixe
      As described in this post (https://processwire.com/talk/topic/8551-custom-urls-for-pages/?p=82742) the option 'Name Format Children' under the tab 'Family' in template settings doesn't work properly and also not as expected. I had a look inside the code and made some changes which are working properly, which offers much more options, more consistency and less code too.

      The result is the following. You have 3 Options for generating name and title, which could be combined in endless variations.
      Name is always derived from title, same like creating pages manually.
      type date: if function detects # character anywhere in the string, conversion will be: deletion of # and string will be used as format parameter for PHP date() function type field: if string is a fieldname of the parent page the value of this field will be used type string: if string doesn't fit to the 2 preceeding it will be taken as it is All parts (separated by comma) will be composed in the order of setting. You can use unlimited numbers of parts

      I made a pull request on github: https://github.com/ryancramerdesign/ProcessWire/pull/831

      Example screenshots

      Setting ...


      will result in


       
    • By kongondo
      FieldtypeRuntimeMarkup and InputfieldRuntimeMarkup
       
      Modules Directory: http://modules.processwire.com/modules/fieldtype-runtime-markup/
      GitHub: https://github.com/kongondo/FieldtypeRuntimeMarkup
       
      This module allows for custom markup to be dynamically (PHP) generated and output within a page's edit screen (in Admin).
       
      The value for the fieldtype is generated at runtime. No data is saved in the database. The accompanying InputfieldRuntimeMarkup is only used to render/display the markup in the page edit screen.
       
      The field's value is accessible from the ProcessWire API in the frontend like any other field, i.e. it has access to $page and $pages.
       
      The module was commissioned/sponsored by @Valan. Although there's certainly other ways to achieve what this module does, it offers a dynamic and flexible alternative to generating your own markup in a page's edit screen whilst also allowing access to that markup in the frontend. Thanks Valan!
       
      Warning/Consideration
      Although access to ProcessWire's Fields' admin pages is only available to Superusers, this Fieldtype will evaluate and run the custom PHP Code entered and saved in the field's settings (Details tab). Utmost care should therefore be taken in making sure your code does not perform any CRUD operations!! (unless of course that's intentional) The value for this fieldtype is generated at runtime and thus no data is stored in the database. This means that you cannot directly query a RuntimeMarkup field from $pages->find(). Usage and API
       
      Backend
      Enter your custom PHP snippet in the Details tab of your field (it is RECOMMENDED though that you use wireRenderFile() instead. See example below). Your code can be as simple or as complicated as you want as long as in the end you return a value that is not an array or an object or anything other than a string/integer.
       
      FieldtypeRuntimeMarkup has access to $page (the current page being edited/viewed) and $pages. 
       
      A very simple example.
      return 'Hello'; Simple example.
      return $page->title; Simple example with markup.
      return '<h2>' . $page->title . '</h2>'; Another simple example with markup.
      $out = '<h1>hello '; $out .= $page->title; $out .= '</h1>'; return $out; A more advanced example.
      $p = $pages->get('/about-us/')->child('sort=random'); return '<p>' . $p->title . '</p>'; An even more complex example.
      $str =''; if($page->name == 'about-us') { $p = $page->children->last(); $str = "<h2><a href='{$p->url}'>{$p->title}</a></h2>"; } else { $str = "<h2><a href='{$page->url}'>{$page->title}</a></h2>"; } return $str; Rather than type your code directly in the Details tab of the field, it is highly recommended that you placed all your code in an external file and call that file using the core wireRenderFile() method. Taking this approach means you will be able to edit your code in your favourite text editor. It also means you will be able to type more text without having to scroll. Editing the file is also easier than editing the field. To use this approach, simply do:
      return wireRenderFile('name-of-file');// file will be in /site/templates/ If using ProcessWire 3.x, you will need to use namespace as follows:
      return ProcessWire\wireRenderFile('name-of-file'); How to access the value of RuntimeMarkup in the frontend (our field is called 'runtime_markup')
       
      Access the field on the current page (just like any other field)
      echo $page->runtime_markup; Access the field on another page
      echo $pages->get('/about-us/')->runtime_markup; Screenshots
       
      Backend
       

       

       
      Frontend