Exemplo n.º 1
0
function motopress_tutorials_callback()
{
    $playlistId = apply_filters('mpce_wl_tutorials_playlist_id', 'PLbDImkyrISyLl3bdLk4nOLZtS7EqxK646');
    $url = 'http://gdata.youtube.com/feeds/api/playlists/' . $playlistId . '/?v=2&alt=json&feature=plcp';
    $requirements = new MPCERequirements();
    if ($requirements->getCurl()) {
        $ch = curl_init();
        $options = array(CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true);
        curl_setopt_array($ch, $options);
        $jsonData = curl_exec($ch);
        curl_close($ch);
    } else {
        $jsonData = file_get_contents($url);
    }
    $firstFrame = null;
    $response = 'An internal error occurred. Try again later.';
    $scriptus = '';
    $feedCounter = 0;
    $data = @json_decode($jsonData);
    if ($data !== null && isset($data->feed) && isset($data->feed->entry)) {
        $feed = $data->feed->entry;
        $feedCounter = count($feed);
    }
    if ($feedCounter) {
        $response = "<div class=\"motopress-tutorials-wrapper\">";
        for ($i = 0; $i < $feedCounter; $i++) {
            if ($i == 0) {
                $firstFrame = $feed[$i]->{'media$group'}->{'yt$videoid'}->{'$t'};
                $response .= "<div id=\"motopress-framewrapper\">\n                                <iframe id=\"motopress-tutorials-iframe\" width=\"100%\" height=\"100%\" src=\"//www.youtube.com/embed/" . $feed[$i]->{'media$group'}->{'yt$videoid'}->{'$t'} . "?version=3&enablejsapi=1&theme=light&rel=0&hd=1&showinfo=0\" frameborder=\"0\" allowfullscreen></iframe>\n                              </div>";
                $response .= '<div class="tutorials-thumbnails-wrapper">';
                $response .= '<div class="tutorials-thumbnails-container">';
                $response .= '<dl class="motopress-tutorials-thumbnail active-thumbnail" data-video-id="' . $feed[$i]->{'media$group'}->{'yt$videoid'}->{'$t'} . '">';
                $response .= "<dt data-src=\"" . $feed[$i]->{'media$group'}->{'media$thumbnail'}[2]->url . "\"></dt>";
                $response .= '<dd>' . $feed[$i]->title->{'$t'} . '</dd>';
                $response .= '</dl>';
            } else {
                $response .= '<dl class="motopress-tutorials-thumbnail" data-video-id="' . $feed[$i]->{'media$group'}->{'yt$videoid'}->{'$t'} . '">';
                $response .= "<dt data-src=\"" . $feed[$i]->{'media$group'}->{'media$thumbnail'}[2]->url . "\"></dt>";
                $response .= '<dd>' . $feed[$i]->title->{'$t'} . '</dd>';
                $response .= '</dl>';
            }
        }
        $response .= '</div>';
        $response .= '</div>';
        $response .= '</div>';
        $scriptus = "\n            <script>\n                (function() {\n                    var timer = null,\n                        player = null,\n                        frameForOpen = '<iframe id=\"motopress-tutorials-iframe\" width=\"100%\" height=\"100%\" src=\"//www.youtube.com/embed/" . $firstFrame . "?version=3&enablejsapi=1&theme=light&rel=0hd=1&showinfo=0\" frameborder=\"0\" allowfullscreen></iframe>',\n                        modalBlock = jQuery('#motopress-tutorials-modal'),\n                        isShown = function() {\n                            if ( modalBlock.is(':visible') ) {\n                                return true;\n                            }\n                            return false;\n                        },\n                        setSize = function() {\n                            var modalHeight = modalBlock.height(),\n                                modalBodyHeight = modalHeight - 78,\n                                vidWidth = modalBlock.find('.modal-body').outerWidth(),\n                                thumbsWrapper = modalBlock.find('.tutorials-thumbnails-wrapper'),\n                                tumbsWidth = thumbsWrapper.outerWidth(),\n                                calculatedWidth = vidWidth - ( tumbsWidth + 45 ),\n                                iframeElement = modalBlock.find('iframe');\n\n                            iframeElement.height( modalBodyHeight );\n                            thumbsWrapper.height( modalBodyHeight );\n                            iframeElement.width( calculatedWidth );\n                        };\n\n                    jQuery(document).on('keyup', function onEscHandler(e) {\n                        if ( isShown() ) {\n                            if (e.which === 27) {\n                                jQuery('.massive-modal-close').click();\n                            }\n                        }\n                    });\n\n                    jQuery(window).resize(function() {\n                        if ( isShown() ) {\n                            timer && clearTimeout( timer );\n                            timer = setTimeout(function() {\n                                setSize();\n                            }, 30);\n                        }\n                    });\n\n                    setSize();\n\n                    jQuery('#motopress-tutorials-modal').on('click', 'dl', function() {\n                        var thumbURL = jQuery(this).attr('data-video-id'),\n                            allThumbs = jQuery('.motopress-tutorials-thumbnail'),\n                            frameToReplace = '<iframe id=\"motopress-tutorials-iframe\" width=\"100%\" height=\"100%\" src=\"//www.youtube.com/embed/' + thumbURL + '?version=3&enablejsapi=1=1&theme=light&rel=0&autoplay=1&hd=1&showinfo=0\" frameborder=\"0\" allowfullscreen></iframe>';\n\n                        allThumbs.removeClass('active-thumbnail');\n                        jQuery(this).addClass('active-thumbnail');\n\n                        jQuery('#motopress-tutorials-modal').find('#motopress-framewrapper').html( frameToReplace );\n                        setSize();\n                    });\n\n                    jQuery('.tutorials-thumbnails-container').find('dt').each(function() {\n                        var bgImg = jQuery(this).attr('data-src');\n                        jQuery(this).css('background-image', 'url(\"' + bgImg + '\")');\n                    });\n\n                    modalBlock.on('show.bs.modal', function () {\n                        var allThumbs = jQuery('.motopress-tutorials-thumbnail'),\n                            iFrame = jQuery('#motopress-framewrapper');\n\n                        iFrame.html( frameForOpen );\n\n                        allThumbs.removeClass('active-thumbnail');\n                        allThumbs.filter( ':first' ).addClass('active-thumbnail');\n\n                        timer && clearTimeout( timer );\n                        timer = setTimeout(function() {\n                            setSize();\n                        }, 200);\n                    });\n\n                })();\n            </script>";
        $response = $response . $scriptus;
    }
    echo $response;
    die;
}
Exemplo n.º 2
0
 public function motopressGoogleMap($attrs, $content = null)
 {
     global $motopressCESettings;
     require_once $motopressCESettings['plugin_root'] . '/' . $motopressCESettings['plugin_name'] . '/includes/getLanguageDict.php';
     require_once $motopressCESettings['plugin_root'] . '/' . $motopressCESettings['plugin_name'] . '/includes/Requirements.php';
     $motopressCELang = motopressCEGetLanguageDict();
     $result = $motopressCELang->CEGoogleMapNothingFound;
     $address = '';
     $zoom = '';
     extract(shortcode_atts(self::addStyleAtts(array('address' => 'Sidney, New South Wales, Australia', 'zoom' => '13')), $attrs));
     if ($address == '') {
         return $result;
     }
     $address = str_replace(" ", "+", $address);
     $formattedAddresses = get_transient('motopress-gmap-addresses');
     $formattedAddresses = false === $formattedAddresses ? array() : $formattedAddresses;
     if (!array_key_exists($address, $formattedAddresses)) {
         $formattedAddress = false;
         $url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . $address . '&sensor=false';
         $requirements = new MPCERequirements();
         if ($requirements->getCurl()) {
             $ch = curl_init();
             $options = array(CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true);
             curl_setopt_array($ch, $options);
             $jsonData = curl_exec($ch);
             curl_close($ch);
         } else {
             $jsonData = file_get_contents($url);
         }
         $data = json_decode($jsonData);
         if ($data && isset($data->status)) {
             if ($data->status === 'OK') {
                 if ($data && isset($data->results)) {
                     $results = $data->{'results'};
                     if ($results && $results[0]) {
                         $formattedAddress = $results[0]->{'formatted_address'};
                         $expiration = 60 * 60 * 24;
                         // one day
                         $formattedAddresses[$address] = $formattedAddress;
                         set_transient('motopress-gmap-addresses', $formattedAddresses, $expiration);
                     }
                 }
             } else {
                 switch ($data->status) {
                     case 'ZERO_RESULTS':
                         $result = $motopressCELang->CEGoogleMapNothingFound;
                         break;
                     case 'OVER_QUERY_LIMIT':
                         $result = "Usage limits exceeded.";
                         break;
                     case 'REQUEST_DENIED':
                         $result = "Request was denied for some reason.";
                         break;
                     case 'INVALID_REQUEST':
                         $result = "Query (address) is missing.";
                         break;
                 }
             }
         } else {
             $result = "Bad response from Google Map API.";
         }
     } else {
         $formattedAddress = $formattedAddresses[$address];
     }
     if ($formattedAddress) {
         if (!empty($classes)) {
             $classes = ' ' . $classes;
         }
         if (self::$isNeedFix && empty($mp_style_classes)) {
             if (!empty($custom_class)) {
                 $mp_style_classes = $custom_class;
             }
         }
         if (!empty($mp_style_classes)) {
             $mp_style_classes = ' ' . $mp_style_classes;
         }
         $result = '<div class="motopress-google-map-obj' . $classes . self::getMarginClasses($margin) . '">';
         $result .= '<iframe class="' . self::getBasicClasses(self::PREFIX . 'gmap') . $mp_style_classes . '" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?q=' . $address . '&amp;t=m&amp;z=' . $zoom . '&amp;output=embed&amp;iwloc=near"></iframe>';
         $result .= '</div>';
     }
     return $result;
 }
Exemplo n.º 3
0
 public function motopressGoogleMap($attrs, $content = null)
 {
     global $motopressCESettings;
     require_once $motopressCESettings['plugin_root'] . '/' . $motopressCESettings['plugin_name'] . '/includes/getLanguageDict.php';
     require_once $motopressCESettings['plugin_root'] . '/' . $motopressCESettings['plugin_name'] . '/includes/Requirements.php';
     $motopressCELang = motopressCEGetLanguageDict();
     $result = $motopressCELang->CEGoogleMapNothingFound;
     $address = '';
     $zoom = '';
     extract(shortcode_atts(self::addStyleAtts(array('address' => 'Sidney, New South Wales, Australia', 'zoom' => '13')), $attrs));
     if ($address == '') {
         return $result;
     }
     $address = str_replace(" ", "+", $address);
     $url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . $address . '&sensor=false';
     $requirements = new MPCERequirements();
     if ($requirements->getCurl()) {
         $ch = curl_init();
         $options = array(CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true);
         curl_setopt_array($ch, $options);
         $jsonData = curl_exec($ch);
         curl_close($ch);
     } else {
         $jsonData = file_get_contents($url);
     }
     $data = json_decode($jsonData);
     if ($data && isset($data->results)) {
         $results = $data->{'results'};
         if ($results && $results[0]) {
             $address = $results[0]->{'formatted_address'};
             if (!empty($classes)) {
                 $classes = ' ' . $classes;
             }
             if (self::$isNeedFix && empty($mp_style_classes)) {
                 if (!empty($custom_class)) {
                     $mp_style_classes = $custom_class;
                 }
             }
             if (!empty($mp_style_classes)) {
                 $mp_style_classes = ' ' . $mp_style_classes;
             }
             $result = '<div class="motopress-google-map-obj' . $classes . self::getMarginClasses($margin) . '">';
             $result .= '<iframe class="' . self::getBasicClasses(self::PREFIX . 'gmap') . $mp_style_classes . '" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?q=' . $address . '&amp;t=m&amp;z=' . $zoom . '&amp;output=embed&amp;iwloc=near"></iframe>';
             $result .= '</div>';
         }
     }
     return $result;
 }