Jump to content

Frank Vèssia

Members
  • Posts

    601
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by Frank Vèssia

  1. PW + Bootstrap, perfect couple, used for tens of my websites...i cannot live without them, thanks
  2. Thanks Ryan
  3. I cannot control pagination with role access because those pages are statistics pages and the template is unique. Every user can submit a link, this link will be a pw page. If you are Standard user you cannot see all links submitted (generated pages) because your account is limited in how many links you can see, it's not a question of permissions. So when i render these pages in a list format i want to limit the total pages the pagination calculate, using "limit=10" in selector don't affect the total pages of course. Sorry, i'll try to make a simple example: 100 pages, same template. Using a selector like "limit=10" will return to me 10 pages. I want to show only the first 5 pages to a particular user because that user can see only 50 pages. Something like using first "limit=50" and than again "limit=10" for getting the pagination.... :-\
  4. I have two roles in my website, "standard" and "premium". Standard users can access only to a certain numbers of "reports" rows in a table format, paginated, Premium users can access all report. I want to block the pagination and show only the page numbers for each type of users, now pagination refer to the total pages of a selector. Is there a way to do this?
  5. super!! Really useful
  6. thanks Soma, it works..
  7. I have a publish date field in this format Y-m-d H:i:s Now i want to select pages published today (of course no matter the hour) I'm trying with $today = strtotime(date("Y-m-d")); $items = $pages->find("template=linkmain,publishdate*=$today,sort=-userid"); I get all pages as result, also pages with dirrefent day date...i tried also ^= with the same result...
  8. You have to remove also the default body texts in some pages...
  9. already tried using string.... I guess the problem is the user. If i use this function with current user ($user) it works...
  10. I cannot understand why i can't get role of user. $userid = 40; $role = $roles->get("premium"); $uid = (int) $userid; $u = $users->get($uid); if ($u->hasRole($role)){ ...stuff } i get a fatal error: Method NullPage::hasRole does not exist or is not callable in this context
  11. I really like the design, great job 8)
  12. I've been there ;D It's funny to see a website of a place near home in a growing up community...More european webdesigners are PW addicted Nice job btw...
  13. Thanks Apeisa. It works fine...i didn't know about the shuffle method.
  14. i'm getting this strange behaviour with image getRandom I want to display all images of one field randomly. So i first count my total images and than use getRandom. <?php $tot = count($gallery->images); $gallery = $gallery->images->getRandom($tot); foreach ($gallery as $image){ ... } I always get the same order but if i change the $tot variable with a smaller value (smaller than the total count) it works...
  15. It works, thanks
  16. For adding description to an image from API i use this code but i think it's to tricky because i need to save again the page for adding it.... <?php ... $link->save(); if ($input->post->imageurl){ $link->images->add("..".$input->post->imageurl); $link->save(); if ($input->post->alt){ $link->images->first()->description = $input->post->alt; $link->save(); } } is there an easier way to do that?
  17. Tried now with latest commit. It works good now...
  18. @adamkiss: sure...
  19. Ryan, i tried with latest commit but i get a page name "0". No exception but name of the page is not the title... simple code: <?php $s = new Page(); $s->template = $templates->get("submit"); $s->parent = $pages->get($userid); $s->title = "Submissions"; $s->save(); Maybe because my parent page is an user?
  20. yes Ryan, i know i have to use always "wire", honestly i don't know why in this case i used the default $_REQUEST... . Regarding the closing ?>, of course i wrong copied from my code...
  21. That's my code. I always use jquery for instant registration without refreshing page, so my code is composed of 3 parts. The html form, the javascript that performs the validation (also check if username and email are already used) and the php that performs registration process. After registration user will redirect to profile page with welcome message. There are some code lines you probably don't need but you can easily clean...simple php. Note: because of jquery you cannot have the php code inside PW folders so i have an external folder called "process" with all my php files called by jquery at the same level of "site" folder, in this case "/process/register.php". P.S.: i'm using jquery validate plugin for validation. FORM <script type="text/javascript" src="/site/templates/scripts/register.js"></script> <div class="row"> <div class="span16"> <fieldset> <legend></legend> <form action='/iscrizione/' method='post' id="registerform"> <div class="clearfix"><label for="login_name">Username</label><div class="input"><input type="text" id="login_name" name="login_name" value="" maxlength="50" /></div></div> <div class="clearfix"><label for="login_pass">Password</label><div class="input"><input type="password" id="login_pass" name="login_pass" value="" /></div></div> <div class="clearfix"><label for="confirm_pass">Ripeti password</label><div class="input"><input type="password" name="confirm_pass" value="" /></div></div> <div class="clearfix"><label for="email">Email</label><div class="input"><input type="text" name="email" id="email" value="" maxlength="40" /></div></div> <div class="actions"> <input type="submit" value="Iscriviti" class="btn primary" name="register_submit" id="register_submit" /> </div> </form> </fieldset> </div> </div> JS $(document).ready(function(){ $("#registerform").validate({ debug: false, rules: { login_name: { required: true, minlength: 6, remote: "/process/username.php" }, login_pass: { required: true, minlength: 6 }, confirm_pass: { required: true, minlength: 6, equalTo: "#login_pass" }, email: { required: true, email: true, remote: "/process/emails.php" } }, messages: { login_name: { required: "Inserisci il tuo username", minlength: jQuery.format("Inserisci almeno {0} caratteri"), remote: jQuery.validator.format("Lo username {0} non è disponibile.") }, login_pass: { required: "Inserisci la password", minlength: jQuery.format("Inserisci almeno {0} caratteri") }, confirm_pass: { required: "Ripeti la password", minlength: jQuery.format("Inserisci almeno {0} caratteri"), equalTo: "Le password non sono uguali" }, email: { required: true, email: "Inserisci una email valida", remote: jQuery.validator.format("Questa email è già presente nel nostro database.") }, }, submitHandler: function(form) { $("#register_submit").attr('value','Attendi...'); $("#register_submit").attr('disabled', 'disabled'); $.post('/process/register.php', $("#registerform").serialize(), function(data) { if (data=='success'){ var url = "/mioprofilo/"; $(location).attr('href',url); }else{ $(".span16").prepend( $(data).hide().fadeIn('slow') ); $(".error").fadeOut(5000); $("#register_submit").attr('value','Iscriviti'); $("#register_submit").removeAttr('disabled'); } }); } }); }); PHP <?php require_once('../index.php'); require_once('class.tempmail.php'); $input = wire('input'); $sanitizer = wire('sanitizer'); $roles = wire('roles'); if($input->post->register_submit) { $username = $sanitizer->username($input->post->login_name); $pass = $input->post->login_pass; $email = $sanitizer->email($input->post->email); $u = new User(); $u->name = $username; $u->pass = $pass; $u->email = $email; $u->roles->add($roles->get("guest")); $u->roles->add($roles->get("utente-basic")); // my custom role $u->save(); // i add profile picture to every user after registration using 5 different random avatar images. $pnum = rand(0,5); $profilephoto = wire('config')->paths->root."site/templates/styles/images/noprofile".$pnum.".jpg"; $u->profilephoto->add($profilephoto); $u->profilethumb->add($profilephoto); $u->save(); if (wire('session')->login($username, $pass)){ $array_content[]=array("username", $username); $array_content[]=array("login", $username); $array_content[]=array("password", $pass); $admin_id = "noreply@domain.com"; $user_email = $email; sendingemail_phpmailer($array_content, "register.html","class.phpmailer.php","Sitename",$admin_id,$user_email,"Welcome to website"); print "success"; }else{ print '<div class="alert-message error"> <p>Errore durante la registrazione. Riprova.</p> </div>'; } } ?> Code for checking the existing email (or username, same code, just change variable) <?php require_once('../index.php'); $email = trim(strtolower($_REQUEST['email'])); $sql_check=wire('users')->find("email=$email"); if($sql_check<>""){ echo 'false'; }else{ echo 'true'; } ?> And that's the login HTML FORM <?php if ($session->get("_user_id")){ $session->redirect('/'); } ?> <? include('./head.inc'); ?> <div class="topbar"> <div class="fill"> <div class="container"> <h3><a href="/">Sitename</a></h3> <ul class="nav"> <li class="active"><a href="/">Login</a></li> </ul> </div> </div> </div> <br><br><br> <script type="text/javascript" src="/site/templates/scripts/login.js"></script> <div class="container"> <div class="content"> <div class="page-header"> <h1><?php echo $page->title; ?><small> effettua l'accesso</small></h1> </div> <div class="row"> <div class="span16"> <fieldset id="formlogin"> <legend>Login</legend> <form action='/login/' method='post' id="loginform"> <div class="clearfix"><label for="login_name">Username</label><div class="input"><input type="text" name="login_name" value="" class="required" /></div></div> <div class="clearfix"><label for="login_pass">Password</label><div class="input"><input type="password" name="login_pass" value="" class="required" /></div></div> <div class="actions"> <input type="submit" value="Accedi" class="btn primary" name="login_submit" id="login_submit" /> </div> </form> </fieldset> </div> </div> </div> <? include('./foot.inc'); ?> </div> <!-- /container --> </body> </html> JS $(document).ready(function(){ $("#loginform").validate({ debug: false, rules: { login_name: { required: true }, login_pass: { required: true } }, messages: { login_name: "Inserisci il tuo username", login_pass: "Inserisci la password", }, submitHandler: function(form) { $("#login_submit").attr('value','Sto accedendo...'); $("#login_submit").attr('disabled', 'disabled'); $.post('/process/login.php', $("#loginform").serialize(), function(data) { if (data=='success'){ var url = "/"; $(location).attr('href',url); }else{ $(".span16").prepend( $(data).hide().fadeIn('slow') ); $(".error").fadeOut(5000); $("#login_submit").attr('value','Accedi'); $("#login_submit").removeAttr('disabled'); } }); } }); }); PHP <?php require_once('../index.php'); $input = wire('input'); if($input->post->login_submit) { $name = wire('sanitizer')->username($input->post->login_name); $pass = $input->post->login_pass; if(wire('session')->login($name, $pass)){ print 'success'; }else{ print '<div class="alert-message error"> <p>Dati non validi. Riprova</p> </div>'; } } ?> After registration i send a welcome email. That's the tempmail php that use the well known phpmailer class for sending emails adding templating functionality. You need to download the class.phpmailer.php from the web. <? function sendingemail_phpmailer ($var_array,$template,$phpmailer,$FromName,$From,$to,$Subject,$videolist){ if (!is_array($var_array)){ echo "first variable should be an array. ITS NOT !"; exit; } require_once($phpmailer); $mail = new PHPMailer(); $mail->IsSendmail(); // telling the class to use SMTP $mail->Host = ""; // SMTP server $mail->FromName = $FromName; $mail->Sender = $FromName; $mail->From = $From; $mail->AddAddress($to); $mail->Subject = $Subject; $mail->IsHTML(true); $filename = $template; $fd = fopen ($filename, "r"); $mailcontent = fread ($fd, filesize ($filename)); foreach ($var_array as $key=>$value){ $mailcontent = str_replace("%%$value[0]%%", $value[1],$mailcontent ); } $mailcontent = stripslashes($mailcontent); fclose ($fd); $mail->Body=$mailcontent; if(!$mail->Send()){ echo "Errore durante l'invio del messaggio"; exit; } } ?>
  22. i copied from here: http://processwire.com/talk/index.php/topic,229.0.html The wrong code appears two times before the screenshots.
  23. Ryan, referring to your example in new user system i'm trying to get some users using this code: $role = wire('roles')->get("superuser"); $users = wire('users')->find("role=$role,sort=name"); but i get this strange error: ProcessWire Error:Exception: Field does not exist: role (in /home/videog/public_html/wire/core/PageFinder.php line 244)
  24. thanks. I use a base64 encoding and secret key to generate that code and it always finish with = or double ==. I'ìm using rtrim and it works good...i prefer this solution rather than a GET value
  25. I have a page that i use for embedding a Streamed Malware like youtube, in this format: wwww.domain.com/embed/videoid Videoid is a string i generate crypted (urlSegment) and normally it ends with "=", ex. "/embed/mZ2Xp5g=". Now, the urlSegment doesn't work with this type of string...the problem is the "=". My solution for now is substr the = and add again when i need to decrypt the string but could be nice to have the entire string working...
×
×
  • Create New...