<?php

/* ====================
[BEGIN_COT_EXT]
Hooks=usertags.main
[END_COT_EXT]
==================== */
/**
 * Avatar and photo for users
 *
 * @package UserImages
 * @copyright (c) Cotonti Team
 * @license https://github.com/Cotonti/Cotonti/blob/master/License.txt
 */
defined('COT_CODE') or die('Wrong URL');
require_once cot_incfile('userimages', 'plug');
require_once cot_incfile('userimages', 'plug', 'resources');
if (is_array($user_data)) {
    $userimages = cot_userimages_config_get();
    foreach ($userimages as $code => $settings) {
        $uimage = $user_data['user_' . $code];
        $temp_array[strtoupper($code) . '_SRC'] = $uimage;
        $temp_array[strtoupper($code)] = is_file($uimage) ? cot_userimages_build($user_data['user_' . $code], $code) : '';
    }
}
Ejemplo n.º 2
0
/* ====================
[BEGIN_COT_EXT]
Hooks=ajax
[END_COT_EXT]
==================== */
/**
 * Avatar and photo for users
 *
 * @package UserImages
 * @copyright (c) Cotonti Team
 * @license https://github.com/Cotonti/Cotonti/blob/master/License.txt
 */
defined('COT_CODE') or die('Wrong URL');
require_once cot_incfile('userimages', 'plug');
switch ($a) {
    case 'delete':
        cot_check_xg();
        $code = strtolower(cot_import('code', 'G', 'ALP'));
        if (in_array($code, array_keys(cot_userimages_config_get()))) {
            $sql = $db->query("SELECT user_" . $db->prep($code) . " FROM {$db_users} WHERE user_id=" . $usr['id']);
            if ($filepath = $sql->fetchColumn()) {
                if (file_exists($filepath)) {
                    unlink($filepath);
                }
                $sql = $db->update($db_users, array('user_' . $db->prep($code) => ''), "user_id=" . $usr['id']);
            }
        }
        break;
}
cot_redirect(cot_url('users', "m=profile", '', true));
Ejemplo n.º 3
0
if ($a == 'edit') {
    $code = cot_import('code', 'G', 'ALP');
    $width = cot_import('userimg_width', 'P', 'INT');
    $height = cot_import('userimg_height', 'P', 'INT');
    $crop = cot_import('userimg_crop', 'P', 'TXT');
    if (!cot_userimages_config_edit($code, $width, $height, $crop)) {
        cot_error('userimages_emptycode', 'code');
    }
    cot_redirect(cot_url('admin', 'm=other&p=userimages', '', true));
}
if ($a == 'remove') {
    $code = cot_import('code', 'G', 'ALP');
    if (!cot_userimages_config_remove($code)) {
        cot_error('userimages_emptycode');
    }
    cot_redirect(cot_url('admin', 'm=other&p=userimages', '', true));
}
$userimg = cot_userimages_config_get(true);
foreach ($userimg as $code => $settings) {
    $tt->assign(array('CODE' => $code, 'WIDTH' => $settings['width'], 'HEIGHT' => $settings['height'], 'CROP' => $settings['crop'], 'EDIT_URL' => cot_url('admin', 'm=other&p=userimages&a=edit&code=' . $code), 'REMOVE' => cot_rc('userimg_remove', array('url' => cot_url('admin', 'm=other&p=userimages&a=remove&code=' . $code)))));
    $tt->parse('MAIN.USERIMG_LIST');
}
cot_display_messages($tt);
// use cot_message()
/* === Hook  === */
foreach (cot_getextplugins('userimages.admin.tags') as $pl) {
    include $pl;
}
/* ===== */
$tt->parse('MAIN');
$plugin_body = $tt->text('MAIN');
Ejemplo n.º 4
0
/**
 * Process uploaded user images files for certain User
 *
 * @param number $uid User ID for uploads to be attached
 * @return boolean|number Number of uploaded images or false for incorrect $uid
 */
function cot_userimages_process_uploads($uid = null)
{
    global $cfg, $usr, $m;
    $files = 0;
    if ($_FILES) {
        if (is_null($uid) || empty($uid)) {
            $uid = $usr['id'];
        }
        if (!is_numeric($uid) || $uid != (int) $uid || $uid < 1) {
            return false;
        }
        if ($uid != $usr['id'] || $m == 'edit') {
            list($usr['auth_read'], $usr['auth_write'], $usr['isadmin']) = cot_auth('users', 'a');
            if (!$usr['isadmin']) {
                return 0;
            }
            $usermode = true;
        }
        @clearstatcache();
        $userimages = cot_userimages_config_get();
        foreach ($userimages as $code => $settings) {
            $file = $_FILES[$usermode ? $code . ':' . $uid : $code];
            if (!$file) {
                continue;
            }
            if (!empty($file['tmp_name']) && $file['size'] > 0 && is_uploaded_file($file['tmp_name'])) {
                $gd_supported = array('jpg', 'jpeg', 'png', 'gif');
                $var = explode(".", $file['name']);
                $file_ext = strtolower(array_pop($var));
                $fcheck = cot_file_check($file['tmp_name'], $file['name'], $file_ext);
                if (in_array($file_ext, $gd_supported) && $fcheck == 1) {
                    $file['name'] = cot_safename($file['name'], true);
                    $path = $code == 'avatar' ? $cfg['avatars_dir'] : $cfg['photos_dir'];
                    $filename_full = $uid . '-' . strtolower($code != 'avatar' ? $code . '-' . $file['name'] : $file['name']);
                    $filepath = $path . '/' . $filename_full;
                    if (file_exists($filepath)) {
                        unlink($filepath);
                    }
                    move_uploaded_file($file['tmp_name'], $filepath);
                    cot_imageresize($filepath, $filepath, $settings['width'], $settings['height'], $settings['crop'], '', 100);
                    @chmod($filepath, $cfg['file_perms']);
                    /* === Hook === */
                    foreach (cot_getextplugins('profile.update.' . $code) as $pl) {
                        include $pl;
                    }
                    /* ===== */
                    $sql = cot::$db->query("SELECT user_" . cot::$db->prep($code) . " FROM " . cot::$db->users . " WHERE user_id=" . $uid);
                    if ($oldimage = $sql->fetchColumn()) {
                        if (file_exists($oldimage)) {
                            unlink($oldimage);
                        }
                    }
                    $sql = cot::$db->update(cot::$db->users, array("user_" . $code => $filepath), "user_id='" . $uid . "'");
                    $files++;
                } elseif ($fcheck == 2) {
                    cot_error(sprintf($L['pfs_filemimemissing'], $file_ext), $code);
                } else {
                    cot_error(sprintf($L['userimages_' . $code . 'notvalid'], $file_ext), $code);
                }
            }
        }
    }
    return $files;
}