Esempio n. 1
0
 static function minify_javascript(&$root, $indent_string = ' ', $wrap_comment = true, $recursive = true)
 {
     include_once 'third party/jsminplus.php';
     $errors = array();
     foreach ($root->select('script:not-empty > "~text~"', false, $recursive, true) as $c) {
         try {
             $text = $c->text;
             while ($text) {
                 $text = trim($text);
                 if (substr($text, 0, 4) === '<!--') {
                     $text = substr($text, 5);
                     continue;
                 } elseif (strtolower(substr($text, 0, 9)) === '<![cdata[') {
                     $text = substr($text, 10);
                     continue;
                 }
                 if (($end = substr($text, -3)) && ($end === '-->' || $end === ']]>')) {
                     $text = substr($text, 0, -3);
                     continue;
                 }
                 break;
             }
             if (trim($text)) {
                 $text = JSMinPlus::minify($text);
                 if ($wrap_comment) {
                     $text = "<!--\n" . $text . "\n//-->";
                 }
                 if ($indent_string && ($wrap_comment || strpos($text, "\n") !== false)) {
                     $text = indent_text("\n" . $text, $c->indent(), $indent_string);
                 }
             }
             $c->text = $text;
         } catch (Exception $e) {
             $errors[] = array($e, $c->parent->dumpLocation());
         }
     }
     return $errors ? $errors : true;
 }
Esempio n. 2
0
/**
 * Indenting
 *
 * @param array   $tokens (reference)
 */
function indent(&$tokens)
{
    // Level of curly brackets
    $curly_braces_count = 0;
    // Level of round brackets
    $round_braces_count = 0;
    $round_brace_opener = false;
    $round_braces_control = 0;
    // Number of opened control structures without curly brackets inside of a level of curly brackets
    $control_structure = array(0);
    $heredoc_started = false;
    $trinity_started = false;
    foreach ($tokens as $key => &$token) {
        // Skip HEREDOC
        if ($heredoc_started) {
            if (isset($token[0]) and $token[0] === T_END_HEREDOC) {
                $heredoc_started = false;
            }
            continue;
        }
        // Detect beginning of a HEREDOC block
        if (isset($token[0]) and $token[0] === T_START_HEREDOC) {
            $heredoc_started = true;
            continue;
        }
        // The closing bracket itself has to be not indented again, so we decrease the brackets count before we reach the bracket.
        if (isset($tokens[$key + 1])) {
            if (is_string($tokens[$key + 1])) {
                if (is_string($token) or $token[0] !== T_WHITESPACE or strpos($token[1], "\n") !== false) {
                    if ($tokens[$key + 1] === "}") {
                        --$curly_braces_count;
                    } elseif ($tokens[$key + 1] === ")") {
                        --$round_braces_count;
                    }
                }
            } else {
                if (isset($tokens[$key + 2]) and $tokens[$key + 1][0] === T_WHITESPACE and strpos($tokens[$key + 1][1], "\n") === false) {
                    if ($tokens[$key + 2] === "}") {
                        --$curly_braces_count;
                    } elseif ($tokens[$key + 2] === ")") {
                        --$round_braces_count;
                    }
                }
            }
        }
        if ($token === "(") {
            ++$round_braces_control;
        } elseif ($token === ")") {
            --$round_braces_control;
        }
        if ($token === "(") {
            if ($round_braces_control == 1) {
                // Remember which command was before the bracket
                $k = $key;
                do {
                    --$k;
                } while (isset($tokens[$k]) and ($tokens[$k][0] === T_WHITESPACE or $tokens[$k][0] === T_STRING));
                if (is_array($tokens[$k])) {
                    $round_brace_opener = $tokens[$k][0];
                } else {
                    $round_brace_opener = false;
                }
            }
            ++$round_braces_count;
        } elseif ($token === ")" and $round_braces_control == 0 and in_array($round_brace_opener, array(T_IF, T_ELSEIF, T_WHILE, T_FOR, T_FOREACH, T_SWITCH, T_FUNCTION)) or is_array($token) and ($token[0] === T_ELSE or $token[0] === T_DO)) {
            // All control stuctures end with a curly bracket, except "else" and "do".
            if (isset($control_structure[$curly_braces_count])) {
                ++$control_structure[$curly_braces_count];
            } else {
                $control_structure[$curly_braces_count] = 1;
            }
        } elseif ($token === ";" or $token === "}") {
            // After a command or a set of commands a control structure is closed.
            if (!empty($control_structure[$curly_braces_count])) {
                --$control_structure[$curly_braces_count];
            }
        } else {
            indent_text($tokens, $key, $curly_braces_count, $round_braces_count, $control_structure, is_array($token) and $token[0] === T_DOC_COMMENT, $trinity_started);
        }
        if ($token === "{" or is_array($token) and ($token[0] === T_CURLY_OPEN or $token[0] === T_DOLLAR_OPEN_CURLY_BRACES)) {
            // If a curly bracket occurs, no command without brackets can follow.
            if (!empty($control_structure[$curly_braces_count])) {
                --$control_structure[$curly_braces_count];
            }
            ++$curly_braces_count;
            // Inside of the new level of curly brackets it starts with no control structure.
            $control_structure[$curly_braces_count] = 0;
        }
    }
}
Esempio n. 3
0
if ($order == 'update') {
    $list_order = '<a href="' . $page_to . '#post-board-list" title="文章列表順序以發表時間排序">發表排序</a>';
    $page_to = $page_to . '?list_order=' . $order . '&';
} else {
    $list_order = '<a href="' . $page_to . '?list_order=update#post-board-list" title="文章列表順序以更新時間排序">更新排序</a>';
    $page_to = $page_to . '?';
}
?>
				<div id="post-list-order"><?php 
echo $list_order;
?>
</div>
				<div id="post-list-pages">
<?php 
$post_pages = page_list($current_page, $total_pages, 4, $page_to, 'post_page', 'post-board-list');
echo indent_text($post_pages, 5);
?>
				</div>
				<div id="post-list-action">
					<span id="post-action-write"><a href="<?php 
echo OUT_PATH . $BD;
?>
/post" title="在<?php 
echo $board_info['nicename'];
?>
發表文章"><img src="<?php 
echo get_stuff('silk/pencil_add.png');
?>
" alt="*">發表文章</a></span>
				</div>
			</div>
Esempio n. 4
0
</link>
<?php 
foreach ($result as $list) {
    ?>
		<item>
			<title><?php 
    echo 'No.' . $list['id'] . ': ' . $list['title'];
    ?>
</title>
			<link><?php 
    echo URL . '?reply=' . $list['id'];
    ?>
</link>
			<description>
<?php 
    echo indent_text(htmlspecialchars(add_link(nl2br($list['content'])), ENT_COMPAT, 'UTF-8'), 4);
    ?>
			</description>
			<author><?php 
    echo $list['author'];
    ?>
</author>
			<category><?php 
    if ($list['reply']) {
        echo 'Reply';
    } else {
        echo 'Post';
    }
    ?>
</category>
			<guid><?php 
Esempio n. 5
0
" title ="<?php 
echo $author_nicename;
?>
">
					<div id="post-view-author" class="post-view-meta"><span>AUTHOR: </span><strong><?php 
echo $author_nicename;
?>
</strong></div>
					<div id="post-view-title" class="post-view-meta"><span>TITLE: </span><strong><?php 
echo $title;
?>
</strong></div>
					<div id="post-view-time" class="post-view-meta" title="From: <?php 
echo $ip;
?>
"><span>TIME: </span><?php 
echo $row["post_date"];
?>
</div>
					<div id="post-view-actions" class="post-view-meta"><span>CATE: </span>未分類</div>
				</div>
				<div id="post-delete-body">
					<div id="post-delete-text">
<?php 
echo indent_text(show_text($row["post_content"]), 6);
?>
					</div>
				</div>
			</div>
<?php 
include load_template('footer');
Esempio n. 6
0
" />
					<span title="IP: <?php 
    echo long2ip($item['ip']);
    ?>
"><?php 
    if (empty($item['homepage'])) {
        echo $item['author'];
    } else {
        echo '<a href="' . $item['homepage'] . '">' . $item['author'] . '</a>';
    }
    ?>
</span>
				</aside>
				<section>
<?php 
    echo indent_text(add_link(nl2br($item['content'])), 4);
    ?>
				</section>
				<footer>
<?php 
    if ($admin || !empty($item['password'])) {
        ?>
					<span><a href="?modify=<?php 
        echo $item['id'];
        ?>
">Modify</a></span>
<?php 
    }
    ?>
					<time><?php 
    echo date('Y-m-d H:i:s', strtotime($item['datetime'] . ' UTC'));
Esempio n. 7
0
/**
 * Indenting
 *
 * @param array   $tokens (reference)
 */
function indent(&$tokens)
{

	// Level of curly brackets
	$curly_braces_count = 0;
	// Level of round brackets
	$round_braces_count = 0;
	
	$extra_indentation = 0;

	$round_brace_opener = false;
	$round_braces_control = 0;
	
	// Array to remember what control structure was last opened
	$control_structure_type = array();

	// Number of opened control structures without curly brackets inside of a level of curly brackets
	$control_structure = array(0);

	$heredoc_started = false;
	$trinity_started = false;
	
	
	$tokens_with_blocks = array(T_IF, T_ELSE, T_ELSEIF, T_SWITCH, T_CLASS, T_INTERFACE, T_FUNCTION, T_DO, T_WHILE, T_CATCH, T_TRY, T_FOREACH);

	foreach ( $tokens as $key => &$token ) {

		// Skip HEREDOC
		if ( $heredoc_started ) {
			if ( isset($token[0]) and $token[0] === T_END_HEREDOC ) {
				$heredoc_started = false;
			}
			continue;
		}

		// Detect beginning of a HEREDOC block
		if ( isset($token[0]) and $token[0] === T_START_HEREDOC ) {
			$heredoc_started = true;
			continue;
		}

		// The closing bracket itself has to be not indented again, so we decrease the brackets count before we reach the bracket.
		if (isset($tokens[$key+1])) {
			if (is_string($tokens[$key+1])) {
				if (
					is_string($token) or
					$token[0] !== T_WHITESPACE or
					strpos($token[1], "\n")!==false
				) {
					if ($tokens[$key+1] === "}") {
						--$curly_braces_count;
						// Remove the last token from out stack
						if (array_pop($control_structure_type) == T_SWITCH) {
							--$extra_indentation;
						}
					}
					elseif ($tokens[$key+1] === ")") --$round_braces_count;
				}
			} else {
				if (
					// If the next token is a T_WHITESPACE without a \n, we have to look at the one after the next.
					isset($tokens[$key+2]) and
					$tokens[$key+1][0] === T_WHITESPACE and
					strpos($tokens[$key+1][1], "\n")===false
				) {
					if ($tokens[$key+2] === "}") {
						--$curly_braces_count;
						// Remove the last token from out stack
						if (array_pop($control_structure_type) == T_SWITCH) {
							--$extra_indentation;
						}
					}
					elseif ($tokens[$key+2] === ")") --$round_braces_count;
				}
			}
		}

		if     ($token === "(") ++$round_braces_control;
		elseif ($token === ")") --$round_braces_control;

		if ( $token === "(" ) {

			if ($round_braces_control==1) {
				// Remember which command was before the bracket
				$k = $key;
				do {
					--$k;
				} while (
					isset($tokens[$k]) and (
						$tokens[$k][0] === T_WHITESPACE or
						$tokens[$k][0] === T_STRING
					)
				);
				if (is_array($tokens[$k])) {
					$round_brace_opener = $tokens[$k][0];
				} else {
					$round_brace_opener = false;
				}
			}

			++$round_braces_count;

		} elseif (
			(
				$token === ")" and
				$round_braces_control == 0 and
				in_array(
					$round_brace_opener,
					array(T_IF, T_ELSEIF, T_WHILE, T_FOR, T_FOREACH, T_SWITCH, T_FUNCTION)
				)
			) or (
				is_array($token) and (
					$token[0] === T_ELSE or $token[0] === T_DO
				)
			)
		) {
			// All control stuctures end with a curly bracket, except "else" and "do".
			if (isset($control_structure[$curly_braces_count])) {
				++$control_structure[$curly_braces_count];
			} else {
				$control_structure[$curly_braces_count] = 1;
			}

		} elseif ( $token === ";" or $token === "}" ) {
			// After a command or a set of commands a control structure is closed.
			if (!empty($control_structure[$curly_braces_count])) --$control_structure[$curly_braces_count];
			
			if ($token === "}") {
				
			}

		} else {
			indent_text(
				$tokens,
				$key,
				$curly_braces_count,
				$extra_indentation,
				$round_braces_count,
				$control_structure,
				(is_array($token) and $token[0] === T_DOC_COMMENT),
				$trinity_started
			);

		}

		if (
			$token === "{" or (
				is_array($token) and (
					$token[0] === T_CURLY_OPEN or
					$token[0] === T_DOLLAR_OPEN_CURLY_BRACES
				)
			)
		) {
			// If a curly bracket occurs, no command without brackets can follow.
			if (!empty($control_structure[$curly_braces_count])) --$control_structure[$curly_braces_count];
			++$curly_braces_count;
			
			// Inside of the new level of curly brackets it starts with no control structure.
			$control_structure[$curly_braces_count] = 0;

			// Find the last taken that can have a block and add it to the stack
			for ($i = $key; $tokens > 0; $i--) {
				if (isset($tokens[$i][0])) {
					if (in_array($tokens[$i][0], $tokens_with_blocks)) {
						$control_structure_type[] = $tokens[$i][0];
						break;
					}
				}
			}
			
			if (end($control_structure_type) == T_SWITCH) {
				++$extra_indentation;
			}
		}
		
		// Debugging code
		/*echo "\nStack:\n";
		foreach ($control_structure_type as $index => $structure) {
			echo $index.". ";
			echo token_name($structure)."\n";
		} */
	}

}
Esempio n. 8
0
				</li>
<?php 
}
?>
			</ul>
<?php 
if ($total_items > $items_page) {
    $items_pages = page_list($current_page, $total_pages, 4, OUT_PATH . $ID . '?', 'comment_page', 'comment-list');
    if ($current_page == 0) {
        $show_pages = '<a href="' . OUT_PATH . $ID . '#comment-list" title="分頁顯示回覆">分頁收合</a>';
    } else {
        $show_pages = '<a href="' . OUT_PATH . $ID . '?comment_page=0#comment-list" title="顯示全部回覆">展開回覆</a>';
    }
    ?>
			<div id="comment-list-footer">
				<div id="comment-pages-all"><?php 
    echo $show_pages;
    ?>
</div>
				<div id="comment-list-pages">
<?php 
    echo indent_text($items_pages, 5);
    ?>
				</div>
				<div id="comment-pages-count"><?php 
    echo $total_items;
    ?>
則回覆</div>
			</div>
<?php 
}
Esempio n. 9
0
?>
" alt="<?php 
echo $author_nicename;
?>
">
						<div class="comment-item-meta">
							<span class="comment-item-ip"><img src="<?php 
echo get_stuff('silk/information.png');
?>
" title="<?php 
echo $modify . 'From ' . $ip;
?>
" alt="info"></span>
							<span class="comment-item-date"><?php 
echo date('Y/m/d H:i', $time);
?>
</span>
							<span class="comment-item-author"><?php 
echo $author;
?>
</span>
						</div>
						<div id="comment-delete-text">
<?php 
echo indent_text(show_text($content), 7);
?>
						</div>
					</div>
				</div>
<?php 
include load_template('footer');
Esempio n. 10
0
</link>
<?php 
foreach ($row as $list) {
    ?>
		<item>
			<title><?php 
    echo $list['post_title'];
    ?>
</title>
			<link><?php 
    echo $prefix . OUT_PATH . $list['id'];
    ?>
</link>
			<description>
<?php 
    echo indent_text($list['post_content'], 4);
    ?>
			</description>
			<author><?php 
    echo $list['post_author'];
    ?>
</author>
			<category><?php 
    echo $list['post_board_nicename'];
    ?>
</category>
			<comments><?php 
    echo $prefix . OUT_PATH . $list['id'] . '#comment';
    ?>
</comments>
			<guid><?php 
Esempio n. 11
0
?>
" alt="<?php 
echo $author;
?>
" />
				<span title="IP: <?php 
echo long2ip($ip);
?>
"><?php 
echo $author;
?>
</span>
			</aside>
			<section>
<?php 
echo indent_text(add_link(nl2br($content)), 4);
?>
			</section>
			<footer>
				<time><?php 
echo date('Y-m-d H:i:s', strtotime($datetime . ' UTC'));
?>
</time>
			</footer>
		</article>
	</div>
	<div id="modify">
		<form action="" method="POST">
			<p>
<?php 
if (!$admin) {
Esempio n. 12
0
    ?>
" title ="<?php 
    echo $list['member_nicename'];
    ?>
">
					<span class="member-list-nicename"><?php 
    echo member_link($list['id']);
    ?>
</span>
					<span class="member-list-join_time">Since <?php 
    echo $list['member_registered'];
    ?>
</span>
				</li>
<?php 
}
?>
			</ul>
<?php 
if ($total_items > $items_page) {
    $list_pages = page_list($current_page, $total_pages, 2, OUT_PATH . 'members?', 'page');
    ?>
			<div id="member-list-footer">
				<div id="member-list-pages">
<?php 
    echo indent_text($list_pages, 5);
    ?>
				</div>
			</div>
<?php 
}