Jump to content

mr-fan

Members
  • Posts

    848
  • Joined

  • Last visited

  • Days Won

    4

Posts posted by mr-fan

  1. Oh i forgot the used fields you need...a headline field, a page select and a url field for internal and external links - so give this import file a try:

    https://github.com/mr-fan/TextformatterGlossary/blob/master/fields-example.json

    the whole system is very flexible since we use pages.

    for now there 3 different types of the glossary there that will be replaced if you look at the code it is very simple to know whats going on behind:

    //set the replacement depending from the item type
    switch ($entry->glossary_type) {
       case '1': //abbr
            $replacement = '<abbr title="' . $entry->headline . '">' . $term . '</abbr>';
            break;
       case '2': //external link
            $replacement = '<a rel="help" target="blank" href="' . $entry->extern_link . '" data-original-title="' . $entry->headline . '"><span class="fa-globe" aria-hidden="true"></span> ' . $term . '</a>';
            break;
       case '3': //internal link
            //internal link need to get the url
            $internLink  = wire('pages')->get("$entry->page_link");
            $replacement = '<a rel="help" href="' . $internLink->url . '" data-original-title="' . $entry->headline . '">' . $term . '</a>';
            break;
       default:
            $replacement = $term;
    }

    it yould be possible to upscale the textformatter to use for footnotes, remarks or something else...;)

    regards mr-fan

  2. Hi,

    i've a one-man business and a bigger project on the run. A working prototype is already there. A budget pot is collected.
    Project sprecifications is a small webapplication that works as kind of mediation platform for farmers. Usage is limited to bavaria country.
    Customer is a Association for farmers. They will provide this tool to their members to solve some upcoming problems.
    Timeframe is to get a working solution at the end of the year and expand and adjust in the next years with some additional features.

    Since this is not a dead simple website project, i'm searching for a strategic partner for this project.

    Main work would done by me, but i will need assistance and experience in things like projectmanagment, refactoring, consultation and a partner that could take over the project if i become inoperative - there will be a payment only for beeing at standby.

    German language would be prefered but it is no requirement from the customer.

    Please write me a PM if you are wanna know more details.

    Best regards

  3. A Question that is Hook related...since i'm not so familiar with hooks...

    I have a form from template "Entry" with some adress fields....and a checkbox for the creator of an entry to use his default adress in the entry...so the question is

    where or how i have to hook to change some values/fields depending on a checkbox...since all fields are set required.

    I need a hook before processing the form to check if the checkbox == 1 to set the needed adressfield values to the default values from the $user...than process the form inputs...don't know how to start. I've read your example hooks on bitbucket and tried some things but without luck.

    Best Regards mr-fan

  4. Some posts earlier i wrote i will give an detailed example of how you could use the Formhelper Module from pwFoo to create a register form an build the logic yourself if you need more complex setups.

    This is a stripped example from my register.php (please ignore the spelling while i've translated the most parts just quick and dirty for this post...)

    Spoiler
    
    <?php
    //check for login and start with defaul $out
    if($user->isLoggedin()) {
    	$out = headline("Wellcome $user->full_name - Your are already logged in...");
    	//check if entry is active by user role stays "pending" until user_activation and user_confirmation is done
    	if($user->hasRole("pending") && $user->user_confirmation != '') {
    		//success message
    		$out .= message("Registration was successfull","success");
    		//info message if user is not activated
    		$out .= message("Please visit your Mailbox to confirm your emailadress!","info");
    	}
    	if ($user->hasRole("pending") && $user->user_activation != '') {
    		//info message if user is not confirmed
    		$out .= message("Your account was not activated - please wait.","info");
    	}
    	if (!$user->hasRole("pending")) {
    		$session->redirect($pages->get('6737')->url); //redirect to frontend user overview page
    	}
    
    //we are not logged in so show form for registration
    } else {
    	//change headline for the entry
    	$headline = "Register New";
    
    	//load FormHelper to generate the form from the user template
    	$fh = $modules->get('FormHelper');
    	// Template based form, skip fields 'title' and other adminfields, unstyled
    	//....we know how pwFoo's module work
    	// take a look at: https://bitbucket.org/pwFoo/formhelper/wiki/Documentation
    	
    	//special we need to fill the two hash fields in the user we save
    
    	//create confirmation code
    	$p1 = new Password();
    	$hash1 = $p1->randomBase64String(32);
    
    
    	//create activation code
    	$p2 = new Password();
    	$hash2 = $p2->randomBase64String(32);
    
    	//create and show the normal register form....
    
    	//if all form fields are correct validated and checked save the new user with the two hashes...and the role pending
    
    	//you could check now on every page like
    	if($user->hasRole("pending")) {
    		//do something	
    	}
    
    }
    
    //now follows the URL Segment magic
    
    /*
     * We are using URL segments to handle activation and confirmation of new users
     *
     * URL's like http://mysite.com/app/register/URLsegment1/UserID/Hash
     *
     * URL segment 1 = activate or confirm
     * URL segment 2 = User ID
     * URL segment 3 = generated Hash
     *
     */
    
    // we are using 3 URL segment, so send a 404 if there's more than 1
    if($input->urlSegment4) throw new Wire404Exception();
    
    switch ($input->urlSegment1){
      case '':
            // segment 1 is empty so display normal content/register form
            // users could submit the register form and a new user is created two tokens are generated
            // email to the user and to admin
            // user is logged in and can add content - but the content will only published if
            // his two tokens are created on the first and second step to validate his email and activated by an admin
    		$content .= $out;
        break;
    
      case 'confirm':
    		//set headline
    		$headline = "Confirm User";
    
    		//ceck for the user id
    		if ($input->urlSegment2) {
    			if ($input->urlSegment2 == $users->get($input->urlSegment2)->id) {
    
    				//user found so get the right user to var
    				$u = $users->get($input->urlSegment2);
    
    				//check for the hash
    				if ($input->urlSegment3) {
    					if ($input->urlSegment3 == $u->user_activation) {
    
    						//proceed activation of the user account
    
    						//send the admin an email for user activation
    						//confirmation url
    						$confirm_url = $page->httpUrl.'confirm/'.$u->id.'/'.$u->user_confirmation;
    
    						//html email template
    						$emailContentHtml = '<html>
    												<body>
    													<p>My great Message to the Admin with details about the new user!<br>
    													<a href="'.$confirm_url.'">Activate a New User Klick the Link!</a></p>
    												</body>
    											</html>';
    
    						//send mail to the admin from the users select_mr field
    						$mail = wireMail();
    						$mail->to($adminmail);
    						$mail->from($u->email);
    						$mail->fromName($u->full_name);
    						$mail->subject('Activate a new User');
    						$mail->bodyHTML($emailContentHtml);
    						$mail->send();
    
    						//success message showed up if the user klick on the confirmation link
    						$content .= message("You have confirmed your emailadress - the Admin get a email!","success");
    
    						//delete user_activation hash
    						$u->of(false);
    						$u->user_activation = '';
    						$u->save();
    						$u->of(true);
    
    					} else {
    						//hash not found debug only
    						$content .= message("Hash $input->urlSegment3 not found!","danger");
    					}
    				} else {
    					//hash not there debug only
    					$content .= message("Hash not there!","danger");
    				}
    			} else {
    				//user id not found debug only
    				$content .= message("User ID $input->urlSegment2 not found!","danger");
    			}
    		} else {
    			//user id not there debug only
    			$content .= message("Die User ID wurde NICHT angegeben!","danger");
    		}
    
        break;
    
      case 'activate':
    		//set headline
    		$headline = "Activate User";
    
    		//ceck for the user id
    		if ($input->urlSegment2) {
    			if ($input->urlSegment2 == $users->get($input->urlSegment2)->id) {
    
    				//user found so get the right user to var
    				$u = $users->get($input->urlSegment2);
    
    				//check for the hash
    				if ($input->urlSegment3) {
    					if ($input->urlSegment3 == $u->user_confirmation) {
    
    						//proceed activation of the user account
    
    						//send the user an email that his accout is activated and link to login page
    						//html email template
    						$emailContentHtml = '<html>
    												<body>
    													<p>Dear User your account was activated<br>
    													<a href="'.$app_root->httpUrl.'">Go for it...</a></p>
    												</body>
    											</html>';
    
    						//send mail to the admin from the users select_mr field
    						$mail = wireMail();
    						$mail->to($u->email);
    						$mail->from($adminemail);
    						$mail->fromName($adminname);
    						$mail->subject('Activation completed');
    						$mail->bodyHTML($emailContentHtml);
    						$mail->send();
    
    						//success message showed up if the admin klick on the activation link
    						$mr = $u->select_mr->title;
    						$content .= message("The Account is now activated!","success");
    
    						//delete user_activation hash
    						$u->of(false);
    						$u->user_confirmation = '';
    						$u->removeRole('pending');
    						$u->save();
    						$u->of(true);
    
    					} else {
    						//hash not found debug only
    						$content .= message("Hash $input->urlSegment3 not found!","danger");
    					}
    				} else {
    					//hash not there debug only
    					$content .= message("Hash not there!","danger");
    				}
    			} else {
    				//user id not found debug only
    				$content .= message("User ID $input->urlSegment2 not found!","danger");
    			}
    		} else {
    			//user id not there debug only
    			$content .= message("User ID not there","danger");
    		}
        break;
    
      default:
        // Anything else? Throw a 404
        throw new Wire404Exception();
    }

     

    Best Regards mr-fan

    • Like 2
  5. ...if i'm honest i was a little bit overwhelmed and lost, too.

    But for me is not really the platform itself important...ok performance and some things are but the really important thing is....the people who are running this are already here ;)

    And with that community such optical things like the right balanced CSS and colours are only a question of time - to get changed in the right manner and style!

    Since this is more a opinion topic, this is mine. Regards mr-fan

    • Like 2
  6. Ok - now with this last link you made a special xmas present in the middle of june... :frantics:

    Thank you again for your useful hint.

    <ot>...I'm part of this forum for two years, using devns, read every week the interesting topics....and there are still so much hidden goodies </ot>

    best regards mr-fan

    • Like 1
  7. Always like to learn new things about the API... ;)

    but your code gives me a Call to a member function implode() on null error...?

    All sorted out your lession is great...no more need for such a PHP function...and replaced with a onliner + API call on implode()!

    Great thank you very much!!

    $page->yourPageField->implode(', ', 'title');
    
  8. I know this topic is kinda old... ;)

    Since this is a othen find on google search on finding/handling first/last entries i will provide a little snippet that get pagefield titles prepared for needed output.

    Should just stay as very simple example for using first() and last() on this short thread...

    //get the page field titles right with a separating ,
    $titles	= '';
    
    //count if we have more than one page in the page field
    if (count($page->mypagefield) == 1) {
        //we have only one page so get the first page title
        $titles = $page->mypagefield->first()->title;
    } else {
        //we have more pages in the pagefield so lets loop
        foreach ($page->mypagefield as $t) {
            //we need a , after every entry but not in the last one
            if ($t === $page->mypagefield->last()) {
                $titles .= $t->title;
            } else {
                $titles .= $t->title.', ';
            }
        }
    }
    
    //output will be  "title1, title2, title3, lasttitle"
    

    best regards mr-fan

    EDIT: use arjen's example of implode() is in this case much more smarter....but the example above shows how to work with first() and last() so it will stay ;)

    • Like 1
  9. Is there a way to set fields to a global context?

    In fact all fields and values are kind of global....;)

    Adrian has all summarized perfect - create a hidden page call it /settings/ or use a new fieldset tab named settings on the /home/ page and using a init.php is the most easiest way to get there - more complex is to setup your own config vars.

    In Processwire it completly depends on you where you put in data and pull it out - very flexible and at the beginning very overwhelming at least for me.....many options to choose from the start.

    Welcome to forums (this is the place very the options for your get sorted right) ;)

    regards mr-fan

  10. If you take the red pill and go deep down the dark path of using devns....just kidding

    This module is definitive the best way to go http://modules.processwire.com/modules/process-wire-upgrade/

    (Since every week there is a new dev version - upgrading with the module is a very easy thing and you could complete roll back.)

    Using the actual devns for a upcoming project and i think i'll be finished if the 3.x stable is there - then i will upgrade to stable and leave it on this version until i need other features or have a problem...but that are just my thoughts.

    regards mr-fan

    • Like 1
  11. My favorite since years is http://komodoide.com/komodo-edit/

    Had all i need to work for my simple dev skills.... ;)

    together with the AutoCode addon i could setup PW and own functions like this and use it with autocompletion:

    $pages->find('[[%tabstop:selector]]');
    

    entering pfind + TAB gets me the whole snippet...everything else like ftp, projectmanagment, autocompletion, todo lists (file/project), commandline, diff, is there...and it is much more faster than other IDE's and has not so much localisation problems like Atom or Brackets with german keyboard layout...

  12. Thank you for your hint...but i'm a just a poor spare time programmer...so very often in the late evening i don't get things sorted right :blush:

    It happens often that if i hit the "Post" button i change my mind and get the solution by my self.... :ph34r:

    $form->get("somefield")->required = true;
    // add only CSS class required to the field so simple get the "*"  - NOT change the form processing/handling like
    // you set the field to required in the admin>field>settings!!
    

    Basic problem was the pass (password) field from the user template....in the admin i don't wanna change it to be required so i have to fill in on every change of the other user fields....and i have frontend forms to edit users profile...so on this frontend stuff i have to check for this field myself on processing and all is good.

    // get the input values for processing
    $email = $form->fhValue("email", "email");
    $password = $form->fhValue("pass", "text");
    
    // check for email duplication
    if (email_valid($email) == true) {
        // email exists
        $out .= message("email exists","danger");
    } elseif ($password == ''){
        // no password is there
        $out .= message("forgot to enter password","danger");
    } else {
    //...
    // all is there so go process form
    

    Best regards mr-fan

    BTW i can't say it too often - your modules for Forms are really really great - have you known that the FormHelper Module even renders MapMarker Fields on frontend....usable!!

    • Like 2
  13. Another question on this...if i setup some fields from a template like the user template.

    And i wanna set a field of this form required....i tried this like in forms from API:

    $form->get("pass")->label = "Change Password?";  //works
    $form->get("pass")->required = true;   //works not
    

    How could i achive this or is there something missing in the FormHelper?

    Edit: All is working perfect....it just sets the CSS class to required not the $form input handling so i've to check manually this special fields...;)

    Best regards mr-fan

  14. Using WireSmtp for WireMail so far...so great...my question is more based on the basic WireMail thing i think but i'm not shure:

    using this call:

    $mail = wireMail();
    $mail->to($u->email);
    $subject = '=?UTF-8?B?'.base64_encode('ÖÄÜ ö ä ü ß').'?=';
    $mail->subject($subject);
    $mail->bodyHTML($emailContentHtml);
    $mail->send();
    

    i don't get german umlaute öäüß working in the subject??

    I've read the forum and stackoverflow but this is the only solution everyone points out so i'm a little lost...how to debug or get it work.

    Best regards mr-fan

  15. @pmichaelis + @chugurk

    maybe my answer help both of you...

    i use MapMarker Field only in backend to get lat and long data from adresses and use them with leaflet cluster maps to generate frontend output from the geodata...

    in your main template or header add needed scripts:

    <!-- set extra scripts to load if there was a map on the page -->
    <script type="text/javascript" src="<?php echo $config->urls->templates?>theme/js/jquery.min.js" ></script>
    <script src="<?php echo $config->urls->templates?>theme/js/leaflet.js"></script>
    <script src="<?php echo $config->urls->templates?>theme/js/leaflet.markercluster.js"></script>
    <link rel="stylesheet" href="<?php echo $config->urls->templates?>theme/css/leaflet.css">
    <link rel="stylesheet" href="<?php echo $config->urls->templates?>theme/css/MarkerCluster.css">
    <link rel="stylesheet" href="<?php echo $config->urls->templates?>theme/css/MarkerCluster.Default.css">
    

    in your template to show the map with many markers using marker cluster output you could use something like this:

    //set output
    $map = '';
    $addressPoints = '';
    
    //get all addresspoints for the JS of the MarkerCluster
    $items = $pages->find("template=entry, map!=''");
    foreach ($items as $m) {
    	if  ($m === $items->last()) {
    		$addressPoints .= '['.$m->map->lat.', '.$m->map->lng.', "<a title=\"'.$m->title.'\" href=\"'.$m->url.'\">read more</a>"]';
    	} else {
    		$addressPoints .= '['.$m->map->lat.', '.$m->map->lng.', "<a title=\"'.$m->title.'\" href=\"'.$m->url.'\">read more</a>"],';
    	}
    }
    
            //render cluster map with all items
    	//centered to bavaria lat/long!!
    	//set the needed inline JS for the map content
    	$inlineJS = "
    		<script>
    			var addressPoints = [$addressPoints];
    			var tiles = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
    					maxZoom: 18,
    					attribution: '© <a href=\"http://www.openstreetmap.org/copyright\">OpenStreetMap</a>'
    			}),
    			latlng = L.latLng(48.1835,11.8570);
    
    			var map = L.map('map', {center: latlng, zoom: 8, layers: [tiles]});
    
    			var markers = L.markerClusterGroup();
    
    			for (var i = 0; i < addressPoints.length; i++) {
    				var a = addressPoints[i];
    				var title = a[2];
    				var marker = L.marker(new L.LatLng(a[0], a[1]), { title: title });
    				marker.bindPopup(title);
    				markers.addLayer(marker);
    			}
    
    			map.addLayer(markers);
    		</script>
    		";
    
    	$map .= '<div id="map"></div>';
    	$map .= $inlineJS;
    	$content .= $map;
    

    This should render a map like the developer locations map http://directory.processwire.com/map/ with marker clusters...

    for single marker output there should be a lot of information in the topic if you search or read for it....;)

    https://processwire.com/talk/topic/9711-map-marker-map/page-2#entry18338

    https://processwire.com/talk/topic/9711-map-marker-map/page-2#entry21061

    https://processwire.com/talk/topic/9711-map-marker-map/page-3#entry28913

    since post #98 you could use MarkupGoogleMap too render a map on frontend:

    https://processwire.com/talk/topic/9711-map-marker-map/page-5#entry41984

    please read carefully before asking and provide code examples if you get stucked....

    best regards mr-fan

    • Like 5
  16. Here is a little trick how a user the user template to manage things like a /profile/ page to frontend edit a users profile and this could be easy used for a own register logic and let the new user fill in all needed fields....the logic could be implemented via URL segments:

    //load module
    $fh = $modules->get('FormHelper');
    // Template based form, skip fields 'title' and other adminfields, unstyled
    $form = $fh->create($templates->get('user'), array(
    	'notifications',
    	'admin_theme',
    	'language',
    	'roles',
    	'user_email',  //this is where we fill a created token/hash to register the user and verifie via emaillink...
    	'confirm'  //confirm link for an admin to set user created stuff puplic
    ));
    

    and in your template you could use URL segements for very simple or complex logic on registration - in my case i need to register a user but hide his content until an admin activated the user...email from the user itself should have to be validated, too so i've to build my own code here...since i wanna stick to just email + password and let the username created automatical in the background...this is just the basic for such a template nothing fancy here - maybe i wrote a little topic if it is running stable.

    Pseudocode for a template file register.php and URL's like:

    http://mysite.com/app/regsiter/URLsegment1/UserID/Hash

    http://mysite.com/app/register/activate/1235/fb5a44cfc2ecd8b5667a667319b66688

    http://mysite.com/app/register/confirm/1235/d41d8cd98f00b204e9800998ecf8427e

    // we are using 3 URL segment, so send a 404 if there's more than 1
    if($input->urlSegment4) throw new Wire404Exception();
    
    switch ($input->urlSegment1){
      case '':
            // segment 1 is empty so display normal content/register form
            // users could submit the register form and a new user is created two tokens are generated
            // email to the user and to admin
            // user is logged in and can add content - but the content will only published if 
            // his two tokens are created on the first step to validate his email and confirm by an admin
        break;
    
      case 'activate':
            if ($input->urlSegment2){
               // check for the user id
               if ($input->urlSegment3 == user_email)
               // check for the email token
    
    	   // user has get an email on submit the register form with a token link
               // and he hit this link so publish/activate the user and show him a message
               // delete user_email token
        break;
    
      case 'confirm':
            if ($input->urlSegment2){
            // check for the user id
               if ($input->urlSegment2 == confirm){
    	   // the user is confirmed by an admin and his content is published, delete confirm token
        break;
    
      default:
        // Anything else? Throw a 404
        throw new Wire404Exception();
    }
    

    This is just a example to how to rebuild the functions of the EmailValidation module in a flexible way with URL segments and some additional fields on the user template....AND the awesome form module from pwFoo... ;)

    URL segments could setup with an regex in the template settings like this:

    regex:^[0-9]*$      //regex for user id
    regex:^[a-f0-9]{32}$     //reges for a hash/token
    

    If my project is finished i will provide more and detailed examples with templates and FormHelper!

    Best regards mr-fan

    • Like 4
  17. Oh i forgot one little problem...you mentioned....https://processwire.com/talk/topic/9811-frontenduser-login-logout-and-register-users-members/page-6#entry108578

    i changed the module that the registration with emailverification works again:

    // Load the plain / html email templates
    $emailContentHtml =
    '<html>
    	<body>
    		<p>'.$vars['content'].'</p>
    		<!-- empty line and comment only lines works as a linebreak with plain emails -->
    		<p>Internetseite: <strong>'.wire('config')->httpHost.'</strong></p>
    
    		<p>Benutzername: <strong>'.$vars['username'].'</strong><br />
    		Email Adresse: <strong>'.$vars['email'].'</strong></p>
    
    		<p>Freischaltcode: <strong>'.$vars['token'].'</strong></p>
    
    		<p>Link zur Registrierung:<br />
    		<strong>'.$vars['url'].'</strong></p>
    	</body>
    </html>';
    

    so the mailbody is generated directly in the module and not loaded via render->template - i think there is a little change in the 3.x render methode...so it doesn't work?

    @pwFoo i'm glad to help here since i use this module for a bigger project and dig deep into - for now i've a little deadline but after it i could provide some snippets and detailed examples of usage...

    Best regards mr-fan

×
×
  • Create New...