CFDBShortcodeExportUrl

The Contact Form DB CFDBShortcodeExportUrl class.

Defined (1)

The class is defined in the following location(s).

/CFDBShortcodeExportUrl.php  
  1. class CFDBShortcodeExportUrl extends ShortCodeLoader { 
  2.  
  3. /** 
  4. * @param $atts array of short code attributes 
  5. * @param $content string not used 
  6. * @return string export link 
  7. */ 
  8. public function handleShortcode($atts, $content = null) { 
  9. $atts = $this->decodeAttributes($atts); 
  10. $params = array(); 
  11. $params[] = admin_url('admin-ajax.php'); 
  12. $params[] = '?action=cfdb-export'; 
  13.  
  14. $special = array('urlonly', 'linktext', 'role'); 
  15. foreach ($atts as $key => $value) { 
  16. if (!in_array($key, $special)) { 
  17. $params[] = sprintf('&%s=%s', urlencode($key), urlencode($value)); 
  18. } else if ($key == 'role') { 
  19. require_once('CF7DBPlugin.php'); 
  20. $plugin = new CF7DBPlugin(); 
  21. $isAuth = $plugin->isUserRoleEqualOrBetterThan($value); 
  22. if (!$isAuth) { 
  23. // Not authorized. Print no link. 
  24. return ''; 
  25. $url = implode($params); 
  26.  
  27. if (isset($atts['urlonly']) && $atts['urlonly'] == 'true') { 
  28. return $url; 
  29.  
  30. $linkText = __('Export', 'contact-form-7-to-database-extension'); 
  31. if (isset($atts['linktext'])) { 
  32. $linkText = $atts['linktext']; 
  33.  
  34. return sprintf('<a href="%s">%s</a>', $url, $linkText);