/** * Load styles */ public function load_styles() { $sql_array = array('SELECT' => 'c.contrib_id, c.contrib_name, c.contrib_name_clean, c.contrib_user_id, c.contrib_demo, s.attachment_id AS thumb_id, s.thumbnail, MAX(r.revision_id) AS revision_id, u.username, u.username_clean, u.user_colour, cat.category_name', 'FROM' => array($this->contribs_table => 'c'), 'LEFT_JOIN' => array(array('FROM' => array($this->users_table => 'u'), 'ON' => 'c.contrib_user_id = u.user_id'), array('FROM' => array($this->attachments_table => 's'), 'ON' => 'c.contrib_id = s.object_id AND s.is_preview = 1 AND s.is_orphan = 0 AND object_type = ' . TITANIA_SCREENSHOT), array('FROM' => array($this->revisions_table => 'r'), 'ON' => 'c.contrib_id = r.contrib_id AND r.revision_submitted = 1 AND r.revision_status = ' . TITANIA_REVISION_APPROVED), array('FROM' => array($this->contrib_in_categories_table => 'cic'), 'ON' => 'c.contrib_id = cic.contrib_id'), array('FROM' => array($this->categories_table => 'cat'), 'ON' => 'cic.category_id = cat.category_id'), array('FROM' => array($this->revisions_phpbb_table => 'rp'), 'ON' => 'c.contrib_id = rp.contrib_id AND r.revision_id = rp.revision_id')), 'WHERE' => 'c.contrib_visible = 1 AND c.contrib_type = ' . TITANIA_TYPE_STYLE . ' AND cat.category_options & ' . TITANIA_CAT_FLAG_DEMO . ' AND c.contrib_status =' . TITANIA_CONTRIB_APPROVED . ' AND c.contrib_demo <> "" AND rp.phpbb_version_branch = ' . (int) $this->phpbb_branch, 'GROUP_BY' => 'c.contrib_id', 'ORDER_BY' => 'cat.left_id, c.contrib_name ASC'); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql, 3600); $style = new \titania_contribution(); while ($row = $this->db->sql_fetchrow($result)) { $style->__set('contrib_demo', $row['contrib_demo']); if ($style->get_demo_url($this->phpbb_branch)) { $this->styles[$row['contrib_id']] = array_merge($row, array('coauthors' => '', 'phpbb_versions' => array())); $this->revisions[] = $row['revision_id']; } } $this->db->sql_freeresult($result); if (empty($this->styles)) { throw new http_exception(200, 'NO_STYLES'); } elseif ($this->default_style && !isset($this->styles[$this->default_style])) { throw new http_exception(404, 'NO_DEMO'); } $sql = 'SELECT contrib_id, attachment_id, revision_license FROM ' . $this->revisions_table . ' WHERE ' . $this->db->sql_in_set('revision_id', $this->revisions); $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $this->styles[$row['contrib_id']] += array('attachment_id' => $row['attachment_id'], 'revision_license' => $row['revision_license']); } $this->db->sql_freeresult($result); // Get coauthors and phpBB versions for the styles $this->get_coauthors(); $this->get_phpbb_versions(); // If we have no default style, we use the first in the list if (!$this->default_style) { $indexes = array_keys($this->styles); $this->default_style = $this->styles[$indexes[0]]['contrib_id']; } return true; }