Monday, February 20, 2017

BuddyPress remove default "----" dashs 1st value from drop-down list-boxes


BuddyPress Default Drop-Down ListBox Fix





I found the having a default value as "----" as the 1st value from drop-down list-boxes in BuddyPress 2.8.0 very annoying. If this is a required field, then "----" is not a valid value? 


Red X indicates default value

Download, back-up  and edit this file class-bp-xprofile-field-type-selectbox.php located in 
public_html/wp-content/plugins/buddypress/bp-xprofile/classes


Change the one line in this file to this; 


$html    = ''; // 


Here's the code block and highlighted line is how to change it. Not, next update to BuddyPress will blow this away so back it up.



/**
  * Output the edit field options HTML for this field type.
  *
  * BuddyPress considers a field's "options" to be, for example, the items in a selectbox.
  * These are stored separately in the database, and their templating is handled separately.
  *
  * This templating is separate from {@link BP_XProfile_Field_Type::edit_field_html()} because
  * it's also used in the wp-admin screens when creating new fields, and for backwards compatibility.
  *
  * Must be used inside the {@link bp_profile_fields()} template loop.
  *
  * @since 2.0.0
  *
  * @param array $args Optional. The arguments passed to {@link bp_the_profile_field_options()}.
  */
 public function edit_field_options_html( array $args = array() ) {
  $original_option_values = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $this->field_obj->id, $args['user_id'] ) );

  $options = $this->field_obj->get_children();
  $html    = ''; //     '<option value="">' . /* translators: no option picked in select box */ esc_html__( '----', 'buddypress' ) . '</option>';

  if ( empty( $original_option_values ) && !empty( $_POST['field_' . $this->field_obj->id] ) ) {
   $original_option_values = sanitize_text_field(  $_POST['field_' . $this->field_obj->id] );
  }

  $option_values = ( $original_option_values ) ? (array) $original_option_values : array();
  for ( $k = 0, $count = count( $options ); $k < $count; ++$k ) {
   $selected = '';

   // Check for updated posted values, but errors preventing them from
   // being saved first time.
   foreach( $option_values as $i => $option_value ) {
    if ( isset( $_POST['field_' . $this->field_obj->id] ) && $_POST['field_' . $this->field_obj->id] != $option_value ) {
     if ( ! empty( $_POST['field_' . $this->field_obj->id] ) ) {
      $option_values[$i] = sanitize_text_field( $_POST['field_' . $this->field_obj->id] );
     }
    }
   }

   // Run the allowed option name through the before_save filter, so
   // we'll be sure to get a match.
   $allowed_options = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false );

   // First, check to see whether the user-entered value matches.
   if ( in_array( $allowed_options, $option_values ) ) {
    $selected = ' selected="selected"';
   }

   // Then, if the user has not provided a value, check for defaults.
   if ( ! is_array( $original_option_values ) && empty( $option_values ) && $options[$k]->is_default_option ) {
    $selected = ' selected="selected"';
   }

   /**
    * Filters the HTML output for options in a select input.
    *
    * @since 1.1.0
    *
    * @param string $value    Option tag for current value being rendered.
    * @param object $value    Current option being rendered for.
    * @param int    $id       ID of the field object being rendered.
    * @param string $selected Current selected value.
    * @param string $k        Current index in the foreach loop.
    */
   $html .= apply_filters( 'bp_get_the_profile_field_options_select', '<option' . $selected . ' value="' . esc_attr( stripslashes( $options[$k]->name ) ) . '">' . esc_html( stripslashes( $options[$k]->name ) ) . '</option>', $options[$k], $this->field_obj->id, $selected, $k );
  }

  echo $html;
 }
?>

Tuesday, February 14, 2017

Copy WPF DataGrid selected rows to clipboard using CopyingRowClipboardContent

Searched high-and-low for this code that properly used of a DataGrid event method signature associated with the DataGridRowClipboardEventArgs. Clipboard.SetText can be flaky, not grabbing/setting the clipboard all the time. 

Set "FullRow" at the SelectionUnit mode for dataGrid called myDataGrid

1
<DataGrid x:Name="myDataGrid" SelectionUnit="FullRow"></DataGrid>

We have a method myDataGrid_CopyingRowClipboardContent that gets called for each row in the dataGrid to copy its contents to the clipboard. For example,for a datagrid with 10 rows this is called 10 times.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
public int clipboardcalledcnt { get; set; } //CopyingRowClipboardContent invoked count
private void myDataGrid_CopyingRowClipboardContent(object sender, DataGridRowClipboardEventArgs e)
    {
        PathInfo cellpath = new PathInfo(); //a custom class to hold path info
        string path = string.Empty;
    
    DataGrid dgdataPaths = (DataGrid)sender;
    int rowcnt = dgdataPaths.SelectedItems.Count;

    cellpath = (PathInfo)e.Item;
    
    path = "Row #"+ clipboardcalledcnt +" Len="+ cellpath.Length.ToString() + ", path=" + cellpath.Path;

    e.ClipboardRowContent.Clear();

    if (clipboardcalledcnt == 0) //add header to clipboard paste
        e.ClipboardRowContent.Add(new DataGridClipboardCellContent("", null, "--- Clipboard Paste ---\t\t\n")); // \t cell divider, repeat (number of cells - 1)
    
    clipboardcalledcnt++;
    e.ClipboardRowContent.Add(new DataGridClipboardCellContent(path, null, path));
    
    if (clipboardcalledcnt == rowcnt)
        clipboardcalledcnt = 0;

}

Saturday, February 11, 2017

Consolidate or Merge multiple files in multiple locations into 1 (one) file location

This post will explore consolidate or merging multiple files in multiple locations into 1 (one) directory and consolidating repeat files into 1 file using Richcopy, a free easy-to-use utility from Microsoft.
Basically the Richcopy GUI tool has some advanced functionality found in Robocopy.  Robocopy is short for robust copy, and is a built-in Windows utility that provides robust file copy, such as copying files without permissions.  Read my post for more info.

First you need to get a copy of RichCopy  as described in this article in TechNet Magazine Utility Spotlight RichCopy, by J. Hoffman

RichCopy is in this file
HoffmanUtilitySpotlight2009_04.exe (5,896 KB)  named after J. Hoffman the author. Download and run setup.exe.

Image 1: RichCopy GUI


A bried background on Robocopy

Robocopy enables the more serious file replication tasks that can really simplify your job. The biggest benefit I think you'll find is the ability to create full mirror duplicates of two file structures (including all sub-directories and files, if you choose) without copying any unnecessary files. Only the files that are new or have been updated in the source location will be copied. Robocopy also allows you to preserve all of the associated file information, including date and time stamps, security access control lists (ACLs) and more.

Robocopy is built into Windows 7, 
Windows 8+, Windows 10+, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, Windows Server 2016+ 

In this case, we're discussing the simplest of tasks: copying files. Except copying files is not always that simple. 
  • What if you're copying thousands of files across a slow connection? 
  • What happens if your network hiccups and interrupts the copy? 
  • What if you want to make sure that you preserve particular file attributes, such as a Last Modified date, but not other attributes, like security descriptors? 
  • What if you want to filter the files you're copying from source to destination based on filename or extension?
  • Copy files without permissions and file information
  • Copy files longer than 260 characters 

Consolidate Repeated Files

RichCopy version 4.0 supports specifying multiple source directories. Default behavior is to create directories with same name as source, and make a copy. When this option is selected, RichCopy copy all sources files and directories into specified destination directory without creating directories with same name as source. 











Also, if you have File A in Directory 1 and File A in Directory 2, File A with the latest date will be copied into Destination directory. This behaviour can be altered using Copy always (do not compare source and destination) options, see image 2.

Never have repeat file again, especially when syncing to the cloud.


Consolidate Files Using RichCopy

Step 1 Choose multiple source directories and destination (consolidated) directory. 

NOTE : When this completes, Copy complete only mentions the last path of Source Path. 

Image 1: RichCopy GUI

Step 2 Choose Option button and select "Consolidate multiple sources"

Image 2: RichCopy Options interface






























Step 3 Wait until "Copy Complete" appears in Description as in Image 1. Copy complete only mentions the last path of Source Path. This behaviour can be altered using Copy always (do not compare source and destination) options.

Step 4 Done.

Consolidate Multiple Source Results

Here's proof of the the process when using "Consolidate multiple sources" option; 
Our two source directories are c:\temp and c:\backup, and contain the same files NameLengths.txt and PathLengths.txt

Image 3 : Temp source Directory 













Take note of NameLength.txt time-stamp in Backup directory (Image 4) is newer than temp directory (Image 3 above).


Image 4 : Backup source directory


















The resultant consolidate directory contains only 1 copy of the all the repeated files. Duplicate files are resolved using the most recent time-stamp. This behaviour can be altered using Copy always (do not compare source and destination) options.

NameLength.txt's 
time-stamp in Backup directory (Image 4) is newer than temp directory (Image 3 above) and therefore end-up in the output consolidate_test directory. 

Image 5 : Consolidate directory and files


There you go, a great way to consolidate your mess of duplicate files.  

Path Tool Long Error 

Richcopy will bomb on paths too long errors. It's a problem for many tools. 

I build a specialized tool to solve the path too long issue completely. Path Tool Long Auto Fixer tool is the 1st tool on the market to find all directories and filenames that are too long and auto correct them!

Download free demo at https://pathtoolongautofixer.blogspot.com

Preview




Monday, February 6, 2017

Powershell Tips and Tricks from the inventor of Powershell, Jeffrey Snover

Learn about the amazing new capabilities available in Microsoft PowerShell V5. Jeffrey Snover (PowerShell's Chief Architect) video presentation describes his vision of Powershell and its intended use.
He points out  that Powershell language and IDE is an environment created to learn by exploring, making mistakes and sharing with others. Generally, having a "blast" is his philosphy for learning.

This presentation is full of Easter eggs, and quite revealing of 
Jeffrey Snover's character.


"Jeffrey Snover is a Microsoft Technical Fellow, PowerShell chief architect, and the lead architect for the Enterprise Cloud Group which includes Azure Stack, Windows Server, System Center and Operations Management Suite. Snover is the inventor of Windows PowerShell, an object-based distributed automation engine, scripting language, and command line shell." Wikipedia

Wednesday, February 1, 2017

How to check you privacy footprint with Microsoft

Microsoft has a tool to review your tracked data as part of the Microsoft Account portal. 




On the Privacy tab, you have access to review and control your activity data from 
Microsoft including; 


  1. browsing history
  2. search history
  3. location activity
  4. Cortana
  5. Health activity


To review your account head to - https://account.microsoft.com