php-general Digest 15 Jun 2013 14:19:19 -0000 Issue 8266

Topics (messages 321401 through 321409):

Re: What is the name of the pattern that will ...
        321401 by: Richard Quadling

Re: Detect and Redirect Mobile Users
        321402 by: Camilo Sperberg
        321403 by: Chirag Vekariya
        321404 by: Marc Guay
        321408 by: Ford, Mike
        321409 by: Tamara Temple

LightBox click detection
        321405 by: Tedd Sperling
        321406 by: Marc Guay
        321407 by: Marc Guay

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
On 13 June 2013 18:38, David Harkness <davi...@highgearmedia.com> wrote:

> Hi Richard,
>
> On Thu, Jun 13, 2013 at 10:16 AM, Richard Quadling <rquadl...@gmail.com>wrote:
>
>> I'm building a class which needs to have certain methods called by the
>> subclass, but the subclass can extend but not obscure/override the
>> behaviour.
>>
>
> This is the Template Method pattern, though in this case you could use a
> Strategy where the specific authentication implementation is in a separate
> class that gets injected into the Auth class. As for your example there a a
> few things I would change.
>
> * The template method that the subclass must implement should not be
> declared by an interface. Interfaces are for declaring public contracts.
> You can simply declare an abstract, protected method in Auth. This is the
> contract that every subclass must fulfill.
>
> * I would avoid reference variables as you've indicated. If you don't want
> to build a data-holder class yet, simply return an array for now. While you
> cannot enforce the return type at parse time, they should be verified with
> unit tests. Unit tests are critical with dynamic languages like PHP and
> Python since runtime is the only way to verify behavior.
>
> Otherwise, your example is spot on, though the name AuthRequestMade
> implies the request has already been made yet I think from your description
> that this method should *make* the actual request. Here's how I would
> write it with the above in place.
>
>     class Auth {
>         public function MakeAuthRequest() {
>             // before
>             $this->MakeAuthRequestImpl(); // Adding "Impl" suffix is a
> common convention
>             // after
>         }
>
>         /**
>          * Make the actual authentication request.
>          *
>          * @return array Must contain keys "state" and "message" to hold
> the result
>          */
>         protected abstract function MakeAuthRequestImpl();
>     }
>
> Peace,
> David
>
>
Excellent advice.

I will be making an extendable data holder class. I'm going to do the sort
of thing Zend_Db does for the adapter/rowset/row classes, allowing an
extended class to supply the corresponding extended adapter/rowset/row
classes. Each of the base classes has a job to do, but they can only
operate in conjunction with an external provider.

Thanks for the pointers.

Richard.

-- 
Richard Quadling
Twitter : @RQuadling
EE : http://e-e.com/M_248814.html
Zend : http://bit.ly/9O8vFY

--- End Message ---
--- Begin Message ---
On Jun 13, 2013, at 15:31, Camille Hodoul <camille.hod...@gmail.com> wrote:

> Hello,
> 
> I stumbled upon this the other day :
> http://mobiledetect.net/
> I haven't tried it yet, since I have my own small user agent parser when I
> need it, but it may help you if it's a pure php solution you're looking for.
> 
> Have a nice day
> 
> 
> 2013/6/13 dealTek <deal...@gmail.com>
> 
>> Hi all,
>> 
>> I'm curious of a simple, common, universal way to detect a mobile user so
>> I can redirect them to a mobile directory...
>> 
>> What is best for this: Javascript - CSS - PHP?
>> 
>> I think for my purposes if I can detect screen size or mobile browser
>> agent - that would be good enough for what I need right now.
>> 
>> Thanks in advance - Dave
>> 
>> 
>> --
>> Thanks,
>> Dave - DealTek
>> deal...@gmail.com
>> [db-3]
>> 
>> 
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>> 
>> 
> 
> 
> -- 
> Camille Hodoul
> http://camille-hodoul.com/

Some time ago, I tested php-mobile-detect and detectmobilebrowsers.com, taking 
the (old) wurfl database (as a reference with a bit less than 15.000 mobile 
devices). Tests came out as follows:

php-mobile-detect: 7 seconds in 15.000 devices, 70% accuracy
detectmobilebrowsers.com: 0.6 seconds in 15.000 devices, 93,5% accuracy

The post I made is in spanish, but could serve as a reference:
http://blog.unreal4u.com/2012/10/detectar-facilmente-un-dispositivo-movil/

As for the OP, I think that the best way would be PHP, because you can do a lot 
more, like not even redirecting the user but rather just load the mobile site 
directly, setting a session value if desktop version is forced or not. This 
way, any links would also be interchangeable, making it easier for you to 
implement specific functionality such as "send link through email" and other 
related things.

Greetings.


--- End Message ---
--- Begin Message ---
Hi,
Post your question to http://answershat.com

On Thu, Jun 13, 2013 at 4:49 AM, dealTek <deal...@gmail.com> wrote:

> Hi all,
>
> I'm curious of a simple, common, universal way to detect a mobile user so
> I can redirect them to a mobile directory...
>
> What is best for this: Javascript - CSS - PHP?
>
> I think for my purposes if I can detect screen size or mobile browser
> agent - that would be good enough for what I need right now.
>
> Thanks in advance - Dave
>
>
> --
> Thanks,
> Dave - DealTek
> deal...@gmail.com
> [db-3]
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
*Thanks & Regards,
Chirag Vekariya.
+91-87582 45922*

--- End Message ---
--- Begin Message ---
http://www.answershat.com/questions/352/How-to-get-rid-of-spam-mail-in-my-mailbox

On 14 June 2013 09:28, Chirag Vekariya <chirag.vekariya...@gmail.com> wrote:
> Hi,
> Post your question to http://answershat.com
>
> On Thu, Jun 13, 2013 at 4:49 AM, dealTek <deal...@gmail.com> wrote:
>
>> Hi all,
>>
>> I'm curious of a simple, common, universal way to detect a mobile user so
>> I can redirect them to a mobile directory...
>>
>> What is best for this: Javascript - CSS - PHP?
>>
>> I think for my purposes if I can detect screen size or mobile browser
>> agent - that would be good enough for what I need right now.
>>
>> Thanks in advance - Dave
>>
>>
>> --
>> Thanks,
>> Dave - DealTek
>> deal...@gmail.com
>> [db-3]
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
>
> --
> *Thanks & Regards,
> Chirag Vekariya.
> +91-87582 45922*

--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Dead Letter.Office [mailto:dead.letter.off...@isam.co.nz]
> Sent: 14 June 2013 05:22
> To: php-gene...@lists.php.net
> 
> http://php.net/manual/en/misc.configuration.php#ini.browscap
> http://tempdownloads.browserscap.com/
> 
> $browser = get_browser(null, TRUE);
> if (isset($browser['ismobiledevice']) && ($browser['ismobiledevice']
>  == TRUE)) {
>     $isMobile = TRUE;
> }
> else {
>      = FALSE;
> }
> unset($browser);

Argh!, Argh!, Argh! -- two of my pet hates in one snippet!

Comparing something ==TRUE is almost always unnecessary, and absolutely always 
when it's used as an element of a Boolean expression: if x evaluates to TRUE, 
x==TRUE is also TRUE, and if it evaluates to FALSE x==TRUE is also FALSE, so 
the comparison is unnecessary, redundant and wasteful. Just use x.

And why use an if test on a Boolean value to see if it's TRUE or FALSE, just so 
you can assign TRUE or FALSE?? Since the thing you're testing has the value you 
want in the first place, just flipping assign it!

  $isMobile = isset($browser['ismobiledevice']) && $browser['ismobiledevice'];

</rant>

Cheers!

Mike

-- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Portland PD507, City Campus, Leeds Metropolitan University,
Portland Way, LEEDS,  LS1 3HE,  United Kingdom
(FROM 21st JUNE: Leslie Silver Building 403a, City Campus, Woodhouse Lane, LS1 
3ES)
E: m.f...@leedsmet.ac.uk     T: +44 113 812 4730





To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

--- End Message ---
--- Begin Message ---
Ford, Mike <m.f...@leedsmet.ac.uk> wrote:
> (someone else wrote:)
> > $browser = get_browser(null, TRUE);
> > if (isset($browser['ismobiledevice']) && ($browser['ismobiledevice'] == 
> > TRUE)) {
> >     $isMobile = TRUE;
> > }
> > else {
> >      = FALSE;

Mike's remarks below notwithstanding, I think something fell off here.

> > }
> > unset($browser);
> 
> Argh!, Argh!, Argh! -- two of my pet hates in one snippet!

Tell us how you really feel, Mike. :))

> Comparing something ==TRUE is almost always unnecessary, and
> absolutely always when it's used as an element of a Boolean
> expression: if x evaluates to TRUE, x==TRUE is also TRUE, and if it
> evaluates to FALSE x==TRUE is also FALSE, so the comparison is
> unnecessary, redundant and wasteful. Just use x.

The only time I'd be looking at whether content of $somearray['somekey']
== TRUE is when it's possible that it may contain something other than
TRUE or FALSE, and somehow my code *cares* whether it does. In this
case, we do not, your rant holds.

> And why use an if test on a Boolean value to see if it's TRUE or
> FALSE, just so you can assign TRUE or FALSE?? Since the thing you're
> testing has the value you want in the first place, just flipping
> assign it!

This is most egregious.

>   $isMobile = isset($browser['ismobiledevice']) && $browser['ismobiledevice'];

This would even be a case where I'd opt for:

    $isMobile = @$browser['ismobiledevice'];

since if it *isn't* set, it's still falsy, with the rather strong caveat
of don't use @ indiscriminantly.

> </rant>

Cheers!

--- End Message ---
--- Begin Message ---
Hi gang:

It's Friday so I am allowed to ask odd questions.

Here's the problem --  I need to count the number of times a user activates a 
LightBox -- how do you do that?

Here's a LightBox Example:

   http://www.webbytedd.com/c2/lightbox/

All the javascript is there (jQuery et al).

Ideally, I would like to have a php/javascript combination that would:

1. Detect when a user clicked the LightBox;
2. Pass that value to PHP so I can keep count.

Any ideas?

Cheers,

tedd

_____________________
t...@sperling.com
http://sperling.com

--- End Message ---
--- Begin Message ---
$('.lightbox-image-class').click(function(){
    $.post('ajax.php', {click: true});
});

and do your DB work in ajax.php

http://api.jquery.com/jQuery.post/

On 14 June 2013 09:52, Tedd Sperling <t...@sperling.com> wrote:
> Hi gang:
>
> It's Friday so I am allowed to ask odd questions.
>
> Here's the problem --  I need to count the number of times a user activates a 
> LightBox -- how do you do that?
>
> Here's a LightBox Example:
>
>    http://www.webbytedd.com/c2/lightbox/
>
> All the javascript is there (jQuery et al).
>
> Ideally, I would like to have a php/javascript combination that would:
>
> 1. Detect when a user clicked the LightBox;
> 2. Pass that value to PHP so I can keep count.
>
> Any ideas?
>
> Cheers,
>
> tedd
>
> _____________________
> t...@sperling.com
> http://sperling.com
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

--- End Message ---
--- Begin Message ---
Also, the docs and functionality for that particular plugin seem a bit
weak.  Maybe there's another one that has a "doneLoadingLightbox"
event that you could hook into and call your ajax script inside of...


On 14 June 2013 10:02, Marc Guay <marc.g...@gmail.com> wrote:
> $('.lightbox-image-class').click(function(){
>     $.post('ajax.php', {click: true});
> });
>
> and do your DB work in ajax.php
>
> http://api.jquery.com/jQuery.post/
>
> On 14 June 2013 09:52, Tedd Sperling <t...@sperling.com> wrote:
>> Hi gang:
>>
>> It's Friday so I am allowed to ask odd questions.
>>
>> Here's the problem --  I need to count the number of times a user activates 
>> a LightBox -- how do you do that?
>>
>> Here's a LightBox Example:
>>
>>    http://www.webbytedd.com/c2/lightbox/
>>
>> All the javascript is there (jQuery et al).
>>
>> Ideally, I would like to have a php/javascript combination that would:
>>
>> 1. Detect when a user clicked the LightBox;
>> 2. Pass that value to PHP so I can keep count.
>>
>> Any ideas?
>>
>> Cheers,
>>
>> tedd
>>
>> _____________________
>> t...@sperling.com
>> http://sperling.com
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>

--- End Message ---

Reply via email to