working on it ...

Filters

Explore Public Snippets

Sort by

Found 24k snippets matching: word

    public by sherazam modified Jan 13, 2016  228084  0  5  0

    How to Insert Check Boxes or HTML into Word Docs during Mail Merge inside .NET Apps

    How to Insert Check Boxes or HTML into Word Docs during Mail Merge inside .NET Apps
    // Enter here the actual content of the snippet.            
    //[C# Code Sample]
     
    using System;
    using System.IO;
    using System.Reflection;
    using Aspose.Words;
    using Aspose.Words.Fields;
    using Aspose.Words.MailMerging;
    
    namespace MailMergeFormFields
    {
        /// <summary>
        /// This sample shows how to insert check boxes and text input form fields during mail merge into a document.
        /// </summary>
        class Program
        {
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            public static void Main(string[] args)
            {
                Program program = new Program();
                program.Execute();
            }
    
            private void Execute()
            {
                string exeDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + Path.DirectorySeparatorChar;
                string dataDir = new Uri(new Uri(exeDir), @"../../Data/").LocalPath;
    
                // Load the template document.
                Document doc = new Document(dataDir + "Template.doc");
    
                // Setup mail merge event handler to do the custom work.
                doc.MailMerge.FieldMergingCallback = new HandleMergeField();
    
                // This is the data for mail merge.
                String[] fieldNames = new String[] {"RecipientName", "SenderName", "FaxNumber", "PhoneNumber",
                    "Subject", "Body", "Urgent", "ForReview", "PleaseComment"};
                Object[] fieldValues = new Object[] {"Josh", "Jenny", "123456789", "", "Hello",
                    "<b>HTML Body Test message 1</b>", true, false, true};
    
                // Execute the mail merge.
                doc.MailMerge.Execute(fieldNames, fieldValues);
    
                // Save the finished document.
                doc.Save(dataDir + "Template Out.doc");
            }
    
            private class HandleMergeField : IFieldMergingCallback
            {
                /// <summary>
                /// This handler is called for every mail merge field found in the document,
                ///  for every record found in the data source.
                /// </summary>
                void IFieldMergingCallback.FieldMerging(FieldMergingArgs e)
                {
                    if (mBuilder == null)
                        mBuilder = new DocumentBuilder(e.Document);
    
                    // We decided that we want all boolean values to be output as check box form fields.
                    if (e.FieldValue is bool)
                    {
                        // Move the "cursor" to the current merge field.
                        mBuilder.MoveToMergeField(e.FieldName);
    
                        // It is nice to give names to check boxes. Lets generate a name such as MyField21 or so.
                        string checkBoxName = string.Format("{0}{1}", e.FieldName, e.RecordIndex);
    
                        // Insert a check box.
                        mBuilder.InsertCheckBox(checkBoxName, (bool)e.FieldValue, 0);
    
                        // Nothing else to do for this field.
                        return;
                    }
    
                    // We want to insert html during mail merge.
                    if (e.FieldName == "Body")
                    {
                        mBuilder.MoveToMergeField(e.FieldName);
                        mBuilder.InsertHtml((string)e.FieldValue);
                    }
    
                    // Another example, we want the Subject field to come out as text input form field.
                    if (e.FieldName == "Subject")
                    {
                        mBuilder.MoveToMergeField(e.FieldName);
                        string textInputName = string.Format("{0}{1}", e.FieldName, e.RecordIndex);
                        mBuilder.InsertTextInput(textInputName, TextFormFieldType.Regular, "", (string)e.FieldValue, 0);
                    }
                }
    
                void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs args)
                {
                    // Do nothing.
                }
    
                private DocumentBuilder mBuilder;
            }
        }
    }
     
    //[VB.NET Code Sample]
     
    
    Imports Microsoft.VisualBasic
    Imports System
    Imports System.IO
    Imports System.Reflection
    Imports Aspose.Words
    Imports Aspose.Words.Fields
    Imports Aspose.Words.MailMerging
    
    Namespace MailMergeFormFields
        ''' <summary>
        ''' This sample shows how to insert check boxes and text input form fields during mail merge into a document.
        ''' </summary>
        Friend Class Program
            ''' <summary>
            ''' The main entry point for the application.
            ''' </summary>
            Public Shared Sub Main(ByVal args() As String)
                Dim program As New Program()
                program.Execute()
            End Sub
    
            Private Sub Execute()
                Dim exeDir As String = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + Path.DirectorySeparatorChar
                Dim dataDir As String = New Uri(New Uri(exeDir), "../../Data/").LocalPath
    
                ' Load the template document.
                Dim doc As New Document(dataDir & "Template.doc")
    
                ' Setup mail merge event handler to do the custom work.
                doc.MailMerge.FieldMergingCallback = New HandleMergeField()
    
                ' This is the data for mail merge.
                Dim fieldNames() As String = {"RecipientName", "SenderName", "FaxNumber", "PhoneNumber", "Subject", "Body", "Urgent", "ForReview", "PleaseComment"}
                Dim fieldValues() As Object = {"Josh", "Jenny", "123456789", "", "Hello", "<b>HTML Body Test message 1</b>", True, False, True}
    
                ' Execute the mail merge.
                doc.MailMerge.Execute(fieldNames, fieldValues)
    
                ' Save the finished document.
                doc.Save(dataDir & "Template Out.doc")
            End Sub
    
            Private Class HandleMergeField
                Implements IFieldMergingCallback
                ''' <summary>
                ''' This handler is called for every mail merge field found in the document,
                '''  for every record found in the data source.
                ''' </summary>
                Private Sub IFieldMergingCallback_FieldMerging(ByVal e As FieldMergingArgs) Implements IFieldMergingCallback.FieldMerging
                    If mBuilder Is Nothing Then
                        mBuilder = New DocumentBuilder(e.Document)
                    End If
    
                    ' We decided that we want all boolean values to be output as check box form fields.
                    If TypeOf e.FieldValue Is Boolean Then
                        ' Move the "cursor" to the current merge field.
                        mBuilder.MoveToMergeField(e.FieldName)
    
                        ' It is nice to give names to check boxes. Lets generate a name such as MyField21 or so.
                        Dim checkBoxName As String = String.Format("{0}{1}", e.FieldName, e.RecordIndex)
    
                        ' Insert a check box.
                        mBuilder.InsertCheckBox(checkBoxName, CBool(e.FieldValue), 0)
    
                        ' Nothing else to do for this field.
                        Return
                    End If
    
                    ' We want to insert html during mail merge.
                    If e.FieldName = "Body" Then
                        mBuilder.MoveToMergeField(e.FieldName)
                        mBuilder.InsertHtml(DirectCast(e.FieldValue, String))
                    End If
    
                    ' Another example, we want the Subject field to come out as text input form field.
                    If e.FieldName = "Subject" Then
                        mBuilder.MoveToMergeField(e.FieldName)
                        Dim textInputName As String = String.Format("{0}{1}", e.FieldName, e.RecordIndex)
                        mBuilder.InsertTextInput(textInputName, TextFormFieldType.Regular, "", CStr(e.FieldValue), 0)
                    End If
                End Sub
    
                Private Sub ImageFieldMerging(ByVal args As ImageFieldMergingArgs) Implements IFieldMergingCallback.ImageFieldMerging
                    ' Do nothing.
                End Sub
    
                Private mBuilder As DocumentBuilder
            End Class
        End Class
    End Namespace
    
    

    public by skaggej modified Jan 10, 2013  336063  3  6  0

    SharePoint 2010 - Disable the "New" icon for newly added content

    This is another easy and useful one; I find it helpful when I'm recording content and adding it as I'm going. I don't really want the word "New" next to some things and not next to others. The finalized recordings look better if that's never there. Here's the simple PowerShell script that you can run per web application to disable the "New" icon
    $webApp = Get-SPWebApplication http://sharepoint2010
    $webApp.DaysToShowNewIndicator = "0"
    $webApp.Update()

    public by Fabax modified Feb 24, 2013  298822  2  4  0

    Wordpress : replace

    Wordpress : replace: searchreplacedb2.php
    <?php
    /**
     *
     * Safe Search and Replace on Database with Serialized Data v2.0.1
     *
     * This script is to solve the problem of doing database search and replace when
     * developers have only gone and used the non-relational concept of serializing
     * PHP arrays into single database columns.  It will search for all matching
     * data on the database and change it, even if it's within a serialized PHP
     * array.
     *
     * The big problem with serialised arrays is that if you do a normal DB style
     * search and replace the lengths get mucked up.  This search deals with the
     * problem by unserializing and reserializing the entire contents of the
     * database you're working on.  It then carries out a search and replace on the
     * data it finds, and dumps it back to the database.  So far it appears to work
     * very well.  It was coded for our WordPress work where we often have to move
     * large databases across servers, but I designed it to work with any database.
     * Biggest worry for you is that you may not want to do a search and replace on
     * every damn table - well, if you want, simply add some exclusions in the table
     * loop and you'll be fine.  If you don't know how, you possibly shouldn't be
     * using this script anyway.
     *
     * To use, simply configure the settings below and off you go.  I wouldn't
     * expect the script to take more than a few seconds on most machines.
     *
     * BIG WARNING!  Take a backup first, and carefully test the results of this
     * code. If you don't, and you vape your data then you only have yourself to
     * blame. Seriously.  And if you're English is bad and you don't fully
     * understand the instructions then STOP. Right there. Yes. Before you do any
     * damage.
     *
     * USE OF THIS SCRIPT IS ENTIRELY AT YOUR OWN RISK. I/We accept no liability
     * from its use.
     *
     * First Written 2009-05-25 by David Coveney of Interconnect IT Ltd (UK)
     * http://www.davidcoveney.com or http://www.interconnectit.com
     * and released under the WTFPL
     * ie, do what ever you want with the code, and we take no responsibility for it
     * OK? If you don't wish to take responsibility, hire us at Interconnect IT Ltd
     * on +44 (0)151 331 5140 and we will do the work for you, but at a cost,
     * minimum 1hr
     *
     * To view the WTFPL go to http://sam.zoy.org/wtfpl/ (WARNING: it's a little
     * rude, if you're sensitive);
     *
     *
     * Version 2.1.0:
     *              - Changed to version 2.1.0 
     *		* Following change by Sergei Biryukov - merged in and tested by Dave Coveney
     *              - Added Charset Support (tested with UTF-8, not tested on other charsets)
     *		* Following changes implemented by James Whitehead with thanks to all the commenters and feedback given!
     * 		- Removed PHP warnings if you go to step 3+ without DB details.
     * 		- Added options to skip changing the guid column. If there are other
     * 		columns that need excluding you can add them to the $exclude_cols global
     * 		array. May choose to add another option to the table select page to let
     * 		you add to this array from the front end.
     * 		- Minor tweak to label styling.
     * 		- Added comments to each of the functions.
     * 		- Removed a dead param from icit_srdb_replacer
     * Version 2.0.0:
     * 		- returned to using unserialize function to check if string is
     * 		serialized or not
     * 		- marked is_serialized_string function as deprecated
     * 		- changed form order to improve usability and make use on multisites a
     * 		bit less scary
     * 		- changed to version 2, as really should have done when the UI was
     * 		introduced
     * 		- added a recursive array walker to deal with serialized strings being
     * 		stored in serialized strings. Yes, really.
     * 		- changes by James R Whitehead (kudos for recursive walker) and David
     * 		Coveney 2011-08-26
     *  Version 1.0.2:
     *  	- typos corrected, button text tweak - David Coveney / Robert O'Rourke
     *  Version 1.0.1
     *  	- styling and form added by James R Whitehead.
     *
     *  Credits:  moz667 at gmail dot com for his recursive_array_replace posted at
     *            uk.php.net which saved me a little time - a perfect sample for me
     *            and seems to work in all cases.
     *
     */
    
    
    /**
     * Form action attribute.
     *
     * @return null
     */
    function icit_srdb_form_action( ) {
    	global $step;
    	echo basename( __FILE__ ) . '?step=' . intval( $step + 1 );
    }
    
    
    /**
     * Used to check the $_post tables array and remove any that don't exist.
     *
     * @param array $table The list of tables from the $_post var to be checked.
     *
     * @return array	Same array as passed in but with any tables that don'e exist removed.
     */
    function check_table_array( $table = '' ){
    	global $all_tables;
    	return in_array( $table, $all_tables );
    }
    
    
    /**
     * Simply create a submit button with a JS confirm popup if there is need.
     *
     * @param string $text    Button string.
     * @param string $warning Submit warning pop up text.
     *
     * @return null
     */
    function icit_srdb_submit( $text = 'Submit', $warning = '' ){
    	$warning = str_replace( "'", "\'", $warning ); ?>
    	<input type="submit" class="button" value="<?php echo htmlentities( $text, ENT_QUOTES, 'UTF-8' ); ?>" <?php echo ! empty( $warning ) ? 'onclick="if (confirm(\'' . htmlentities( $warning, ENT_QUOTES, 'UTF-8' ) . '\')){return true;}return false;"' : ''; ?>/> <?php
    }
    
    
    /**
     * Simple html esc
     *
     * @param string $string Thing that needs escaping
     * @param bool $echo   Do we echo or return?
     *
     * @return string    Escaped string.
     */
    function esc_html_attr( $string = '', $echo = false ){
    	$output = htmlentities( $string, ENT_QUOTES, 'UTF-8' );
    	if ( $echo )
    		echo $output;
    	else
    		return $output;
    }
    
    
    /**
     * Walk and array replacing one element for another. ( NOT USED ANY MORE )
     *
     * @param string $find    The string we want to replace.
     * @param string $replace What we'll be replacing it with.
     * @param array $data    Used to pass any subordinate arrays back to the
     * function for searching.
     *
     * @return array    The original array with the replacements made.
     */
    function recursive_array_replace( $find, $replace, $data ) {
        if ( is_array( $data ) ) {
            foreach ( $data as $key => $value ) {
                if ( is_array( $value ) ) {
                    recursive_array_replace( $find, $replace, $data[ $key ] );
                } else {
                    // have to check if it's string to ensure no switching to string for booleans/numbers/nulls - don't need any nasty conversions
                    if ( is_string( $value ) )
    					$data[ $key ] = str_replace( $find, $replace, $value );
                }
            }
        } else {
            if ( is_string( $data ) )
    			$data = str_replace( $find, $replace, $data );
        }
    }
    
    
    /**
     * Take a serialised array and unserialise it replacing elements as needed and
     * unserialising any subordinate arrays and performing the replace on those too.
     *
     * @param string $from       String we're looking to replace.
     * @param string $to         What we want it to be replaced with
     * @param array  $data       Used to pass any subordinate arrays back to in.
     * @param bool   $serialised Does the array passed via $data need serialising.
     *
     * @return array	The original array with all elements replaced as needed.
     */
    function recursive_unserialize_replace( $from = '', $to = '', $data = '', $serialised = false ) {
    
    	// some unseriliased data cannot be re-serialised eg. SimpleXMLElements
    	try {
    
    		if ( is_string( $data ) && ( $unserialized = @unserialize( $data ) ) !== false ) {
    			$data = recursive_unserialize_replace( $from, $to, $unserialized, true );
    		}
    
    		elseif ( is_array( $data ) ) {
    			$_tmp = array( );
    			foreach ( $data as $key => $value ) {
    				$_tmp[ $key ] = recursive_unserialize_replace( $from, $to, $value, false );
    			}
    
    			$data = $_tmp;
    			unset( $_tmp );
    		}
    
    		else {
    			if ( is_string( $data ) )
    				$data = str_replace( $from, $to, $data );
    		}
    
    		if ( $serialised )
    			return serialize( $data );
    
    	} catch( Exception $error ) {
    
    	}
    
    	return $data;
    }
    
    
    /**
     * Is the string we're dealing with a serialised string? ( NOT USED ANY MORE )
     *
     * @param string $data The string we want to check
     *
     * @return bool    true if serialised.
     */
    function is_serialized_string( $data ) {
    	// if it isn't a string, it isn't a serialized string
    	if ( !is_string( $data ) )
    		return false;
    	$data = trim( $data );
    	if ( preg_match( '/^s:[0-9]+:.*;$/s', $data ) ) // this should fetch all serialized strings
    		return true;
    	return false;
    }
    
    
    /**
     * The main loop triggered in step 5. Up here to keep it out of the way of the
     * HTML. This walks every table in the db that was selected in step 3 and then
     * walks every row and column replacing all occurences of a string with another.
     * We split large tables into 50,000 row blocks when dealing with them to save
     * on memmory consumption.
     *
     * @param mysql  $connection The db connection object
     * @param string $search     What we want to replace
     * @param string $replace    What we want to replace it with.
     * @param array  $tables     The tables we want to look at.
     *
     * @return array    Collection of information gathered during the run.
     */
    function icit_srdb_replacer( $connection, $search = '', $replace = '', $tables = array( ) ) {
    	global $guid, $exclude_cols;
    
    	$report = array( 'tables' => 0,
    					 'rows' => 0,
    					 'change' => 0,
    					 'updates' => 0,
    					 'start' => microtime( ),
    					 'end' => microtime( ),
    					 'errors' => array( ),
    					 );
    
    	if ( is_array( $tables ) && ! empty( $tables ) ) {
    		foreach( $tables as $table ) {
    			$report[ 'tables' ]++;
    
    			$columns = array( );
    
    			// Get a list of columns in this table
    		    $fields = mysql_query( 'DESCRIBE ' . $table, $connection );
    			while( $column = mysql_fetch_array( $fields ) )
    				$columns[ $column[ 'Field' ] ] = $column[ 'Key' ] == 'PRI' ? true : false;
    
    			// Count the number of rows we have in the table if large we'll split into blocks, This is a mod from Simon Wheatley
    			$row_count = mysql_query( 'SELECT COUNT(*) FROM ' . $table, $connection );
    			$rows_result = mysql_fetch_array( $row_count );
    			$row_count = $rows_result[ 0 ];
    			if ( $row_count == 0 )
    				continue;
    
    			$page_size = 50000;
    			$pages = ceil( $row_count / $page_size );
    
    			for( $page = 0; $page < $pages; $page++ ) {
    
    				$current_row = 0;
    				$start = $page * $page_size;
    				$end = $start + $page_size;
    				// Grab the content of the table
    				$data = mysql_query( sprintf( 'SELECT * FROM %s LIMIT %d, %d', $table, $start, $end ), $connection );
    
    				if ( ! $data )
    					$report[ 'errors' ][] = mysql_error( );
    
    				while ( $row = mysql_fetch_array( $data ) ) {
    
    					$report[ 'rows' ]++; // Increment the row counter
    					$current_row++;
    
    					$update_sql = array( );
    					$where_sql = array( );
    					$upd = false;
    
    					foreach( $columns as $column => $primary_key ) {
    						if ( $guid == 1 && in_array( $column, $exclude_cols ) )
    							continue;
    
    						$edited_data = $data_to_fix = $row[ $column ];
    
    						// Run a search replace on the data that'll respect the serialisation.
    						$edited_data = recursive_unserialize_replace( $search, $replace, $data_to_fix );
    
    						// Something was changed
    						if ( $edited_data != $data_to_fix ) {
    							$report[ 'change' ]++;
    							$update_sql[] = $column . ' = "' . mysql_real_escape_string( $edited_data ) . '"';
    							$upd = true;
    						}
    
    						if ( $primary_key )
    							$where_sql[] = $column . ' = "' . mysql_real_escape_string( $data_to_fix ) . '"';
    					}
    
    					if ( $upd && ! empty( $where_sql ) ) {
    						$sql = 'UPDATE ' . $table . ' SET ' . implode( ', ', $update_sql ) . ' WHERE ' . implode( ' AND ', array_filter( $where_sql ) );
    						$result = mysql_query( $sql, $connection );
    						if ( ! $result )
    							$report[ 'errors' ][] = mysql_error( );
    						else
    							$report[ 'updates' ]++;
    
    					} elseif ( $upd ) {
    						$report[ 'errors' ][] = sprintf( '"%s" has no primary key, manual change needed on row %s.', $table, $current_row );
    					}
    
    				}
    			}
    		}
    
    	}
    	$report[ 'end' ] = microtime( );
    
    	return $report;
    }
    
    
    /**
     * Take an array and turn it into an English formatted list. Like so:
     * array( 'a', 'b', 'c', 'd' ); = a, b, c, or d.
     *
     * @param array $input_arr The source array
     *
     * @return string    English formatted string
     */
    function eng_list( $input_arr = array( ), $sep = ', ', $before = '"', $after = '"' ) {
    	if ( ! is_array( $input_arr ) )
    		return false;
    
    	$_tmp = $input_arr;
    
    	if ( count( $_tmp ) >= 2 ) {
    		$end2 = array_pop( $_tmp );
    		$end1 = array_pop( $_tmp );
    		array_push( $_tmp, $end1 . $after . ' or ' . $before . $end2 );
    	}
    
    	return $before . implode( $before . $sep . $after, $_tmp ) . $after;
    }
    
    
    /**
     * Search through the file name passed for a set of defines used to set up
     * WordPress db access.
     *
     * @param string $filename The file name we need to scan for the defines.
     *
     * @return array    List of db connection details.
     */
    function icit_srdb_define_find( $filename = 'wp-config.php' ) {
    
    	$filename = dirname( __FILE__ ) . '/' . basename( $filename );
    
    	if ( file_exists( $filename ) && is_file( $filename ) && is_readable( $filename ) ) {
    		$file = @fopen( $filename, 'r' );
    		$file_content = fread( $file, filesize( $filename ) );
    		@fclose( $file );
    	}
    
    	preg_match_all( '/define\s*?\(\s*?([\'"])(DB_NAME|DB_USER|DB_PASSWORD|DB_HOST|DB_CHARSET)\1\s*?,\s*?([\'"])([^\3]*?)\3\s*?\)\s*?;/si', $file_content, $defines );
    
    	if ( ( isset( $defines[ 2 ] ) && ! empty( $defines[ 2 ] ) ) && ( isset( $defines[ 4 ] ) && ! empty( $defines[ 4 ] ) ) ) {
    		foreach( $defines[ 2 ] as $key => $define ) {
    
    			switch( $define ) {
    				case 'DB_NAME':
    					$name = $defines[ 4 ][ $key ];
    					break;
    				case 'DB_USER':
    					$user = $defines[ 4 ][ $key ];
    					break;
    				case 'DB_PASSWORD':
    					$pass = $defines[ 4 ][ $key ];
    					break;
    				case 'DB_HOST':
    					$host = $defines[ 4 ][ $key ];
    					break;
    				case 'DB_CHARSET':
    					$char = $defines[ 4 ][ $key ];
    					break;
    			}
    		}
    	}
    
    	return array( $host, $name, $user, $pass, $char );
    }
    
    /*
     Check and clean all vars, change the step we're at depending on the quality of
     the vars.
    */
    $errors = array( );
    $step = isset( $_REQUEST[ 'step' ] ) ? intval( $_REQUEST[ 'step' ] ) : 0; // Set the step to the request, we'll change it as we need to.
    
    // Check that we need to scan wp-config.
    $loadwp = isset( $_POST[ 'loadwp' ] ) ? true : false;
    
    // DB details
    $host = isset( $_POST[ 'host' ] ) ? stripcslashes( $_POST[ 'host' ] ) : 'localhost';	// normally localhost, but not necessarily.
    $data = isset( $_POST[ 'data' ] ) ? stripcslashes( $_POST[ 'data' ] ) : '';	// your database
    $user = isset( $_POST[ 'user' ] ) ? stripcslashes( $_POST[ 'user' ] ) : '';	// your db userid
    $pass = isset( $_POST[ 'pass' ] ) ? stripcslashes( $_POST[ 'pass' ] ) : '';	// your db password
    $char = isset( $_POST[ 'char' ] ) ? stripcslashes( $_POST[ 'char' ] ) : '';	// your db charset
    // Search replace details
    $srch = isset( $_POST[ 'srch' ] ) ? stripcslashes( $_POST[ 'srch' ] ) : '';
    $rplc = isset( $_POST[ 'rplc' ] ) ? stripcslashes( $_POST[ 'rplc' ] ) : '';
    // Tables to scanned
    $tables = isset( $_POST[ 'tables' ] ) && is_array( $_POST[ 'tables' ] ) ? array_map( 'stripcslashes', $_POST[ 'tables' ] ) : array( );
    // Do we want to skip changing the guid column
    $guid = isset( $_POST[ 'guid' ] ) && $_POST[ 'guid' ] == 1 ? 1 : 0;
    $exclude_cols = array( 'guid' ); // Add columns to be excluded from changes to this array. If the GUID checkbox is ticked they'll be skipped.
    
    // If we're at the start we'll check to see if wp is about so we can get the details from the wp-config.
    if ( $step == 0 || $step == 1 )
    	$step = file_exists( dirname( __FILE__ ) . '/wp-config.php' ) ? 1 : 2;
    
    // Scan wp-config for the defines. We can't just include it as it will try and load the whole of wordpress.
    if ( $loadwp && file_exists( dirname( __FILE__ ) . '/wp-config.php' ) )
    	list( $host, $data, $user, $pass, $char ) = icit_srdb_define_find( 'wp-config.php' );
    
    // Check the db connection else go back to step two.
    if ( $step >= 3 ) {
    	$connection = @mysql_connect( $host, $user, $pass );
    	if ( ! $connection ) {
    		$errors[] = mysql_error( );
    		$step = 2;
    	}
    	
    	if ( ! empty( $char ) ) {
    		if ( function_exists( 'mysql_set_charset' ) )
    			mysql_set_charset( $char, $connection );
    		else
    			mysql_query( 'SET NAMES ' . $char, $connection );  // Shouldn't really use this, but there for backwards compatibility	
    	}
    	
    	// Do we have any tables and if so build the all tables array
    	$all_tables = array( );
    	@mysql_select_db( $data, $connection );
    	$all_tables_mysql = @mysql_query( 'SHOW TABLES', $connection );
    
    	if ( ! $all_tables_mysql ) {
    		$errors[] = mysql_error( );
    		$step = 2;
    	} else {
    		while ( $table = mysql_fetch_array( $all_tables_mysql ) ) {
    			$all_tables[] = $table[ 0 ];
    		}
    	}
    }
    
    // Check and clean the tables array
    $tables = array_filter( $tables, 'check_table_array' );
    if ( $step >= 4 && empty( $tables ) ) {
    	$errors[] = 'You didn\'t select any tables.';
    	$step = 3;
    }
    
    // Make sure we're searching for something.
    if ( $step >= 5 ) {
    	if ( empty( $srch ) ) {
    		$errors[] = 'Missing search string.';
    		$step = 4;
    	}
    
    	if ( empty( $rplc ) ) {
    		$errors[] = 'Replace string is blank.';
    		$step = 4;
    	}
    
    	if ( ! ( empty( $rplc ) && empty( $srch ) ) && $rplc == $srch ) {
    		$errors[] = 'Search and replace are the same, please check your values.';
    		$step = 4;
    	}
    }
    
    
    /*
     Send the HTML to the screen.
    */
    @header('Content-Type: text/html; charset=UTF-8');?>
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml" xmlns:dc="http://purl.org/dc/terms/" dir="ltr" lang="en-US">
    <head profile="http://gmpg.org/xfn/11">
    	<title>Search and replace DB.</title>
    	<style type="text/css">
    	body {
    		background-color: #E5E5E5;
    		color: #353231;
    	        font: 14px/18px "Gill Sans MT","Gill Sans",Calibri,sans-serif;
    	}
    
    	p {
    	    line-height: 18px;
    	    margin: 18px 0;
    	    max-width: 520px;
    	}
    
    	p.byline {
    	    margin: 0 0 18px 0;
    	    padding-bottom: 9px;
                border-bottom: 1px dashed #999999;
    	    max-width: 100%;
    	}
    
    	h1,h2,h3 {
    	    font-weight: normal;
    	    line-height: 36px;
    	    font-size: 24px;
    	    margin: 9px 0;
    	    text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.8);
    	}
    
    	h2 {
    	    font-weight: normal;
    	    line-height: 24px;
    	    font-size: 21px;
    	    margin: 9px 0;
    	    text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.8);
    	}
    
    	h3 {
    	    font-weight: normal;
    	    line-height: 18px;
    	    margin: 9px 0;
    	    text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.8);
    	}
    
    	a {
    	    -moz-transition: color 0.2s linear 0s;
    	    color: #DE1301;
    	    text-decoration: none;
    	    font-weight: normal;
    	}
    
    	a:visited {
    	   -moz-transition: color 0.2s linear 0s;
    	    color: #AE1301;
    	}
    
    	a:hover, a:visited:hover {
    	    -moz-transition: color 0.2s linear 0s;
    	    color: #FE1301;
    	    text-decoration: underline;
    }
    
    	#container {
    		display:block;
    		width: 768px;
    		padding: 10px;
    		margin: 0px auto;
    		border:solid 10px 0px 0px 0px #ccc;
    		border-top: 18px solid #DE1301;
    		background-color: #F5F5F5;
    	}
    
    	fieldset {
    		border: 0 none;
    	}
    
    	.error {
    		border: solid 1px #c00;
    		padding: 5px;
    		background-color: #FFEBE8;
    		text-align: center;
    		margin-bottom: 10px;
    	}
    
    	label {
    		display:block;
    		line-height: 18px;
    		cursor: pointer;
    	}
    
    	select.multi,
    	input.text {
    		margin-bottom: 1em;
    		display:block;
    		width: 90%;
    	}
    
    	select.multi {
    		height: 144px;
    	}
    
    
    	input.button {
    	}
    
    	div.help {
    		border-top: 1px dashed #999999;
    		margin-top: 9px;
    	}
    
    	</style>
    </head>
    <body>
    	<div id="container"><?php
    		if ( ! empty( $errors ) && is_array( $errors ) ) {
    			echo '<div class="error">';
    			foreach( $errors as $error )
    				echo '<p>' . $error . '</p>';
    			echo '</div>';
    		}?>
    
    
    	<h1>Safe Search Replace</h1>
    	<p class="byline">by interconnect/<strong>it</strong></p>
    	<?php
    /*
     The bit that does all the work.
    */
    switch ( $step ) {
    	case 1:
    		// Prompt for the loading of WordPress or not.	?>
    		<h2>Load DB connection values from WordPress?</h2>
    		<form action="<?php icit_srdb_form_action( ); ?>" method="post">
    			<fieldset>
    				<p><label for="loadwp"><input type="checkbox" checked="checked" value="1" name="loadwp" id="loadwp" /> Pre-populate the DB values form with the ones used in wp-config?  It is possible to edit them later.</label></p> <?php
    				icit_srdb_submit( 'Submit' ); ?>
    			</fieldset>
    		</form>	<?php
    		break;
    
    
    	case 2:
    		// Ask for db username password. ?>
    		<h2>Database details</h2>
    		<form action="<?php icit_srdb_form_action( ); ?>" method="post">
    			<fieldset>
    				<p>
    					<label for="host">Server Name:</label>
    					<input class="text" type="text" name="host" id="host" value="<?php esc_html_attr( $host, true ) ?>" />
    				</p>
    
    				<p>
    					<label for="data">Database Name:</label>
    					<input class="text" type="text" name="data" id="data" value="<?php esc_html_attr( $data, true ) ?>" />
    				</p>
    
    				<p>
    					<label for="user">Username:</label>
    					<input class="text" type="text" name="user" id="user" value="<?php esc_html_attr( $user, true ) ?>" />
    				</p>
    
    				<p>
    					<label for="pass">Password:</label>
    					<input class="text" type="password" name="pass" id="pass" value="<?php esc_html_attr( $pass, true ) ?>" />
    				</p>
    				
    				<p>
    					<label for="pass">Charset:</label>
    					<input class="text" type="text" name="char" id="char" value="<?php esc_html_attr( $char, true ) ?>" />
    				</p>
    				<?php icit_srdb_submit( 'Submit DB details' ); ?>
    			</fieldset>
    		</form>	<?php
    		break;
    
    
    	case 3:
    		// Ask which tables to deal with ?>
    		<h2>Which tables do you want to scan?</h2>
    		<form action="<?php icit_srdb_form_action( ); ?>" method="post">
    
    			<fieldset>
    
    				<input type="hidden" name="host" value="<?php esc_html_attr( $host, true ) ?>" />
    				<input type="hidden" name="data" value="<?php esc_html_attr( $data, true ) ?>" />
    				<input type="hidden" name="user" value="<?php esc_html_attr( $user, true ) ?>" />
    				<input type="hidden" name="pass" value="<?php esc_html_attr( $pass, true ) ?>" />
    				<input type="hidden" name="char" value="<?php esc_html_attr( $char, true ) ?>" />
    				<p>
    					<label for="tables">Tables:</label>
    					<select id="tables" name="tables[]" multiple="multiple" class="multi"><?php
    					foreach( $all_tables as $table ) {
    						echo '<option selected="selected" value="' . esc_html_attr( $table ) . '">' . $table . '</option>';
    					} ?>
    					</select>
    					<em>Multiple tables can be selected with ( CTRL/CMD + click ).</em>
    				</p>
    
    				<p>
    					<label for="guid">
    					<input type="checkbox" name="guid" id="guid" value="1" <?php echo $guid == 1 ? 'checked="checked"' : '' ?>/> Leave GUID column unchanged? </label>
    					<em>If the values in the GUID column from the WordPress posts table change RSS readers and other tools will be under the impression that the posts are new and may show them in feeds again. <br />
    					All columns titled <?php echo eng_list( $exclude_cols ) ?> will be skipped if this it ticked.</em>
    				</p>
    
    				<?php icit_srdb_submit( 'Continue', 'Do be sure that you have selected the correct tables - especially important on multi-sites installs.' );	?>
    			</fieldset>
    		</form>	<?php
    		break;
    
    
    	case 4:
    		// Ask for the search replace strings. ?>
    		<h2>What to replace?</h2>
    		<form action="<?php icit_srdb_form_action( ); ?>" method="post">
    			<fieldset>
    				<input type="hidden" name="host" id="host" value="<?php esc_html_attr( $host, true ) ?>" />
    				<input type="hidden" name="data" id="data" value="<?php esc_html_attr( $data, true ) ?>" />
    				<input type="hidden" name="user" id="user" value="<?php esc_html_attr( $user, true ) ?>" />
    				<input type="hidden" name="pass" id="pass" value="<?php esc_html_attr( $pass, true ) ?>" />
    				<input type="hidden" name="char" id="char" value="<?php esc_html_attr( $char, true ) ?>" />
    				<input type="hidden" name="guid" id="guid" value="<?php esc_html_attr( $guid, true ) ?>" /> <?php
    
    				foreach( $tables as $i => $tab ) {
    					printf( '<input type="hidden" name="tables[%s]" value="%s" />', esc_html_attr( $i, false ), esc_html_attr( $tab, false ) );
    				} ?>
    
    				<p>
    					<label for="srch">Search for (case sensitive string):</label>
    					<input class="text" type="text" name="srch" id="srch" value="<?php esc_html_attr( $srch, true ) ?>" />
    				</p>
    
    				<p>
    					<label for="rplc">Replace with:</label>
    					<input class="text" type="text" name="rplc" id="rplc" value="<?php esc_html_attr( $rplc, true ) ?>" />
    				</p>
    
    				<?php icit_srdb_submit( 'Submit Search string', 'Are you REALLY sure you want to go ahead and do this?' ); ?>
    			</fieldset>
    		</form>	<?php
    		break;
    
    
    	case 5:
    
    		@ set_time_limit( 60 * 10 );
    		// Try to push the allowed memory up, while we're at it
    		@ ini_set( 'memory_limit', '1024M' );
    
    		// Process the tables
    		if ( isset( $connection ) )
    			$report = icit_srdb_replacer( $connection, $srch, $rplc, $tables );
    
    		// Output any errors encountered during the db work.
    		if ( ! empty( $report[ 'errors' ] ) && is_array( $report[ 'errors' ] ) ) {
    			echo '<div class="error">';
    			foreach( $report[ 'errors' ] as $error )
    				echo '<p>' . $error . '</p>';
    			echo '</div>';
    		}
    
    		// Calc the time taken.
    		$time = array_sum( explode( ' ', $report[ 'end' ] ) ) - array_sum( explode( ' ', $report[ 'start' ] ) ); ?>
    
    		<h2>Completed</h2>
    		<p><?php printf( 'In the process of replacing <strong>"%s"</strong> with <strong>"%s"</strong> we scanned <strong>%d</strong> tables with a total of <strong>%d</strong> rows, <strong>%d</strong> cells were changed and <strong>%d</strong> db update performed and it all took <strong>%f</strong> seconds.', $srch, $rplc, $report[ 'tables' ], $report[ 'rows' ], $report[ 'change' ], $report[ 'updates' ], $time ); ?></p> <?php
    		break;
    
    
    	default: ?>
    		<h2>No idea how we got here.</h2>
    		<p>Something strange has happened.</p> <?php
    		break;
    }
    
    if ( isset( $connection ) && $connection )
    	mysql_close( $connection );
    
    
    // Warn if we're running in safe mode as we'll probably time out.
    if ( ini_get( 'safe_mode' ) ) {
    	echo '<h4>Warning</h4>';
    	printf( '<p style="color:red;">Safe mode is on so you may run into problems if it takes longer than %s seconds to process your request.</p>', ini_get( 'max_execution_time' ) );
    }
    /*
     Close out the html and exit.
    */ ?>
    		<div class="help">
    			<h4><a href="http://interconnectit.com/">interconnect/it</a> <a href="http://interconnectit.com/124/search-and-replace-for-wordpress-databases/">Safe Search and Replace on Database with Serialized Data v2.0.0</a></h4>
    			<p>This developer/sysadmin tool helps solve the problem of doing a search and replace on a
    			WordPress site when doing a migration to a domain name with a different length.</p>
    
    			<p><style="color:red">WARNING!</strong> Take a backup first, and carefully test the results of this code.
    			If you don't, and you vape your data then you only have yourself to blame.
    			Seriously.  And if you're English is bad and you don't fully understand the
    			instructions then STOP.  Right there.  Yes.  Before you do any damage.
    
    			<h2>Don't Forget to Remove Me!</h3>
    
    			<p style="color:red">Delete this utility from your
    			server after use.  It represents a major security threat to your database if
    			maliciously used.</p>
    
    			<h2>Use Of This Script Is Entirely At Your Own Risk</h2>
    
    			<p> We accept no liability from the use of this tool.</p>
    
    			<p>If you're not comfortable with this kind of stuff, get an expert, like us, to do
    			this work for you.  You do this ENTIRELY AT YOUR OWN RISK!  We accept no responsibility
    			if you mess up your data.  There is NO UNDO here!</p>
    
    			<p>The easiest way to use it is to copy your site's files and DB to the new location.
    			You then, if required, fix up your .htaccess and wp-config.php appropriately.  Once
    			done, run this script, select your tables (in most cases all of them) and then
    			enter the search replace strings.  You can press back in your browser to do
    			this several times, as may be required in some cases.</p>
    
    			<p>Of course, you can use the script in many other ways - for example, finding
    			all references to a company name and changing it when a rebrand comes along.  Or
    			perhaps you changed your name.  Whatever you want to search and replace the code will help.</p>
    
    			<p><a href="http://interconnectit.com/124/search-and-replace-for-wordpress-databases/">Got feedback on this script? Come tell us!</a>
    
    		</div>
    	</div>
    </body>
    </html>
    
    
    

    public by cghersi modified Nov 4, 2014  246615  1  6  1

    Calculate the occurrences of words in Rss feed

    Creates a dictionary with keys=words and values=occurrences of that word in the given Rss (specified by the URL). The caller should specify the maximum number of items in the returning dictionary and, optionally, the minimum length of the words that will be added to the output.
    public static Dictionary<string, int> ComputeWordsOccurrencesInRss(string url, int maxItems, int minLenOfAcceptedWords = 1)
    {
      Dictionary<string, int> occurrences = new Dictionary<string, int>();
    
      IList<RssReader.RssItem> singleRssResult = RssReader.ReadRss(url, maxItems, true);
      string[] splitted = null;
      foreach (RssReader.RssItem rss in singleRssResult)
      {
        List<string> words = new List<string>();
    
        //split title in words:
        splitted = StringHelper.SplitIntoWords(rss.Title);
        if (splitted != null)
          words.AddRange(splitted);
    
        //split summary in words:
        splitted = StringHelper.SplitIntoWords(rss.Summary);
        if (splitted != null)
          words.AddRange(splitted);
    
        //compute occurrences of words:
        for (int w = 0; w < words.Count; w++)
        {
          string word = words[w].ToLower();
          if (word.Length < minLenOfAcceptedWords)
            continue;
          if (occurrences.ContainsKey(word))
            occurrences[word]++;
          else
            occurrences.Add(word, 1);
        }
      }
    
      return occurrences;
    }
    

    public by elenka modified Jan 22, 2015  237284  3  7  0

    add WooCommerce settins tab

    <?php
    
    if ( !class_exists('Woo_Settings ') ):
    
    /**
     * 
     * @version 1.0
     * @access public
     */
    class Woo_Settings {
    
      public static function init() {
        add_filter( 'woocommerce_settings_tabs_array', __CLASS__ . '::add_settings_tab', 70);
        add_action( 'woocommerce_settings_tabs_settings_orders_page', __CLASS__ . '::settings_tab' );
      }
    
      /**
      * Add a new settings tab to the WooCommerce settings tabs array.
      */
      public static function add_settings_tab( $settings_tabs ) {
        $settings_tabs['settings_orders_page'] = __( 'Orders Page', 'linen' );
        return $settings_tabs;
      }
      /**
      * Uses the WooCommerce admin fields API to output settings via the @see woocommerce_admin_fields() function.
      *
      * @uses woocommerce_admin_fields()
      * @uses self::get_settings()
      */
      public static function settings_tab() {
        woocommerce_admin_fields( self::get_settings() );
      }
    
      /**
      * Get all the settings for this plugin for @see woocommerce_admin_fields() function.
      *
      * @return array Array of settings for @see woocommerce_admin_fields() function.
      */
      public static function get_settings() {
    
        $settings[] = array( 'title' => __( 'Orders Page', 'linen' ), 'type' => 'title', 'desc' => '', 'id' => 'wc_order_customiser_orders_page' );
        $settings[] = array(
          'title'    => __( 'Table Type', 'linen' ),
          'id'       => 'wc_order_customiser_table_type',
          'default'  => 'static',
          'type'     => 'radio',
          'options'  => array(
            'static'  => __( 'Static', 'linen' ),
            'dynamic' => __( 'Dynamic', 'linen' ),
          ),
          'autoload' => true
        );
        $settings[] = array( 'type' => 'sectionend', 'id' => 'wc_order_customiser_orders_page' );
    
        $settings[] = array( 'title' => __( 'Position & Size', 'linen' ), 'type' => 'title', 'desc' => '', 'id' => 'wc_order_customiser_position_n_size' );
        $settings[] = array(
          'title'    => __( 'Table Type', 'linen' ),
          'id'       => 'wc_order_customiser_table_type',
          'default'  => 'static',
          'type'     => 'radio',
          'options'  => array(
            'static'  => __( 'Static', 'linen' ),
            'dynamic' => __( 'Dynamic', 'linen' ),
          ),
          'autoload' => true
        );
        $settings[] = array( 'type' => 'sectionend', 'id' => 'wc_order_customiser_position_n_size' );
    
        return apply_filters( 'wc_settings_tab_orders_page', $settings );
      }
    
      /**
      * Uses the WooCommerce options API to save settings via the @see woocommerce_update_options() function.
      *
      * @uses woocommerce_update_options()
      * @uses self::get_settings()
      */
      public static function update_settings() {
        woocommerce_update_options( self::get_settings() );
      }
    
    	
    }
    Woo_Settings::init();
    endif;
    ?>                        

    public by strykerraven modified Sep 22, 2016  187947  3  5  1

    WordPress safely defining and executing functions

    Handy safe way to include functions in your WordPress Themes functions.php file. This is even more useful if you are using a child theme and don't want to conflict with functions already defined by the parent theme. Even better; These functions can be executed within the same if(function_exists()) block that defines them creating a neater to manage
    <?php
    
    // Lets get rid of the versioning on static .js and .css files.
    // It looks tacky anyway for static files.
    
    	/**
    	 * Strips Version query strings
    	 * @param type $src
    	 * @return type
    	 */
    	if(!function_exists('remove_css_js_versions')){ // if the function doesnt exist then...
    		function remove_css_js_versions($src){ // define the function
    			return remove_query_arg('ver', $src); // call built-in wordpress function to remove query named "ver" from whatever is passed as $src
    		}
    		add_filter('script_loader_src', 'remove_css_js_versions'); // Pass a hook as $src for js to function listed above named "remove_css_js_versions"
    		add_filter('style_loader_src', 'remove_css_js_versions'); // Pass a hook as $src for css to function listed above named "remove_css_js_versions"
    	} // All scripts and styles will be filtered to have ?ver=1.2.3 stripped from urls. Function defined and executed in same if() statement.
    
      /**
      * Need to debug? Instead of just using print_r($array) you just do preprint_r($array)
      * the array will be output neatly instead of wrapped and messy.
      */
    	if(!function_exists('preprint_r')){
    		function preprint_r($val){
    			echo '<pre>' . PHP_EOL;
    			print_r($val) . PHP_EOL;
    			echo '</pre>' . PHP_EOL;
    		}
    	}
    	
    	/** Remove the WP Icon (Menu) from profile and admin pages. */
    		if(!function_exists('remove_wp_logo')){
      		function remove_wp_logo($wp_admin_bar){
      			$wp_admin_bar->remove_node('wp-logo');
      		}
      		add_action('admin_bar_menu', 'remove_wp_logo', 33);
      	}
      	
    /**
    	 * Wordpress Login Page fixes. By default WordPress shows its logo on your login pages and links to its own site.
    	 * A visitor logging into your site don't need this potential roadblock so lets show WordPress that we mean business!
    	 */
    	# Fix Login Page WordPress URL
    	if(!function_exists('fix_wp_login_img_url')){
    		function fix_wp_login_img_url($url){
    			return get_bloginfo('url');
    		}
    		add_filter('login_headerurl', 'fix_wp_login_img_url');
    	}
    
    	# Fix Login Page WordPress Title (Text displayed on hover defaults to Powered By WordPress)
    	if(!function_exists('fix_wp_login_img_title')){
    		function fix_wp_login_img_title($title){
    			return get_bloginfo('description');
    		}
    		add_filter('login_headertitle', 'fix_wp_login_img_title');
    	}
    
    	/**
    		Change Login Page WordPress Logo, You will need to update path and point to a valid image.
    		WordPress adds this with a CSS background image for your anchor link. It first applys a PNG and then a SVG override if your browser is modern and supports svg
    		In your themes custom stylesheet you can change default Wordpress image by supplying a new background image:
    
    		.login h1 a {
    			background-image: none,url(images/your_image.png);
    		}
    
    		Hint: WordPress uses an 64x64 image but you can adapt size to your need. You might want to use SVG like WordPress did because it will scale best at any resolution.
    
    	 */
    
    	/**
    	 * Simple Actions that use wp_head hook to cleanup WP header Junk/Bloat
    	 * that is included with WordPress by default.
    	 */
    	remove_action('wp_head', 'wp_generator');
    	remove_action('wp_head', 'rsd_link');
    	remove_action('wp_head', 'wlwmanifest_link');
    	remove_action('wp_head', 'wp_shortlink_wp_head');            
    	
    	
    	?>

    public by cghersi modified Dec 19, 2012  140240  0  6  0

    Courier font for code words in Wiki

    this is how to enlight a word to be displayed in Courier as a sfotware code word
    <code enclose="none">MyClass</code>

    public by lbottaro modified Aug 18, 2014  21403  129  9  3

    How to programmatically create a Microsoft Word document in csharp

    This code shows how to simply create a doc using csharp and Microsoft Office Word library. 1) You need to add a reference to Microsoft.Office.Interop library in your project solution. 2) Add the following line to the end of the list of using directives: using Word = Microsoft.Office.Interop.Word; using System.Reflection; 3) Now you are
    private void button1_Click(object sender, EventArgs e)
            {
              object oMissing = System.Reflection.Missing.Value;
               object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
    
               //Start Word and create a new document.
               Word._Application oWord;
               Word._Document oDoc;
               oWord = new Word.Application();
               oWord.Visible = true;
               oDoc = oWord.Documents.Add(ref oMissing, ref oMissing,
                   ref oMissing, ref oMissing);
    
               //Insert a paragraph at the beginning of the document.
               Word.Paragraph oPara1;
               oPara1 = oDoc.Content.Paragraphs.Add(ref oMissing);
               oPara1.Range.Text = "Heading 1";
               oPara1.Range.Font.Bold = 1;
               oPara1.Format.SpaceAfter = 24;    //24 pt spacing after paragraph.
               oPara1.Range.InsertParagraphAfter();
    
               //Insert a paragraph at the end of the document.
               Word.Paragraph oPara2;
               object oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
               oPara2 = oDoc.Content.Paragraphs.Add(ref oRng);
               oPara2.Range.Text = "Heading 2";
               oPara2.Format.SpaceAfter = 6;
               oPara2.Range.InsertParagraphAfter();
    
               //Insert another paragraph.
               Word.Paragraph oPara3;
               oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
               oPara3 = oDoc.Content.Paragraphs.Add(ref oRng);
               oPara3.Range.Text = "This is a sentence of normal text. Now here is a table:";
               oPara3.Range.Font.Bold = 0;
               oPara3.Format.SpaceAfter = 24;
               oPara3.Range.InsertParagraphAfter();
    
               //Insert a 3 x 5 table, fill it with data, and make the first row
               //bold and italic.
               Word.Table oTable;
               Word.Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
               oTable = oDoc.Tables.Add(wrdRng, 3, 5, ref oMissing, ref oMissing);
               oTable.Range.ParagraphFormat.SpaceAfter = 6;
               int r, c;
               string strText;
               for (r = 1; r <= 3; r++)
                   for (c = 1; c <= 5; c++)
                   {
                       strText = "r" + r + "c" + c;
                       oTable.Cell(r, c).Range.Text = strText;
                   }
               oTable.Rows[1].Range.Font.Bold = 1;
               oTable.Rows[1].Range.Font.Italic = 1;
    
               //Add some text after the table.
               Word.Paragraph oPara4;
               oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
               oPara4 = oDoc.Content.Paragraphs.Add(ref oRng);
               oPara4.Range.InsertParagraphBefore();
               oPara4.Range.Text = "And here's another table:";
               oPara4.Format.SpaceAfter = 24;
               oPara4.Range.InsertParagraphAfter();
    
               //Insert a 5 x 2 table, fill it with data, and change the column widths.
               wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
               oTable = oDoc.Tables.Add(wrdRng, 5, 2, ref oMissing, ref oMissing);
               oTable.Range.ParagraphFormat.SpaceAfter = 6;
               for (r = 1; r <= 5; r++)
                   for (c = 1; c <= 2; c++)
                   {
                       strText = "r" + r + "c" + c;
                       oTable.Cell(r, c).Range.Text = strText;
                   }
               oTable.Columns[1].Width = oWord.InchesToPoints(2); //Change width of columns 1 & 2
               oTable.Columns[2].Width = oWord.InchesToPoints(3);
    
               //Keep inserting text. When you get to 7 inches from top of the
               //document, insert a hard page break.
               object oPos;
               double dPos = oWord.InchesToPoints(7);
               oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range.InsertParagraphAfter();
               do
               {
                   wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                   wrdRng.ParagraphFormat.SpaceAfter = 6;
                   wrdRng.InsertAfter("A line of text");
                   wrdRng.InsertParagraphAfter();
                   oPos = wrdRng.get_Information
                                  (Word.WdInformation.wdVerticalPositionRelativeToPage);
               }
               while (dPos >= Convert.ToDouble(oPos));
               object oCollapseEnd = Word.WdCollapseDirection.wdCollapseEnd;
               object oPageBreak = Word.WdBreakType.wdPageBreak;
               wrdRng.Collapse(ref oCollapseEnd);
               wrdRng.InsertBreak(ref oPageBreak);
               wrdRng.Collapse(ref oCollapseEnd);
               wrdRng.InsertAfter("We're now on page 2. Here's my chart:");
               wrdRng.InsertParagraphAfter();
    
               //Insert a chart.
               Word.InlineShape oShape;
               object oClassType = "MSGraph.Chart.8";
               wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
               oShape = wrdRng.InlineShapes.AddOLEObject(ref oClassType, ref oMissing,
                   ref oMissing, ref oMissing, ref oMissing,
                   ref oMissing, ref oMissing, ref oMissing);
    
               //Demonstrate use of late bound oChart and oChartApp objects to
               //manipulate the chart object with MSGraph.
               object oChart;
               object oChartApp;
               oChart = oShape.OLEFormat.Object;
               oChartApp = oChart.GetType().InvokeMember("Application",
                   BindingFlags.GetProperty, null, oChart, null);
    
               //Change the chart type to Line.
               object[] Parameters = new Object[1];
               Parameters[0] = 4; //xlLine = 4
               oChart.GetType().InvokeMember("ChartType", BindingFlags.SetProperty,
                   null, oChart, Parameters);
    
               //Update the chart image and quit MSGraph.
               oChartApp.GetType().InvokeMember("Update",
                   BindingFlags.InvokeMethod, null, oChartApp, null);
               oChartApp.GetType().InvokeMember("Quit",
                   BindingFlags.InvokeMethod, null, oChartApp, null);
               //... If desired, you can proceed from here using the Microsoft Graph 
               //Object model on the oChart and oChartApp objects to make additional
               //changes to the chart.
    
               //Set the width of the chart.
               oShape.Width = oWord.InchesToPoints(6.25f);
               oShape.Height = oWord.InchesToPoints(3.57f);
    
               //Add text after the chart.
               wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
               wrdRng.InsertParagraphAfter();
               wrdRng.InsertAfter("THE END.");
    
               //Close this form.
               this.Close();
    }
    

    public by sherazam modified Mar 16, 2016  2686  0  5  0

    How to Insert Clone of an Existing Table in a Word Document inside .NET Apps

    // Enter here the actual content of the snippet.  
    
    //Code samples Shows how to insert a table using the constructors of nodes
    
    //[C# Code Sample]
     
    
    // For complete examples and data files, please go to https://github.com/asposewords/Aspose_Words_NET
    
    Document doc = new Document(dataDir + "Table.SimpleTable.doc");
    
    // Retrieve the first table in the document.
    
    Table table = (Table)doc.GetChild(NodeType.Table, 0, true);
    
    // Create a clone of the table.
    
    Table tableClone = (Table)table.Clone(true);
    
    // Insert the cloned table into the document after the original
    
    table.ParentNode.InsertAfter(tableClone, table);
    
    // Insert an empty paragraph between the two tables or else they will be combined into one
    
    // upon save. This has to do with document validation.
    
    table.ParentNode.InsertAfter(new Paragraph(doc), table);
    
    dataDir = dataDir + "Table.CloneTableAndInsert_out_.doc";
    
    // Save the document to disk.
    
    doc.Save(dataDir);
    
    
    // [Visual Basic Code Sample]
     
    
    
    ' For complete examples and data files, please go to https://github.com/asposewords/Aspose_Words_NET
    
    
    Dim doc As New Document(dataDir & Convert.ToString("Table.SimpleTable.doc"))
    
    
    ' Retrieve the first table in the document.
    
    
    Dim table As Table = DirectCast(doc.GetChild(NodeType.Table, 0, True), Table)
    
    ' Create a clone of the table.
    
    
    Dim tableClone As Table = DirectCast(table.Clone(True), Table)
    
    
    ' Insert the cloned table into the document after the original
    
    
    table.ParentNode.InsertAfter(tableClone, table)
    
    
    ' Insert an empty paragraph between the two tables or else they will be combined into one
    
    
    ' upon save. This has to do with document validation.
    
    
    table.ParentNode.InsertAfter(New Paragraph(doc), table)
    
    
    dataDir = dataDir & Convert.ToString("Table.CloneTableAndInsert_out_.doc")
    
    ' Save the document to disk.
    
    doc.Save(dataDir)
    
    // Code sample Shows how to make a clone of the last row of a table and append it to the table.
    
    //[C# Code Sample]
     
    // For complete examples and data files, please go to https://github.com/asposewords/Aspose_Words_NET
    
    Document doc = new Document(dataDir + "Table.SimpleTable.doc");
    
    // Retrieve the first table in the document.
    
    Table table = (Table)doc.GetChild(NodeType.Table, 0, true);
    
    // Clone the last row in the table.
    
    Row clonedRow = (Row)table.LastRow.Clone(true);
    
    // Remove all content from the cloned row's cells. This makes the row ready for
    
    // new content to be inserted into.
    
    foreach (Cell cell in clonedRow.Cells)
    
    cell.RemoveAllChildren();
    
    // Add the row to the end of the table.
    
    table.AppendChild(clonedRow);
    
    dataDir = dataDir + "Table.AddCloneRowToTable_out_.doc";
    
    // Save the document to disk.
    
    doc.Save(dataDir);
    
    // [Visual Basic Code Sample]
    
    // [Visual Basic Code Sample]
     
    
    ' For complete examples and data files, please go to https://github.com/asposewords/Aspose_Words_NET
    
    Dim doc As New Document(dataDir & Convert.ToString("Table.SimpleTable.doc"))
    
    ' Retrieve the first table in the document.
    
    Dim table As Table = DirectCast(doc.GetChild(NodeType.Table, 0, True), Table)
    
    ' Clone the last row in the table.
    
    Dim clonedRow As Row = DirectCast(table.LastRow.Clone(True), Row)
    
    ' Remove all content from the cloned row's cells. This makes the row ready for
    
    ' new content to be inserted into.
    
    For Each cell As Cell In clonedRow.Cells
    
    cell.RemoveAllChildren()
    
    Next
    
    ' Add the row to the end of the table.
    
    
    table.AppendChild(clonedRow)
    
    dataDir = dataDir & Convert.ToString("Table.AddCloneRowToTable_out_.doc")
    
    
    ' Save the document to disk.
    
    doc.Save(dataDir)
    
    

    public by fostus modified May 11, 2016  79283  0  3  0

    wordpress_register_sidebar

    wordpress_register_sidebar: sidebar_to_function.php
    function true_register_wp_sidebars() {
    
    	/* сайдбар */
    	register_sidebar(
    		array(
    			'id' => 'hidden_side', // уникальный id
    			'name' => 'Скрытый фильтр', // название сайдбара
    			'description' => 'Перетащите сюда виджеты, чтобы добавить их в сайдбар.', // описание
    			'before_widget' => '<div id="%1$s" class="side widget %2$s">', // по умолчанию виджеты выводятся <li>-списком
    			'after_widget' => '</div>',
    			'before_title' => '<h3 class="widget-title">', // по умолчанию заголовки виджетов в <h2>
    			'after_title' => '</h3>'
    		)
    	);
    
    	/* сайдбар */
    	register_sidebar(
    		array(
    			'id' => 'visible_side', // уникальный id
    			'name' => 'Фильтры поиска', // название сайдбара
    			'description' => 'Перетащите сюда виджеты, чтобы добавить их в сайдбар.', // описание
    			'before_widget' => '<div id="%1$s" class="side widget %2$s">', // по умолчанию виджеты выводятся <li>-списком
    			'after_widget' => '</div>',
    			'before_title' => '<h3 class="widget-title">', // по умолчанию заголовки виджетов в <h2>
    			'after_title' => '</h3>'
    		)
    	);
    
    	/* сайдбар */
    	register_sidebar(
    		array(
    			'id' => 'search_side', // уникальный id
    			'name' => 'Расширенный фильтр для поиска', // название сайдбара
    			'description' => 'add widget', // описание
    			'before_widget' => '<div id="%1$s" class="side widget %2$s">', // по умолчанию виджеты выводятся <li>-списком
    			'after_widget' => '</div>',
    			'before_title' => '<h3 class="widget-title">', // по умолчанию заголовки виджетов в <h2>
    			'after_title' => '</h3>'
    		)
    	);
    
    	/* сайдбар */
    	register_sidebar(
    		array(
    			'id' => 'currency_switcher', // уникальный id
    			'name' => 'Валюта', // название сайдбара
    			'description' => 'add widget', // описание
    			'before_widget' => '<div id="%1$s" class="side widget %2$s">', // по умолчанию виджеты выводятся <li>-списком
    			'after_widget' => '</div>',
    			'before_title' => '<h3 class="widget-title">', // по умолчанию заголовки виджетов в <h2>
    			'after_title' => '</h3>'
    		)
    	);
    
    }
    
    add_action( 'widgets_init', 'true_register_wp_sidebars' );
    
    
    • Public Snippets
    • Channels Snippets