{"id":21404341,"url":"https://github.com/boost/ip2region-drupal-module","last_synced_at":"2025-07-04T03:06:19.781Z","repository":{"id":66517019,"uuid":"645647","full_name":"boost/ip2region-Drupal-module","owner":"boost","description":"Create \"regions\" and associate them with IP addresses. Determine content to be served by region","archived":false,"fork":false,"pushed_at":"2010-10-28T01:29:44.000Z","size":108,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-16T16:44:44.236Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://www.boost.co.nz","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/boost.png","metadata":{"files":{"readme":"README","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-05-04T01:05:45.000Z","updated_at":"2014-01-29T10:34:12.000Z","dependencies_parsed_at":"2023-02-20T05:40:20.235Z","dependency_job_id":null,"html_url":"https://github.com/boost/ip2region-Drupal-module","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/boost/ip2region-Drupal-module","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boost%2Fip2region-Drupal-module","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boost%2Fip2region-Drupal-module/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boost%2Fip2region-Drupal-module/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boost%2Fip2region-Drupal-module/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/boost","download_url":"https://codeload.github.com/boost/ip2region-Drupal-module/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boost%2Fip2region-Drupal-module/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263437343,"owners_count":23466367,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-22T16:14:30.239Z","updated_at":"2025-07-04T03:06:19.759Z","avatar_url":"https://github.com/boost.png","language":"PHP","readme":"IP2Region Installation and Usage\n================================\n\nINSTALLING\n----------\n1. Download and install the ip2region module into the relevant modules folder.\n\nFor example, if all of your Drupal Sites will use ip2region, place the module \\sites\\all\\modules\\ip2region\n\nIf you are only using ip2region for one particular site, place it in the module folder in that site.\n\n\n2. In the Drupal admin console navigate to \u003eAdminister \u003eSite building \u003eModules and switch on the ip2region module.\n\n\n3. Next navigate to \u003eAdminister \u003eUser management \u003ePermissions and give the appropriate permissions to your users.  NOTE:  A standard authenticated or anonymous user should only be able to \"view regional content\"\n\n\n4. Create a Taxonomy called \"Regions\", navigate to \u003eAdminister \u003eContent Management \u003eTaxonomy and create the list of regions that can be used by the IP2Region module for setting up IP ranges. \n\nEach entry in the taxonomy is the name of a region, for example:\n\nName\n=====\nBoost\nBuller\nCentral Hawke's Bay\nGisborne\nGrey\nHamilton\nHauraki\n\nIf you have already created Content types that you want to make regional, you should select those content types from the list when you are creating the Taxonomy.  If you haven't already created regional content types, you will need create the content type and then come back to this screen and associate the \"Regions\" taxonomy with the particular content type.\n\n\n5. The ip2region module should now be configured for use, navigate to \u003eAdminister \u003eSite configuration \u003eIP to Region\n\nHere you enter the regions and their IP ranges, for example\n\nLibrary Name      Region               IP From        IP To\n===================================================================\nHawarden          Hurunui\t            172.23.5.0\t   172.23.5.255\nWaipawa\t         Central Hawke's Bay\t172.22.79.0\t   172.22.79.255\nWanganui          Wanganui\t            172.21.28.0\t   172.21.28.255\n\nUse \"Add\" to a region IP range.\n\nUse \"Test IP Range\" to confirm a particular IP range is working.\n\n\n6. The \"Regions\" Taxonomy is automatically associated with a user and will show as a dropdown list on the user form when you create a user. If you associate a region with the user and the user is logged into Drupal, the region associated with their user profile will take preference over their actual IP address (the function ip2region_get_region_tid() provides this functionality). \n\nYou can also use the region in views. This can be useful, for example, if you have regional users who can only see certain content.  If you set up an administrative view that filters by region, then a user will only be able to edit content associated with their region.\n\n\n\n\nKEY FUNCTIONS PROVIDED\n----------------------\n\n/**\n * Get id for Regions Taxonomy according to IP address \n * (if forced_region or forced_ip, or logged in user's region, will take precedence over machine IP address)\n */\nfunction ip2region_get_region_tid()\n\n/**\n * Get the current user's IP address\n */\nfunction ip2region_ip_address()  \n\nThis returns the IP Address for the current user, regardless of whether they are authenticated or anonymous.\n\n/**\n *Get the region associated with a particular IP address\n */\nfunction ip2region_get_region_from_ip($users_ip=NULL)\n\n/**\n * Ensure the specified region is in the Region table\n */\nfunction ip2region_get_region_from_region($users_region=NULL)\n\n\n/**\n * Finds all nodes that match selected taxonomy conditions.\n *\n * This code modifies the standard drupal function taxonomy_select_nodes.\n * \n * Core drupal taxonomy_select_nodes limits number of items the RSS feed variable 'feed_default_items'\n * Default was 10 and could only be raised to a maximum of 30)\n * see http://drupal.org/node/296632 for more info\n * \n * This function modifies the number of available results, takes an optional parameter of $number_results, default is 10\n * \n */\nfunction ip2region_taxonomy_select_nodes($tids = array(), $operator = 'or', $depth = 0, $pager = TRUE, $order = 'n.sticky DESC, n.created DESC', $number_results=10)\n\n\n\n\nEXAMPLE CODE FOR LOADING REGIONAL CONTENT\n-----------------------------------------\n\nFrom within the template.php file (for your site theme)\n\n/*\n *Loads any nodes with regional content based on the ID from the Regions Taxonomy.\n *In this example the regional content type is called \"regional_go_local\" (that's the Drupal \"machine\" name)\n */\nfunction load_regional_content() {\n  //Get the region associated with the current IP address\n  $region_id = ip2region_get_region_tid();\n  \n  //Create a query to return the ids of the nodes which are associated with the region \n  //NOTE: Nodes loaded in created descending order, i.e. latest first\n  $result = ip2region_taxonomy_select_nodes(array($region_id), 'and', $depth = \"all\", $pager = FALSE, $order = 'n.created DESC', $number_results=200);\n  $local_nodes = array();\n  \n  //Execute the query to return regional nodes\n  while ($data = db_fetch_object($result)) {\n    $local_nodes[] = $data;\n  }\n\n  //Create an array of regional nodes to pass to the page templates\n  $regional_vars = array();\n  $regional_vars = array_merge($regional_vars, load_single_node($local_nodes, 'regional_go_local'));\n\n  return $regional_vars;\n}\n\n\n//Load a particular regional node of $node_type\nfunction load_single_node($local_nodes, $node_type) {\n  $regional_vars = array();\n  foreach ($local_nodes as $local_node) :\n    $regional_node = node_load($local_node-\u003enid);\n    if ($regional_node-\u003estatus) :\n      if ($regional_node-\u003etype == $node_type) :\n        $regional_vars[$node_type] = $regional_node;\n        break;\n      endif;\n    endif;\n  endforeach;\n \n  return $regional_vars;\n}\n\n\nFrom within the page template files you can access the $regional_vars, for example\n\n\u003c?php if (isset($regional_go_local)) : ?\u003e\t\n   \u003cdiv class='module-a'\u003e\n      \u003ch3\u003e\u003ca href=''\u003e\u003c?php print($regional_go_local-\u003efield_display_title[0]['value']) ?\u003e\u003c/a\u003e\u003c/h3\u003e\n      \u003cp\u003e\u003c?php print($regional_go_local-\u003ebody) ?\u003e\u003c/p\u003e\n      \u003cdiv class='ft'\u003e\u003c/div\u003e\n\t\u003c/div\u003e\u003c!-- module-a --\u003e\n\u003c?php endif ;?\u003e\n\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboost%2Fip2region-drupal-module","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fboost%2Fip2region-drupal-module","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboost%2Fip2region-drupal-module/lists"}