web/wp-content/plugins/exec-php/includes/write_ui.php
branchwordpress
changeset 123 561aa6d282f6
equal deleted inserted replaced
112:fb7cd02b9848 123:561aa6d282f6
       
     1 <?php
       
     2 
       
     3 require_once(dirname(__FILE__).'/cache.php');
       
     4 require_once(dirname(__FILE__).'/const.php');
       
     5 require_once(dirname(__FILE__).'/l10n.php');
       
     6 require_once(dirname(__FILE__).'/script.php');
       
     7 
       
     8 // -----------------------------------------------------------------------------
       
     9 // the ExecPhp_WriteUi class displays the user warnings in case of false
       
    10 // configuration
       
    11 // -----------------------------------------------------------------------------
       
    12 
       
    13 // use this guard to avoid error messages in WP admin panel if plugin
       
    14 // is disabled because of a version conflict but you still try to reload
       
    15 // the plugins config interface
       
    16 if (!class_exists('ExecPhp_WriteUi')) :
       
    17 class ExecPhp_WriteUi
       
    18 {
       
    19 	var $m_cache = NULL;
       
    20 	var $m_script = NULL;
       
    21 
       
    22 	// ---------------------------------------------------------------------------
       
    23 	// init
       
    24 	// ---------------------------------------------------------------------------
       
    25 
       
    26 	function ExecPhp_WriteUi(&$cache, &$script)
       
    27 	{
       
    28 		$this->m_cache =& $cache;
       
    29 		$this->m_script =& $script;
       
    30 
       
    31 		add_action('edit_form_advanced', array(&$this, 'action_edit_form'));
       
    32 		add_action('edit_page_form', array(&$this, 'action_edit_form'));
       
    33 		add_action('sidebar_admin_page', array(&$this, 'action_sidebar_admin_page'));
       
    34 	}
       
    35 
       
    36 	// ---------------------------------------------------------------------------
       
    37 	// hooks
       
    38 	// ---------------------------------------------------------------------------
       
    39 
       
    40 	function action_edit_form()
       
    41 	{
       
    42 		if ($this->rtfm_article())
       
    43 		{
       
    44 			$heading = __s('Exec-PHP WYSIWYG Conversion Warning.', ExecPhp_PLUGIN_ID);
       
    45 			$text = __s('Saving this article will render all contained PHP code permanently unuseful. Even if you are saving this article through the Code editor. You can turn off this warning in your user profile. Ignore this warning in case this article does not contain PHP code. <a href="%s">Read the Exec-PHP documentation if you are unsure what to do next</a>.', ExecPhp_PLUGIN_ID
       
    46 				, ExecPhp_HOME_URL. '/docs/'. __s('readme.html', ExecPhp_PLUGIN_ID). '#execute_php');
       
    47 			$this->m_script->print_message($heading, $text);
       
    48 		}
       
    49 	}
       
    50 
       
    51 	function action_sidebar_admin_page()
       
    52 	{
       
    53 		if ($this->rtfm_widget())
       
    54 		{
       
    55 			$heading = __s('Exec-PHP Widget Conversion Warning.', ExecPhp_PLUGIN_ID);
       
    56 			$text = __s('Saving the widgets will render all contained PHP code permanently unuseful. Ignore this warning in case the text widgets do not contain PHP code. <a href="%s">Read the Exec-PHP documentation if you are unsure what to do next</a>.', ExecPhp_PLUGIN_ID
       
    57 				, ExecPhp_HOME_URL. '/docs/'. __s('readme.html', ExecPhp_PLUGIN_ID). '#execute_php');
       
    58 			$this->m_script->print_message($heading, $text);
       
    59 		}
       
    60 	}
       
    61 
       
    62 	// ---------------------------------------------------------------------------
       
    63 	// tools
       
    64 	// ---------------------------------------------------------------------------
       
    65 
       
    66 	// checks whether the author / editor has read the documentation
       
    67 	function rtfm_article()
       
    68 	{
       
    69 		global $post;
       
    70 
       
    71 		$current_user = wp_get_current_user();
       
    72 
       
    73 		// the user turned off the wysiwyg warning in its preferences
       
    74 		$usermeta =& $this->m_cache->get_usermeta($current_user->ID);
       
    75 		if ($usermeta->hide_wysiwyg_warning())
       
    76 			return false;
       
    77 
       
    78 		if (!isset($post->author) || $post->post_author == $current_user->ID)
       
    79 		{
       
    80 			// the editor is equal to the writer of the article
       
    81 			if (!current_user_can(ExecPhp_CAPABILITY_EXECUTE_ARTICLES))
       
    82 				return false;
       
    83 			if (!current_user_can(ExecPhp_CAPABILITY_WRITE_PHP))
       
    84 				return true;
       
    85 		}
       
    86 		else
       
    87 		{
       
    88 			// the editor is different to the writer of the article
       
    89 			$poster = new WP_User($post->post_author);
       
    90 			if (!$poster->has_cap(ExecPhp_CAPABILITY_EXECUTE_ARTICLES))
       
    91 				return false;
       
    92 			// no check for posters write cap because the editor may want to
       
    93 			// insert code after the poster created the article
       
    94 		}
       
    95 		if (!current_user_can(ExecPhp_CAPABILITY_WRITE_PHP))
       
    96 			return true;
       
    97 		if (user_can_richedit())
       
    98 			return true;
       
    99 		if (get_option('use_balanceTags'))
       
   100 			return true;
       
   101 		return false;
       
   102 	}
       
   103 
       
   104 	// checks whether the admin has read the documentation
       
   105 	function rtfm_widget()
       
   106 	{
       
   107 		$option =& $this->m_cache->get_option();
       
   108 		if (!$option->get_widget_support())
       
   109 			return false;
       
   110 		if (!current_user_can(ExecPhp_CAPABILITY_WRITE_PHP))
       
   111 			return true;
       
   112 		return false;
       
   113 	}
       
   114 }
       
   115 endif;
       
   116 
       
   117 ?>