/[drupal]/contributions/modules/node_import/node_import.inc
ViewVC logotype

Diff of /contributions/modules/node_import/node_import.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1.2.22, Tue Dec 16 22:12:23 2008 UTC revision 1.1.2.23, Thu Jan 1 09:49:31 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: node_import.inc,v 1.1.2.21 2008/12/16 13:55:06 robrechtj Exp $  // $Id: node_import.inc,v 1.1.2.22 2008/12/16 22:12:23 robrechtj Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 1045  function node_import_check_node(&$value, Line 1045  function node_import_check_node(&$value,
1045   */   */
1046    
1047  /**  /**
1048     * @defgroup node_import_util Various node import utility functions.
1049     * @{
1050     */
1051    
1052    /**
1053     * Store an object-id in the node_import cache.
1054     *
1055     * As some string->object-id lookups can be expensive (in db queries) and
1056     * most of the time the same strings are looked up (eg users), we have a
1057     * cache of object-ids we already have looked up.
1058     *
1059     * This function is used to store an object-id in the cache.
1060     *
1061     * @param $type
1062     *   String. The type of object (eg 'user').
1063     *
1064     * @param $value
1065     *   String or array. The value we haved looked up.
1066     *
1067     * @param $oid
1068     *   Integer. The looked-up object-id. If NULL, the currently stored
1069     *   object-id is returned without setting the $type/$value to NULL.
1070     *   If you want to reset (eg make it NULL) a value, use
1071     *   @code
1072     *   node_import_set_object($type, $value, NULL, TRUE);
1073     *   @endcode
1074     *
1075     * @param $reset
1076     *   Boolean. Whether to reset the cache. If $type is NULL, the whole
1077     *   cache is reset. If $value is not NULL only the cache for that
1078     *   specific $type/$value is reset.
1079     *
1080     * @return
1081     *   Integer. The looked-up object-id.
1082     *
1083     * @see node_import_get_object().
1084     */
1085    function node_import_set_object($type, $value, $oid = NULL, $reset = FALSE) {
1086      static $cache;
1087    
1088      if (!isset($cache)) {
1089        $cache = array();
1090      }
1091      if (isset($type) && !isset($cache[$type])) {
1092        $cache[$type] = array();
1093      }
1094    
1095      $stored_value = NULL;
1096      if (isset($value)) {
1097        $stored_value = is_array($value) ? implode("\n", array_map('drupal_strtolower', $value)) : drupal_strtolower($value);
1098      }
1099    
1100      if ($reset) {
1101        if (isset($type)) {
1102          if (isset($value)) {
1103            unset($cache[$type][$stored_value]);
1104          }
1105          else {
1106            $cache[$type] = array();
1107          }
1108        }
1109        else {
1110          $cache = array();
1111        }
1112        return;
1113      }
1114    
1115      if (isset($oid)) {
1116        $cache[$type][$stored_value] = $oid;
1117      }
1118    
1119      return $cache[$type][$stored_value];
1120    }
1121    
1122    /**
1123     * Get an object-id from the node_import cache.
1124     *
1125     * @param $type
1126     *   String. The type of object (eg 'user').
1127     *
1128     * @param $value
1129     *   String or array. The value to get the object-id of.
1130     *
1131     * @return
1132     *   NULL if not yet in cache. Otherwise an integer.
1133     *
1134     * @see node_import_set_object().
1135     */
1136    function node_import_get_object($type, $value) {
1137      return node_import_set_object($type, $value);
1138    }
1139    
1140    /**
1141   * Get a property from each element of an array.   * Get a property from each element of an array.
1142   *   *
1143   * @param $array   * @param $array
# Line 1109  function node_import_input_error($messag Line 1202  function node_import_input_error($messag
1202  }  }
1203    
1204  /**  /**
1205     * @}
1206     */
1207    
1208    /**
1209   * @defgroup node_import_files Node import file functions   * @defgroup node_import_files Node import file functions
1210   * @{   * @{
1211     */
1212    
1213  /**  /**
1214   * Returns a list of available files.   * Returns a list of available files.

Legend:
Removed from v.1.1.2.22  
changed lines
  Added in v.1.1.2.23

  ViewVC Help
Powered by ViewVC 1.1.2