| [21] | 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | Plugin Name: Flutter |
|---|
| 4 | Plugin URI: http://freshoutcreative.com/goodies |
|---|
| 5 | Description: Create page templates with custom file uploads and integrated photo resizing. |
|---|
| 6 | Author: Freshout |
|---|
| 7 | Version: .2.26 |
|---|
| 8 | Author URI: http://freshoutcreative.com |
|---|
| 9 | */ |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | // To generate PHPDoc, use the following command: |
|---|
| 13 | // phpdoc -o HTML:Smarty:default -t ./docs -d . -i purifier_lib/ -po FlutterDatabaseObjects -ti 'Flutter API Documentation' |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | // Globals |
|---|
| 17 | global $wpdb, $canvas, $main_page, $table_prefix, $zones, $parents, $installed, $main_page, $post; |
|---|
| 18 | global $current_user; |
|---|
| 19 | global $wp_filesystem; |
|---|
| 20 | global $FIELD_TYPES; |
|---|
| 21 | |
|---|
| 22 | // Classes |
|---|
| 23 | require_once 'classes/FlutterPanelFields.php'; |
|---|
| 24 | |
|---|
| 25 | // Include Flutter API related files |
|---|
| 26 | require_once 'RCCWP_CustomGroup.php'; |
|---|
| 27 | require_once 'RCCWP_CustomField.php'; |
|---|
| 28 | require_once 'RCCWP_CustomWriteModule.php'; |
|---|
| 29 | require_once 'RCCWP_CustomWritePanel.php'; |
|---|
| 30 | |
|---|
| 31 | // Include files containing Flutter public functions |
|---|
| 32 | require_once 'canvas-core.php'; |
|---|
| 33 | require_once 'get-custom.php'; |
|---|
| 34 | |
|---|
| 35 | // Include other files used in this script |
|---|
| 36 | require_once 'RCCWP_Menu.php'; |
|---|
| 37 | require_once 'RCCWP_CreateCustomFieldPage.php'; |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | global $is_wordpress_mu; |
|---|
| 42 | if(isset($current_blog)) |
|---|
| 43 | $is_wordpress_mu=true; |
|---|
| 44 | else |
|---|
| 45 | $is_wordpress_mu=false; |
|---|
| 46 | |
|---|
| 47 | if (is_admin()) |
|---|
| 48 | { |
|---|
| 49 | |
|---|
| 50 | require_once ('RCCWP_Constant.php'); |
|---|
| 51 | require_once ('RCCWP_Application.php'); |
|---|
| 52 | require_once ('RCCWP_WritePostPage.php'); |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | //add_action('activate_Flutter/RCCWP_Application.php', array('RCCWP_Application', 'Install')); |
|---|
| 56 | //add_action('activate_Flutter.php', array('RCCWP_Application', 'Install')); |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | register_activation_hook(dirname(__FILE__) . '/Main.php', array('RCCWP_Application', 'Install')); |
|---|
| 60 | |
|---|
| 61 | //if($is_wordpress_mu) |
|---|
| 62 | if(isset($current_blog)) |
|---|
| 63 | RCCWP_Application::Install(); |
|---|
| 64 | add_action('admin_menu', array('RCCWP_Application', 'ContinueInstallation')); |
|---|
| 65 | |
|---|
| 66 | if (get_option(RC_CWP_OPTION_KEY) !== false) |
|---|
| 67 | { |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | //register_deactivation_hook(dirname(__FILE__) . '/Main.php', array('RCCWP_Application', 'Uninstall')); |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | require_once ('RCCWP_Processor.php'); |
|---|
| 74 | add_action('init', array('RCCWP_Processor', 'Main')); |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | add_action('admin_menu', array('RCCWP_Menu', 'AttachCustomWritePanelMenuItems')); |
|---|
| 78 | add_action('admin_menu', array('RCCWP_Menu', 'DetachWpWritePanelMenuItems')); |
|---|
| 79 | add_action('admin_menu', array('RCCWP_Menu', 'AttachOptionsMenuItem')); |
|---|
| 80 | |
|---|
| 81 | add_filter('posts_where', array('RCCWP_Menu', 'FilterPostsPagesList')); |
|---|
| 82 | add_action('admin_head', array('RCCWP_Menu', 'HighlightCustomPanel')); |
|---|
| 83 | add_action('admin_head', array('RCCWP_CreateCustomFieldPage', 'AddAjaxDynamicList')); |
|---|
| 84 | |
|---|
| 85 | //add_filter('the_posts', array('RCCWP_Menu', 'FilterPostsPagesList')); |
|---|
| 86 | //add_filter('get_pages', array('RCCWP_Menu', 'FilterPostsPagesList')); |
|---|
| 87 | |
|---|
| 88 | // -- Hook all functions related to saving posts in order to save custom fields values |
|---|
| 89 | require_once ('RCCWP_Post.php'); |
|---|
| 90 | add_action('edit_post', array('RCCWP_Post', 'SaveCustomFields')); |
|---|
| 91 | add_action('save_post', array('RCCWP_Post', 'SaveCustomFields')); |
|---|
| 92 | add_action('publish_post', array('RCCWP_Post', 'SaveCustomFields')); |
|---|
| 93 | add_action('delete_post', array('RCCWP_Post','DeletePostMetaData')) ; |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | add_filter('wp_redirect', array('RCCWP_Processor', 'Redirect')); |
|---|
| 98 | |
|---|
| 99 | add_action('shutdown', array('RCCWP_Processor', 'FlushAllOutputBuffer')); |
|---|
| 100 | |
|---|
| 101 | add_action('admin_notices', array('RCCWP_Application', 'CheckInstallation')); |
|---|
| 102 | add_action('admin_notices', array('RCCWP_WritePostPage', 'FormError')); |
|---|
| 103 | |
|---|
| 104 | } |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | add_action('admin_print_scripts', array('RCCWP_Menu', 'AddThickbox')); |
|---|
| 108 | add_action('admin_menu', array('RCCWP_Menu', 'AttachFlutterMenus')); |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | require_once ('RCCWP_EditnPlace.php'); |
|---|
| 112 | //add_filter('the_title', array('RCCWP_EditnPlace', 'EditnTitle'),10, 2); |
|---|
| 113 | //add_filter('the_content', array('RCCWP_EditnPlace', 'EditnContent'),10, 2); |
|---|
| 114 | add_action('wp_head', array('RCCWP_EditnPlace', 'EditnHeader')); |
|---|
| 115 | |
|---|
| 116 | require_once ('RCCWP_Query.php'); |
|---|
| 117 | add_action('pre_get_posts', array('RCCWP_Query', 'FilterPrepare')); |
|---|
| 118 | add_filter('posts_where', array('RCCWP_Query', 'FilterCustomPostsWhere')); |
|---|
| 119 | add_filter('posts_orderby', array('RCCWP_Query', 'FilterCustomPostsOrderby')); |
|---|
| 120 | add_filter('posts_fields', array('RCCWP_Query', 'FilterCustomPostsFields')); |
|---|
| 121 | add_filter('posts_join_paged', array('RCCWP_Query', 'FilterCustomPostsJoin')); |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | add_action('edit_page_form','cwp_add_pages_identifiers'); |
|---|
| 125 | add_action('edit_form_advanced','cwp_add_type_identifier'); |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | add_action('admin_head', 'canvas_head'); |
|---|
| 132 | add_action('switch_theme', 'canvas_check_theme'); |
|---|
| 133 | |
|---|
| 134 | add_action('admin_head', 'add_ink_js'); |
|---|
| 135 | add_action('wp_head', 'output_ink'); |
|---|
| 136 | add_action('wp_head', 'ink_highlight'); |
|---|
| 137 | |
|---|
| 138 | add_action('template_redirect', 'canvas_interrupt'); |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | // HTML Purifier. |
|---|
| 142 | require_once('RCCWP_HTML_Purifier.php'); |
|---|
| 143 | //remove_action ('init', 'kses_init'); |
|---|
| 144 | //remove_action ('set_current_user', 'kses_init'); |
|---|
| 145 | add_filter('pre_comment_content', array('RCCWP_HTML_Purifier', 'ApplyHTMLPurifier')); |
|---|
| 146 | add_filter('title_save_pre', array('RCCWP_HTML_Purifier', 'ApplyHTMLPurifier')); |
|---|
| 147 | add_filter('content_save_pre', array('RCCWP_HTML_Purifier', 'ApplyHTMLPurifier')); |
|---|
| 148 | add_filter('excerpt_save_pre', array('RCCWP_HTML_Purifier', 'ApplyHTMLPurifier')); |
|---|
| 149 | add_filter('content_filtered_save_pre', array('RCCWP_HTML_Purifier', 'ApplyHTMLPurifier')); |
|---|
| 150 | |
|---|
| 151 | |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | function cwp_add_type_identifier(){ |
|---|
| 155 | |
|---|
| 156 | global $wpdb; |
|---|
| 157 | global $post; |
|---|
| 158 | |
|---|
| 159 | if( isset($_GET['custom-write-panel-id']) && !empty($_GET['custom-write-panel-id'])) |
|---|
| 160 | { |
|---|
| 161 | $getPostID = $wpdb->get_results("SELECT id, type FROM ". RC_CWP_TABLE_PANELS ." WHERE id='".$_GET['custom-write-panel-id']."'"); |
|---|
| 162 | echo "<input type=\"hidden\" id=\"post_type\" name=\"post_type\" value=\"". $getPostID[0]->type ."\" />"; |
|---|
| 163 | |
|---|
| 164 | } |
|---|
| 165 | else{ |
|---|
| 166 | if($post->post_type == 'page') { |
|---|
| 167 | echo "<input type=\"hidden\" id=\"post_type\" name=\"post_type\" value=\"page\" />"; |
|---|
| 168 | } else { |
|---|
| 169 | echo "<input type=\"hidden\" id=\"post_type\" name=\"post_type\" value=\"post\" />"; |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | } |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | function cwp_add_pages_identifiers(){ |
|---|
| 176 | global $post; |
|---|
| 177 | global $wpdb; |
|---|
| 178 | |
|---|
| 179 | $key = wp_create_nonce('rc-custom-write-panel'); |
|---|
| 180 | $id = ""; |
|---|
| 181 | $result = $wpdb->get_results( " SELECT meta_value |
|---|
| 182 | FROM $wpdb->postmeta |
|---|
| 183 | WHERE post_id = '$post->ID' and meta_key = '_rc_cwp_write_panel_id'", ARRAY_A ); |
|---|
| 184 | |
|---|
| 185 | if (count($result) > 0) |
|---|
| 186 | $id = $result[0]['meta_value']; |
|---|
| 187 | echo |
|---|
| 188 | <<<EOF |
|---|
| 189 | <input type="hidden" name="rc-custom-write-panel-verify-key" id="rc-custom-write-panel-verify-key" value="$key" /> |
|---|
| 190 | |
|---|
| 191 | EOF; |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | if ( !function_exists('sys_get_temp_dir')) { |
|---|
| 195 | function sys_get_temp_dir() { |
|---|
| 196 | if (!empty($_ENV['TMP'])) { return realpath($_ENV['TMP']); } |
|---|
| 197 | if (!empty($_ENV['TMPDIR'])) { return realpath( $_ENV['TMPDIR']); } |
|---|
| 198 | if (!empty($_ENV['TEMP'])) { return realpath( $_ENV['TEMP']); } |
|---|
| 199 | $tempfile=tempnam(uniqid(rand(),TRUE),''); |
|---|
| 200 | if (file_exists($tempfile)) { |
|---|
| 201 | unlink($tempfile); |
|---|
| 202 | return realpath(dirname($tempfile)); |
|---|
| 203 | } |
|---|
| 204 | } |
|---|
| 205 | } |
|---|
| 206 | |
|---|
| 207 | if ( !function_exists('chmod_R')) { |
|---|
| 208 | function chmod_R($path, $filemode) { |
|---|
| 209 | if (!is_dir($path)) |
|---|
| 210 | return chmod($path, $filemode); |
|---|
| 211 | |
|---|
| 212 | $dh = opendir($path); |
|---|
| 213 | while ($file = readdir($dh)) { |
|---|
| 214 | if($file != '.' && $file != '..') { |
|---|
| 215 | $fullpath = $path.'/'.$file; |
|---|
| 216 | if(is_link($fullpath)) |
|---|
| 217 | return FALSE; |
|---|
| 218 | elseif(!is_dir($fullpath)) |
|---|
| 219 | if (!chmod($fullpath, $filemode)) |
|---|
| 220 | return FALSE; |
|---|
| 221 | elseif(!chmod_R($fullpath, $filemode)) |
|---|
| 222 | return FALSE; |
|---|
| 223 | } |
|---|
| 224 | } |
|---|
| 225 | |
|---|
| 226 | closedir($dh); |
|---|
| 227 | |
|---|
| 228 | if(chmod($path, $filemode)) |
|---|
| 229 | return TRUE; |
|---|
| 230 | else |
|---|
| 231 | return FALSE; |
|---|
| 232 | } |
|---|
| 233 | } |
|---|
| 234 | |
|---|
| 235 | function advancedRmdir($path) { //mappát töröl akkor is, ha nem Ìres |
|---|
| 236 | $origipath = $path; |
|---|
| 237 | $handler = opendir($path); |
|---|
| 238 | while (true) { |
|---|
| 239 | $item = readdir($handler); |
|---|
| 240 | if ($item == "." or $item == "..") { |
|---|
| 241 | continue; |
|---|
| 242 | } elseif (gettype($item) == "boolean") { |
|---|
| 243 | closedir($handler); |
|---|
| 244 | if (!@rmdir($path)) { |
|---|
| 245 | return false; |
|---|
| 246 | } |
|---|
| 247 | if ($path == $origipath) { |
|---|
| 248 | break; |
|---|
| 249 | } |
|---|
| 250 | $path = substr($path, 0, strrpos($path, "/")); |
|---|
| 251 | $handler = opendir($path); |
|---|
| 252 | } elseif (is_dir($path."/".$item)) { |
|---|
| 253 | closedir($handler); |
|---|
| 254 | $path = $path."/".$item; |
|---|
| 255 | $handler = opendir($path); |
|---|
| 256 | } else { |
|---|
| 257 | unlink($path."/".$item); |
|---|
| 258 | } |
|---|
| 259 | } |
|---|
| 260 | return true; |
|---|
| 261 | } |
|---|
| 262 | |
|---|
| 263 | if ( !function_exists('dircopy')) { |
|---|
| 264 | |
|---|
| 265 | /* Copies a dir to another. Optionally caching the dir/file structure, used to synchronize similar destination dir (web farm). |
|---|
| 266 | * |
|---|
| 267 | * @param $src_dir str Source directory to copy. |
|---|
| 268 | * @param $dst_dir str Destination directory to copy to. |
|---|
| 269 | * @param $verbose bool Show or hide file copied messages |
|---|
| 270 | * @param $use_cached_dir_trees bool Set to true to cache src/dst dir/file structure. Used to sync to web farms |
|---|
| 271 | * (avoids loading the same dir tree in web farms; making sync much faster). |
|---|
| 272 | * @return Number of files copied/updated. |
|---|
| 273 | * @example |
|---|
| 274 | * To copy a dir: |
|---|
| 275 | * dircopy("c:\max\pics", "d:\backups\max\pics"); |
|---|
| 276 | * |
|---|
| 277 | * To sync to web farms (webfarm 2 to 4 must have same dir/file structure (run once with cache off to make sure if necessary)): |
|---|
| 278 | * dircopy("//webfarm1/wwwroot", "//webfarm2/wwwroot", false, true); |
|---|
| 279 | * dircopy("//webfarm1/wwwroot", "//webfarm3/wwwroot", false, true); |
|---|
| 280 | * dircopy("//webfarm1/wwwroot", "//webfarm4/wwwroot", false, true); |
|---|
| 281 | */ |
|---|
| 282 | function dircopy($src_dir, $dst_dir, $verbose = false, $use_cached_dir_trees = false) |
|---|
| 283 | { |
|---|
| 284 | static $cached_src_dir; |
|---|
| 285 | static $src_tree; |
|---|
| 286 | static $dst_tree; |
|---|
| 287 | $num = 0; |
|---|
| 288 | |
|---|
| 289 | if (($slash = substr($src_dir, -1)) == "\\" || $slash == "/") $src_dir = substr($src_dir, 0, strlen($src_dir) - 1); |
|---|
| 290 | if (($slash = substr($dst_dir, -1)) == "\\" || $slash == "/") $dst_dir = substr($dst_dir, 0, strlen($dst_dir) - 1); |
|---|
| 291 | |
|---|
| 292 | if (!$use_cached_dir_trees || !isset($src_tree) || $cached_src_dir != $src_dir) |
|---|
| 293 | { |
|---|
| 294 | $src_tree = get_dir_tree($src_dir); |
|---|
| 295 | $cached_src_dir = $src_dir; |
|---|
| 296 | $src_changed = true; |
|---|
| 297 | } |
|---|
| 298 | if (!$use_cached_dir_trees || !isset($dst_tree) || $src_changed) |
|---|
| 299 | $dst_tree = get_dir_tree($dst_dir); |
|---|
| 300 | if (!is_dir($dst_dir)) mkdir($dst_dir, 0777, true); |
|---|
| 301 | |
|---|
| 302 | foreach ($src_tree as $file => $src_mtime) |
|---|
| 303 | { |
|---|
| 304 | if (!isset($dst_tree[$file]) && $src_mtime === false) // dir |
|---|
| 305 | mkdir("$dst_dir/$file"); |
|---|
| 306 | elseif (!isset($dst_tree[$file]) && $src_mtime || isset($dst_tree[$file]) && $src_mtime > $dst_tree[$file]) // file |
|---|
| 307 | { |
|---|
| 308 | if (copy("$src_dir/$file", "$dst_dir/$file")) |
|---|
| 309 | { |
|---|
| 310 | if($verbose) echo "Copied '$src_dir/$file' to '$dst_dir/$file'<br>\r\n"; |
|---|
| 311 | touch("$dst_dir/$file", $src_mtime); |
|---|
| 312 | $num++; |
|---|
| 313 | } else |
|---|
| 314 | echo "<font color='red'>File '$src_dir/$file' could not be copied!</font><br>\r\n"; |
|---|
| 315 | } |
|---|
| 316 | } |
|---|
| 317 | |
|---|
| 318 | return $num; |
|---|
| 319 | } |
|---|
| 320 | |
|---|
| 321 | /* Creates a directory / file tree of a given root directory |
|---|
| 322 | * |
|---|
| 323 | * @param $dir str Directory or file without ending slash |
|---|
| 324 | * @param $root bool Must be set to true on initial call to create new tree. |
|---|
| 325 | * @return Directory & file in an associative array with file modified time as value. |
|---|
| 326 | */ |
|---|
| 327 | function get_dir_tree($dir, $root = true) |
|---|
| 328 | { |
|---|
| 329 | static $tree; |
|---|
| 330 | static $base_dir_length; |
|---|
| 331 | |
|---|
| 332 | if ($root) |
|---|
| 333 | { |
|---|
| 334 | $tree = array(); |
|---|
| 335 | $base_dir_length = strlen($dir) + 1; |
|---|
| 336 | } |
|---|
| 337 | |
|---|
| 338 | if (is_file($dir)) |
|---|
| 339 | { |
|---|
| 340 | //if (substr($dir, -8) != "/CVS/Tag" && substr($dir, -9) != "/CVS/Root" && substr($dir, -12) != "/CVS/Entries") |
|---|
| 341 | $tree[substr($dir, $base_dir_length)] = filemtime($dir); |
|---|
| 342 | } elseif (is_dir($dir) && $di = dir($dir)) // add after is_dir condition to ignore CVS folders: && substr($dir, -4) != "/CVS" |
|---|
| 343 | { |
|---|
| 344 | if (!$root) $tree[substr($dir, $base_dir_length)] = false; |
|---|
| 345 | while (($file = $di->read()) !== false) |
|---|
| 346 | if ($file != "." && $file != "..") |
|---|
| 347 | get_dir_tree("$dir/$file", false); |
|---|
| 348 | $di->close(); |
|---|
| 349 | } |
|---|
| 350 | |
|---|
| 351 | if ($root) |
|---|
| 352 | return $tree; |
|---|
| 353 | } |
|---|
| 354 | } |
|---|
| 355 | |
|---|
| 356 | ?> |
|---|