Jump to content

MarkupSEO - The all-in-one SEO solution for ProcessWire.


Nico Knoll

Recommended Posts

7 minutes ago, tpr said:

I guess you could check $page->seo->description and if it's empty, set it to your likings, eg. in ready.php or in your template php file (latter untested).


if($page->seo_description === "") {
	$page->seo_description = 'whatever';
}

 

Thank you for the answer.

The problem is, that i activated the "automatically" method to insert the code on my page. And the module inserts the empty description metatag anyway.

I don't know, if your code example will help me in this case?

Link to comment
Share on other sites

Just fast from mobile....

You have to use a hook on pagesave and check the SEO fields there....I ve some functions for creating keywords and description from some given fields... May tomorow I can post an example...

Link to comment
Share on other sites

On 31.7.2017 at 0:29 PM, tpr said:

It should.

YES! It works!
Thank you very much!!!

I unchecked the option "smart description" an add the code below in my template.

<?
    if($page->seo_description === "") {
       // Remove HTML tags
       $description = strip_tags($page->mytext);

       // Remove linebreaks
       $description = preg_replace( "/\r|\n/", " ", $description );

       // Shorten text
       $description = substr($description, 0, 160)." …";

       // Set new metadescription
       $page->seo_description = $description;
    }
    ?>

 

Link to comment
Share on other sites

Ok great that it works for you....a more complex solution with a hook on saveReady if SEO fields are empty put some own magic in there....if tey not empty do nothing...

functions that i use:

Spoiler

/**
 * Wordlimiter cuts a textarea only after complete words not between
 * used in admin.php for seo function and in some templates
 */
function wordLimiter($str = '', $limit = 200, $endstr = '...'){

	if($str == '') return '';

	if(strlen($str) <= $limit) return $str;

	$out = substr($str, 0, $limit);
	$pos = strrpos($out, " ");
	if ($pos>0) {
		$out = substr($out, 0, $pos);
	}
	$out .= $endstr;
	return $out;

}

/**
 * Alternative with regex for striptags function
 * used in admin.php for seo function and in some templates
 */
function ripTags($string) {

    // ----- remove HTML TAGs -----
    $string = preg_replace ('/<[^>]*>/', ' ', $string);

    // ----- remove control characters -----
    $string = str_replace("\r", '', $string);    // --- replace with empty space
    $string = str_replace("\n", ' ', $string);   // --- replace with space
    $string = str_replace("\t", ' ', $string);   // --- replace with space

    // ----- remove multiple spaces -----
    $string = trim(preg_replace('/ {2,}/', ' ', $string));

    return $string;

}
      
/**
 * Finds all of the keywords (words that appear most) on param $str
 * and return them in order of most occurrences to less occurrences.
 * @param string $str The string to search for the keywords.
 * @param int $minWordLen[optional] The minimun length (number of chars) of a word to be considered a keyword.
 * @param int $minWordOccurrences[optional] The minimun number of times a word has to appear
 * on param $str to be considered a keyword.
 * @param boolean $asArray[optional] Specifies if the function returns a string with the
 * keywords separated by a comma ($asArray = false) or a keywords array ($asArray = true).
 * @return mixed A string with keywords separated with commas if param $asArray is true,
 * an array with the keywords otherwise.
 */
function extractKeywords($str, $minWordLen = 5, $minWordOccurrences = 2, $asArray = false)
{
	function keyword_count_sort($first, $sec)
	{
		return $sec[1] - $first[1];
	}
	$str = preg_replace('/[^\p{L}0-9 ]/', ' ', $str);
	$str = trim(preg_replace('/\s+/', ' ', $str));

	$words = explode(' ', $str);
	$keywords = array();
	while(($c_word = array_shift($words)) !== null)
	{
		if(strlen($c_word) < $minWordLen) continue;

		$c_word = strtolower($c_word);
		if(array_key_exists($c_word, $keywords)) $keywords[$c_word][1]++;
		else $keywords[$c_word] = array($c_word, 1);
	}
	usort($keywords, 'keyword_count_sort');

	$final_keywords = array();
	foreach($keywords as $keyword_det)
	{
		if($keyword_det[1] < $minWordOccurrences) break;
		array_push($final_keywords, $keyword_det[0]);
	}
	return $asArray ? $final_keywords : implode(', ', $final_keywords);
}

 

the hook itself works in admin.php under site/templates/:

Spoiler

/**
 * Hook for changing seo_* fields if empty on Page Publish
 */
$pages->addHookAfter('saveReady', null, 'changeSeoFields');
function changeSeoFields(HookEvent $event) {
    $page = $event->arguments[0];
    //for this template only
    if($page->template == 'artikel'|| $page->template == 'seite') {
        // page is about to be published
        if($page->isChanged('status') && !$page->is(Page::statusUnpublished)) {
            // check if seo_title fields are exist and if they are empty
            if (!$page->seo_title) {
                //get the default value that would used as fallback
                if ($page->headline) {
                    //Headline field is used for seo_title
                    $default_title = ripTags($page->headline);
                } else {
                    //Headline field empty - page title is used
                    $default_title = ripTags($page->title);
                }
                //set seo_title on publishing
                $page->set ('seo_title', $default_title);
            }
            // check if seo_description fields are exist and if they are empty
            if (!$page->seo_description) {
                //get the default value that would used as fallback
                if ($page->kurztext) {
                    $default_desc = ripTags($page->kurztext);
                } else {
                    //is there a main content block as pagetable field pt_inhalt?
                    if(count($page->pt_inhalt)>0) {
                        //get the first text field in the pagetable and use it for the seo description
                        $first_item = $page->pt_inhalt->get("template=part_text|part_text_image_left|part_text_image_right|part_text_spalten");
                        $first_content = ripTags($first_item->text);
                        $default_desc = wordLimiter($first_content, 160);
                    }
                }
                //set seo_description on publishing
                $page->set ('seo_description', $default_desc);
            }
            // check if seo_keywords fields are exist and if they are empty
            if (!$page->seo_keywords) {
                //get the string that should be used to generate automatical keywords for this page
                //we use all textfields in the pagetable from the main content and collect them
                $keyword_texts = '';
                //is there a main content block as pagetable field pt_inhalt?
                if(count($page->pt_inhalt)>0) {
                    foreach ($page->pt_inhalt as $keyword_text) {
                        if ($keyword_text->title) $keyword_texts .= $keyword_text->title;
                        if ($keyword_text->text) $keyword_texts .= $keyword_text->text;
                        if ($keyword_text->text2) $keyword_texts .= $keyword_text->text2;
                        if ($keyword_text->text3) $keyword_texts .= $keyword_text->text3;
                    }
                } else {
                    $keyword_texts = $page->headline.' '.$page->kurztext.' '.$page->title;
                }
                //rip tags
                $keyword_string = ripTags($keyword_texts);

                $default_keywords = extractKeywords($keyword_string);

                //set seo_title on publishing
                $page->set ('seo_keywords', $default_keywords);
            }
        }
    }
}

 

As always it is not the best PHP code since im no professional....but it works for me....if i somedays get some time i could add something like that with optionfields to the module itself. ;)

Best regards mr-fan

  • Like 1
Link to comment
Share on other sites

1 hour ago, mr-fan said:

Ok great that it works for you....a more complex solution with a hook on saveReady if SEO fields are empty put some own magic in there....if tey not empty do nothing...

functions that i use:

  Hide contents


/**
 * Wordlimiter cuts a textarea only after complete words not between
 * used in admin.php for seo function and in some templates
 */
function wordLimiter($str = '', $limit = 200, $endstr = '...'){

	if($str == '') return '';

	if(strlen($str) <= $limit) return $str;

	$out = substr($str, 0, $limit);
	$pos = strrpos($out, " ");
	if ($pos>0) {
		$out = substr($out, 0, $pos);
	}
	$out .= $endstr;
	return $out;

}

/**
 * Alternative with regex for striptags function
 * used in admin.php for seo function and in some templates
 */
function ripTags($string) {

    // ----- remove HTML TAGs -----
    $string = preg_replace ('/<[^>]*>/', ' ', $string);

    // ----- remove control characters -----
    $string = str_replace("\r", '', $string);    // --- replace with empty space
    $string = str_replace("\n", ' ', $string);   // --- replace with space
    $string = str_replace("\t", ' ', $string);   // --- replace with space

    // ----- remove multiple spaces -----
    $string = trim(preg_replace('/ {2,}/', ' ', $string));

    return $string;

}
      
/**
 * Finds all of the keywords (words that appear most) on param $str
 * and return them in order of most occurrences to less occurrences.
 * @param string $str The string to search for the keywords.
 * @param int $minWordLen[optional] The minimun length (number of chars) of a word to be considered a keyword.
 * @param int $minWordOccurrences[optional] The minimun number of times a word has to appear
 * on param $str to be considered a keyword.
 * @param boolean $asArray[optional] Specifies if the function returns a string with the
 * keywords separated by a comma ($asArray = false) or a keywords array ($asArray = true).
 * @return mixed A string with keywords separated with commas if param $asArray is true,
 * an array with the keywords otherwise.
 */
function extractKeywords($str, $minWordLen = 5, $minWordOccurrences = 2, $asArray = false)
{
	function keyword_count_sort($first, $sec)
	{
		return $sec[1] - $first[1];
	}
	$str = preg_replace('/[^\p{L}0-9 ]/', ' ', $str);
	$str = trim(preg_replace('/\s+/', ' ', $str));

	$words = explode(' ', $str);
	$keywords = array();
	while(($c_word = array_shift($words)) !== null)
	{
		if(strlen($c_word) < $minWordLen) continue;

		$c_word = strtolower($c_word);
		if(array_key_exists($c_word, $keywords)) $keywords[$c_word][1]++;
		else $keywords[$c_word] = array($c_word, 1);
	}
	usort($keywords, 'keyword_count_sort');

	$final_keywords = array();
	foreach($keywords as $keyword_det)
	{
		if($keyword_det[1] < $minWordOccurrences) break;
		array_push($final_keywords, $keyword_det[0]);
	}
	return $asArray ? $final_keywords : implode(', ', $final_keywords);
}

 

the hook itself works in admin.php under site/templates/:

  Hide contents

/**
 * Hook for changing seo_* fields if empty on Page Publish
 */
$pages->addHookAfter('saveReady', null, 'changeSeoFields');
function changeSeoFields(HookEvent $event) {
    $page = $event->arguments[0];
    //for this template only
    if($page->template == 'artikel'|| $page->template == 'seite') {
        // page is about to be published
        if($page->isChanged('status') && !$page->is(Page::statusUnpublished)) {
            // check if seo_title fields are exist and if they are empty
            if (!$page->seo_title) {
                //get the default value that would used as fallback
                if ($page->headline) {
                    //Headline field is used for seo_title
                    $default_title = ripTags($page->headline);
                } else {
                    //Headline field empty - page title is used
                    $default_title = ripTags($page->title);
                }
                //set seo_title on publishing
                $page->set ('seo_title', $default_title);
            }
            // check if seo_description fields are exist and if they are empty
            if (!$page->seo_description) {
                //get the default value that would used as fallback
                if ($page->kurztext) {
                    $default_desc = ripTags($page->kurztext);
                } else {
                    //is there a main content block as pagetable field pt_inhalt?
                    if(count($page->pt_inhalt)>0) {
                        //get the first text field in the pagetable and use it for the seo description
                        $first_item = $page->pt_inhalt->get("template=part_text|part_text_image_left|part_text_image_right|part_text_spalten");
                        $first_content = ripTags($first_item->text);
                        $default_desc = wordLimiter($first_content, 160);
                    }
                }
                //set seo_description on publishing
                $page->set ('seo_description', $default_desc);
            }
            // check if seo_keywords fields are exist and if they are empty
            if (!$page->seo_keywords) {
                //get the string that should be used to generate automatical keywords for this page
                //we use all textfields in the pagetable from the main content and collect them
                $keyword_texts = '';
                //is there a main content block as pagetable field pt_inhalt?
                if(count($page->pt_inhalt)>0) {
                    foreach ($page->pt_inhalt as $keyword_text) {
                        if ($keyword_text->title) $keyword_texts .= $keyword_text->title;
                        if ($keyword_text->text) $keyword_texts .= $keyword_text->text;
                        if ($keyword_text->text2) $keyword_texts .= $keyword_text->text2;
                        if ($keyword_text->text3) $keyword_texts .= $keyword_text->text3;
                    }
                } else {
                    $keyword_texts = $page->headline.' '.$page->kurztext.' '.$page->title;
                }
                //rip tags
                $keyword_string = ripTags($keyword_texts);

                $default_keywords = extractKeywords($keyword_string);

                //set seo_title on publishing
                $page->set ('seo_keywords', $default_keywords);
            }
        }
    }
}

 

As always it is not the best PHP code since im no professional....but it works for me....if i somedays get some time i could add something like that with optionfields to the module itself. ;)

Best regards mr-fan

WOW, that seems to be the sophisticated version ... :-)

An optionfiled in the module would be great!!!

Best regards!

 

Link to comment
Share on other sites

  • 2 months later...

Can I revive the subject ? :)

I want to use this module for a website I inherited, (I didn't use the processwire before)

There is one thing that makes me uncertain.

In:  Choose the templates which should get a SEO tab 
There is a note Be careful with this field. If you remove an entry all of it's "seo_*" fields get deleted (including the data).

Is there any risk there

An do I have to type in the Author and Sitename?

2017-10-25_102907.jpg

Link to comment
Share on other sites

4 hours ago, Marudor said:

Is there any risk there

This simply means that if you assign a template that can use the SEO fields and then you actually use them on a page and then remove the template from the list, the SEO fields will be deleted from the template and, therefore, the pages assigned to it.

4 hours ago, Marudor said:

An do I have to type in the Author and Sitename?

I believe the module's <head> markup might require it, so yes, I'd fill those out.

Link to comment
Share on other sites

2 hours ago, Marudor said:

OK thanks

Just to clarify - The author here - means the author of the module or the author of the website  or it doesn't matter what I type in there.

I don't want to blow up the site...:-X

:lol: Author of the site. I think you can exclude it as I'd imagine the module won't include the relevant tag if it hasn't been specified. You'd need to "view source" in your browser to check if everything is okay. As far as I'm concerned, only the site title is important in terms of meta data.

Link to comment
Share on other sites

Ok I have chosen the template to MarkupSEO module.  

I does change the meta description and meta keyword which is very handy.

But it didn't change the meta title tag.

It's still the one withe the suffix added that comes from the homepage title 

Eventhough i have type in the short one Employer branding - pracownik staje się klientem - Poznań, Warszawa

I still have Employer branding - pracownik staje się klientem - Agencja PR Q&A Communications – Poznań, Warszawa

Where is the problem ? Why id doesn't change the title tag????

Link to comment
Share on other sites

2 hours ago, Marudor said:

Ok I have chosen the template to MarkupSEO module.  

I does change the meta description and meta keyword which is very handy.

But it didn't change the meta title tag.

It's still the one withe the suffix added that comes from the homepage title 

Eventhough i have type in the short one Employer branding - pracownik staje się klientem - Poznań, Warszawa

I still have Employer branding - pracownik staje się klientem - Agencja PR Q&A Communications – Poznań, Warszawa

Where is the problem ? Why id doesn't change the title tag????

Changing the title in the SEO tab only affects the SEO title (<meta property="og:title" content="...SEO title...">). Your page title in the browser is the one you set in the <title> tag of your HTML. If you are referring to Google showing the old one, then you will need to wait a while for it to be re-indexed.

Edit: I apologise, it seems I'm incorrect. MarkupSEO will include a <title> tag for you if you fill out "Title Format" in that case, make sure you don't have your own <title> tag as well.

Link to comment
Share on other sites

I tough this is the module to change the meta title tag and meta description tag.

It changes the description and keyword all right...but the meta title  stays the same.

I  have the article title -  Employer branding - pracownik staje się klientem

But I want the meta title Employer branding - pracownik staje się klientem - Poznań, Warszawa

At the moment the meta title on every psgr is a mix of 2  - the article title and the suffix from the homepage title Agencja PR Q&A Communications – Poznań, Warszawa

I have even changed it in the code from 

<title><?php if($page->id > 1) { echo $page->title .' - '; } echo $home->title ?></title>
TO
<title><?php echo $page->title; ?></title>

BUT still the same. The mix of title with the suffix Agencja PR Q&A Communications – Poznań, Warszawa

added to all article titles makes the meta tag title too long. It Is more than 70 characters on every page. which is no good.

Link to comment
Share on other sites

21 hours ago, Marudor said:

<title><?php if($page->id > 1) { echo $page->title .' - '; } echo $home->title ?></title>
TO
<title><?php echo $page->title; ?></title>

BUT still the same.

It sounds like you need to change it somewhere else. Because ProcessWire based sites always depend on the developer to implement the frontend, it can be tricky to find the right piece of code. Have you tried something like  <title>AAAAAA<?php echo $page->title; ?></title> for example? As a last resort I always type in some fake string which can be easily searched. If it is not in the source code of the rendered page then that is not right part of the code to change it. You probably need to dig in more, unfortunately.

Link to comment
Share on other sites

  • 3 months later...

Hello, I found & fixed an issue wich gives you an illegal string offset error in the latest PHP version. (7.1). 

Around line 429 you declare $return = ''; and then fill it up as an array doing $return[$key] = $value; at line 435.

All you got to do is declare $return = array(); instead of $return = ''; and it should be fixed. Filling up an empty string as an array caused the errors. Can you fix this and push it to github? :)

Kind regards,
Jonathan

 

	private function parseCustom($custom) {
		if(trim($custom) == '') return;

		$return = array();
		$lines = explode(PHP_EOL, $custom);
		foreach($lines as $line) {
			list($key, $value) = explode(':=', $line);
			$key = preg_replace('%[^A-Za-z0-9\-\.\:\_]+%', '', str_replace(' ', '-', trim($key)));	
			$value = trim(wire('sanitizer')->text(html_entity_decode($value)));

			$return[$key] = $value;
		}
		
		return $return;
	}

 

  • Thanks 1
Link to comment
Share on other sites

  • 3 weeks later...

Hi,
I'm having a problem with this module. I't installed with Processwire ver3.
The problem is -> on localhost plugin is working fine, but on live server plugin is not working (strange is that it was working fine, but stopped without any reason ):
when i type title, keywords and description and click SAVE, page is reloaded without errors, but i see old entries, so cannot update existing entries.
I was able to edit Title and description, but next attempts fails. So it saves SEO daya randomly, sometimes im able to edit and save, and sometimes it will just return previous values.

Does anybody has this issue ? Thanks.

Actually im seeing this on edit page in SEO TAB

image.png.2c9ee50f8dfef7641101278db0765e35.png

Link to comment
Share on other sites

  • 3 weeks later...

If anyone is interested, I have a new fork of this module available here: https://github.com/adrianbj/MarkupSEO/commits/various-fixes-enhancements

It's very much a work in progress, but it includes several bug fixes and lots of new features. Please read the commit log to learn about what's fixed and what's new.

At the moment you should not upgrade an existing site (new fields won't be created) and probably don't use it on a live site just yet.

It's not well tested at all yet, so use at your own peril :) 

I'd really appreciate any feedback on it.

  • Like 14
  • Thanks 2
Link to comment
Share on other sites

@adrian

Hi Adrian, thank you for the awesome updates and improvements.

I would suggest to take a look on the Canonical link field and make it ready for multi language websites .

Meaning that he can detect if there are any other languages present and canonicalize them properly according to the languages. 

 

  • Like 1
Link to comment
Share on other sites

3 hours ago, B3ta said:

I would suggest to take a look on the Canonical link field and make it ready for multi language websites .

Hi @B3ta - I'm afraid I don't really have time to look into this at the moment. I am extending this module for my needs and I rarely have multi-language websites so it's not high on my list. I am happy to accept PRs though so together we can build a better version of this module. Once we are all happy with the stability/functionality of the new version I'll try contacting Nico to see what we can do about getting it into the main repo. Hope you understand where I am coming from.

  • Like 3
Link to comment
Share on other sites

  • 2 weeks later...
30 minutes ago, neosin said:

@Nico Knoll for the images, it requires a URL; I am curious if I change those to file upload field will it affect the module? just want to confirm before I try, thank you

In my fork (linked above), the field is an images field (for the page specific SEO tab, not the default image).

  • Like 1
Link to comment
Share on other sites

49 minutes ago, adrian said:

In my fork (linked above), the field is an images field (for the page specific SEO tab, not the default image).

thank you, I will check it out now

@adrian I've uninstalled the SEO and installed your version however the SEO image fields still show up as url text fields. Do I need to change the fields to images?

Link to comment
Share on other sites

  • 4 weeks later...

Hi,

EDIT: Found it, change it in the module configuration. Can't be overwritten by field definition.

 

i cannot change the length of the seo_title field. I changed the field max length to 100 but it is still 60 at the input field. i tried to remove the counter to check, does not work. Tried to change the title and description of the field, this works. I'm confused.

 

Thx for any help!

seotitle.jpg

Link to comment
Share on other sites

  • 2 weeks later...
On 3/25/2018 at 8:48 AM, neosin said:

thank you, I will check it out now

@adrian I've uninstalled the SEO and installed your version however the SEO image fields still show up as url text fields. Do I need to change the fields to images?

Sorry I missed this - not getting emails on @ pings anymore. If you upgrade from an old install of this module, you will need to manually change the field type.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Similar Content

    • By monollonom
      PageMjmlToHtml
      Github: https://github.com/romaincazier/PageMjmlToHtml
      Modules directory: https://processwire.com/modules/page-mjml-to-html/
      A module allowing you to write your Processwire template using MJML and get a converted HTML output using MJML API.
      This is considered to be in alpha and as such needs some testing before being used in production!

      About
      Created by Mailjet, MJML is a markup language making it a breeze to create newsletters displayed consistently across all email clients.
      Write your template using MJML combined with Processwire’s API and this module will automatically convert your code into a working newsletter thanks to their free-to-use Rest API.
      Prerequisite
      For this module to work you will need to get an API key and paste it in the module’s configuration.
      Usage
      Once your credentials are validated, select the template(s) in which you’re using the MJML syntax, save and go visualize your page(s) to see if everything’s good. You will either get error/warning messages or your email properly formatted and ready-to-go.
      From there you can copy/paste the raw generated code in an external mailing service or distribute your newsletter using ProMailer.
      Features
      The MJML output is cached to avoid repetitive API calls Not cached if there are errors/warnings Cleared if the page is saved Cleared if the template file has been modified A simple (dumb?) code viewer highlights lines with errors/warnings A button is added to quickly copy the raw code of the generated newsletter Not added if the page is rendered outside of a PageView Only visible to users with the page’s edit permission A shortcut is also added under “View” in the edit page to open the raw code in a new tab Multi-languages support
      Notes
      The code viewer is only shown to superusers. If there’s an error the page will display:
      Only its title for guests Its title and a message inviting to contact the administrator for editors If you are using the markup regions output strategy, it might be best to not append files to preserve your MJML markup before calling the MJML API. This option is available in the module’s settings.
    • By Marco Ro
      Hi guys!
      I'm a bit anxious because this is the first module I present! (beta modulo) But I will finally be able to share something with the community too! :)
      This is a BETA version of the PayPal payment system called: PayPal Commerce Platform.
      It is an advanced system (Business Pro account is needed) that brings various benefits in terms of fees and above all integrates direct payment with credit/debit cards. 
      The module integrates with Padloper 0.0.2, which is the current installation I'm using.
      This system integrates the classic PayPal buy button, the alternative or local payment method and the new payment system: credit/debit cards that doesn't go through the PayPal account. It is a Stripe-style payment, it connects directly with the bank and integrates 3D security validation.
      I say that it is a BETA because this module currently only works with Sandbox account, to put it live you need to change API url manually (manually for the moment).
      Because this module is not ready for live:
      I would like to have your opinion on how I built the module (is the first one I do). I don't want to share something that is not fish but I need a comparison with someone more experienced than me, for be sure that this is the best way to code the module.
      If you want to try this I created a git, you will find all the instructions for installation and correct operation. (Git has a MIT licensed)
      https://github.com/MarcooRo/processwire-PayPal-Commerce-Platform I hope I did something that you guys can like :)
    • By monollonom
      (once again I was surprised to see a work of mine pop up in the newsletter, this time without even listing the module on PW modules website 😅. Thx @teppo !)
      FieldtypeQRCode
      Github: https://github.com/romaincazier/FieldtypeQRCode
      Modules directory: https://processwire.com/modules/fieldtype-qrcode/
      A simple fieldtype generating a QR Code from the public URL of the page, and more.
      Using the PHP library QR Code Generator by Kazuhiko Arase.

      Options
      In the field’s Details tab you can change between .gif or .svg formats. If you select .svg you will have the option to directly output the markup instead of a base64 image. SVG is the default.
      You can also change what is used to generate the QR code and even have several sources. The accepted sources (separated by a comma) are: httpUrl, editUrl, or the name of any text/URL/file/image field.
      If LanguageSupport is installed the compatible sources (httpUrl, text field, ...) will return as many QR codes as there are languages. Note however that when outputting on the front-end, only the languages visible to the user will be generated.
      Formatting
      Unformatted value
      When using $page->getUnformatted("qrcode_field") it returns an array with the following structure:
      [ [ "label" => string, // label used in the admin "qr" => string, // the qrcode image "source" => string, // the source, as defined in the configuration "text" => string // and the text used to generate the qrcode ], ... ] Formatted value
      The formatted value is an <img>/<svg> (or several right next to each other). There is no other markup.
      Should you need the same markup as in the admin you could use:
      $field = $fields->get("qrcode_field"); $field->type->markupValue($page, $field, $page->getUnformatted("qrcode_field")); But it’s a bit cumbersome, plus you need to import the FieldtypeQRCode's css/js. Best is to make your own markup using the unformatted value.
      Static QR code generator
      You can call FieldtypeQRCode::generateQRCode to generate any QR code you want. Its arguments are:
      string $text bool $svg Generate the QR code as svg instead of gif ? (default=true) bool $markup If svg, output its markup instead of a base64 ? (default=false) Hooks
      Please have a look at the source code for more details about the hookable functions.
      Examples
      $wire->addHookAfter("FieldtypeQRCode::getQRText", function($event) { $page = $event->arguments("page"); $event->return = $page->title; // or could be: $event->return = "Your custom text"; }) $wire->addHookAfter("FieldtypeQRCode::generateQRCodes", function($event) { $qrcodes = $event->return; // keep everything except the QR codes generated from editUrl foreach($qrcodes as $key => &$qrcode) { if($qrcode["source"] === "editUrl") { unset($qrcodes[$key]); } } unset($qrcode); $event->return = $qrcodes; })
    • By Sebi
      AppApiFile adds the /file endpoint to the AppApi routes definition. Makes it possible to query files via the api. 
      This module relies on the base module AppApi, which must be installed before AppApiFile can do its work.
      Features
      You can access all files that are uploaded at any ProcessWire page. Call api/file/route/in/pagetree?file=test.jpg to access a page via its route in the page tree. Alternatively you can call api/file/4242?file=test.jpg (e.g.,) to access a page by its id. The module will make sure that the page is accessible by the active user.
      The GET-param "file" defines the basename of the file which you want to get.
      The following GET-params (optional) can be used to manipulate an image:
      width height maxwidth maxheight cropX cropY Use GET-Param format=base64 to receive the file in base64 format.
    • By MarkE
      This fieldtype and inputfield bundle was built for storing measurement values within a field, rendering them in a variety of formats and converting them to other units or otherwise modifying them via the API.
      The API consists of a number of predefined functions, some of which include...
      render() for rendering the measurement object, valueAs() for converting the value to another unit value, convertTo() for converting the whole measurement object to different units, and add() and subtract() for for modifying the stored value by the value (converted as required) in another measurement. In the admin the inputfield includes a checkbox (which can be optionally disabled) for converting values on page save. For an example if a value was typed in as centimeters, the unit was changed to metres, and the page saved with this checkbox selected, said value would be automatically converted so that e.g. 170 cm becomes 1.7 m.

      A simple length field using Fieldtype Measurement and Inputfield Measurement.
      Combination units (e.g. feet and inches) are also supported.
      Please note that this module is 'proof of concept' at the moment - there are limited units available and quite a lot of code tidying to do. More units will be added shortly.
      See the GitHub at https://github.com/MetaTunes/FieldtypeMeasurement for full details and updates.
×
×
  • Create New...