' . __('K2 Support Group', 'k2_domain') . '
' .
'' . __('K2 Bug Tracker', 'k2_domain') . '
'
);
}
}
/**
* Displays K2 Options page
*/
function admin() {
include(TEMPLATEPATH . '/app/display/options.php');
}
/**
* Displays content in HEAD tag. Called by action: admin_head
*/
function admin_head() {
?>
query) )
$rolling_query = $wp_query->query;
elseif ( is_string($wp_query->query) )
parse_str($wp_query->query, $rolling_query);
// Get list of page dates
if ( !is_page() and !is_single() )
$page_dates = get_rolling_page_dates($wp_query);
// Get the current page
$rolling_page = intval( get_query_var('paged') );
if ( $rolling_page < 1 )
$rolling_page = 1;
?>
read()) !== false) {
// Check the file is a file, and is a PHP file
if(is_file($dir_path . $file) and (!$ignore or !in_array($file, $ignore)) and preg_match('/\.php$/i', $file)) {
include_once($dir_path . $file);
}
}
// Close the directory
$dir->close();
}
/**
* Helper function to search for files based on given criteria
*
* @param string $path directory to search
* @param array $ext file extensions
* @param integer $depth depth of search
* @param mixed $relative relative to which path
* @return array paths of files found
*/
function files_scan($path, $ext = false, $depth = 1, $relative = true) {
$files = array();
// Scan for all matching files
K2::_files_scan( trailingslashit($path), '', $ext, $depth, $relative, $files);
return $files;
}
/**
* Recursive function for files_scan
*
* @param string $base_path
* @param string $path
* @param string $ext
* @param string $depth
* @param mixed $relative
* @param string $files
* @return array paths of files found
*/
function _files_scan($base_path, $path, $ext, $depth, $relative, &$files) {
if (!empty($ext)) {
if (!is_array($ext)) {
$ext = array($ext);
}
$ext_match = implode('|', $ext);
}
// Open the directory
if(($dir = @dir($base_path . $path)) !== false) {
// Get all the files
while(($file = $dir->read()) !== false) {
// Construct an absolute & relative file path
$file_path = $path . $file;
$file_full_path = $base_path . $file_path;
// If this is a directory, and the depth of scan is greater than 1 then scan it
if(is_dir($file_full_path) and $depth > 1 and !($file == '.' or $file == '..')) {
K2::_files_scan($base_path, $file_path . '/', $ext, $depth - 1, $relative, $files);
// If this is a matching file then add it to the list
} elseif(is_file($file_full_path) and (empty($ext) or preg_match('/\.(' . $ext_match . ')$/i', $file))) {
if ( $relative === true ) {
$files[] = $file_path;
} elseif ( $relative === false ) {
$files[] = $file_full_path;
} else {
$files[] = str_replace($relative, '', $file_full_path);
}
}
}
// Close the directory
$dir->close();
}
}
/**
* Move an existing file to a new path
*
* @param string $source original path
* @param string $dest new path
* @param boolean $overwrite if destination exists, overwrite
* @return string new path to file
*/
function move_file($source, $dest, $overwrite = false) {
return K2::_copy_or_move_file($source, $dest, $overwrite, true);
}
function copy_file($source, $dest, $overwrite = false) {
return K2::_copy_or_move_file($source, $dest, $overwrite, false);
}
function _copy_or_move_file($source, $dest, $overwrite = false, $move = false) {
// check source and destination folder
if ( file_exists($source) and is_dir(dirname($dest)) ) {
// destination is a folder, assume move to there
if ( is_dir($dest) ) {
if ( DIRECTORY_SEPARATOR != substr($dest, -1) )
$dest .= DIRECTORY_SEPARATOR;
$dest = $dest . basename($source);
}
// destination file exists
if ( is_file($dest) ) {
if ($overwrite) {
// Delete existing destination file
@unlink($dest);
} else {
// Find a unique name
$dest = K2::get_unique_path($dest);
}
}
if ($move) {
if ( rename($source, $dest) )
return $dest;
} else {
if ( copy($source, $dest) )
return $dest;
}
}
return false;
}
function get_unique_path($source) {
$source = pathinfo($source);
$path = trailingslashit($source['dirname']);
$filename = $source['filename'];
$ext = $source['extension'];
$number = 0;
while ( file_exists($path . $filename . ++$number . $ext) );
return $path . sanitize_title_with_dashes($filename . $number) . $ext;
}
}
// Actions and Filters
add_action( 'admin_menu', array('K2', 'add_options_menu') );
add_action( 'admin_init', array('K2', 'admin_init') );
add_action( 'wp_print_scripts', array('K2', 'enqueue_scripts') );
add_action( 'wp_footer', array('K2', 'init_scripts') );
add_action( 'template_redirect', array('K2', 'dynamic_content') );
add_filter( 'query_vars', array('K2', 'add_custom_query_vars') );
// Decrease the priority of redirect_canonical
remove_action( 'template_redirect', 'redirect_canonical' );
add_action( 'template_redirect', 'redirect_canonical', 11 );
//add_filter( 'redirect_canonical', array('K2', 'prevent_dynamic_redirect') );