Example #1
0
 /**
  * Constructor - checks that the registry object has been passed correctly.
  *
  * @param	vB_Registry	Instance of the vBulletin data registry object - expected to have the database object as one of its $this->db member.
  * @param	integer		One of the ERRTYPE_x constants
  */
 public function __construct(&$registry, $errtype = ERRTYPE_STANDARD)
 {
     parent::__construct($registry, $errtype);
     ($hook = vBulletinHook::fetch_hook('attachdata_start')) ? eval($hook) : false;
 }
Example #2
0
/**
* Class factory. This is used for instantiating the extended classes.
*
* @param	string			The type of the class to be called (user, forum etc.)
* @param	vB_Registry		An instance of the vB_Registry object.
* @param	integer			One of the ERRTYPE_x constants
* @param	string			Option to force loading a class from a specific file; no extension
*
* @return	vB_DataManager	An instance of the desired class
*/
function &datamanager_init($classtype, &$registry, $errtype = ERRTYPE_STANDARD, $forcefile = '')
{
    static $called;
    if (empty($called)) {
        // include the abstract base class
        require_once DIR . '/includes/class_dm.php';
        $called = true;
    }
    if (preg_match('#^\\w+$#', $classtype)) {
        $classtype = strtolower($classtype);
        if ($forcefile) {
            $classfile = preg_replace('#[^a-z0-9_]#i', '', $forcefile);
        } else {
            $classfile = str_replace('_multiple', '', $classtype);
        }
        require_once DIR . '/includes/class_dm_' . $classfile . '.php';
        switch ($classtype) {
            case 'attachment':
                $object = vB_DataManager_Attachment::fetch_library($registry, $errtype);
                break;
            case 'userpic_avatar':
            case 'userpic_profilepic':
            case 'userpic_sigpic':
                $object = vB_DataManager_Userpic::fetch_library($registry, $errtype, $classtype);
                break;
            default:
                $classname = 'vB_DataManager_' . $classtype;
                $object = new $classname($registry, $errtype);
        }
        return $object;
    }
}
Example #3
0
 /**
  * Any checks to run immediately before saving. If returning false, the save will not take place.
  *
  * @param	boolean	Do the query?
  *
  * @return	boolean	True on success; false if an error occurred
  */
 function pre_save($doquery = true)
 {
     if ($this->presave_called !== null) {
         return $this->presave_called;
     }
     // make sure we don't have the binary data set
     // if so move it to an information field
     // benefit of this is that when we "move" files from DB to FS,
     // the filedata/thumbnail fields are not blanked in the database
     // during the update.
     if ($file =& $this->fetch_field('filedata')) {
         $this->setr_info('filedata', $file);
         $this->do_unset('filedata');
     }
     if ($thumb =& $this->fetch_field('thumbnail')) {
         $this->setr_info('thumbnail', $thumb);
         $this->do_unset('thumbnail');
     }
     if (!empty($this->info['filedata'])) {
         $this->set('filehash', md5($this->info['filedata']));
         $this->set('filesize', strlen($this->info['filedata']));
     } else {
         if (!empty($this->info['filedata_location']) and file_exists($this->info['filedata_location'])) {
             $this->set('filehash', md5_file($this->info['filedata_location']));
             $this->set('filesize', filesize($this->info['filedata_location']));
         }
     }
     if (!empty($this->info['thumbnail'])) {
         $this->set('thumbnail_filesize', strlen($this->info['thumbnail']));
     }
     if (!empty($this->info['filedata']) or !empty($this->info['thumbnail']) or !empty($this->info['filedata_location'])) {
         $path = $this->verify_attachment_path($this->fetch_field('userid'));
         if (!$path) {
             $this->error('attachpathfailed');
             return false;
         }
         if (!is_writable($path)) {
             $this->error('upload_file_system_is_not_writable');
             return false;
         }
     }
     return parent::pre_save($doquery);
 }