/**
         * Implementation of the janrain_capture shortcode.
         *
         * @param string $args
         *	 Arguments appended to the shortcode
         *
         * @return string
         *	 Text or HTML to render in place of the shortcode
         */
        function shortcode($args)
        {
            $atts = array('text' => 'Sign in / Register', 'action' => 'signin');
            $atts = shortcode_atts($atts, $args);
            if (strpos($atts['action'], 'edit_profile') === 0) {
                return $this->profile();
            }
            $link = '<a id="janrain_auth" href="#" class="capture_modal_open" >' . esc_html($atts['text']) . '</a>
					 <script>
						 if(localStorage && localStorage.getItem("janrainCaptureToken")) {
						 var authLink = document.getElementById("janrain_auth");
						 authLink.innerHTML = "Log out";
						 authLink.setAttribute("href", "' . esc_url(admin_url() . 'admin-ajax.php?action=janrain_capture_logout&source=' . rawurlencode(JanrainCaptureUi::current_page_url())) . '");
						 authLink.setAttribute("onclick", "janrain.capture.ui.endCaptureSession()");
						 authLink.setAttribute("class","");
						 }
					 </script>';
            return $link;
        }
Exemplo n.º 2
0
 /**
  * Implementation of the janrain_capture shortcode.
  *
  * @param string $args
  *   Arguments appended to the shortcode
  *
  * @return string
  *   Text or HTML to render in place of the shortcode
  */
 function shortcode($args)
 {
     extract(shortcode_atts(array('type' => 'modal', 'text' => 'Sign in / Register', 'action' => 'signin', 'height' => '400', 'width' => '700', 'href_only' => 'false', 'callback' => 'CAPTURE.closeProfile'), $args));
     $class = 'capture-anon';
     $capture_addr = self::get_option(self::$name . '_ui_address') ? self::get_option(self::$name . '_ui_address') : self::get_option(self::$name . '_address');
     if (strpos($action, 'profile') === 0) {
         $uargs = array('action' => self::$name . '_profile', 'callback' => self::sanitize($callback));
         if (strlen($action) > 7) {
             $method = substr($action, 7);
             $uargs['method'] = self::sanitize($method);
         }
         $link = admin_url('admin-ajax.php', '') . '?' . http_build_query($uargs, '', '&');
         $class = 'capture-auth';
     } else {
         if (strpos($action, 'signin') === 0) {
             $action .= JanrainCapture::get_option(JanrainCapture::$name . '_signin_ext');
         } elseif (strpos($action, 'edit_profile') === 0) {
             $display = $this->widget_profile();
             return $display;
         }
         $link = 'https://' . $capture_addr . '/oauth/' . $action;
         $args = array('response_type' => 'code', 'redirect_uri' => admin_url('admin-ajax.php', '') . '?action=' . self::$name . '_redirect_uri', 'client_id' => self::get_option(self::$name . '_client_id'), 'xd_receiver' => admin_url('admin-ajax.php', '') . '?action=' . self::$name . '_xdcomm', 'recover_password_callback' => 'CAPTURE.closeRecoverPassword');
         $link = $link . '?' . http_build_query($args, '', '&');
         if (JanrainCapture::get_option(JanrainCapture::$name . '_ui_type') == 'Capture') {
             if (!is_user_logged_in()) {
                 $link = '<a href="javascript:janrain.capture.ui.modal.open();" >' . $text . '</a>';
             } else {
                 $link = '<a href="' . wp_logout_url(JanrainCaptureUi::current_page_url()) . '" onclick="janrain.capture.ui.endCaptureSession();" >Log out</a>';
             }
             return $link;
         }
     }
     if ($href_only == 'true') {
         return esc_url($link);
     }
     if ($type == 'inline') {
         $iframe = '<iframe src="' . esc_url($link) . '" style="width:' . (int) $width . 'px;height:' . (int) $height . 'px;" class="' . self::$name . '_iframe ' . $class . ' ' . self::$name . '_' . self::sanitize($action) . '"></iframe>';
         return $iframe;
     } else {
         $anchor = '<a href="' . esc_url($link) . '" rel="width:' . (int) $width . 'px;height:' . (int) $height . 'px;" class="' . self::$name . '_anchor modal-link ' . $class . ' ' . self::$name . '_' . self::sanitize($action) . '">' . $text . '</a>';
         return $anchor;
     }
 }