Jump to content

sins7ven

Members
  • Posts

    26
  • Joined

  • Last visited

Posts posted by sins7ven

  1. Hi community,

    I am trying to build a way to create some JSON output for some pages. For this I created a template called json.php. This one has URL segments enabled and based on this it gives me some page data. I mostly use this for getting some JSON into my JS libraries (like Vue.js) to build some interactive filters. 

    So for example www.domain.com/json/referenzen should give me all data from the clients child pages (usually logo references). This works totally fine. 

    But for one special case (getting management child pages) I have a repeater item on each page and I am not sure how to get this repeater item into my JSON data. My code looks as follows: 

    <?php namespace ProcessWire;
    
    if (!$input->urlSegment1) {
        $session->redirect($pages->get('/')->url);
    }
    
    $data = array();
    
    switch ($input->urlSegment1) {
    	case "referenzen":
    		$p = $pages->get("name=referenzen");
    		foreach ($p->logo_select as $logo) {
    			$data[] = array(
    				"name" => $logo->title,
    				"url" => $logo->image->url,
    				"category" => $logo->business_category->value
    			);
    		}
    		break;
    	case "management":
    		$p = $pages->get("name=management")->children;
    		
    		foreach ($p as $m) {
    			$data[] = array(
    				"name" => $m->title,
    				"venture" => $m->venture_select->title,
    				"image"	=> array(
    					"url" => $m->image->url,
    					"description" => $m->image->description
    				),
    				"position" => $m->team_details->position,
    				"email" => $m->team_details->email,
    				"phone" => $m->team_details->phone,
    				"socials" => $m->socials // This is the repeater item which has links to social networks
    				),
    			);
    
    		};
    		break;
    }
    
    header("Content-type: application/json");
    echo wireEncodeJSON($data);
    return $this->halt();
    ?>

    I know there are some modules like Pages2JSON or PageQueryBoss but I thought I could solve this without extra need of a module. Would be nice if someone could point me into the right direction. Thanks!

  2. Thanks a lot Dragan, but this is something I am already aware of and my problem is a bit different. Please see the image here as an illustration example. It is more a matter of rearranging the order within each language. So when I just sort by the language tag it just outputs all the logos that have this particular language tag but not in a specific order as I would set it in the backend with drag and drop of the gallery items. But I assume this could also be done with some tags. Just creating some tags (first, second, third etc) and assigning them as well to the tags so they would appear before the other ones that do not have one of these "priority" tags? 

    logo-order.png

  3. Hi Processwire Community,

    I am wondering if its possible to change the order of an image gallery based on the language. I have the following use case. A multi-language website (german, english, dutch). These are business websites and they show some clients logos. Now basically this would just be an issue of using the image field and getting all images in one and iterating over them to generate the output. Now how would it be possible to change the order of how they appear based on the language? Let's say for the german site I want some logos to appear much earlier than for example on the dutch site. Is that possible? I found some forum entries about language alternate fields so which would basically mean I need to set up 3 different fields (gallery, gallery_english, gallery_dutch) to make it possible to set different sort orders of the logos? But wouldn't this also mean I basially end up having 3 versions of each logo/image on my page? Or is there another way to achieve this? 

    I was also thinking about creating a repeater field for each image so I can add some more properties to each image (e.g. a category so I can later use some Javascript to build some nice category filters). So in regards to my example above I would need 3 different repeater fields (e.g. gallery_repeater, gallery_repeater_english, gallery_repeater_dutch) to get this working, right? How much impact does that have on the performance, assuming I have something between 40 and 50 logos to display (which would basically mean 40-50 repeater items per language). 

  4. Thank you! That looks pretty close to what I have in mind. However - I am not sure if this approach let me allow only some selected languages to be available in the language switcher (for example domainA.com should only show default and english and domainB.com should show default, french and dutch). But I am not sure if it is even possible to change the default language based on the host? I am going to play around with your solution and see what I can achieve. Thanks again!

  5. Hi community, I am wondering if its possible to display languages based on what host/domain has been requested.

    The use case is the following: I have one installation of PW - and within this installation I set up 5 different languages (default, english, spanish, french, dutch). Now I have 3 different domains (domainA.com, domainB.com, domainC.com) and I want to decide which languages to make available based on what domain has been navigated to. 

    For example:

    domainA.com
     - default (domainA.com)
     - english (domainA.com/en)

    domainB.com
      - default (domainB.com)
      - french (domainB.com/fr)
      - dutch (domainB.com/nl)

    domainC.com
      - default (domainC.com)
      - dutch (domainC.com/nl)

    So what I want to achieve is making only these particular languages selectable in the language switcher on the frontend. Since all pages share the same templates and overall site structure I don't see the benefits of running this installation as a multisite setup or would it be better to do so? But I assume that this would be difficult to handle since the default language might change as well. (On the french version of the page, french should be the default language and so on). Any suggestions how to accomplish that? Thanks!

  6. Hi community,
    I have been thinking about a project lately and was wondering if this is something I can accomplish with Processwire. I know the platform is pretty much capable of getting everything done but tbh I am not sure on this one.

    I want to create a site which only has a login. The logins and details are pre-made and been sent to the user before. So there is no need for registration. After the login, the user can see his own kind of dashboard and a dropdown where he can select "projects". Each project has a number of properties or data values, for example:

    Project 1:
        - time to finish: 30 days
        - time spent: [amount per user]
        - project budget: 100.000 $
        - money earned per user: [amount per user]

    Project 2:
        - time to finish: 40 days
        - time spent: [amount per user]
        - project budget: 50.000 $
        - money earned per user: [amount per user]

    The fields are just an example. The goal is to assign users to the projects and set the value as per example above so when the user sees his dashboard and selects a project from a dropdown, he only sees his values. Projects of course can and will have multiple users.

    In addition to that, there should be some project-relevant documents to download but these permissions can be set up by roles and that would be the problem here. My question is, what would be the best approach here? From my thinking I would set up the projects as pages and define the values with fields. But how can I set up the users to assign them to projects? Maybe creating the users also as pages or is there another way? The users should also only see their own data and not the data from the other guys. So meaning that once the user is logged in he only sees his dashboard and a dropdown. 

    I know this example sounds a bit abstract but it should only visualise what a common approach would be to this problem. Would love to hear your thoughts!

  7. Is it possible to create custom markers? I have around 20 markers and want to show them as numbered coloured dots on the map. Its basically just a red spot (all CSS, no images) with the number right in the middle. Not sure if this has already been asked here before. Anyone else tried this before? 

  8. Hi there,

    just a small update on this for those who are interested. Finally I've got my script / download proxy up and running. 

    This is the code that generates a list with downloadable files (in this case logos) through a repeater field. 

    <?php 
    foreach($page->logos as $logo) {
    echo "<p><a href='{$config->urls->root}download.php?pageid={$logo->id}&file={$logo->logo_file}'>{$config->urls->root}download.php?pageid={$logo->id}&file={$logo->logo_file}</a></p>";
    }
    ?>
    

    So a download links then looks like this:

    http://www.domain.com/download.php?pageid=1057&file=hi_res_100_percent_pure_logo.zip
    

    Here is the download.php:

    <?php
    // bootstrap PW
    include("./index.php");
    
    // make sure user is logged in
    if(wire("user")->isLoggedin()){
        $fn = wire('input')->get->file;
        $pid = wire('input')->get->pageid;
        $filepage = wire("config")->paths->files;  
        // put together the complete path to the file
        $filename = $filepage.$pid.'/'.$fn;   
            if(!$filename) die("download not found");
            // send file to browser
            wireSendFile($filename, array('exit' => true));
    } else {
        wire("session")->redirect("/");
    }
    ?>
    

    Everything works great now. However I still wanted to protect the original path of the files (assets/files/...) allthough nobody would know the exact location. To do this I modified to the .htaccess to suite my needs to block all unwanted access to files with the most common endings for downloads (e.g. zip, rar, pdf, etc.)

    So the part in my .htaccess which takes care of that is the following:

    <FilesMatch "(^#.*#|\.(htaccess|htpasswd|ini|phps|bak|config|dist|fla|in[ci]|log|psd|pdf|zip|rar|sh|sql|sw[op])|~)$">
    
        # Apache < 2.3
        <IfModule !mod_authz_core.c>
            Order allow,deny
            Deny from all
            Satisfy All
        </IfModule>
    
        # Apache  2.3
        <IfModule mod_authz_core.c>
            Require all denied
        </IfModule>
    
      </FilesMatch>
    

    I found that part during my research for .htaccess modifications and finally I ended up with using that part of the HTML5 Boilerplate. I know that might be a bit strict and I don't know yet if there are any issues with that but so far everything seems to work fine. 

    Thanks to all the helpers (especially Horst) for guiding me that way to get my solution to work. :)

    • Like 4
  9. now THAT is confusing ;) Sorry for that - this was on my second installation on a laptop where I have a subdirectory under my localhost folder. So "return-pw" is the project folder where my PW installation is located. 

    I placed the download.php file into the sites/templates directory. Maybe that is the problem? Does it belong into the document root of the website project ? 

  10. Sorry what I wanted to say was that this page with the repeaters etc was working fine. The output of the fields and the structure. The only problem is still that download script is not working.

    I replaced the <a href ..> with the code that builds the download link that it looks like this now:

    <?php 
    foreach($page->logos as $logo) {
    echo "<p><a href='{$config->urls->root}download.php?pageid={$logo->id}&file={$logo->logo_file}'>{$config->urls->root}download.php?pageid={$logo->id}&file={$logo->logo_file}</a></p>";
    }
    ?>
    
    

    And the link is looking like this:

    /return-pw/download.php?pageid=1057&file=hi_res_100_percent_pure_logo.zip
    /return-pw/download.php?pageid=1058&file=hi_res_remote_area_logo.zip
    

    But its still not working. When I click on it I get redirected to my 404 page.

  11. Sorry when I missed to mention the repeaters earlier. I was not aware that these could have an important effect to the logic of the script. But anyway - you are right. $page->logos is a Repeater Field. It consists of an file field (logo_file) and an image field (logo_thumb). The result on the page looks something like this (see attachment)

    post-2329-0-27441400-1401052160_thumb.jp

    Everything works fine. In my template I use the following code to get this result:

    <ul class="blocks-5 dl-list">			
      <?php foreach($page->logos as $logo) { ?>  
      <li>
        <a href="<?php echo $logo->logo_file->url; ?>" title="<?php echo $logo->logo_file->description; ?>">
        <img src="<?php echo $logo->logo_thumb->url; ?>" title="<?php echo $logo->logo_thumb->description; ?>"   alt="<?php echo $logo->logo_thumb->description; ?>">
        <h3><?php echo $logo->logo_thumb->description; ?></h3>
      </a>	    		
      </li>
      <?php }	?>			    
    </ul>
    

    When I use your foreach code I get a result something like this:

    /localhost/download.php?pageid=1057&file=hi_res_100_percent_pure_logo.zip
    /localhost/download.php?pageid=1058&file=hi_res_remote_area_logo.zip
    
    

    Thanks for your time! I really appreciate this!

  12. What do you mean with setup? I am running this site on a local machine with Xampp. Its not on a live server. Or do you mean the code? This is what I have so far. 

    Example Downloadlink from my press page:

    <?php foreach($page->logos as $logo) { ?>
    	<p><a href="<?php echo $config->urls->root ?>download.php?pageid=<?php echo $logo->id ?>&file=<?php echo $logo->logo_file; ?>">Download File</a></p>	
    <?php }	?>	
    

    As you can see I managed to receive the individual page IDs from each download folder ($logo->id) and it is now included to the link.

    The download.php file:

    <?php
    include("./index.php");
    
    if(wire("user")->isLoggedin()){
       
        $filename = wire('input')->get->file;
        $pid = wire('input')->get->pageid;
        $filepath = $config->path->files . $pid;
        $full_file = $filepath . '/' . $filename;
    
        $options = array(
            'exit' => true, 
            'forceDownload' => false, 
            'downloadFilename' => '',
        );
    
        wireSendFile($full_file, $options);
        
        } else {
            wire("session")->redirect("/");
        }
    ?>
    

    So both "file" and "pageid" from the link are handed over to the script that I am able to create the full path to the file. At least this is what I thought would work ;)

    I upload the files to via the PW backend to the download page. I set up various repeater fields for various types of downloads ( for example, one repeater for logos, one for images, one for documents etc.) These Repeaters are looping through the uploaded files via foreach so I basically end up with a download page and various download links. Everything has been set up with an own template and everything worked fine except now when I try to get this download passthrough running :)

    The download page also is going to have some child pages (in my example for a music label, each artist gets his own download page as a child so its going to look like this in the end:

    www.domain.com/press/artist/

    Sorry if that sounds a bit confusing :)

  13. thank you both for your input but I think the problem is that every download that I provide on my press page, has been uploaded via the backend to the page so as it is the nature of PW every single download file sits in its own folder. And I need to tell the download script what exactly that ID of each folder is to append it to the download path. That is why I thought I receive these individual IDs by using $page->id. But obviously that only gives me the ID of the download page itself and not of each individual download.

  14. A short update on my project. I tried to build a download passthrough page based on this forum post: https://processwire.com/talk/topic/3634-down-uploads-on-a-per-user-policy/ but my script is not working. 

    This is how my script looks like (download.php):

    <?php
    include("./index.php");
    
    if($user->isLoggedin()){
       
        $file = $_GET['file'];
        $filepath = $config->path->files.$page;
        $filename = $filepath . '/' . $file;
    
        $options = array(
            'exit' => true, 
            'forceDownload' => false, 
            'downloadFilename' => '',
        );
    
        wireSendFile($filename, $options);
        
        } else {
            wire("session")->redirect("/");
        }
    ?>
    

    My download links ony my press page are looking like this. In this particular example its looping through all the logos that I have in my download section.

    <?php foreach($page->logos as $logo) { ?>
        <p><a href="download.php?file=<?php echo $logo->logo_file; ?>">Download file</a></p>	
    <?php }	?>		
    

    When I click on one of these download links I always get redirected to my standard 404 page which means that no page was found. But what exactly is the problem? Is it the download.php file which cannot be found? I placed it as a normal php file into my templates directory.

    Seems I am getting slowly into all of this but at this particular point I am stuck right now :)

  15. Now it works! I also used parts of the code from this post https://processwire.com/talk/topic/107-custom-login/ So I am bit more flexible now and I can include the login form wherever I want to because I also have some child pages below my press page and I only needed to include that login code snippet in my child pages and thats it. Amazing!

    Now I need to figure out how to set up these download redirects because it doesn't matter if a user is logged in or not when he know the exact path to the files that are situated in the assets/files folders.

    • Like 1
  16. Thank you very much Horst - this is a great starting point for me. I already have the basic login procedure running. Regarding the user I also gave the new user "press" a dedicated role. You wrote that its only neccessary to asign him to the "guest-user" role but shouldn't he be asigned to the press role as well? Anyway this is a good start for me and I slowly getting there so thanks a lot for your help! :)

  17. just another question - how complicated would it be to build this with the user/permission settings from PW? Maybe its possible to create a user (maybe called "press") and then only this user is allowed to view a particular page where only this user is allowed? Is that possible somehow? 

  18. Hi there,

    I am kinda new to PW but I gave it a try for a current project and I am pretty amazed so far. It really works great and allthough I have pretty much no knowledge about PHP I can wrap my mind around these functions and also get lots of my queries working. My site is almost complete but I also struggeling with a problem which is the following.

    I am building a website for a music label. They want to provide a dedicated press and download area where press people can download latest press releases, music, artworks and stuff like this.

    The site structure should be like this:

    www.domain.com

     - Page 1

     - Page 2

     - and so on

    and the press area which should be www.domain.com/press 

    The link to the press area is not visible on the main website. The page is hidden and should have a simple protection with htaccess. No user or login / member management required. Just a simple htaccess password protection. How can I do that? What I would normally do is just create a folder "press" on my FTP directory where I put the htaccess and thats it but how can I accomplish this in PW?

    I also provide downloads on that press page. These files for download have been uploaded via the backend and now sit in the assets/file folders. How can I protect them from being downloaded? I want to achieve that once people got access to www.domain.com/press that they are also able to download these files. 

    Maybe its a simple task but I am not sure how to do this properly.

    Thanks for your help - I really appreciate all that kind support here in the forum!

    Cheers,

    Martin

×
×
  • Create New...