Jump to content

ankh2054

Members
  • Posts

    85
  • Joined

  • Last visited

Everything posted by ankh2054

  1. Hi all, I am having some problems pulling pages and showing their image field. The code below only shows one page and no other. image field = discuss_image (maximum file allowed = 1) // Pull all discussion pages $discussions = $pages->find("template=discussions"); foreach($discussions as $item) //Load and assign Image $discuss_image = $item->get("discuss_image"); $discuss_logo = $discuss_image->size(200,200, $image_options); $discuss_image_logo .= "<img class='img-rounded img-responsive' src='{$discuss_logo->url}'' alt='{$discuss_image->description}'' />"; //Theme each page echo " <a href='{$item->url}' class='list-group-item'> <div class='media col-md-3'> <figure class='pull-left'> <img class='media-object img-rounded img-responsive' src='{$item->discuss_image}' alt='placehold.it/350x250' > </figure> </div> <div class='col-md-6'> <h4 class='list-group-item-heading'>{$item->title}</h4> <p class='list-group-item-text'>{$item->body}</p> </div> <div class='col-md-3 text-center'> <h2> 14240 <small> votes </small></h2> <button type='button' class='btn btn-default btn-lg btn-block'> Vote Now! </button> <div class='stars'> <span class='glyphicon glyphicon-star'></span> <span class='glyphicon glyphicon-star'></span> <span class='glyphicon glyphicon-star'></span> <span class='glyphicon glyphicon-star'></span> <span class='glyphicon glyphicon-star-empty'></span> </div> <p> Average 4.5 <small> / </small> 5 </p> </div> </a> "; ?> If I have remove the image variables as per below code I get all pages. // Pull all discussion pages $discussions = $pages->find("template=discussions"); foreach($discussions as $item) //Theme each page echo " <a href='{$item->url}' class='list-group-item'> <div class='media col-md-3'> <figure class='pull-left'> <img class='media-object img-rounded img-responsive' src='placehold.it/350x250' alt='placehold.it/350x250' > </figure> </div> <div class='col-md-6'> <h4 class='list-group-item-heading'>{$item->title}</h4> <p class='list-group-item-text'>{$item->body}</p> </div> <div class='col-md-3 text-center'> <h2> 14240 <small> votes </small></h2> <button type='button' class='btn btn-default btn-lg btn-block'> Vote Now! </button> <div class='stars'> <span class='glyphicon glyphicon-star'></span> <span class='glyphicon glyphicon-star'></span> <span class='glyphicon glyphicon-star'></span> <span class='glyphicon glyphicon-star'></span> <span class='glyphicon glyphicon-star-empty'></span> </div> <p> Average 4.5 <small> / </small> 5 </p> </div> </a> "; ?> any ideas I think it has something to do with the maximum file = 1, but when I set it to 0 (array) then I get the following error. Error: Exception: Method Pageimages::size does not exist or is not callable in this context (in /var/www/www.bommachine.co.uk/wire/core/Wire.php line 320)
  2. thanks all I will give t thanks that worked perfectly
  3. Hi Adrian, Thanks for your help, what I would like to happen is the following. If a user not currently logged in tries to access the profile page, it would redirect them to the login page, then once logged in, I would like it to redirect back to profile page. profile.php $requested_pid = (int) $input->get->pid; $t = $pages->get($requested_pid)->path; // if user isn't logged in, forward to login page if(!$user->isLoggedin()) { $session->redirect("/test/"); } login.php $requested_pid = (int) $input->get->pid; $t = $pages->get($requested_pid)->path; //if user not logging if with tmp_pass proceed with standard login try { if($session->login($user, $pass)) { $session->redirect($t); }
  4. thanks Adrian, I have amended my login.php but not sure how I can use the login link in my profile page, as it automatically re-directs a user, instead of the user actually pressing the login page.
  5. Hi all, I am wondering what code to use to redirect to the previous page requested, I have a profile page, which redirects to the login page. But once the use logs in I wold like to redirect back to profile page (or any other page that requires the user to be logged in) Profile.php // if user isn't logged in, forward to login page if(!$user->isLoggedin()) { $session->redirect("/login/"); } Login.php if($session->login($user, $pass)) { $session->redirect($page->path); } The above is wrong I know, but not sure how to get the previous page URL. if I output $page->path I get the login page. thanks
  6. Hi all, Just wondering whether anyone has tried to integrate www.loginradius.com into process wire. Looks very possible, but being a PHP newbie I thought I would ask first, before I venture into the abyss. http://apidocs.loginradius.com/php/quickstart.html thanks Charles
  7. thanks Adrian, I ended doing this which also worked, but am going to change to yours as cleaner. $redname = $p->name; $session->redirect("/discuss/$redname");
  8. thanks, how embarrassing For the redirect, I would like to redirect to the newly created page, $session->redirect("/"); seems to only redirect to my homepage.
  9. Hi all, One problem and one question: Problem: The below code does not update the body field attached to the template (discussions) Question: What type of redirect can I use to redirect session to newly created page after page save. Code // Process new page creation if($input->post->create_submit) { //Sanatize variables taking in the form data $title = $sanitizer->text($input->post->title); $body = $sanitizer->textarea($input->post->body); $p = new Page(); // create new page object $p->template = 'discussions'; // set template $p->parent = wire('pages')->get('/discuss/'); // set the parent $p->title = $title; // set page title (not neccessary but recommended) $P->body = $body; //Set the body $p->save(); } ?> <form class="form-horizontal" action="./" accept-charset="UTF-8" autocomplete="off" method="post"> <div class="form-group"> <label for="inputFullname3" class="col-sm-2 control-label">Title</label> <div class="col-sm-10"> <input type="text" class="form-control" name="title" placeholder="Enter the Title" > </div> </div> <div class="form-group"> <label for="inputEmail3" class="col-sm-2 control-label">Body</label> <div class="col-sm-10"> <textarea name='body' rows='5' cols='45' id='body' placeholder="Your message"></textarea> </div> </div> <button class="btn btn-lg btn-primary" type="submit" name="create_submit" value="create_submit">Create Discussions</button> </form>
  10. thanks for the helpful information
  11. forgot that, but yet that is actually already included. Just wondering whether a user would be able to update someone else's profile?
  12. Hi all, I have created a fronted form to allow user to update their profiles (fields in the user template). It works, but I am sort of wondering what security checks I should put in place to ensure that a user can only update his/her own fields? // if user isn't logged in, forward to login page if(!$user->isLoggedin()) { $session->redirect("/login/"); } //***UPDATE PROFILE***// if($input->post->profile_submit) { //instantiate variables taking in the form data $email = $sanitizer->email($input->post->email); $full_name = $sanitizer->text($input->post->full_name); //Update user details $user->of(false); $user->email = $email; $user->user_full_name = $full_name; $user->save(); $user->of(true); } //***UPDATE PROFILE***// //** Update details form *// <form class="form-horizontal" action="./" accept-charset="UTF-8" autocomplete="off" method="post"> <div> <input type="text" class="form-control" id="inputFullname3" name="full_name" value="<?php echo $user->user_full_name; ?>" > </div> <div> <input type="text" class="form-control" id="inputEmail3" name="email" value="<?php echo $user->email; ?>"> </div> <button class="btn btn-lg btn-primary btn-block" type="submit" name="profile_submit" value="profile_submit">Update Details</button> </form> //** Update details form *//
  13. seems like this is working, but a image with 100x100 was already created so I think that was in the cache.
  14. Hi All, I am probably dong something wrong here, but I am trying to resize images without cropping them, but images are still being cropped even when cropping is set to false. This is actually working. Using the below code: //Load the user via API $u = $users->get($username); //Will be single object of type Pageimage $avatar = $u->avatar; //Set Image array optons $image_options = array( 'cropping' => false, 'quality' => 90 ); //Check if avatar field is empty and assigns default image if ($u->avatar->url){ $thumb = $avatar->size(100,100, $image_options); $avatar_thumb .= "<img class='img-rounded img-responsive' src='{$thumb->url}'' alt='{$avatar->description}'' />"; }
  15. thanks all for the very helpful comments, you guys are really making this CMS amazing. Hopefully one day I will be able to help new users myself. My final code for the avatar display: //Load the user via API $u = $users->get($username); //Will be single object of type Pageimage $avatar = $u->avatar; //Check if avatar field is empty and assigns default image if ($u->avatar->url){ $thumb = $avatar->size(142); $avatar_thumb .= "<img class='img-rounded img-responsive' src='{$thumb->url}'' alt='{$avatar->description}'' />"; } else { $avatar_thumb .= "<img class='img-rounded img-responsive' src='{$config->urls->templates}/styles/images/bom-mashien.png' alt='BOMmachine' />"; } ?> <div class="user-image"> <?php echo $avatar_thumb; ?> </div> Avatar upload Image: // Upload avatar settings $upload_path = $config->paths->assets . "files/avatar_uploads/"; $f = new WireUpload('avatar'); //avatar is the name of the input-file field $f->setMaxFiles(1); $f->setMaxFileSize(3*1024*1024); $f->setOverwrite(true); $f->setDestinationPath($upload_path); $f->setValidExtensions(array('jpg', 'jpeg', 'png', 'gif')); // Process code if form_submit is issued if($input->post->form_submit) { if(!wireMkdir($upload_path)) { throw new WireException("No upload path!"); } $files = $f->execute(); if ($f->getErrors()) { foreach($files as $filename) @unlink($upload_path . $filename); foreach($f->getErrors() as $e) echo $e; } else { $user->of(false); $user->avatar->removeAll(); $user->avatar = $upload_path . $files[0]; $user->save(); $user->of(true); @unlink($upload_path . $files[0]); $session->redirect("/profile/"); } }
  16. Is there a way to remove the existing image attached to that field, because what happens now is that after if a user changes his profile pic with another, it always references the first one. Is there a way to remove the original and replace with with newly uploaded one?
  17. I have done the following as a test and it works. <?php $user->setOutputFormatting(true); $avatar = $user->avatar; if ($avatar->url){ $logo = $avatar->size(20); $avatar_logo .= "<img class='img-rounded img-responsive' src='{$logo->url}'' alt='{$avatar->description}'' />"; } ?> <div class="user-image"> <?php echo $avatar_logo; ?> </div>
  18. Below is link showing the settings for the field, should I be checking anywhere else? http://www.tiikoni.com/tis/view/?id=e8d80f6
  19. thanks, Even though multiple images are stored against the field it only shows the single image using the array.
  20. Maximum files allowed is set to 1 on the actual image field in backend control panel. Plus below: // Upload avatar settings $upload_path = $config->paths->assets . "files/avatar_uploads/"; $f = new WireUpload('avatar'); //avatar is the name of the input-file field $f->setMaxFiles(1); $f->setMaxFileSize(3*1024*1024); $f->setOverwrite(true); $f->setDestinationPath($upload_path); $f->setValidExtensions(array('jpg', 'jpeg', 'png', 'gif')); Again this might not be the right way, but I did not want users to be able to upload multiple pictures at once and overwrite original.
  21. thanks Diogo, I tried that and it throws the following error: Error: Exception: Method Pageimages::size does not exist or is not callable in this context
  22. I ended up going with the isset method. thanks Hope the code makes more sense now. Otherwise ill update. Read more: http://techtalk.virendrachandak.com/php-isset-vs-empty-vs-is_null/#ixzz30uwVmlIV
  23. thanks so much for all the help. I made the code above cleaner and will update once I have implemented the final code.
  24. sorry question no attached still full code
×
×
  • Create New...