Forum Activity for @the-patria-company

PatriaCo
@the-patria-company
12/20/18 08:18:32AM
349 posts

jrCore_is_mobile_device() in module listener


Jamroom Developers

**UPDATE**

I am getting closer!

I have registered my listener:

    jrCore_register_event_listener('jrImage', 'img_src', 'myModule_img_src_listener');

And my function is successfully listening for the event.

Now, I need to run my smarty_function instead. How can I make it run in order to produce the $_data output?

function myModule_img_src_listener($_data, $_user, $_conf, $_args, $event)
{ if(jrCore_is_mobile_device()){ $_data['src'] = '//HOW DO I RUN MY SMARTY_FUNCTION HERE?//'; } return $_data; }





THANKS :)
updated by @the-patria-company: 12/20/18 08:35:37AM
PatriaCo
@the-patria-company
12/19/18 08:24:26PM
349 posts

jrCore_is_mobile_device() in module listener


Jamroom Developers

I am looking for (but can't find) the jrCore_is_mobile_device() function so that I can add it as a part of a module listener function.

Also, what is the best way to add this mobile_device() if statement into a listener?

function myCustomModule_imageDisplay_listener($_data, $_user, $_conf, $_args, $event)
{ // I need to inject this code if the image is being displayed on a mobile device $_rs = array( 'src' => "<amp-img src=\"{$url}\"" . $wid . $hgt . $attrs . ' layout="responsive">' ); return $_rs['src']; }

I currently have the code working in my module, but it requires a template change for every image string. If my module could just listen and replace, it would save me many hours of coding.

Thank you!!
updated by @the-patria-company: 04/13/19 03:31:08PM
PatriaCo
@the-patria-company
12/11/18 08:38:13AM
349 posts

Make Custom Module Pages Searchable


Jamroom Developers

OK, so I have my schema set up and I simply want to add a directory of pages to the datastore. I also want the integrity check to check the directory so that if any changes are made to the module's index.php (such as adding cities) that the datastore will not contain duplicates.

My module's index.php (with the proposed save to datastore function)
function view_myCustomModule_default($_post, $_user, $_conf)
{ switch ($_post['option']) { case'my-custom-module-page-houston': case'my-custom-module-page-chicago': case'my-custom-module-page-new-york': return jrCore_parse_template('my-custom-module-page.tpl', $_rep, 'myCustomModule'); break; } } //------------------------------ // create pages directory in datastore //------------------------------ function view_myCustomModule_create_dir($_post, $_user, $_conf)
{ $_sv = array( 'page' => "{$_conf['jrCore_base_url']}/{$url}/my-custom-module-page-houston", ); $_sv = array( 'page' => "{$_conf['jrCore_base_url']}/{$url}/my-custom-module-page-chicago", ); $_sv = array( 'page' => "{$_conf['jrCore_base_url']}/{$url}/my-custom-module-page-new-york", ); }

Am I going in the right direction? I don't need to "view" the function, but I am not sure of the right syntax to use here. Thanks for the help. :)
updated by @the-patria-company: 12/11/18 08:43:06AM
PatriaCo
@the-patria-company
12/11/18 07:09:38AM
349 posts

Make Custom Module Pages Searchable


Jamroom Developers

Is there a way to add the pages, like a directory, into the datastore for the module?
PatriaCo
@the-patria-company
12/10/18 05:53:47PM
349 posts

Make Custom Module Pages Searchable


Jamroom Developers

When referencing the last entry in this forum post:

https://www.jamroom.net/the-jamroom-network/forum/my_posts/59966/custom-module-pages-in-sitemap

What is the best method I should use to make these pages searchable by jrSearch?
updated by @the-patria-company: 04/20/19 01:26:50PM
PatriaCo
@the-patria-company
12/04/18 01:22:14PM
349 posts

Img Tag Override to Amp-Img


Jamroom Developers

Thank you for the help!

I ended up using a different fundamental approach, but I have it working. :)
PatriaCo
@the-patria-company
11/30/18 12:26:23PM
349 posts

Img Tag Override to Amp-Img


Jamroom Developers

OK, I am really not sure if this is the best strategy, but here is an idea that I would like to get your feedback on:

In my includes.php

function smarty_function_myModule_ampify($params, $smarty)
{ $result = preg_replace('/(<img[^>]+>(?:<\/img>)?)/i', '$1</amp-img>',.$params['html']); echo str_replace('<img', '<amp-img', $result); }

In a template:

{if jrCore_is_mobile_device()}
{myModule_ampify html="
{/if}

My non-ampified code with img tags.

{if jrCore_is_mobile_device()}
"}
{/if}


Will this be too costly on processing speed? I appreciate your help with this.
PatriaCo
@the-patria-company
11/25/18 03:02:05PM
349 posts

Img Tag Override to Amp-Img


Jamroom Developers

GREAT NEWS! I have this first step working. The following code does make the replacement properly.

function ampify($html='') {

    $result = preg_replace('/(<img[^>]+>(?:<\/img>)?)/i', '$1</amp-img>',$html);

    echo str_replace('<img', '<amp-img', $result);
}

$html = <<<EOF
    <p>HELLO, WE ARE CONVERTING AN IMG TAG TO AMP-IMG.</p>
    <p><img src="/gallery-1.jpg" class="img-responsive" width="375px" height="250px" layout="responsive" alt="gallery1"></p>
EOF;

echo ampify($html);

Now, how do I add it to my module so that all the html generated from a series of templates passes through the function?

Currently, I use the jrCore_is_mobile_device "if" statement to replace the header.tpl and meta.tpl as AMP requires a specific set of meta parameters. I am thinking that I need to set up a listener for when the amp-meta.tpl is being used? And then pass the generated html through the function? Am I close?
PatriaCo
@the-patria-company
11/23/18 08:13:42AM
349 posts

Img Tag Override to Amp-Img


Jamroom Developers

I have tried a couple versions, but I am not understanding how to get the $html to pass through the function properly. It keeps breaking and giving me a white page.
PatriaCo
@the-patria-company
11/22/18 06:39:51AM
349 posts

Img Tag Override to Amp-Img


Jamroom Developers

Unfortunately, I am unable to use xdebug because I am doing all my dev on one of our Jamroom Hosting servers. (I want to make sure the environment is exactly the same as our production site). May I ask if my set up is correct? Hypothetically if the function is working correctly then I should just add it to the include.php like this:

/**
 * init
 */
function pcAMP_init(){
    return true;
}


function ampify($html='') {

    # Replace img, audio, and video elements with amp custom elements

    $html = str_ireplace(

        ['<img','<video','/video>','<audio','/audio>'],

        ['<amp-img','<amp-video','/amp-video>','<amp-audio','/amp-audio>'],

        $html

    );

    # Add closing tags to amp-img custom element

    $html = preg_replace('/<amp-img(.*?)\/?>/', '<amp-img$1></amp-img>',$html);

    # Whitelist of HTML tags allowed by AMP

    $html = strip_tags($html,'<h1><h2><h3><h4><h5><h6><a><p><ul><ol><li><blockquote><q><cite><ins><del><strong><em><code><pre><svg><table><thead><tbody><tfoot><th><tr><td><dl><dt><dd><article><section><header><footer><aside><figure><time><abbr><div><span><hr><small><br><amp-img><amp-audio><amp-video><amp-ad><amp-anim><amp-carousel><amp-fit-rext><amp-image-lightbox><amp-instagram><amp-lightbox><amp-twitter><amp-youtube>');

    return $html;
}

updated by @the-patria-company: 11/22/18 06:40:29AM
  5