Пример #1
0
 public function run($params)
 {
     if (C('IMERGE.IS_MIGRATE') && !file_exists(C('IMERGE_PATH') . '/' . C('IMERGE_IMAGE_DIR'))) {
         mark('正在进行合图配置迁移...', 'emphasize');
         $tool = $params[1];
         $path = $this->findOldM3dPath();
         if ($path) {
             mark('找到旧配置文件,开始迁移...');
             $imergePath = $path . '/imerge/*';
             $entries = glob($imergePath);
             foreach ($entries as $entry) {
                 if (is_dir($entry)) {
                     $files = scandir($entry);
                     foreach ($files as $file) {
                         if ($file[0] === '_') {
                             include $entry . '/' . $file;
                         }
                     }
                     $type = basename($entry);
                     $var = 'post_' . $type . '_confs_maps';
                     if (isset(${$var})) {
                         $tool->getWriter()->writeImageConfigByType(${$var}, $type, true);
                     }
                 }
             }
         }
     }
 }
Пример #2
0
 public function run($params)
 {
     //        $oldRevision = 117093;
     $oldRevision = self::getPrevRevision();
     //        $oldRevision = null;
     // 检查m3d配置文件是否已改变
     $path = defined('M3D_FILE') ? M3D_FILE : (defined('SRC_ROOT') ? SRC_ROOT . '/m3d.php' : null);
     if ($path && self::checkFileChange($path, $oldRevision)) {
         mark('m3d配置文件已改变,重新加载配置,并且进行全量编译', 'especial');
         $params[1]->reload(PROJECT_SITE_PATH . '/' . C('PROJECT.SRC_DIR') . '/' . PROJECT_MODULE_NAME . '/' . C('M3D_FILENAME'));
         C('INCRE.IS_INCRE', false);
         trigger('m3d_config_change');
     }
     if (isset($_GET['isIncre']) && $_GET['isIncre'] === 'false' || !C('INCRE.IS_INCRE') || is_null($oldRevision)) {
         // 事件解绑
         self::off();
     } else {
         mark('增量编译准备中...', 'emphasize');
         $newRevision = IncreMap::getRevision();
         self::$files = self::getChangeList($newRevision, $oldRevision);
         IncreMap::loadBelongMap();
         if (!empty(self::$files[self::DELETE])) {
             IncreMap::rebuildBelongMap(self::$files[self::DELETE]);
         }
         // 更新modify列表
         self::$files[self::MODIFY] = array_unique(array_merge(self::$files[self::MODIFY], IncreMap::getAffectList(self::$files[self::MODIFY])));
     }
 }
Пример #3
0
/**
 * @param callable $fn
 * @param array|void $args
 * @param callable|void $collector
 * @return mixed
 */
function invoke(callable $fn, $args = [], callable $collector = null)
{
    mark($key = uniqid());
    $result = call_user_func_array($fn, $args);
    call_user_func($collector ?: __NAMESPACE__ . '\\collector', mark($key));
    return $result;
}
Пример #4
0
 public function generate()
 {
     foreach ($this->files as $file) {
         mark('解析CSS文件:' . $file);
         $this->file = $file;
         $content = file_get_contents($file);
         $cssDoc = JCssParser::parse($content);
         foreach ($cssDoc['stylesheet']['rules'] as $rule) {
             if ($rule['type'] === 'rule') {
                 $bgDecls = array();
                 $merge = null;
                 foreach ($rule['declarations'] as $declaration) {
                     if (strpos($declaration['property'], 'background') !== false) {
                         array_push($bgDecls, $declaration);
                     } elseif ($declaration['property'] === 'merge') {
                         $merge = $declaration['value'];
                     }
                 }
                 if ($merge) {
                     $this->setConfigByRule($merge, $bgDecls);
                 }
             }
         }
     }
     return $this;
 }
Пример #5
0
 public static function ci()
 {
     mark('执行svn提交操作...', 'emphasize');
     self::localDelToSvn();
     shell_exec_ensure(C('SVN') . ' add ' . C('SRC.BUILD_PATH') . ' --force', false);
     shell_exec_ensure(C('SVN') . ' add ' . C('SRC.M3D_PATH') . ' --force', false);
     shell_exec_ensure(C('SVN') . ' ci "' . C('SRC.ROOT') . '" -m "commit by M3D"', false);
 }
Пример #6
0
 /**
  * 自动合图
  */
 public function auto()
 {
     //        ini_set('memory_limit', -1);
     //        set_time_limit(0);
     header('Content-Type: text/event-stream');
     header('Cache-Control: no-cache');
     $this->tool->run();
     mark('Done!', 'emphasize');
     show_json();
 }
Пример #7
0
 public function run()
 {
     trigger('imerge_start', $this);
     mark('开始自动合图扫描', 'emphasize');
     $files = get_files_by_type(C('SRC.SRC_PATH'), 'css');
     $generator = new MergeConfigGenerator($files);
     $generator->generate();
     $writer = new MergeConfigWriter(C('IMERGE_PATH'));
     $writer->writeImageConfig($generator->getConfig());
     // 更新大图
     $this->updateSprite();
     trigger('imerge_end', $this);
 }
Пример #8
0
 /**
  * 设置一个将要处理的文件路径
  * @param $file 文件路径
  */
 public function setFile($file)
 {
     if (file_exists($file)) {
         $info = pathinfo($file);
         $this->type = $info['extension'];
         $this->filename = $info['basename'];
         $this->setContents(file_get_contents($file));
         $this->path = $file;
         $this->relativePath = str_replace(C('SRC.SRC_PATH'), '', $file);
         $this->orgRelativePath = $this->relativePath;
         $this->fileUid = null;
     } else {
         mark($file . '不存在', 'error');
     }
 }
Пример #9
0
 public function index()
 {
     // Server Sent Event
     //        header('Content-Type: text/event-stream');
     header('Content-Type: text/octet-stream');
     header('Cache-Control: no-cache');
     $t1 = microtime(true);
     define('PROJECT_SITE_PATH', C('PROJECT.SITE_PATH') . '/' . $_GET['site']);
     define('PROJECT_MODULE_NAME', $_GET['module']);
     $path = PROJECT_SITE_PATH . '/' . C('PROJECT.SRC_DIR') . '/' . PROJECT_MODULE_NAME . '/' . C('M3D_FILENAME');
     $tool = new PreprocessTool($path);
     $tool->run();
     mark('处理完成!', 'emphasize');
     $t2 = microtime(true);
     show_json('编译用时:' . round($t2 - $t1, 2) . 's');
 }
Пример #10
0
 public function run($params)
 {
     $item = $params[2];
     if ($this->options['requirejs.path'] && $item['processor'] === 'js') {
         mark('requireJs插件开始处理' . $this->options['requirejs.path'], 'emphasize');
         $this->options['requirejs.path'] = C('SRC.SRC_PATH') . $this->options['requirejs.path'];
         if (!file_exists($this->options['requirejs.path'])) {
             mark('"' . $this->options['requirejs.path'] . '"不存在,请检查m3d.php中requireJs配置', 'error');
             return;
         }
         $tool = $params[1];
         $map = $this->getMap($tool);
         $script = $this->genScript($map);
         $processor = Preprocess::getInstance('js');
         $mapFiles = $this->options['requirejs.path'];
         if (is_string($mapFiles)) {
             $mapFiles = array($mapFiles);
         }
         foreach ($mapFiles as $file) {
             $processor->setFile($file);
             $processor->setContents($script);
             $processor->process();
             $processor->compress();
             $path = $processor->getRelativePath();
             $buildPath = $tool->writeBuildFile($processor, $item, $path);
             $oldBuildPath = $tool->getMap('js', $path);
             if ($buildPath !== $oldBuildPath) {
                 $tool->updateMap('js', $path, $buildPath);
                 // 清除文件
                 $file = C('SRC.BUILD_PATH') . $oldBuildPath;
                 if (file_exists($file)) {
                     unlink($file);
                 }
                 $file = C('SRC.BUILD_CACHE_PATH') . $oldBuildPath;
                 if (file_exists($file)) {
                     unlink($file);
                 }
                 trigger('change_file', $path);
             }
         }
     }
 }
Пример #11
0
 /**
  * 绘制图像
  * @param $type
  */
 public function draw($type, $config = array())
 {
     if (empty($config)) {
         $loader = new MergeConfigLoader($this->imergePath);
         $config = $loader->getImageConfigByType($type);
     }
     $imgList = array();
     if (!empty($config)) {
         foreach ($config as $key => $value) {
             try {
                 $imgList[$key] = new Image($this->staticRelativePath . $key, $value);
             } catch (ImageException $e) {
                 mark("合图{$type}中,存在小图{$key}的配置文件,但该小图不存在,请到合图配置界面删除该小图", 'warn');
             }
         }
     }
     $layout = new Layout($imgList);
     $spriteConfigs = array();
     $spriteConfigs[$type] = array();
     if ($layout->reflow($width, $height)) {
         $this->sprite = imagecreatetruecolor($width, $height);
         imagealphablending($this->sprite, false);
         imagesavealpha($this->sprite, true);
         imagefill($this->sprite, 0, 0, imagecolorallocatealpha($this->sprite, 0, 0, 0, 127));
         $spriteConfigs[$type]['config'] = $this->repaint($this->sprite, $imgList, $width, $height);
         // 记录sprite的属性
         $spriteConfigs[$type]['attr'] = array('filename' => $type . C('SPRITE_SUFFIX') . '.png', 'width' => $width, 'height' => $height);
         //            $spriteConfigs[$type]['filename'] = $type.C('SPRITE_SUFFIX').'.png';
         // 生成大图到imerge_sprite_dir
         $path = $this->imergePath . '/' . C('IMERGE_SPRITE_DIR') . '/' . $type . C('SPRITE_SUFFIX') . '.png';
         imagepng($this->sprite, $path);
         // 写入配置
         $writer = new MergeConfigWriter($this->imergePath);
         $writer->writeSpriteConfig($spriteConfigs);
         // 派发处理完成事件
         trigger('DRAW_SPRITE_END', $path);
     }
 }
Пример #12
0
 private function getBackgroundUrlData($url, $merge = null)
 {
     $ret = array('url' => $url, 'config' => null);
     $newUrl = $url;
     if (!$url || strpos($url, 'data:') !== false || strpos($url, 'about:') !== false || strpos($url, '://') !== false) {
         return $ret;
     }
     $url = Tool::getActualPath($url);
     $mask = 0;
     $mask += !is_null($merge);
     $mask += $mask > 0 && isset($this->spriteConfig[$merge]);
     $mask += $mask > 1 && isset($this->spriteConfig[$merge]['config'][$url]);
     $mask <<= 1;
     $mask += isset($this->map['media'][$url]);
     if (($mask & 6) === 6) {
         $sprite = $this->spriteConfig[$merge]['attr']['filename'];
         if (isset($this->map['media'][$sprite])) {
             $newUrl = $this->map['media'][$sprite];
         } else {
             mark('找不到合图文件' . $sprite . '的去向,请确定该合图已编译', 'error');
             return $ret;
         }
         $ret['config'] = $this->spriteConfig[$merge]['config'][$url];
         trigger('css_background_change', $this, $sprite);
     } else {
         if (($mask & 1) === 1) {
             $newUrl = $this->map['media'][$url];
         }
         trigger('css_background_change', $this, $url);
         // 依然将合图加入依赖关系表中,万一某天心血来潮又合图了,依然可以进行增量编译
         if ($mask > 1) {
             trigger('css_background_change', $this, $merge . C('SPRITE_SUFFIX') . '.png');
         }
         // 5中异常情况
         switch ($mask) {
             case 0:
                 mark('文件“' . $this->path . '”中引用了“' . $url . '”,但该图片不存在!', 'warn');
                 return $ret;
             case 1:
                 // 正常情况
                 break;
             case 2:
                 mark('文件“' . $this->path . '”中存在未知合图类型“' . $merge . '”,并且图片“' . $url . '”也不存在', 'warn');
                 return $ret;
             case 3:
                 mark('文件“' . $this->path . '”中存在未知合图类型“' . $merge . '”,将用小图地址代替', 'warn');
                 break;
             case 4:
                 mark('文件“' . $this->path . '”中引用了合图“' . $merge . '”,但该合图类型中不存在“' . $url . '”的配置信息,并且该图片也不存在', 'warn');
                 return $ret;
             case 5:
                 mark('文件“' . $this->path . '”中引用了合图“' . $merge . '”,但该合图类型中不存在“' . $url . '”的配置信息,将用小图地址代替', 'warn');
                 break;
             default:
                 mark('文件“' . $this->path . '”中引用了“' . $url . '”,未知错误码:' . $mask, 'error');
                 return $ret;
         }
     }
     $ret['url'] = Tool::addCdn($newUrl);
     return $ret;
 }
Пример #13
0
 /**
  * 合图文件处理
  * @param $processor
  * @param $item
  */
 private function processSprite(Preprocess $processor, $item)
 {
     // 确保大图最新
     $imergeTool = new InstantmergeTool($this->options, false);
     $imergeTool->updateSprite();
     // 如果处理图片类,则需要扫描合图目录
     $spriteList = $this->getFileList(C('IMERGE_PATH') . '/' . C('IMERGE_SPRITE_DIR'), $item['type']);
     foreach ($spriteList as $file) {
         mark('处理文件:' . $file);
         $processor->setFile($file);
         $processor->process();
         $processor->compress(true);
         $path = str_replace(C('SRC.ROOT'), '', $file);
         $buildPath = $this->writeBuildFile($processor, $item, $path);
         // 更新map, 合图文件仅使用文件名作为key
         $filename = $processor->getFilename();
         $this->map[$item['name']][$filename] = $buildPath;
     }
 }
Пример #14
0
 /**
  * @dataProvider markProvider
  */
 public function testMark($time)
 {
     mark($key = uniqid());
     sleep($time);
     $this->assertEquals($time, (int) mark($key));
 }
Пример #15
0
 function statisticsExecTime($func, array $params, $xAxis)
 {
     set_time_limit(170);
     $func_name = '';
     if (is_array($func)) {
         if (!method_exists($func[0], $func[1])) {
             return false;
         }
         $func_name = object_name($func[0]) . '->' . $func[1];
     } else {
         if (is_string($func)) {
             if (!function_exists($func)) {
                 return false;
             }
             $func_name = $func;
         } else {
             if (is_callable($func)) {
                 // if(! function_exists($func)){
                 // return false;
                 // }
                 $func_name = 'Closure';
             } else {
                 return false;
             }
         }
     }
     $mem = [];
     $time = [];
     foreach ($params as $v) {
         mark('start');
         $result = call_user_func_array($func, (array) $v);
         $time[] = floatval(mark('start', 'end'));
         $memory = memory_mark();
         if (isset($memory['start']) && isset($memory['end'])) {
             $mem[] = floatval(memory_mark('start', 'end'));
         }
         mark('[clear]');
         memory_mark('[clear]');
     }
     $data = [['name' => 'Exec Time', 'data' => $time]];
     $mem && ($data[] = ['name' => 'Exec Memory', 'data' => $mem]);
     $xAxis = ['categories' => $xAxis];
     return chart($xAxis, $data, 'Function [' . htmlentities($func_name) . '] Execute Time Statistics', 'At ' . date('Y-m-d H:i:s'), 'Number');
 }
Пример #16
0
/**
 * 从stdio中读写数据,执行命令
 * @param $exec
 * @param $content
 * @return string
 */
function shell_exec_stdio($exec, $content)
{
    $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
    //windows only, bypass cmd.exe shell when set to TRUE
    $options = array('bypass_shell' => true);
    $process = proc_open($exec, $descriptorspec, $pipes, null, null, $options);
    if (is_resource($process)) {
        fwrite($pipes[0], $content);
        fclose($pipes[0]);
        $output = stream_get_contents($pipes[1]);
        fclose($pipes[1]);
        $err = stream_get_contents($pipes[2]);
        fclose($pipes[2]);
        $ret = proc_close($process);
        if ($ret !== 0) {
            mark('执行命令' . $exec . '错误,返回值:' . $ret . ',errmsg:' . $err, 'error');
            return $content;
        }
        return $output;
    } else {
        mark('执行命令' . $exec . '失败', 'error');
        return $content;
    }
}
Пример #17
0
        $search = preg_replace('/&quot;/', '"', current($_POST));
        $config = session::global_get('config');
        foreach ($config->department_info as $dn => $info) {
            if (!isset($pathMapping[$dn])) {
                continue;
            }
            if (mb_stristr($info['name'], $search) !== FALSE) {
                $res .= "<li>" . mark($search, $pathMapping[$dn]) . ($info['description'] == '' ? "" : "<span class='informal'> [" . mark($search, $info['description']) . "]</span>") . "</li>";
                continue;
            }
            if (mb_stristr($info['description'], $search) !== FALSE) {
                $res .= "<li>" . mark($search, $pathMapping[$dn]) . ($info['description'] == '' ? "" : "<span class='informal'> [" . mark($search, $info['description']) . "]</span>") . "</li>";
                continue;
            }
            if (mb_stristr($pathMapping[$dn], $search) !== FALSE) {
                $res .= "<li>" . mark($search, $pathMapping[$dn]) . ($info['description'] == '' ? "" : "<span class='informal'> [" . mark($search, $info['description']) . "]</span>") . "</li>";
                continue;
            }
        }
        /* Return results */
        if (!empty($res)) {
            echo "<ul>{$res}</ul>";
        }
    }
} else {
    $ui = session::global_get('ui');
    /* Is there a filter object arround? */
    if (session::is_set("autocomplete")) {
        $filter = session::get("autocomplete");
        $filter->processAutocomplete();
    }
Пример #18
0
 protected function _execute($cmd)
 {
     mark();
     exec($cmd, $o, $r);
     mark();
     if ($r !== 0) {
         return array(false, $o);
     }
     return array(true, $o);
 }
echo number($diff);
?>
 kr</td>
				<td class="numeric revenue_p<?php 
echo mark(($markup = round($diff / $product->price * 100)) < 20);
?>
" ><?php 
echo $markup;
?>
 %</td>
				<td class="numeric threshold"><?php 
echo $product->inventory_threshold ? $product->inventory_threshold . ' st' : '';
?>
</td>
				<td class="numeric threshold_diff<?php 
echo mark(($t_diff = $product->count - $product->inventory_threshold) <= 0 && $product->inventory_threshold != null);
?>
" ><?php 
echo $product->inventory_threshold > 0 ? $t_diff . ' st' : '';
?>
</td>
				<td class="numeric sales"><?php 
echo $count = TransactionContent::sum('count', array('product_id' => $product->id, 'Transaction.timestamp:>' => date('Y-m-d', time() - 60 * 60 * 24 * 30)));
?>
 st</td>
				<td class="numeric sales_value"><?php 
echo number($sold = TransactionContent::sum('amount', array('product_id' => $product->id, 'Transaction.timestamp:>' => date('Y-m-d', time() - 60 * 60 * 24 * 30))));
?>
 kr</td>
				<td class="numeric sales_value"><?php 
echo number($sold - $count * $product->value);