File indexing completed on 2024-12-22 05:33:27
0001 <?php 0002 0003 /** 0004 * ocs-webserver 0005 * 0006 * Copyright 2016 by pling GmbH. 0007 * 0008 * This file is part of ocs-webserver. 0009 * 0010 * This program is free software: you can redistribute it and/or modify 0011 * it under the terms of the GNU Affero General Public License as 0012 * published by the Free Software Foundation, either version 3 of the 0013 * License, or (at your option) any later version. 0014 * 0015 * This program is distributed in the hope that it will be useful, 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0018 * GNU Affero General Public License for more details. 0019 * 0020 * You should have received a copy of the GNU Affero General Public License 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0022 * 0023 * https://github.com/yohang88/letter-avatar 0024 * 0025 * */ 0026 0027 use YoHang88\LetterAvatar\LetterAvatar; 0028 class Backend_MemberLetterAvatarCliController extends Local_Controller_Action_CliAbstract 0029 { 0030 0031 /** 0032 * run the following composer to download libs put in /library/ 0033 * composer require yohang88/letter-avatar 0034 * Run php code 0035 * I.e.: 0036 * /usr/bin/php /var/www/ocs-webserver/scripts/cron.php -a /backend/member-letter-avatar-cli/run/action 0037 * ubuntu@ip-10-171-104-73:/var/www/pling.it/pling$ sudo -u www-data php /var/www/pling.it/pling/scripts/cron.php -a /backend/member-letter-avatar-cli/run/action 0038 * @see Local_Controller_Action_CliInterface::runAction() 0039 */ 0040 public function runAction() 0041 { 0042 require_once 'vendor/autoload.php'; 0043 echo "Start runAction\n"; 0044 $sql = ' 0045 select member_id,username 0046 from tmp_member_hive_nopic m 0047 '; 0048 // $sql = ' 0049 // select member_id,username from tmp_member_avatar_unknow where is_auto_generated = 1 0050 // '; 0051 // $sql = ' 0052 // select member_id,username from tmp_member_avatar_unknow where member_id in (512473,512808) 0053 // '; 0054 $result = Zend_Db_Table::getDefaultAdapter()->query($sql)->fetchAll(); 0055 foreach ($result as $m) { 0056 $name = substr($m['username'],0,1).' '.substr($m['username'],1); // hive nopic user has two chars 0057 // $name = $m['username'].' '; 0058 $avatar = new LetterAvatar($name,'square', 400); 0059 $tmpImagePath = IMAGES_UPLOAD_PATH . 'tmp/la/'.$m['member_id'].'.png'; 0060 $avatar->saveAs($tmpImagePath, LetterAvatar::MIME_TYPE_PNG); 0061 0062 // $sql = 'update tmp_member_hive_nopic set avatar = 1 where member_id = '.$m['member_id']; 0063 // Zend_Db_Table::getDefaultAdapter()->query($sql); 0064 // echo $m['member_id']."\n"; 0065 } 0066 echo 'done!'; 0067 } 0068 0069 0070 public function runupdateAction() 0071 { 0072 0073 echo "Start runupdateAction\n"; 0074 // $sql = "select * from tmp_member_avatar_unknow where width >0 and filetype is null"; 0075 $sql = ' 0076 select * from tmp_member_avatar_unknow where width=0 0077 '; 0078 $result = Zend_Db_Table::getDefaultAdapter()->query($sql)->fetchAll(); 0079 foreach ($result as $m) { 0080 //$file = 'https://cn.pling.it/img/'.$m['avatar']; // cc 0081 $file = 'https://cn.opendesktop.org/img/'.$m['avatar']; //live 0082 0083 // echo "\n"; 0084 try { 0085 list($width, $height, $type) = getimagesize($file); 0086 $sql = 'update tmp_member_avatar_unknow set width='.$width.', height='.$height.', filetype='.$type.' where member_id = '.$m['member_id']; 0087 Zend_Db_Table::getDefaultAdapter()->query($sql); 0088 0089 } 0090 catch (Exception $e) { 0091 $sql = 'update tmp_member_avatar_unknow set width=-1 where member_id = '.$m['member_id']; 0092 Zend_Db_Table::getDefaultAdapter()->query($sql); 0093 } 0094 } 0095 echo 'done!'; 0096 } 0097 0098 }