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

2013-06-15 Thread php-general-digest-help

php-general Digest 15 Jun 2013 14:19:19 - 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


--
---BeginMessage---
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.comwrote:

 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---
---BeginMessage---

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, 

Re: [PHP] Detect and Redirect Mobile Users

2013-06-15 Thread Tamara Temple
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!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: AW: AW: [PHP] PHP is Zero

2013-06-15 Thread Tamara Temple
BUSCHKE Daniel daniel.busc...@nextiraone.eu wrote:
 Why is PHP doing that? I know it works as designed and I know it is
 documented like this but that does not mean that it is a good feature,
 does it? So lets talk about the question: Is that behaviour awaited by
 PHP software developers? Is that really the way PHP should work here?
 May we should change that?!

If you've been using PHP since 2000, you probably well know all the
rants there are about how terrible PHP is as a language; this is one of
the big ones people always mention.

An analog to your statement above is This screwdriver is absolute
*bollux* at pounding in nails! Maybe we should change that!?. (In point
of fact, PHP can be seen as a screwdriver that is *astoundingly* capable
of pounding in nails, so the analogy is in kind only, not in fact. In
real fact, PHP is a programmer's wealthy toolkit; not complete by any
means, but tools that will work for most things, *when you know how to
use them*.)

I don't know the reasons why; it's moot to me. The designers of PHP
chose to go that route, it's up to me as a developer to know how the
language works. If I'm insufficiently able to use it without throwing
errors, or without realizing my code is throwing errors, perhaps it
isn't the language's fault, but mine to learn to adapt to it's
quirks. If I am sufficiently fed up with having to adapt to it's quirks,
Then I will find another language to use.

Now, that said, PHP is often some people's first programming language,
and that, IMO, is a serious problem. PHP is full of these sorts of
things that may not help a newbie learn proper software development
skills. I love that people can teach themselves to program; I wouldn't
want to take that away from anyone. And sometimes that leads to
problems, too. Eventually they'll learn, and get better, or they won't,
and probably not make much of a living at it if that's their desire.

When I came up, I was learning how to program in two languages at the
same time (not mixed in the same program; alternating): Pascal and
Lisp. There really could not be two more different languages (and this
was before anyone thought about OO as an actual thing rather than some
loosely associated concepts.) Pascal being strongly typed, Lisp having
no types and no distinction between code and data. I actually learned a
hella lot more working in Lisp than I did working in Pascal. (Not the
least of which was how to make my TAs scratch their heads in confusion.)
But that may just be me, and since it may just be me, I'm not about to
suggest it to anyone else.

Now, the question here may be merely academic (read: somewhat
interesting, but not really that practical). If it is not, however, this
isn't the right forum. Take your question to -dev and see what they
think. I am personally not interested in such a change to the language
at this point. It's bad enough when they roll to a new major release
breaking backwards compatibility. The anger and invective goes on for
years; people quit using PHP altogether because of such things and hold
grudges for years and years.

 Regards
 Daniel


Cheers,
   tamouse__

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] LightBox click detection

2013-06-15 Thread Tamara Temple
Tedd Sperling t...@sperling.com wrote:
 It's Friday so I am allowed to ask odd questions.

W00T! Friday!

 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?

First off, do you have the javascript code available in an unsquished
form? That would mean I could read it.

Not knowing whether your JS code or Lightbox has any hooks that you can
take advantage of, I'd steal the onclick event from those images that
start lightbox, fire off an AJAX request and ignore the return, then
fire the lightbox event handler.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] LightBox click detection

2013-06-15 Thread Tamara Temple
Marc Guay marc.g...@gmail.com wrote:
 $('.lightbox-image-class').click(function(){
 $.post('ajax.php', {click: true});
 });

Do javascript DOM events stack? If they do, this is definitely the
simplest way to go. If they don't, you need to capture the previous
click handler and call it.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] LightBox click detection

2013-06-15 Thread Julian Wanke

They do, afaik...

Am 15.06.2013, 20:11 Uhr, schrieb Tamara Temple tamouse.li...@gmail.com:


Marc Guay marc.g...@gmail.com wrote:

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


Do javascript DOM events stack? If they do, this is definitely the
simplest way to go. If they don't, you need to capture the previous
click handler and call it.




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] LightBox click detection

2013-06-15 Thread Bastien
Sorry 'bout the top post.

That's how I do it. Capture the click event with jquery and Ajax that back to 
the server

Bastien Koert

On 2013-06-15, at 2:07 PM, Tamara Temple tamouse.li...@gmail.com wrote:

 Tedd Sperling t...@sperling.com wrote:
 It's Friday so I am allowed to ask odd questions.
 
 W00T! Friday!
 
 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?
 
 First off, do you have the javascript code available in an unsquished
 form? That would mean I could read it.
 
 Not knowing whether your JS code or Lightbox has any hooks that you can
 take advantage of, I'd steal the onclick event from those images that
 start lightbox, fire off an AJAX request and ignore the return, then
 fire the lightbox event handler.
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php