Example #1
0
 /**
  *  Installing Magic fields
  * 
  *  This function create all the Magic Fields default values and
  *  his  tables in the database 
  * 
  *  @return void
  */
 function Install()
 {
     include_once 'RCCWP_Options.php';
     global $wpdb;
     // First time installation
     if (get_option(RC_CWP_OPTION_KEY) === false) {
         // Giving full rights to folders. thanks Akis Kesoglou
         wp_mkdir_p(MF_UPLOAD_FILES_DIR);
         wp_mkdir_p(MF_CACHE_DIR);
         wp_mkdir_p(MF_GET_CACHE_DIR);
         //Initialize options
         $options['condense-menu'] = 0;
         $options['hide-non-standart-content'] = 1;
         $options['hide-write-post'] = 0;
         $options['hide-write-page'] = 0;
         $options['hide-visual-editor'] = 0;
         $options['prompt-editing-post'] = 0;
         $options['assign-to-role'] = 0;
         $options['default-custom-write-panel'] = "";
         RCCWP_Options::Update($options);
     }
     // Check blog database
     if (get_option("RC_CWP_BLOG_DB_VERSION") == '') {
         update_option("RC_CWP_BLOG_DB_VERSION", 0);
     }
     if (get_option("RC_CWP_BLOG_DB_VERSION") < RC_CWP_DB_VERSION) {
         $BLOG_DBChanged = true;
     } else {
         $BLOG_DBChanged = false;
     }
     // Install blog tables
     if (!$wpdb->get_var("SHOW TABLES LIKE '" . MF_TABLE_POST_META . "'") == MF_TABLE_POST_META || $BLOG_DBChanged) {
         $blog_tables[] = "CREATE TABLE " . MF_TABLE_POST_META . " (\n\t\t\t\tid integer NOT NULL,\n\t\t\t\tgroup_count integer NOT NULL,\n\t\t\t\tfield_count integer NOT NULL,\n\t\t\t\tpost_id integer NOT NULL,\n\t\t\t\tfield_name text NOT NULL,\n\t\t\t\torder_id integer NOT NULL,\n\t\t\t\tPRIMARY KEY (id) ) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci";
         // try to get around
         // these includes like http://trac.mu.wordpress.org/ticket/384
         // and http://www.quirm.net/punbb/viewtopic.php?pid=832#p832
         if (file_exists(ABSPATH . 'wp-includes/pluggable.php')) {
             require_once ABSPATH . 'wp-includes/pluggable.php';
         } else {
             require_once ABSPATH . 'wp-includes/pluggable-functions.php';
         }
         require_once ABSPATH . 'wp-admin/upgrade-functions.php';
         foreach ($blog_tables as $blog_table) {
             dbDelta($blog_table);
         }
     }
     update_option('RC_CWP_BLOG_DB_VERSION', RC_CWP_DB_VERSION);
     // Upgrade Blog
     if ($BLOG_DBChanged) {
         RCCWP_Application::UpgradeBlog();
     }
     if (RCCWP_Application::IsWordpressMu()) {
         if (get_site_option("RC_CWP_DB_VERSION") == '') {
             update_site_option("RC_CWP_DB_VERSION", 0);
         }
         if (get_site_option("RC_CWP_DB_VERSION") < RC_CWP_DB_VERSION) {
             $DBChanged = true;
         } else {
             $DBChanged = false;
         }
     } else {
         if (get_option("RC_CWP_DB_VERSION") == '') {
             update_option("RC_CWP_DB_VERSION", 0);
         }
         if (get_option("RC_CWP_DB_VERSION") < RC_CWP_DB_VERSION) {
             $DBChanged = true;
         } else {
             $DBChanged = false;
         }
     }
     // -- Create Tables if they don't exist or the database changed
     $not_installed = false;
     if (!$wpdb->get_var("SHOW TABLES LIKE '" . MF_TABLE_PANELS . "'") == MF_TABLE_PANELS) {
         $not_installed = true;
     }
     if ($not_installed || $DBChanged) {
         $qst_tables[] = "CREATE TABLE " . MF_TABLE_PANELS . " (\n\t\t\t\tid int(11) NOT NULL auto_increment,\n\t\t\t\tname varchar(255) NOT NULL,\n\t\t\t\tsingle tinyint(1) NOT NULL default 0,\n\t\t\t\tdescription varchar(255),\n\t\t\t\tdisplay_order int(11),\n\t\t\t\tcapability_name varchar(255) NOT NULL,\n\t\t\t\ttype varchar(255) NOT NULL,\n        expanded tinyint NOT NULL DEFAULT 1,\n\t\t\t\tPRIMARY KEY (id) ) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci";
         $qst_tables[] = "CREATE TABLE " . MF_TABLE_GROUP_FIELDS . " (\n\t\t\t\tid int(11) NOT NULL auto_increment,\n\t\t\t\tgroup_id int(11) NOT NULL,\n\t\t\t\tname varchar(255) NOT NULL,\n\t\t\t\tdescription varchar(255),\n\t\t\t\tdisplay_order int(11),\n\t\t\t\tdisplay_name enum('true', 'false') NOT NULL,\n\t\t\t\tdisplay_description enum('true', 'false') NOT NULL,\n\t\t\t\ttype tinyint NOT NULL,\n\t\t\t\tCSS varchar(100),\n\t\t\t\trequired_field tinyint,\n\t\t\t\tduplicate tinyint(1) NOT NULL,\n\t\t\t\thelp_text text,\n\t\t\t\tPRIMARY KEY (id) ) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci";
         $qst_tables[] = "CREATE TABLE " . MF_TABLE_CUSTOM_FIELD_OPTIONS . " (\n\t\t\t\tcustom_field_id int(11) NOT NULL,\n\t\t\t\toptions text,\n\t\t\t\tdefault_option text,\n\t\t\t\tPRIMARY KEY (custom_field_id) ) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci";
         $qst_tables[] = "CREATE TABLE " . MF_TABLE_PANEL_CATEGORY . " (\n\t\t\t\tpanel_id int(11) NOT NULL,\n\t\t\t\tcat_id varchar(100) NOT NULL,\n\t\t\t\tPRIMARY KEY (panel_id, cat_id) ) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci";
         $qst_tables[] = "CREATE TABLE " . MF_TABLE_PANEL_STANDARD_FIELD . " (\n\t\t\t\tpanel_id int(11) NOT NULL,\n\t\t\t\tstandard_field_id int(11) NOT NULL,\n\t\t\t\tPRIMARY KEY (panel_id, standard_field_id) ) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci";
         $qst_tables[] = "CREATE TABLE " . MF_TABLE_CUSTOM_FIELD_PROPERTIES . " (\n\t\t\t\tcustom_field_id int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\tproperties TEXT,\n\t\t\t\tPRIMARY KEY (custom_field_id)\n\t\t\t\t) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;";
         $qst_tables[] = "CREATE TABLE " . MF_TABLE_PANEL_GROUPS . " (\n\t\t\t\tid int(11) NOT NULL auto_increment,\n\t\t\t\tpanel_id int(11) NOT NULL,\n\t\t\t\tname varchar(255) NOT NULL,\n\t\t\t\tduplicate tinyint(1) NOT NULL,\n        expanded tinyint,\n\t\t\t\tat_right tinyint(1) NOT NULL,\n\t\t\t\tPRIMARY KEY (id) ) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci";
         // try to get around
         // these includes like http://trac.mu.wordpress.org/ticket/384
         // and http://www.quirm.net/punbb/viewtopic.php?pid=832#p832
         if (file_exists(ABSPATH . 'wp-includes/pluggable.php')) {
             require_once ABSPATH . 'wp-includes/pluggable.php';
         } else {
             require_once ABSPATH . 'wp-includes/pluggable-functions.php';
         }
         require_once ABSPATH . 'wp-admin/upgrade-functions.php';
         foreach ($qst_tables as $qst_table) {
             dbDelta($qst_table);
         }
         if (RCCWP_Application::IsWordpressMu()) {
             update_site_option('RC_CWP_DB_VERSION', RC_CWP_DB_VERSION);
         } else {
             update_option('RC_CWP_DB_VERSION', RC_CWP_DB_VERSION);
         }
     }
     //Import Default modules
     if (RCCWP_Application::IsWordpressMu()) {
         if (get_site_option('MAGIC_FIELDS_fist_time') == '') {
             update_site_option('MAGIC_FIELDS_fist_time', '1');
         }
     } else {
         if (get_option('MAGIC_FIELDS_fist_time') == '') {
             update_option('MAGIC_FIELDS_fist_time', '1');
         }
     }
     //Post types
     if (is_wp30()) {
         require_once MF_PATH . '/MF_PostTypesPage.php';
         MF_PostTypePages::CreatePostTypesTables();
     }
     RCCWP_Application::UpgradeBlog();
 }
function change_number_not_write_panel_manage($where)
{
    global $parent_file;
    if (isset($_SESSION['change_number_not_write_panel_manage'])) {
        return $where;
    }
    $types = array('edit.php', 'edit-pages.php', 'edit.php?post_type=page');
    if (!in_array($parent_file, $types)) {
        return $where;
    }
    if (isset($_GET['custom-write-panel-id'])) {
        return $where;
    }
    if (!RCCWP_Options::Get('hide-non-standart-content')) {
        return $where;
    }
    $type = 'post';
    if (is_wp30()) {
        if ($parent_file == 'edit.php?post_type=page') {
            $type = 'page';
        }
    } else {
        if ($parent_file == 'edit-pages.php') {
            $type = 'page';
        }
    }
    $num_posts_mf = RCCWP_CustomWritePanel::GetCountPostNotWritePanel($type);
    printf("\n    <script type=\"text/javascript\">\n    //<![CDATA[\n      jQuery().ready(function() {\n        change_number_manage_not_write_panel('(%s)','(%s)','(%s)','(%s)','(%s)','(%s)','(%s)');\n      });\n    //]]>\n    </script>", array_sum((array) $num_posts_mf) - $num_posts_mf->trash, $num_posts_mf->publish, $num_posts_mf->pending, $num_posts_mf->draft, $num_posts_mf->private, $num_posts_mf->trash, $num_posts_mf->future);
    $_SESSION['change_number_not_write_panel_manage'] = "1";
    return $where;
}
Example #3
0
 public static function HighlightCustomPanel()
 {
     global $wpdb, $submenu_file, $post;
     if (empty($post)) {
         return true;
     }
     $sql = $wpdb->prepare("SELECT meta_value FROM {$wpdb->postmeta} WHERE post_id = %d and meta_key = %s", array($post->ID, "_mf_write_panel_id"));
     $result = $wpdb->get_results($sql, ARRAY_A);
     $currPage = basename($_SERVER['SCRIPT_NAME']);
     if (is_wp30()) {
         if (count($result) > 0 && $currPage == "edit.php") {
             $id = $result[0]['meta_value'];
             $base = 'edit.php?';
             if (isset($_GET['post_type']) && $_GET['post_type'] == 'page') {
                 $base = 'edit.php?post_type=page&';
             }
             $submenu_file = $base . "filter-posts=1&custom-write-panel-id={$id}";
         } elseif (@$_GET['custom-write-panel-id']) {
             //$id = $result[0]['meta_value'];
             $base = 'post-new.php?';
             if (isset($_GET['post_type']) && $_GET['post_type'] == 'page') {
                 $base = 'post-new.php?post_type=page&';
             }
             $submenu_file = $base . "custom-write-panel-id=" . $_GET['custom-write-panel-id'];
         } elseif (count($result) > 0 && $currPage == "post.php") {
             $id = $result[0]['meta_value'];
             $base = 'edit.php?';
             if ($post->post_type == 'page') {
                 $base = 'edit.php?post_type=page&';
             }
             $submenu_file = $base . "filter-posts=1&custom-write-panel-id={$id}";
         }
     } else {
         if (count($result) > 0 && $currPage == "post.php") {
             $id = $result[0]['meta_value'];
             $submenu_file = "edit.php?filter-posts=1&custom-write-panel-id={$id}";
         } elseif (count($result) > 0 && $currPage == "page.php") {
             $id = $result[0]['meta_value'];
             $submenu_file = "edit-pages.php?filter-posts=1&custom-write-panel-id={$id}";
         }
     }
 }
    public static function MediaPhotoInterface($customField, $inputName, $groupCounter, $fieldCounter)
    {
        global $mf_domain, $post;
        $idField = RCCWP_WritePostPage::changeNameInput($inputName);
        if (!empty($_GET['post'])) {
            $hidValue = RCCWP_CustomField::GetCustomFieldValues(true, $_GET['post'], $customField->name, $groupCounter, $fieldCounter);
        } else {
            $hidValue = '';
        }
        $filepath = $inputName . '_filepath';
        //The Image is required?
        $requiredClass = "";
        if ($customField->required_field) {
            $requiredClass = "field_required";
        }
        $imageThumbID = "img_thumb_" . $idField;
        $value = "<img src='" . MF_URI . "images/noimage.jpg' id='{$imageThumbID}'/>";
        if (!empty($hidValue)) {
            $path = PHPTHUMB . "?src=";
            $info = wp_get_attachment_image_src($hidValue, 'original');
            $path_image_media = $info[0];
            $value = $path . $path_image_media . "&w=150&h=120&zc=1";
            $value = "<img src='{$value}' id='{$imageThumbID}'/>";
        }
        ?>
  		<p 	class="error_msg_txt" id="upload_progress_<?php 
        echo $idField;
        ?>
" style="visibility:hidden;height:0px">
  		</p>	
  		<div id="image_photo" style="width:150px; float: left">
  			<?php 
        echo $value;
        ?>
  		<div id="photo_edit_link_<?php 
        echo $idField;
        ?>
" class="photo_edit_link"> 
  			<?php 
        if ($hidValue) {
            echo "&nbsp;<strong><a href='#remove' class='remove_media' id='remove-{$idField}'>" . __("Remove Image", $mf_domain) . "</a></strong>";
        }
        ?>
  		</div>
  		</div>
  		<div id="image_input" style="padding-left: 170px;">
  	<?php 
        if (empty($requiredClass)) {
            $requiredClass = '';
        }
        ?>
		
  			<div class="mf_custom_field">
  			<input tabindex="3" 
  				id="<?php 
        echo $idField;
        ?>
" 
  				name="<?php 
        echo $inputName;
        ?>
" 
  				type="hidden" 
  				class="<?php 
        echo $requiredClass;
        ?>
"
  				size="46"
  				value="<?php 
        echo $hidValue;
        ?>
"
  				<?php 
        if ($customField->required_field) {
            echo 'validate="required:true"';
        }
        ?>
  				/>
  				<?php 
        $thumb_class = 'thickbox1';
        if (is_wp30()) {
            $thumb_class = 'thickbox';
        }
        ?>

  			<a class="<?php 
        echo $thumb_class;
        ?>
 update_field_media_upload" id="thumb_<?php 
        echo $idField;
        ?>
" href="media-upload.php?post_id=<?php 
        echo $post->ID;
        ?>
&#038;type=image&#038;TB_iframe=1" ><?php 
        _e('Set Image', $mf_domain);
        ?>
</a>
  			</div>
  			<?php 
        if (!is_wp30()) {
            ?>
  			<script>
  			jQuery(document).ready(function(){
        	tb_init('a#thumb_<?php 
            echo $idField;
            ?>
');
        	jQuery('a#thumb_<?php 
            echo $idField;
            ?>
').click( function(){
        	  window.mf_field_id = jQuery(this).attr('id');
        	});
        });
  			</script>
  			<?php 
        }
        ?>
  		</div>

  		<div style="clear: both; height: 1px;"> </div>
  			<?php 
        if ($customField->required_field) {
            ?>
  				<div class="mf_message_error"><label for="<?php 
            echo $inputName;
            ?>
" class="error_magicfields error"><?php 
            _e("This field is required", $mf_domain);
            ?>
</label></div>
  			<?php 
        }
        ?>

  		<?php 
    }