public function execute($par) { // Shortcut by using $par if ($par) { $this->getOutput()->redirect($this->getTitle()->getLinkURL(array('user' => $par))); return; } $this->setHeaders(); $this->outputHeader(); // Parse options $opt = new \FormOptions(); $opt->add('user', ''); $opt->add('delete', ''); $opt->add('reason', ''); $opt->fetchValuesFromRequest($this->getRequest()); // Parse user $user = $opt->getValue('user'); $userObj = \User::newFromName($user); $userExists = $userObj && $userObj->getId() !== 0; // If current task is delete and user is not allowed $canDoAdmin = $this->getUser()->isAllowed('avataradmin'); if ($opt->getValue('delete')) { if (!$canDoAdmin) { throw new \PermissionsError('avataradmin'); } // Delete avatar if the user exists if ($userExists) { if (Avatars::deleteAvatar($userObj)) { global $wgAvatarLogInRC; $logEntry = new \ManualLogEntry('avatar', 'delete'); $logEntry->setPerformer($this->getUser()); $logEntry->setTarget($userObj->getUserPage()); $logEntry->setComment($opt->getValue('reason')); $logId = $logEntry->insert(); $logEntry->publish($logId, $wgAvatarLogInRC ? 'rcandudp' : 'udp'); } } } $this->getOutput()->addModules(array('mediawiki.userSuggest')); $this->showForm($user); if ($userExists) { $haveAvatar = Avatars::hasAvatar($userObj); if ($haveAvatar) { $html = \Xml::tags('img', array('src' => Avatars::getLinkFor($user, 'original') . '&nocache&ver=' . dechex(time()), 'height' => 400), ''); $html = \Xml::tags('p', array(), $html); $this->getOutput()->addHTML($html); // Add a delete button if ($canDoAdmin) { $this->showDeleteForm($user); } } else { $this->getOutput()->addWikiMsg('viewavatar-noavatar'); } } else { if ($user) { $this->getOutput()->addWikiMsg('viewavatar-nouser'); } } }
public function loadModel($id) { //$model=Avatars::model()->findByPk($id); $model = Avatars::model()->find('usersid=:usersid', array(':usersid' => Yii::app()->user->id)); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
private function processUpload() { $request = $this->getRequest(); $dataurl = $request->getVal('avatar'); if (!$dataurl || parse_url($dataurl, PHP_URL_SCHEME) !== 'data') { $this->displayMessage($this->msg('avatar-notuploaded')); return false; } $img = Thumbnail::open($dataurl); global $wgMaxAvatarResolution; switch ($img->type) { case IMAGETYPE_GIF: case IMAGETYPE_PNG: case IMAGETYPE_JPEG: break; default: $this->displayMessage($this->msg('avatar-invalid')); return false; } // Must be square if ($img->width !== $img->height) { $this->displayMessage($this->msg('avatar-notsquare')); return false; } // Check if image is too small if ($img->width < 32 || $img->height < 32) { $this->displayMessage($this->msg('avatar-toosmall')); return false; } // Check if image is too big if ($img->width > $wgMaxAvatarResolution || $img->height > $wgMaxAvatarResolution) { $this->displayMessage($this->msg('avatar-toolarge')); return false; } $user = $this->getUser(); Avatars::deleteAvatar($user); // Avatar directories global $wgAvatarUploadDirectory; $uploadDir = $wgAvatarUploadDirectory . '/' . $this->getUser()->getId() . '/'; @mkdir($uploadDir, 0777, true); // We do this to convert format to png $img->createThumbnail($wgMaxAvatarResolution, $uploadDir . 'original.png'); // We only create thumbnail with default resolution here. Others are generated on demand global $wgDefaultAvatarRes; $img->createThumbnail($wgDefaultAvatarRes, $uploadDir . $wgDefaultAvatarRes . '.png'); $img->cleanup(); $this->displayMessage($this->msg('avatar-saved')); global $wgAvatarLogInRC; $logEntry = new \ManualLogEntry('avatar', 'upload'); $logEntry->setPerformer($this->getUser()); $logEntry->setTarget($this->getUser()->getUserPage()); $logId = $logEntry->insert(); $logEntry->publish($logId, $wgAvatarLogInRC ? 'rcandudp' : 'udp'); return true; }
public function execute($par) { global $wgDefaultAvatar, $wgDefaultAvatarRes; $path = $wgDefaultAvatar; if ($par) { // Parse parts $parts = explode('/', $par, 2); $username = $parts[0]; $res = count($parts) === 2 ? Avatars::normalizeResolution($parts[1]) : $wgDefaultAvatarRes; $user = \User::newFromName($username); $path = Avatars::getAvatar($user, $res); } $this->getOutput()->disable(); $response = $this->getRequest()->response(); // We use send custom header, in order to control cache $response->statusHeader('302'); $response->header('Content-Type: text/html; charset=utf-8'); $response->header('Cache-Control: public, max-age=86400'); // $response->header('Cache-Control: no-cache'); $response->header('Location: ' . $path); }
public function __construct(AvatarsAvatar $obj) { $xoops = Xoops::getInstance(); $helper = Avatars::getInstance(); // Get avatar handler $avatar_handler = $helper->getHandlerAvatar(); $action = $_SERVER['REQUEST_URI']; parent::__construct(AvatarsLocale::USERFORM, 'avatar_user_form', $action, "post", true); $this->setExtra('enctype="multipart/form-data"'); // select and uploads $avatar_select = new Xoops\Form\Select('', 'user_avatar', $xoops->user->getVar('user_avatar')); $avatar_list = $avatar_handler->getListByType('S', true); $avatar_selected = $xoops->user->getVar("user_avatar", "E"); $avatar_selected = in_array($avatar_selected, array_keys($avatar_list)) ? $avatar_selected : "blank.gif"; $avatar_select->addOptionArray($avatar_list); $xoops_url = \XoopsBaseConfig::get('url'); $xoops_upload_url = \XoopsBaseConfig::get('uploads-url'); $avatar_select->setExtra("onchange='showImgSelected(\"avatar\", \"user_avatar\", \"uploads\", \"\", \"" . $xoops_url . "\")'"); $avatar_tray = new Xoops\Form\ElementTray(XoopsLocale::FILE, ' '); $avatar_tray->addElement($avatar_select); $avatar_tray->addElement(new Xoops\Form\Label('', "<a href=\"javascript:openWithSelfMain('" . $xoops_url . "/modules/avatars/popup.php','avatars',600,400);\">" . XoopsLocale::LIST_ . "</a><br />")); $avatar_tray->addElement(new Xoops\Form\Label('', "<br /><img src='" . $xoops_upload_url . "/" . $avatar_selected . "' name='avatar' id='avatar' alt='' />")); if ($helper->getConfig('avatars_allowupload') == 1 && $xoops->user->getVar('posts') >= $helper->getConfig('avatars_postsrequired')) { $fileseltray_img = new Xoops\Form\ElementTray('<br />', '<br /><br />'); $fileseltray_img->addElement(new Xoops\Form\File(XoopsLocale::A_UPLOAD, 'user_avatar'), false); $avatar_tray->addElement($fileseltray_img); } $this->addElement($avatar_tray); // Hidden $this->addElement(new Xoops\Form\Hidden('avatar_type', 'c')); $this->addElement(new Xoops\Form\Hidden('uid', $xoops->user->getVar('uid'))); $this->addElement(new Xoops\Form\Hidden('op', 'save')); $this->addElement(new Xoops\Form\Hidden('avatar_id', $obj->getVar('avatar_id', 'e'))); // Button $this->addElement(new Xoops\Form\Button('', 'submit', XoopsLocale::A_SUBMIT, 'submit')); }
*/ use Xoops\Core\Request; /** * avatars module * * @copyright XOOPS Project (http://xoops.org) * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) * @package avatar * @since 2.6.0 * @author Mage Grégory (AKA Mage) * @version $Id$ */ include __DIR__ . '/header.php'; // Get main instance $xoops = Xoops::getInstance(); $helper = Avatars::getInstance(); $xoops_upload_path = \XoopsBaseConfig::get('uploads-path'); $xoops_upload_url = \XoopsBaseConfig::get('uploads-url'); // Get avatar handler $avatar_Handler = $helper->getHandlerAvatar(); // Parameters $nb_avatars = $helper->getConfig('avatars_pager'); $mimetypes = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png'); $upload_size = $helper->getConfig('avatars_imagefilesize'); $width = $helper->getConfig('avatars_imagewidth'); $height = $helper->getConfig('avatars_imageheight'); // Get Action type $op = Request::getCmd('op', 'list'); // Call Header $xoops->header('admin:avatars/avatars_admin_custom.tpl'); $admin_page = new \Xoops\Module\Admin();
protected function afterSave() { parent::afterSave(); if ($this->isNewRecord) { $avatars = new Avatars(); $avatars->usersid = $this->id; $avatars->image = 'noimage.png'; $avatars->save(); } return parent::afterSave(); }
<?php /* @var $this AvatarsController */ /* @var $model Avatars */ $this->breadcrumbs = array('Avatars' => array('index'), 'Create'); $this->menu = array(array('label' => 'List Avatars', 'url' => array('index')), array('label' => 'Manage Avatars', 'url' => array('admin'))); ?> <h1>Create Avatars</h1> <?php $this->renderPartial('_form', array('model' => $model = Avatars::model()->find('usersid=:usersid', array(':usersid' => Yii::app()->user->id))));
public static function onGetPreferences(\User $user, &$preferences) { $link = \Linker::link(\SpecialPage::getTitleFor("UploadAvatar"), wfMsg('uploadavatar')); $preferences['editavatar'] = array('type' => 'info', 'raw' => true, 'label-message' => 'prefs-editavatar', 'default' => '<img src="' . Avatars::getLinkFor($user->getName()) . '" width="32"></img> ' . $link, 'section' => 'personal/info'); return true; }
<?php /* You may not change or alter any portion of this comment or credits of supporting developers from this source code or any supporting source code which is considered copyrighted (c) material of the original comment or credit authors. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ /** * avatars extension * * @copyright XOOPS Project (http://xoops.org) * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) * @package avatar * @since 2.6.0 * @author Mage Grégory (AKA Mage) * @version $Id$ */ include dirname(dirname(__DIR__)) . '/mainfile.php'; $xoops = Xoops::getInstance(); $xoops->disableErrorReporting(); $xoops->simpleHeader(false); $criteria = new Criteria('avatar_type', 'S'); $tpl = new XoopsTpl(); $tpl->assign('avatars', Avatars::getInstance()->getHandlerAvatar()->getObjects($criteria, false, false)); $tpl->assign('closebutton', 1); $tpl->display('module:avatars/avatars_popup.tpl'); $xoops->simpleFooter();