Xonox

Members
  • Content count

    62
  • Joined

  • Last visited

Community Reputation

36 Excellent

About Xonox

  • Rank
    Full Member

Recent Profile Visitors

933 profile views
  1. I tried Image Interceptor, and it didn't fit my needs. I guess I'm stuck with regex, then. I knew this, the problem is getting the original size and insert it in the body where the images are placed. I'll have to do it via regex/string replacement. Thanks for your help. I'll see what I can do with your input.
  2. Hi, I need to add the original image dimensions (width x height) for the images inserted in the body field, in a few data-fields. Something like: <a href="/site/assets/files/1092/image-1.jpg"> <img alt="" src="/site/assets/files/1092/image-1.690x0-is.jpg" width="690" data-width="1500" data-height="1000 "> </a> Where data-width and data-height are the image-1.jpg dimensions. I tried to do this through a file, to control the field output: templates/fields/post/body.php But turns out the body comes already formatted from the DB, so I can't override the image display, unless I use some cumbersome str_replaces. Even with this solution, it's impossible to achieve the desired result. Is there any way I can do this through a ProcessWire process? I know it can be done through php, reading the file's header to extract the height and width and then do a str_replace on the body string to insert the desired code. However I'm curious if it can be done in any simpler and more effective way, without having to read the files from disk and do the replaces. Thanks,
  3. Thanks I just added that to my code. Turns out the user name ($page->title) was hiding on a different language. So I guess I'll be using this to make sure it is stored on the default language: $p->title->setLanguageValue('default', $form['name']); However, is it possible for PW to automatically jump to new language?
  4. WAIT!!!! I've got news. After cheking out the reservations closely, I found out that the title is being stored, hidden away on a different language from the default. So it's saved on the right field, but on the wrong language. How come?
  5. I am not using current user or saving any kind of session whatsoever. About the structure, you nailed it. The user gave the same email for the two reservations. If Rick did both the reservations, he inserted the same email, because he doesn't know Xonox' email. So Rick did indeed receive both emails. The variable $form['name'] has the name, or else it wouldn't show up on the sent email. Every other information is saved, just not the $page->title. What does this do?
  6. Ok, let me see if I can shed some light into this. 1. The user name (Rick, for instance), is saved into the "title" field ($page->title); 2. The page name is a microtime to make sure that it is unique ($page->name = microtime()); 3. As for the page_target, it's a hidden field in the form to make sure that the user reservation (Rick) is associated to the right event (Get a Cup of Coffee). Now the problem of not storing the value in the $page-title, only usually happens when the user (Rick) tries to add a friend (Xonox) to the same event (Get a Cup of Coffee) by filling the same form again with his email and phone number. The strangest thing is that neither Rick's or Xonox' name are added to the reservation. However, when Rick gets the two emails, both names are correct.
  7. Hi, I have a site that has events where the users can make a reservation and something really weird is happening. This is the code: $form = array( 'name' => $sanitizer->text($input->post->name), 'email' => $sanitizer->email($input->post->email), 'phone' => $phone, ); $p = new Page(); $p->template = 'reservation'; $p->parent = wire('pages')->get('/agenda/' . $sanitizer->text($input->post->page_target) . '/'); $p->name = microtime(); $p->title = $form['name']; $p->save(); // CODE TO SEND EMAIL BELOW The user path is: 1. User fills the form with name, email, phone and some more information. 2. Form is validated to see if every information is ok. 3. Information is saved into a new page (reservation template). 4. Send email to user. Everything works fine except in one case: When the same user fills the same form more than once (to add reserves for one or more friends), usually using the same number and email, the friend's name is not filled in the "title" field. This seems to be the only field that fails, it shows empty on the backoffice. However, the email sent to the user has the name (using the same $form['name'] variable). Am I missing something?
  8. I eventually change the whole system: 1. Created a template "private_gallery" that has two fields: "login" and "password" (Text). 2. When accessing the private gallery the system checks if user is logged in via cookie. If it is not logged in it shows the login page. The galleries are created by the site master, so I don't think there's a need for the usual security involved on a common password. And I can secure the images for each gallery. Thanks for your help.
  9. Even if I give the user profile-edit permissions, the gallery images are still not available on the site - even if I give the client profile permissions to view the fields. This leads me to think that creating the private_gallery inside the user profile wasn't the best option, despite being very practical. The link I posted first, had some reference to a module that @ryan developed. But that module link isn't working and I can't find anything of that kind in the Modules section. So what's the best approach? Creating a user and a specific gallery page with that user name so that I can validate, as suggested by @onjegolders? if ($user->name === $page->name) { // show all the pictures and other member stuff } else { throw new Wire404Exception(); }
  10. I've tried $config->pagefileSecurePathPrefix = '-'; I get the same results. Can't load the images inside the template. $config->pagefileSecurePathPrefix = 'sec'; I get the same results. Can't load the images inside the template but they're not secure on hotlinking.
  11. Just to make my question clearer, this is the code on the private gallery page: if(!$user->isLoggedin() && count($user->private_gallery)) { ?> <div id="gallery"> <?php foreach($user->private_gallery as $image) { $thumbnail = $image->size(400, 0); echo '<a href="' . $image->url . '"><img src="' . $thumbnail->url . '" /></a>'; } ?> </div> <?php } Shouldn't the user, that it's logged in, have access to the images inside his user?
  12. Thanks... I added this to my config: $config->pagefileSecure = true; $config->pagefileSecurePathPrefix = '.'; This secured the images, however, the gallery stopped working (no images whatsoever). I believe that the reason is this: 1. I have a page with a template called "private_gallery" that can only be viewed by users with the profile "client". 2. However, the client "gallery" is associated to the "user" template, so it's not related to the page in any way. So I'm trying to get to the user gallery, through a different page. How can I do this? Am I missing something? With $image->url, I'm getting the images URL without the "." that secures the folder.
  13. Hi, I'm building a site that has private galleries, according to the input of this topic: The topic is a couple of years old but was enough to get me going. Here's the method I chose: 1. Created an image field called private_gallery; 2. Associated this field to the ProcessWire user template, this way you create a user with password and gallery very easily; 3. Created a gallery template that checks for the user login and displays their gallery. So, what do I need? Everything is working fine, but if I copy the image link and paste it on a non logged in browser, I can see the image. What's the best method to prevent non logged in users from viewing these images?
  14. I've been using PW for quite a while, now, so I would like to give back to the community that helped me so many times. I had this customer that wanted to use the Google Translate API to automatically translate the site, so I built this function that takes advantage of it without the need to use the API on every page cycle. I put it on a file that gets called on the _init.php, so that I can use it on every template. Here it is: <?php function googleAutoTranslate($page, $field) { // Turn off outputFormatting $page->of(false); // Get current language and field content for this language $current_language = wire('user')->language->name; $field_content = $page->getLanguageValue($current_language, $field); // Is there any content for this language? if($field_content != '') { // Do nothing! } else { // No content, lets translate... // Get default language text $text = $page->getLanguageValue('default', $field); // Translate only if there's content in the default language if($text != '') { // Translate it $apiKey = 'YOUR API KEY HERE'; $default_language = 'pt'; // Your default language here! $url = 'https://www.googleapis.com/language/translate/v2?key=' . $apiKey .'&q=' . rawurlencode($text) . '&source=' . $default_language . '&target=' . $current_language; $json = json_decode(file_get_contents($url)); $field_content = $json->data->translations[0]->translatedText; // Save translated text $page->$field->setLanguageValue($current_language, $field_content); $page->save(); } } // Turn on outputFormatting $page->of(true); // Return result return $field_content; } ?> Whenever you use a field on a template that should be auto translated, just call the function with a page object and the field name, like so: echo googleAutoTranslate($page, 'body'); Features: Translation occurs only once per field, so you don't need to keep paying translations (it stores the translation into the field language); You can correct the translation in the admin area and it won't be overwritten; If you need the translation to be made again, just delete the field content in the needed language. For the translation to occur, content must exist in the default language. I had to fight a little to get this working, so I hope this helps anyone, who comes across this particular need. Nice Things To Have If someone wants to give it a shot to make this into a module, please do. It would be nice to have a checkbox "Enable Google auto translate for this field", when you edit a field input features. Don't Spend Too Much Mind you that the Google translate is a payed service! and needs a Credit Card to get it going (even with $300 free credit); With a relatively small site (and the tests made to get this to work) I already spent about 80.000 translated characters = $3, Hope this helps someone!
  15. I also develop like that. I noticed that when I copy the changes to the production server, there's no need to delete the cache. So I'm figuring that it must be some configuration. I haven't had the time to compare both dev and the production servers. If I get to any conclusion, I'll post it.