/** * Return the URL with the avatar from the User * * @param integer $size * @return string */ public function getAvatar($size = self::AVATAR_SIZE_DEFAULT) { $avatar = $this->getImage(self::KEY_AVATAR, $size, $size); if (empty($avatar)) { return Utils::getUrlAvatarDefault($size); } return $avatar; }
/** * @param Form $form * @param $values */ function projectFormSucceeded(Form $form, $values) { $new_project = $this->projectManager->add($values->name, $values->description, $this->user->id); foreach (Utils::safeExplodeByComma($values->tags) as $tag) { try { $project_tag = $this->database->table('tags')->insert(array('tag' => $tag)); $tag_id = $project_tag->id; } catch (UniqueConstraintViolationException $e) { $tag_id = $this->database->table('tags')->where('tag', $tag)->fetch()->id; } $this->database->table('projects_tags')->insert(array('projects_id' => $new_project->id, 'tags_id' => $tag_id)); } $this->flashMessage("Project {$values->name} has been successfully created!", 'success'); }
/** * * @param unknown $key * @param unknown $params * @param unknown $forceLang */ public static function substr($key, $params = [], $forceLang = false) { list($string, $len) = explode(' ', $key); Utils::debug("{$string}, {$len}"); if ($len) { return substr($string, 0, $len); } else { return $string; } }
/** * Devuelve el src del thumbnail del post * * @param string $size * size */ public function getThumbnail($size = self::IMG_SIZE_THUMBNAIL) { /* * Define a func for to get the attachment-src from the post_id */ $getSrc = function ($_id) use($size) { $imageObject = wp_get_attachment_image_src(get_post_thumbnail_id($_id), $size); if (empty($imageObject)) { return false; } return $imageObject[0]; }; if ($imageObject = $getSrc($this->ID)) { return $imageObject; } else { // if they aren't, we get the first img from the post, and let it as thumbnail preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $this->post_content, $matches); $src = $matches[1]; $attachmentId = Utils::getAttachmentIdFromUrl($src); // try to set the first img as thumbnail // Intento establecer como thumbnail la primera img encontrada al post set_post_thumbnail($this->ID, $attachmentId); // En caso de encontrarla la devolvemos, en caso contrario devolvemos el src if ($imageObject = $getSrc($this->ID)) { return $imageObject; } return $src; } }