'protoPress_byFernTec_projects' , 'unique_key' => $basepress_dataset_uid_projects , 'version' => '0.1' ) ; // ------------------------------------------------------------------------- // REFERENCE URLS dataset... // ------------------------------------------------------------------------- $basepress_dataset_uid_reference_urls = '2f35c079-ef2e-4dea-a0e2-f1f861375aef' . '-' . 'afe2576d-76b2-4a5c-83a3-60b652467438' . '-' . '995a2d40-63d3-11e3-949a-0800200c9a66' . '-' . 'a6acf950-63d3-11e3-949a-0800200c9a66' ; // ------------------------------------------------------------------------- $basepress_dataset_handle_reference_urls = array( 'nice_name' => 'protoPress_byFernTec_reference_urls' , 'unique_key' => $basepress_dataset_uid_reference_urls , 'version' => '0.1' ) ; // ------------------------------------------------------------------------- // CANDIDATE PAGES dataset... // ------------------------------------------------------------------------- $basepress_dataset_uid_candidate_pages = 'ccc7eaf0-63d3-11e3-949a-0800200c9a66' . '-' . 'fcbc06ea-9feb-4b4b-8d51-c0d88928ec2b' . '-' . 'eaf2cd2e-8ada-4b65-a9c9-bcd2c214c187' . '-' . 'f4ad272d-021b-4c5d-bfee-43644b44ce42' ; // ------------------------------------------------------------------------- $basepress_dataset_handle_candidate_pages = array( 'nice_name' => 'protoPress_byFernTec_candidate_pages' , 'unique_key' => $basepress_dataset_uid_candidate_pages , 'version' => '0.1' ) ; // ------------------------------------------------------------------------- // TEST dataset... // ------------------------------------------------------------------------- $basepress_dataset_uid_test = '-9a6e-ccb5d826-c0eb-4cfab538-4f96e100' . '-' . '-ae76-a1932fbc-2606-42a95a09-58720680' . '-' . '-949a-fb05ba50-594c-11e30800-200c9a66' . '-' . '-b3bc-970958d4-849c-4344e72d-3cff374e' ; // ------------------------------------------------------------------------- $basepress_dataset_handle_test = array( 'nice_name' => 'protoPress_byFernTec_test' , 'unique_key' => $basepress_dataset_uid_test , 'version' => '0.1' ) ; // ========================================================================= // Define the DATASETS USED... // ========================================================================= $GLOBALS['GREAT_KIWI']['ARRAY_STORAGE']['supported_datasets'] = array( 'projects' => array( 'storage_method' => NULL , 'json_filespec' => NULL , 'basepress_dataset_handle' => $basepress_dataset_handle_projects ) , 'reference_urls' => array( 'storage_method' => NULL , 'json_filespec' => NULL , 'basepress_dataset_handle' => $basepress_dataset_handle_reference_urls ) , 'candidate_pages' => array( 'storage_method' => NULL , 'json_filespec' => NULL , 'basepress_dataset_handle' => $basepress_dataset_handle_candidate_pages ) , 'test-dataset' => array( 'storage_method' => NULL , 'json_filespec' => NULL , 'basepress_dataset_handle' => $basepress_dataset_handle_test ) ) ; // ========================================================================= // Define the DEFAULT STORAGE METHOD... // ========================================================================= // $GLOBALS['GREAT_KIWI']['ARRAY_STORAGE']['default_storage_method'] = 'json' ; $GLOBALS['GREAT_KIWI']['ARRAY_STORAGE']['default_storage_method'] = 'basepress-dataset' ; */ // ============================================================================= // init() // ============================================================================= function init( $default_storage_method , $json_data_files_dir = NULL , $supported_datasets = array() ) { // ------------------------------------------------------------------------- // \greatKiwi_byFernTec_adSwapper_local_v0x1x210_arrayStorage\ // init( // $default_storage_method , // $json_data_files_dir = NULL , // $supported_datasets = array() // ) // - - - - - - - - - - - - - - - - - // You MUST call this function - to initialise the array storage system - // BEFORE calling any of the array storage functions proper. Ie; before // calling:- // o load() // o load_numerically_indexed() // o save() // o save_numerically_indexed() // o (etc) // // $supported_datasets must be a (possibly empty) array like (eg):- // // $supported_datasets = array( // => // ... // ) // // Eg:- // // $supported_datasets = array( // // 'projects' => array( // 'storage_method' => NULL , // 'json_filespec' => NULL , // 'basepress_dataset_handle' => array( // 'nice_name' => 'protoPress_byFernTec_test' , // 'unique_key' => 'a6acf950-63d3-11e3-949a-0800200c9a66' , // 'version' => '0.1' // ) // ) , // // ... // // ) // // RETURNS // o On SUCCESS // - - - - - // TRUE // // o On FAILURE // - - - - - // $error_message STRING // ------------------------------------------------------------------------- // ========================================================================= // ERROR CHECKING // ========================================================================= // ------------------------------------------------------------------------- // default_storage_method ? // ------------------------------------------------------------------------- if ( ! is_string( $default_storage_method ) || ! in_array( $default_storage_method , array( 'json' , 'basepress-dataset' ) , TRUE ) ) { return << $default_storage_method , 'json_data_files_dir' => $json_data_files_dir , 'supported_datasets' => $supported_datasets ) ; // ========================================================================= // SUCCESS! // ========================================================================= return TRUE ; // ========================================================================= // That's that! // ========================================================================= } // ============================================================================= // load_numerically_indexed() // ============================================================================= function load_numerically_indexed( $dataset_name , $question_die_on_error = FALSE , $array_storage_data = NULL ) { // ------------------------------------------------------------------------- // \greatKiwi_byFernTec_adSwapper_local_v0x1x210_arrayStorage\ // load_numerically_indexed( // $dataset_name , // $question_die_on_error = FALSE , // $array_storage_data = NULL // ) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Loads and returns the specified PHP numerically indexed array. // // $array_storage_data can be either:- // // o NULL (in which case:- // $GLOBALS['GREAT_KIWI']['ARRAY_STORAGE'] // is used), or; // // o array( // 'default_storage_method' => "json" | "basepress-dataset" // 'json_data_files_dir' => NULL | "xxx" // 'supported_datasets' => $supported_datasets // ) // Where $supported_datasets is:- // array( // '' => array( // 'storage_method' => NULL | "json" | "basepress-dataset" , // 'json_filespec' => NULL | "xxx" , // 'basepress_dataset_handle' => $some_basepress_dataset_handle // ) // ... // ) // Where $some_basepress_dataset_handle is (eg):- // array( // 'nice_name' => 'adSwapper_byFerntec_someDatasetName' , // 'unique_key' => $some_basepress_dataset_uid , // 'version' => '0.1' // ) // Where $some_basepress_dataset_uid is (eg):- // '2f35c079-ef2e-4dea-a0e2-f1f861375aef' . '-' . // 'afe2576d-76b2-4a5c-83a3-60b652467438' . '-' . // '995a2d40-63d3-11e3-949a-0800200c9a66' . '-' . // 'a6acf950-63d3-11e3-949a-0800200c9a66' // ; // // RETURNS // o On SUCCESS // - - - - - // ARRAY $array // A possibly empty PHP numerically indexed ARRAY. // // o On FAILURE // - - - - - // $error_message STRING // ------------------------------------------------------------------------- // ========================================================================= // LOAD the ARRAY... // ========================================================================= $result = load( $dataset_name , $question_die_on_error , $array_storage_data ) ; // ======================================================================= // Make sure the records are numerically indexed, starting from 0 // (and in steps of 1). // // Because many of the PHP and Javascript routines that handle the // returned PHP array assume this to be the case - and will fail if // it isn't)... // ======================================================================= if ( is_array( $result ) ) { $result = array_values( $result ) ; } // ======================================================================= // RETURN the results... // ======================================================================= //if ( is_array( $result ) ) { // pr( $result , ' ' . $dataset_name . ' as loaded...' ) ; //} return $result ; // ======================================================================= // That's that! // ======================================================================= } // ============================================================================= // load() // ============================================================================= function load( $dataset_name , $question_die_on_error = FALSE , $array_storage_data = NULL ) { // ------------------------------------------------------------------------- // \greatKiwi_byFernTec_adSwapper_local_v0x1x210_arrayStorage\ // load( // $dataset_name , // $question_die_on_error = FALSE , // $array_storage_data = NULL // ) // - - - - - - - - - - - - - - - - - - - - - // Loads and returns the specified PHP numerically indexed or associative // ARRAY. // // $array_storage_data can be either:- // // o NULL (in which case:- // $GLOBALS['GREAT_KIWI']['ARRAY_STORAGE'] // is used), or; // // o array( // 'default_storage_method' => "json" | "basepress-dataset" // 'json_data_files_dir' => NULL | "xxx" // 'supported_datasets' => $supported_datasets // ) // Where $supported_datasets is:- // array( // '' => array( // 'storage_method' => NULL | "json" | "basepress-dataset" , // 'json_filespec' => NULL | "xxx" , // 'basepress_dataset_handle' => $some_basepress_dataset_handle // ) // ... // ) // Where $some_basepress_dataset_handle is (eg):- // array( // 'nice_name' => 'adSwapper_byFerntec_someDatasetName' , // 'unique_key' => $some_basepress_dataset_uid , // 'version' => '0.1' // ) // Where $some_basepress_dataset_uid is (eg):- // '2f35c079-ef2e-4dea-a0e2-f1f861375aef' . '-' . // 'afe2576d-76b2-4a5c-83a3-60b652467438' . '-' . // '995a2d40-63d3-11e3-949a-0800200c9a66' . '-' . // 'a6acf950-63d3-11e3-949a-0800200c9a66' // ; // // RETURNS // o On SUCCESS // - - - - - // ARRAY $array // A possibly empty PHP numerically indexed or associative ARRAY. // // o On FAILURE // - - - - - // $error_message STRING // ------------------------------------------------------------------------- // ========================================================================= // DEFAULT the ARRAY STORAGE DATA... // ========================================================================= if ( $array_storage_data === NULL ) { $array_storage_data = $GLOBALS['GREAT_KIWI']['ARRAY_STORAGE'] ; } // ========================================================================= // DATASET NAME VALID ? // ========================================================================= if ( ! array_key_exists( $dataset_name , $array_storage_data['supported_datasets'] ) ) { // --------------------------------------------------------------------- $msg = << "xxx" // 'unique_key' => "xxx" // 'version' => "xxx" // ) ; // // Where:- // // o $nice_name // is a max 255 character string that gives a friendly but // hopefully still unique name to the dataset. Usually, // datasets will be owned by plugins or themes. So the // $nice_name will be that of the plugin or them. But // possibly with some extra words to identify the author // (whether an individual or a business) - and anything else // that might help to uniquely identify the dataset. // // For example:- // "wordpress-post-search-and-replace-by-cocktail-systems" // // The intention with this name, is to create something that // no other dataset - created by another plugin or theme - is // likely to duplicate. // // o $unique_key // is a max 255 character string that gives a genuinely random // and thereby almost certainly unique name to the dataset. // // For example:- // "85adfc5b-f268-441a-8aa8-40913d816b49-48bfb6c4-d951" // // In other words, it's something that the online password and // GUID/UUID generators can easily generate for you. To // maximise the chances of uniqueness, you can easily string // multiple such passwords/GUIDs together - up to the 255 // character limit. // // The idea with the $unique_key is simply to decrease the // chances that some other plugin or theme author will // (accidentally) duplicate BOTH the $nice_name and the // $unique_key that you selected. // // o $version // is a max 255 character string that you can use to assign // a version number to your dataset. Obviously, as you // release new/updated versions of your plugin or theme, // while some might use exactly the same dataset as previous // versions, others may not. // // So $version allows you to differentiate between the // different versions you might create. // // RETURNS // o On SUCCESS // - - - - - // ARRAY( $record_id , $data ) // // Where:- // o $record_id is either:- // -- The record ID of the "basepress_datasets" table // record (that holds the requested dataset's data), or; // // -- NULL if either the "basePress_datasets" table - or the // specified dataset record - doesn't exist yet). // // o $data is a (possibly empty) PHP associative ARRAY of // name=value pairs. // // o On FAILURE // - - - - - // An error message STRING. // ------------------------------------------------------------------------- $basepress_dataset_handle = $array_storage_data['supported_datasets'][ $dataset_name ]['basepress_dataset_handle'] ; // ------------------------------------------------------------------------- $result = \greatKiwi_byFernTec_adSwapper_local_v0x1x210_basepressDatasets\load( $basepress_dataset_handle ) ; // ------------------------------------------------------------------------- if ( is_string( $result ) ) { // --------------------------------------------------------------------- if ( $question_die_on_error ) { die( $result ) ; } // --------------------------------------------------------------------- return $result ; // --------------------------------------------------------------------- } // ------------------------------------------------------------------------- list( $record_id , $data ) = $result ; // ========================================================================= // SUCCESS! // ========================================================================= return $data ; // ========================================================================= // That's that! // ========================================================================= } // ============================================================================= // save_numerically_indexed() // ============================================================================= function save_numerically_indexed( $dataset_name , $array_to_save , $question_die_on_error = FALSE , $array_storage_data = NULL ) { // ------------------------------------------------------------------------- // \greatKiwi_byFernTec_adSwapper_local_v0x1x210_arrayStorage\ // save_numerically_indexed( // $dataset_name , // $array_to_save , // $question_die_on_error = FALSE , // $array_storage_data = NULL // ) // - - - - - - - - - - - - - - - - - - - - - - - - - // Saves the specified numerically-indexed PHP array. // // NOTE! // ----- // Does:- // $array_to_save = array_values( $array_to_save ) ; // // to ensures it's indices are 0, 1, 2... (before saving it). // // --- // // $array_storage_data can be either:- // // o NULL (in which case:- // $GLOBALS['GREAT_KIWI']['ARRAY_STORAGE'] // is used), or; // // o array( // 'default_storage_method' => "json" | "basepress-dataset" // 'json_data_files_dir' => NULL | "xxx" // 'supported_datasets' => $supported_datasets // ) // Where $supported_datasets is:- // array( // '' => array( // 'storage_method' => NULL | "json" | "basepress-dataset" , // 'json_filespec' => NULL | "xxx" , // 'basepress_dataset_handle' => $some_basepress_dataset_handle // ) // ... // ) // Where $some_basepress_dataset_handle is (eg):- // array( // 'nice_name' => 'adSwapper_byFerntec_someDatasetName' , // 'unique_key' => $some_basepress_dataset_uid , // 'version' => '0.1' // ) // Where $some_basepress_dataset_uid is (eg):- // '2f35c079-ef2e-4dea-a0e2-f1f861375aef' . '-' . // 'afe2576d-76b2-4a5c-83a3-60b652467438' . '-' . // '995a2d40-63d3-11e3-949a-0800200c9a66' . '-' . // 'a6acf950-63d3-11e3-949a-0800200c9a66' // ; // // RETURNS // o On SUCCESS // - - - - - // TRUE // // o On FAILURE // - - - - - // $error message STRING // ------------------------------------------------------------------------- // ======================================================================= // Make sure the records are numerically indexed, starting from 0 // (and in steps of 1). // // Because many of the PHP and Javascript routines that handle the // returned PHP array assume this to be the case - and will fail if // it isn't)... // ======================================================================= if ( is_array( $array_to_save ) ) { $array_to_save = array_values( $array_to_save ) ; } // ======================================================================= // Do the SAVE proper... // ======================================================================= return save( $dataset_name , $array_to_save , $question_die_on_error , $array_storage_data ) ; // ======================================================================= // That's that! // ======================================================================= } // ============================================================================= // save() // ============================================================================= function save( $dataset_name , $array_to_save , $question_die_on_error = FALSE , $array_storage_data = NULL ) { // ------------------------------------------------------------------------- // \greatKiwi_byFernTec_adSwapper_local_v0x1x210_arrayStorage\ // save( // $dataset_name , // $array_to_save , // $question_die_on_error = FALSE , // $array_storage_data = NULL // ) // - - - - - - - - - - - - - - - - - - - - - // Saves the specified (PHP) array. // // This array is typically either:- // // o An PHP NUMERICALLY-INDEXED ARRAY of RECORDS // // Eg:- // $returned_array = array( // [0] => array( // 'name1' => // 'name2' => // ... // 'nameN' => // ) , // ... // ) // // o A PHP ASSOCIATIVE ARRAY of NAME=VALUE PAIRS // // Eg:- // $returned_array = array( // 'name1' => // 'name2' => // ... // 'nameN' => // ) // // Where each value can itself be a numeric or associative array // (to any depth). // // --- // // $array_storage_data can be either:- // // o NULL (in which case:- // $GLOBALS['GREAT_KIWI']['ARRAY_STORAGE'] // is used), or; // // o array( // 'default_storage_method' => "json" | "basepress-dataset" // 'json_data_files_dir' => NULL | "xxx" // 'supported_datasets' => $supported_datasets // ) // Where $supported_datasets is:- // array( // '' => array( // 'storage_method' => NULL | "json" | "basepress-dataset" , // 'json_filespec' => NULL | "xxx" , // 'basepress_dataset_handle' => $some_basepress_dataset_handle // ) // ... // ) // Where $some_basepress_dataset_handle is (eg):- // array( // 'nice_name' => 'adSwapper_byFerntec_someDatasetName' , // 'unique_key' => $some_basepress_dataset_uid , // 'version' => '0.1' // ) // Where $some_basepress_dataset_uid is (eg):- // '2f35c079-ef2e-4dea-a0e2-f1f861375aef' . '-' . // 'afe2576d-76b2-4a5c-83a3-60b652467438' . '-' . // '995a2d40-63d3-11e3-949a-0800200c9a66' . '-' . // 'a6acf950-63d3-11e3-949a-0800200c9a66' // ; // // RETURNS // o On SUCCESS // - - - - - // TRUE // // o On FAILURE // - - - - - // $error message STRING // ------------------------------------------------------------------------- // ========================================================================= // DEFAULT the ARRAY STORAGE DATA... // ========================================================================= if ( $array_storage_data === NULL ) { $array_storage_data = $GLOBALS['GREAT_KIWI']['ARRAY_STORAGE'] ; } // ========================================================================= // DATASET NAME VALID ? // ========================================================================= if ( ! array_key_exists( $dataset_name , $array_storage_data['supported_datasets'] ) ) { // --------------------------------------------------------------------- $msg = << "xxx" // 'unique_key' => "xxx" // 'version' => "xxx" // ) ; // // Where:- // // o $nice_name // is a max 255 character string that gives a friendly but // hopefully still unique name to the dataset. Usually, // datasets will be owned by plugins or themes. So the // $nice_name will be that of the plugin or them. But // possibly with some extra words to identify the author // (whether an individual or a business) - and anything else // that might help to uniquely identify the dataset. // // For example:- // "wordpress-post-search-and-replace-by-cocktail-systems" // // The intention with this name, is to create something that // no other dataset - created by another plugin or theme - is // likely to duplicate. // // o $unique_key // is a max 255 character string that gives a genuinely random // and thereby almost certainly unique name to the dataset. // // For example:- // "85adfc5b-f268-441a-8aa8-40913d816b49-48bfb6c4-d951" // // In other words, it's something that the online password and // GUID/UUID generators can easily generate for you. To // maximise the chances of uniqueness, you can easily string // multiple such passwords/GUIDs together - up to the 255 // character limit. // // The idea with the $unique_key is simply to decrease the // chances that some other plugin or theme author will // (accidentally) duplicate BOTH the $nice_name and the // $unique_key that you selected. // // o $version // is a max 255 character string that you can use to assign // a version number to your dataset. Obviously, as you // release new/updated versions of your plugin or theme, // while some might use exactly the same dataset as previous // versions, others may not. // // So $version allows you to differentiate between the // different versions you might create. // // --- // // $record_id can be either:- // // o The record ID retrieved when the dataset was originally loaded // (by "\basepress_datasets\load()"), or; // // o NULL if either the dataset's record (and possibly the // "basepress_datasets" table too,) doesn't exist. Or the // record may exist - but it's record ID isn't known. // // --- // // RETURNS // o On SUCCESS // - - - - - // INT The saved dataset's $record_id. (Which is returned in // case either the dataset didn't exist (before it was saved). Or // it did exist, but it's record ID was unknown.) // // o On FAILURE // - - - - - // An error message STRING. // ------------------------------------------------------------------------- $basepress_dataset_handle = $array_storage_data['supported_datasets'][ $dataset_name ]['basepress_dataset_handle'] ; // ------------------------------------------------------------------------- $record_id = NULL ; // ------------------------------------------------------------------------- $result = \greatKiwi_byFernTec_adSwapper_local_v0x1x210_basepressDatasets\save( $basepress_dataset_handle , $array_to_save , $record_id ) ; // ------------------------------------------------------------------------- if ( is_string( $result ) ) { // --------------------------------------------------------------------- if ( $question_die_on_error ) { die( $result ) ; } // --------------------------------------------------------------------- return $result ; // --------------------------------------------------------------------- } // ========================================================================= // SUCCESS! // ========================================================================= return TRUE ; // ========================================================================= // That's that! // ========================================================================= } // ============================================================================= // That's that! // =============================================================================