예제 #1
0
function ladderLength($start, $end, $dict)
{
    $visited = array($start);
    for ($i = 0; $i < count($dict); $i++) {
        foreach ($dict as $key => $value) {
            if (isMatch($start, $value) && !in_array($value, $visited)) {
                $visited[] = $value;
                $start = $value;
                if (isMatch($start, $end)) {
                    $visited[] = $end;
                    return $visited;
                }
            }
        }
    }
    return $visited;
}
function isMatch($s, $p)
{
    if ($s == $p) {
        return true;
    }
    if (empty($p)) {
        return $s == '';
    }
    if (@$p[1] != '*') {
        return ($s[0] == $p[0] || $p[0] == '.' && isset($s[0])) && isMatch(substr($s, 1), substr($p, 1));
    }
    $i = 0;
    while (@$s[$i] == $p[0] || $p[0] == '.' && isset($s[$i])) {
        if (isMatch($s, substr($p, 2))) {
            return true;
        }
        $i++;
    }
    return isMatch(substr($s, $i), substr($p, 2));
}
function displayFastEdit()
{
    if ($_REQUEST['action'] == 'update') {
        $posts = getPosts($_REQUEST['categories'], $_REQUEST['s'], $num);
        $ids = array();
        $content = trim(stripslashes($_REQUEST['content']));
        $content_stripped = strip_tags($_POST['content']);
        $updated = 0;
        foreach ($posts as $post) {
            $post_content = trim($post->post_content);
            if (!$_REQUEST['location']) {
                //at the start
                //check if it is existent
                $match = isMatchAtStart($post_content, $content, $newContent);
                if (!$match && $_POST['actionType'] == 'insert') {
                    $post_content = $content . '<br /><br />' . $post_content;
                    $updated++;
                } else {
                    if ($match && $_REQUEST['actionType'] == 'delete') {
                        $post_content = preg_replace('/<br *?\\/?><br *\\/?>(<\\/body><\\/html>)?$/i', '$1', $newContent);
                        $updated++;
                    } else {
                        $skipped++;
                    }
                }
            } else {
                //at the end
                //check if it is existent
                $match = isMatch($post_content, $content, $newContent);
                if (!$match && $_POST['actionType'] == 'insert') {
                    $post_content = $post_content . '<br /><br />' . $content;
                    $updated++;
                } else {
                    if ($match && $_REQUEST['actionType'] == 'delete') {
                        $post_content = preg_replace('/<br *?\\/?><br *\\/?>(<\\/body><\\/html>)?$/i', '$1', $newContent);
                        $updated++;
                    } else {
                        $skipped++;
                    }
                }
            }
            wp_update_post(array('ID' => $post->ID, 'post_content' => $post_content));
        }
        if ($_POST['actionType'] == 'insert') {
            $message = 'Updated ' . $updated . ' posts';
            if ($skipped > 0) {
                $message .= ' and skipped ' . $skipped . ' posts because they have the text already';
            }
        } else {
            $message = 'Updated ' . $updated . ' posts';
            if ($skipped > 0) {
                $message .= ' and skipped ' . $skipped . ' posts because they do not have the text';
            }
        }
        $messages[] = $message . '.';
    }
    ?>
<style>

#poststuff .inside {
    margin: 0;
    padding: 0;
}
</style>
<script>
	jQuery(document).ready(function() {
		jQuery('#post-search-keyword, #categories').change(function() {
			jQuery.ajax({
				url:ajaxurl,
				data:{
					action:'getResultNumber',
					keyword:jQuery('#post-search-keyword').val(),
					category:jQuery('#categories').val(),
				},
				success: function(data) {
					jQuery('#postsCountBox').text('Matches: '+data+' posts');
				}
			});
		});
	});
</script>
<div class="wrap">
<form id="posts-filter" action="" method="post">
<input type="hidden" name="action" value="update" />
<h2><?php 
    echo __('Fast Edit Plugin');
    ?>
</h2>
<?php 
    if (!empty($messages)) {
        echo '<div id="message" class="updated"><p>' . join(' ', $messages) . '</p></div>';
    }
    unset($messages);
    ?>
<div id="poststuff">
<div id="post-body" class="columns-2">


<?php 
    $args = array('show_option_all' => 'All Categories', 'show_option_none' => '', 'orderby' => 'ID', 'order' => 'ASC', 'show_count' => 0, 'hide_empty' => 1, 'child_of' => 0, 'exclude' => '', 'echo' => 1, 'selected' => $_POST['category'], 'hierarchical' => 1, 'name' => 'categories', 'id' => 'categories', 'class' => 'postform', 'depth' => 0, 'tab_index' => 0, 'taxonomy' => 'category', 'hide_if_empty' => false, 'walker' => '');
    ?>
<input type="hidden" name="post_type" class="post_type_page" value="<?php 
    echo $post_type;
    ?>
" />

<div id="post-body-content">
<?php 
    the_editor(stripslashes($_POST['content']), $id = 'content', $prev_id = 'title', $media_buttons = false, $tab_index = 2);
    ?>
</div>
<div class="postbox" id="postbox-container-1">
<h3 class="hndle"><span>Search Criteria / Action</span></h3>

<div class="inside">
<div style="border-bottom: 1px solid #DDDDDD;border-top: 1px solid #FFFFFF;padding: 10px 12px 0;">
<p><b>Filter by Cartegory:</b></p>
<?php 
    wp_dropdown_categories($args);
    ?>
 

 <p><b>
	Filter By Keyword:
</b></p>
 <p>	<input type="search" value="" name="s" id="post-search-keyword">
</p>
</div>
<div style="border-bottom: 1px solid #DDDDDD;border-top: 1px solid #FFFFFF;padding: 10px 12px 0;">

 <p><b>
	What to do?
</b></p>
 <p>
	<input type="radio" value="insert" name="actionType"<?php 
    if ($_POST['actionType'] != 'delete') {
        echo ' checked="checked"';
    }
    ?>
> Insert Text<br />
	<input type="radio" value="delete" name="actionType"<?php 
    if ($_POST['actionType'] == 'delete') {
        echo ' checked="checked"';
    }
    ?>
> Delete Text <br />
</p>
</div>
<div style="border-bottom: 1px solid #DDDDDD;border-top: 1px solid #FFFFFF;padding: 10px 12px 0;">

 <p><b>
	Insertion Location
</b></p>
 <p>
	<input type="radio" value="0" name="location"<?php 
    if (isset($_POST['location']) && $_POST['location'] != '1') {
        echo ' checked="checked"';
    }
    ?>
> At the start<br />
	<input type="radio" value="1" name="location"<?php 
    if (!isset($_POST['location']) || $_POST['location'] == '1') {
        echo ' checked="checked"';
    }
    ?>
> At the end<br />
</p></div>
<div style="float:left;padding: 1em 10px;" id="postsCountBox"></div>
<p style="border-top: 1px solid #FFFFFF;margin: 0;padding: 1em 10px;text-align: right;">

<input type="submit" value="Update" class="button button-primary button-large" id="updatePosts" name="">
</p>
</div>


</div>
</div>
</form>

</div>
<?php 
}
예제 #4
0
파일: index.php 프로젝트: jimng/dotdotdot
                                    $num = rand(1, $count);
                                    $quote = getSQLRows($con, "SELECT quote from bible where id = {$num}")[0]['quote'];
                                    sendMessage($id, $quote);
                                } else {
                                    if (isMatch($input[0], '/noit')) {
                                        $con = connectDB();
                                        $count = getSQLRows($con, 'SELECT count(1) ct FROM noit')[0]['ct'];
                                        $num = rand(1, $count);
                                        $quote = getSQLRows($con, "SELECT quote from noit where id = {$num}")[0]['quote'];
                                        sendMessage($id, $quote);
                                    } else {
                                        if (isMatch($input[0], '/echo')) {
                                            $msg = implode(' ', array_slice($input, 1));
                                            sendMessage('-42984161', $msg);
                                        } else {
                                            if (isMatch($input[0], '/hknews')) {
                                                $resp = json_decode(file_get_contents("http://localhost:8080/news"))->text;
                                                sendMessage($id, $resp, '&disable_web_page_preview=true');
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    writeLog($id, $text);
} else {