Overview

Classes

  • CMLLanguage
  • CMLPost
  • CMLTranslations
  • CMLUtils

Functions

  • cml_dropdown_langs
  • cml_get_browser_lang
  • cml_get_menu
  • cml_get_notice
  • cml_get_the_link
  • cml_is_homepage
  • cml_show_flags
  • Overview
  • Function
  • Tree
  1: <?php
  2: /**
  3:  * Check if current url ( or $url ) is the homepage
  4:  *
  5:  * If is set a static page as homepage, the plugin check if
  6:  * current page is front page or its translation
  7:  *
  8:  * @param string $url - ( optional ) url to check
  9:  * 
 10:  */
 11: function cml_is_homepage( $url = null ) {
 12:   global $wpdb;
 13: 
 14:   if( ! empty( $wpdb ) && method_exists( $wpdb, 'is_category' ) ) {
 15:     if( is_category() || is_archive() ) return false;
 16:   }
 17: 
 18:   //Controllo se è stata impostata una pagina "statica" se l'id di questa è = a quello della statica
 19:   if( cml_use_static_page() ) {
 20:     global $wp_query;
 21:     $static_id = array( get_option( "page_for_posts" ), get_option( "page_on_front" ) );
 22: 
 23:     $lang_id = CMLLanguage::get_current_id();
 24: 
 25:     /*
 26:      * on some site get_queried_object_id isn't available on start
 27:      * and I get:
 28:      * Fatal error: Call to a member function get_queried_object_id() on a non-object
 29:      *
 30:      * So ensure that method exists, otherwise I use get_the_ID() method
 31:      */
 32:     /*
 33:      * If I call get_queried_object_id in the footer can happens that
 34:      * queried_object_id is different from "real" queried_object,
 35:      * so I store that info in $GLOBALS to avoid this problem :)
 36:      */
 37:     if( ! isset( $GLOBALS[ '_cml_get_queried_object_id' ] ) ) {
 38:       if( ! empty( $wpdb ) && method_exists( $wpdb, 'get_queried_object' ) ) {
 39:         $GLOBALS[ '_cml_get_queried_object_id' ] = get_queried_object()->ID;
 40:         $GLOBALS[ '_cml_get_queried_object' ] = get_queried_object();
 41: 
 42:         $the_id = & $GLOBALS[ '_cml_get_queried_object_id' ];
 43:       } else {
 44:         if( is_object( get_post() ) ) {
 45:           $the_id = get_the_ID();
 46:           
 47:           $GLOBALS[ '_cml_get_queried_object_id' ] = $the_id;
 48:         }
 49:       }
 50:     } else {
 51:       $the_id = $GLOBALS[ '_cml_get_queried_object_id' ];
 52:     }
 53: 
 54:     if( ! empty( $the_id ) ) {
 55:       if( in_array( $the_id, $static_id ) ) return true;    //Yes, it is :)
 56: 
 57:       //Is a translation of front page?
 58:       $linked = CMLPost::get_translation( CMLLanguage::get_current_id(), $the_id  );
 59:       if( ! empty( $linked ) ) {
 60:         return in_array( $linked, $static_id );
 61:       }
 62:     }
 63:   }
 64: 
 65:   //I can't use is_home(), because it return empty value, so I have to check
 66:   //it manually
 67:   if( ! empty( $wpdb ) && method_exists( $wpdb, 'is_home' ) ) {
 68:     return is_home();
 69:   }
 70: 
 71:   //Remove language information by url
 72:   CMLUtils::clear_url();
 73: 
 74:   return trailingslashit( CMLUtils::get_clean_url() ) == trailingslashit( CMLUtils::home_url() );
 75: }
 76: 
 77: /**
 78:  * @ignore
 79:  * @internal
 80:  *
 81:  * get page by path
 82:  *
 83:  * On some site I can't use url_to_postid() because
 84:  * $wp_reqruite is empty...
 85:  * 
 86:  */
 87: function cml_get_page_id_by_path($url, $types = null) {
 88:   $url = untrailingslashit( $url );
 89:   $plinks = explode( "/", $url );
 90: 
 91:   if( $types == null ) {
 92:     $types = array_keys( get_post_types() );
 93:   }
 94: 
 95:   $p = cml_get_page_by_path( $url, OBJECT, $types );
 96:   $the_id = is_object( $p ) ? $p->ID : 0;
 97: 
 98:   return $the_id;
 99: }
100: 
101: /**
102:  * @ignore
103:  * @internal
104:  *
105:  * This is modified version of wordpress function get_page_by_path,
106:  * because original one doesn't works correctly for me
107:  *
108:  * @since 2.1.0
109:  * @uses $wpdb
110:  *
111:  * @param string $page_path Page path
112:  * @param string $output Optional. Output type. OBJECT, ARRAY_N, or ARRAY_A. Default OBJECT.
113:  * @param array $post_type Optional. Post type. Default page.
114:  * @return WP_Post|null WP_Post on success or null on failure
115:  */
116: function cml_get_page_by_path($page_path, $output = OBJECT, $post_type = array('page')) {
117:     global $wpdb;
118: 
119:     $page_path = rawurlencode(urldecode($page_path));
120:     $page_path = str_replace('%2F', '/', $page_path);
121:     $page_path = str_replace('%20', ' ', $page_path);
122:     $parts = explode( '/', trim( $page_path, '/' ) );
123:     $parts = array_map( 'esc_sql', $parts );
124:     $parts = array_map( 'sanitize_title_for_query', $parts );
125: 
126:     $in_string = "'". implode( "','", $parts ) . "'";
127:     $post_type_sql = implode( "','", $post_type );
128: //     $wpdb->escape_by_ref( $post_type_sql );
129: 
130:     if( empty( $in_string ) ) {
131:       return;
132:     }
133: 
134:     $query = "SELECT ID, post_name, post_parent, post_type FROM $wpdb->posts WHERE post_name IN ($in_string) AND (post_type IN ( '$post_type_sql' ) ) AND post_status = 'publish'";
135:     $pages = $wpdb->get_results( $query, OBJECT_K );
136:     $revparts = array_reverse( $parts );
137: 
138:     $foundid = 0;
139:     foreach ( (array) $pages as $page ) {
140:         if ( $page->post_name == $revparts[0] ) {
141:             $count = 0;
142:             $p = $page;
143: 
144:             while ( $p->post_parent != 0 && isset( $pages[ $p->post_parent ] ) ) {
145:                 $count++;
146:                 $parent = $pages[ $p->post_parent ];
147:                 if ( ! isset( $revparts[ $count ] ) || $parent->post_name != $revparts[ $count ] )
148:                     break;
149:                 $p = $parent;
150:             }
151: 
152:             //if ( $p->post_parent == 0 && $count + 1 == count( $revparts ) && $p->post_name == $revparts[ $count ] ) {
153:             if ( $p->post_parent == 0 && $p->post_name == $revparts[ $count ] ) {
154:               $foundid = $page->ID;
155:               if ( $page->post_type == $post_type )
156:                   break;
157:             }
158:         }
159:     }
160: 
161:     if ( $foundid )
162:         return get_post( $foundid, $output );
163: 
164:     return null;
165: }
166: 
167: /**
168:  * return link of current page in according to selected $language, so if $result != current language
169:  * this function will return its translation link.
170:  *
171:  * @param stdObject $result - language object ( i.e. CMLLanguage::get_default() ) used to translate current link
172:  * @param boolean $linked - true, return linked translation, false return homepage link
173:  * @param boolean $only_existings - return linked post only if it exists, otherwise return blank link
174:  * @param boolean $queried - use get_queried_object_id instead of get_the_ID
175:  *
176:  * return string
177:  */
178: function cml_get_the_link( $result, $linked = true, $only_existings = false, $queried = false ) {
179:   global $wpCeceppaML, $_cml_settings;
180: 
181:   if( $queried && ( cml_is_homepage() || is_search() ) ) { //&& cml_use_static_page() ) {
182:     //current page is homepage?
183:     $link = CMLUtils::get_home_url( $result->cml_language_slug );
184: 
185:     if( is_search() ) {
186:       if( isset( $_GET[ 's' ] ) ) {
187:         $args[ 's' ] = esc_attr( $_GET[ 's' ] );
188:       }
189: 
190:       if( CMLUtils::get_url_mode() <= PRE_LANG ) {
191:         $args[ 'lang' ] = $result->cml_language_slug;
192:       }
193: 
194:       $link = add_query_arg( $args, trailingslashit( $link ) );
195:     }
196:   } else {
197:     $GLOBALS[ '_cml_force_home_slug' ] = $result->cml_language_slug;
198:     CMLUtils::_set( "_forced_language_slug", $result->cml_language_slug );
199:     CMLUtils::_set( "_forced_language_id", $result->id );
200: 
201:     //I have to force language to $result one
202:     $wpCeceppaML->force_category_lang( $result->id );
203: 
204:     if( $queried ) {
205:       if( empty( $GLOBALS[ '_cml_get_queried_object' ] ) ) {
206:         $GLOBALS[ '_cml_get_queried_object' ] = get_queried_object();
207:       }
208:       $q = & $GLOBALS[ '_cml_get_queried_object' ];
209: 
210:       $is_tag = isset( $q->taxonomy ) && "post_tag" == $q->taxonomy;
211:       if( ! $is_tag ) {
212:         $is_category = isset( $q->taxonomy );
213:       } else {
214:         $is_category = false;
215:       }
216: 
217:       /*
218:        * added for detect woocommerce "shop" page
219:        */
220:       $is_single = apply_filters( 'cml_is_single_page', isset( $q->ID ), $q );
221:       $is_page = $is_single;
222: 
223:       if( $is_single && ! isset( $q->ID ) ) {
224:         $the_id = apply_filters( 'cml_get_custom_page_id', 0, $q );
225:       } else {
226:         $the_id = ( $is_single ) ? $q->ID : 0;
227:       }
228: 
229:       if( empty( $q ) ) {
230:         $is_404 = is_404();
231:       }
232:     } else {
233:       $q = null;
234: 
235:       $is_category = is_category();
236:       $is_single = is_single();
237:       $is_page = is_page();
238:       $the_id = get_the_ID();
239:       $is_404 = is_404();
240:       $is_tag = is_tag();
241:     }
242: 
243:     /* Collego la categoria della lingua attuale con quella della linga della bandierina */
244:     $link = "";
245: 
246:     if( ! in_the_loop() ) {
247:       $lang_id = CMLLanguage::get_current_id();
248:     } else
249:       $lang_id = CMLLanguage::get_id_by_post_id( $the_id );
250: 
251:     /*
252:      * I must check that is_category is false, or wp will display 404
253:      * is_single is true also for category and in this case
254:      * the plugin will return wrong link
255:      */
256:     if( ( ( $is_single || $is_page ) ||  $linked ) && ! $is_category ) {
257:       $linked_id = CMLPost::get_translation( $result->id, $the_id );
258: 
259:       if( ! empty( $linked_id ) ) {
260:         $link = get_permalink( $linked_id );
261:         $link = CMLPost::remove_extra_number( $link, get_post( $linked_id ) );
262: 
263:         if( CMLUtils::_get( '_real_language' ) != CMLLanguage::get_current_id()
264:             && $linked_id == $the_id ) {
265: 
266:           if( CMLUtils::get_url_mode() == PRE_PATH ) {
267:             $link = $wpCeceppaML->convert_url( $link, $result->cml_language_slug );
268:           }
269:         }
270:       }
271:     }
272: 
273:     if( is_archive() && ! $is_category && ! is_post_type_archive() ) {
274:       global $wp;
275: 
276:       $link = trailingslashit( home_url( $wp->request ) );
277: 
278:       if( CMLUtils::get_url_mode() == PRE_NONE ||
279:           CMLUtils::get_url_mode() == PRE_LANG ) {
280:         $link = add_query_arg( array( "lang" => $result->cml_language_slug ), $link );
281:       }
282:     }
283: 
284:     //Collego le categorie delle varie lingue
285:     if( $is_category ) {
286:       if( $queried && isset( $q->term_id ) ) {
287:         $cat = array(
288:                     "term_id" => $q->term_id,
289:                     "taxonomy" => $q->taxonomy,
290:                     );
291:       } else {
292:         $cat = get_the_category();
293:       }
294: 
295:       if( is_array( $cat ) ) {
296:         $cat_id = ( isset( $cat[ 'term_id' ] ) ) ? $cat[ 'term_id' ] : ( $cat[ count($cat) - 1 ]->term_id );
297: 
298:         //Mi recupererà il link tradotto dal mio plugin ;)
299:         CMLUtils::_set( '_force_category_lang', $result->id );
300: 
301:         $link = get_term_link( $cat_id, $cat[ 'taxonomy' ] );
302:         
303:         //if is object, it's an Error
304:         if( is_object( $link ) ) $link = "";
305: 
306:         CMLUtils::_del( '_force_category_lang' );
307:       } //endif;
308: 
309:       if( CMLUtils::get_category_url_mode() == PRE_LANG &&
310:           CMLUtils::get_url_mode() == PRE_NONE ) {
311:         $link = add_query_arg( array( 'lang' => $result->cml_language_slug ), $link );
312:       }
313:     }
314:     
315:     if( $queried && $is_tag ) { //&& false !== strpos( CMLUtils::get_clean_url(), "/tag/" ) ) ) {
316:       if( ! empty( $q ) ) {
317:         $term_id = $q->term_id;
318:       } else {
319:         $term_id = CMLUtils::_get( "_reverted" );
320:       }
321: 
322:       if( ! empty( $term_id ) ) {
323:         CMLUtils::_set( '_force_category_lang', $result->id );
324: 
325:         $link = get_tag_link( $term_id );
326: 
327:         CMLUtils::_del( '_force_category_lang' );
328:       }
329:     }
330: 
331:     if( is_paged() ) {
332:       $link = add_query_arg( array( "lang" => $result->cml_language_slug ) );
333:     }
334: 
335:     unset( $GLOBALS[ '_cml_force_home_slug' ] );
336: 
337:     CMLUtils::_del( "_forced_language_slug" );
338:     CMLUtils::_del( "_forced_language_id" );
339: 
340:     $wpCeceppaML->unset_category_lang();
341: 
342:     /* Controllo se è stata impostata una pagina statica,
343:         perché così invece di restituire il link dell'articolo collegato
344:         aggiungo il più "bello" ?lang=## alla fine della home.
345: 
346:         Se non ho trovato nesuna traduzione per l'articolo, la bandiera punterà alla homepage
347:     */
348:     if( empty( $link ) && ! $only_existings ) {
349:       if( 1 === CMLUtils::_get( "is_crawler" ) ) {
350:         return;
351:       }
352: 
353:       //If post doesn't exists in current language I'll return the link to default language, if exists :)
354:       if( $_cml_settings[ 'cml_force_languge' ] == 1 ) {
355:         /*
356:          * return translation, if exists :)
357:          */
358:         if( is_single() || is_page() ) {
359:           $l = cml_get_linked_post( $the_id, CMLLanguage::get_default_id() );
360:           // if( ! empty( $l ) ) return get_permalink( $l );
361:         }
362: 
363:         /*
364:          * no translation found, and user choosed to force page to flag language,
365:          * I add parameter "lang=##" to url
366:          */
367:         $link = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
368:         if( CMLPost::get_language_by_id( $the_id ) != $result->id ) {
369:           $link = add_query_arg( array( "lang" => $result->cml_language_slug ), $link );
370:         }
371:       } else {
372:         $link = CMLUtils::get_home_url( $result->cml_language_slug );
373:       }
374: 
375:       if( ( $is_tag || ( isset( $is_404 ) && $is_404 ) ) && CMLUtils::get_url_mode() > PRE_LANG ) {
376:         $clean = CMLUtils::get_clean_url();
377:         $url = CMLUtils::home_url();
378:         
379:         //Change slug in url instead of append ?lang arg
380:         $link = str_replace( $url, "", $clean );
381:         $link = CMLUtils::get_home_url( $result->cml_language_slug ) . $link;
382:       }
383:     }
384:     
385: 
386:     $link = apply_filters( 'cml_get_the_link', $link, array(
387:                                                     "is_single" => $is_single,
388:                                                     "is_category" => $is_category,
389:                                                     "is_tag" => $is_tag,
390:                                                     "the_id" => $the_id,
391:                                                     ),
392:                             $q, $result->id );
393: 
394:   }
395: 
396:   return $link;
397: }
398: 
399: /**
400:  * @ignore
401:  * @internal
402:  *
403:  * use static page?
404:  */
405: function cml_use_static_page() {
406:   return (get_option("page_for_posts") > 0) ||
407:       (get_option("page_on_front") > 0);
408: }
409: 
410: /**
411:  * grab browser language
412:  *
413:  * @return string
414:  */
415: function cml_get_browser_lang() {
416:   if( isset( $GLOBALS[ '_browser_lang' ] ) ) return $GLOBALS[ '_browser_lang' ];
417: 
418:   global $wpdb;
419: 
420:   $browser_langs = @explode( ";", $_SERVER['HTTP_ACCEPT_LANGUAGE'] );
421:   $lang = null;
422: 
423:   //Se la lingua del browser coincide con una di quella attuale della pagina, ignoro tutto
424:   foreach( $browser_langs as $blang ) {
425:     @list( $code1, $code2 ) = explode( ",", $blang );
426: 
427:     $locale[] = str_replace( "-", "_", $code1 );
428:     $locale[] = str_replace( "-", "_", $code2 );
429: 
430:     //Per ogni codice che trovo verifico se è gestito, appena ne trovo 1 mi fermo
431:     //Perché il mio browser mi restituisce sia it-IT, che en-EN, quindi mi devo fermare appena trovo un riscontro
432:     //Senno mi ritrovo sempre la lingua en-EN come $browser_langs;
433:     $i = 0;
434:     while( empty( $lang ) && $i < count( $locale ) ) {
435:       $l = $locale[$i];
436:     
437:       if( strlen( $l ) > 2 ) {
438:         $lang = CMLLanguage::get_id_by_locale( $l );
439:       } else {
440:         //Se ho solo 2 caratteri, cerco negli "slug"
441:         $lang = CMLLanguage::get_id_by_slug( $l );
442:       }
443:     
444:       $i++;
445:     } //endwhile;
446: 
447:     if( ! empty ($lang ) ) {
448:       break;
449:     }
450:   }  //endforeach;
451: 
452:   $GLOBALS[ '_browser_lang' ] = $lang;
453: 
454:   return $lang;
455: }
456: 
457: /**
458:  * return post/page notice in selected language
459:  *
460:  * @param sting $lang_slug - language slug
461:  * 
462:  * @return string return translated notice
463:  */
464: function cml_get_notice( $lang ) {
465:   global $wpdb, $wpCeceppaML;
466: 
467:   //$type - type of notice ( post or page )
468:   $type = ( is_single() ) ? "post" : "page";
469: 
470:   $r = CMLTranslations::get( $lang,
471:                             "_notice_$type",
472:                             "N", true, true );
473: 
474:   if( ! empty( $r ) )
475:     return $r;
476:   else
477:     CMLLanguage::get_current()->cml_language;
478: }
479: 
480: /**
481:  * Return flag &lt;ul&gt;&lt;li&gt;....&lt;/li&gt;&lt;/ul&gt; list
482:  *
483:  * @param array $args is parameters list:
484:  *              <ul>
485:  *                <li>
486:  *                  show ( string ) - choose what to display:<br />
487:  *                  <i>default: text</i>
488:  *                </li>
489:  *                <ul>
490:  *                   <li>text: show only language name</li>
491:  *                   <li>slug: show language slug</li>
492:  *                   <li>none: show no text</li>
493:  *               </ul>
494:  *               <li>
495:  *                show_flag ( boolean ) - show flag?<br />
496:  *                <i>default: true</i>
497:  *               </li>
498:  *               <li>size ( string ) - flag size<br />
499:  *                you can use constants:<br />
500:  *                  CML_FLAG_TINY ( 16x11 )<br />
501:  *                  CML_FLAG_SMALL ( 32x23 )<br />
502:  *                  <i>default: CML_FLAG_TINY</i>
503:  *                <ul>
504:  *                  <li>tiny</li>
505:  *                  <li>small</li>
506:  *                </ul>
507:  *               <li>
508:  *                class_name ( string ) - secondary classname to assign to the list
509:  *                <i>default: ""</i>
510:  *                generated &gt;ul&lt; list has primary class "cml_flags", with that parameter you
511:  *                can assign a secondary one.
512:  *               </li>
513:  *               <li>
514:  *                echo ( boolean ) - If true print list, otherwise return string containing generated list<br />
515:  *                <i>default: true</i>
516:  *               </li>
517:  *               <li>
518:  *                linked ( boolean ) - If true flags link to current translation, false will link to homepage<br />
519:  *                <i>default: true</i>
520:  *               </li>
521:  *               <li>
522:  *                only_existings ( boolean ) - show only flags in which current page exists.<br />
523:  *                <i>default: false</i>
524:  *               </li>
525:  *               <li>
526:  *                queried ( boolean ) - use queried object instead of get_the_ID() or other methods, so output will be
527:  *                                      generated in according to main query, not current one.
528:  *                <i>default: false</i>
529:  *               <li>
530:  *              </ul>
531:  */
532: function cml_show_flags( $args ) {
533:   global $wpdb;
534: 
535:   $args = extract( shortcode_atts( array(
536:                       "show" => "text",
537:                       "size" => "tiny",
538:                       "class" => "",
539:                       "image_class" => "",
540:                       "echo" => true,
541:                       "linked" => true,
542:                       "only_existings" => false,
543:                       "sort" => false,
544:                       "queried" => false,
545:                       "show_flag" => true,
546:                       ), $args ) );
547: 
548:   $_cml_settings = & $GLOBALS[ '_cml_settings' ];
549:   $redirect = $_cml_settings[ 'cml_option_redirect' ];
550: 
551:   $results = cml_get_languages( true, false );
552:   $width = ( $size == "tiny" ) ? 16 : 32;
553: 
554:   $r = "<ul class=\"cml_flags $class\">";
555:   
556:   //Post language...
557:   $lang_id = ( ! $sort ) ? -1 : CMLPost::get_language_by_id( get_the_ID() );
558:   $items = array();
559: 
560:   foreach($results as $result) {
561:     $lang = ( $show == "text" ) ? $result->cml_language : "";
562:     $lang = ( $show == "slug" ) ? $result->cml_language_slug : $lang;
563: 
564:     $link = cml_get_the_link( $result, $linked, $only_existings, $queried );
565:     if( empty( $link) ) continue;
566: 
567:     if( $show_flag ) {
568:       $img = sprintf( '<img class="%s %s" src="%s" title="%s" alt="%s" width="%s" />',
569:                      $size, $image_class, CMLLanguage::get_flag_src( $result->id, $size ),
570:                      $result->cml_language,
571:                      sprintf( __( '%1$ flag', 'ceceppaml' ), $result->cml_language_slug ),
572:                      $width );
573:       //$img = "<img class=\"$size $image_class\" src=\"" . cml_get_flag_by_lang_id( $result->id, $size ) . "\" title='$result->cml_language' width=\"$width\"/>";
574:     } else {
575:       $img = "";
576:     }
577: 
578:     $class = ( $result->id == CMLLanguage::get_current_id() ) ? "current" : "";
579:     $li = "<li class=\"$class\"><a href=\"$link\">{$img}{$lang}</a></li>";
580:     if( $sort && is_array( $items ) && $result->id == $lang_id ) {
581:       array_unshift( $items, $li );
582:     } else {
583:       $items[] = $li;
584:     }
585: 
586:   } //endforeach;
587: 
588: 
589:   $r .= join( "\n", $items );
590:   $r .= "</ul>";
591: 
592:   if( $echo ) 
593:     echo $r;
594:   else
595:     return $r;
596: }
597: 
598: /**
599:  * @ignore
600:  * 
601:  * Check if current post is a custom post
602:  */
603: function cml_is_custom_post_type() {
604:   $types = get_post_types( array ( '_builtin' => FALSE ), 'names' );
605:   
606:   if( empty( $types) ) return FALSE;
607: 
608:   $name = get_post_type();
609:   return in_array( $name, $types );
610: }
611: 
612: /**
613:  * @ignore
614:  */
615: function removesmartquotes($content) {
616:   $content = str_replace('&#8220;', '&quot;', $content);
617:   $content = str_replace('&#8221;', '&quot;', $content);
618:   $content = str_replace('&#8216;', '&#39;', $content);
619:   $content = str_replace('&#8217;', '&#39;', $content);
620:  
621:   return $content;
622: }
623: 
624: /**
625:  * @ignore
626:  * 
627:  * http://www.cult-f.net/detect-crawlers-with-php/
628:  *
629:  * Questa funzione server per evitare di reindirizzare o nascondere i post nella lingua differente
630:  * da quella del browser se schi stà visitando il sito è un crawler, al fine di permettere l'indicizzazione di tutti
631:  * gli articoli
632:  *
633:  */
634: function isCrawler()
635: {
636:   global $wp_query;
637:   
638:   if( ! empty( $wp_query ) && $wp_query->is_robots() ) {
639:     CMLUtils::_set( "is_crawler", 1 );
640: 
641:     return true;
642:   }
643:   
644:     $USER_AGENT = $_SERVER['HTTP_USER_AGENT'];
645: 
646:     // to get crawlers string used in function uncomment it
647:     // it is better to save it in string than use implode every time
648:     // global $crawlers
649:     // $crawlers_agents = implode('|',$crawlers);
650:     $crawlers_agents = 'Google|msnbot|Rambler|Yahoo|AbachoBOT|accoona|AcioRobot|ASPSeek|CocoCrawler|Dumbot|FAST-WebCrawler|GeonaBot|Gigabot|Lycos|MSRBOT|Scooter|AltaVista|IDBot|eStyle|Scrubby';
651:  
652:     if ( strpos($crawlers_agents , $USER_AGENT) === false )
653:        return false;
654:     // crawler detected
655:     // you can use it to return its name
656:     /*
657:     else {
658:        return array_search($USER_AGENT, $crawlers);
659:     }
660:     */
661:     return true;
662: }
663: 
664: /**
665:  * return the id of menu to use in according to current language
666:  * return value can be used as wp_nav_menu function.
667:  *
668:  * The plugin automatically switch menu in according to current language,
669:  * you can use this function if automatic switch doesn't works with your theme/framework
670:  * or if you to force a theme.
671:  * 
672:  * @example
673:  * <?php;<br />
674:  *  $menu = cml_get_menu();<br />
675:  *  wp_nav_menu(array('theme_location' => $menu));<br />
676:  * ?>
677:  */
678: function cml_get_menu() {
679:   //Restituisco il nome del menù da utilizzare a seconda della lingua
680:   $lang = cml_get_current_language();
681: 
682:   return "cml_menu_" . $lang->cml_language_slug;
683: }
684: ?>
685: 
API documentation generated by ApiGen 2.8.0