本文整理汇总了PHP中Avatar::insert方法的典型用法代码示例。如果您正苦于以下问题:PHP Avatar::insert方法的具体用法?PHP Avatar::insert怎么用?PHP Avatar::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Avatar
的用法示例。
在下文中一共展示了Avatar::insert方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: newAvatar
function newAvatar($profile_id, $size, $mediatype, $filename)
{
global $config;
$avatar = new Avatar();
$avatar->profile_id = $profile_id;
switch ($size) {
case 'mini':
$avatar->width = 24;
$avatar->height = 24;
break;
case 'normal':
$avatar->width = 48;
$avatar->height = 48;
break;
default:
// Note: Twitter's big avatars are a different size than
// StatusNet's (StatusNet's = 96)
$avatar->width = 73;
$avatar->height = 73;
}
$avatar->original = 0;
// we don't have the original
$avatar->mediatype = $mediatype;
$avatar->filename = $filename;
$avatar->url = Avatar::url($filename);
$avatar->created = common_sql_now();
try {
$id = $avatar->insert();
} catch (Exception $e) {
common_log(LOG_WARNING, $this->name() . ' Couldn\'t insert avatar - ' . $e->getMessage());
}
if (empty($id)) {
common_log_db_error($avatar, 'INSERT', __FILE__);
return null;
}
common_debug($this->name() . " - Saved new {$size} avatar for {$profile_id}.");
return $id;
}
示例2: array
function gravatar_save()
{
$cur = common_current_user();
if (empty($cur->email)) {
return array('message' => _m('You do not have an email address set in your profile.'), 'success' => false);
}
//Get rid of previous Avatar
$this->gravatar_remove();
foreach (array(AVATAR_PROFILE_SIZE, AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) {
$gravatar = new Avatar();
$gravatar->profile_id = $cur->id;
$gravatar->width = $size;
$gravatar->height = $size;
$gravatar->original = false;
//No file, so no original
$gravatar->mediatype = 'img';
//XXX: Unsure what to put here
//$gravatar->filename = null;//No filename. Remote
$gravatar->url = $this->gravatar_url($cur->email, $size);
$gravatar->created = DB_DataObject_Cast::dateTime();
# current time
if (!$gravatar->insert()) {
return array('message' => _m('Failed to save Gravatar to the database.'), 'success' => false);
}
}
return array('message' => _m('Gravatar added.'), 'success' => true);
}
示例3: setOriginal
function setOriginal($filename)
{
$imagefile = new ImageFile($this->id, Avatar::path($filename));
$avatar = new Avatar();
$avatar->profile_id = $this->id;
$avatar->width = $imagefile->width;
$avatar->height = $imagefile->height;
$avatar->mediatype = image_type_to_mime_type($imagefile->type);
$avatar->filename = $filename;
$avatar->original = true;
$avatar->url = Avatar::url($filename);
$avatar->created = DB_DataObject_Cast::dateTime();
# current time
# XXX: start a transaction here
if (!$this->delete_avatars() || !$avatar->insert()) {
@unlink(Avatar::path($filename));
return null;
}
foreach (array(AVATAR_PROFILE_SIZE, AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) {
# We don't do a scaled one if original is our scaled size
if (!($avatar->width == $size && $avatar->height == $size)) {
$scaled_filename = $imagefile->resize($size);
//$scaled = DB_DataObject::factory('avatar');
$scaled = new Avatar();
$scaled->profile_id = $this->id;
$scaled->width = $size;
$scaled->height = $size;
$scaled->original = false;
$scaled->mediatype = image_type_to_mime_type($imagefile->type);
$scaled->filename = $scaled_filename;
$scaled->url = Avatar::url($scaled_filename);
$scaled->created = DB_DataObject_Cast::dateTime();
# current time
if (!$scaled->insert()) {
return null;
}
}
}
return $avatar;
}
示例4: setOriginal
public function setOriginal($filename)
{
if ($this->isGroup()) {
// Until Group avatars are handled just like profile avatars.
return $this->getGroup()->setOriginal($filename);
}
$imagefile = new ImageFile(null, Avatar::path($filename));
$avatar = new Avatar();
$avatar->profile_id = $this->id;
$avatar->width = $imagefile->width;
$avatar->height = $imagefile->height;
$avatar->mediatype = image_type_to_mime_type($imagefile->type);
$avatar->filename = $filename;
$avatar->original = true;
$avatar->url = Avatar::url($filename);
$avatar->created = common_sql_now();
// XXX: start a transaction here
if (!Avatar::deleteFromProfile($this, true) || !$avatar->insert()) {
// If we can't delete the old avatars, let's abort right here.
@unlink(Avatar::path($filename));
return null;
}
return $avatar;
}
示例5: newAvatar
protected function newAvatar(Profile $profile, $url, $filename, $mediatype)
{
// Clear out old avatars, won't do anything if there are none
Avatar::deleteFromProfile($profile);
// throws exception if unable to fetch
$this->fetchRemoteUrl($url, Avatar::path($filename));
$avatar = new Avatar();
$avatar->profile_id = $profile->id;
$avatar->original = 1;
// this is an original/"uploaded" avatar
$avatar->mediatype = $mediatype;
$avatar->filename = $filename;
$avatar->width = $this->avatarsize;
$avatar->height = $this->avatarsize;
$avatar->created = common_sql_now();
$id = $avatar->insert();
if (empty($id)) {
common_log(LOG_WARNING, __METHOD__ . " Couldn't insert avatar - " . $e->getMessage());
common_log_db_error($avatar, 'INSERT', __FILE__);
throw new ServerException('Could not insert avatar');
}
common_debug(__METHOD__ . " - Saved new avatar for {$profile->id}.");
return $avatar;
}
示例6: creationavatarAction
function creationavatarAction()
{
$this->view->title = "Créer votre avatar";
$this->view->action = "creationavatar";
$this->user = Zend_Auth::getInstance()->getIdentity();
$avatar = new Avatar();
$classe = new Classe();
$ville = new Ville();
$ava = array();
$erreurs = array();
$this->view->classe = $classe->fetchAll();
$this->view->ville = $ville->fetchAll();
if ($this->_request->isPost()) {
Zend_Loader::loadClass('Zend_Filter_StripTags');
$filter = new Zend_Filter_StripTags();
$ava['avatarpseudo'] = trim($filter->filter($this->_request->getPost('avatarpseudo')));
$ava['classe'] = trim($filter->filter($this->_request->getPost('classe')));
$ava['ville'] = trim($filter->filter($this->_request->getPost('ville')));
if (!preg_match('`^[[:alnum:]]{3,20}$`', $ava['avatarpseudo'])) {
$erreurs['avatarpseudo'] = '<span class="erreur">Nom incorrect.</span>';
}
if ($avatar->findByNom($ava['avatarpseudo'])) {
$erreurs['avatarpseudo'] = '<span class="erreur">Veuillez choisir un nom différent.</span>';
}
if (empty($ava['classe'])) {
$erreurs['classe'] = '<span class="erreur">Vous devez choisir une classe.</span>';
}
if (empty($ava['ville'])) {
$erreurs['ville'] = '<span class="erreur">Vous devez choisir un village.</span>';
}
$ok = true;
foreach ($erreurs as $erreur) {
if ($erreur != "") {
$ok = false;
}
}
if ($ok) {
if (!empty($_FILES['fichier']['name'])) {
$max_size = 100000;
// Taille max en octets du fichier
$width_max = 100;
// Largeur max de l'image en pixels
$height_max = 100;
// Hauteur max de l'image en pixels
$nom_file = $_FILES['fichier']['name'];
$taille = $_FILES['fichier']['size'];
$tmp = $_FILES['fichier']['tmp_name'];
$extension = substr($nom_file, -4);
if ($extension == '.png') {
$infos_img = getimagesize($_FILES['fichier']['tmp_name']);
if ($infos_img[0] <= $width_max && $infos_img[1] <= $height_max && $_FILES['fichier']['size'] <= $max_size) {
$fichier_temp = $_FILES['fichier']['tmp_name'];
} else {
// Sinon on affiche une erreur pour les dimensions et taille de l'image
$erreurs["portrait"] = '<span class="erreur">Les dimensions et/ou la taille de l\'image dépassent nos limites exigées.</span>';
}
} else {
// Sinon on affiche une erreur pour l'extension
$erreurs["portrait"] = '<span class="erreur">Votre image doit être en .png .</span>';
}
} else {
$extension = ".png";
$fichier_default = $_SERVER['DOCUMENT_ROOT'] . '/Magic_TA/public/images/avatar/default_avatar.png';
}
if ($extension == '.png') {
$data = array('id_utilisateur' => $this->user->id_utilisateur, 'id_classe' => $ava['classe'], 'id_case' => $ville->findById($ava['ville'])->id_case, 'nom_avatar' => $ava['avatarpseudo']);
$target = $_SERVER['DOCUMENT_ROOT'] . '/Magic_TA/public/images/avatar/';
// Repertoire cible
$avatar->insert($data);
$avatar = $avatar->findByNom($ava['avatarpseudo']);
$idava = $avatar->id_avatar;
$fichier = $idava . $extension;
if (!empty($_FILES['fichier']['name'])) {
move_uploaded_file($fichier_temp, $target . $fichier);
} else {
copy($fichier_default, $target . $fichier);
}
}
$ok = true;
foreach ($erreurs as $erreur) {
if ($erreur != "") {
$ok = false;
}
}
if ($ok) {
$this->_redirect('avatar/avatar');
return;
}
}
$this->view->avatar = $ava;
$this->view->erreurs = $erreurs;
}
}
示例7: newAvatar
function newAvatar($profile_id, $size, $mediatype, $filename)
{
global $config;
$avatar = new Avatar();
$avatar->profile_id = $profile_id;
switch ($size) {
case 'mini':
$avatar->width = 24;
$avatar->height = 24;
break;
case 'normal':
$avatar->width = 48;
$avatar->height = 48;
break;
default:
// Note: Twitter's big avatars are a different size than
// Laconica's (Laconica's = 96)
$avatar->width = 73;
$avatar->height = 73;
}
$avatar->original = 0;
// we don't have the original
$avatar->mediatype = $mediatype;
$avatar->filename = $filename;
$avatar->url = Avatar::url($filename);
if (defined('SCRIPT_DEBUG')) {
common_debug("new filename: {$avatar->url}");
}
$avatar->created = common_sql_now();
$id = $avatar->insert();
if (empty($id)) {
common_log_db_error($avatar, 'INSERT', __FILE__);
return null;
}
if (defined('SCRIPT_DEBUG')) {
common_debug("Saved new {$size} avatar for {$profile_id}.");
}
return $id;
}