复制图片

@param string  $oldImg
@param string  $newImg
@param string  $subFolder
@param boolean $returnStatic

@return string
6612
public static function copyImg($oldImg, $newImg = '', $subFolder = '', $returnStatic = false)
    {
        if(substr($oldImg, 0, 4) != 'http'){
            $oldImgStatic = Folder::getStatic($oldImg);

            if(!$oldImg || !file_exists($oldImgStatic)){
                return $oldImg;
            }
        }else{
            $oldImgStatic = $oldImg;
        }

        if(!$newImg){
            $newImg = File::newFile(pathinfo($oldImgStatic, PATHINFO_EXTENSION), $subFolder);
        }

        $newImgStatic = Folder::getStatic($newImg);

        Folder::mkdir(pathinfo($newImgStatic, PATHINFO_DIRNAME));

        if(file_exists($newImgStatic)){
            File::delFile($newImg);
        }

        if(File::saveFile($newImgStatic, $oldImgStatic)){
            return $returnStatic ? $newImgStatic : $newImg;
        }

        return false;
    }
1107996
public function rename($oldPath, $newPath)
    {
        $old = $this->at($oldPath);
        $new = $this->at($newPath);

        if (null === $old || (null !== $new && 'dir' === $new->type))
            return false;

        if ('file' === $old->type) {
            $this->at($newPath, $old);
        } else {
            if (! $this->mkdir($newPath, $old->perms)) {
                return false;
            }
            $oldPath = $this->realpath($oldPath) . '/';
            $newPath = $this->realpath($newPath) . '/';
            $length = strlen($oldPath);
            foreach (array_keys($this->files) as $childPath) {
                if (substr($childPath, 0, $length) === $oldPath) {
                    $newChildPath = $newPath . substr($childPath, $length);
                    $this->at($newChildPath, $this->at($childPath));
                    $this->at($childPath, null);
                }
            }
        }
        $this->at($oldPath, null);
        return true;
    }
615797
public function actionMark($queue_name, $message_id = null, $subscriber_id = null, $returnUrl = null)
    {
        if (($subscriber_id = trim($subscriber_id)) === '') {
            $subscriber_id = null;
        }
        /** @var QueueInterface $queue */
        list($queue, $authItems) = $this->loadQueue($queue_name, ['nfy.message.read']);
        $this->verifySubscriber($queue, $subscriber_id);

        if ($authItems['nfy.message.read']) {
            if ($message_id === null) {
                $queue->receive($subscriber_id);
            } else {
                $queue->delete($message_id, $subscriber_id);
            }
        }
        return $this->redirect($returnUrl !== null ? $returnUrl : Yii::$app->user->returnUrl);
    }
777799
protected function diffCells($oldCell, $newCell, $usingExtraRow = false)
    {
        $diffCell = $this->getNewCellNode($oldCell, $newCell);

        $oldContent = $oldCell ? $this->getInnerHtml($oldCell->getDomNode()) : '';
        $newContent = $newCell ? $this->getInnerHtml($newCell->getDomNode()) : '';

        $htmlDiff = HtmlDiff::create(
            mb_convert_encoding($oldContent, 'UTF-8', 'HTML-ENTITIES'),
            mb_convert_encoding($newContent, 'UTF-8', 'HTML-ENTITIES'),
            $this->config
        );
        $diff = $htmlDiff->build();

        $this->setInnerHtml($diffCell, $diff);

        if (null === $newCell) {
            $diffCell->setAttribute('class', trim($diffCell->getAttribute('class').' del'));
        }

        if (null === $oldCell) {
            $diffCell->setAttribute('class', trim($diffCell->getAttribute('class').' ins'));
        }

        if ($usingExtraRow) {
            $diffCell->setAttribute('class', trim($diffCell->getAttribute('class').' extra-row'));
        }

        return $diffCell;
    }
1081411
static function defaultValue( $url, $returnDefault )
    {
        if ( $returnDefault )
        {
            $mime = eZMimeType::defaultMimeType();
            $mime['url'] = $url;
            $suffixPos = strpos( $url, '.' );

            if ( $suffixPos !== false )
            {
                $mime['suffix'] = substr( $url, $suffixPos + 1 );
                $mime['dirpath'] = dirname( $url );
                $mime['basename'] = basename( $url, '.' . $mime['suffix'] );
                $mime['filename'] = $mime['basename'] . '.' . $mime['suffix'];
            }
            else
            {
                $mime['basename'] = $url;
                $mime['suffix'] = false;
            }
            $mime['is_valid'] = false;
            return $mime;
        }
        else
            return false;
    }
338534
private static function generateReturnTypeCode(\ReflectionType $return_type) : string
    {
        if ($return_type->isBuiltin()){
            return $return_type;
        }
        $_ = explode('\\', $return_type);
        return array_pop($_);
    }
164991
static function findByURL( $url, $returnDefault = true )
    {
        $instance = eZMimeType::instance();

        $file = $url;
        $dirPosition = strrpos( $url, '/' );
        if ( $dirPosition !== false )
            $file = substr( $url, $dirPosition + 1 );
        $suffixPosition = strrpos( $file, '.' );
        $suffix = false;
        $prefix = false;
        $mimeName = false;
        if ( $suffixPosition !== false )
        {
            $suffix = strtolower( substr( $file, $suffixPosition + 1 ) );
            if ( $suffix )
            {
                $subURL = substr( $file, 0, $suffixPosition );
                $suffixList =& $instance->SuffixList;
                if ( array_key_exists( $suffix, $suffixList ) )
                {
                    $mimeName = $suffixList[$suffix];
                }
            }
            if ( !$mimeName )
            {
                $prefixPosition = strpos( $file, '.' );
                if ( $prefixPosition !== false )
                {
                    $prefix = strtolower( substr( $file, 0, $prefixPosition ) );
                }
                if ( $prefix )
                {
                    $subURL = substr( $file, $suffixPosition + 1 );
                    $prefixList =& $instance->PrefixList;
                    if ( array_key_exists( $prefix, $prefixList ) )
                    {
                        $mimeName = $prefixList[$prefix];
                    }
                }
            }
            if ( $mimeName )
            {
                $mimeList =& $instance->MIMEList;
                if ( array_key_exists( $mimeName, $mimeList ) )
                {
                    $lastDirPosition = strrpos( $url, '/' );
                    $filename = $url;
                    $dirpath = false;
                    if ( $lastDirPosition !== false )
                    {
                        $filename = substr( $url, $lastDirPosition + 1 );
                        $dirpath = substr( $url, 0, $lastDirPosition );
                    }
                    $lastDirPosition = strrpos( $subURL, '/' );
                    $basename = $subURL;
                    if ( $lastDirPosition !== false )
                        $basename = substr( $subURL, $lastDirPosition + 1 );
                    $mime = $mimeList[$mimeName];
                    $mime['name'] = $mimeName;
                    $mime['url'] = $url;
                    $mime['filename'] = $filename;
                    $mime['dirpath'] = $dirpath;
                    $mime['basename'] = $basename;
                    $mime['suffix'] = $suffix;
                    $mime['prefix'] = $prefix;
                    $mime['is_valid'] = true;
                    return $mime;
                }
            }
        }
        return eZMimeType::defaultValue( $url, $returnDefault );
    }
358569
public function renameFolder($old_name, $new_name, $expunge = true) {
        $this->checkConnection();
        $status = imap_renamemailbox($this->getConnection(), $this->getAddress() . imap_utf7_encode($old_name), $this->getAddress() . imap_utf7_encode($new_name));
        if($expunge) $this->expunge();

        return $status;
    }
745596
public function diffHtml($old, $new, $output = 'array')
    {
        if (!in_array($output, ['array', 'string'])) {
            throw new \RuntimeException(
                sprintf('Unknown output type "%s"', $output)
            );
        }

        $ret = '';
        $arr = [
            'old' => '',
            'new' => '',
        ];

        $diff = $this->diff(preg_split("/[\s]+/", $old), preg_split("/[\s]+/", $new));

        //die(print_r($diff));
        foreach ($diff as $k) {
            if (is_array($k)) {
                $deletions  = !empty($k['d']) ? '<del>'.implode(' ', $k['d']).'</del>' : '';
                $insertions = !empty($k['i']) ? '<ins>'.implode(' ', $k['i']).'</ins>' : '';
                $deletions  = $deletions.(!empty($deletions) ? ' ' : '');
                $insertions = $insertions.(!empty($insertions) ? ' ' : '');
                $ret .= trim($deletions).$insertions;
                $arr['old'] .= $deletions;
                $arr['new'] .= $insertions;
            } else {
                // No differences
                $str = $k.' ';
                $ret .= $str;
                $arr['old'] .= $str;
                $arr['new'] .= $str;
            }
        }

        // cleanup
        $ret        = trim(ltrim($ret));
        $arr['old'] = trim(ltrim($arr['old']));
        $arr['new'] = trim(ltrim($arr['new']));

        return ($output === 'string') ? $ret : $arr;
    }
179708
protected function execute(InputInterface $input, OutputInterface $output) : int
    {
        $logger = LoggerHelper::createDefaultLogger($output);

        /** @var string $cacheOption */
        $cacheOption = $input->getOption('cache');
        $fileCache = new FilesystemCache($cacheOption);
        $cache = new SimpleCacheAdapter($fileCache);

        $logger->info('initializing converting process');

        $browscap = new BrowscapUpdater($cache, $logger);

        $logger->info('started converting local file');

        /** @var string $file */
        $file = $input->getArgument('file');
        if (! $file) {
            $file = $this->defaultIniFile;
        }

        $output->writeln(sprintf('converting file %s', $file));

        try {
            $browscap->convertFile($file);
        } catch (Exception\FileNameMissingException $e) {
            $logger->debug($e);

            return 6;
        } catch (Exception\FileNotFoundException $e) {
            $logger->debug($e);

            return 7;
        } catch (Exception\ErrorReadingFileException $e) {
            $logger->debug($e);

            return 8;
        }

        $logger->info('finished converting local file');

        return 0;
    }
1359291
public function sendToRandomWorker($type, $uns_data, string $callStaticFuc)
    {
        $send_data = get_instance()->packServerMessageBody($type, $uns_data, $callStaticFuc);
        $id = rand(0, get_instance()->worker_num - 1);
        if ($this->server->worker_id == $id) {
            //自己的进程是收不到消息的所以这里执行下
            sd_call_user_func($callStaticFuc, $uns_data);
        } else {
            get_instance()->server->sendMessage($send_data, $id);
        }
    }
919002
public function sendToAllWorks($type, $uns_data, string $callStaticFuc)
    {
        $send_data = $this->packServerMessageBody($type, $uns_data, $callStaticFuc);
        for ($i = 0; $i < $this->worker_num + $this->task_num; ++$i) {
            if ($this->server->worker_id == $i) {
                continue;
            }
            $this->server->sendMessage($send_data, $i);
        }
        //自己的进程是收不到消息的所以这里执行下
        sd_call_user_func($callStaticFuc, $uns_data);
    }
1081766
public static function delegate($flag, $submodule, $arguments) {
		$options = Application::get($flag . '.' . $submodule . '.options');
		if (!empty($options)) {
			// todo: maybe add to first array instead to first element in arguments
			$arguments[0] = array_merge_hard($options, $arguments[0]);
		}
		// we need to determine whether we need to use additional submodule
		if (Application::get($flag . '.' . $submodule . '.submodule') && empty($arguments[0]['flag_call_previous_parent'])) {
			return call_user_func_array([self::submodule($flag . '.' . $submodule . '.submodule'), $submodule], $arguments);
		} else {
			return call_user_func_array([self::submodule($flag . '.submodule'), $submodule], $arguments);
		}
	}
1147142
function(inDir, outDir, relativePath, newCache) {
    var ext = this._matchingFileExtension(relativePath);
    var moduleName = relativePath.slice(0, relativePath.length - (ext.length + 1));
    var fullInputPath = path.join(inDir, relativePath);
    var fullOutputPath = path.join(outDir, moduleName + '.' + this.targetExtension);

    var entry = this._transpileThroughCache(
      moduleName,
      fs.readFileSync(fullInputPath, 'utf-8'),
      newCache
    );

    mkdirp.sync(path.dirname(fullOutputPath));
    fs.writeFileSync(fullOutputPath, entry.output);
  }
466084
protected function getTableMigrationNewDatabase($output, $new, $old)
    {
        if (empty($new['database'])) {
            return $output;
        }
        if ($this->neq($new, $old, ['database', 'default_character_set_name'])) {
            $output[] = $this->getAlterDatabaseCharset($new['database']['default_character_set_name']);
        }
        if ($this->neq($new, $old, ['database', 'default_collation_name'])) {
            $output[] = $this->getAlterDatabaseCollate($new['database']['default_collation_name']);
        }

        return $output;
    }
358464
protected function executeSubFields(ObjectType $returnType, array $fieldNodes, array $path, &$result)
    {
        $subFields            = [];
        $visitedFragmentNames = [];

        foreach ($fieldNodes as $fieldNode) {
            if (null !== $fieldNode->getSelectionSet()) {
                $subFields = $this->fieldCollector->collectFields(
                    $returnType,
                    $fieldNode->getSelectionSet(),
                    $subFields,
                    $visitedFragmentNames
                );
            }
        }

        if (!empty($subFields)) {
            return $this->executeFields($returnType, $result, $path, $subFields);
        }

        return $result;
    }
528815
public function getClientBrowserDetails($returnType = ['Browser', 'Device', 'OS'], $tmpFolder = null)
    {
        $userAgent      = $this->getUserAgentByCommonLib();
        $devDetectClass = new \DeviceDetector\DeviceDetector($userAgent);
        if (is_null($tmpFolder)) {
            $tmpFolder = '../../tmp/DoctrineCache/';
        }
        $devDetectClass->setCache(new \Doctrine\Common\Cache\PhpFileCache($tmpFolder));
        $devDetectClass->discardBotInformation();
        $devDetectClass->parse();
        if ($devDetectClass->isBot()) {
            return [
                'Bot' => $devDetectClass->getBot(),
            ];
        }
        return $this->getClientBrowserDetailsNonBot($devDetectClass, $userAgent, $returnType);
    }