public function index($id, $width = 200, $height = 200, $crop = false) { if ($image = Model\Image::get($id)) { $image->display($width, $height, $crop); } else { throw new Error(Error::NOT_FOUND); } }
public static function process($action = 'list', $id = null) { $node = isset($_SESSION['admin_node']) ? $_SESSION['admin_node'] : \GOTEO_NODE; $model = 'Goteo\\Model\\Sponsor'; $url = '/admin/sponsors'; $errors = array(); switch ($action) { case 'add': return new View('view/admin/index.html.php', array('folder' => 'base', 'file' => 'edit', 'data' => (object) array('order' => $model::next($node), 'node' => $node), 'form' => array('action' => "{$url}/edit/", 'submit' => array('name' => 'update', 'label' => Text::_('Añadir')), 'fields' => array('id' => array('label' => '', 'name' => 'id', 'type' => 'hidden'), 'node' => array('label' => '', 'name' => 'node', 'type' => 'hidden'), 'name' => array('label' => Text::_('Patrocinador'), 'name' => 'name', 'type' => 'text'), 'url' => array('label' => Text::_('Enlace'), 'name' => 'url', 'type' => 'text', 'properties' => 'size=100'), 'image' => array('label' => Text::_('Logo'), 'name' => 'image', 'type' => 'image'), 'order' => array('label' => Text::_('Posición'), 'name' => 'order', 'type' => 'text'))))); break; case 'edit': // gestionar post if ($_SERVER['REQUEST_METHOD'] == 'POST') { // instancia $item = new $model(array('id' => $_POST['id'], 'name' => $_POST['name'], 'node' => $_POST['node'], 'image' => $_POST['image'], 'url' => $_POST['url'], 'order' => $_POST['order'])); // tratar si quitan la imagen $current = $_POST['image']; // la actual if (isset($_POST['image-' . $current . '-remove'])) { $image = Model\Image::get($current); $image->remove('sponsor'); $item->image = ''; $removed = true; } // tratar la imagen y ponerla en la propiedad image if (!empty($_FILES['image']['name'])) { $item->image = $_FILES['image']; } if ($item->save($errors)) { Message::Info(Text::_('Datos grabados correctamente')); throw new Redirection($url); } else { Message::Error(Text::_('No se ha grabado correctamente. ') . implode(', ', $errors)); } } else { $item = $model::get($id); } return new View('view/admin/index.html.php', array('folder' => 'base', 'file' => 'edit', 'data' => $item, 'form' => array('action' => "{$url}/edit/{$id}", 'submit' => array('name' => 'update', 'label' => Text::get('regular-save')), 'fields' => array('id' => array('label' => '', 'name' => 'id', 'type' => 'hidden'), 'node' => array('label' => '', 'name' => 'node', 'type' => 'hidden'), 'name' => array('label' => Text::_('Patrocinador'), 'name' => 'name', 'type' => 'text'), 'url' => array('label' => Text::_('Enlace'), 'name' => 'url', 'type' => 'text', 'properties' => 'size=100'), 'image' => array('label' => Text::_('Logo'), 'name' => 'image', 'type' => 'image'), 'order' => array('label' => Text::_('Posición'), 'name' => 'order', 'type' => 'text'))))); break; case 'up': $model::up($id, $node); throw new Redirection($url); break; case 'down': $model::down($id, $node); throw new Redirection($url); break; case 'remove': if ($model::delete($id)) { Message::Info(Text::_('Se ha eliminado el registro')); throw new Redirection($url); } else { Message::Info(Text::_('No se ha podido eliminar el registro')); } break; } return new View('view/admin/index.html.php', array('folder' => 'base', 'file' => 'list', 'addbutton' => Text::_('Nuevo patrocinador'), 'data' => $model::getAll($node), 'columns' => array('edit' => '', 'name' => Text::_('Patrocinador'), 'url' => Text::_('Enlace'), 'image' => Text::_('Imagen'), 'order' => Text::_('Posición'), 'up' => '', 'down' => '', 'remove' => ''), 'url' => "{$url}")); }
public static function getList() { $list = array(); $sql = static::query("\n SELECT\n id,\n name,\n url,\n image\n FROM sponsor\n ORDER BY `order` ASC, name ASC\n "); foreach ($sql->fetchAll(\PDO::FETCH_CLASS, __CLASS__) as $sponsor) { // imagen if (!empty($sponsor->image)) { $sponsor->image = Image::get($sponsor->image); } $list[] = $sponsor; } return $list; }
public static function getAll($activeonly = false, $node = \GOTEO_NODE) { // estados $status = Project::status(); $banners = array(); $sqlFilter = $activeonly ? " AND banner.active = 1" : ''; $query = static::query("\n SELECT\n banner.id as id,\n banner.node as node,\n banner.project as project,\n project.name as name,\n IFNULL(banner_lang.title, banner.title) as title,\n IFNULL(banner_lang.description, banner.description) as description,\n banner.url as url,\n project.status as status,\n banner.image as image,\n banner.order as `order`,\n banner.active as `active`\n FROM banner\n LEFT JOIN project\n ON project.id = banner.project\n LEFT JOIN banner_lang\n ON banner_lang.id = banner.id\n AND banner_lang.lang = :lang\n WHERE banner.node = :node\n {$sqlFilter}\n ORDER BY `order` ASC\n ", array(':node' => $node, ':lang' => \LANG)); foreach ($query->fetchAll(\PDO::FETCH_CLASS, __CLASS__) as $banner) { $banner->image = !empty($banner->image) ? Image::get($banner->image) : null; $banner->status = $status[$banner->status]; $banners[] = $banner; } return $banners; }
* along with Goteo. If not, see <http://www.gnu.org/licenses/agpl.txt>. * */ use Goteo\Library\Text, Goteo\Model; // aviso para el usuario, puede ser start->hola , ok->gracias o fail->lo sentimos $user = $this['user']; if (!$user instanceof Model\User) { $name = ''; $avatarhtml = ''; } else { $name = $user->name . "さん"; $avatar = ($user->avatar instanceof Model\Image) ? $user->avatar : Model\Image::get(1); $avatarhtml = '<img src="'.$avatar->getLink(50, 50, true).'" />'; } switch ($this['message']) { case 'start': $title = Text::get('regular-hello') . " $name"; // $message = Text::get('project-invest-start'); break; case 'login': $title = Text::get('regular-hello') . " $name"; // $message = Text::get('project-invest-login'); break; case 'confirm': $title = Text::get('regular-hello') . " $name"; // $message = Text::get('project-invest-confirm');
public static function investors($project, $projNum = false, $showall = false) { $worth = array(); $investors = array(); $sql = "\n SELECT\n invest.user as user,\n user.name as name,\n user.avatar as avatar,\n user.worth as worth,\n invest.amount as amount,\n DATE_FORMAT(invest.invested, '%d/%m/%Y') as date,\n "; $sql .= "user.hide as hide,\n invest.anonymous as anonymous\n FROM invest\n INNER JOIN user\n ON user.id = invest.user\n WHERE project = ?\n AND invest.status IN ('0', '1', '3', '4')\n ORDER BY invest.invested DESC, invest.id DESC\n "; $query = self::query($sql, array($project)); foreach ($query->fetchAll(\PDO::FETCH_OBJ) as $investor) { $investor->avatar = Image::get($investor->avatar); if (empty($investor->avatar->id) || !$investor->avatar instanceof Image) { $investor->avatar = Image::get(1); } // si el usuario es hide o el aporte es anonymo, lo ponemos como el usuario anonymous (avatar 1) if (!$showall && ($investor->hide == 1 || $investor->anonymous == 1)) { // mantenemos la fecha del anonimo mas reciente $anonymous_date = empty($investors['anonymous']->date) ? $investor->date : $investors['anonymous']->date; $investors[] = (object) array('user' => 'anonymous', 'name' => Text::get('regular-anonymous'), 'projects' => null, 'avatar' => Image::get(1), 'worth' => $investor->worth, 'amount' => $investor->amount, 'date' => $investor->date); } else { if (!isset($worth[$investor->user])) { $worth[$investor->user] = \Goteo\Model\User::calcWorth($investor->user); } $investors[] = (object) array('user' => $investor->user, 'name' => $investor->name, 'projects' => $investor->projects, 'avatar' => $investor->avatar, 'worth' => $worth[$investor->user], 'amount' => $investor->amount, 'date' => $investor->date); } } return $investors; }
public static function getMini($id) { try { $query = static::query("\r\n SELECT\r\n id,\r\n name,\r\n avatar,\r\n email,\r\n IFNULL(lang, 'es') as lang\r\n FROM user\r\n WHERE id = :id\r\n ", array(':id' => $id)); $user = $query->fetchObject(); // stdClass para qno grabar accidentalmente y machacar todo $user->avatar = Image::get($user->avatar); if (empty($user->avatar->id) || !$user->avatar instanceof Image) { $user->avatar = Image::get(1); } return $user; } catch (\PDOException $e) { return false; } }
public static function share($user, $category = null, $limit = null) { $array = array(); try { $values = array(':me' => $user); $sql = "SELECT \n DISTINCT(user_interest.user) as id, \n user.name as name,\n user.avatar as avatar\n FROM user_interest\n INNER JOIN user_interest as mine\n ON user_interest.interest = mine.interest\n AND mine.user = :me\n INNER JOIN user\n ON user.id = user_interest.user\n AND (user.hide = 0 OR user.hide IS NULL)\n WHERE user_interest.user != :me\n "; if (!empty($category)) { $sql .= "AND user_interest.interest = :interest\n "; $values[':interest'] = $category; } $sql .= " ORDER BY RAND()"; if (!empty($limit)) { $sql .= " LIMIT {$limit}"; } $query = static::query($sql, $values); $shares = $query->fetchAll(\PDO::FETCH_ASSOC); foreach ($shares as $share) { // nombre i avatar vienen en la sentencia, hay que sacar la imagen $share['user'] = $share['id']; $queryI = static::query("SELECT COUNT(DISTINCT(project)) FROM invest WHERE user = ? AND status IN ('0', '1', '3')", array($share['id'])); $share['invests'] = $queryI->fetchColumn(0); $queryP = static::query('SELECT COUNT(id) FROM project WHERE owner = ? AND status > 2', array($share['id'])); $share['projects'] = $queryP->fetchColumn(0); $share['avatar'] = empty($share['avatar']) ? Image::get(1) : Image::get($share['avatar']); if (!$share['avatar'] instanceof Image) { $share['avatar'] = Image::get(1); } $array[] = (object) $share; } return $array; } catch (\PDOException $e) { throw new \Goteo\Core\Exception($e->getMessage()); } }
/** * Retorna les imatges i contingut en html * * $num_icons: el numero de icones per fila del widget * */ public function html_content($num_icons = 19) { $URL = NODE_ID != GOTEO_NODE ? NODE_URL : SITE_URL; $ret = array(); foreach ($this->avatars as $user => $mult) { $style = ''; $w = $this->w_size; $h = $this->h_size; $src = $URL . '/image/2/' . "{$w}/{$h}"; if ($this->investors[$user]->avatar instanceof \Goteo\Model\Image) { if ($this->investors[$user]->avatar->id == 1) { $noface = \Goteo\Model\Image::get(2); $src = $noface->getLink($w, $h, true); } else { $src = $this->investors[$user]->avatar->getLink($w, $h, true); } } $img = '<a href="' . $URL . '/user/profile/' . $user . '"><img' . $style . ' src="' . $src . '" alt="' . $this->investors[$user]->name . '" title="' . $this->investors[$user]->name . '" /></a>'; for ($i = 0; $i < $mult + 1; $i++) { $ret[] = $img; $total = count($ret); //cas que es posicioni a partir de la segona columna if ($num_icons > 14) { //final de 1a fila, 2a columna if (in_array($total, array($num_icons + 1, $num_icons * 2 - 12, $num_icons * 3 - 25))) { $ret[] = '<div class="c"></div>'; } if (in_array($total, array($num_icons * 5 - 38, $num_icons * 6 - 49, $num_icons * 7 - 60))) { $ret[] = '<div class="a"></div>'; } if (in_array($total, array($num_icons * 5 - 36, $num_icons * 6 - 47, $num_icons * 7 - 58))) { $ret[] = '<div class="b"></div>'; } if (in_array($total, array($num_icons * 9 - 71, $num_icons * 10 - 84))) { $ret[] = '<div class="d"></div>'; } } else { if ($total == $num_icons) { $ret[] = '<div class="c"></div><div class="c"></div><div class="c"></div>'; } if ($total == $num_icons * 2 + 1) { $ret[] = '<div class="a"></div>'; } if (in_array($total, array($num_icons * 2 + 3, $num_icons * 2 + 5))) { $ret[] = '<div class="b"></div><div class="a"></div>'; } if ($total == $num_icons * 2 + 7) { $ret[] = '<div class="b"></div>'; } if ($total == $num_icons * 3 + 8) { $ret[] = '<div class="d"></div><div class="d"></div>'; } } } } return $ret; /* //afegim el logo al final de tot $final = array(); $total = count($ret); $cols = floor(($total + 3*14 + 3*13 + 2*14)/$num_icons); if($num_icons > 14) { foreach($ret as $i => $v) { if(in_array($i, array($num_icons*($cols-1) - 103,$num_icons*$cols - 107))) { $final[] = '<div class="e"></div>'; } $final[] = $v; } } else { foreach($ret as $i => $v) { if(in_array($i, array($num_icons*($cols-2) - 94,$num_icons*($cols-1) - 98))) { //if(in_array($i, array($num_icons*($cols-2) - 94))) { $final[] = '<div class="e"></div>'; } $final[] = $v; } } return $final; */ }
public static function getGallery($id) { $gallery = array(); try { $sql = "SELECT image FROM project_image WHERE project = ? AND (section = '' OR section IS NULL) ORDER BY `order` ASC, image DESC"; $query = self::query($sql, array($id)); foreach ($query->fetchAll(\PDO::FETCH_ASSOC) as $image) { $gallery[] = Model\Image::get($image['image']); } return $gallery; } catch (\PDOException $e) { return false; } }