Exemplo n.º 1
0
 /**
  * @param $atts array of short code attributes
  * @param $content string not used
  * @return string export link
  */
 public function handleShortcode($atts, $content = null)
 {
     $atts = $this->decodeAttributes($atts);
     $params = array();
     $params[] = admin_url('admin-ajax.php');
     $params[] = '?action=cfdb-export';
     $special = array('urlonly', 'linktext', 'role');
     foreach ($atts as $key => $value) {
         if (!in_array($key, $special)) {
             $params[] = sprintf('&%s=%s', urlencode($key), urlencode($value));
         } else {
             if ($key == 'role') {
                 require_once 'CF7DBPlugin.php';
                 $plugin = new CF7DBPlugin();
                 $isAuth = $plugin->isUserRoleEqualOrBetterThan($value);
                 if (!$isAuth) {
                     // Not authorized. Print no link.
                     return '';
                 }
             }
         }
     }
     $url = implode($params);
     if (isset($atts['urlonly']) && $atts['urlonly'] == 'true') {
         return $url;
     }
     $linkText = __('Export', 'contact-form-7-to-database-extension');
     if (isset($atts['linktext'])) {
         $linkText = $atts['linktext'];
     }
     return sprintf('<a href="%s">%s</a>', $url, $linkText);
 }
 /**
  * @return bool
  */
 protected function isAuthorized()
 {
     if (!$this->isFromShortCode) {
         return $this->plugin->canUserDoRoleOption('CanSeeSubmitData');
     } else {
         $isAuth = $this->plugin->canUserDoRoleOption('CanSeeSubmitDataViaShortcode');
         if ($isAuth && isset($this->options['role'])) {
             $isAuth = $this->plugin->isUserRoleEqualOrBetterThan($this->options['role']);
         }
         return $isAuth;
     }
 }