Пример #1
0
 public static function getInstance(&$debug)
 {
     if (self::$instance === NULL) {
         self::$instance = new serendipity_mobile($debug);
     }
     return self::$instance;
 }
 function event_hook($event, &$bag, &$eventData, $addData = null)
 {
     global $serendipity;
     $hooks =& $bag->get('event_hooks');
     if (isset($hooks[$event])) {
         switch ($event) {
             ////////////////////////////////////////////////////////////////////
             // SITEMAP
             ////////////////////////////////////////////////////////////////////
             case 'backend_publish':
             case 'backend_save':
                 if ($this->get_config('sitemap')) {
                     $this->generateSitemap($bag);
                 }
                 return true;
                 break;
         }
     }
     // plugin enabled?
     if (!$this->get_config('enable')) {
         return false;
     }
     // get instance of serendipity_mobile class
     $this->m = serendipity_mobile::getInstance($this->debugItems);
     // mobile device?
     if (!$this->m->isMobileDevice && $_SERVER['HTTP_HOST'] != $this->get_config('sticky_host')) {
         return false;
     }
     if ($this->m->isMobileDevice) {
         $this->debugItems[] = 'Mobile device found';
     }
     if ($this->m->isIPhone) {
         $this->debugItems[] = 'Apple IPhone or IPod Touch device found';
     }
     if ($this->m->isAndroid) {
         $this->debugItems[] = 'Android device found';
     }
     if ($_SERVER['HTTP_HOST'] == $this->get_config('sticky_host')) {
         $this->debugItems[] = 'Sticky host! Outputting mobile markup anyways';
     }
     if (isset($hooks[$event])) {
         switch ($event) {
             ////////////////////////////////////////////////////////////////////
             // FRONTEND
             ////////////////////////////////////////////////////////////////////
             case 'frontend_configure':
                 // redirect? don't loop and don't redirect admin backend
                 if ($this->get_config('redirect') && $this->get_config('redirect_url') != $_SERVER['HTTP_HOST'] && !strstr($_SERVER['REQUEST_URI'], 'serendipity_admin.php')) {
                     header('Status: 302 Found');
                     header('Location: http://' . $this->get_config('redirect_url') . $_SERVER['REQUEST_URI']);
                     exit;
                 }
                 // set template and css to the included style.css - requires the (normally included) xhtml_mp or iphone template from http://c.seo-mobile.de/
                 $this->debugItems[] = 'Charset: ' . LANG_CHARSET;
                 if ($this->m->isIPhone == true) {
                     $template = $this->get_config('iphone_template');
                 } elseif ($this->m->isAndroid == true) {
                     $template = $this->get_config('android_template');
                 } else {
                     $template = $this->get_config('mobile_template');
                 }
                 if (!empty($template)) {
                     $eventData['template'] = $template;
                     $eventData['template_engine'] = $template;
                     $serendipity['smarty_vars']['head_link_stylesheet'] = $serendipity['baseURL'] . 'serendipity.css.php?switch=' . $template;
                     $this->debugItems[] = 'Template changed to: ' . $template;
                 }
                 return true;
                 break;
                 ////////////////////////////////////////////////////////////////////
                 // ENTRIES
                 ////////////////////////////////////////////////////////////////////
             ////////////////////////////////////////////////////////////////////
             // ENTRIES
             ////////////////////////////////////////////////////////////////////
             case 'entry_display':
                 // AJAX Request (IPhone)
                 if ($_SERVER['HTTP_X_XMLHTTPREQUEST']) {
                     $serendipity['smarty']->assign(array('ajax' => 1));
                 } else {
                     $serendipity['smarty']->assign(array('ajax' => 0));
                 }
                 // send content-type xhtml header (not for iphones)
                 if ($this->m->isIPhone == true || $this->m->isAndroid == true) {
                     header('Content-Type: text/html; charset=' . LANG_CHARSET);
                 } else {
                     header('Content-Type: application/xhtml+xml; charset=' . LANG_CHARSET);
                 }
                 // add categories to footer navigation?
                 if ($this->get_config('categories')) {
                     $this->debugItems[] = 'Adding categories to footer navigation';
                     $this->assignCategories($serendipity);
                 }
                 $smallteaser = $this->get_config('smallteaser', true);
                 $template_meta = new serendipity_template_meta($serendipity['template']);
                 $template_supports_extended_articles = $template_meta->supports('ext_article');
                 $article_overview = count($eventData) > 1;
                 foreach ($eventData as $key => $entry) {
                     // get body and extended body
                     $body = $this->cleanupMobileHtml($this->getFieldReference('body', $entry), $serendipity);
                     $extended = $this->cleanupMobileHtml($this->getFieldReference('extended', $entry), $serendipity);
                     if (!$article_overview && !$template_supports_extended_articles) {
                         $body .= $extended;
                     }
                     if ($article_overview && $smallteaser) {
                         if (preg_match('/^(.+?)<\\/p>/', $body, $matches)) {
                             $body = $matches[1] . "</p>";
                         }
                     }
                     // debugging
                     $this->debug($serendipity);
                     // check for caching again
                     if ($eventData[$key]['properties']['ep_cache_body']) {
                         $eventData[$key]['properties']['ep_cache_body'] = $body;
                         $eventData[$key]['properties']['ep_cache_extended'] = $extended;
                     } elseif ($eventData[$key]['ep_cache_body']) {
                         $eventData[$key]['ep_cache_body'] = $body;
                         $eventData[$key]['ep_cache_extended'] = $extended;
                     } else {
                         $eventData[$key]['body'] = $body;
                         $eventData[$key]['extended'] = $extended;
                     }
                     //return true; // do all entries!
                 }
                 break;
         }
     }
 }