function logQuery($sql) { $return = parent::logQuery($sql); if (Configure::read('Cake.logQuery')) { debugger::log("sql[{$this->_queriesCnt}]:" . $sql); } $this->log($sql, LOG_DEBUG); return $return; }
public function signup($data) { $error = array(); // create a new user $this->create(); // fill array with data we need in the db $data['User']['added'] = date('Y-m-d'); $data['User']['accessed'] = date('Y-m-d'); $data['User']['email'] = strtolower($data['User']['email']); $data['User']['level'] = '1'; $data['User']['invisible'] = false; $data['User']['slug'] = $data['User']['slug']; $data['User']['type'] = '1'; $data['User']['searchable'] = true; $data['User']['avatar_id'] = '-1'; $data['User']['first_login'] = true; // save the user if (!$this->save(Sanitize::clean($data))) { // don't continue anything if this failed return false; } // no longer needed, scrap it unset($data); // make their home directory structure $dir = $this->makeUserDir($this->id); if ($dir != false) { $this->saveField('home_dir', $dir['home']); $this->saveField('sub_dir', $dir['sub']); } else { $error['User']['user_dir'] = 'Could not create user directory'; } $this->Profile->create(); $profile['Profile']['user_id'] = $this->id; $profile['Profile']['dob'] = '1900-01-01'; $this->Profile->save($profile); $this->Album->create(); $data['Album']['title'] = 'Profile Pictures'; $data['Album']['description'] = __('profile_pictures', true); $data['Album']['user_id'] = $this->id; $data['Album']['slug'] = 'profile_pictures'; if (!$this->Album->save($data)) { $error['User']['album_error'] = 'Could not create album'; } if (count($error)) { debugger::log($error['User']); return false; } else { return $this->id; } }
/** * This is the method that actually does the thumbnail generation by setting up * the parameters and calling phpThumb * * @return bool Success? * @author Nate Constant **/ function generateThumb($baseDir, $dir, $filename, $size, $options = array()) { // Make sure we have the name of the uploaded file and that the Model is specified if (empty($baseDir) || empty($filename)) { Debugger::log('Base directory or filename is empty'); return false; } $source = $baseDir . $dir . $filename; if (empty($size)) { $height = 100; $width = 100; } else { $height = $size['height']; $width = $size['width']; } // verify that the size is greater than 0 ( emtpy file uploaded ) if (filesize($baseDir . $dir . $filename === 0)) { Debugger::log('File is empty'); return false; } // verify that the filesystem is writable, if not add an error to the object // dont fail if not and let phpThumb try anyway $cacheDir = $baseDir . 'cache' . DS; if (!file_exists($cacheDir)) { debugger::log('Cache directory doesn\'t exist'); if (!mkdir($cacheDir)) { Debugger::log('Can\' create ' . $cacheDir); return false; } } if (!is_writable($cacheDir)) { debugger::log($cacheDir . ' not writable'); chmod($cacheDir, 0777); } // Load phpThumb App::import('Vendor', 'phpThumb', array('file' => 'phpThumb/phpthumb.class.php')); $phpThumb = new phpThumb(); // phpThumb configs $phpThumb->setParameter('config_cache_force_passthru', false); $phpThumb->setParameter('config_allow_src_above_docroot', true); // ignore aspect ratio and allow enlarging // $phpThumb->setParameter('iar', 1); // image configs $phpThumb->setSourceFilename($source); $phpThumb->setParameter('w', $width); $phpThumb->setParameter('h', $height); // auto rotate based on exif data $phpThumb->setParameter('ar', 'x'); foreach ($options as $key => $val) { $phpThumb->setParameter($key, $val); } // $phpThumb->setParameter('zc', 1); if ($phpThumb->generateThumbnail()) { if (!$phpThumb->RenderToFile($cacheDir . $filename . '-' . $height . 'x' . $width . '.jpg')) { Debugger::log('Could not render to file'); return false; } } else { Debugger::log('Could not generate thumbnail'); return false; } return true; }