Esempio n. 1
0
 public function submit()
 {
     // @todo search indexer on posts (reindex all in case the topic_access level has changed))
     $this->topic_subject_clean = titania_url::url_slug($this->topic_subject);
     parent::submit();
     // Hooks
     titania::$hook->call_hook_ref(array(__CLASS__, __FUNCTION__), $this);
 }
Esempio n. 2
0
 public function submit()
 {
     $this->attention_url = titania_url::unbuild_url($this->attention_url);
     // Subscriptions
     if (!$this->attention_id) {
         $email_vars = array('NAME' => $this->attention_title, 'U_VIEW' => titania_url::build_url('manage/attention', array('type' => $this->attention_type, 'id' => $this->attention_object_id)));
         titania_subscriptions::send_notifications(TITANIA_ATTENTION, 0, 'subscribe_notify.txt', $email_vars, $this->attention_poster_id);
     }
     parent::submit();
 }
Esempio n. 3
0
 /**
  * Add a Rating for an item
  *
  * @param mixed $rating The rating
  */
 public function add_rating($rating)
 {
     if ($this->cannot_rate || !phpbb::$user->data['is_registered'] || !phpbb::$auth->acl_get('u_titania_rate')) {
         return false;
     }
     if ($rating < 0 || $rating > titania::$config->max_rating || $this->rating_id) {
         return false;
     }
     $this->rating_value = $rating;
     parent::submit();
     // This is accurate enough as long as we have at least 2 decimal places
     $sql = "UPDATE {$this->cache_table} SET\n\t\t\t{$this->cache_rating} = ({$this->cache_rating} * {$this->rating_count} + {$this->rating_value}) / ({$this->rating_count} + 1),\n\t\t\t{$this->cache_rating_count} = {$this->cache_rating_count} + 1\n\t\t\tWHERE {$this->object_column} = {$this->rating_object_id}";
     phpbb::$db->sql_query($sql);
     return true;
 }
Esempio n. 4
0
    /**
     * Update/create the queue entry for this revision
     */
    public function update_queue()
    {
        // Create the queue entry if required, else update it
        if (titania::$config->use_queue && titania_types::$types[$this->contrib->contrib_type]->use_queue) {
            $queue = $this->get_queue();
            // Only create the queue for revisions set as new
            if ($queue === false && $this->revision_status == TITANIA_REVISION_NEW) {
                $queue = new titania_queue();
            }
            // If we have to create or update one...
            if ($queue !== false) {
                $queue->__set_array(array('revision_id' => $this->revision_id, 'contrib_id' => $this->contrib_id, 'contrib_name_clean' => $this->contrib->contrib_name_clean));
                // Set the queue status to new if it's submitted and the queue status is set to hide it
                if ($this->revision_submitted && $queue->queue_status == TITANIA_QUEUE_HIDE) {
                    // Only set the queue as new if there are not any newer revisions in the queue
                    $sql = 'SELECT queue_id FROM ' . TITANIA_QUEUE_TABLE . '
						WHERE contrib_id = ' . (int) $this->contrib_id . '
							AND revision_id > ' . $this->revision_id;
                    $result = phpbb::$db->sql_query($sql);
                    if (!($row = phpbb::$db->sql_fetchrow($result))) {
                        $queue->queue_status = TITANIA_QUEUE_NEW;
                    }
                }
                $queue->submit();
                // Set the revision queue id
                $this->revision_queue_id = $queue->queue_id;
                parent::submit();
                if ($this->revision_submitted) {
                    // Change the status on any old revisions that were in the queue and marked as New to repacked
                    $sql = 'SELECT * FROM ' . TITANIA_QUEUE_TABLE . '
						WHERE contrib_id = ' . (int) $this->contrib_id . '
							AND revision_id < ' . $this->revision_id . '
							AND queue_status = ' . TITANIA_QUEUE_NEW;
                    $result = phpbb::$db->sql_query($sql);
                    while ($row = phpbb::$db->sql_fetchrow($result)) {
                        $queue = new titania_queue();
                        $queue->__set_array($row);
                        $queue->close(TITANIA_REVISION_RESUBMITTED);
                        unset($queue);
                    }
                    phpbb::$db->sql_freeresult($result);
                }
            }
        }
    }
Esempio n. 5
0
    /**
     * Upload any files we attempted to attach
     *
     * @param bool|int $max_thumbnail_width The maximum thumbnail width (if we create one)
     */
    public function upload($max_thumbnail_width = false)
    {
        // First, we shall handle the items already attached
        $attached_ids = request_var($this->form_name . '_attachments', array(0));
        // Query the ones we must
        $to_query = array_diff($attached_ids, array_keys($this->attachments));
        if (sizeof($to_query)) {
            $sql = 'SELECT * FROM ' . $this->sql_table . '
				WHERE ' . phpbb::$db->sql_in_set('attachment_id', array_map('intval', $to_query)) . '
					AND object_type = ' . (int) $this->object_type . '
					AND object_id = ' . (int) $this->object_id;
            // Don't let them be messin with us
            $result = phpbb::$db->sql_query($sql);
            while ($row = phpbb::$db->sql_fetchrow($result)) {
                $this->attachments[$row['attachment_id']] = $row;
            }
            phpbb::$db->sql_freeresult($result);
        }
        // Next, delete those requested
        $delete = request_var('delete_file', array(0));
        foreach ($delete as $attach_id => $null) {
            $this->delete($attach_id);
            $this->deleted = true;
            // Sometime I'll look into this again; having it setup to only delete attachments after the form is submitted
            /*if (isset($this->attachments[$attach_id]))
            		{
            			$this->attachments[$attach_id]['deleted'] = true;
            		}*/
        }
        // And undelete any
        /*$undelete = request_var('undelete_file', array(0));
        		foreach ($delete as $attach_id => $null)
        		{
        			if (isset($this->attachments[$attach_id]))
        			{
        				$this->attachments[$attach_id]['deleted'] = false;
        			}
        		}*/
        if (isset($_FILES[$this->form_name])) {
            // In order to save ourselves from rewriting the phpBB uploader to support multi-uploads, we have to do some hacking
            $uploaded_files = array();
            if (is_array($_FILES[$this->form_name]['name'])) {
                // Store the files in our own data array
                foreach ($_FILES[$this->form_name]['name'] as $id => $name) {
                    $uploaded_files[] = array('name' => $name, 'type' => $_FILES[$this->form_name]['type'][$id], 'tmp_name' => $_FILES[$this->form_name]['tmp_name'][$id], 'error' => $_FILES[$this->form_name]['error'][$id], 'size' => $_FILES[$this->form_name]['size'][$id]);
                }
            } else {
                // Compatibility with non-multi-upload forms
                $uploaded_files[] = $_FILES[$this->form_name];
            }
            // Finally upload new items if required
            foreach ($uploaded_files as $uploaded_file) {
                // Hack time
                $_FILES[$this->form_name] = $uploaded_file;
                if ($_FILES[$this->form_name]['name'] != 'none' && trim($_FILES[$this->form_name]['name'])) {
                    // Setup uploader tool.
                    $this->uploader = new titania_uploader($this->form_name, $this->object_type);
                    // Try uploading the file.
                    $this->uploader->upload_file();
                    // Store for easier access
                    $this->error = array_merge($this->error, $this->uploader->filedata['error']);
                    // If we had no problems we can submit the data to the database.
                    if (!sizeof($this->uploader->filedata['error'])) {
                        // Create thumbnail
                        $has_thumbnail = false;
                        if ($this->uploader->filedata['is_image']) {
                            phpbb::_include('functions_posting', 'create_thumbnail');
                            $src = titania::$config->upload_path . utf8_basename($this->uploader->filedata['attachment_directory']) . '/' . utf8_basename($this->uploader->filedata['physical_filename']);
                            $dst = titania::$config->upload_path . utf8_basename($this->uploader->filedata['attachment_directory']) . '/thumb_' . utf8_basename($this->uploader->filedata['physical_filename']);
                            $has_thumbnail = $this->create_thumbnail($src, $dst, $this->uploader->filedata['mimetype'], $max_thumbnail_width, $max_thumbnail_width === false ? false : 0);
                        }
                        $this->__set_array(array('attachment_id' => 0, 'physical_filename' => $this->uploader->filedata['physical_filename'], 'attachment_directory' => $this->uploader->filedata['attachment_directory'], 'real_filename' => $this->uploader->filedata['real_filename'], 'extension' => $this->uploader->filedata['extension'], 'mimetype' => $this->uploader->filedata['mimetype'], 'filesize' => $this->uploader->filedata['filesize'], 'filetime' => $this->uploader->filedata['filetime'], 'hash' => $this->uploader->filedata['md5_checksum'], 'thumbnail' => $has_thumbnail, 'attachment_comment' => utf8_normalize_nfc(request_var('filecomment', '', true))));
                        parent::submit();
                        // Store in $this->attachments[]
                        $this->attachments[$this->attachment_id] = $this->__get_array();
                        // Additional fields
                        foreach ($this->additional_fields as $output_key => $row_key) {
                            $this->attachments[$this->attachment_id][$row_key] = utf8_normalize_nfc(request_var($row_key, '', true));
                        }
                    }
                    $this->uploaded = true;
                }
            }
            // We do not want to upload it again if this function is called again.
            unset($_FILES[$this->form_name]);
        }
    }