Jump to content

Frank Vèssia

Members
  • Posts

    584
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by Frank Vèssia

  1. 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?
  2. Tried now with latest commit. It works good now...
  3. 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?
  4. 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...
  5. 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; } } ?>
  6. i copied from here: http://processwire.com/talk/index.php/topic,229.0.html The wrong code appears two times before the screenshots.
  7. 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)
  8. 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
  9. 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...
  10. damn, i need to sleep more at night... thanks
  11. After updating PW from 2.0 to 2.1 i get a strange behavior in api. I cannot add any image except from the admin. I made more test with no luck, this is my code, very simple. $p = $pages->get(6629); $p->setOutputFormatting(false); $p->immagine->add("http://www.9freepictures.com/d/file/art-online/200907/bob-ross-landscape-oil-painting-27-20.jpg"); $p->save; no warning, no error_log, anything...
  12. you are right Adamkiss, putting the sort as last item it works... thanks, it's a bug??
  13. @Ryan: yes pdate is date fieldtype. function listVideo($sort="sort=-pdate",$limit=",limit=20",$cats="",$id=""){ $pages= wire('pages'); $today = strtotime(date('d-m-Y')); $videos=$pages->get(1006)->children("$sort$limit$published$cats$id,published=1,pdate<=$today"); foreach($videos as $video){ $new = ""; $vidtime = $video->pdate; $curtime = date("d-m-Y"); $yesterday = date("d-m-Y", strtotime("yesterday")); if ($vidtime==$curtime || $vidtime==$yesterday){ $new = "<div class='newvid'><span class='label success'>Nuovo</span></div>"; } $thumb = $video->videothumb->first()->size(210,118)->url; $totalthumbs = count($video->videothumb); if ($totalthumbs>1){ foreach ($video->videothumb as $tempthumb){ $thumbtemp=$tempthumb->size(210,118)->url; } $vidid = "id='{$video->id}'"; }else{ $vidid = "id=''"; } $videotitle = ucfirst(substr($video->title,0,43)); echo " <div class='blockvideo'> {$new} <div class='videotitleblock'>{$videotitle}</div> <a href='{$video->url}' class='video'> <img class='thumbnail' src='{$thumb}' {$vidid} alt='{$video->title}'> </a> <div class='fake'><img class='fakethumb' src='{$thumb}' ></div> <div class='videostatblock'>Visite: <span class='visits'>{$video->pageviews}</span> | ".strftime("%d %B %Y",strtotime($video->pdate))."<span class='duration'>{$video->duration}</span></div> </div> "; } }
  14. I have a date field in european format d-m-Y. I want to order my "articles" by this field. I cannot use the created built in field because publisher decide the publish date using this field, but it seems doesn't work using sort=pdate pdate is my date field
  15. Honestly i don't remember but probably i was looking for "custom fields cms" because this WAS the only thing i never found in any other cms. So happy now. ;D
  16. Ryan i got an exception after the upgrade from 2.0 to 2.1, after the admin creation step Exception: Unable to add field '' to Fieldgroup 'annuncio' (in /home/daydule/public_html/wire/core/Fieldgroup.php line 83) This error message was shown because /install.php still exists. Error has been logged.
  17. I have a PW website with thousand of pages and comments. Any comment must the approved by admin and everytime i need to approve a comment of searching for a comment i loose time searching it. Could be a nice thing having an additional main tab on topbar "Comments" for managing, listing editing ecc...
  18. you can leave the title but at least change the name (url)
  19. ops..so i really missed something...sorry for bother you. thanks.
×
×
  • Create New...