News:

Please note these forums are mostly a testing ground for my SMF work and I don't really use them otherwise.

Main Menu

Paste-1259966360:v:use_geshi-1:v:type-php

Started by Guest, Dec 04, 2009, 10:39 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Guest

// Send me an array of customization ids and I'll return an array of context.
function loadCustomizationContext($id_cust = array(), $order = '')
{
   global $context, $cust_settings, $smcFunc, $modSettings;

   //$id_cust = is_array($id_cust) ? $id_cust : array($id_cust);

   $id_cust = $id_cust === array() ? $context['customization']['id'] : $id_cust;

   if (($context['customization'] = cache_get_data('custs_' . serialize($id_cust), $cust_settings['cache_time'])) == null)
   {
      // The reason why I'm not joining the members table again for c.id_owner is because the owner is also an author.
      // So, we can just grab that information from the authors table.
      $request = $smcFunc['db_query']('cust_context', '
         SELECT c.id_cust, c.id_site, c.id_owner, c.id_topic, c.id_topic_discuss, c.id_topic_dev,
            c.submit_time, c.modified_time, c.latest_version, c.name, c.id_file,
            c.cust_type as type, c.id_cat, c.approved, c.downloads, c.package_id, c.short_desc,
            c.enabled_features, c.description, t.id_tag, t.name AS tag_name,
            a.id_member AS id_author, IFNULL(feat.id_cust, 0) as featured,
            IFNULL(f.id_file, 0) as id_file, at.id_attach, at.id_thumb, at.id_folder,
            at.attachment_type, at.filename, at.file_hash, at.fileext, at.size,
            at.downloads AS file_downloads, at.width, at.height, at.mime_type
         FROM {raw:database}customizations as c
         LEFT JOIN {raw:database}tagged as td ON (td.id_cust = c.id_cust)
         LEFT JOIN {raw:database}tags as t ON (t.id_tag = td.id_tag)
         LEFT JOIN {raw:database}authors as a ON (a.id_cust = c.id_cust)
         LEFT JOIN {raw:database}members as m ON (mem.id_member = a.id_member)
         LEFT JOIN {raw:database}featured as feat ON (feat.id_cust = c.id_cust)
         LEFT JOIN {raw:database}files as f ON (f.id_cust = c.id_cust)
         LEFT JOIN {raw:database}attachments as at ON (at.id_attach = f.id_attach)
         WHERE c.id_cust IN({raw:id_cust})
         {raw:order_by} {raw:order}
         LIMIT {int:limit}',
         array(
            'database' => $cust_settings['db_prefix'],
            'id_cust' => implode(',', $id_cust),
            'order_by' => empty($order) ? '' : 'ORDER BY',
            'limit' => count($id_cust),
         )
      );

      if ($smcFunc['db_num_rows']($request) == 0)
         return null;

      // Setup those empty arrays.
      $context['cust_tags'] = array();
      $context['cust_authors'] = array();
      $context['cust_tags'] = array();

      while ($row = $smcFunc['db_fetch_assoc']($request))
      {
         if (!isset($context['customization'][$row['id_cust']])
         {
            $context['customization'][$row['id_cust']] = array(
               'name' => $row['name'],
               'id' => $row['id_cust'],
               'owner' => array(
                  'id' => $row['id_owner'],
                  'name' => $row['poster_name'],
               ),
               'site' => array(
                  'id' => $row['id_site'],
                  'name' => ,
               ),
               'authors' => array(),
               'files' => array(),
               'tags' => array(),
               'downloads' => comma_format($row['downloads']),
               'description' => parse_bbc($row['description']),
               'short_desc' => parse_bbc($row['short_desc']),
               'submit_time' => timeformat($row['submit_time']),
               'modified_time' => timeformat($row['modified_time']),
               'package_id' => $row['package_id'],
               'featured' => (bool) $row['featured'],
            );
         }

         // Tags.
         if (!isset($context['cust_tags'][$row['id_tag']])
            $context['cust_tags'][$row['id_tag']] = array(
               'id' => $row['id_tag'],
               'name' => $row['tag_name'],
            );
         if (!in_array($row['id_tag'], $context['customization'][$row['id_cust']]['tags']))
            $context['customization'][$row['id_cust']]['tags'][] = $row['id_tag'];

         // Authors.
         if (!isset($context['cust_authors'][$row['id_author']])
            $context['cust_authors'][$row['id_author']] = array(
               'id' => $row['id_author'],
               'name' => $row['author_name'],
            );
         if (!in_array($row['id_author'], $context['customization'][$row['id_cust']]['authors']))
            $context['customization'][$row['id_cust']]['authors'][] = $row['id_author'];
         if ($row['id_author'] == $row['id_owner'])
            $context['customization'][$row['id_cust']]['owner']['name'] = $row['author_name'];

         // Files.
         if (!isset($context['customization'][$row['id_cust']]['files'][$row['id_file']] && $row['id_file'] != 0)
            $context['customization'][$row['id_cust']]['files'][$row['id_file']] = array(
               'id' => $row['id_file'],
               'name' => $row['filename'],
               'location' => $modSettings['attachmentUploadDir'][$row['id_folder']] . '/' . $row['filename'],
               //'url' => $row[''],
               'id_attach' => $row['id_attach'],
               'id_folder' => $row['id_folder'],
               'type' => $row['attachment_type'],
               'hash' => $row['file_hash'],
               'ext' => $row['fileext'],
               'size' => $row['size'],
               'downloads' => $row['file_downloads'],
               'width' => $row['width'],
               'height' => $row['height'],
               'mime_type' => $row['mime_type'],
            );
      }

      if (!empty($modSettings['cache_enable']))
         cache_put_data('custs_' . serialize($id_cust), $context['cust_tags'], $cust_settings['extended_cache_time']);
   }
}