コード例 #1
0
ファイル: functions.php プロジェクト: asimo124/AngularSite1
function trimright($string, $position)
{
    if (strlen($string) > $position) {
        $leftstring = substr($string, 0, $position);
        $position2 = strposReverse($leftstring, " ", strlen($leftstring) - 1);
        $string6 = substr($leftstring, 0, $position2);
        return $string6;
    } else {
        return $string;
    }
}
$results = 0;
foreach ($files as $file) {
    $file = file_get_contents($file);
    $test = 0;
    #foreach($findArray as $find){
    $label = strpos_recursive(strip_tags($file), $find);
    if (!$label) {
        continue;
    }
    $date = substr($file, strpos($file, "{{"), strpos($file, "}}") - strpos($file, "{{") + 2);
    $date = str_replace(array("{{", "}}"), array('<h3>', '</h3>'), $date);
    if (!$test) {
        echo $date;
    }
    $endpos = strpos($file, $end, strrpos($file, $find));
    $startpos = strposReverse($file, $end, strpos($file, $find));
    $wfile = '';
    if ($endpos) {
        $wfile = substr($file, $startpos, $endpos - $startpos);
    } else {
        $wfile = substr($file, $startpos);
    }
    $wfile = str_replace(array("\n", "\r"), '<br/>', $wfile);
    $wfile = str_replace('??', $whitespace, $wfile);
    $wfile = str_replace('##', '&nbsp;', $wfile);
    $wfile = str_replace(array("[[", "]]"), array('<div id = "label"> &nbsp;', '&nbsp; </div>'), $wfile);
    $wfile = str_replace(array("{{", "}}"), array('<h3>', '</h3>'), $wfile);
    $wfile = str_replace(array("<<", ">>"), array('<img src="', '" style="margin:auto;display:block;"/>'), $wfile);
    $wfile = str_replace(array(">l>", ">r>"), array('" style="margin:auto;display:block;" align="left" width="400" height="350"/>', '" style="margin:auto;display:block;" align="right" width="400" height="350"/>'), $wfile);
    #$stripFile = strip_tags($wfile);
    $wfile = str_replace($find, '<span style="background-color:yellow;">' . $find . '</span>', $wfile);
コード例 #3
0
ファイル: CodeShell.php プロジェクト: Jony01/LLD
 protected function _correctFile($file)
 {
     $fileContent = $content = file_get_contents($file);
     preg_match_all('/class \\w+ extends (.+)\\s*{/', $fileContent, $matches);
     if (empty($matches)) {
         continue;
     }
     $excludes = array('Fixture', 'Exception', 'TestSuite', 'CakeTestModel');
     $missingClasses = array();
     foreach ($matches[1] as $match) {
         $match = trim($match);
         preg_match('/\\bApp\\:\\:uses\\(\'' . $match . '\'/', $fileContent, $usesMatches);
         if (!empty($usesMatches)) {
             continue;
         }
         preg_match('/class ' . $match . '\\s*(w+)?{/', $fileContent, $existingMatches);
         if (!empty($existingMatches)) {
             continue;
         }
         if (in_array($match, $missingClasses)) {
             continue;
         }
         $break = false;
         foreach ($excludes as $exclude) {
             if (strposReverse($match, $exclude) === 0) {
                 $break = true;
                 break;
             }
         }
         if ($break) {
             continue;
         }
         $missingClasses[] = $match;
     }
     if (empty($missingClasses)) {
         return;
     }
     $fileContent = explode(LF, $fileContent);
     $inserted = array();
     $pos = 1;
     if (!empty($fileContent[1]) && $fileContent[1] === '/**') {
         $count = count($fileContent);
         for ($i = $pos; $i < $count - 1; $i++) {
             if (strpos($fileContent[$i], '*/') !== false) {
                 if (strpos($fileContent[$i + 1], 'class ') !== 0) {
                     $pos = $i + 1;
                 }
                 break;
             }
         }
     }
     // try to find the best position to insert app uses statements
     foreach ($fileContent as $row => $rowValue) {
         preg_match('/^App\\:\\:uses\\(/', $rowValue, $matches);
         if ($matches) {
             $pos = $row;
             break;
         }
     }
     foreach ($missingClasses as $missingClass) {
         $classes = array('Controller' => 'Controller', 'Component' => 'Controller/Component', 'Shell' => 'Console/Command', 'Model' => 'Model', 'Behavior' => 'Model/Behavior', 'Datasource' => 'Model/Datasource', 'Task' => 'Console/Command/Task', 'View' => 'View', 'Helper' => 'View/Helper');
         $type = null;
         foreach ($classes as $class => $namespace) {
             if (($t = strposReverse($missingClass, $class)) === 0) {
                 $type = $namespace;
                 break;
             }
         }
         if (empty($type)) {
             $this->err($missingClass . ' (' . $file . ') could not be matched');
             continue;
         }
         if ($class === 'Model') {
             $missingClassName = $missingClass;
         } else {
             $missingClassName = substr($missingClass, 0, strlen($missingClass) - strlen($class));
         }
         $objects = App::objects(($this->params['plugin'] ? $this->params['plugin'] . '.' : '') . $class);
         //FIXME: correct result for plugin classes
         if ($missingClass === 'Component') {
             $type = 'Controller';
         } elseif ($missingClass === 'Helper') {
             $type = 'View';
         } elseif ($missingClass === 'ModelBehavior') {
             $type = 'Model';
         } elseif (!empty($this->params['plugin']) && ($location = App::location($missingClass))) {
             $type = $location;
         } elseif (in_array($missingClass, $objects)) {
             $type = ($this->params['plugin'] ? $this->params['plugin'] . '.' : '') . $type;
         }
         $inserted[] = 'App::uses(\'' . $missingClass . '\', \'' . $type . '\');';
     }
     if (!$inserted) {
         return;
     }
     array_splice($fileContent, $pos, 0, $inserted);
     $fileContent = implode(LF, $fileContent);
     if (empty($this->params['dry-run'])) {
         file_put_contents($file, $fileContent);
         $this->out(__d('cake_console', 'Correcting %s', $file), 1, Shell::VERBOSE);
     }
 }