2014-04-10 2 views
0

나를 믿어, 내가 Modx 및 Stackoverflow 커뮤니티 q를 통해 보았습니다 q & 꽤이 질문에 대한 답변을 찾을 수 있고 거기에 그냥 내가 찾는 대답이 아닌 것 같습니다 어디서나.모바일 특정 페이지로 리디렉션

먼저 Modx Revo CMS를 실행 중이지만이 질문은 모든 CMS에 실제로 적용될 수 있으며 모바일 하위 도메인으로 리디렉션하고 싶지만 특정 페이지로 이동해야합니다. 소셜 미디어 등에 대한 링크를 게시하면 휴대 기기 사용자가 자동으로 해당 페이지의 모바일 담당자에게 리디렉션됩니다. 장치에 따라 템플리트를 변경하는 것은 옵션이 아닙니다.

먼저 당신이 조각을 만든 :

지금 한 번에, brainhandles 뒤에 사람이 COM (매우 명성이 그들에게 간다) 생성, 그것은 간단했다 점 이동식 재전송라는 훌륭한 추가 기능이 있었다 ,

[[!Mobile_redirect? &url=`http://m.demonstrationsite.com/` ]] 

하지만 : 그것은 당신이 머리 섹션 위에 페이지에 스 니펫 호출을 배치 다음

<?php 
    /*  Mobile_redirect 
      01/28/11 1:40 pm cet 
      01/28/11 6:14 am est 
      11/24/09 10:31 am est 

      original code: http://www.brainhandles.com/techno-thoughts/detecting-mobile-browsers 
      usage: call in the top of your template 
      [[!Mobile_redirect? &mID=`1`]] 
      [[!Mobile_redirect? &url=`http://redirectdomain.com`]] 
      [[!Mobile_redirect? &exclude=`iPad`]] 

      link back to main page: 
      add &views=1 to the link 
      ex: <a href="http://yourmaindemonstrationsite.com?views=1">Link Back to Main site</a> 
    */ 

    // set the MODx document ID of the mobile page 
    $mid = isset($mID) ? $mID : ""; 

    // set the url you want to redirect to 
    // http://domain.com or http://sub.domain.com 
    $url = isset($url) ? $url : 'http://m.demonstrationsite.com'; 

    // add any names you want to exclude 
    $exclude = isset($exclude) ? explode(',', $exclude) : array(); 

    if(isset($_GET['views']) || $_SESSION['views'] =='1'){ 
     $_SESSION['views'] = 1; 
    }else{ 
     if(isset($_SERVER["HTTP_X_WAP_PROFILE"]) || preg_match("/wap\.|\.wap/i",$_SERVER["HTTP_ACCEPT"])) { 
      if($mid =="" && $url !=""){ 
       header("Location: ".$url.""); 
      }else{ 
       $goto = $modx->makeUrl($mid); 
       $modx->sendRedirect($goto); 
      } 
     } 
     if(isset($_SERVER["HTTP_USER_AGENT"])){ 
      $uastring = $_SERVER["HTTP_USER_AGENT"]; 
      if(preg_match("/Creative\ AutoUpdate/i",$_SERVER["HTTP_USER_AGENT"])) { 
       return false; 
      } 
      $check_for_mobiles = true; 
      foreach($exclude as $not_mobil){ 
       if(stripos($uastring, $not_mobil) !== false) { 
        $check_for_mobiles = false; 
        break; 
       } 
      } 

      if ($check_for_mobiles == true) { 
       $mobiles = array("webOS","midp", "j2me", "avantg", "iphone", "docomo", "novarra", "palmos", "palmsource", "240x320", "opwv", "chtml", "pda", "windows\ ce", "mmp\/", "blackberry", "mib\/", "symbian", "wireless", "nokia", "hand", "mobi", "phone", "cdm", "up\.b", "audio", "SIE\-", "SEC\-", "samsung", "HTC", "mot\-", "mitsu", "sagem", "sony", "alcatel", "lg", "erics", "vx", "NEC", "philips", "mmm", "xx", "mobi", "panasonic", "sharp", "wap", "sch", "rover", "pocket", "benq", "java", "pt", "pg", "vox", "amoi", "bird", "compal", "kg", "voda", "sany", "kdd", "dbt", "sendo", "sgh", "gradi", "jb", "\d\d\di", "moto"); 
       foreach($mobiles as $mobil){ 
        if(stripos($uastring, $mobil) !== false){ 
         if($mid =="" && $url !=""){ 
          header("Location: ".$url.""); 
         }else{ 
          $goto = $modx->makeUrl($mid); 
          $modx->sendRedirect($goto); 
         } 
         exit; 
        } 
       } 
      } 
     } 
    } 

를 원 Mobile_Redirect 또는 무엇이든 전화 나의 놀람에 나는 나가 나의 가정 페이지 및 모든 내부 페이지 (다른 사람에 1 개의 외침을 두는 경우에) 매력 같이 방향을 바꾸는 일할 것이라는 점을 것을을 발견했다!

[[!Mobile_redirect? &url=`http://m.demonstrationsite.com/` &exclude=`iPad`]] 

[[!Mobile_redirect? &url=`http://m.demonstrationsite.com/[[~[[*id]]]]` &exclude=`iPad`]] 

자, 정말이 완벽는 (원래 코드에서 주석으로) 주요 사이트에 반환 할 수있는 능력이었다에 추가했다, 모든 사람이해야 할 일을했을 그들의 웹 사이트의 메뉴는 아래의 링크를 추가했다 :

http://demonstrationsite.com?views=1 

모든 것이 잘되면 문제가 발생합니까? 음, 추가 기능은 더 이상 brainhandles.com의 사람들이 관리하지 않습니다.

2 년 후에, 나는이 코드의 유지 보수 및 업데이트를 중단하기로 결정했습니다. 나는 현재 그것을 사용하고 있지 않으며, 풍경을 바꾸지 않고 계속 유지하고있는 모든 장치로 분해 검사가 필요하게되었습니다. . 나는 오픈 소스 DetectMobileBrowser.com을 제안했다. 나는를 변경하는 경우에도,

<?php 
    $useragent=$_SERVER['HTTP_USER_AGENT']; 
    if(preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm(os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',$useragent)||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s)|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp(i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac(|\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt(|\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg(g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v)|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v)|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-|)|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i',substr($useragent,0,4))) 
    header('Location: http://demonstrationsite.com/mobile'); 
    ?> 

작동하지만, 그것은 특정 페이지로 리디렉션되지 않습니다

확인은, 멋진, 그래서 나는 DetectMobileBrowser.com에 이상에 가서 PHP 코드를 얻을 위치 :

http://m.demonstrationsite.com/[[~[[*id]]]] 

을 아무리 내가 노력하는 방법, 그것은 단순히 마케팅을위한 소셜 미디어를 활용하려는 경우 좋지 않아 홈 페이지로 리디렉션됩니다 ... 당신은 단순히 보낼 수 없습니다 누군가 기사 더미를 통해 샅샅이 뒤져 볼 수 있습니까?

제 질문은 이것입니다. 큰 애들이 PHP로 놀고있는 곳을 뒤흔들려고 생각하는 프런트 엔드 디자이너로서, 나는 둘을 통합하는 것처럼 보이지 않아서 앞으로 DetectMobileBrowser 업데이트의 코드로 Mobile_redirect 스 니펫을 업데이트 할 수 있습니다. DetectMobileBrowser에서 제공하는 업데이트 된 장치 목록을 유지하고 싶지만 원래의 Brainhandles 코드의 기능을 사용하고 싶습니다.이에

어떤 도움은 매우 매우, 매우, 매우 감사하겠습니다. 지옥, 당신은 내가 논리가 당신에게 빚을 영원히 나를 만들 것이라고 볼 수 있도록 detectmobilebrowser 닷컴 코드 업데이트 Mobile_redirect 조각을 게시 할 수있는 경우에도 나는 즉시 전체 Modx 커뮤니티와 공유 할 것입니다!

건배

+0

http://m.demonstrationsite.com/YourId 'YourId'가 $ mid라고 가정합니다. 그래서,'헤더 ("위치 : http://demonstrationsite.com/$mid");는 놀라 울 일이야' –

답변

0

이 원래 조각을 변경하려면 너무 단단하지 않다. 다시 작성한 버전을 사용해보십시오 :

<?php 
/*  Mobile_redirect 
     01/28/11 1:40 pm cet 
     01/28/11 6:14 am est 
     11/24/09 10:31 am est 

     original code: http://www.brainhandles.com/techno-thoughts/detecting-mobile-browsers 
     usage: call in the top of your template 
     [[!Mobile_redirect? &mID=`1`]] 
     [[!Mobile_redirect? &url=`http://redirectdomain.com`]] 
     [[!Mobile_redirect? &exclude=`iPad`]] 

     link back to main page: 
     add &views=1 to the link 
     ex: <a href="http://yourmaindemonstrationsite.com?views=1">Link Back to Main site</a> 
*/ 

// set the MODx document ID of the mobile page 
$mid = isset($mID) ? $mID : ""; 

// set the url you want to redirect to 
// http://domain.com or http://sub.domain.com 
$url = isset($url) ? $url : 'http://m.demonstrationsite.com'; 

// add any names you want to exclude 
$exclude = isset($exclude) ? explode(',', $exclude) : array(); 

if(isset($_GET['views']) || $_SESSION['views'] =='1'){ 
    $_SESSION['views'] = 1; 
}else{ 
    $useragent=$_SERVER['HTTP_USER_AGENT']; 
    if(preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm(os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',$useragent)||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s)|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp(i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac(|\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt(|\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg(g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v)|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v)|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-|)|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i',substr($useragent,0,4))) { 
     if($mid =="" && $url !=""){ 
      header("Location: ".$url.""); 
     }else{ 
      $goto = $modx->makeUrl($mid); 
      $modx->sendRedirect($goto); 
     } 
    } 
} 
+0

가, 감사합니다, 감사합니다 감사합니다 !!!! 이 크롬 모바일에서 작동하지 않았기 때문에 처음에는 겁했지만, 나는 한 번 역사와 chache, 비올라를 클리어! 매력처럼, 나는 정말로 당신을 충분히 감사 할 수 없다! 오, 그리고 휴대 전화의 귀환 링크도 잘 작동했습니다. – user3520199

+0

p.s. 당신이 알다시피하자, 나는, Modx에서의 사람들을 통해 저를 도운에 대해 알려 코드를 게시, 신용이 때문이었다 신용을주고 얼마나 큰 유래 커뮤니티입니다! – user3520199

+0

당신을 환영합니다!) – Vasis