function vbmkdir($path, $mode = 0777)
{
    if (is_dir($path)) {
        if (!is_writable($path)) {
            @chmod($path, $mode);
        }
        return true;
    } else {
        $oldmask = @umask(0);
        $partialpath = dirname($path);
        if (!vbmkdir($partialpath, $mode)) {
            return false;
        } else {
            return @mkdir($path, $mode);
        }
    }
}
Example #2
0
	function post_save_each($doquery = true)
	{
		# Check if revision was passed as an info object or as existing
		if (isset($this->info["{$this->revision}"]))
		{
			$revision = $this->info["{$this->revision}"];
		}
		else if ($this->fetch_field($this->revision) !== null)
		{
			$revision = $this->fetch_field($this->revision);
		}

		// We were given an image and a revision number so write out a new image.
		if (!empty($this->info['filedata']) AND isset($revision))
		{
			$oldfilename = $this->fetch_path($this->fetch_field('userid'), $revision);
			$oldthumbfilename = $this->fetch_path($this->fetch_field('userid'), $revision, true);
			$newfilename = $this->fetch_path($this->fetch_field('userid'), $revision + 1);
			$thumbfilename = $this->fetch_path($this->fetch_field('userid'), $revision + 1, true);
			if ($filenum = fopen($newfilename, 'wb'))
			{
				@unlink($oldfilename);
				if ($this->table == 'customavatar')
				{
					@unlink($oldthumbfilename);
				}
				@fwrite($filenum, $this->info['filedata']);
				@fclose($filenum);

				// init user data manager
				$userdata =& datamanager_init('User', $this->registry, ERRTYPE_SILENT);
				$userdata->setr('userid', $this->fetch_field('userid'));
				$userdata->condition = "userid = " . $this->fetch_field('userid');
				$userdata->set($this->revision, $revision + 1);

				$userdata->save();
				unset($userdata);

				if ($this->table == 'customavatar')
				{
					if ($this->info['filedata_thumb'])
					{
						$thumbnail['filedata'] =& $this->info['filedata_thumb'];
					}
					else
					{
						$thumbnail = $this->fetch_thumbnail($newfilename, true);
					}

					require_once(DIR . '/includes/functions_file.php');

					if ($thumbnail['filedata'] AND vbmkdir(dirname($thumbfilename)) AND $filenum = @fopen($thumbfilename, 'wb'))
					{
						@fwrite($filenum, $thumbnail['filedata']);
						@fclose($filenum);

						if ($thumbnail['height'] AND $thumbnail['width'])
						{
							$this->registry->db->query_write("
								UPDATE " . TABLE_PREFIX . "customavatar
								SET width_thumb = $thumbnail[width],
									height_thumb = $thumbnail[height]
								WHERE userid = " . $this->fetch_field('userid')
							);
						}

						unset($thumbnail);
					}
				}

				($hook = vBulletinHook::fetch_hook('userpicdata_postsave')) ? eval($hook) : false;

				return true;
			}
			else
			{
				($hook = vBulletinHook::fetch_hook('userpicdata_postsave')) ? eval($hook) : false;

				$this->error('upload_invalid_imagepath');
				return false;
			}
		}
		else
		{
			($hook = vBulletinHook::fetch_hook('userpicdata_postsave')) ? eval($hook) : false;

			return true;
		}
	}
	/**
	* Additional data to update after a save call (such as denormalized values in other tables).
	* In batch updates, is executed for each record updated.
	*
	* @access protected
	*
	* @param boolean $doquery					Do the query?
	* @return boolean
	*/
	function post_save_each($doquery = true)
	{
		// We were given an image so write out a new image.
		if (!empty($this->info['filedata']))
		{
			// get the file paths
			$oldfilename = $this->fetch_path($this->fetch_field('groupid'), $this->info['group']['icondateline']);
			$oldthumbfilename = $this->fetch_path($this->fetch_field('groupid'), $this->info['group']['icondateline'], true);
			$newfilename = $this->fetch_path($this->fetch_field('groupid'), $this->fetch_field('dateline'));
			$thumbfilename = $this->fetch_path($this->fetch_field('groupid'), $this->fetch_field('dateline'), true);

			// delete the old files and create new ones
			if ($filenum = fopen($newfilename, 'wb'))
			{
				@unlink($oldfilename);
				@unlink($oldthumbfilename);
				@fwrite($filenum, $this->info['filedata']);
				@fclose($filenum);

				if ($this->info['thumbnail_filedata'])
				{
					$thumbnail['filedata'] =& $this->info['thumbnail_filedata'];
				}
				else
				{
					$thumbnail = $this->fetch_thumbnail($newfilename, true);
				}

				require_once(DIR . '/includes/functions_file.php');

				if ($thumbnail['filedata'] AND vbmkdir(dirname($thumbfilename)) AND $filenum = @fopen($thumbfilename, 'wb'))
				{
					@fwrite($filenum, $thumbnail['filedata']);
					@fclose($filenum);

					// ensure the image data contains the correct height and width
					if ($thumbnail['height'] AND $thumbnail['width'])
					{
						$this->registry->db->query_write("
							UPDATE " . TABLE_PREFIX . "socialgroupicon
							SET thumbnail_width = $thumbnail[width],
								thumbnail_height = $thumbnail[height]
							WHERE groupid = " . $this->fetch_field('groupid')
						);
					}

					unset($thumbnail);
				}

				($hook = vBulletinHook::fetch_hook('socgroupicondata_postsave')) ? eval($hook) : false;

				return true;
			}
			else
			{
				($hook = vBulletinHook::fetch_hook('socgroupicondata_postsave')) ? eval($hook) : false;

				$this->error('upload_invalid_imagepath');
				return false;
			}
		}
		else
		{
			($hook = vBulletinHook::fetch_hook('socgroupicondata_postsave')) ? eval($hook) : false;

			return true;
		}
	}
Example #4
0
 }
 if (!$founddest) {
     $postman->set('infraction', 0, true, false);
     // Bypass verify
 }
 if (!empty($updateinfraction)) {
     $db->query_write("\n\t\t\t\tUPDATE " . TABLE_PREFIX . "infraction\n\t\t\t\tSET postid = 0\n\t\t\t\tWHERE infractionid IN (" . implode(',', $updateinfraction) . ")\n\t\t\t");
 }
 $postman->save();
 unset($postman);
 // Update Attachments to point to new owner
 if ($attachtotal) {
     if ($vbulletin->options['attachfile']) {
         require_once DIR . '/includes/functions_file.php';
         $new_path = fetch_attachment_path($userid);
         if (vbmkdir($new_path)) {
             // need to move the attachments not owned by the user
             $attachments = $db->query_read_slave("\n\t\t\t\t\t\tSELECT attachmentid, postid, userid\n\t\t\t\t\t\tFROM " . TABLE_PREFIX . "attachment\n\t\t\t\t\t\tWHERE postid IN (" . implode(',', array_keys($postarray)) . ",{$destpost['postid']})\n\t\t\t\t\t\t\tAND userid <> " . intval($userid) . "\n\t\t\t\t\t");
             while ($attachment = $db->fetch_array($attachments)) {
                 $old_path = fetch_attachment_path($attachment['userid']);
                 @rename("{$old_path}/{$attachment['attachmentid']}.attach", "{$new_path}/{$attachment['attachmentid']}.attach");
                 if (file_exists("{$old_path}/{$attachment['attachmentid']}.thumb")) {
                     @rename("{$old_path}/{$attachment['attachmentid']}.thumb", "{$new_path}/{$attachment['attachmentid']}.thumb");
                 }
             }
         }
     }
     $db->query_write("\n\t\t\t\tUPDATE " . TABLE_PREFIX . "attachment\n\t\t\t\tSET postid = {$destpost['postid']},\n\t\t\t\t\tuserid = {$userid}\n\t\t\t\tWHERE postid IN (" . implode(',', array_keys($postarray)) . ",{$destpost['postid']})\n\t\t\t");
 }
 if ($destpost['threadid'] != $threadinfo['threadid']) {
     // retrieve threadinfo for the owner of the first post
Example #5
0
/**
* Verifies that the picture filesystem path is created as necessary.
*
* @param	array	Array of picture info (to deduce the path)
* @param	boolean	True if you want to verify the thunbnail path
*
* @return	string|bool	Path if successful, false otherwise
*/
function verify_picture_fs_path($pictureinfo, $thumb = false)
{
    global $vbulletin;
    if (!function_exists('vbmkdir')) {
        require_once DIR . '/includes/functions_file.php';
    }
    $path = fetch_picture_fs_path($pictureinfo, $thumb, false);
    if (vbmkdir($path)) {
        return $path;
    } else {
        return false;
    }
}
Example #6
0
 /**
  * Verify that user's attach path exists, create if it doesn't
  *
  * @param	int		userid
  */
 function verify_attachment_path($userid)
 {
     // Allow userid to be 0 since vB2 allowed guests to post attachments
     $userid = intval($userid);
     $path = fetch_attachment_path($userid);
     if (vbmkdir($path)) {
         return $path;
     } else {
         return false;
     }
 }
Example #7
0
 function post_save_each($doquery = true)
 {
     // Check if revision was passed as an info object or as existing
     if (isset($this->info["{$this->revision}"])) {
         $revision = $this->info["{$this->revision}"];
     } else {
         if ($this->fetch_field($this->revision) !== null) {
             $revision = $this->fetch_field($this->revision);
         }
     }
     // We were given an image and a revision number so write out a new image.
     if (!empty($this->info['filedata']) and isset($revision)) {
         $ext = empty($this->existing['aextension']) ? 'gif' : $this->existing['aextension'];
         $oldfilename = $this->fetch_path($this->fetch_field('userid'), $revision, false, $ext);
         $oldthumbfilename = $this->fetch_path($this->fetch_field('userid'), $revision, true, $ext);
         $newfilename = $this->fetch_path($this->fetch_field('userid'), $revision + 1, false, $ext);
         $thumbfilename = $this->fetch_path($this->fetch_field('userid'), $revision + 1, true, $ext);
         if ($filenum = fopen($newfilename, 'wb')) {
             $table = $this->fetchTableBase($this->table);
             if ($revision) {
                 $this->deleteFile($oldfilename);
                 if ($table == 'customavatar') {
                     $this->deleteFile($oldthumbfilename);
                 }
             }
             @fwrite($filenum, $this->info['filedata']);
             @fclose($filenum);
             // init user data manager
             $userdata = new vB_Datamanager_User($this->registry, vB_DataManager_Constants::ERRTYPE_SILENT);
             $userdata->setr('userid', $this->fetch_field('userid'));
             $userdata->condition = array('userid' => $this->fetch_field('userid'));
             $userdata->set($this->revision, $revision + 1);
             $userdata->save();
             unset($userdata);
             if ($table == 'customavatar') {
                 if ($this->info['filedata_thumb']) {
                     $thumbnail['filedata'] =& $this->info['filedata_thumb'];
                 } else {
                     $thumbnail = $this->fetch_thumbnail($newfilename, true);
                 }
                 require_once DIR . '/includes/functions_file.php';
                 $newfiledetails = pathinfo($newfilename);
                 $fields = " filename = '{$newfiledetails['basename']}'";
                 if ($thumbnail['filedata'] and vbmkdir(dirname($thumbfilename)) and $filenum = @fopen($thumbfilename, 'wb')) {
                     @fwrite($filenum, $thumbnail['filedata']);
                     @fclose($filenum);
                     if ($thumbnail['height'] and $thumbnail['width']) {
                         $fields .= ", width_thumb = {$thumbnail['width']}, height_thumb = {$thumbnail['height']}";
                     }
                     unset($thumbnail);
                 }
                 $this->registry->db->query_write("\n\t\t\t\t\t\tUPDATE " . TABLE_PREFIX . "customavatar\n\t\t\t\t\t\tSET {$fields}\n\t\t\t\t\t\tWHERE userid = " . $this->fetch_field('userid'));
             }
             return true;
         } else {
             $this->error('upload_invalid_imagepath');
             return false;
         }
     } else {
         return true;
     }
 }
Example #8
0
 /**
  * Verify that user's attach path exists, create if it doesn't
  *
  * @param	int		userid
  */
 function verify_attachment_path($userid)
 {
     if (!$userid) {
         return false;
     }
     $path = fetch_attachment_path($userid, 0, false, $this->registry->options['pt_attachpath']);
     if (vbmkdir($path)) {
         return $path;
     } else {
         return false;
     }
 }