/** * Output ColorizeIt data for a given revision in XML format. * * @param int $id Attachment id. * @return Symfony\Component\HttpFoundation\Response */ public function colorizeit_data($id) { if (!strlen($this->ext_config->colorizeit) || !$this->check_auth()) { return $this->error('ERROR_NO_ATTACHMENT'); } try { $this->load($id); } catch (\Exception $e) { return $this->error($e->getMessage()); } if (!$this->contrib->has_colorizeit()) { return $this->error('CLR_ERROR_NOSAMPLE'); } if (!empty($this->revision->revision_clr_options)) { $options = unserialize($this->revision->revision_clr_options); } else { $colorizeit_helper = new colorizeit_helper(); try { $options = $colorizeit_helper->generate_options($this->attachment->get_filepath(), $this->ext_config->__get('contrib_temp_path')); } catch (\Exception $e) { return $this->error($e->getMessage()); } $colorizeit_helper->submit_options($options, $this->revision->revision_id, $this->db); } return new Response($this->get_xml_output($options), 200); }
/** * Sync attachments */ public function attachments($mode, $attachment_id = false) { switch ($mode) { case 'hash': $sql = 'SELECT * FROM ' . $this->attachments_table . ($attachment_id !== false ? 'WHERE attachment_id = ' . (int) $attachment_id : ''); $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $this->attachment->__set_array($row); $file = $this->attachment->get_filepath(); if (file_exists($file)) { $md5 = md5_file($file); if ($md5 != $row['hash']) { $sql = 'UPDATE ' . $this->attachments_table . ' SET hash = "' . $this->db->sql_escape($md5) . '" WHERE attachment_id = ' . $row['attachment_id']; $this->db->sql_query($sql); } } } $this->db->sql_freeresult($result); break; } }
/** * Set package location and temp path. */ protected function set_package_paths() { $this->package->set_temp_path($this->ext_config->__get('contrib_temp_path'), true)->set_source($this->attachment->get_filepath()); }
/** * @{inheritDoc} */ public function fix_package_name(\titania_contribution $contrib, \titania_revision $revision, attachment $attachment, $root_dir = null) { // If we managed to find a single parent directory, then we use that in the zip name, otherwise we fall back to using contrib_name_clean if ($root_dir !== null) { $new_real_filename = $root_dir . '_' . strtolower($revision->revision_version) . '.' . $attachment->extension; } else { $new_real_filename = $contrib->contrib_name_clean . '_' . strtolower($revision->revision_version) . '.' . $attachment->extension; } $attachment->change_real_filename($new_real_filename); return $root_dir; }
/** * @{inheritDoc} */ public function fix_package_name(\titania_contribution $contrib, \titania_revision $revision, attachment $attachment, $root_dir = null) { $new_real_filename = url::generate_slug($contrib->contrib_name_clean) . '_' . preg_replace('#[^0-9a-z]#', '_', strtolower($revision->revision_version)); $attachment->change_real_filename($new_real_filename . '.' . $attachment->extension); return $new_real_filename; }
/** * Compare the order of two attachments. * * @param attachment $attach1 * @param attachment $attach2 * @return int */ public function order_comparison($attach1, $attach2) { if ($attach1->get('attachment_order') == $attach2->get('attachment_order')) { return 0; } else { return $attach1->get('attachment_order') > $attach2->get('attachment_order') ? 1 : -1; } }
/** * Load revision package. */ protected function load_package() { $this->package = new \phpbb\titania\entity\package(); $this->package->set_source($this->attachment->get_filepath())->set_temp_path($this->ext_config->__get('contrib_temp_path'), true); }