/[drupal]/contributions/modules/import/import.module
ViewVC logotype

Diff of /contributions/modules/import/import.module

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

revision 1.16, Fri Jun 18 11:42:46 2004 UTC revision 1.17, Fri Oct 31 17:51:22 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: import.module,v 1.15 2004/04/06 15:04:13 ber Exp $  // $Id$
 function import_perm() {  
   return array("access import");  
 }  
   
 function import_link($type, $node = 0, $main = 0) {  
   global $user;  
   
   if ($type == "system" && user_access("access import")) {  
     if (!module_exist("feed") || !module_exist("item")) {  
       menu("import", t("news aggregator"), "import_page_error", 0);  
     }  
     elseif (user_access("edit own feed")) {  
       menu("node/add/feed", t("news feed"), "node_page", 0);  
       menu("import", t("news aggregator"), "import_page_latest", 0);  
       menu("import/user", t("news feeds"), "import_page_user", 0, MENU_HIDE);  
       menu("import/user/". $user->uid, t("my feeds"), "import_page_user", 1);  
       menu("import/sources", t("news by source"), "import_page_sources", 0);  
       if (module_exist("taxonomy_dhtml")) {  
         menu("import/categories/item", t("categories"), "import_categories", 0);  
         menu("import/categories/feed", t("sources by category"), "import_categories", 0);  
       }  
     }  
     else {  
       menu("import", t("news aggregator"), "import_page_latest", 0);  
       menu("import/sources", t("news by source"), "import_page_sources", 0);  
       menu("import/user", t("news feeds"), "import_page_user", 0, MENU_HIDE);  
       if (module_exist("taxonomy_dhtml")) {  
         menu("import/categories/item", t("categories"), "import_categories", 0);  
         menu("import/categories/feed", t("sources by category"), "import_categories", 0);  
       }  
     }  
   }  
   
   return $links ? $links : array();  
 }  
   
 function theme_import_latestitem($node) {  
   return theme("node", $node, 0);  
 }  
   
 function import_page_latest() {  
   $nids = module_invoke_all("import", "items");  
   if ($nids) {  
     $result = pager_query("SELECT nid FROM {node} WHERE nid IN (". implode(",", $nids) .") ORDER BY created DESC, nid DESC", ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10)), 0);  
   }  
   
   while ($import_node = db_fetch_object($result)) {  
     $output .= theme("import_latestitem", node_load(array("nid" => $import_node->nid)));  
   }  
   
   $output .= theme("pager", "", ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10)), 0);  
   
   print theme("page", $output);  
 }  
   
 function import_categories() {  
   $type = arg(2);  
   if ($type != "item" && $type != "feed") {  
     $type = "item";  
   }  
   $boxes = taxonomy_dhtml_overview($type);  
   print theme("header");  
   for ($n=0; $n < count($boxes); $n++) {  
     print theme("box", $boxes[$n]["subject"], $boxes[$n]["content"]);  
   }  
   return theme("footer");  
 }  
   
 function theme_import_source($node) {  
   return theme("node", $node, 1);  
 }  
   
 function import_page_user() {  
   $uid = arg(2);  
   
   if(!is_numeric($uid)) {  
     print drupal_not_found();  
     return;  
   }  
   
   $nids = module_invoke_all("import", "sources");  
   if ($nids) {  
     $result = pager_query("SELECT nid FROM {node} n LEFT JOIN {users} u ON u.uid = n.uid WHERE u.uid = $uid AND n.nid IN (". implode(",", $nids) .") ORDER BY title, nid", ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10)), 0);  
   }  
   
   while ($import_source = db_fetch_object($result)) {  
     $output .= theme("import_source", node_load(array("nid" => $import_source->nid)));  
   }  
   
   $output .= theme("pager", "", ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10)), 0);  
   
   print theme("page", $output);  
 }  
   
 function import_page_sources() {  
   $nids = module_invoke_all("import", "sources");  
   if ($nids) {  
     $result = pager_query("SELECT nid FROM {node} WHERE nid IN (". implode(",", $nids) .") ORDER BY title, nid", ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10)), 0);  
   }  
   
   while ($import_source = db_fetch_object($result)) {  
     $output .= theme("import_source", node_load(array("nid" => $import_source->nid)));  
   }  
   
   $output .= theme("pager", "", ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10)), 0);  
   
   print theme("page", $output);  
 }  
   
 function import_page_error() {  
   print theme("page", theme("error", t("For the import module to function properly please ensure that both the feed and item modules are enabled in the ". l(t("modules configuration"), "admin/system/modules") ." page.")));  
 }  
3    
4  function import_user($type, $edit, &$user) {  /**
5    // What type of registration action are we taking?   * creates hook_import
6    switch ($type) {   */
7      case "view_public":  function import_stage_import() {
8      case "view_private":    module_invoke_all('import_stage');
9        return form_item(t("Import"), l(t("view personal feeds"), "import/user/$user->uid", array("title" => t("Read %username's latest blog entries.", array("%username" => $user->name)))));    return;
10       }  }
11    /**
12     * creates hook_import
13     */
14    function import_process_import($data) {
15      module_invoke_all('import_process',$data);
16      return;
17    }
18    /*
19     * Implementation of hook_menu().
20     */
21    function import_menu() {
22      $items = array();
23      $items['admin/settings/import'] = array(
24        'title' => 'Import',
25        'description' => 'Settings for Import.',
26        'page callback' => 'drupal_get_form',
27        'page arguments' => array('import_settings'),
28        'type' => MENU_NORMAL_ITEM,
29        'access arguments' => array('administer nodes'),
30      );
31      return $items;
32    }
33    
34    /**
35     * Stages content into {import}
36     *
37     * @param array $args accepts $args['impid'] and $args['type']
38     */
39    function import_stage($args) {
40      if(array_key_exists('impid',$args) && array_key_exists('type',$args)) {
41        db_query("INSERT INTO {import} VALUES('%s', '%s')", $args['impid'], $args['type']);
42      } else {
43        drupal_set_message(t("There was an error staging your data.  Please provide an array with impid and type keys."));
44      }
45      return;
46    }
47    
48    /**
49     * Implementation of hook_cron().
50     */
51    function import_cron() {
52      global $total_user_save, $total_profile_save, $total_import_save, $total_user_import, $total_get_old_user;
53      $total_user_save = 0;
54      $total_profile_save = 0;
55      $total_import_save = 0;
56      $total_user_import = 0;
57      $total_get_old_user = 0;
58      $start_timer = time();
59      // first stage all data
60      import_stage_import();
61      //dpm('Staging took '. (time() - $start_timer) .' seconds.');
62      $result = db_query_range("Select impid, type from {import}", 0, variable_get("import_per_cron",50));
63      while ($row = db_fetch_object($result)) {
64        import_process_import($row);
65      }
66      $timer_duration = time() - $start_timer;
67      //dpm('Importing took '. $timer_duration .' seconds.');
68      //dpm('Getting old user from sportingnews_users took '. $total_get_old_user .' seconds.');
69      //dpm('Import of just users was '. $total_user_save .' seconds');
70      //dpm('Import of profile_value rows was '. $total_profile_save .' seconds.');
71      //dpm('Talking to import_pass/fail was '. $total_import_save .' seconds.');
72      //dpm(t('Total of calls to import function: @time seconds', array('@time' => $total_user_import)));
73    }
74    
75    /**
76     * a modified version of
77     *
78     * @param object $node
79     * @param string $msg
80     * @todo implement message
81     */
82    function import_pass($data, $msg='') {
83      db_query("INSERT INTO {import_pass} VALUES('%s', '%s')", $data->impid, $data->type);
84      db_query("DELETE from {import} where impid = '%s'", $data->impid);
85    }
86    
87    /**
88     * a modified version of
89     *
90     * @param object $node
91     * @param string $msg
92     * @todo implement message
93     */
94    function import_fail($data, $msg='') {
95      db_query("INSERT INTO {import_fail} VALUES('%s','%s','%s')", $data->impid, $data->type, $msg);
96      db_query("DELETE from {import} where impid = '%s'", $data->impid);
97    }
98    
99    /**
100     * Implementation of hook_settings
101     */
102    function import_settings() {
103      $form['import_per_cron'] = array(
104        '#type' => 'textfield',
105        '#title' => t('Number of items to process per cron'),
106        '#size' => 10,
107        '#maxlength' => 20,
108        '#required' => true,
109        '#default_value' => variable_get('import_per_cron', 50),
110      );
111      return system_settings_form($form);
112  }  }
 ?>  

Legend:
Removed from v.1.16  
changed lines
  Added in v.1.17

  ViewVC Help
Powered by ViewVC 1.1.2