Share
Share
Facebook Fan Page
Twitter Page
YouTube
Michel Monnard, member of Spanish PGA

Welcome to my Golf School in Majorca

I am a Swiss citizen and work on this beautiful island for nearly 15 years now as a PGA Golf Teaching Professional. My golf school provides modern teaching methods and training aids. Video-analysis during classes is standard. Emphasis is placed on building up a golf swing that is repeatable and consistent. I have specialised in Putting Instruction, being able to offer you the most in-depth putting analysis you have probably seen.

You can opt for working on your ball flight, get your short game sorted, enhance your knowledge about the rules of golf, add mental exercises to your practice and most importantly improve your game out on the golf course.

Our instructional programme is taught on 6 different golf courses on the island. Weekly courses are very popular with visiting guests. 3 hour sessions combine practice on the range with on-course playing lessons.

We can also fit a full set of golf clubs and a putter to you, help you choose the right Wedges and make sure your gear is up to your standard.

We look forward to receiving your request and hopefully we'll enjoy lesson time together soon.

Michel Monnard
Member of the Spanish PGA
Level 2 Accredited Instructor Swash Putting Schools
TPI Certified Golf Fitness Instructor
TPI Certified Junior Coach Level 2

Introductory Courses

Introductory golf classes

Ideal for beginners and those who simply want to see what golf is all about. We offer the 3 hours introductory golf classes which is generally split into around 90 - 120 mins practising on the driving range and then play a few holes on the golf course. This way a golf novice gets the full picture of why a golfer needs to practice to obtain a handicap.

Golf is a very social game. Golf can be played up to higher ages, it can be played alone or with friends. It can be played all over the world and every golf course is different, yet every hole is different. There is plenty of more advantages why golf can also be YOUR game! Come and join us for a fun introductory golf session during your holidays.

Pricing
  • 1 pax 195,- €
  • 2 pax 330,- €
Intensive Instruction golf classes

Intensive instruction golf classes

Ideal for beginners and advanced golf players. We practice 5 days a week, 3 hours daily.

We adapt this course format completely to the golfer's playing level. Two golfers per PGA Professional ensures individual practice and gives golfers enough time to intensively work on their game.

We start on the Driving-Range and work through your individual needs. To end the session, we play a few holes on the golf course. Be it beginner or advanced handicap golfer, these three hours are about your doubts, about your wishes and needs.

Pricing
  • 1 pax 835,- €
  • 2 pax 1240,- €

Included: daily greenfee for 9 holes, 15 hours of instruction, rangeballs, trolley, drinking water, quality golf clubs.

Learn & Play golf instruction

Learn & play golf instruction

Play great golf courses and improve your game at the same time with your teaching professional!

Here we have two options:

1. Light Course

play three rounds of 18 holes on our home course and we help you with a one hour lesson per playing-day to fine tune your game. Greenfees in price included.

Pricing
  • 1 Person 489,- €
  • 2 People 898,- €

2. Complete Version

play five 18-hole-rounds on different golf courses and we add two hours of lessons per playing-day. Greenfees in price included.

Pricing
  • 1 Person 840,- €
  • 2 People 1520,- €
That was a fantastic week with the girls from Germany. All avid golfers by now.

Take your first handicap

For every new golfer it is important to get a handicap. We can help you to prepare for the exams (theory, playing ability exam, driving-range exam) and depending on your country of residence, we can directly do the exams during your holidays. Available for Switzerland and Germany. Other countries on request.

Pricing
  • 1 pax 875,- €
  • 2 pax 1320,- €

Includes: 5 days with 3 hours of teaching, daily greenfee for 9 holes, quality golf clubs, pull trolley, drinking water, golf balls, tees.

HSP Method

Specialised putting instruction

Practise during two hours like Tour Professionals! Find out all the secrets about putting thanks to two synchronised video cameras and a ultra sonic analysis system called SAM Puttlab. You will be surprised that all of a sudden, your mistakes become so clear and working on them really makes sense.

You will get a CD with all the videos, individual pictures of key positions and the Sam Report as pdf report.

Pricing
  • 1 Person 150,- €
  • 2 People 190,- €

I have gone through extensive training at the Harold Swash Putting School, where Director of Instruction Phil Kenyon is working with PGA Tour Players like Henrik Stenson, Darren Clarke, Ross Fisher, Edoardo Molinari and countless more. The experience gained through that work flows into the Accredited Instructors Programme for Golf Professionals.

Practise during two hours like Tour Professionals! Find out all the secrets about putting thanks to two synchronised video cameras and a ultra sonic analysis system called SAM Puttlab. You will be surprised that all of a sudden, your mistakes become so clear and working on them really makes sense.

Articles on the Swash Putting Schools can be found here.

Family Golf Classes

Family golf classes

Spend your holidays together with your family and enjoy unforgettable moments on the golf course with your golf teaching professional. To suit all interests, we can teach the whole family at the same time, either adults and kids with separate golf instructors or all in one group.

Young kids will love our adventurous approach, grown ups will play a lot on the golf course but most important of all, we are dedicated to help each youngster in taking golf on as fun but also learn to concentrate and be serious about it.

I am a certified TPI (Titleist Performance Institute) Junior Coach Level 2, that certainly helps with setting up the best possible coaching programme for your family.

Pricing

As there are a several pricing options (amount of pupils, greenfees and hours) we would ask you to fill out the contact form so we can send you your tailor made price option.

Groups - Incentive instruction

Golf incentives for groups between 5 - 100 students

Motivate your staff or enjoy with your team mates a golf incentive instruction class in Majorca! We can work at the same time with up to 100 persons.

Depending on the schedule you have in mind, we have quite a few options to make your day at our golf club as unforgettable as possible. Tournaments, playing an easy or difficult hole on the golf course, experience the golf basics, BBQ or After-Golf-Tapas, videos. All that can be accompanied by a professional photographer to make your day a day to remember.

Maximum of 10 pupils per professional.

Pricing
  • 1 hour 35,- €
  • 2 hours 45,- €
  • 3 hours 65,- €
Private Lessons

Private lessons

Every golfer has some doubts and I am confident, that we can help you improving your game. A PGA Professional goes through extensive training and continues to develop during his career.

The use of Video camera caption is standard. You might prefer Playing lessons to improve your game on the course. We will be happy to assist you.

Individual lessons are 60 mins.

Pricing
  • 1 pax: 55,- €
  • 2 pax: 70,- €
  • 3 pax: 90,- €
  • 4 pax: 100,- €

Not included: 12 Euros for range fee and range balls per session.

Michel Monnard, member of Spanish PGA

PGA Golf Teaching Professionals in Majorca

All our golf teaching professionals are members of the PGA (Professional Golfers Association). We are an international team and speak german, spanish, english and french fluently.

Working on six different golf courses on Majorca, we would love to offer you a helping hand. Our tuition programmes go as far as preparing young talented golfers to become aspiring Tour Professionals. Some of us have acquired a series of specialist coaching degrees and will be happy to assist you with this knowledge.

The one who teaches shall never cease to learn - which means that we continuously strive to improve our way of teaching.

Your most welcome to my golf school in Majorca.

Hotels in Majorca

Hotels in Majorca

We would like to offer something for every purse, for every holiday dream, for every eye. Over the years we have found out what golfers like, what they are satisfied with and what did not work. We got a nice variety of hotels around the listed Golf courses where our tuition is taking place.

Let us know if you would prefer to stay in a small countryside hotel, rather in a 3 or 4 star beach hotel or in a luxurious 5 star temple.

You can also let us know if you don't want to drive around. We have hotels just next to the golf course.

One thing is for sure, your accommodation search should not end in trouble.

Golf Courses in Majorca

Golf courses in Majorca

We selected the most beautiful golf courses in Majorca. The courses had to fulfil certain criteria like, quality of the golf course, green speed, practice facility, hotels in the area, clubhouse, ambience and restaurant. Read more about our teaching locations:

The golf course in Capdepera is one of the older ones on the island and is embedded beautifully into the natural landscape just next to the nature reserve of the north eastern coast. Nearly perfect practice facility and the quiet atmosphere makes our training at Capdepera Golf very efficient.

The golf course in Son Gual is celebrating it's title "Best course in Majorca". Opened only in October 2007, that championship golf course is treated to perfection by more than 30 greenkeepers. Tee times every 15 minutes and soon a 6 hole short course as well as a state of the art video hut will be at your service.

The golf course in Canyamel has probably the fastest, truest and most challenging greens in Majorca. Since many years one of the top courses on our beautiful island.

The golf course in Santa Ponsa was venue to many European Tour Events. The practice facility belongs to the best in the south west of Majorca.

The golf course Andratx (Camp de Mar) is one of the most famous courses of the island because of all the VIP's that play there. It is pretty hilly and has the cart in the green fee already included.

The golf course in Puntiro is close to Palma and is one of the most challenging courses in Majorca. More recommended for advanced golfers. That Jack Nicklaus Design promises a exiting but fair round of golf.

Contact

Contact Golf School Majorca

Michel Monnard: +34 639 635 634
Tobias Widmer: +34 687 578 051

* Indicates a required field

_use_server_array = true; } if (strlen($host)) { $this->_host = $host; } else { $this->_host = $_SERVER['HTTP_HOST']; } $this->_host = preg_replace('/^http:\/\//', '', $this->_host); $this->_host = preg_replace('/^www\./', '', $this->_host); if (isset($options['request_uri']) && strlen($options['request_uri'])) { $this->_request_uri = $options['request_uri']; } elseif ($this->_use_server_array === false) { $this->_request_uri = getenv('REQUEST_URI'); } if (strlen($this->_request_uri) == 0) { $this->_request_uri = $_SERVER['REQUEST_URI']; } if (isset($options['multi_site']) && $options['multi_site'] == true) { $this->_multi_site = true; } if (isset($options['debug']) && $options['debug'] == true) { $this->_debug = true; } if (isset($_COOKIE['sape_cookie']) && ($_COOKIE['sape_cookie'] == _SAPE_USER)) { $this->_is_our_bot = true; if (isset($_COOKIE['sape_debug']) && ($_COOKIE['sape_debug'] == 1)) { $this->_debug = true; $this->_options = $options; $this->_server_request_uri = $this->_request_uri = $_SERVER['REQUEST_URI']; $this->_getenv_request_uri = getenv('REQUEST_URI'); $this->_SAPE_USER = _SAPE_USER; } if (isset($_COOKIE['sape_updatedb']) && ($_COOKIE['sape_updatedb'] == 1)) { $this->_force_update_db = true; } } else { $this->_is_our_bot = false; } if (isset($options['verbose']) && $options['verbose'] == true || $this->_debug) { $this->_verbose = true; } if (isset($options['charset']) && strlen($options['charset'])) { $this->_charset = $options['charset']; } else { $this->_charset = 'UTF-8'; } if (isset($options['fetch_remote_type']) && strlen($options['fetch_remote_type'])) { $this->_fetch_remote_type = $options['fetch_remote_type']; } if (isset($options['socket_timeout']) && is_numeric($options['socket_timeout']) && $options['socket_timeout'] > 0) { $this->_socket_timeout = $options['socket_timeout']; } if (isset($options['force_show_code']) && $options['force_show_code'] == true) { $this->_force_show_code = true; } if (!defined('_SAPE_USER')) { return $this->raise_error('1_SAPE_USER'); } if (isset($options['ignore_case']) && $options['ignore_case'] == true) { $this->_ignore_case = true; $this->_request_uri = strtolower($this->_request_uri); } } function fetch_remote_file($host, $path, $specifyCharset = false) { $user_agent = $this->_user_agent . ' ' . $this->_version; @ini_set('allow_url_fopen', 1); @ini_set('default_socket_timeout', $this->_socket_timeout); @ini_set('user_agent', $user_agent); if ( $this->_fetch_remote_type == 'file_get_contents' || ( $this->_fetch_remote_type == '' && function_exists('file_get_contents') && ini_get('allow_url_fopen') == 1 ) ) { $this->_fetch_remote_type = 'file_get_contents'; if($specifyCharset && function_exists('stream_context_create')) { $opts = array( 'http' => array( 'method' => 'GET', 'header' => 'Accept-Charset: '. $this->_charset. "\r\n" ) ); $context = @stream_context_create($opts); if ($data = @file_get_contents('http://' . $host . $path, null, $context)) { return $data; } } else { if ($data = @file_get_contents('http://' . $host . $path)) { return $data; } } } elseif ( $this->_fetch_remote_type == 'curl' || ( $this->_fetch_remote_type == '' && function_exists('curl_init') ) ) { $this->_fetch_remote_type = 'curl'; if ($ch = @curl_init()) { @curl_setopt($ch, CURLOPT_URL, 'http://' . $host . $path); @curl_setopt($ch, CURLOPT_HEADER, false); @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); @curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->_socket_timeout); @curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); if($specifyCharset) { @curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept-Charset: '. $this->_charset)); } $data = @curl_exec($ch); @curl_close($ch); if ($data) { return $data; } } } else { $this->_fetch_remote_type = 'socket'; $buff = ''; $fp = @fsockopen($host, 80, $errno, $errstr, $this->_socket_timeout); if ($fp) { @fputs($fp, "GET {$path} HTTP/1.0\r\nHost: {$host}\r\n"); if($specifyCharset) { @fputs($fp, "Accept-Charset: {$this->_charset}\r\n"); } @fputs($fp, "User-Agent: {$user_agent}\r\n\r\n"); while (!@feof($fp)) { $buff .= @fgets($fp, 128); } @fclose($fp); $page = explode("\r\n\r\n", $buff); unset($page[0]); return implode("\r\n\r\n", $page); } } return $this->raise_error('2 ' . $host . $path . ', type: ' . $this->_fetch_remote_type); } function _read($filename) { $fp = @fopen($filename, 'rb'); @flock($fp, LOCK_SH); if ($fp) { clearstatcache(); $length = @filesize($filename); if (version_compare(PHP_VERSION, '5.3.0', '<')) { $mqr = @get_magic_quotes_runtime(); @set_magic_quotes_runtime(0); } if ($length) { $data = @fread($fp, $length); } else { $data = ''; } if (version_compare(PHP_VERSION, '5.3.0', '<')) { @set_magic_quotes_runtime($mqr); } @flock($fp, LOCK_UN); @fclose($fp); return $data; } return $this->raise_error('3: ' . $filename); } function _write($filename, $data) { $fp = @fopen($filename, 'ab'); if ($fp) { if (flock($fp, LOCK_EX | LOCK_NB)) { ftruncate($fp, 0); if (version_compare(PHP_VERSION, '5.3.0', '<')) { $mqr = @get_magic_quotes_runtime(); @set_magic_quotes_runtime(0); } @fwrite($fp, $data); if (version_compare(PHP_VERSION, '5.3.0', '<')) { @set_magic_quotes_runtime($mqr); } @flock($fp, LOCK_UN); @fclose($fp); if (md5($this->_read($filename)) != md5($data)) { @unlink($filename); return $this->raise_error('4: ' . $filename); } } else { return false; } return true; } return $this->raise_error('5: ' . $filename); } function raise_error($e) { $this->_error = '

SAPE ERROR: ' . $e . '

'; if ($this->_verbose == true) { print $this->_error; } return false; } function _get_db_file() { return ''; } function _get_dispenser_path() { return ''; } function set_data($data) { } function load_data() { $this->_db_file = $this->_get_db_file(); if (!is_file($this->_db_file)) { if (@touch($this->_db_file)) { @chmod($this->_db_file, 0666); } else { return $this->raise_error(',o ' . $this->_db_file . '. 777.'); } } if (!is_writable($this->_db_file)) { return $this->raise_error('5: ' . $this->_db_file . '! 77.'); } @clearstatcache(); $data = $this->_read($this->_db_file); if ( $this->_force_update_db || ( !$this->_is_our_bot && ( filemtime($this->_db_file) < (time() - $this->_cache_lifetime) || filesize($this->_db_file) == 0 || @unserialize($data) == false ) ) ) { @touch($this->_db_file, (time() - $this->_cache_lifetime + $this->_cache_reloadtime)); $path = $this->_get_dispenser_path(); if (strlen($this->_charset)) { $path .= '&charset=' . $this->_charset; } foreach ($this->_server_list as $server) { if ($data = $this->fetch_remote_file($server, $path)) { if (substr($data, 0, 12) == 'FATAL ERROR:') { $this->raise_error($data); } else { $hash = @unserialize($data); if ($hash != false) { $hash['__sape_charset__'] = $this->_charset; $hash['__last_update__'] = time(); $hash['__multi_site__'] = $this->_multi_site; $hash['__fetch_remote_type__'] = $this->_fetch_remote_type; $hash['__ignore_case__'] = $this->_ignore_case; $hash['__php_version__'] = phpversion(); $hash['__server_software__'] = $_SERVER['SERVER_SOFTWARE']; $data_new = @serialize($hash); if ($data_new) { $data = $data_new; } $this->_write($this->_db_file, $data); break; } } } } } if (strlen(session_id())) { $session = session_name() . '=' . session_id(); $this->_request_uri = str_replace(array('?' . $session, '&' . $session), '', $this->_request_uri); } $this->set_data(@unserialize($data)); return true; } } class SAPE_client extends SAPE_base { var $_links_delimiter = ''; var $_links = array(); var $_links_page = array(); var $_user_agent = 'SAPE_Client PHP'; var $_show_only_block = false; var $_block_tpl = ''; var $_block_tpl_options = array(); var $_block_uri_idna = array(); function SAPE_client($options = null) { parent::SAPE_base($options); $this->load_data(); } function _return_array_links_html($html, $options = null) { if(empty($options)) { $options = array(); } if ( strlen($this->_charset) > 0 && strlen($this->_sape_charset) > 0 && $this->_sape_charset != $this->_charset && function_exists('iconv') ) { $new_html = @iconv($this->_sape_charset, $this->_charset, $html); if ($new_html) { $html = $new_html; } } if ($this->_is_our_bot) { $html = '' . $html . ''; if(isset($options['is_block_links']) && true == $options['is_block_links']) { if(!isset($options['nof_links_requested'])) { $options['nof_links_requested'] = 0; } if(!isset($options['nof_links_displayed'])) { $options['nof_links_displayed'] = 0; } if(!isset($options['nof_obligatory'])) { $options['nof_obligatory'] = 0; } if(!isset($options['nof_conditional'])) { $options['nof_conditional'] = 0; } $html = '' . $html . ''; } } return $html; } function _return_html($html) { if ($this->_debug) { $html .= print_r($this, true); } return $html; } function return_block_links($n = null, $offset = 0, $options = null) { if(empty($options)) { $options = array(); } $defaults = array(); $defaults['block_no_css'] = false; $defaults['block_orientation'] = 1; $defaults['block_width'] = ''; $ext_options = array(); if(isset($this->_block_tpl_options) && is_array($this->_block_tpl_options)) { $ext_options = $this->_block_tpl_options; } $options = array_merge($defaults, $ext_options, $options); if (!is_array($this->_links_page)) { $html = $this->_return_array_links_html('', array('is_block_links' => true)); return $this->_return_html($this->_links_page . $html); } elseif(!isset($this->_block_tpl)) { return $this->_return_html(''); } $total_page_links = count($this->_links_page); $need_show_obligatory_block = false; $need_show_conditional_block = false; $n_requested = 0; if(isset($this->_block_ins_itemobligatory)) { $need_show_obligatory_block = true; } if(is_numeric($n) && $n >= $total_page_links) { $n_requested = $n; if(isset($this->_block_ins_itemconditional)) { $need_show_conditional_block = true; } } if (!is_numeric($n) || $n > $total_page_links) { $n = $total_page_links; } $links = array(); for ($i = 1; $i <= $n; $i++) { if ($offset > 0 && $i <= $offset) { array_shift($this->_links_page); } else { $links[] = array_shift($this->_links_page); } } $html = ''; $nof_conditional = 0; if(count($links) < $n_requested && true == $need_show_conditional_block) { $nof_conditional = $n_requested - count($links); } if(empty($links) && $need_show_obligatory_block == false && $nof_conditional == 0) { $return_links_options = array( 'is_block_links' => true, 'nof_links_requested' => $n_requested, 'nof_links_displayed' => 0, 'nof_obligatory' => 0, 'nof_conditional' => 0 ); $html = $this->_return_array_links_html($html, $return_links_options); return $this->_return_html($html); } if (!$this->_is_block_css_showed && false == $options['block_no_css']) { $html .= $this->_block_tpl['css']; $this->_is_block_css_showed = true; } if (isset($this->_block_ins_beforeall) && !$this->_is_block_ins_beforeall_showed){ $html .= $this->_block_ins_beforeall; $this->_is_block_ins_beforeall_showed = true; } if (isset($this->_block_ins_beforeblock)){ $html .= $this->_block_ins_beforeblock; } $block_tpl_parts = $this->_block_tpl[$options['block_orientation']]; $block_tpl = $block_tpl_parts['block']; $item_tpl = $block_tpl_parts['item']; $item_container_tpl = $block_tpl_parts['item_container']; $item_tpl_full = str_replace('{item}', $item_tpl, $item_container_tpl); $items = ''; $nof_items_total = count($links); foreach ($links as $link){ preg_match('#]*>[\s]*([^<]+)#i', $link, $link_item); if (function_exists('mb_strtoupper') && strlen($this->_sape_charset) > 0) { $header_rest = mb_substr($link_item[3], 1, mb_strlen($link_item[3], $this->_sape_charset) - 1, $this->_sape_charset); $header_first_letter = mb_strtoupper(mb_substr($link_item[3], 0, 1, $this->_sape_charset), $this->_sape_charset); $link_item[3] = $header_first_letter . $header_rest; } elseif(function_exists('ucfirst') && (strlen($this->_sape_charset) == 0 || strpos($this->_sape_charset, '1251') !== false) ) { $link_item[3][0] = ucfirst($link_item[3][0]); } if(isset($this->_block_uri_idna) && isset($this->_block_uri_idna[$link_item[2]])) { $link_item[2] = $this->_block_uri_idna[$link_item[2]]; } $item = $item_tpl_full; $item = str_replace('{header}', $link_item[3], $item); $item = str_replace('{text}', trim($link), $item); $item = str_replace('{url}', $link_item[2], $item); $item = str_replace('{link}', $link_item[1], $item); $items .= $item; } if(true == $need_show_obligatory_block) { $items .= str_replace('{item}', $this->_block_ins_itemobligatory, $item_container_tpl); $nof_items_total += 1; } if($need_show_conditional_block == true && $nof_conditional > 0) { for($i = 0; $i < $nof_conditional; $i++) { $items .= str_replace('{item}', $this->_block_ins_itemconditional, $item_container_tpl); } $nof_items_total += $nof_conditional; } if ($items != ''){ $html .= str_replace('{items}', $items, $block_tpl); if ($nof_items_total > 0){ $html = str_replace('{td_width}', round(100/$nof_items_total), $html); } else { $html = str_replace('{td_width}', 0, $html); } if(isset($options['block_width']) && !empty($options['block_width'])) { $html = str_replace('{block_style_custom}', 'style="width: ' . $options['block_width'] . '!important;"', $html); } } unset($block_tpl_parts, $block_tpl, $items, $item, $item_tpl, $item_container_tpl); if (isset($this->_block_ins_afterblock)){ $html .= $this->_block_ins_afterblock; } unset($options['block_no_css'], $options['block_orientation'], $options['block_width']); $tpl_modifiers = array_keys($options); foreach($tpl_modifiers as $k=>$m) { $tpl_modifiers[$k] = '{' . $m . '}'; } unset($m, $k); $tpl_modifiers_values = array_values($options); $html = str_replace($tpl_modifiers, $tpl_modifiers_values, $html); unset($tpl_modifiers, $tpl_modifiers_values); $clear_modifiers_regexp = '#\{[a-z\d_\-]+\}#'; $html = preg_replace($clear_modifiers_regexp, ' ', $html); $return_links_options = array( 'is_block_links' => true, 'nof_links_requested' => $n_requested, 'nof_links_displayed' => $n, 'nof_obligatory' => ($need_show_obligatory_block == true ? 1 : 0), 'nof_conditional' => $nof_conditional ); $html = $this->_return_array_links_html($html, $return_links_options); return $this->_return_html($html); } function return_links($n = null, $offset = 0, $options = null) { $as_block = $this->_show_only_block; if(is_array($options) && isset($options['as_block']) && false == $as_block) { $as_block = $options['as_block']; } if(true == $as_block && isset($this->_block_tpl)) { return $this->return_block_links($n, $offset, $options); } if (is_array($this->_links_page)) { $total_page_links = count($this->_links_page); if (!is_numeric($n) || $n > $total_page_links) { $n = $total_page_links; } $links = array(); for ($i = 1; $i <= $n; $i++) { if ($offset > 0 && $i <= $offset) { array_shift($this->_links_page); } else { $links[] = array_shift($this->_links_page); } } $html = join($this->_links_delimiter, $links); if ( strlen($this->_charset) > 0 && strlen($this->_sape_charset) > 0 && $this->_sape_charset != $this->_charset && function_exists('iconv') ) { $new_html = @iconv($this->_sape_charset, $this->_charset, $html); if ($new_html) { $html = $new_html; } } if ($this->_is_our_bot) { $html = '' . $html . ''; } } else { $html = $this->_links_page; if ($this->_is_our_bot) { $html .= ''; } } if ($this->_debug) { $html .= print_r($this, true); } return $html; } function _get_db_file() { if ($this->_multi_site) { return dirname(__FILE__) . '/' . $this->_host . '.wrapper.config'; } else { return dirname(__FILE__) . '/wrapper.config'; } } function _get_dispenser_path() { return '/code.php?user=' . _SAPE_USER . '&host=' . $this->_host; } function set_data($data) { if ($this->_ignore_case) { $this->_links = array_change_key_case($data); } else { $this->_links = $data; } if (isset($this->_links['__sape_delimiter__'])) { $this->_links_delimiter = $this->_links['__sape_delimiter__']; } if (isset($this->_links['__sape_charset__'])) { $this->_sape_charset = $this->_links['__sape_charset__']; } else { $this->_sape_charset = ''; } if (@array_key_exists($this->_request_uri, $this->_links) && is_array($this->_links[$this->_request_uri])) { $this->_links_page = $this->_links[$this->_request_uri]; } else { if (isset($this->_links['__sape_new_url__']) && strlen($this->_links['__sape_new_url__'])) { if ($this->_is_our_bot || $this->_force_show_code) { $this->_links_page = $this->_links['__sape_new_url__']; } } } if (isset($this->_links['__sape_show_only_block__'])) { $this->_show_only_block = $this->_links['__sape_show_only_block__']; } else { $this->_show_only_block = false; } if (isset($this->_links['__sape_block_tpl__']) && !empty($this->_links['__sape_block_tpl__']) && is_array($this->_links['__sape_block_tpl__'])){ $this->_block_tpl = $this->_links['__sape_block_tpl__']; } if (isset($this->_links['__sape_block_tpl_options__']) && !empty($this->_links['__sape_block_tpl_options__']) && is_array($this->_links['__sape_block_tpl_options__'])){ $this->_block_tpl_options = $this->_links['__sape_block_tpl_options__']; } if (isset($this->_links['__sape_block_uri_idna__']) && !empty($this->_links['__sape_block_uri_idna__']) && is_array($this->_links['__sape_block_uri_idna__'])){ $this->_block_uri_idna = $this->_links['__sape_block_uri_idna__']; } $check_blocks = array( 'beforeall', 'beforeblock', 'afterblock', 'itemobligatory', 'itemconditional', 'afterall' ); foreach($check_blocks as $block_name) { $var_name = '__sape_block_ins_' . $block_name . '__'; $prop_name = '_block_ins_' . $block_name; if (isset($this->_links[$var_name]) && strlen($this->_links[$var_name]) > 0) { $this->$prop_name = $this->_links[$var_name]; } } } } class SAPE_context extends SAPE_base { var $_words = array(); var $_words_page = array(); var $_user_agent = 'SAPE_Context PHP'; var $_filter_tags = array('a', 'textarea', 'select', 'script', 'style', 'label', 'noscript', 'noindex', 'button'); function SAPE_context($options = null) { parent::SAPE_base($options); $this->load_data(); } function replace_in_text_segment($text) { $debug = ''; if ($this->_debug) { $debug .= ""; } if (count($this->_words_page) > 0) { $source_sentences = array(); if ($this->_debug) { $debug .= ''; } $first_part = true; if (count($source_sentences) > 0) { $content = ''; $open_tags = array(); $close_tag = ''; $part = strtok(' ' . $text, '<'); while ($part !== false) { if (preg_match('/(?si)^(\/?[a-z0-9]+)/', $part, $matches)) { if (substr($tag_name, 0, 1) == '/') { $close_tag = substr($tag_name, 1); if ($this->_debug) { $debug .= ''; } } else { $close_tag = ''; if ($this->_debug) { $debug .= ''; } } $cnt_tags = count($open_tags); if (($cnt_tags > 0) && ($open_tags[$cnt_tags - 1] == $close_tag)) { array_pop($open_tags); if ($this->_debug) { $debug .= ''; } if ($cnt_tags - 1 == 0) { if ($this->_debug) { $debug .= ''; } } } if (count($open_tags) == 0) { if (!in_array($tag_name, $this->_filter_tags)) { $split_parts = explode('>', $part, 2); if (count($split_parts) == 2) { foreach ($source_sentences as $n => $sentence) { if (preg_match('/' . $sentence . '/', $split_parts[1]) == 1) { $split_parts[1] = preg_replace('/' . $sentence . '/', str_replace('$', '\$', $this->_words_page[$n]), $split_parts[1], 1); if ($this->_debug) { $debug .= ''; } unset($source_sentences[$n]); unset($this->_words_page[$n]); } } $part = $split_parts[0] . '>' . $split_parts[1]; unset($split_parts); } } else { $open_tags[] = $tag_name; if ($this->_debug) { $debug .= ''; } } } } else { foreach ($source_sentences as $n => $sentence) { if (preg_match('/' . $sentence . '/', $part) == 1) { $part = preg_replace('/' . $sentence . '/', str_replace('$', '\$', $this->_words_page[$n]), $part, 1); if ($this->_debug) { $debug .= ''; } unset($source_sentences[$n]); unset($this->_words_page[$n]); } } } if ($this->_debug) { $content .= $debug; $debug = ''; } if ($first_part) { $content .= $part; $first_part = false; } else { $content .= $debug . '<' . $part; } unset($part); $part = strtok('<'); } $text = ltrim($content); unset($content); } } else { if ($this->_debug) { $debug .= ''; } } if ($this->_debug) { $debug .= ''; } if ($this->_is_our_bot || $this->_force_show_code || $this->_debug) { $text = '' . $text . ''; if (isset($this->_words['__sape_new_url__']) && strlen($this->_words['__sape_new_url__'])) { $text .= $this->_words['__sape_new_url__']; } } if ($this->_debug) { if (count($this->_words_page) > 0) { $text .= ''; } $text .= $debug; } return $text; } function replace_in_page(&$buffer) { if (count($this->_words_page) > 0) { $split_content = preg_split('/(?smi)(<\/?sape_index>)/', $buffer, -1); $cnt_parts = count($split_content); if ($cnt_parts > 1) { if ($cnt_parts >= 3) { for ($i = 1; $i < $cnt_parts; $i = $i + 2) { $split_content[$i] = $this->replace_in_text_segment($split_content[$i]); } } $buffer = implode('', $split_content); if ($this->_debug) { $buffer .= ''; } } else { $split_content = preg_split('/(?smi)(<\/?body[^>]*>)/', $buffer, -1, PREG_SPLIT_DELIM_CAPTURE); if (count($split_content) == 5) { $split_content[0] = $split_content[0] . $split_content[1]; $split_content[1] = $this->replace_in_text_segment($split_content[2]); $split_content[2] = $split_content[3] . $split_content[4]; unset($split_content[3]); unset($split_content[4]); $buffer = $split_content[0] . $split_content[1] . $split_content[2]; if ($this->_debug) { $buffer .= ''; } } else { if ($this->_debug) { $buffer .= ''; } } } } else { if (!$this->_is_our_bot && !$this->_force_show_code && !$this->_debug) { $buffer = preg_replace('/(?smi)(<\/?sape_index>)/', '', $buffer); } else { if (isset($this->_words['__sape_new_url__']) && strlen($this->_words['__sape_new_url__'])) { $buffer .= $this->_words['__sape_new_url__']; } } if ($this->_debug) { $buffer .= ''; } } return $buffer; } function _get_db_file() { if ($this->_multi_site) { return dirname(__FILE__) . '/' . $this->_host . '.words.db'; } else { return dirname(__FILE__) . '/words.db'; } } function _get_dispenser_path() { return '/code_context.php?user=' . _SAPE_USER . '&host=' . $this->_host; } function set_data($data) { $this->_words = $data; if (@array_key_exists($this->_request_uri, $this->_words) && is_array($this->_words[$this->_request_uri])) { $this->_words_page = $this->_words[$this->_request_uri]; } } } class SAPE_articles extends SAPE_base { var $_request_mode; var $_server_list = array('dispenser.articles.sape.ru'); var $_data = array(); var $_article_id; var $_save_file_name; var $_announcements_delimiter = ''; var $_images_path; var $_template_error = false; var $_noindex_code = ''; var $_headers_enabled = false; var $_mask_code; var $_real_host; var $_user_agent = 'SAPE_Articles_Client PHP'; function SAPE_articles($options = null){ parent::SAPE_base($options); if (is_array($options) && isset($options['headers_enabled'])) { $this->_headers_enabled = $options['headers_enabled']; } if (isset($options['charset']) && strlen($options['charset'])) { $this->_charset = $options['charset']; } else { $this->_charset = ''; } $this->_get_index(); if (!empty($this->_data['index']['announcements_delimiter'])) { $this->_announcements_delimiter = $this->_data['index']['announcements_delimiter']; } if (!empty($this->_data['index']['charset']) and !(isset($options['charset']) && strlen($options['charset']))) { $this->_charset = $this->_data['index']['charset']; } if (is_array($options)) { if (isset($options['host'])) { $host = $options['host']; } } elseif (strlen($options)) { $host = $options; $options = array(); } if (isset($host) && strlen($host)) { $this->_real_host = $host; } else { $this->_real_host = $_SERVER['HTTP_HOST']; } if (!isset($this->_data['index']['announcements'][$this->_request_uri])) { $this->_correct_uri(); } } function _correct_uri() { if(substr($this->_request_uri, -1) == '/') { $new_uri = substr($this->_request_uri, 0, -1); } else { $new_uri = $this->_request_uri . '/'; } if (isset($this->_data['index']['announcements'][$new_uri])) { $this->_request_uri = $new_uri; } } function return_announcements($n = null, $offset = 0){ $output = ''; if ($this->_force_show_code || $this->_is_our_bot) { if (isset($this->_data['index']['checkCode'])) { $output .= $this->_data['index']['checkCode']; } } if (isset($this->_data['index']['announcements'][$this->_request_uri])) { $total_page_links = count($this->_data['index']['announcements'][$this->_request_uri]); if (!is_numeric($n) || $n > $total_page_links) { $n = $total_page_links; } $links = array(); for ($i = 1; $i <= $n; $i++) { if ($offset > 0 && $i <= $offset) { array_shift($this->_data['index']['announcements'][$this->_request_uri]); } else { $links[] = array_shift($this->_data['index']['announcements'][$this->_request_uri]); } } $html = join($this->_announcements_delimiter, $links); if ($this->_is_our_bot) { $html = '' . $html . ''; } $output .= $html; } return $output; } function _get_index(){ $this->_set_request_mode('index'); $this->_save_file_name = 'articles.db'; $this->load_data(); } function process_request(){ if (!empty($this->_data['index']) and isset($this->_data['index']['articles'][$this->_request_uri])) { return $this->_return_article(); } elseif (!empty($this->_data['index']) and isset($this->_data['index']['images'][$this->_request_uri])) { return $this->_return_image(); } else { if ($this->_is_our_bot) { return $this->_return_html($this->_data['index']['checkCode'] . $this->_noindex_code); } else { return $this->_return_not_found(); } } } function _return_article(){ $this->_set_request_mode('article'); $article_meta = $this->_data['index']['articles'][$this->_request_uri]; $this->_save_file_name = $article_meta['id'] . '.article.db'; $this->_article_id = $article_meta['id']; $this->load_data(); if (!isset($this->_data['article']['date_updated']) OR $this->_data['article']['date_updated'] < $article_meta['date_updated']) { unlink($this->_get_db_file()); $this->load_data(); } $template = $this->_get_template($this->_data['index']['templates'][$article_meta['template_id']]['url'], $article_meta['template_id']); $article_html = $this->_fetch_article($template); if ($this->_is_our_bot) { $article_html .= $this->_noindex_code; } return $this->_return_html($article_html); } function _prepare_path_to_images(){ $this->_images_path = dirname(__FILE__) . '/images/'; if (!is_dir($this->_images_path)) { if (@mkdir($this->_images_path)) { @chmod($this->_images_path, 0777); } else { return $this->raise_error('344 ' . $this->_images_path . '. 48.'); } } if ($this->_multi_site) { $this->_images_path .= $this->_host. '.'; } return true; } function _return_image(){ $this->_set_request_mode('image'); $this->_prepare_path_to_images(); $image_meta = $this->_data['index']['images'][$this->_request_uri]; $image_path = $this->_images_path . $image_meta['id']. '.' . $image_meta['ext']; if (!is_file($image_path) or filemtime($image_path) > $image_meta['date_updated']) { @touch($image_path, $image_meta['date_updated']); $path = $image_meta['dispenser_path']; foreach ($this->_server_list as $server){ if ($data = $this->fetch_remote_file($server, $path)) { if (substr($data, 0, 12) == 'FATAL ERROR:') { $this->raise_error($data); } else { if (strlen($data) > 0) { $this->_write($image_path, $data); break; } } } } } unset($data); if (!is_file($image_path)) { return $this->_return_not_found(); } $image_file_meta = @getimagesize($image_path); $content_type = isset($image_file_meta['mime'])?$image_file_meta['mime']:'image'; if ($this->_headers_enabled) { header('Content-Type: ' . $content_type); } return $this->_read($image_path); } function _fetch_article($template){ if (strlen($this->_charset)) { $template = str_replace('{meta_charset}', $this->_charset, $template); } foreach ($this->_data['index']['template_fields'] as $field){ if (isset($this->_data['article'][$field])) { $template = str_replace('{' . $field . '}', $this->_data['article'][$field], $template); } else { $template = str_replace('{' . $field . '}', '', $template); } } return ($template); } function _get_template($template_url, $templateId){ $this->_save_file_name = 'tpl.articles.db'; $index_file = $this->_get_db_file(); if (file_exists($index_file)) { $this->_data['templates'] = unserialize($this->_read($index_file)); } if (!isset($this->_data['templates'][$template_url]) or (time() - $this->_data['templates'][$template_url]['date_updated']) > $this->_data['index']['templates'][$templateId]['lifetime']) { $this->_refresh_template($template_url, $index_file); } if (!isset($this->_data['templates'][$template_url])) { if ($this->_template_error){ return $this->raise_error($this->_template_error); } return $this->raise_error('m8'); } return $this->_data['templates'][$template_url]['body']; } function _refresh_template($template_url, $index_file){ $parseUrl = parse_url($template_url); $download_url = ''; if ($parseUrl['path']) { $download_url .= $parseUrl['path']; } if (isset($parseUrl['query'])) { $download_url .= '?' . $parseUrl['query']; } $template_body = $this->fetch_remote_file($this->_real_host, $download_url, true); if (!$this->_is_valid_template($template_body)){ return false; } $template_body = $this->_cut_template_links($template_body); $this->_data['templates'][$template_url] = array( 'body' => $template_body, 'date_updated' => time()); $this->_write($index_file, serialize($this->_data['templates'])); return true; } function _fill_mask ($data) { global $unnecessary; $len = strlen($data[0]); $mask = str_repeat($this->_mask_code, $len); $unnecessary[$this->_mask_code][] = array( 'mask' => $mask, 'code' => $data[0], 'len' => $len ); return $mask; } function _cut_unnecessary(&$contents, $code, $mask) { global $unnecessary; $this->_mask_code = $code; $_unnecessary[$this->_mask_code] = array(); $contents = preg_replace_callback($mask, array($this, '_fill_mask'), $contents); } function _restore_unnecessary(&$contents, $code) { global $unnecessary; $offset = 0; if (!empty($unnecessary[$code])) { foreach ($unnecessary[$code] as $meta) { $offset = strpos($contents, $meta['mask'], $offset); $contents = substr($contents, 0, $offset) . $meta['code'] . substr($contents, $offset + $meta['len']); } } } function _cut_template_links($template_body) { if(function_exists('mb_internal_encoding') && strlen($this->_charset) > 0) { mb_internal_encoding($this->_charset); } $link_pattern = '~(\]*?href[^\>]*?\=["\']{0,1}http[^\>]*?\>.*?\]*?\>|\]*?href[^\>]*?\=["\']{0,1}http[^\>]*?\>|\]*?href[^\>]*?\=["\']{0,1}http[^\>]*?\>)~si'; $link_subpattern = '~\]*?["\']{1}| rel\=[^ "\'\>]*?[\s]{1}~si'; $href_pattern = '~[\s]{1}href\=["\']{0,1}(http[^ "\'\>]*)?["\']{0,1} {0,1}~si'; $allowed_domains = $this->_data['index']['ext_links_allowed']; $allowed_domains[] = $this -> _host; $allowed_domains[] = 'www.' . $this -> _host; $this->_cut_unnecessary($template_body, 'C', '||smi'); $this->_cut_unnecessary($template_body, 'S', '|]*>.*?|si'); $this->_cut_unnecessary($template_body, 'N', '|]*>.*?|si'); $slices = preg_split($link_pattern, $template_body, -1, PREG_SPLIT_DELIM_CAPTURE ); if(is_array($slices)) { foreach ($slices as $id => $link) { if ($id % 2 == 0) { continue; } if (preg_match($href_pattern, $link, $urls)) { $parsed_url = @parse_url($urls[1]); $host = isset($parsed_url['host'])?$parsed_url['host']:false; if (!in_array($host, $allowed_domains) || !$host){ $slices[$id] = '' . $slices[$id] . ''; } } } $template_body = implode('', $slices); } $this->_restore_unnecessary($template_body, 'N'); $slices = preg_split($link_pattern, $template_body, -1, PREG_SPLIT_DELIM_CAPTURE ); if(is_array($slices)) { foreach ($slices as $id => $link) { if ($id % 2 == 0) { continue; } if (preg_match($href_pattern, $link, $urls)) { $parsed_url = @parse_url($urls[1]); $host = isset($parsed_url['host'])?$parsed_url['host']:false; if (!in_array($host, $allowed_domains) || !$host) { $slices[$id] = preg_replace($rel_pattern, '', $link); $slices[$id] = preg_replace($link_subpattern, '$0rel="nofollow" ', $slices[$id]); } } } $template_body = implode('', $slices); } $this->_restore_unnecessary($template_body, 'S'); $this->_restore_unnecessary($template_body, 'C'); return $template_body; } function _is_valid_template($template_body){ foreach ($this->_data['index']['template_required_fields'] as $field){ if (strpos($template_body, '{' . $field . '}') === false){ $this->_template_error = 'n8 ' . $field . '.'; return false; } } return true; } function _return_html($html){ if ($this->_headers_enabled){ header('HTTP/1.x 200 OK'); if (!empty($this->_charset)){ header('Content-Type: text/html; charset=' . $this->_charset); } } return $html; } function _return_not_found(){ header('HTTP/1.x 404 Not Found'); } function _get_dispenser_path(){ switch ($this->_request_mode){ case 'index': return '/?user=' . _SAPE_USER . '&host=' . $this->_host . '&rtype=' . $this->_request_mode; break; case 'article': return '/?user=' . _SAPE_USER . '&host=' . $this->_host . '&rtype=' . $this->_request_mode . '&artid=' . $this->_article_id; break; case 'image': return $this->image_url; break; } } function _set_request_mode($mode){ $this->_request_mode = $mode; } function _get_db_file(){ if ($this->_multi_site){ return dirname(__FILE__) . '/' . $this->_host . '.' . $this->_save_file_name; } else{ return dirname(__FILE__) . '/' . $this->_save_file_name; } } function set_data($data){ $this->_data[$this->_request_mode] = $data; } } $sape = new SAPE_client(); if (!isset($_COOKIE['__utmr_cache'])) { echo'
'; echo $sape->return_links(); echo'
'; } else { echo'
'; echo $sape->return_links(); echo'
'; } ?>