function tdomf_show_your_submissions_menu()
{
    global $current_user;
    // how many of the recently published/approved entries to see
    //
    $limit = 10;
    get_currentuserinfo();
    $tdomf_flag = get_usermeta($current_user->ID, TDOMF_KEY_FLAG);
    $sub_total = tdomf_get_users_submitted_posts_count($current_user->ID);
    $app_total = tdomf_get_users_published_posts_count($current_user->ID);
    $user_status = get_usermeta($current_user->ID, TDOMF_KEY_STATUS);
    $app_posts = tdomf_get_user_published_posts($current_user->ID, 0, $limit);
    $mod_posts = tdomf_get_user_draft_posts($current_user->ID);
    $mod_total = count($mod_posts);
    $fut_posts = tdomf_get_user_scheduled_posts($current_user->ID);
    $fut_total = count($fut_posts);
    $unapp_edits = tdomf_get_edits(array('state' => 'unapproved', 'unique_post_ids' => true, 'user_id' => $current_user->ID));
    $app_edits = tdomf_get_edits(array('state' => 'approved', 'unique_post_ids' => true, 'user_id' => $current_user->ID, 'limit' => $limit));
    ?>

  <div class="wrap">
    <h2><?php 
    _e('Your Submissions', 'tdomf');
    ?>
</h2>
    
    <?php 
    if (in_array($_REQUEST['REMOTE_ADDR'], tdomf_get_ips_banned())) {
        ?>
      <?php 
        printf(__("You are logged on from the banned IP %s. If this is in error please contact the <a href='mailto:%s'>admins</a>.", "tdomf"), $_SERVER['REMOTE_ADDR'], get_bloginfo('admin_email'));
        ?>
    <?php 
    } else {
        if ($user_status == TDOMF_USER_STATUS_BANNED) {
            ?>
      <?php 
            printf(__("You are banned from using this functionality on this site. If this is in error please contact the <a href='mailto:%s'>admins</a>.", "tdomf"), get_bloginfo('admin_email'));
            ?>
    <?php 
        } else {
            ?>

      <p>
      <?php 
            if ($user_status == TDOMF_USER_STATUS_TRUSTED) {
                ?>
        <?php 
                printf(__("Good to see you again <b>%s</b>! ", "tdomf"), $current_user->display_name);
                ?>
      <?php 
            } else {
                if ($tdomf_flag) {
                    ?>
        <?php 
                    printf(__("Welcome back <b>%s</b>!", "tdomf"), $current_user->display_name);
                    ?>
      <?php 
                } else {
                    ?>
        <?php 
                    printf(__("Welcome <b>%s</b>.", "tdomf"), $current_user->display_name);
                    ?>
      <?php 
                }
            }
            ?>
      </p>
      
      <p><?php 
            printf(__("From here you can submit posts to the %s using the form below and check on the status of your submissions.", "tdomf"), get_bloginfo());
            ?>
</p>
      
      <?php 
            if (current_user_can('edit_others_posts') || current_user_can('manage_options')) {
                ?>
      <ul>
      <?php 
                if (current_user_can('manage_options')) {
                    ?>
      <li><a href="admin.php?page=tdomf_show_options_menu"><?php 
                    _e("Configure Options", "tdomf");
                    ?>
</a></li>
      <li><a href="admin.php?page=tdomf_show_form_menu"><?php 
                    _e("Modify Form", "tdomf");
                    ?>
</a></li>
      <?php 
                }
                ?>
      <li><a href="admin.php?page=tdomf_show_mod_posts_menu"><?php 
                _e("Moderate Submissions", "tdomf");
                ?>
</a></li>
      </ul>
      <?php 
            }
            ?>

    <?php 
            if ($tdomf_flag && ($sub_total > 0 || $app_total > 0)) {
                ?>
        
        <?php 
                if ($fut_total > 0) {
                    ?>
            <h3><?php 
                    printf(__('Your Next %d Scheduled Submissions', 'tdomf'), $fut_total);
                    ?>
</h3>
            <ul>
         <?php 
                    foreach ($fut_posts as $p) {
                        ?>
          <li>
          <?php 
                        $t_time = get_the_time(__('Y/m/d g:i:s A'));
                        $m_time = $p->post_date;
                        $time = tdomf_get_post_time('G', true, $p);
                        if (abs(time() - $time) < 86400) {
                            $h_time = sprintf(__('%s from now'), human_time_diff($time));
                        } else {
                            $h_time = mysql2date(__('Y/m/d'), $m_time);
                        }
                        ?>
                <?php 
                        printf(__("<a href='%s'>%s</a> will be published %s", "tdomf"), get_permalink($p->ID), $p->post_title, "<abbr title='{$t_time}'>{$h_time}</abbr>");
                        ?>
          </li>
         <?php 
                    }
                    ?>
    	  </ul>
        <?php 
                }
                ?>
        
       <?php 
                if ($app_total > 0) {
                    ?>
         <h3><?php 
                    printf(__('Your Last %d Published Submissions', 'tdomf'), $app_total < 5 ? $app_total : 5);
                    ?>
</h3>
         <ul>
         <?php 
                    foreach ($app_posts as $p) {
                        ?>
          <li>
          <?php 
                        $t_time = get_the_time(__('Y/m/d g:i:s A'));
                        $m_time = $p->post_date;
                        $time = tdomf_get_post_time('G', true, $p);
                        if (abs(time() - $time) < 86400) {
                            $h_time = sprintf(__('%s ago'), human_time_diff($time));
                        } else {
                            $h_time = mysql2date(__('Y/m/d'), $m_time);
                        }
                        ?>
                <?php 
                        printf(__("<a href='%s'>%s</a> approved %s", "tdomf"), get_permalink($p->ID), $p->post_title, "<abbr title='{$t_time}'>{$h_time}</abbr>");
                        ?>
          </li>
         <?php 
                    }
                    ?>
    	  </ul>
       <?php 
                }
                ?>
       
       <?php 
                if ($mod_total > 0) {
                    ?>
         <h3><?php 
                    _e('Your Sumissions awaiting Moderation', 'tdomf');
                    ?>
</h3>
         <ul>
         <?php 
                    foreach ($mod_posts as $p) {
                        ?>
          <li>"<?php 
                        echo $p->post_title;
                        ?>
"</li>
         <?php 
                    }
                    ?>
    	  </ul>
       <?php 
                }
                ?>
    <?php 
            }
            ?>
      
      
    <?php 
            if (!empty($app_edits)) {
                $num = number_format_i18n(count($app_edits));
                $text = __ngettext('Your Last Approved Contribution', 'Your Last %d Approved Contributions', count($app_edits));
                ?>
        <h3><?php 
                printf($text, count($app_edits));
                ?>
</h3>
        <ul>
        <?php 
                foreach ($app_edits as $app_edit) {
                    ?>
            <li>
            <?php 
                    $edit = tdomf_get_edits(array('state' => 'approved', 'post_id' => $app_edit->post_id, 'user_id' => $current_user->ID, 'limit' => 1));
                    $edit = $edit[0];
                    $t_time = get_the_time(__('Y/m/d g:i:s A'));
                    $h_time = mysql2date(__('Y/m/d'), $edit->date);
                    $post = get_post($app_edit->post_id);
                    printf(__("<a href='%s'>%s</a> edited %s", "tdomf"), get_permalink($app_edit->post_id), $post->post_title, "<abbr title='{$t_time}'>{$h_time}</abbr>");
                    ?>
            </li>
        <?php 
                }
                ?>
        </ul>
    <?php 
            }
            ?>
    
    <?php 
            if (!empty($unapp_edits)) {
                $num = number_format_i18n(count($unapp_edits));
                $text = __ngettext('Your Contribution awaiting Moderation', 'Your Contributions awaiting Moderation', count($unapp_edits));
                ?>
        <h3><?php 
                printf($text, count($unapp_edits));
                ?>
</h3>
        <ul>
        <?php 
                foreach ($unapp_edits as $unapp_edit) {
                    ?>
            <li>
            <?php 
                    $edit = tdomf_get_edits(array('state' => 'unapproved', 'post_id' => $unapp_edit->post_id, 'user_id' => $current_user->ID, 'limit' => 1));
                    $edit = $edit[0];
                    $t_time = get_the_time(__('Y/m/d g:i:s A'));
                    $h_time = mysql2date(__('Y/m/d'), $edit->date);
                    $post = get_post($unapp_edit->post_id);
                    printf(__("<a href='%s'>%s</a> edited %s", "tdomf"), get_permalink($unapp_edit->post_id), $post->post_title, "<abbr title='{$t_time}'>{$h_time}</abbr>");
                    ?>
            </li>
        <?php 
                }
                ?>
        </ul>
    <?php 
            }
            ?>
    
     </div>
      
     <!-- Form formatting -->     
     <style>
     .tdomf_form {
     }
     .tdomf_form fieldset legend {
       #border-bottom: 1px dotted black;
       font-weight: bold;
       padding: 0px;
       margin: 0px;
       padding-bottom: 10px;
     }
     .tdomf_form_preview {
       border: 1px dotted black;
       padding: 5px;
       margin: 5px;
       margin-bottom: 20px;
     }
     .tdomf_form_preview p {
       margin-left: 15px;
     }
     .tdomf_form .required {
       color: red;
     }
     .tdomf_form fieldset {
       margin-bottom: 10px;
       border: 0;
     }
     </style>
      
    <?php 
            $form_ids = tdomf_get_form_ids();
            if (!empty($form_ids)) {
                foreach ($form_ids as $form_id) {
                    if (tdomf_get_option_form(TDOMF_OPTION_INCLUDED_YOUR_SUBMISSIONS, $form_id->form_id)) {
                        $edit = tdomf_get_option_form(TDOMF_OPTION_FORM_EDIT, $form_id->form_id);
                        $post_id = false;
                        if (isset($_REQUEST['tdomf_post_id'])) {
                            $post_id = intval($_REQUEST['tdomf_post_id']);
                        }
                        $good = true;
                        if ($edit && tdomf_check_permissions_form($form_id->form_id, $post_id) != NULL) {
                            $good = false;
                        }
                        if ($good) {
                            ?>
     <div class="wrap">
        <h2><?php 
                            echo tdomf_get_option_form(TDOMF_OPTION_NAME, $form_id->form_id);
                            ?>
</h2>
        <p><?php 
                            echo tdomf_get_option_form(TDOMF_OPTION_DESCRIPTION, $form_id->form_id);
                            ?>
</p>
        <?php 
                            echo tdomf_generate_form($form_id->form_id);
                            ?>
        <br/><br/>
     </div>
          <?php 
                        }
                    }
                }
            }
            ?>
    <?php 
        }
    }
    ?>
    
  </div>

  <p><center><?php 
    _e('Powered by the <a href="http://thedeadone.net/software/tdo-mini-forms-wordpress-plugin/">TDO Mini Forms Plugin.', 'tdomf');
    ?>
</a></center></p>
  
<?php 
}
Exemplo n.º 2
0
function tdomf_show_manage_user_menu()
{
    global $wp_roles;
    $limit = 15;
    if (isset($_REQUEST['limit'])) {
        $limit = intval($_REQUEST['limit']);
    }
    $offset = 0;
    if (isset($_REQUEST['offset'])) {
        $offset = intval($_REQUEST['offset']);
    }
    if (isset($_REQUEST['f']) && $_REQUEST['f'] == "1") {
        $users = tdomf_get_users_banned($offset, $limit);
        $max = tdomf_get_users_banned_count();
    } else {
        if (isset($_REQUEST['f']) && $_REQUEST['f'] == "2") {
            $users = tdomf_get_users_trusted($offset, $limit);
            $max = tdomf_get_users_trusted_count();
        } else {
            $users = tdomf_get_users_submitted($offset, $limit);
            $max = tdomf_get_users_submitted_count();
        }
    }
    ?>

   <div class="wrap">

   <?php 
    if (isset($_REQUEST['f']) && $_REQUEST['f'] == "1") {
        ?>
       <h2><?php 
        if ($offset > 0) {
            _e("Previous Banned Users", "tdomf");
        } else {
            printf(__('Last %d Banned Users', 'tdomf'), $limit);
        }
        ?>
</h2>
   <?php 
    } else {
        if (isset($_REQUEST['f']) && $_REQUEST['f'] == "2") {
            ?>
       <h2><?php 
            if ($offset > 0) {
                _e("Previous Trusted Users", "tdomf");
            } else {
                printf(__('Last %d Trusted Users', 'tdomf'), $limit);
            }
            ?>
</h2>
   <?php 
        } else {
            ?>
       <h2><?php 
            if ($offset > 0) {
                _e("Previous Submitters", "tdomf");
            } else {
                printf(__('Last %d Submitters', 'tdomf'), $limit);
            }
            ?>
</h2>
   <?php 
        }
    }
    ?>

    <p><?php 
    _e("You can ban (and un-ban) any registered user. This means the user cannot use the forms. It has no impact on anything else. i.e. they can still read, comment and post. You can also make a user \"trusted\". This means that anything they submit using the form is automatically published.", "tdomf");
    ?>
</p>

    <p><a href="admin.php?page=tdomf_show_manage_menu&mode=ip"><?php 
    _e("Manage Submitter IPs &raquo;", "tdomf");
    ?>
</a>
    
   <form method="post" action="admin.php?page=tdomf_show_manage_menu" id="filterusers" name="filterusers" >
   <fieldset>
	  <b><?php 
    _e("Filter Users", "tdomf");
    ?>
</b>
      <select name="f">
      <option value="0" <?php 
    if (!isset($_REQUEST['f']) || isset($_REQUEST['f']) && $_REQUEST['f'] == "0") {
        ?>
 selected <?php 
    }
    ?>
><?php 
    _e("All Submitters", "tdomf");
    ?>
        <option value="1" <?php 
    if (isset($_REQUEST['f']) && $_REQUEST['f'] == "1") {
        ?>
 selected <?php 
    }
    ?>
><?php 
    _e("Banned Users", "tdomf");
    ?>
        <option value="2" <?php 
    if (isset($_REQUEST['f']) && $_REQUEST['f'] == "2") {
        ?>
 selected <?php 
    }
    ?>
><?php 
    _e("Trusted Users", "tdomf");
    ?>
      </select>
      <input type="submit" name="submit" value="Show" />
   </fieldset>
   </form>

   <br/>

   <?php 
    if (count($users) <= 0) {
        _e("There are no users to moderate with this filter.", "tdomf");
    } else {
        ?>

<script type="text/javascript">
<!--
function checkAll(form)
{
	for (i = 0, n = form.elements.length; i < n; i++) {
		if(form.elements[i].type == "checkbox") {
			if(form.elements[i].checked == true)
				form.elements[i].checked = false;
			else
				form.elements[i].checked = true;
		}
	}
}

function getNumChecked(form)
{
	var num = 0;
	for (i = 0, n = form.elements.length; i < n; i++) {
		if(form.elements[i].type == "checkbox") {
			if(form.elements[i].checked == true)
				num++;
		}
	}
	return num;
}
//-->
</script>


   <form method="post" action="admin.php?page=tdomf_show_manage_menu" id="moderateusers" name="moderateusers" >

   <table class="widefat">
   <tr>
    <th scope="col" style="text-align: center"><input type="checkbox" onclick="checkAll(document.getElementById('moderateusers'));" /></th>

    <th scope="col"><?php 
        _e("ID", "tdomf");
        ?>
</th>
	<th scope="col"><?php 
        _e("Login", "tdomf");
        ?>
</th>
	<th scope="col"><?php 
        _e("Display Name", "tdomf");
        ?>
</th>
	<th scope="col"><?php 
        _e("Role", "tdomf");
        ?>
</th>
	<th scope="col"><?php 
        _e("Status", "tdomf");
        ?>
</th>
    <th scope="col"><?php 
        _e("Submitted<br/>Approved/Total", "tdomf");
        ?>
</th>
    <th scope="col"><?php 
        _e("Contributed<br/>Approved/Total", "tdomf");
        ?>
</th>
    <th scope="col" colspan="2" style="text-align: center">Actions</th>
   </tr>

   <?php 
        $i = 0;
        foreach ($users as $u) {
            $i++;
            if ($i % 2 == 0) {
                ?>
		  <tr id='x' class=''>
	     <?php 
            } else {
                ?>
		  <tr id='x' class='alternate'>
         <?php 
            }
            ?>

               <?php 
            $u = get_userdata($u->user_id);
            ?>

               <td><input type="checkbox" name="moderateusers[]" value="<?php 
            echo $u->ID;
            ?>
" /></td>
               <th scope="row"><?php 
            echo $u->ID;
            ?>
</th>
		       <td><a href="edit.php?author=<?php 
            echo $u->ID;
            ?>
" ><?php 
            echo $u->user_login;
            ?>
</a></td>
		       <td><a href="user-edit.php?user_id=<?php 
            echo $u->ID;
            ?>
" ><?php 
            echo $u->display_name;
            ?>
</a></td>

               <td>
		       <?php 
            if (!isset($wp_roles)) {
                $wp_roles = new WP_Roles();
            }
            $roles = $wp_roles->role_objects;
            $userrole = new WP_User($u->ID);
            foreach ($roles as $role) {
                if ($userrole->has_cap($role->name)) {
                    if (function_exists('translate_with_context')) {
                        $user_role = translate_with_context($wp_roles->role_names[$role->name]);
                    } else {
                        $user_role = $wp_roles->role_names[$role->name];
                    }
                    break;
                }
            }
            ?>
		       <?php 
            echo $user_role;
            ?>
		       </td>

		       <td>
		       <?php 
            if ($userrole->has_cap('edit_others_posts')) {
                _e("N/A", "tdomf");
            } else {
                if (!get_usermeta($u->ID, TDOMF_KEY_STATUS)) {
                    _e("-", "tdomf");
                } else {
                    _e(get_usermeta($u->ID, TDOMF_KEY_STATUS), "tdomf");
                }
            }
            ?>
		       </td>

             <td>
             <a href="<?php 
            tdomf_get_mod_posts_url(array('echo' => true, 'user_id' => $u->ID));
            ?>
">
             <?php 
            echo tdomf_get_users_published_posts_count($u->ID);
            ?>
/<?php 
            echo tdomf_get_users_submitted_posts_count($u->ID);
            ?>
             </a>
             </td>

             <td><?php 
            echo tdomf_get_edits(array('user_id' => $u->ID, 'count' => true, 'state' => 'approved'));
            ?>
/<?php 
            echo tdomf_get_edits(array('user_id' => $u->ID, 'count' => true));
            ?>
</td>
                 
           <?php 
            if (isset($_REQUEST['f'])) {
                $farg = "&f=" . $_REQUEST['f'];
            }
            ?>
                 
                 
		       <td>
		       <?php 
            if ($userrole->has_cap('edit_others_posts')) {
                ?>
 N/A
		       <?php 
            } else {
                if (get_usermeta($u->ID, TDOMF_KEY_STATUS) == TDOMF_USER_STATUS_BANNED) {
                    ?>
             <a href="<?php 
                    echo wp_nonce_url("admin.php?page=tdomf_show_manage_menu&action=reset&user={$u->ID}{$farg}&offset={$offset}&limit={$limit}", 'tdomf-reset-user_' . $u->ID);
                    ?>
"><?php 
                    _e("Un-ban", "tdomf");
                    ?>
</a>
		       <?php 
                } else {
                    ?>
             <a href="<?php 
                    echo wp_nonce_url("admin.php?page=tdomf_show_manage_menu&action=ban&user={$u->ID}{$farg}&offset={$offset}&limit={$limit}", 'tdomf-ban-user_' . $u->ID);
                    ?>
"><?php 
                    _e("Ban", "tdomf");
                    ?>
</a>
           <?php 
                }
            }
            ?>
		       </td>

		       <td>
		       <?php 
            if ($userrole->has_cap('edit_others_posts')) {
                ?>
 N/A
		       <?php 
            } else {
                if (get_usermeta($u->ID, TDOMF_KEY_STATUS) == TDOMF_USER_STATUS_TRUSTED) {
                    ?>
             <a href="<?php 
                    echo wp_nonce_url("admin.php?page=tdomf_show_manage_menu&action=reset&user={$u->ID}{$farg}&offset={$offset}&limit={$limit}", 'tdomf-reset-user_' . $u->ID);
                    ?>
"><?php 
                    _e("Un-trust", "tdomf");
                    ?>
</a>
		       <?php 
                } else {
                    ?>
             <a href="<?php 
                    echo wp_nonce_url("admin.php?page=tdomf_show_manage_menu&action=trust&user={$u->ID}{$farg}&offset={$offset}&limit={$limit}", 'tdomf-trust-user_' . $u->ID);
                    ?>
"><?php 
                    _e("Trust", "tdomf");
                    ?>
</a>
           <?php 
                }
            }
            ?>
		       </td>

           </tr>

         <?php 
        }
        ?>

   </table>

   <?php 
        $farg = "0";
        if (isset($_REQUEST['f'])) {
            $farg = $_REQUEST['f'];
        }
        ?>

   <input type="hidden" name="limit" id="limit" value="<?php 
        echo $limit;
        ?>
" />
   <input type="hidden" name="offset" id="offset" value="<?php 
        echo $offset;
        ?>
" />
   <input type="hidden" name="f" id="f" value="<?php 
        echo $farg;
        ?>
" />
   <?php 
        if (function_exists('wp_nonce_field')) {
            wp_nonce_field('tdomf-manage-bulk_users');
        }
        ?>

   <p class="submit">
    <input type="submit" name="ban_button" class="delete" value="<?php 
        _e("Ban");
        ?>
" onclick="var numchecked = getNumChecked(document.getElementById('moderateusers')); if(numchecked < 1) { alert('Please select some users to ban'); return false } return confirm('You are about to ban ' + numchecked + ' users \n  \'Cancel\' to stop, \'OK\' to ban.')" />
    <input type="submit" name="trust_button" value="<?php 
        _e("Trust");
        ?>
" onclick="var numchecked = getNumChecked(document.getElementById('moderateusers')); if(numchecked < 1) { alert('Please select some users to trust'); return false } return confirm('You are about to trust ' + numchecked + ' users \n  \'Cancel\' to stop, \'OK\' to trust')" />
    <input type="submit" name="clear_button" value="<?php 
        _e("Reset");
        ?>
" onclick="var numchecked = getNumChecked(document.getElementById('moderateusers')); if(numchecked < 1) { alert('Please select some users to reset'); return false } return confirm('You are about to reset the status of ' + numchecked + ' users \n  \'Cancel\' to stop, \'OK\' to reset')" />
   </p>

   </form>

   <br/><br/>

   <div class="navigation">
   <?php 
        if ($max - ($offset + $limit) > 0) {
            ?>
      <div class="alignleft"><a href="admin.php?page=tdomf_show_manage_menu&offset=<?php 
            echo $offset + $limit;
            if (isset($_REQUEST['f'])) {
                echo "&f=" . $_REQUEST['f'];
            }
            ?>
">&laquo; <?php 
            _e("Previous Entries", "tdomf");
            ?>
</a></div>
   <?php 
        }
        ?>

   <?php 
        if ($offset > 0) {
            ?>
      <div class="alignright"><a href="admin.php?page=tdomf_show_manage_menu&offset=<?php 
            echo $offset - $limit;
            if (isset($_REQUEST['f'])) {
                echo "&f=" . $_REQUEST['f'];
            }
            ?>
"><?php 
            _e("Next Entries", "tdomf");
            ?>
 &raquo;</a></div>
   <?php 
        }
        ?>
   </div>

   <br/><br/>

   <?php 
    }
    ?>

   </div> <!-- wrap -->

   <?php 
}