Esempio n. 1
0
function tdomf_show_mod_posts_menu()
{
    tdomf_moderation_handler();
    $user_id = false;
    if (isset($_REQUEST['user_id'])) {
        $user_id = intval($_REQUEST['user_id']);
    }
    $ip = false;
    if (isset($_REQUEST['ip'])) {
        $ip = $_REQUEST['ip'];
    }
    $form_id = false;
    if (isset($_REQUEST['form_id'])) {
        $form_id = intval($_REQUEST['form_id']);
        if ($form_id <= 0) {
            $form_id = false;
        }
    }
    $pending_count = tdomf_get_posts(array('count' => true, 'post_status' => array('draft'), 'nospam' => true, 'form_id' => $form_id, 'user_id' => $user_id, 'ip' => $ip));
    $scheduled_count = tdomf_get_posts(array('count' => true, 'post_status' => array('future'), 'form_id' => $form_id, 'user_id' => $user_id, 'ip' => $ip));
    $published_count = tdomf_get_posts(array('count' => true, 'post_status' => array('publish'), 'form_id' => $form_id, 'user_id' => $user_id, 'ip' => $ip));
    $spam_count = tdomf_get_posts(array('count' => true, 'spam' => true, 'form_id' => $form_id, 'user_id' => $user_id, 'ip' => $ip));
    $all_count = tdomf_get_posts(array('count' => true, 'form_id' => $form_id, 'user_id' => $user_id, 'ip' => $ip));
    $form_ids = tdomf_get_form_ids();
    $pending_edits_count = tdomf_get_edits(array('state' => 'unapproved', 'count' => true, 'unique_post_ids' => true, 'form_id' => $form_id, 'user_id' => $user_id, 'ip' => $ip));
    $spam_edits_count = tdomf_get_edits(array('state' => 'spam', 'count' => true, 'unique_post_ids' => true, 'form_id' => $form_id, 'user_id' => $user_id, 'ip' => $ip));
    $approved_edits_count = tdomf_get_edits(array('state' => 'approved', 'count' => true, 'form_id' => $form_id, 'user_id' => $user_id, 'ip' => $ip));
    $limit = 10;
    # fixed
    if (isset($_REQUEST['limit'])) {
        $limit = intval($_REQUEST['limit']);
    }
    $paged = 1;
    if (isset($_GET['paged'])) {
        $paged = intval($_GET['paged']);
    }
    $offset = $limit * ($paged - 1);
    $show = 'all';
    if (isset($_REQUEST['show'])) {
        $show = $_REQUEST['show'];
    }
    $posts = false;
    $max_pages = 0;
    $max_items = 0;
    if ($show == 'all') {
        $posts = tdomf_get_posts(array('offset' => $offset, 'limit' => $limit, 'form_id' => $form_id, 'user_id' => $user_id, 'ip' => $ip));
        $max_pages = ceil($all_count / $limit);
        $max_items = $all_count;
    } else {
        if ($show == 'pending_submissions') {
            $posts = tdomf_get_posts(array('offset' => $offset, 'limit' => $limit, 'post_status' => array('draft'), 'nospam' => true, 'form_id' => $form_id, 'user_id' => $user_id, 'ip' => $ip));
            $max_pages = ceil($pending_count / $limit);
            $max_items = $pending_count;
        } else {
            if ($show == 'scheduled') {
                $posts = tdomf_get_posts(array('offset' => $offset, 'post_status' => array('future'), 'limit' => $limit, 'form_id' => $form_id, 'user_id' => $user_id, 'ip' => $ip));
                $max_pages = ceil($scheduled_count / $limit);
                $max_items = $scheduled_count;
            } else {
                if ($show == 'published') {
                    $posts = tdomf_get_posts(array('offset' => $offset, 'post_status' => array('publish'), 'limit' => $limit, 'form_id' => $form_id, 'user_id' => $user_id, 'ip' => $ip));
                    $max_pages = ceil($published_count / $limit);
                    $max_items = $published_count;
                } else {
                    if ($show == 'spam_submissions') {
                        $posts = tdomf_get_posts(array('offset' => $offset, 'spam' => true, 'limit' => $limit, 'form_id' => $form_id, 'user_id' => $user_id, 'ip' => $ip));
                        $max_pages = ceil($spam_count / $limit);
                        $max_items = $spam_count;
                    } else {
                        if ($show == 'pending_edits') {
                            $edits = tdomf_get_edits(array('state' => 'unapproved', 'unique_post_ids' => true, 'offset' => $offset, 'limit' => $limit, 'form_id' => $form_id, 'user_id' => $user_id, 'ip' => $ip));
                            $max_pages = ceil($pending_edits_count / $limit);
                            $posts = array();
                            # a little hacky magic
                            foreach ($edits as $e) {
                                $posts[] = (object) array('ID' => $e->post_id);
                            }
                            $max_items = $pending_edits_count;
                        } else {
                            if ($show == 'spam_edits') {
                                $edits = tdomf_get_edits(array('state' => 'spam', 'unique_post_ids' => true, 'offset' => $offset, 'limit' => $limit, 'form_id' => $form_id, 'user_id' => $user_id, 'ip' => $ip));
                                $max_pages = ceil($spam_edits_count / $limit);
                                $posts = array();
                                # a little hacky magic
                                foreach ($edits as $e) {
                                    $posts[] = (object) array('ID' => $e->post_id);
                                }
                                $max_items = $spam_edits_count;
                            } else {
                                if ($show == 'approved_edits') {
                                    $edits = tdomf_get_edits(array('state' => 'approved', 'offset' => $offset, 'limit' => $limit, 'form_id' => $form_id, 'user_id' => $user_id, 'ip' => $ip));
                                    $max_pages = ceil($approved_edits_count / $limit);
                                    $posts = array();
                                    # a little hacky magic
                                    foreach ($edits as $e) {
                                        $posts[] = (object) array('ID' => $e->post_id, 'edit_id' => $e->edit_id);
                                    }
                                    $max_items = $approved_edits_count;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    # max is incorrect... doesn't account for form filter...
    $mode = 'list';
    if (isset($_GET['mode'])) {
        $mode = $_GET['mode'];
    }
    $count = 0;
    # what bulk actions to support
    $bulk_sub_publish_now = false;
    $bulk_sub_publish = false;
    $bulk_sub_unpublish = false;
    $bulk_sub_spamit = false;
    $bulk_sub_hamit = false;
    $bulk_sub_lock = false;
    $bulk_sub_unlock = false;
    $bulk_edit_approve = false;
    $bulk_edit_revert = false;
    $bulk_edit_delete = false;
    $bulk_edit_spamit = false;
    $bulk_edit_hamit = false;
    ?>
   
   <div class="wrap">
   
   <?php 
    /* screen_icon(); */
    ?>
   <h2>
   <?php 
    if ($user_id || $ip) {
        if ($user_id) {
            $u = get_userdata($user_id);
            printf(__('Posts submitted by user %s', 'tdomf'), $u->user_login);
        } else {
            if ($ip) {
                printf(__('Posts submitted from IP %s', 'tdomf'), $ip);
            }
        }
    } else {
        ?>
   <?php 
        _e('Moderation', 'tdomf');
        ?>
   <?php 
    }
    ?>
   </h2>
   
   <?php 
    /*if(count($posts) <= 0) { ?>
         <div class="clear"></div>
         <p><?php _e('No submissions found','tdomf') ?></p>
         </div> <!-- wrap --><?php 
      return; }*/
    ?>
   
   <form id="posts-filter" action="<?php 
    tdomf_get_mod_posts_url(true, $show, 0);
    ?>
" method="post">
   
   <!-- hidden vars -->
   
   <ul class="subsubsub">
   <?php 
    if ($all_count > 0) {
        ?>
       <li><a href="<?php 
        tdomf_get_mod_posts_url(array('echo' => true, 'show' => 'all'));
        ?>
"<?php 
        if ($show == 'all') {
            ?>
 class="current"<?php 
        }
        ?>
><?php 
        printf(__('All Submissions (%s)', 'tdomf'), $all_count);
        ?>
</a> | </li>
   <?php 
    }
    ?>
       
   <?php 
    if ($pending_count > 0) {
        ?>
      <li><a href="<?php 
        tdomf_get_mod_posts_url(array('echo' => true, 'show' => 'pending_submissions'));
        ?>
"<?php 
        if ($show == 'pending_submissions') {
            ?>
 class="current"<?php 
        }
        ?>
><?php 
        printf(__('Pending Submissions (%s)', 'tdomf'), $pending_count);
        ?>
</a> | </li>
   <?php 
    }
    ?>
   <?php 
    if ($scheduled_count > 0) {
        ?>
      <li><a href="<?php 
        tdomf_get_mod_posts_url(array('echo' => true, 'show' => 'scheduled'));
        ?>
"<?php 
        if ($show == 'scheduled') {
            ?>
 class="current"<?php 
        }
        ?>
><?php 
        printf(__('Scheduled Submissions (%s)', 'tdomf'), $scheduled_count);
        ?>
</a> | </li>
   <?php 
    }
    ?>
   <?php 
    if ($published_count > 0) {
        ?>
       <li><a href="<?php 
        tdomf_get_mod_posts_url(array('echo' => true, 'show' => 'published'));
        ?>
"<?php 
        if ($show == 'published') {
            ?>
 class="current"<?php 
        }
        ?>
><?php 
        printf(__('Published (%s)', 'tdomf'), $published_count);
        ?>
</a> | </li>
   <?php 
    }
    ?>
   <?php 
    if ($spam_count > 0) {
        ?>
       <li><a href="<?php 
        tdomf_get_mod_posts_url(array('echo' => true, 'show' => 'spam_submissions'));
        ?>
"<?php 
        if ($show == 'spam_submissions') {
            ?>
 class="current"<?php 
        }
        ?>
><?php 
        printf(__('Spam Submissions (%s)', 'tdomf'), $spam_count);
        ?>
</a> | </li>
   <?php 
    }
    ?>
   <?php 
    if ($approved_edits_count > 0) {
        ?>
       <li><a href="<?php 
        tdomf_get_mod_posts_url(array('echo' => true, 'show' => 'approved_edits'));
        ?>
"<?php 
        if ($show == 'approved_edits') {
            ?>
 class="current"<?php 
        }
        ?>
><?php 
        printf(__('Approved Edits (%s)', 'tdomf'), $approved_edits_count);
        ?>
</a> | </li>
   <?php 
    }
    ?>
    
   <?php 
    if ($pending_edits_count > 0) {
        ?>
       <li><a href="<?php 
        tdomf_get_mod_posts_url(array('echo' => true, 'show' => 'pending_edits'));
        ?>
"<?php 
        if ($show == 'pending_edits') {
            ?>
 class="current"<?php 
        }
        ?>
><?php 
        printf(__('Pending Edits (%s)', 'tdomf'), $pending_edits_count);
        ?>
</a> | </li>
   <?php 
    }
    ?>
   <?php 
    if ($spam_edits_count > 0) {
        ?>
       <li><a href="<?php 
        tdomf_get_mod_posts_url(array('echo' => true, 'show' => 'spam_edits'));
        ?>
"<?php 
        if ($show == 'spam_edits') {
            ?>
 class="current"<?php 
        }
        ?>
><?php 
        printf(__('Spam Edits (%s)', 'tdomf'), $spam_edits_count);
        ?>
</a> | </li>
   <?php 
    }
    ?>
 
   </ul>

   <div class="tablenav">
   
   <?php 
    $page_links = paginate_links(array('base' => add_query_arg('paged', '%#%', tdomf_get_mod_posts_url(array())), 'format' => '', 'prev_text' => __('&laquo;'), 'next_text' => __('&raquo;'), 'total' => $max_pages, 'current' => $paged));
    ?>
    
<?php 
    if ($page_links) {
        ?>
<div class="tablenav-pages"><?php 
        $page_links_text = sprintf('<span class="displaying-num">' . __('Displaying %s&#8211;%s of %s') . '</span>%s', number_format_i18n($offset), number_format_i18n($offset + count($posts)), number_format_i18n($max_items), $page_links);
        echo $page_links_text;
        ?>
</div>
<?php 
    }
    ?>

<div class="view-switch">
	<a href="<?php 
    tdomf_get_mod_posts_url(array('echo' => true, 'mode' => 'list'));
    ?>
"><img <?php 
    if ('list' == $mode) {
        echo 'class="current"';
    }
    ?>
 id="view-switch-list" src="../wp-includes/images/blank.gif" width="20" height="20" title="<?php 
    _e('List View');
    ?>
" alt="<?php 
    _e('List View');
    ?>
" /></a>
	<a href="<?php 
    tdomf_get_mod_posts_url(array('echo' => true, 'mode' => 'excerpt'));
    ?>
"><img <?php 
    if ('excerpt' == $mode) {
        echo 'class="current"';
    }
    ?>
 id="view-switch-excerpt" src="../wp-includes/images/blank.gif" width="20" height="20" title="<?php 
    _e('Excerpt View');
    ?>
" alt="<?php 
    _e('Excerpt View');
    ?>
" /></a>
</div>
    
    <?php 
    $form_ids_check = array();
    foreach ($form_ids as $form) {
        if (TDOMF_Widget::isSubmitForm(false, $form->form_id)) {
            $count = tdomf_get_posts(array('count' => true, 'form_id' => $form->form_id));
        } else {
            $count = tdomf_get_edits(array('count' => true, 'form_id' => $form->form_id));
        }
        if ($count > 0) {
            $form_ids_check[] = $form->form_id;
        }
    }
    if (!empty($form_ids_check)) {
        ?>
              <select name='form_id'>
                 <option value="-1" selected="selected"><?php 
        _e('Show All', 'tdomf');
        ?>
</option>
                 <?php 
        foreach ($form_ids_check as $form) {
            ?>
 
                        <option value="<?php 
            echo $form;
            ?>
" <?php 
            if ($form_id == $form) {
                ?>
 selected="selected" <?php 
            }
            ?>
><?php 
            printf(__('Form #%d', 'tdomf'), $form);
            ?>
</option>
                <?php 
        }
        ?>
              </select>
              <input type="submit" id="post-query-submit" value="<?php 
        _e('Filter');
        ?>
" class="button-secondary" />
     <?php 
    }
    ?>
    
<div class="clear"></div>

</div> <!-- tablenav -->

<div class="clear"></div>

<table class="widefat post fixed" cellspacing="0">

	<thead>
	<tr>
	<th scope="col" id="cb" class="manage-column column-cb check-column" style=""><input type="checkbox" /></th>
	<th scope="col" id="title" class="manage-column column-title" style=""><?php 
    _e('Post', 'tdomf');
    ?>
</th>
	<th scope="col" id="submitted" class="manage-column column-submitted" style=""><?php 
    _e('Submitted', 'tdomf');
    ?>
</th>
	<th scope="col" id="edited" class="manage-column column-edited" style="">
    <?php 
    if ($show == 'approved_edits') {
        _e('Edit', 'tdomf');
    } else {
        if ($show == 'pending_edits') {
            _e('Pending Edit', 'tdomf');
        } else {
            if ($show == 'spam_edits') {
                _e('Spam Edit', 'tdomf');
            } else {
                _e('Most Recent Edit', 'tdomf');
            }
        }
    }
    ?>
</th>
	<th scope="col" id="status" class="manage-column column-status" style=""><?php 
    _e('Status', 'tdomf');
    ?>
</th>
	</tr>
	</thead>

	<tfoot>
	<tr>
	<th scope="col" id="cb" class="manage-column column-cb check-column" style=""><input type="checkbox" /></th>
	<th scope="col" id="title" class="manage-column column-title" style=""><?php 
    _e('Post', 'tdomf');
    ?>
</th>
	<th scope="col" id="submitted" class="manage-column column-submitted" style=""><?php 
    _e('Submitted', 'tdomf');
    ?>
</th>
	<th scope="col" id="edited" class="manage-column column-edited" style="">
    <?php 
    if ($show == 'approved_edits') {
        _e('Edit', 'tdomf');
    } else {
        if ($show == 'pending_edits') {
            _e('Pending Edit', 'tdomf');
        } else {
            if ($show == 'spam_edits') {
                _e('Spam Edit', 'tdomf');
            } else {
                _e('Most Recent Edit', 'tdomf');
            }
        }
    }
    ?>
</th>
	<th scope="col" id="status" class="manage-column column-status" style=""><?php 
    _e('Status', 'tdomf');
    ?>
</th>
	</tr>
	</tfoot>
    
    <tbody>
    <?php 
    if (!empty($posts)) {
        foreach ($posts as $p) {
            $count++;
            ?>

        <?php 
            $post =& get_post($p->ID);
            /* seems I need this later */
            ?>
 
        <?php 
            if ($show == 'approved_edits') {
                // not really the "last" edit but lest pretend
                $last_edit = array(tdomf_get_edit($p->edit_id));
            } else {
                $last_edit = tdomf_get_edits(array('post_id' => $p->ID, 'limit' => 2));
                /* and need this earlier too */
            }
            ?>
        <?php 
            $form_id = get_post_meta($p->ID, TDOMF_KEY_FORM_ID, true);
            ?>
        <?php 
            $queue = intval(tdomf_get_option_form(TDOMF_OPTION_QUEUE_PERIOD, $form_id));
            if ($queue > 0) {
                $queue = true;
            } else {
                $queue = false;
            }
            ?>
        <?php 
            $is_spam = get_post_meta($p->ID, TDOMF_KEY_SPAM);
            ?>
        <?php 
            $locked = get_post_meta($post->ID, TDOMF_KEY_LOCK, true);
            ?>

        <tr id='post-<?php 
            echo $p->ID;
            ?>
' class='<?php 
            if ($count % 2 != 0) {
                ?>
alternate <?php 
            }
            ?>
status-<?php 
            echo $post->post_status;
            ?>
 iedit' valign="top">

        <th scope="row" class="check-column"><input type="checkbox" name="post[]" value="<?php 
            echo $p->ID;
            ?>
" /></th>
        <td class="post-title column-title"><strong><a class="row-title" href="post.php?action=edit&amp;post=<?php 
            echo $p->ID;
            ?>
" title="Edit"><?php 
            echo $post->post_title;
            ?>
</a></strong>

        <?php 
            /*$fuoptions = TDOMF_WidgetUploadFiles::getOptions($form_id);*/
            $index = 0;
            $filelinks = "";
            while (true) {
                $filename = get_post_meta($p->ID, TDOMF_KEY_DOWNLOAD_NAME . $index, true);
                if ($filename == false) {
                    break;
                }
                /*if($fuoptions['nohandler'] && trim($fuoptions['url']) != "") {
                      $uri = trailingslashit($fuoptions['url'])."$p->ID/".$filename;
                  } else {*/
                $uri = trailingslashit(get_bloginfo('wpurl')) . '?tdomf_download=' . $p->ID . '&id=' . $i;
                /*}*/
                $filelinks .= "<a href='{$uri}' title='" . htmlentities($filename) . "'>{$index}</a>, ";
                $index++;
            }
            if (!empty($filelinks)) {
                ?>
                 <?php 
                _e('Uploaded Files: ', 'tdomf');
                echo $filelinks;
                ?>
<br/>
             <?php 
            }
            ?>
  
        <?php 
            if ('excerpt' == $mode) {
                # Have to create our own excerpt, the_excerpt() doesn't cut it
                # here :(
                if (empty($post->post_excerpt)) {
                    $excerpt = apply_filters('the_content', $post->post_content);
                } else {
                    $excerpt = apply_filters('the_excerpt', $post->post_excerpt);
                }
                $excerpt = str_replace(']]>', ']]&gt;', $excerpt);
                $excerpt = wp_html_excerpt($excerpt, 252);
                if (strlen($excerpt) == 252) {
                    $excerpt .= '...';
                }
                echo '<blockquote>' . $excerpt . '</blockquote>';
            }
            ?>
        
        <?php 
            if (get_option(TDOMF_OPTION_MOD_SHOW_LINKS)) {
                ?>
        <div>
        <?php 
            } else {
                ?>
        <div class="row-actions">
        <?php 
            }
            ?>
           <?php 
            if ($post->post_status == 'future') {
                $bulk_sub_publish_now = true;
                ?>
               <span class="publish"><a href="<?php 
                tdomf_get_mod_posts_url(array('echo' => true, 'action' => 'publish_now', 'post_id' => $p->ID, 'nonce' => 'tdomf-publish_' . $p->ID));
                ?>
" title="<?php 
                echo htmlentities(__('Publish this submission now', 'tdomf'));
                ?>
"><?php 
                _e('Publish Now', 'tdomf');
                ?>
</a> |</span>
           <?php 
            } else {
                if ($post->post_status != 'publish') {
                    ?>
               <?php 
                    if ($queue) {
                        $bulk_sub_publish_now = true;
                        $bulk_sub_publish = true;
                        ?>
                   <span class="publish"><a href="<?php 
                        tdomf_get_mod_posts_url(array('echo' => true, 'action' => 'publish', 'post_id' => $p->ID, 'nonce' => 'tdomf-publish_' . $p->ID));
                        ?>
" title="<?php 
                        echo htmlentities(__('Add submission to publish queue', 'tdomf'));
                        ?>
"><?php 
                        _e('Queue', 'tdomf');
                        ?>
</a> |</span>
                   <span class="publish"><a href="<?php 
                        tdomf_get_mod_posts_url(array('echo' => true, 'action' => 'publish_now', 'post_id' => $p->ID, 'nonce' => 'tdomf-publish_' . $p->ID));
                        ?>
" title="<?php 
                        echo htmlentities(__('Publish submission now', 'tdomf'));
                        ?>
"><?php 
                        _e('Publish Now', 'tdomf');
                        ?>
</a> |</span>
               <?php 
                    } else {
                        $bulk_sub_publish = true;
                        ?>
                   <span class="publish"><a href="<?php 
                        tdomf_get_mod_posts_url(array('echo' => true, 'action' => 'publish_now', 'post_id' => $p->ID, 'nonce' => 'tdomf-publish_' . $p->ID));
                        ?>
" title="<?php 
                        echo htmlentities(__('Publish submission', 'tdomf'));
                        ?>
"><?php 
                        _e('Publish', 'tdomf');
                        ?>
</a> |</span>
               <?php 
                    }
                    ?>
           <?php 
                } else {
                    if ($post->post_status == 'publish') {
                        $bulk_sub_unpublish = true;
                        ?>
               <span class="publish"><a href="<?php 
                        tdomf_get_mod_posts_url(array('echo' => true, 'action' => 'unpublish', 'post_id' => $p->ID, 'nonce' => 'tdomf-unpublish_' . $p->ID));
                        ?>
" title="<?php 
                        echo htmlentities(__('Set submission to draft/unmoderated status.', 'tdomf'));
                        ?>
"><?php 
                        _e('Un-publish', 'tdomf');
                        ?>
</a> |</span>
           <?php 
                    }
                }
            }
            ?>
           <span class='delete'><a class='submitdelete' title='Delete this submission' href='<?php 
            echo wp_nonce_url("post.php?action=delete&amp;post={$p->ID}", 'delete-post_' . $p->ID);
            ?>
' onclick="if ( confirm('<?php 
            echo js_escape(sprintf(__("You are about to delete this post \\'%s\\'\n \\'Cancel\\' to stop, \\'OK\\' to delete.", 'tdomf'), $post->post_title));
            ?>
') ) { return true;}return false;"><?php 
            _e('Delete', 'tdomf');
            ?>
</a> | </span>
           <?php 
            if ($locked) {
                $bulk_sub_unlock = true;
                ?>
               <span class="lock"><a href="<?php 
                tdomf_get_mod_posts_url(array('echo' => true, 'action' => 'unlock', 'post_id' => $p->ID, 'nonce' => 'tdomf-unlock_' . $p->ID));
                ?>
" title="<?php 
                echo htmlentities(__('Unlock submission so it can be edited.', 'tdomf'));
                ?>
"><?php 
                _e('Unlock', 'tdomf');
                ?>
</a> |</span>
           <?php 
            } else {
                $bulk_sub_lock = true;
                ?>
               <span class="lock"><a href="<?php 
                tdomf_get_mod_posts_url(array('echo' => true, 'action' => 'lock', 'post_id' => $p->ID, 'nonce' => 'tdomf-lock_' . $p->ID));
                ?>
" title="<?php 
                echo htmlentities(__('Lock submission from being edited.', 'tdomf'));
                ?>
"><?php 
                _e('Lock', 'tdomf');
                ?>
</a> |</span>               
           <?php 
            }
            ?>
           <?php 
            if ($post->post_status == 'publish') {
                ?>
            <span class='view'><a href="<?php 
                echo get_permalink($p->ID);
                ?>
" title="<?php 
                echo htmlentities(sprintf(__('View \'%s\'', 'tdomf'), $post->post_title));
                ?>
" rel="permalink"><?php 
                _e('View', 'tdomf');
                ?>
</a> | </span>
           <?php 
            } else {
                ?>
            <span class='view'><a href="<?php 
                echo get_permalink($p->ID);
                ?>
" title="<?php 
                echo htmlentities(sprintf(__('Preview \'%s\'', 'tdomf'), $post->post_title));
                ?>
" rel="permalink"><?php 
                _e('Preview', 'tdomf');
                ?>
</a> | </span>               
           <?php 
            }
            ?>
            <span class='edit'><a href="post.php?action=edit&amp;post=<?php 
            echo $p->ID;
            ?>
" title="<?php 
            echo htmlentities(__('Edit this submission', 'tdomf'));
            ?>
"><?php 
            _e('Edit', 'tdomf');
            ?>
</a>
           <?php 
            if (get_option(TDOMF_OPTION_SPAM)) {
                ?>
 |</span><?php 
            }
            ?>
           <?php 
            if (get_option(TDOMF_OPTION_SPAM)) {
                if (!$is_spam) {
                    $bulk_sub_spamit = true;
                    ?>
               <span class="spam"><a href="<?php 
                    tdomf_get_mod_posts_url(array('echo' => true, 'action' => 'spamit', 'post_id' => $p->ID, 'nonce' => 'tdomf-spamit_' . $p->ID));
                    ?>
" onclick="if ( confirm('<?php 
                    echo js_escape(sprintf(__("You are about to flag this submission \\'%s\\' as spam\n \\'Cancel\\' to stop, \\'OK\\' to delete.", 'tdomf'), $post->post_title));
                    ?>
') ) { return true;}return false;"><?php 
                    _e('Spam', 'tdomf');
                    ?>
</a></span>
           <?php 
                } else {
                    $bulk_sub_hamit = true;
                    ?>
              <span class="spam"><a href="<?php 
                    tdomf_get_mod_posts_url(array('echo' => true, 'action' => 'hamit', 'post_id' => $p->ID, 'nonce' => 'tdomf-hamit_' . $p->ID));
                    ?>
" ><?php 
                    _e('Not Spam', 'tdomf');
                    ?>
</span>
           <?php 
                }
            }
            ?>
        </div>
        </td>
        
        <td class="column-submitted">
       
        <ul style="font-size: 11px;">
        <li>
        <?php 
            $name = get_post_meta($p->ID, TDOMF_KEY_NAME, true);
            $email = get_post_meta($p->ID, TDOMF_KEY_EMAIL, true);
            $user_id = get_post_meta($p->ID, TDOMF_KEY_USER_ID, true);
            if ($user_id != false) {
                ?>
                 <!-- <a href="user-edit.php?user_id=<?php 
                echo $user_id;
                ?>
" class="edit"> -->
                 <a href="<?php 
                tdomf_get_mod_posts_url(array('echo' => true, 'user_id' => $user_id, 'ip' => false, 'form_id' => false));
                ?>
">
                 <?php 
                $u = get_userdata($user_id);
                echo $u->user_login;
                ?>
</a>
                 <?php 
            } else {
                if (!empty($name) && !empty($email)) {
                    echo $name . " (" . $email . ")";
                } else {
                    if (!empty($name)) {
                        echo $name;
                    } else {
                        if (!empty($email)) {
                            echo $email;
                        } else {
                            _e("N/A", "tdomf");
                        }
                    }
                }
            }
            ?>
                 / <?php 
            $ip = get_post_meta($p->ID, TDOMF_KEY_IP, true);
            if (!empty($ip)) {
                ?>
           <a href="<?php 
                tdomf_get_mod_posts_url(array('echo' => true, 'ip' => $ip, 'user_id' => false, 'form_id' => false));
                ?>
">
                 <?php 
            }
            ?>
 <?php 
            echo $ip;
            ?>
 <?php 
            if (!empty($ip)) {
                ?>
 </a> <?php 
            }
            ?>
         </li>
        <li>
        <?php 
            if ($form_id == false || tdomf_form_exists($form_id) == false) {
                ?>
                 <?php 
                _e("Unknown or deleted form", "tdomf");
                ?>
              <?php 
            } else {
                $form_edit_url = "admin.php?page=tdomf_show_form_options_menu&form={$form_id}";
                $form_name = tdomf_get_option_form(TDOMF_OPTION_NAME, $form_id);
                echo '<a href="' . $form_edit_url . '">' . sprintf(__('Form #%d: %s</a>', 'tdomf'), $form_id, $form_name) . '</a>';
            }
            ?>
        </li>
        <li>
        <?php 
            if ($post->post_status != 'publish' && $post->post_status != 'future') {
                $post_date_gmt = get_post_meta($p->ID, TDOMF_KEY_SUBMISSION_DATE, true);
                if ($post_date_gmt) {
                    echo mysql2date(__('Y/m/d'), $post_date_gmt);
                } else {
                    #echo mysql2date(__('Y/m/d'), $post->post_modified_gmt);
                }
            } else {
                echo mysql2date(__('Y/m/d'), $post->post_date_gmt);
            }
            ?>
        </li>
        </ul>
        </td>

        <td class="column-edited">
        <?php 
            /*$last_edit = tdomf_get_edits(array('post_id' => $p->ID, 'limit' => 1));*/
            if ($last_edit == false || empty($last_edit) || $last_edit == NULL) {
                ?>
                        <!-- no edits -->
        <?php 
            } else {
                $previous_edit = false;
                if (count($last_edit) == 2) {
                    $previous_edit = $last_edit[1];
                }
                $last_edit = $last_edit[0];
                # only care about the first entry
                $last_edit_data = maybe_unserialize($last_edit->data);
                ?>
        <ul style="font-size: 11px;">
        <li><?php 
                $user_id = $last_edit->user_id;
                $name = __("N/A", "tdomf");
                if (isset($last_edit_data[TDOMF_KEY_NAME])) {
                    $name = $last_edit_data[TDOMF_KEY_NAME];
                }
                $email = __("N/A", "tdomf");
                if (isset($last_edit_data[TDOMF_KEY_EMAIL])) {
                    $email = $last_edit_data[TDOMF_KEY_EMAIL];
                }
                if ($user_id != 0) {
                    ?>
                 <a href="user-edit.php?user_id=<?php 
                    echo $user_id;
                    ?>
" class="edit">
                 <?php 
                    $u = get_userdata($user_id);
                    echo $u->user_login;
                    ?>
</a>
                 <?php 
                } else {
                    if (!empty($name) && !empty($email)) {
                        echo $name . " (" . $email . ")";
                    } else {
                        if (!empty($name)) {
                            echo $name;
                        } else {
                            if (!empty($email)) {
                                echo $email;
                            } else {
                                _e("N/A", "tdomf");
                            }
                        }
                    }
                }
                ?>
         / <?php 
                echo $last_edit->ip;
                ?>
         </li>
        <li>
        <?php 
                $form_id = $last_edit->form_id;
                if ($form_id == false || tdomf_form_exists($form_id) == false) {
                    ?>
                 <?php 
                    _e("Unknown or deleted form", "tdomf");
                    ?>
              <?php 
                } else {
                    $form_edit_url = "admin.php?page=tdomf_show_form_options_menu&form={$form_id}";
                    $form_name = tdomf_get_option_form(TDOMF_OPTION_NAME, $form_id);
                    echo '<a href="' . $form_edit_url . '">' . sprintf(__('Form #%d: %s', 'tdomf'), $form_id, $form_name) . '</a>';
                }
                ?>
         </li>
         <li><?php 
                echo mysql2date(__('Y/m/d'), $last_edit->date_gmt);
                ?>
</li>
        <li><?php 
                switch ($last_edit->state) {
                    case 'unapproved':
                        _e('Unapproved', "tdomf");
                        break;
                    case 'approved':
                        _e('Approved', "tdomf");
                        break;
                    case 'spam':
                        _e('Spam', "tdomf");
                        break;
                    default:
                        echo _e($last_edit->state, "tdomf");
                        break;
                }
                ?>
         </li>
        </ul>
        
        <div class="row-actions">
        
        <?php 
                /* nothing to do if revisioning is disabled for the edits... */
                if ($last_edit->revision_id != 0) {
                    ?>
        
           <?php 
                    if ($last_edit->state != 'approved') {
                        ?>
              <span class='view'><a href="admin.php?page=<?php 
                        echo TDOMF_FOLDER . DIRECTORY_SEPARATOR . "admin" . DIRECTORY_SEPARATOR . 'tdomf-revision.php&edit=' . $last_edit->edit_id;
                        ?>
"><?php 
                        _e('View', 'tdomf');
                        ?>
</a> |<span>
              <!-- <span class='view'><a href="revision.php?revision=<?php 
                        echo $last_edit->revision_id;
                        ?>
"><?php 
                        _e('View', 'tdomf');
                        ?>
</a> |<span> -->
           <?php 
                    }
                    ?>
 
           <?php 
                    if ($last_edit->state == 'approved') {
                        $bulk_edit_revert = true;
                        ?>
              <span class="edit"><a href="<?php 
                        tdomf_get_mod_posts_url(array('echo' => true, 'action' => 'revert_edit', 'edit_id' => $last_edit->edit_id, 'nonce' => 'tdomf-revert_edit_' . $last_edit->edit_id));
                        ?>
"><?php 
                        _e('Revert', 'tdomf');
                        ?>
</a> | </span>
           <?php 
                    } else {
                        if ($last_edit->state == 'unapproved' || $last_edit->state == 'spam') {
                            $bulk_edit_delete = true;
                            $bulk_edit_approve = true;
                            ?>
               <span class="delete"><a href="<?php 
                            tdomf_get_mod_posts_url(array('echo' => true, 'action' => 'delete_edit', 'edit_id' => $last_edit->edit_id, 'nonce' => 'tdomf-delete_edit_' . $last_edit->edit_id));
                            ?>
"><?php 
                            _e('Delete', 'tdomf');
                            ?>
</a> | </span>
               <span class="edit"><a href="<?php 
                            tdomf_get_mod_posts_url(array('echo' => true, 'action' => 'approve_edit', 'edit_id' => $last_edit->edit_id, 'nonce' => 'tdomf-approve_edit_' . $last_edit->edit_id));
                            ?>
"><?php 
                            _e('Approve', 'tdomf');
                            ?>
</a> | </span>
           <?php 
                        }
                    }
                    ?>
           <?php 
                    if ($previous_edit) {
                        ?>
               <span class="edit"><a href="admin.php?page=<?php 
                        echo TDOMF_FOLDER . DIRECTORY_SEPARATOR . "admin" . DIRECTORY_SEPARATOR . 'tdomf-revision.php&edit=' . $last_edit->edit_id;
                        ?>
&right=<?php 
                        echo $last_edit->edit_id;
                        ?>
&left=<?php 
                        echo $previous_edit->edit_id;
                        ?>
"><?php 
                        _e('Compare', 'tdomf');
                        ?>
</a>
           <?php 
                    } else {
                        ?>
               <!-- <span class="edit"><a href="revision.php?action=diff&right=<?php 
                        echo $last_edit->revision_id;
                        ?>
&left=<?php 
                        echo $last_edit->current_revision_id;
                        ?>
"><?php 
                        _e('Compare', 'tdomf');
                        ?>
</a> -->
               <span class="edit"><a href="admin.php?page=<?php 
                        echo TDOMF_FOLDER . DIRECTORY_SEPARATOR . "admin" . DIRECTORY_SEPARATOR . 'tdomf-revision.php&edit=' . $last_edit->edit_id;
                        ?>
&right=<?php 
                        echo $last_edit->edit_id;
                        ?>
&left=previous"><?php 
                        _e('Compare', 'tdomf');
                        ?>
</a>
           <?php 
                    }
                    ?>
        <?php 
                    if (get_option(TDOMF_OPTION_SPAM)) {
                        ?>
 |<?php 
                    }
                    ?>
</span>           
        <?php 
                    if (get_option(TDOMF_OPTION_SPAM)) {
                        if ($last_edit->state == 'spam') {
                            $bulk_edit_hamit = true;
                            ?>
             <span class="spam"><a href="<?php 
                            tdomf_get_mod_posts_url(array('echo' => true, 'action' => 'hamit_edit', 'edit_id' => $last_edit->edit_id, 'nonce' => 'tdomf-hamit_edit_' . $last_edit->edit_id));
                            ?>
" title="<?php 
                            echo htmlentities(__('Flag contributation as not being spam', 'tdomf'));
                            ?>
" ><?php 
                            _e('Not Spam', 'tdomf');
                            ?>
</span>
         <?php 
                        } else {
                            $bulk_edit_spamit = true;
                            ?>
              <span class="spam"><a href="<?php 
                            tdomf_get_mod_posts_url(array('echo' => true, 'action' => 'spamit_edit', 'edit_id' => $last_edit->edit_id, 'nonce' => 'tdomf-spamit_edit_' . $last_edit->edit_id));
                            ?>
" title="<?php 
                            echo htmlentities(__('Flag contributation as being spam', 'tdomf'));
                            ?>
" onclick="if ( confirm('<?php 
                            echo js_escape(__("You are about to flag this contribution as spam\n \\'Cancel\\' to stop, \\'OK\\' to delete.", 'tdomf'));
                            ?>
') ) { return true;}return false;"><?php 
                            _e('Spam', 'tdomf');
                            ?>
</a></span>
        <?php 
                        }
                    }
                    ?>
        
        <?php 
                }
                ?>
            
           </div>
        
        <?php 
            }
            ?>
        
        </td>
        
         <td class="status column-status">
         <!-- todo take into account edited status -->
         <?php 
            if ($is_spam && $post->post_status == 'draft') {
                ?>
                      <?php 
                _e('Spam', "tdomf");
                ?>
                   <?php 
            } else {
                switch ($post->post_status) {
                    case 'draft':
                        _e('Draft', "tdomf");
                        break;
                    case 'publish':
                        _e('Published', "tdomf");
                        break;
                    case 'future':
                        _e('Scheduled', "tdomf");
                        break;
                    default:
                        echo _e($post->post_status, "tdomf");
                        break;
                }
                if ($is_spam) {
                    _e(' (Spam)', "tdomf");
                }
                if ($locked) {
                    _e(' [Locked]', 'tdomf');
                }
            }
            ?>
         </td>
    <?php 
        }
    }
    ?>
    
    </tbody>
    
</table>

<div class="tablenav">

<?php 
    if ($page_links) {
        echo "<div class='tablenav-pages'>{$page_links_text}</div>";
    }
    ?>
         
<?php 
    if (count($posts) > 0) {
        ?>
    <div class="alignleft actions">
    <select name="action">
    <option value="-1" selected="selected"><?php 
        _e('Bulk Actions');
        ?>
</option>
    <?php 
        if ($bulk_sub_publish_now) {
            ?>
       <option value="publish_now"><?php 
            _e('Publish Submissions (Now)', 'tdomf');
            ?>
</option>
    <?php 
        }
        ?>
    <?php 
        if ($bulk_sub_publish) {
            ?>
       <option value="publish"><?php 
            _e('Publish/Queue Submissions', 'tdomf');
            ?>
</option>
    <?php 
        }
        ?>
    <?php 
        if ($bulk_sub_unpublish) {
            ?>
       <option value="unpublish"><?php 
            _e('Un-publish Submissions', 'tdomf');
            ?>
</option>
    <?php 
        }
        ?>
    <option value="delete"><?php 
        _e('Delete Submissions', 'tdomf');
        ?>
</option>
    <?php 
        if ($bulk_sub_unlock) {
            ?>
        <option value="unlock"><?php 
            _e('Unlock Submissions', 'tdomf');
            ?>
</option>
    <?php 
        }
        ?>
    <?php 
        if ($bulk_sub_lock) {
            ?>
        <option value="lock"><?php 
            _e('Lock Submissions', 'tdomf');
            ?>
</option>
    <?php 
        }
        ?>
    <?php 
        if ($bulk_sub_spamit) {
            ?>
       <option value="spamit"><?php 
            _e('Mark Submissions as Spam', 'tdomf');
            ?>
</option>
    <?php 
        }
        ?>
    <?php 
        if ($bulk_sub_hamit) {
            ?>
       <option value="hamit"><?php 
            _e('Mark Submissions as Not Spam', 'tdomf');
            ?>
</option>
    <?php 
        }
        ?>
    <?php 
        if ($bulk_sub_hamit || $bulk_sub_spamit) {
            ?>
       <option value="spam_recheck"><?php 
            _e('Recheck Submssions for Spam', 'tdomf');
            ?>
</option>
    <?php 
        }
        ?>
    <?php 
        if ($bulk_edit_approve) {
            ?>
        <option value="edit_approve"><?php 
            _e('Approve Edits', 'tdomf');
            ?>
</option>
    <?php 
        }
        ?>
    <?php 
        if ($bulk_edit_revert) {
            ?>
        <option value="edit_revert"><?php 
            _e('Revert Edits', 'tdomf');
            ?>
</option>
    <?php 
        }
        ?>
   
    <?php 
        if ($bulk_edit_delete) {
            ?>
        <option value="edit_delete"><?php 
            _e('Delete Edits', 'tdomf');
            ?>
</option>
    <?php 
        }
        ?>
     
    <?php 
        if ($bulk_edit_spamit) {
            ?>
        <option value="edit_spamit"><?php 
            _e('Mark Edits as Spam', 'tdomf');
            ?>
</option>
    <?php 
        }
        ?>
     
    <?php 
        if ($bulk_edit_hamit) {
            ?>
        <option value="edit_hamit"><?php 
            _e('Mark Edits as not Spam', 'tdomf');
            ?>
</option>
    <?php 
        }
        ?>
     
    <?php 
        if ($bulk_edit_hamit || $bulk_edit_spamit) {
            ?>
       <option value="edit_spam_recheck"><?php 
            _e('Recheck Edits for Spam', 'tdomf');
            ?>
</option>
    <?php 
        }
        ?>
    </select>
    <input type="submit" value="<?php 
        _e('Apply');
        ?>
" name="doaction" id="doaction" class="button-secondary action" />
    <?php 
        wp_nonce_field('tdomf-moderate-bulk');
    }
    ?>

    <!-- hide filters
    
    <select name='form'>
    <option value="-1" selected="selected"><?php 
    _e('Show All Forms', 'tdomf');
    ?>
</option>
    <?php 
    foreach ($form_ids as $form) {
        ?>
       <option value="<?php 
        echo $form->form_id;
        ?>
"><?php 
        printf(__('Form #%d', 'tdomf'), $form->form_id);
        ?>
</option>
    <?php 
    }
    ?>
    </select>
    
    -->
    
    <br class="clear" />

    </div> <!-- tablenav -->
    
    <br class="clear" />
    
</div> <!-- wrap -->

</form>

   <?php 
}
Esempio n. 2
0
function tdomf_full_uninstall()
{
    // Delete Posts
    //
    echo "<span style='width:200px;'>";
    _e("Removing posts submitted or managed by TDO Mini Forms (this may take a few minutes depending on the number of posts)... ", "tdomf");
    echo "</span>";
    $posts = tdomf_get_all_posts();
    foreach ($posts as $post) {
        delete_option(TDOMF_NOTIFY . $post->ID);
        $tdomf_flag = get_post_meta($post->ID, TDOMF_KEY_FLAG, true);
        if (!empty($tdomf_flag)) {
            wp_delete_post($post->ID);
        }
    }
    echo "<span style='color:green;'>";
    _e("DONE", "tdomf");
    echo "</span><br/>";
    // Delete Created Users
    //
    echo "<span style='width:200px;'>";
    _e("Attempting to delete any users created by TDOMF... ", "tdomf");
    echo "</span>";
    $users = get_option(TDOMF_OPTION_CREATEDUSERS);
    if ($users != false) {
        foreach ($users as $u) {
            wp_delete_user($u);
        }
    }
    echo "<span style='color:green;'>";
    _e("DONE", "tdomf");
    echo "</span><br/>";
    // Strip existing Users
    //
    echo "<span style='width:200px;'>";
    _e("Removing info from remaining users (this may take a few minutes depending on number of users)... ", "tdomf");
    echo "</span>";
    $users = tdomf_get_all_users();
    foreach ($users as $user) {
        delete_usermeta($user->ID, TDOMF_KEY_FLAG);
        delete_usermeta($user->ID, TDOMF_KEY_STATUS);
    }
    echo "<span style='color:green;'>";
    _e("DONE", "tdomf");
    echo "</span><br/>";
    // Delete Forms
    //
    $form_ids = tdomf_get_form_ids();
    foreach ($form_ids as $f) {
        echo "<span style='width:200px;'>";
        printf(__("Deleting Form %d... ", "tdomf"), $f->form_id);
        echo "</span>";
        if (tdomf_delete_form($f->form_id)) {
            echo "<span style='color:green;'>";
            _e("DONE", "tdomf");
        } else {
            echo "<span style='color:red;'>";
            _e("FAIL", "tdomf");
        }
        echo "</span><br/>";
    }
    // Delete Options
    //
    tdomf_reset_options();
}
Esempio n. 3
0
function tdomf_init()
{
    // Update/upgrade options!
    // Pre 0.7 or a fresh install!
    if (get_option(TDOMF_VERSION_CURRENT) == false) {
        add_option(TDOMF_VERSION_CURRENT, TDOMF_BUILD);
        // Some defaults for new options!
        add_option(TDOMF_OPTION_MODERATION, true);
        add_option(TDOMF_OPTION_PREVIEW, true);
        add_option(TDOMF_OPTION_TRUST_COUNT, -1);
        add_option(TDOMF_OPTION_YOUR_SUBMISSIONS, true);
        add_option(TDOMF_OPTION_WIDGET_MAX_WIDTH, 500);
        add_option(TDOMF_OPTION_WIDGET_MAX_HEIGHT, 400);
    }
    // Pre 0.9.3 (beta)/16
    if (intval(get_option(TDOMF_VERSION_CURRENT)) < 16) {
        add_option(TDOMF_OPTION_YOUR_SUBMISSIONS, true);
    }
    // Pre WP 2.5/0.10.2
    if (intval(get_option(TDOMF_VERSION_CURRENT)) < 26) {
        add_option(TDOMF_OPTION_WIDGET_MAX_WIDTH, 500);
        add_option(TDOMF_OPTION_WIDGET_MAX_HEIGHT, 400);
    }
    if (get_option(TDOMF_OPTION_VERIFICATION_METHOD) == false) {
        add_option(TDOMF_OPTION_VERIFICATION_METHOD, 'wordpress_nonce');
    }
    if (get_option(TDOMF_OPTION_FORM_DATA_METHOD) == false) {
        if (ini_get('register_globals')) {
            add_option(TDOMF_OPTION_FORM_DATA_METHOD, 'db');
        } else {
            add_option(TDOMF_OPTION_FORM_DATA_METHOD, 'session');
        }
    }
    if (get_option(TDOMF_OPTION_LOG_MAX_SIZE) == false) {
        add_option(TDOMF_OPTION_LOG_MAX_SIZE, 1000);
    }
    if (intval(get_option(TDOMF_VERSION_CURRENT)) < 44) {
        $form_ids = tdomf_get_form_ids();
        foreach ($form_ids as $form_id) {
            tdomf_set_option_form(TDOMF_OPTION_ALLOW_PUBLISH, true, $form_id->form_id);
            tdomf_set_option_form(TDOMF_OPTION_PUBLISH_NO_MOD, true, $form_id->form_id);
        }
    }
    // Update build number
    if (get_option(TDOMF_VERSION_CURRENT) != TDOMF_BUILD) {
        update_option(TDOMF_VERSION_LAST, get_option(TDOMF_VERSION_CURRENT));
        update_option(TDOMF_VERSION_CURRENT, TDOMF_BUILD);
    }
}
Esempio n. 4
0
function tdomf_get_error_messages($show_links = true, $form_id = 0)
{
    global $wpdb, $wp_roles;
    if (!isset($wp_roles)) {
        $wp_roles = new WP_Roles();
    }
    $roles = $wp_roles->role_objects;
    $message = "";
    #if(ini_get('register_globals') && !TDOMF_HIDE_REGISTER_GLOBAL_ERROR){
    #  $message .= "<font color=\"red\"><strong>".__("ERROR: <em>register_globals</em> is enabled. This is a security risk and also prevents TDO Mini Forms from working.")."</strong></font>";
    #}
    if (version_compare("5.0.0", phpversion(), ">")) {
        $message .= sprintf(__("Warning: You are currently using PHP version %s. It is strongly recommended to use PHP5 with TDO Mini Forms.", "tdomf"), phpversion());
        $message .= "<br/>";
    }
    if (get_option(TDOMF_OPTION_VERIFICATION_METHOD) == 'none') {
        $message .= __("Warning: Form input verification is disabled. This is a potential security risk.", "tdomf");
        $message .= "<br/>";
    }
    # Revisions disabled => editing won't work well
    if (!constant('WP_POST_REVISIONS')) {
        $form_ids = tdomf_get_form_ids();
        foreach ($form_ids as $a_form_id) {
            if (tdomf_get_option_form(TDOMF_OPTION_FORM_EDIT, $a_form_id->form_id)) {
                $message .= __("Error: Post Revisioning is disabled, post editing will not work correctly!", "tdomf");
                $message .= "<br/>";
                break;
            }
        }
    }
    if (isset($_REQUEST['form']) || $form_id != 0) {
        if ($form_id == 0) {
            $form_id = intval($_REQUEST['form']);
        }
        // permissions error
        if (tdomf_get_option_form(TDOMF_OPTION_ALLOW_EVERYONE, $form_id) == false) {
            $caps = tdomf_get_option_form(TDOMF_OPTION_ALLOW_CAPS, $form_id);
            if (is_array($caps) && empty($caps)) {
                $caps = false;
            }
            $users = tdomf_get_option_form(TDOMF_OPTION_ALLOW_USERS, $form_id);
            if (is_array($users) && empty($users)) {
                $users = false;
            }
            $publish = tdomf_get_option_form(TDOMF_OPTION_ALLOW_PUBLISH, $form_id);
            $role_count = 0;
            $role_publish_count = 0;
            foreach ($roles as $role) {
                if (isset($role->capabilities[TDOMF_CAPABILITY_CAN_SEE_FORM . '_' . $form_id])) {
                    $role_count++;
                    if (isset($role->capabilities['publish_posts'])) {
                        $role_publish_count++;
                    }
                }
            }
            // if nothing set
            if ($role_count == 0 && $caps == false && $users == false && $publish == false) {
                if ($show_links) {
                    $message .= "<font color=\"red\">" . sprintf(__("<b>Warning</b>: No-one has been configured to be able to access the form! <a href=\"%s\">Configure on Options Page &raquo;</a>", "tdomf"), get_bloginfo('wpurl') . "/wp-admin/admin.php?page=tdomf_show_form_options_menu&form={$form_id}") . "</font><br/>";
                } else {
                    $message .= "<font color=\"red\">" . __("<b>Warning</b>: No-one has been configured to be able to access the form!", "tdomf") . "</font><br/>";
                }
                tdomf_log_message("No-one has been configured to access this form ({$form_id})", TDOMF_LOG_BAD);
            } else {
                if ($caps == false && $users == false && $role_count == $role_publish_count && $publish == false) {
                    if ($show_links) {
                        $message .= "<font color=\"red\">" . sprintf(__("<b>Warning</b>: Only users who can <i>already publish posts</i>, can see the form! <a href=\"%s\">Configure on Options Page &raquo;</a>", "tdomf"), get_bloginfo('wpurl') . "/wp-admin/admin.php?page=tdomf_show_form_options_menu&form={$form_id}") . "</font><br/>";
                    } else {
                        $message .= "<font color=\"red\">" . __("<b>Warning</b>: Only users who can <i>already publish posts</i>, can see this form!", "tdomf") . "</font><br/>";
                    }
                    tdomf_log_message("Only users who can already publish can access the form ({$form_id})", TDOMF_LOG_BAD);
                }
            }
        }
        // form hacker modified
        $mode = tdomf_generate_default_form_mode($form_id) . '-hack';
        $curr_unmod_prev = trim(tdomf_preview_form(array('tdomf_form_id' => $form_id), $mode));
        $org_unmod_prev = trim(tdomf_get_option_form(TDOMF_OPTION_FORM_PREVIEW_HACK_ORIGINAL, $form_id));
        $hacked_prev = trim(tdomf_get_option_form(TDOMF_OPTION_FORM_PREVIEW_HACK, $form_id));
        if ($hacked_prev != false && $curr_unmod_prev != $org_unmod_prev) {
            $message .= "<font color=\"red\">";
            $diffs = "admin.php?page=tdomf_show_form_hacker&form={$form_id}&mode={$mode}&diff&form2=cur&form1=org&type=preview";
            $form_hacker = "admin.php?page=tdomf_show_form_hacker&form={$form_id}";
            $dismiss = wp_nonce_url("admin.php?page=tdomf_show_form_hacker&form={$form_id}&dismiss&type=preview", 'tdomf-form-hacker');
            $message .= sprintf(__("<b>Warning</b>: Form configuration has been changed that affect the preview output but Form Hacker has not been updated! <a href='%s'>Diff &raquo;</a> | <a href='%s'>Hack Form &raquo;</a> | <a href='%s'>Dismiss</a>", "tdomf"), $diffs, $form_hacker, $dismiss);
            $message .= "</font><br/>";
        }
        $curr_unmod_form = trim(tdomf_generate_form($form_id, $mode));
        $org_unmod_form = trim(tdomf_get_option_form(TDOMF_OPTION_FORM_HACK_ORIGINAL, $form_id));
        $hacked_form = trim(tdomf_get_option_form(TDOMF_OPTION_FORM_HACK, $form_id));
        if ($hacked_form != false && $curr_unmod_form != $org_unmod_form) {
            $message .= "<font color=\"red\">";
            $diffs = "admin.php?page=tdomf_show_form_hacker&form={$form_id}&mode={$mode}&diff&form2=cur&form1=org";
            $form_hacker = "admin.php?page=tdomf_show_form_hacker&form={$form_id}";
            $dismiss = wp_nonce_url("admin.php?page=tdomf_show_form_hacker&form={$form_id}&dismiss", 'tdomf-form-hacker');
            $message .= sprintf(__("<b>Warning</b>: Form configuration has been changed that affect the generated form but Form Hacker has not been updated! <a href='%s'>Diff &raquo;</a> | <a href='%s'>Hack Form &raquo;</a> | <a href='%s'>Dismiss</a>", "tdomf"), $diffs, $form_hacker, $dismiss);
            $message .= "</font><br/>";
        }
        // widget errors
        global $tdomf_form_widgets_admin_errors;
        $mode = "new-post";
        if (tdomf_get_option_form(TDOMF_OPTION_SUBMIT_PAGE, $form_id)) {
            $mode = "new-page";
        }
        $uri = "admin.php?page=tdomf_show_form_menu&form=" . $form_id;
        do_action('tdomf_control_form_start', $form_id, $mode);
        $widget_order = tdomf_get_widget_order($form_id);
        $widgets = tdomf_filter_widgets($mode, $tdomf_form_widgets_admin_errors);
        foreach ($widget_order as $w) {
            if (isset($widgets[$w])) {
                $widget_message = call_user_func($widgets[$w]['cb'], $form_id, $widgets[$w]['params']);
                if (!empty($widget_message)) {
                    $message .= "<font color=\"red\">" . $widget_message . sprintf(__(" <a href='%s'>Fix &raquo;</a>", "tdomf"), $uri) . "</font><br/>";
                }
            }
        }
        // @todo check that key is unique in custom fields
    }
    if (get_option(TDOMF_OPTION_EXTRA_LOG_MESSAGES) && !get_option(TDOMF_OPTION_DISABLE_ERROR_MESSAGES)) {
        $message .= "<font color=\"red\">";
        if ($show_links) {
            $message .= sprintf(__("<b>Warning:</b> You have enabled 'Extra Debug Messages' and disabled 'Disable Error Messages'. This invokes a special mode where all PHP errors are turned on. This can lead to unexpected problems and could be considered a security leak! <a href=\"%s\">Change on the Options Page &raquo;</a>", "tdomf"), get_bloginfo('wpurl') . "/wp-admin/admin.php?page=tdomf_show_options_menu");
        } else {
            $message .= __("<b>Warning:</b> You have enabled 'Extra Debug Messages' and disabled 'Disable Error Messages'. This invokes a special mode where all PHP errors are turned on. This can lead to unexpected problems and could be considered a security leak! This should only be used for debugging purposes.", "tdomf");
        }
        $message .= "</font><br/>";
    }
    $create_user_link = get_bloginfo('wpurl') . "/wp-admin/admin.php?page=tdomf_show_options_menu&action=create_dummy_user";
    if (function_exists('wp_nonce_url')) {
        $create_user_link = wp_nonce_url($create_user_link, 'tdomf-create-dummy-user');
    }
    if (get_option(TDOMF_DEFAULT_AUTHOR) == false) {
        $message .= "<font color=\"red\">" . sprintf(__("<b>Error</b>: No default author set! <a href=\"%s\">Create dummy user for default author automatically &raquo;</a>", "tdomf"), $create_user_link) . "</font><br/>";
        tdomf_log_message("Option Default Author not set!", TDOMF_LOG_BAD);
    } else {
        $def_aut = new WP_User(get_option(TDOMF_DEFAULT_AUTHOR));
        if (empty($def_aut->data->ID)) {
            // User does not exist! Deleting option
            delete_option(TDOMF_DEFAULT_AUTHOR);
            $message .= "<font color=\"red\">" . sprintf(__("<b>Error</b>: Current Default Author does not exist! <a href=\"%s\">Create dummy user for default author automatically &raquo;</a>", "tdomf"), $create_user_link) . "</font><br/>";
            tdomf_log_message("Current Default Author does not exist! Deleting option.", TDOMF_LOG_BAD);
        }
        if ($def_aut->has_cap("publish_posts")) {
            $message .= "<font color=\"red\">" . sprintf(__("<b>Error</b>: Default author can publish posts. Default author should not be able to publish posts! <a href=\"%s\">Create a dummy user for default author automatically &raquo;</a>", "tdomf"), $create_user_link) . "</font><br/>";
            tdomf_log_message("Option Default Author is set to an author who can publish posts.", TDOMF_LOG_BAD);
        }
    }
    if (function_exists('wp_get_http')) {
        $post_uri = TDOMF_URLPATH . 'tdomf-form-post.php';
        $headers = wp_get_http($post_uri, false, 1);
        if ($headers != false && $headers["response"] != '200') {
            $message .= "<font color=\"red\">";
            $message .= sprintf(__("<b>Error</b>: Got a %d error when checking <a href=\"%s\">%s</a>! This will prevent posts from being submitted. The permissions may be wrong on the tdo-mini-forms folder.", "tdomf"), $headers["response"], $post_uri, $post_uri);
            $message .= "</font><br/>";
            tdomf_log_message("Did not receive a 200 response when checking {$post_uri}:<pre>" . var_export($headers, true) . "</pre>", TDOMF_LOG_ERROR);
        }
        $ajax_uri = TDOMF_URLPATH . 'tdomf-form-ajax.php';
        $headers = wp_get_http($ajax_uri, false, 1);
        if ($headers != false && $headers["response"] != '200') {
            $message .= "<font color=\"red\">";
            $message .= sprintf(__("<b>Error</b>: Got a %d error when checking <a href=\"%s\">%s</a>! This will prevent forms that use AJAX from submitting posts. The permissions may be wrong on the tdo-mini-forms folder.", "tdomf"), $headers["response"], $ajax_uri, $ajax_uri);
            $message .= "</font><br/>";
            tdomf_log_message("Did not receive a 200 response when checking {$ajax_uri}:<pre>" . var_export($headers, true) . "</pre>", TDOMF_LOG_ERROR);
        }
        $css_uri = TDOMF_URLPATH . 'tdomf-style-form.css';
        $headers = wp_get_http($css_uri, false, 1);
        if ($headers != false && $headers["response"] != '200') {
            $message .= "<font color=\"red\">";
            $message .= sprintf(__("<b>Error</b>: Got a %d error when checking <a href=\"%s\">%s</a>! This will make your forms, by default, look very ugly. The permissions may be wrong on the tdo-mini-forms folder.", "tdomf"), $headers["response"], $css_uri, $css_uri);
            $message .= "</font><br/>";
            tdomf_log_message("Did not receive a 200 response when checking {$css_uri}:<pre>" . var_export($headers, true) . "</pre>", TDOMF_LOG_ERROR);
        }
    }
    return $message;
}
function tdomf_show_form_hacker()
{
    global $wp_version;
    $form_id = false;
    if (isset($_REQUEST['form'])) {
        $form_id = $_REQUEST['form'];
    } else {
        $form_id = tdomf_get_first_form_id();
    }
    if ($form_id == false || !tdomf_form_exists($form_id)) {
        ?>
    <div class="wrap">
       <h2><?php 
        _e('Form Hacker', 'tdomf');
        ?>
</h2>
       <p><?php 
        if (is_numeric($form_id)) {
            printf(__('Invalid Form ID %s specified!'), $form_id);
        } else {
            _e('No Form ID specified!');
        }
        ?>
</p>
    </div>
  <?php 
    } else {
        if (isset($_REQUEST['diff'])) {
            ?>
    <div class="wrap">
          <?php 
            tdomf_form_hacker_diff($form_id);
            ?>
    </div> <!-- wrap -->
  <?php 
        } else {
            $mode = tdomf_generate_default_form_mode($form_id);
            $mode .= '-hack';
            tdomf_form_hacker_actions($form_id);
            $message = tdomf_get_error_messages(true, $form_id);
            if (!empty($message)) {
                ?>
        <div id="message" class="updated fade"><p><?php 
                echo $message;
                ?>
</p></div>
    <?php 
            }
            tdomf_forms_top_toolbar($form_id, 'tdomf_show_form_hacker');
            $form_ids = tdomf_get_form_ids();
            ?>
        
        <div class="wrap">
        <?php 
            if (!isset($_REQUEST['text'])) {
                ?>
          <h2><?php 
                printf(__("Form Hacker for Form %d: \"%s\"", "tdomf"), $form_id, tdomf_get_option_form(TDOMF_OPTION_NAME, $form_id));
                ?>
</h2>            
        <?php 
            } else {
                ?>
          <h2><?php 
                printf(__("Message Hacker for Form %d: \"%s\"", "tdomf"), $form_id, tdomf_get_option_form(TDOMF_OPTION_NAME, $form_id));
                ?>
</h2>            
        <?php 
            }
            ?>

          <script type="text/javascript">
            function tdomfHideHelp() {
                jQuery('#tdomf_help').attr('class','hidden');
                jQuery('#tdomf_show_help').attr('class','');
                jQuery('#tdomf_hide_help').attr('class','hidden');
            }
            function tdomfShowHelp() {
                jQuery('#tdomf_help').attr('class','');
                jQuery('#tdomf_show_help').attr('class','hidden');
                jQuery('#tdomf_hide_help').attr('class','');
            }
          </script>
          
          <?php 
            tdomf_forms_under_title_toolbar($form_id, 'tdomf_show_form_hacker');
            ?>
    
          <?php 
            if (isset($_REQUEST['text'])) {
                ?>
           
          <!-- <div id="tdomf_help" class='hidden'> -->
          
          <?php 
                $code_on = false;
                if (isset($_REQUEST['code'])) {
                    $code_on = true;
                }
                ?>
          
          <p><?php 
                _e("You can use this page to modify any messages outputed from TDOMF for your form. From here you can change the post published messages, post held in moderation, etc. etc.", "tdomf");
                ?>
</p>
            
          <?php 
                if (version_compare($wp_version, "2.8-beta2", ">=")) {
                    if (!$code_on) {
                        ?>
              <p><a href="admin.php?page=tdomf_show_form_hacker&text&code&form=<?php 
                        echo $form_id;
                        ?>
"><?php 
                        _e("Enable Code Syntax Highlighting...", 'tdomf');
                        ?>
</a></p>
          <?php 
                    } else {
                        ?>
              <p><a href="admin.php?page=tdomf_show_form_hacker&text&form=<?php 
                        echo $form_id;
                        ?>
"><?php 
                        _e("Disable Code Syntax Highlighting...", 'tdomf');
                        ?>
</a></p>
          <?php 
                    }
                }
                ?>
          
          <?php 
                $form_edit = tdomf_get_option_form(TDOMF_OPTION_FORM_EDIT, $form_id);
                ?>
 
          
          <p><?php 
                _e("PHP code can be included in the hacked messages. Also TDOMF will automatically expand these macro strings:", "tdomf");
                ?>
             <ul>
             <li><?php 
                printf(__("<code>%s</code> - User name of the currently logged in user", "tdomf"), TDOMF_MACRO_USERNAME);
                ?>
             <li><?php 
                printf(__("<code>%s</code> - IP of the current visitor", "tdomf"), TDOMF_MACRO_IP);
                ?>
             <li><?php 
                printf(__("<code>%s</code> - The ID of the current form (which is currently %d)", "tdomf"), TDOMF_MACRO_FORMID, $form_id);
                ?>
             <li><?php 
                printf(__("<code>%s</code> - Name of the Form (set in options)", "tdomf"), TDOMF_MACRO_FORMNAME);
                ?>
             <li><?php 
                printf(__("<code>%s</code> - Form Description (set in options)", "tdomf"), TDOMF_MACRO_FORMDESCRIPTION);
                ?>
             <li><?php 
                printf(__("<code>%s</code> - Submission Errors", "tdomf"), TDOMF_MACRO_SUBMISSIONERRORS);
                ?>
             <?php 
                if ($form_edit) {
                    ?>
             <li><?php 
                    printf(__("<code>%s</code> - URL of Post/Page being edited", "tdomf"), TDOMF_MACRO_SUBMISSIONURL);
                    ?>
             <li><?php 
                    printf(__("<code>%s</code> - Original Submission Date", "tdomf"), TDOMF_MACRO_SUBMISSIONDATE);
                    ?>
             
             <li><?php 
                    printf(__("<code>%s</code> - Original Submission Time", "tdomf"), TDOMF_MACRO_SUBMISSIONTIME);
                    ?>
             <li><?php 
                    printf(__("<code>%s</code> - Title of Post/Page being edited", "tdomf"), TDOMF_MACRO_SUBMISSIONTITLE);
                    ?>
             <?php 
                } else {
                    ?>
             <li><?php 
                    printf(__("<code>%s</code> - URL of Submission", "tdomf"), TDOMF_MACRO_SUBMISSIONURL);
                    ?>
             <li><?php 
                    printf(__("<code>%s</code> - Date of Submission", "tdomf"), TDOMF_MACRO_SUBMISSIONDATE);
                    ?>
             
             <li><?php 
                    printf(__("<code>%s</code> - Time of Submission", "tdomf"), TDOMF_MACRO_SUBMISSIONTIME);
                    ?>
             <li><?php 
                    printf(__("<code>%s</code> - Title of Submission", "tdomf"), TDOMF_MACRO_SUBMISSIONTITLE);
                    ?>
             <?php 
                }
                ?>
             </ul>
          </p>
          
          <!-- </div> -->
          
          <form method="post" name="formhackermsgs" id="formhackermsgs">
          <?php 
                if (function_exists('wp_nonce_field')) {
                    wp_nonce_field('tdomf-form-hacker');
                }
                ?>
          
          <p class="submit">
          <input type="submit" value="<?php 
                _e('Save &raquo;', 'tdomf');
                ?>
" id="tdomf_hack_messages_save" name="tdomf_hack_messages_save" />
          <input type="submit" value="<?php 
                _e('Reset &raquo;', 'tdomf');
                ?>
" id="tdomf_hack_messages_reset" name="tdomf_hack_messages_reset" />
          </p>
          
          <?php 
                if (!tdomf_get_option_form(TDOMF_OPTION_MODERATION, $form_id) && !tdomf_get_option_form(TDOMF_OPTION_REDIRECT, $form_id)) {
                    ?>
              <h3><?php 
                    if ($form_edit) {
                        _e('Contribution Approved', 'tdomf');
                    } else {
                        _e('Submission Published', 'tdomf');
                    }
                    ?>
</h3>
              <textarea title="true" rows="5" cols="70" name="tdomf_msg_sub_publish" id="tdomf_msg_sub_publish" <?php 
                    if ($code_on) {
                        ?>
class="codepress .php"<?php 
                    }
                    ?>
 ><?php 
                    echo htmlentities(tdomf_get_message(TDOMF_OPTION_MSG_SUB_PUBLISH, $form_id), ENT_NOQUOTES, get_bloginfo('charset'));
                    ?>
</textarea>
              <br/><br/>
          <?php 
                }
                ?>
                    
          <?php 
                if (intval(tdomf_get_option_form(TDOMF_OPTION_QUEUE_PERIOD, $form_id)) > 0 && !tdomf_get_option_form(TDOMF_OPTION_MODERATION, $form_id)) {
                    ?>
              <h3><?php 
                    _e('Submission Queued', 'tdomf');
                    ?>
</h3>
              <textarea title="true" rows="5" cols="70" name="tdomf_msg_sub_future" id="tdomf_msg_sub_future" <?php 
                    if ($code_on) {
                        ?>
class="codepress .php"<?php 
                    }
                    ?>
 ><?php 
                    echo htmlentities(tdomf_get_message(TDOMF_OPTION_MSG_SUB_FUTURE, $form_id), ENT_NOQUOTES, get_bloginfo('charset'));
                    ?>
</textarea>
              <br/><br/>
          <?php 
                }
                ?>
          
          <?php 
                if (get_option(TDOMF_OPTION_SPAM)) {
                    ?>
              <h3><?php 
                    if ($form_edit) {
                        _e('Contribution is Spam', 'tdomf');
                    } else {
                        _e('Submission is Spam', 'tdomf');
                    }
                    ?>
</h3>
              <textarea title="true" rows="5" cols="70" name="tdomf_msg_sub_spam" id="tdomf_msg_sub_spam" <?php 
                    if ($code_on) {
                        ?>
class="codepress .php"<?php 
                    }
                    ?>
 ><?php 
                    echo htmlentities(tdomf_get_message(TDOMF_OPTION_MSG_SUB_SPAM, $form_id), ENT_NOQUOTES, get_bloginfo('charset'));
                    ?>
</textarea>
              <br/><br/>
          <?php 
                }
                ?>
          
          <?php 
                if (tdomf_get_option_form(TDOMF_OPTION_MODERATION, $form_id)) {
                    ?>
              <h3><?php 
                    if ($form_edit) {
                        _e('Contribution awaiting Moderation', 'tdomf');
                    } else {
                        _e('Submission awaiting Moderation', 'tdomf');
                    }
                    ?>
</h3>
              <textarea title="true" rows="5" cols="70" name="tdomf_msg_sub_mod" id="tdomf_msg_sub_mod" <?php 
                    if ($code_on) {
                        ?>
class="codepress .php"<?php 
                    }
                    ?>
 ><?php 
                    echo htmlentities(tdomf_get_message(TDOMF_OPTION_MSG_SUB_MOD, $form_id), ENT_NOQUOTES, get_bloginfo('charset'));
                    ?>
</textarea>
              <br/><br/>
          <?php 
                }
                ?>
          
          <h3><?php 
                if ($form_edit) {
                    _e('Contribution contains Errors', 'tdomf');
                } else {
                    _e('Submission contains Errors', 'tdomf');
                }
                ?>
</h3>
          <textarea title="true" rows="5" cols="70" name="tdomf_msg_sub_error" id="tdomf_msg_sub_error" <?php 
                if ($code_on) {
                    ?>
class="codepress .php"<?php 
                }
                ?>
 ><?php 
                echo htmlentities(tdomf_get_message(TDOMF_OPTION_MSG_SUB_ERROR, $form_id), ENT_NOQUOTES, get_bloginfo('charset'));
                ?>
</textarea>
          <br/><br/>
          
          <h3><?php 
                _e('Banned User', 'tdomf');
                ?>
</h3>
          <textarea title="true" rows="5" cols="70" name="tdomf_msg_perm_banned_user" id="tdomf_msg_perm_banned_user" <?php 
                if ($code_on) {
                    ?>
class="codepress .php"<?php 
                }
                ?>
 ><?php 
                echo htmlentities(tdomf_get_message(TDOMF_OPTION_MSG_PERM_BANNED_USER, $form_id), ENT_NOQUOTES, get_bloginfo('charset'));
                ?>
</textarea>
          <br/><br/>

          <h3><?php 
                _e('Banned IP', 'tdomf');
                ?>
</h3>          
          <textarea title="true" rows="5" cols="70" name="tdomf_msg_perm_banned_ip" id="tdomf_msg_perm_banned_ip" <?php 
                if ($code_on) {
                    ?>
class="codepress .php"<?php 
                }
                ?>
 ><?php 
                echo htmlentities(tdomf_get_message(TDOMF_OPTION_MSG_PERM_BANNED_IP, $form_id), ENT_NOQUOTES, get_bloginfo('charset'));
                ?>
</textarea>
          <br/><br/>
          
          <?php 
                $throttle_rules = tdomf_get_option_form(TDOMF_OPTION_THROTTLE_RULES, $form_id);
                if (is_array($throttle_rules) && !empty($throttle_rules)) {
                    ?>
              <h3><?php 
                    _e('Throttled Submission', 'tdomf');
                    ?>
</h3>
              <textarea title="true" rows="5" cols="70" name="tdomf_msg_perm_throttle" id="tdomf_msg_perm_throttle" <?php 
                    if ($code_on) {
                        ?>
class="codepress .php"<?php 
                    }
                    ?>
 ><?php 
                    echo htmlentities(tdomf_get_message(TDOMF_OPTION_MSG_PERM_THROTTLE, $form_id), ENT_NOQUOTES, get_bloginfo('charset'));
                    ?>
</textarea>
              <br/><br/>
          <?php 
                }
                ?>
          
          <?php 
                if (!tdomf_get_option_form(TDOMF_OPTION_ALLOW_EVERYONE, $form_id)) {
                    ?>
              <h3><?php 
                    _e('Denied User', 'tdomf');
                    ?>
</h3>
              <textarea title="true" rows="5" cols="70" name="tdomf_msg_perm_invalid_user" id="tdomf_msg_perm_invalid_user" <?php 
                    if ($code_on) {
                        ?>
class="codepress .php"<?php 
                    }
                    ?>
 ><?php 
                    echo htmlentities(tdomf_get_message(TDOMF_OPTION_MSG_PERM_INVALID_USER, $form_id), ENT_NOQUOTES, get_bloginfo('charset'));
                    ?>
</textarea>
              <br/><br/>
          <?php 
                }
                ?>
          
          <?php 
                if (!tdomf_get_option_form(TDOMF_OPTION_ALLOW_EVERYONE, $form_id)) {
                    ?>
              <h3><?php 
                    _e('Banned Unregistered User', 'tdomf');
                    ?>
</h3>
              <textarea title="true" rows="5" cols="70" name="tdomf_msg_perm_invalid_nouser" id="tdomf_msg_perm_invalid_nouser" <?php 
                    if ($code_on) {
                        ?>
class="codepress .php"<?php 
                    }
                    ?>
 ><?php 
                    echo htmlentities(tdomf_get_message(TDOMF_OPTION_MSG_PERM_INVALID_NOUSER, $form_id), ENT_NOQUOTES, get_bloginfo('charset'));
                    ?>
</textarea>
              <br/><br/>
          <?php 
                }
                ?>

          <?php 
                if ($form_edit) {
                    ?>

              <?php 
                    /*if(tdomf_get_option_form(TDOMF_OPTION_AJAX_EDIT,$form_id)) {*/
                    ?>
              
                 <h3><?php 
                    _e('\'Edit Post\' Link Text', 'tdomf');
                    ?>
</h3>
                 <textarea title="true" rows="5" cols="70" name="tdomf_msg_edit_post_link" id="tdomf_msg_edit_post_link" <?php 
                    if ($code_on) {
                        ?>
class="codepress .php"<?php 
                    }
                    ?>
 ><?php 
                    echo htmlentities(tdomf_get_message(TDOMF_OPTION_ADD_EDIT_LINK_TEXT, $form_id), ENT_NOQUOTES, get_bloginfo('charset'));
                    ?>
</textarea>
                 <br/><br/>
             
              <?php 
                    /*}*/
                    ?>
              
              <h3><?php 
                    _e('Invalid Post for Form', 'tdomf');
                    ?>
</h3>
              <textarea title="true" rows="5" cols="70" name="tdomf_msg_invalid_post" id="tdomf_msg_invalid_post" <?php 
                    if ($code_on) {
                        ?>
class="codepress .php"<?php 
                    }
                    ?>
 ><?php 
                    echo htmlentities(tdomf_get_message(TDOMF_OPTION_MSG_INVALID_POST, $form_id), ENT_NOQUOTES, get_bloginfo('charset'));
                    ?>
</textarea>
              <br/><br/>
              
              <h3><?php 
                    _e('Invalid Form for Post', 'tdomf');
                    ?>
</h3>
              <textarea title="true" rows="5" cols="70" name="tdomf_msg_invalid_form" id="tdomf_msg_invalid_form" <?php 
                    if ($code_on) {
                        ?>
class="codepress .php"<?php 
                    }
                    ?>
 ><?php 
                    echo htmlentities(tdomf_get_message(TDOMF_OPTION_MSG_INVALID_FORM, $form_id), ENT_NOQUOTES, get_bloginfo('charset'));
                    ?>
</textarea>
              <br/><br/>
              
              <h3><?php 
                    _e('Locked Post', 'tdomf');
                    ?>
</h3>
              <textarea title="true" rows="5" cols="70" name="tdomf_msg_locked_post" id="tdomf_msg_locked_post" <?php 
                    if ($code_on) {
                        ?>
class="codepress .php"<?php 
                    }
                    ?>
 ><?php 
                    echo htmlentities(tdomf_get_message(TDOMF_OPTION_MSG_LOCKED_POST, $form_id), ENT_NOQUOTES, get_bloginfo('charset'));
                    ?>
</textarea>
              <br/><br/>
              
              <?php 
                    if (get_option(TDOMF_OPTION_SPAM)) {
                        ?>

                 <h3><?php 
                        _e('Spam Edit on Post', 'tdomf');
                        ?>
</h3>
                 <textarea title="true" rows="5" cols="70" name="tdomf_msg_spam_edit_on_post" id="tdomf_msg_spam_edit_on_post" <?php 
                        if ($code_on) {
                            ?>
class="codepress .php"<?php 
                        }
                        ?>
 ><?php 
                        echo htmlentities(tdomf_get_message(TDOMF_OPTION_MSG_SPAM_EDIT_ON_POST, $form_id), ENT_NOQUOTES, get_bloginfo('charset'));
                        ?>
</textarea>
                 <br/><br/>
                  
              <?php 
                    }
                    ?>
              
             <h3><?php 
                    _e('Unapproved Edit on Post', 'tdomf');
                    ?>
</h3>
             <textarea title="true" rows="5" cols="70" name="tdomf_msg_unapproved_edit_on_post" id="tdomf_msg_unapproved_edit_on_post" <?php 
                    if ($code_on) {
                        ?>
class="codepress .php"<?php 
                    }
                    ?>
 ><?php 
                    echo htmlentities(tdomf_get_message(TDOMF_OPTION_MSG_UNAPPROVED_EDIT_ON_POST, $form_id), ENT_NOQUOTES, get_bloginfo('charset'));
                    ?>
</textarea>
             <br/><br/>

          <?php 
                }
                ?>
          
          <?php 
                do_action('tdomf_form_hacker_messages_bottom', $form_id, $mode);
                ?>
                    
          <span class="submit">
          <input type="submit" value="<?php 
                _e('Save &raquo;', 'tdomf');
                ?>
" id="tdomf_hack_messages_save" name="tdomf_hack_messages_save" />
          <input type="submit" value="<?php 
                _e('Reset &raquo;', 'tdomf');
                ?>
" id="tdomf_hack_messages_reset" name="tdomf_hack_messages_reset" />
          </span>
          
          </form>
          
          <?php 
            } else {
                ?>
          
          <!-- <div id="tdomf_help" class='hidden'> -->
          
          <p><?php 
                _e("You can use this page to hack the generated HTML code for your form without modifing the code of TDOMF. Please only do this if you know what you are doing. From here you can modify titles, default values, re-arrange fields, etc. etc.", "tdomf");
                ?>
</p>
             
          <p><?php 
                _e('Do not modify or remove the "name" and "id" attributes of fields as this is what the widgets and TDOMF use to get input values for processing', 'tdomf');
                ?>
</p>
             
          <p><?php 
                printf(__("Every time a form is generated, it creates a unique key. If you hack the form, make sure you keep <code>%s</code> (and also <code>%s</code>) within the form. TDOMF will replace this string with the unique key.", "tdomf"), TDOMF_MACRO_FORMKEY, TDOMF_MACRO_FORMURL);
                ?>
</p>
          
          <p><?php 
                _e("PHP code can be included in the hacked form. Also TDOMF will automatically expand these macro strings:", "tdomf");
                ?>
             <ul>
             <li><?php 
                printf(__("<code>%s</code> - User name of the currently logged in user", "tdomf"), TDOMF_MACRO_USERNAME);
                ?>
             <li><?php 
                printf(__("<code>%s</code> - IP of the current visitor", "tdomf"), TDOMF_MACRO_IP);
                ?>
             <li><?php 
                printf(__("<code>%s</code> - The form's unique key", "tdomf"), TDOMF_MACRO_FORMKEY);
                ?>
             <li><?php 
                printf(__("<code>%s</code> - The current URL of the form", "tdomf"), TDOMF_MACRO_FORMURL);
                ?>
             <li><?php 
                printf(__("<code>%s</code> - The ID of the current form (which is currently %d)", "tdomf"), TDOMF_MACRO_FORMID, $form_id);
                ?>
             <li><?php 
                printf(__("<code>%s</code> - Name of the Form (set in options)", "tdomf"), TDOMF_MACRO_FORMNAME);
                ?>
             <li><?php 
                printf(__("<code>%s</code> - Form Description (set in options)", "tdomf"), TDOMF_MACRO_FORMDESCRIPTION);
                ?>
             <li><?php 
                printf(__("<code>%s</code> - Form Output (such as preview, errors, etc.). This is automatically encapsulated in a div called tdomf_form_message (and tdomf_form_preview for preview)", "tdomf"), TDOMF_MACRO_FORMMESSAGE);
                ?>
             <li><?php 
                printf(__("<code>%swidget-name%s</code> - Original, unmodified output from 'widget-name'", "tdomf"), TDOMF_MACRO_WIDGET_START, TDOMF_MACRO_END);
                ?>
             </ul>
          </p>
          
          <!-- </div> -->
 
          <form method="post" name="formhacker" id="formhacker">
          <?php 
                if (function_exists('wp_nonce_field')) {
                    wp_nonce_field('tdomf-form-hacker');
                }
                ?>
      
          <p class="submit">
          <input type="submit" value="<?php 
                _e('Save &raquo;', 'tdomf');
                ?>
" id="tdomf_form_hack_save" name="tdomf_form_hack_save" />
          <input type="submit" value="<?php 
                _e('Reset &raquo;', 'tdomf');
                ?>
" id="tdomf_form_hack_reset" name="tdomf_form_hack_reset" />
          </p>
          
          <?php 
                if (tdomf_widget_is_preview_avaliable($form_id)) {
                    ?>
          
              <h3><?php 
                    _e('Core Form', 'tdomf');
                    ?>
</h3>
              
          <?php 
                }
                ?>
          
            <?php 
                $cur_form = tdomf_generate_form($form_id, $mode);
                $form = $cur_form;
                $hacked_form = tdomf_get_option_form(TDOMF_OPTION_FORM_HACK, $form_id);
                if ($hacked_form != false) {
                    $form = $hacked_form;
                }
                ?>
                  
            <?php 
                if ($hacked_form != false) {
                    ?>
              <?php 
                    _e("You can diff the hacked form to see what you have changed", "tdomf");
                    ?>
              <ul>
              <li><a href="admin.php?page=tdomf_show_form_hacker&form=<?php 
                    echo $form_id;
                    ?>
&mode=<?php 
                    echo $mode;
                    ?>
&diff&form1=hack&form2=cur"><?php 
                    _e("Diff Hacked Form with Current Form", "tdomf");
                    ?>
</a></li>
              <?php 
                    $org_form = tdomf_get_option_form(TDOMF_OPTION_FORM_HACK_ORIGINAL, $form_id);
                    if (trim($cur_form) != trim($org_form)) {
                        ?>
              <li><a href="admin.php?page=tdomf_show_form_hacker&form=<?php 
                        echo $form_id;
                        ?>
&mode=<?php 
                        echo $mode;
                        ?>
&diff&form2=hack&form1=org"><?php 
                        _e("Diff Hacked Form with Previous Form", "tdomf");
                        ?>
</a></li>
              <li><a href="admin.php?page=tdomf_show_form_hacker&form=<?php 
                        echo $form_id;
                        ?>
&mode=<?php 
                        echo $mode;
                        ?>
&diff&form2=cur&form1=org"><?php 
                        _e("Diff Current Form with Previous Form", "tdomf");
                        ?>
</a></li>
                    <?php 
                    }
                    ?>
              </ul>
            <?php 
                }
                ?>
                  
            <textarea title="true" rows="30" cols="100" name="tdomf_form_hack" id="tdomf_form_hack" class="codepress .php" ><?php 
                echo htmlentities($form, ENT_NOQUOTES, get_bloginfo('charset'));
                ?>
</textarea>
            
          <br/><br/>
          
          <?php 
                if (tdomf_widget_is_preview_avaliable($form_id)) {
                    ?>
          
              <h3><?php 
                    _e('Form Preview', 'tdomf');
                    ?>
</h3>
              
              <?php 
                    $cur_preview = tdomf_preview_form(array('tdomf_form_id' => $form_id), $mode);
                    $preview = $cur_preview;
                    $hacked_preview = tdomf_get_option_form(TDOMF_OPTION_FORM_PREVIEW_HACK, $form_id);
                    if ($hacked_preview != false) {
                        $preview = $hacked_preview;
                    }
                    ?>
              
              <?php 
                    if ($hacked_preview != false) {
                        ?>
              <?php 
                        _e("You can diff the hacked preview to see what you have changed", "tdomf");
                        ?>
              <ul>
              <li><a href="admin.php?page=tdomf_show_form_hacker&form=<?php 
                        echo $form_id;
                        ?>
&mode=<?php 
                        echo $mode;
                        ?>
&diff&form1=hack&form2=cur&type=preview"><?php 
                        _e("Diff Hacked Preview with Current Preview", "tdomf");
                        ?>
</a></li>
              <?php 
                        $org_preview = tdomf_get_option_form(TDOMF_OPTION_FORM_PREVIEW_HACK_ORIGINAL, $form_id);
                        if (trim($cur_preview) != trim($org_preview)) {
                            ?>
              <li><a href="admin.php?page=tdomf_show_form_hacker&form=<?php 
                            echo $form_id;
                            ?>
&mode=<?php 
                            echo $mode;
                            ?>
&diff&form2=hack&form1=org&type=preview"><?php 
                            _e("Diff Hacked Preview with Previous Preview", "tdomf");
                            ?>
</a></li>
              <li><a href="admin.php?page=tdomf_show_form_hacker&form=<?php 
                            echo $form_id;
                            ?>
&mode=<?php 
                            echo $mode;
                            ?>
&diff&form2=cur&form1=org&type=preview"><?php 
                            _e("Diff Current Preview with Previous Preview", "tdomf");
                            ?>
</a></li>
                    <?php 
                        }
                        ?>
              </ul>
            <?php 
                    }
                    ?>
                    
                    
              <textarea title="true" rows="15" cols="100" name="tdomf_form_preview_hack" id="tdomf_form_preview_hack" class="codepress .php"><?php 
                    echo htmlentities($preview, ENT_NOQUOTES, get_bloginfo('charset'));
                    ?>
</textarea>
                
              <br/><br/>
                
          <?php 
                }
                ?>

          <!-- @TODO Validation Message Hacker -->
          <!-- @TODO Upload Form Hacker -->     
          <?php 
                do_action('tdomf_form_hacker_bottom', $form_id, $mode);
                ?>
          
          <span class="submit">
          <input type="submit" value="<?php 
                _e('Save &raquo;', 'tdomf');
                ?>
" id="tdomf_form_hack_save" name="tdomf_form_hack_save" />
          <input type="submit" value="<?php 
                _e('Reset &raquo;', 'tdomf');
                ?>
" id="tdomf_form_hack_reset" name="tdomf_form_hack_reset" />
          </span>
          
          </form>
          
          <!-- @TODO: warning about updated form (with dismiss link) -->
          
          <?php 
            }
            ?>
          
        </div>
    <?php 
        }
    }
}
function tdomf_editpostlink_filter($url, $post_id)
{
    $form_ids = tdomf_get_form_ids();
    foreach ($form_ids as $form_id) {
        if (tdomf_get_option_form(TDOMF_OPTION_FORM_EDIT, $form_id->form_id) && tdomf_check_permissions_form($form_id->form_id, $post_ID) == NULL) {
            $edit_link_style = tdomf_get_option_form(TDOMF_OPTION_AUTO_EDIT_LINK, $form_id->form_id);
            if ($edit_link_style != 'none' && $edit_link_style != false) {
                if ($edit_link_style == 'page') {
                    $pages = tdomf_get_option_form(TDOMF_OPTION_CREATEDPAGES, $form_id->form_id);
                    $url = get_permalink($pages[0]);
                    if (strpos($url, '?') !== false) {
                        $url .= '&tdomf_post_id=' . $post_ID;
                    } else {
                        $url .= '?tdomf_post_id=' . $post_ID;
                    }
                } else {
                    if ($edit_link_style == 'your_submissions') {
                        $url = trailingslashit(get_bloginfo('wpurl')) . 'wp-admin/users.php?page=tdomf_your_submissions&tdomf_post_id=' . $post_ID . '#tdomf_form' . $form_id->form_id . '_' . $post_ID;
                    } else {
                        if ($edit_link_style != 'none') {
                            $url = $edit_link_style;
                            if (strpos($url, '?') !== false) {
                                $url .= '&tdomf_post_id=' . $post_ID;
                            } else {
                                $url = trailingslashit($url) . '?tdomf_post_id=' . $post_ID;
                            }
                        }
                    }
                }
                // once we find one, use it!
                break;
            }
        }
    }
    return $url;
}
function tdomf_theme_widgets_init()
{
    if (!function_exists('register_sidebar_widget') || !function_exists('register_widget_control')) {
        return;
    }
    function tdomf_theme_widget_form($args, $params)
    {
        extract($args);
        $form_id = $params;
        if (!tdomf_form_exists($form_id)) {
            $form_id = tdomf_get_first_form_id();
        }
        echo $before_widget;
        echo $before_title;
        echo tdomf_get_option_form(TDOMF_OPTION_NAME, $form_id);
        echo $after_title;
        tdomf_the_form($form_id);
        echo "<br/><br/>\n";
        echo $after_widget;
    }
    $form_ids = tdomf_get_form_ids();
    foreach ($form_ids as $form_id) {
        register_sidebar_widget("TDOMF Form " . $form_id->form_id, 'tdomf_theme_widget_form', $form_id->form_id);
    }
    function tdomf_theme_widget_admin($args)
    {
        if (current_user_can('manage_options') || current_user_can('edit_others_posts')) {
            extract($args);
            $errors = tdomf_get_error_messages();
            if (trim($errors) != "") {
                echo $before_widget;
                echo $before_title . __("TDOMF Errors", "tdomf") . $after_title;
                echo "<p>{$errors}</p>";
                echo $after_widget;
            }
            $options = get_option('tdomf_theme_widget_admin');
            if ($options == false) {
                $log = 5;
                $mod = 5;
            } else {
                $log = $options['log'];
                $mod = $options['mod'];
            }
            if ($log > 0) {
                echo $before_widget;
                echo $before_title;
                _e('TDOMF Log', 'tdomf');
                if (current_user_can('manage_options')) {
                    echo "<a href=\"" . get_bloginfo('wpurl') . "/wp-admin/admin.php?page=tdomf_show_log_menu\" title=\"Full Log...\">&raquo;</a>";
                }
                echo $after_title;
                echo '<p>' . tdomf_get_log($log) . '</p>';
                echo $after_widget;
            }
            if ($mod > 0) {
                $posts = tdomf_get_unmoderated_posts(0, $mod);
                if (!empty($posts)) {
                    echo $before_widget;
                    echo $before_title;
                    printf(__('Awaiting Approval (%d)', 'tdomf'), tdomf_get_unmoderated_posts_count());
                    if (current_user_can('edit_others_posts')) {
                        echo "<a href=\"" . get_bloginfo('wpurl') . "/wp-admin/admin.php?page=tdomf_show_mod_posts_menu&f=0\" title=\"Moderate Submissions...\">&raquo;</a>";
                    }
                    echo $after_title;
                    echo '<ul>';
                    foreach ($posts as $p) {
                        echo tdomf_get_post_list_line($p);
                    }
                    echo '</ul>';
                    echo $after_widget;
                }
            }
            if (get_option(TDOMF_OPTION_SPAM)) {
                $spam_count = tdomf_get_spam_posts_count();
                if ($spam_count > 0) {
                    echo $before_widget;
                    echo $before_title;
                    printf(__('Spam Queue (%d)', 'tdomf'), $spam_count);
                    if (current_user_can('edit_others_posts')) {
                        echo '<a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=tdomf_show_mod_posts_menu&f=3" title="' . __("Moderate Spam...", "tdomf") . '">&raquo;</a>';
                    }
                    echo $after_title;
                    echo $after_widget;
                }
            }
            echo $before_widget;
            echo $before_title;
            _e('TDOMF Admin Links', 'tdomf');
            echo $after_title;
            echo "<ul>";
            if ($mod <= 0 && tdomf_is_moderation_in_use()) {
                echo "<li>";
                printf(__("<a href=\"%s\">Moderate (%d)</a>", "tdomf"), get_bloginfo('wpurl') . "/wp-admin/admin.php?page=tdomf_show_mod_posts_menu&f=0", tdomf_get_unmoderated_posts_count());
                echo "</li>";
            }
            echo "<li>";
            printf(__("<a href=\"%s\">Configure</a>", "tdomf"), get_bloginfo('wpurl') . "/wp-admin/admin.php?page=tdomf_show_options_menu");
            echo "</li>";
            echo "<li>";
            printf(__("<a href=\"%s\">Manage</a>", "tdomf"), get_bloginfo('wpurl') . "/wp-admin/admin.php?page=tdomf_show_manage_menu");
            echo "</li>";
            echo "<li>";
            printf(__("<a href=\"%s\">Create Form</a>", "tdomf"), get_bloginfo('wpurl') . "/wp-admin/admin.php?page=tdomf_show_form_menu");
            echo "</li>";
            if ($log <= 0) {
                echo "<li>";
                printf(__("<a href=\"%s\">Log</a>", "tdomf"), get_bloginfo('wpurl') . "/wp-admin/admin.php?page=tdomf_show_log_menu");
                echo "</li>";
            }
            echo "</ul>";
            echo $after_widget;
        }
    }
    function tdomf_theme_widget($args)
    {
        extract($args);
        $options = get_option('tdomf_theme_widget');
        if ($options == false) {
            $title = 'Recent Submissions';
            $mod = 5;
        } else {
            $title = $options['title'];
            $mod = $options['mod'];
        }
        $posts = tdomf_get_published_posts(0, $mod);
        if (!empty($posts)) {
            echo $before_widget;
            if ($title) {
                echo $before_title;
                echo $title;
                echo $after_title;
            }
            echo "<ul>";
            foreach ($posts as $p) {
                #echo "<li><a href=\"".get_permalink($p->ID)."\">".$p->post_title."</a> from ".get_post_meta($p->ID, TDOMF_KEY_NAME, true)."</li>";
                echo tdomf_get_latest_submissions_post_list_line($p);
            }
            echo "</ul>";
            echo $after_widget;
        }
    }
    function tdomf_theme_widget_control()
    {
        $options = get_option('tdomf_theme_widget');
        if ($_POST['tdomf-mod']) {
            $newoptions['title'] = htmlentities(strip_tags($_POST['tdomf-title']));
            $newoptions['mod'] = intval($_POST['tdomf-mod']);
            if ($options != $newoptions) {
                $options = $newoptions;
                update_option('tdomf_theme_widget', $options);
            }
        }
        if ($options == false) {
            $title = 'Recent Submissions';
            $mod = 5;
        } else {
            $title = $options['title'];
            $mod = $options['mod'];
        }
        ?>
  <div>
  
  <label for="tdomf-title">
  Title
  <input type="text" id="tdomf-title" name="tdomf-title" value="<?php 
        echo htmlentities($title, ENT_QUOTES);
        ?>
" size="20" />
  </label>
  <br/><br/>
  <label for="tdomf-mod">
  Number of posts to show:
  <input type="text" id="tdomf-mod" name="tdomf-mod" value="<?php 
        echo htmlentities($mod, ENT_QUOTES);
        ?>
" size="2" />
  </label>
  
  </div>
  <?php 
    }
    function tdomf_theme_widget_admin_control()
    {
        $options = get_option('tdomf_theme_widget_admin');
        if ($_POST['tdomf-admin-info-log']) {
            $newoptions['log'] = intval($_POST['tdomf-admin-info-log']);
            $newoptions['mod'] = intval($_POST['tdomf-admin-info-mod']);
            if ($options != $newoptions) {
                $options = $newoptions;
                update_option('tdomf_theme_widget_admin', $options);
            }
        }
        if ($options == false) {
            $log = 5;
            $mod = 5;
        } else {
            $log = $options['log'];
            $mod = $options['mod'];
        }
        ?>
  <div>
  
  <label for="tdomf-admin-info-log">
  Number of log lines to show:
  <input type="text" id="tdomf-admin-info-log" name="tdomf-admin-info-log" value="<?php 
        echo htmlentities($log, ENT_QUOTES);
        ?>
" size="2" />
  </label>
  <br/><br/>
  <label for="tdomf-admin-info-mod">
  Number of posts to show:
  <input type="text" id="tdomf-admin-info-mod" name="tdomf-admin-info-mod" value="<?php 
        echo htmlentities($mod, ENT_QUOTES);
        ?>
" size="2" />
  </label>
  
  </div>
  <?php 
    }
    function tdomf_theme_widget_submitters_control()
    {
        $options = get_option('tdomf_theme_widget_submitters');
        if ($_POST['tdomf_theme_widget_submitters-title']) {
            $newoptions['title'] = $_POST['tdomf_theme_widget_submitters-title'];
            $newoptions['count'] = intval($_POST['tdomf_theme_widget_submitters-count']);
            $newoptions['use_subs'] = isset($_POST['tdomf_theme_widget_submitters-use_subs']);
            $newoptions['use_reg'] = isset($_POST['tdomf_theme_widget_submitters-use_reg']);
            $newoptions['use_link'] = isset($_POST['tdomf_theme_widget_submitters-use_link']);
            $newoptions['avatar'] = isset($_POST['tdomf_theme_widget_submitters-avatar']);
            $newoptions['avatar_size'] = intval($_POST['tdomf_theme_widget_submitters-avatar_size']);
            $newoptions['avatar_default'] = $_POST['tdomf_theme_widget_submitters-avatar_default'];
            if ($options != $newoptions) {
                $options = $newoptions;
                update_option('tdomf_theme_widget_submitters', $options);
            }
        }
        $title = 'Top Submitters';
        $count = 5;
        $use_subs = true;
        $use_reg = true;
        $use_link = false;
        $avatar = false;
        $avatar_size = 25;
        $avatar_default = "";
        if ($options != false) {
            $title = $options['title'];
            $count = $options['count'];
            $use_subs = $options['use_subs'];
            $use_reg = $options['use_reg'];
            $use_link = $options['use_link'];
            if (isset($options['avatar'])) {
                $avatar = $options['avatar'];
                $avatar_size = $options['avatar_size'];
                $avatar_default = $options['avatar_default'];
            }
        }
        ?>
  <div>
  
  <label for="tdomf_theme_widget_submitters-title">
  <?php 
        _e("Title", "tdomf");
        ?>
  <input type="text" id="tdomf_theme_widget_submitters-title" name="tdomf_theme_widget_submitters-title" value="<?php 
        echo htmlentities($title, ENT_QUOTES);
        ?>
" size="20" />
  </label>
  <br/><br/>
  <?php 
        _e("How many to show:", "tdomf");
        ?>
  <input type="text" id="tdomf_theme_widget_submitters-count" name="tdomf_theme_widget_submitters-count" value="<?php 
        echo htmlentities($count, ENT_QUOTES);
        ?>
" size="2" />
  </label>
  <br/><br/>
  <?php 
        _e("Include Unregistered Users:", "tdomf");
        ?>
  <input type="checkbox" id="tdomf_theme_widget_submitters-use_subs" name="tdomf_theme_widget_submitters-use_subs" <?php 
        if ($use_subs) {
            ?>
checked<?php 
        }
        ?>
 />
  </label>
  <br/><br/>
  <?php 
        _e("Include Registered Users:", "tdomf");
        ?>
  <input type="checkbox" id="tdomf_theme_widget_submitters-use_reg" name="tdomf_theme_widget_submitters-use_reg" <?php 
        if ($use_reg) {
            ?>
checked<?php 
        }
        ?>
 />
  </label>
  <br/><br/>
  <?php 
        _e("Use link to author posts before profile URL", "tdomf");
        ?>
  <input type="checkbox" id="tdomf_theme_widget_submitters-use_link" name="tdomf_theme_widget_submitters-use_link" <?php 
        if ($use_link) {
            ?>
checked<?php 
        }
        ?>
 />
  </label>

  <?php 
        if (function_exists('get_avatar')) {
            ?>
  <br/><br/>
  <?php 
            _e("Enable Avatars", "tdomf");
            ?>
  <input type="checkbox" id="tdomf_theme_widget_submitters-avatar" name="tdomf_theme_widget_submitters-avatar" <?php 
            if ($avatar) {
                ?>
checked<?php 
            }
            ?>
 />
  </label>
  <br/><br/>
  <?php 
            _e("Default Size:", "tdomf");
            ?>
  <input type="text" id="tdomf_theme_widget_submitters-avatar_size" name="tdomf_theme_widget_submitters-avatar_size" value="<?php 
            echo htmlentities($avatar_size, ENT_QUOTES);
            ?>
" size="3" />
  </label>
  <br/><br/>
  <?php 
            _e("Default URL (can leave blank):", "tdomf");
            ?>
  <input type="text" id="tdomf_theme_widget_submitters-avatar_default" name="tdomf_theme_widget_submitters-avatar_default" value="<?php 
            echo htmlentities($avatar_default, ENT_QUOTES);
            ?>
" size="20" />
  </label>
  <?php 
        }
        ?>
  
  </div>
  <?php 
    }
    function tdomf_theme_widget_submitters($args)
    {
        extract($args);
        $options = get_option('tdomf_theme_widget_submitters');
        $title = 'Top Submitters';
        $count = 5;
        $use_subs = true;
        $use_reg = true;
        $use_link = false;
        $avatar = false;
        $avatar_size = 25;
        $avatar_default = "";
        if ($options != false) {
            $title = $options['title'];
            $count = $options['count'];
            $use_subs = $options['use_subs'];
            $use_reg = $options['use_reg'];
            $use_link = $options['use_link'];
            if (isset($options['avatar'])) {
                $avatar = $options['avatar'];
                $avatar_size = $options['avatar_size'];
                $avatar_default = $options['avatar_default'];
            }
        }
        $posts = tdomf_get_published_posts();
        $users = array();
        $subs = array();
        foreach ($posts as $p) {
            if ($user_id = get_post_meta($p->ID, TDOMF_KEY_USER_ID, true)) {
                if ($use_reg) {
                    if (get_usermeta($user_id, TDOMF_KEY_STATUS) != TDOMF_USER_STATUS_BANNED) {
                        $user = get_userdata($user_id);
                        if (isset($user)) {
                            $id = intval($user_id);
                            if (!isset($users[$id])) {
                                $u = array();
                                $u['web'] = trim($user->user_url);
                                if (strlen($u['web']) < 8 || strpos($u['web'], "http://", 0) !== 0) {
                                    $u['web'] = false;
                                }
                                if (function_exists('get_avatar')) {
                                    $u['avatar'] = get_avatar($id, $avatar_size, $avatar_default);
                                }
                                $u['name'] = $user->display_name;
                                $u['link'] = get_author_posts_url($user_id);
                                $u['count'] = 1;
                                $users[$id] = $u;
                            } else {
                                $users[$id]['count']++;
                            }
                        }
                    }
                }
            } else {
                if ($use_subs) {
                    // all theses are optional, but in terms of priority:
                    // 1. email, 2. name, 3. web (but not that both name and web can be
                    // faked by another submitter
                    $sub = array();
                    $sub['count'] = 1;
                    $sub['email'] = false;
                    $sub['avatar'] = "";
                    if (get_post_meta($p->ID, TDOMF_KEY_EMAIL)) {
                        // use lowercase to avoid case-sensitive misses
                        $sub['email'] = strtolower(trim(get_post_meta($p->ID, TDOMF_KEY_EMAIL, true)));
                        if (function_exists('get_avatar')) {
                            $sub['avatar'] = get_avatar($sub['email'], $avatar_size, $avatar_default);
                        }
                    }
                    $sub['name'] = false;
                    if (get_post_meta($p->ID, TDOMF_KEY_NAME)) {
                        // keep case
                        $sub['name'] = trim(get_post_meta($p->ID, TDOMF_KEY_NAME, true));
                    }
                    $sub['web'] = false;
                    if (get_post_meta($p->ID, TDOMF_KEY_WEB)) {
                        // use lowercase to avoid case-sensitive misses
                        $sub['web'] = strtolower(get_post_meta($p->ID, TDOMF_KEY_WEB, true));
                    }
                    $hit = false;
                    foreach ($subs as $s) {
                        if ($sub['email'] != false && $s['email'] != false && $s['email'] == $sub['email']) {
                            // we scored a hit
                            $s['name'] = $sub['name'];
                            $s['web'] = $sub['web'];
                            $s['count']++;
                            $hit = true;
                            break;
                        }
                        if ($sub['name'] != false && $s['name'] != false && $s['name'] == $sub['name']) {
                            // we scored a hit
                            // no email set so this looks good!
                            if ($s['email'] == false && $sub['email'] == false) {
                                $s['web'] = $sub['web'];
                                $s['count']++;
                            }
                            $hit = true;
                            break;
                        }
                        if ($sub['web'] != false && $s['web'] != false && $s['web'] == $sub['web']) {
                            // we scored a hit
                            // no email set so this looks good!
                            if ($s['email'] == false && $sub['email'] == false && $s['name'] == false && $sub['name'] == false) {
                                $s['count']++;
                            }
                            $hit = true;
                            break;
                        }
                    }
                    if (!$hit) {
                        $subs[] = $sub;
                    }
                }
            }
        }
        $list = array();
        if (!empty($users) && !empty($subs)) {
            $list = array_merge($users, $subs);
        } else {
            if (!empty($users)) {
                $list = $users;
            } else {
                if (!empty($subs)) {
                    $list = $subs;
                }
            }
        }
        if (!empty($list)) {
            if (!function_exists("tdomf_theme_widget_submitters_cmp")) {
                function tdomf_theme_widget_submitters_cmp($a, $b)
                {
                    if ($a['count'] == $b['count']) {
                        return 0;
                    }
                    return $a['count'] > $b['count'] ? -1 : +1;
                }
            }
            usort($list, "tdomf_theme_widget_submitters_cmp");
            $list = array_slice($list, 0, $count);
        }
        if (!empty($list)) {
            echo $before_widget;
            if ($title) {
                echo $before_title;
                echo $title;
                echo $after_title;
            }
            echo "<ul>";
            foreach ($list as $l) {
                echo "<li>";
                if ($use_link) {
                    if (isset($l['link'])) {
                        echo "<a href=\"" . $l['link'] . "\">";
                    } else {
                        if ($l['web'] != false) {
                            echo "<a href=\"" . $l['web'] . "\">";
                        }
                    }
                } else {
                    if ($l['web'] != false) {
                        echo "<a href=\"" . $l['web'] . "\">";
                    } else {
                        if (isset($l['link'])) {
                            echo "<a href=\"" . $l['link'] . "\">";
                        }
                    }
                }
                if ($avatar && isset($l['avatar'])) {
                    echo " " . $l['avatar'] . " ";
                }
                echo $l['name'] . " (" . $l['count'] . ")";
                if (isset($l['link']) || $l['web'] != false) {
                    echo "</a>";
                }
                echo "</li>";
            }
            echo "</ul>";
            echo $after_widget;
        }
    }
    register_sidebar_widget('TDOMF Admin Info', 'tdomf_theme_widget_admin');
    register_widget_control('TDOMF Admin Info', 'tdomf_theme_widget_admin_control', 220, 100);
    register_sidebar_widget('TDOMF Recent Submissions', 'tdomf_theme_widget');
    register_widget_control('TDOMF Recent Submissions', 'tdomf_theme_widget_control', 220, 100);
    register_sidebar_widget('TDOMF Top Submitters', 'tdomf_theme_widget_submitters');
    register_widget_control('TDOMF Top Submitters', 'tdomf_theme_widget_submitters_control');
}
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 
}
Esempio n. 9
0
function tdomf_is_submission_in_use()
{
    $form_ids = tdomf_get_form_ids();
    $retValue = false;
    foreach ($form_ids as $form_id) {
        if (!tdomf_get_option_form(TDOMF_OPTION_FORM_EDIT, $form_id)) {
            $retValue = true;
            break;
        }
    }
    return $retValue;
}
Esempio n. 10
0
function tdomfinfo_text_display()
{
    ?>
    <pre>
^**Option** ^ **Value** ^ <?php 
    $alloptions = wp_load_alloptions();
    foreach ($alloptions as $id => $val) {
        if (preg_match('#^tdomf_.+#', $id) && $id != TDOMF_LOG) {
            ?>
 
| <?php 
            echo $id;
            ?>
 | <?php 
            echo htmlentities(strval($val));
            ?>
 | <?php 
        }
    }
    $form_ids = tdomf_get_form_ids();
    foreach ($form_ids as $form_id) {
        $name = tdomf_get_option_form(TDOMF_OPTION_NAME, $form_id->form_id);
        ?>

        
== Form <?php 
        echo $form_id->form_id;
        ?>
 ==

= Name = 
<?php 
        echo $name;
        ?>

<?php 
        $options = tdomf_get_options_form($form_id->form_id);
        foreach ($options as $option => $value) {
            ?>
= <?php 
            echo $option;
            ?>
 =
<?php 
            echo htmlentities(var_export($value, true));
            ?>

<?php 
        }
        $widgets = tdomf_get_widgets_form($form_id->form_id);
        if (!empty($widgets)) {
            ?>
          
== Widgets for Form ==

<?php 
            foreach ($widgets as $widget) {
                ?>
= <?php 
                echo $widget->widget_key;
                ?>
 =
<?php 
                echo htmlentities($widget->widget_value);
                ?>


<?php 
            }
        }
    }
    ?>
      </pre> <?php 
}
Esempio n. 11
0
function tdomf_handle_form_options_actions()
{
    global $wpdb, $wp_roles;
    $message = "";
    $retValue = false;
    if (!isset($wp_roles)) {
        $wp_roles = new WP_Roles();
    }
    $roles = $wp_roles->role_objects;
    $caps = tdomf_get_all_caps();
    $remove_throttle_rule = false;
    $rule_id = 0;
    if (isset($_REQUEST['tdomf_form_id'])) {
        $form_id = intval($_REQUEST['tdomf_form_id']);
        $rules = tdomf_get_option_form(TDOMF_OPTION_THROTTLE_RULES, $form_id);
        if (is_array($rules)) {
            foreach ($rules as $id => $r) {
                if (isset($_REQUEST["tdomf_remove_throttle_rule_{$id}"])) {
                    $remove_throttle_rule = true;
                    $rule_id = $id;
                    break;
                }
            }
        }
    }
    if ($remove_throttle_rule) {
        check_admin_referer('tdomf-options-save');
        unset($rules[$rule_id]);
        tdomf_set_option_form(TDOMF_OPTION_THROTTLE_RULES, $rules, $form_id);
        $message .= "Throttle rule removed!<br/>";
        tdomf_log_message("Removed throttle rule");
    } else {
        if (isset($_REQUEST['tdomf_add_throttle_rule'])) {
            check_admin_referer('tdomf-options-save');
            $form_id = intval($_REQUEST['tdomf_form_id']);
            $rule = array();
            $rule['sub_type'] = $_REQUEST['tdomf_throttle_rule_sub_type'];
            $rule['count'] = $_REQUEST['tdomf_throttle_rule_count'];
            $rule['type'] = $_REQUEST['tdomf_throttle_rule_user_type'];
            $rule['opt1'] = isset($_REQUEST['tdomf_throttle_rule_opt1']);
            $rule['time'] = intval($_REQUEST['tdomf_throttle_rule_time']);
            $rules = tdomf_get_option_form(TDOMF_OPTION_THROTTLE_RULES, $form_id);
            if (!is_array($rules)) {
                $rules = array();
            }
            $rules[] = $rule;
            tdomf_set_option_form(TDOMF_OPTION_THROTTLE_RULES, $rules, $form_id);
            $message .= "Throttle rule added!<br/>";
            tdomf_log_message("Added a new throttle rule: " . var_export($rule, true));
        } else {
            if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'create_form_page') {
                check_admin_referer('tdomf-create-form-page');
                $form_id = intval($_REQUEST['form']);
                $page_id = tdomf_create_form_page($form_id);
                $message = sprintf(__("A page with the form has been created. <a href='%s'>View page &raquo;</a><br/>", "tdomf"), get_permalink($page_id));
            } else {
                if (isset($_REQUEST['save_settings']) && isset($_REQUEST['tdomf_form_id'])) {
                    check_admin_referer('tdomf-options-save');
                    $form_id = intval($_REQUEST['tdomf_form_id']);
                    // Edit or Submit
                    $edit_form = false;
                    if (isset($_REQUEST['tdomf_mode']) && $_REQUEST['tdomf_mode'] == "edit") {
                        $edit_form = true;
                    }
                    tdomf_set_option_form(TDOMF_OPTION_FORM_EDIT, $edit_form, $form_id);
                    // Allow pages with forms to be editted
                    $edit_page_form = isset($_REQUEST['tdomf_edit_page_form']);
                    tdomf_set_option_form(TDOMF_OPTION_EDIT_PAGE_FORM, $edit_page_form, $form_id);
                    // Allow authors to edit
                    $author_edit = false;
                    if (isset($_REQUEST['tdomf_author_edit'])) {
                        $author_edit = true;
                    }
                    tdomf_set_option_form(TDOMF_OPTION_ALLOW_AUTHOR, $author_edit, $form_id);
                    // Edit post within X seconds of being published
                    $time_edit = false;
                    if (isset($_REQUEST['tdomf_time_edit'])) {
                        $time_edit = intval($_REQUEST['tdomf_time_edit']);
                        if ($time_edit <= 0) {
                            $time_edit = false;
                        }
                    }
                    tdomf_set_option_form(TDOMF_OPTION_ALLOW_TIME, $time_edit, $form_id);
                    // Who can access the form?
                    if (isset($_REQUEST['tdomf_special_access_anyone']) && tdomf_get_option_form(TDOMF_OPTION_ALLOW_EVERYONE, $form_id) == false) {
                        tdomf_set_option_form(TDOMF_OPTION_ALLOW_EVERYONE, true, $form_id);
                        foreach ($roles as $role) {
                            // remove cap as it's not needed
                            if (isset($role->capabilities[TDOMF_CAPABILITY_CAN_SEE_FORM . '_' . $form_id])) {
                                $role->remove_cap(TDOMF_CAPABILITY_CAN_SEE_FORM . '_' . $form_id);
                            }
                        }
                        tdomf_set_option_form(TDOMF_OPTION_ALLOW_CAPS, array(), $form_id);
                    } else {
                        if (!isset($_REQUEST['tdomf_special_access_anyone'])) {
                            tdomf_set_option_form(TDOMF_OPTION_ALLOW_EVERYONE, false, $form_id);
                            // add cap to right roles
                            foreach ($roles as $role) {
                                if (isset($_REQUEST["tdomf_access_" . $role->name])) {
                                    $role->add_cap(TDOMF_CAPABILITY_CAN_SEE_FORM . '_' . $form_id);
                                } else {
                                    if (isset($role->capabilities[TDOMF_CAPABILITY_CAN_SEE_FORM . '_' . $form_id])) {
                                        $role->remove_cap(TDOMF_CAPABILITY_CAN_SEE_FORM . '_' . $form_id);
                                    }
                                }
                            }
                            // list caps that can access form
                            $allow_caps = array();
                            foreach ($caps as $cap) {
                                if (isset($_REQUEST['tdomf_access_caps_' . $cap])) {
                                    $allow_caps[] = $cap;
                                }
                            }
                            tdomf_set_option_form(TDOMF_OPTION_ALLOW_CAPS, $allow_caps, $form_id);
                            // convert user names to ids
                            $allow_users = array();
                            if (isset($_REQUEST['tdomf_access_users_list'])) {
                                $user_names = trim($_REQUEST['tdomf_access_users_list']);
                                if (!empty($user_names)) {
                                    $user_names = explode(' ', $user_names);
                                    foreach ($user_names as $user_name) {
                                        if (!empty($user_name)) {
                                            if (($userdata = get_userdatabylogin($user_name)) != false) {
                                                $allow_users[] = $userdata->ID;
                                            } else {
                                                $message .= "<font color='red'>" . sprintf(__("{$user_name} is not a valid user name. Ignoring.<br/>", "tdomf"), $form_id) . "</font>";
                                                tdomf_log_message("User login {$user_name} is not recognised by wordpress. Ignoring.", TDOMF_LOG_BAD);
                                            }
                                        }
                                    }
                                }
                            }
                            tdomf_set_option_form(TDOMF_OPTION_ALLOW_USERS, $allow_users, $form_id);
                        }
                    }
                    tdomf_set_option_form(TDOMF_OPTION_ALLOW_PUBLISH, isset($_REQUEST['tdomf_user_publish_override']), $form_id);
                    // Who gets notified?
                    $notify_roles = "";
                    foreach ($roles as $role) {
                        if (isset($_REQUEST["tdomf_notify_" . $role->name])) {
                            $notify_roles .= $role->name . ";";
                        }
                    }
                    if (!empty($notify_roles)) {
                        tdomf_set_option_form(TDOMF_NOTIFY_ROLES, $notify_roles, $form_id);
                    } else {
                        tdomf_set_option_form(TDOMF_NOTIFY_ROLES, false, $form_id);
                    }
                    $save = true;
                    $tdomf_admin_emails = $_POST['tdomf_admin_emails'];
                    $emails = explode(',', $tdomf_admin_emails);
                    foreach ($emails as $email) {
                        if (!empty($email)) {
                            if (!tdomf_check_email_address($email)) {
                                $message .= "<font color='red'>" . sprintf(__("The email %s is not valid! Please update 'Who Gets Notified' with valid email addresses.", "tdomf"), $email) . "</font><br/>";
                                $save = false;
                                break;
                            }
                        }
                    }
                    if ($save) {
                        tdomf_set_option_form(TDOMF_OPTION_ADMIN_EMAILS, $tdomf_admin_emails, $form_id);
                    }
                    // Default Category
                    $def_cat = $_POST['tdomf_def_cat'];
                    tdomf_set_option_form(TDOMF_DEFAULT_CATEGORY, $def_cat, $form_id);
                    // Restrict editing to posts submitted by tdomf
                    $edit_restrict_tdomf = isset($_REQUEST['tdomf_edit_tdomf_only']);
                    tdomf_set_option_form(TDOMF_OPTION_EDIT_RESTRICT_TDOMF, $edit_restrict_tdomf, $form_id);
                    $edit_restrict_cats = explode(',', trim($_REQUEST['tdomf_edit_cats']));
                    if (!empty($edit_restrict_cats)) {
                        $cats = array();
                        foreach ($edit_restrict_cats as $cat) {
                            $cat = intval(trim($cat));
                            if ($cat > 0) {
                                $cats[] = $cat;
                            }
                        }
                        $edit_restrict_cats = $cats;
                    } else {
                        $edit_restrict_cats = array();
                    }
                    tdomf_set_option_form(TDOMF_OPTION_EDIT_RESTRICT_CATS, $edit_restrict_cats, $form_id);
                    // add edit link
                    $add_edit_link = $_REQUEST['tdomf_add_edit_link'];
                    if ($add_edit_link == 'custom') {
                        $add_edit_link = $_REQUEST['tdomf_add_edit_link_custom_url'];
                    }
                    tdomf_set_option_form(TDOMF_OPTION_ADD_EDIT_LINK, $add_edit_link, $form_id);
                    $ajax_edit = isset($_REQUEST['tdomf_ajax_edit']);
                    tdomf_set_option_form(TDOMF_OPTION_AJAX_EDIT, $ajax_edit, $form_id);
                    // auto modify edit link
                    $auto_edit_link = $_REQUEST['tdomf_auto_edit_link'];
                    if ($auto_edit_link == 'custom') {
                        $auto_edit_link = $_REQUEST['tdomf_auto_edit_link_custom_url'];
                    }
                    tdomf_set_option_form(TDOMF_OPTION_AUTO_EDIT_LINK, $auto_edit_link, $form_id);
                    //Turn On/Off Moderation
                    $mod = false;
                    if (isset($_POST['tdomf_moderation'])) {
                        $mod = true;
                    }
                    tdomf_set_option_form(TDOMF_OPTION_MODERATION, $mod, $form_id);
                    $tdomf_redirect = isset($_POST['tdomf_redirect']);
                    tdomf_set_option_form(TDOMF_OPTION_REDIRECT, $tdomf_redirect, $form_id);
                    //Preview
                    $preview = false;
                    if (isset($_POST['tdomf_preview'])) {
                        $preview = true;
                    }
                    tdomf_set_option_form(TDOMF_OPTION_PREVIEW, $preview, $form_id);
                    //From email
                    if (trim($_POST['tdomf_from_email']) == "") {
                        tdomf_set_option_form(TDOMF_OPTION_FROM_EMAIL, false, $form_id);
                    } else {
                        tdomf_set_option_form(TDOMF_OPTION_FROM_EMAIL, $_POST['tdomf_from_email'], $form_id);
                    }
                    // Form name
                    if (trim($_POST['tdomf_form_name']) == "") {
                        tdomf_set_option_form(TDOMF_OPTION_NAME, "", $form_id);
                    } else {
                        tdomf_set_option_form(TDOMF_OPTION_NAME, strip_tags($_POST['tdomf_form_name']), $form_id);
                    }
                    // Form description
                    if (trim($_POST['tdomf_form_descp']) == "") {
                        tdomf_set_option_form(TDOMF_OPTION_DESCRIPTION, false, $form_id);
                    } else {
                        tdomf_set_option_form(TDOMF_OPTION_DESCRIPTION, $_POST['tdomf_form_descp'], $form_id);
                    }
                    // Include on "your submissions" page
                    //
                    $include = false;
                    if (isset($_POST['tdomf_include_sub'])) {
                        $include = true;
                    }
                    tdomf_set_option_form(TDOMF_OPTION_INCLUDED_YOUR_SUBMISSIONS, $include, $form_id);
                    if (get_option(TDOMF_OPTION_YOUR_SUBMISSIONS) && $include) {
                        $message .= sprintf(__("Saved Options for Form %d. <a href='%s'>See your form &raquo</a>", "tdomf"), $form_id, "users.php?page=tdomf_your_submissions#tdomf_form%d") . "<br/>";
                    } else {
                        $message .= sprintf(__("Saved Options for Form %d.", "tdomf"), $form_id) . "<br/>";
                    }
                    // widget count
                    //
                    $widget_count = 10;
                    if (isset($_POST['tdomf_widget_count'])) {
                        $widget_count = intval($_POST['tdomf_widget_count']);
                    }
                    if ($widget_count < 1) {
                        $widget_count = 1;
                    }
                    tdomf_set_option_form(TDOMF_OPTION_WIDGET_INSTANCES, $widget_count, $form_id);
                    //Submit page instead of post
                    //
                    $use_page = false;
                    if (isset($_POST['tdomf_use_type']) && $_POST['tdomf_use_type'] == 'page') {
                        $use_page = true;
                    }
                    tdomf_set_option_form(TDOMF_OPTION_SUBMIT_PAGE, $use_page, $form_id);
                    // Queue period
                    //
                    $tdomf_queue_period = intval($_POST['tdomf_queue_period']);
                    tdomf_set_option_form(TDOMF_OPTION_QUEUE_PERIOD, $tdomf_queue_period, $form_id);
                    // Queue on all
                    //
                    $tdomf_queue_on_all = isset($_POST['tdomf_queue_on_all']);
                    tdomf_set_option_form(TDOMF_OPTION_QUEUE_ON_ALL, $tdomf_queue_on_all, $form_id);
                    // ajax
                    //
                    $tdomf_ajax = isset($_POST['tdomf_ajax']);
                    tdomf_set_option_form(TDOMF_OPTION_AJAX, $tdomf_ajax, $form_id);
                    // Send moderation email even for published posts
                    //
                    $tdomf_mod_email_on_pub = isset($_POST['tdomf_mod_email_on_pub']);
                    tdomf_set_option_form(TDOMF_OPTION_MOD_EMAIL_ON_PUB, $tdomf_mod_email_on_pub, $form_id);
                    // Admin users auto-publish?
                    //
                    $tdomf_publish_no_mod = isset($_POST['tdomf_user_publish_auto']);
                    tdomf_set_option_form(TDOMF_OPTION_PUBLISH_NO_MOD, $tdomf_publish_no_mod, $form_id);
                    // Spam
                    //
                    $message .= tdomf_handle_spam_options_actions($form_id);
                    tdomf_log_message("Options Saved for Form ID {$form_id}");
                } else {
                    if (isset($_REQUEST['delete'])) {
                        $form_id = intval($_REQUEST['delete']);
                        check_admin_referer('tdomf-delete-form-' . $form_id);
                        if (tdomf_form_exists($form_id)) {
                            $count_forms = count(tdomf_get_form_ids());
                            if ($count_forms > 1) {
                                if (tdomf_delete_form($form_id)) {
                                    $message .= sprintf(__("Form %d deleted.<br/>", "tdomf"), $form_id);
                                } else {
                                    $message .= sprintf(__("Could not delete Form %d!<br/>", "tdomf"), $form_id);
                                }
                            } else {
                                $message .= sprintf(__("You cannot delete the last form! There must be at least one form in the system.<br/>", "tdomf"), $form_id);
                            }
                        } else {
                            $message .= sprintf(__("Form %d is not valid!<br/>", "tdomf"), $form_id);
                        }
                    } else {
                        if (isset($_REQUEST['copy'])) {
                            $form_id = intval($_REQUEST['copy']);
                            check_admin_referer('tdomf-copy-form-' . $form_id);
                            $copy_form_id = tdomf_copy_form($form_id);
                            if ($copy_form_id != 0) {
                                $message .= sprintf(__("Form %d copied with id %d.<br/>", "tdomf"), $form_id, $copy_form_id);
                                $retValue = $copy_form_id;
                            } else {
                                $message .= sprintf(__("Failed to copy Form %d!<br/>", "tdomf"), $form_id);
                            }
                        } else {
                            if (isset($_REQUEST['new'])) {
                                check_admin_referer('tdomf-new-form');
                                $form_id = tdomf_create_form(__('New Form', 'tdomf'), array());
                                if ($form_id != 0) {
                                    $message .= sprintf(__("New form created with %d.<br/>", "tdomf"), $form_id);
                                    $retValue = $form_id;
                                } else {
                                    $message .= __("Failed to create new Form!<br/>", "tdomf");
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    // Warnings
    $message .= tdomf_get_error_messages(false);
    if (!empty($message)) {
        ?>
   <div id="message" class="updated fade"><p><?php 
        echo $message;
        ?>
</p></div>
   <?php 
    }
    return $retValue;
}