Viewing Paste 408

Formated Paste

  1. // Send me an array of customization ids and I'll return an array of context.
  2. function loadCustomizationContext($id_cust = array(), $order = '')
  3. {
  4. global $context, $cust_settings, $smcFunc, $modSettings;
  5.  
  6. //$id_cust = is_array($id_cust) ? $id_cust : array($id_cust);
  7.  
  8. $id_cust = $id_cust === array() ? $context['customization']['id'] : $id_cust;
  9.  
  10. if (($context['customization'] = cache_get_data('custs_' . serialize($id_cust), $cust_settings['cache_time'])) == null)
  11. {
  12. // The reason why I'm not joining the members table again for c.id_owner is because the owner is also an author.
  13. // So, we can just grab that information from the authors table.
  14. $request = $smcFunc['db_query']('cust_context', '
  15. SELECT c.id_cust, c.id_site, c.id_owner, c.id_topic, c.id_topic_discuss, c.id_topic_dev,
  16. c.submit_time, c.modified_time, c.latest_version, c.name, c.id_file,
  17. c.cust_type as type, c.id_cat, c.approved, c.downloads, c.package_id, c.short_desc,
  18. c.enabled_features, c.description, t.id_tag, t.name AS tag_name,
  19. a.id_member AS id_author, IFNULL(feat.id_cust, 0) as featured,
  20. IFNULL(f.id_file, 0) as id_file, at.id_attach, at.id_thumb, at.id_folder,
  21. at.attachment_type, at.filename, at.file_hash, at.fileext, at.size,
  22. at.downloads AS file_downloads, at.width, at.height, at.mime_type
  23. FROM {raw:database}customizations as c
  24. LEFT JOIN {raw:database}tagged as td ON (td.id_cust = c.id_cust)
  25. LEFT JOIN {raw:database}tags as t ON (t.id_tag = td.id_tag)
  26. LEFT JOIN {raw:database}authors as a ON (a.id_cust = c.id_cust)
  27. LEFT JOIN {raw:database}members as m ON (mem.id_member = a.id_member)
  28. LEFT JOIN {raw:database}featured as feat ON (feat.id_cust = c.id_cust)
  29. LEFT JOIN {raw:database}files as f ON (f.id_cust = c.id_cust)
  30. LEFT JOIN {raw:database}attachments as at ON (at.id_attach = f.id_attach)
  31. WHERE c.id_cust IN({raw:id_cust})
  32. {raw:order_by} {raw:order}
  33. LIMIT {int:limit}',
  34. 'database' => $cust_settings['db_prefix'],
  35. 'id_cust' => implode(',', $id_cust),
  36. 'order_by' => empty($order) ? '' : 'ORDER BY',
  37. 'limit' => count($id_cust),
  38. )
  39. );
  40.  
  41. if ($smcFunc['db_num_rows']($request) == 0)
  42. return null;
  43.  
  44. // Setup those empty arrays.
  45. $context['cust_tags'] = array();
  46. $context['cust_authors'] = array();
  47. $context['cust_tags'] = array();
  48.  
  49. while ($row = $smcFunc['db_fetch_assoc']($request))
  50. {
  51. if (!isset($context['customization'][$row['id_cust']])
  52. {
  53. $context['customization'][$row['id_cust']] = array(
  54. 'name' => $row['name'],
  55. 'id' => $row['id_cust'],
  56. 'owner' => array(
  57. 'id' => $row['id_owner'],
  58. 'name' => $row['poster_name'],
  59. ),
  60. 'site' => array(
  61. 'id' => $row['id_site'],
  62. 'name' => ,
  63. ),
  64. 'authors' => array(),
  65. 'files' => array(),
  66. 'tags' => array(),
  67. 'downloads' => comma_format($row['downloads']),
  68. 'description' => parse_bbc($row['description']),
  69. 'short_desc' => parse_bbc($row['short_desc']),
  70. 'submit_time' => timeformat($row['submit_time']),
  71. 'modified_time' => timeformat($row['modified_time']),
  72. 'package_id' => $row['package_id'],
  73. 'featured' => (bool) $row['featured'],
  74. );
  75. }
  76.  
  77. // Tags.
  78. if (!isset($context['cust_tags'][$row['id_tag']])
  79. $context['cust_tags'][$row['id_tag']] = array(
  80. 'id' => $row['id_tag'],
  81. 'name' => $row['tag_name'],
  82. );
  83. if (!in_array($row['id_tag'], $context['customization'][$row['id_cust']]['tags']))
  84. $context['customization'][$row['id_cust']]['tags'][] = $row['id_tag'];
  85.  
  86. // Authors.
  87. if (!isset($context['cust_authors'][$row['id_author']])
  88. $context['cust_authors'][$row['id_author']] = array(
  89. 'id' => $row['id_author'],
  90. 'name' => $row['author_name'],
  91. );
  92. if (!in_array($row['id_author'], $context['customization'][$row['id_cust']]['authors']))
  93. $context['customization'][$row['id_cust']]['authors'][] = $row['id_author'];
  94. if ($row['id_author'] == $row['id_owner'])
  95. $context['customization'][$row['id_cust']]['owner']['name'] = $row['author_name'];
  96.  
  97. // Files.
  98. if (!isset($context['customization'][$row['id_cust']]['files'][$row['id_file']] && $row['id_file'] != 0)
  99. $context['customization'][$row['id_cust']]['files'][$row['id_file']] = array(
  100. 'id' => $row['id_file'],
  101. 'name' => $row['filename'],
  102. 'location' => $modSettings['attachmentUploadDir'][$row['id_folder']] . '/' . $row['filename'],
  103. //'url' => $row[''],
  104. 'id_attach' => $row['id_attach'],
  105. 'id_folder' => $row['id_folder'],
  106. 'type' => $row['attachment_type'],
  107. 'hash' => $row['file_hash'],
  108. 'ext' => $row['fileext'],
  109. 'size' => $row['size'],
  110. 'downloads' => $row['file_downloads'],
  111. 'width' => $row['width'],
  112. 'height' => $row['height'],
  113. 'mime_type' => $row['mime_type'],
  114. );
  115. }
  116.  
  117. if (!empty($modSettings['cache_enable']))
  118. cache_put_data('custs_' . serialize($id_cust), $context['cust_tags'], $cust_settings['extended_cache_time']);
  119. }
  120. }
Name:
Email:
Code/text to paste:
  • Enable code highlighting
  • Code Language:
  • A duck, cat and a goose walk into a bar. How many animals walked into a bar?:
Highslide for Wordpress Plugin