method search documentation in bbn\Appui\Ide

function(array $info) { $res['success'] = false; if ( !empty($info['search']) && !empty($info['nameRepository']) && !empty($info['repository']) && isset($info['typeSearch']) ) { $list = []; $fileData = []; $result = []; $totLines = 0; $tot_num_files = 0; $occourences = 0; $base = $info['repository']['name']; $base_rep = $this->getRootPath($base); //function that defines whether the search is sensitive or non-sensitive $typeSearch = function ($element, $code, $type) { if ($type === "sensitive") { return strpos($element, $code); } else { return stripos($element, $code); } }; if (!empty($info['isProject'])) { $part = $info['type']; } else { $part = $info['repository']['path']; } $path = $base_rep . $part; $all = $this->fs->getFiles($path, true); if (is_array($all) && count($all)) { foreach ($all as $i => $v) { if (X::basename($v) !== "cfg") { //if folder if ($this->fs->isDir($v)) { //case tree if (!empty($info['searchFolder'])) { if (!empty($info['mvc']) || ($info['type'] === 'mvc')) { $content = $v; } else { $content = $path; } $content .= $info['searchFolder']; } else { $content = $v; } $content = $this->fs->scan($content); if (is_array($content) && count($content)) { foreach ($content as $j => $val) { $list = []; // case file into folder if ($this->fs->isFile($val)) { $tot_num_files++; if ($typeSearch($this->fs->getContents($val), $info['search'], $info['typeSearch']) !== false) { $path = $base_rep . $part; $path_file = $val; $link = explode("/", substr($val, strlen($path) + 1, strlen($val))); if ((!empty($info['isProject']) && $info['type'] === 'mvc') || !empty($info['mvc']) ) { $tab = array_shift($link); $link = implode('/', $link); $link = explode('.', $link); $link = array_shift($link); } elseif ((!empty($info['isProject']) && ($info['type'] === 'components')) || !empty($info['components']) ) { $link = implode('/', $link); $link = explode('.', $link); $tab = array_pop($link); $link = $link[0]; } elseif (!empty($info['isProject']) && (($info['type'] === 'lib') || ($info['type'] === 'cli'))) { $link = implode('/', $link); $link = explode('.', $link); $tab = 'code'; $link = $link[0]; } elseif (empty($info['isProject']) && empty($info['type'])) { $file = $link[count($link) - 1]; $file = explode('.', $file); $tab = array_pop($file); $link[count($link) - 1] = array_shift($file); $link = implode('/', $link); } //object initialization with every single file to check the lines that contain it $file = new \SplFileObject($val); //cycle that reads all the lines of the file, it means until it has finished reading a file while (!$file->eof()) { //current line reading $lineCurrent = $file->current(); //if we find what we are looking for in this line and that this is not '\ n' then we will take the coirispjective line number with the key function, insert it into the array and the line number if (($typeSearch($lineCurrent, $info['search'], $info['typeSearch']) !== false) && (strpos($lineCurrent, '\n') === false)) { $lineNumber = $file->key() + 1; $name_path = $info['repository']['path'] . substr(X::dirname($val), strlen($base_rep)); $position = $typeSearch($lineCurrent, $info['search'], $info['typeSearch']); $line = "" . 'line ' . $lineNumber . ' : ' . ""; $text = $line; if ( !empty($info['mvc']) || (!empty($info['isProject']) && $info['type'] === 'mvc') ) { if ($tab === "public") { $tab = 'php'; } else { if (explode("/", $path_file)[1] === "html") { $lineCurrent = htmlentities($lineCurrent); } } } $text .= str_replace($info['search'], "" . $info['search'] . "", $lineCurrent); $file_name = X::basename($path_file); $path = X::dirname($base . '/' . substr($path_file, strlen($base_rep))); $occourences = $occourences + substr_count($lineCurrent, $info['search']); // info for code $list[] = [ 'text' => strlen($text) > 1000 ? $line . "" . X::_('content too long to be shown') . "" : $text, 'line' => $lineNumber - 1, 'position' => $position, 'link' => $link, 'tab' => !empty($tab) ? $tab : false, 'code' => true, 'uid' => $path . '/' . $file_name, 'icon' => 'nf nf-fa-code' ]; } //next line $file->next(); } } } //if we find rows then we will create the tree structure with all the information if (count($list) > 0) { $totLines = $totLines + count($list); if (!empty($info['mvc'])) { if (explode("/", $path_file)[1] === "public") { $tab = 'php'; } else { $tab = explode("/", $path_file)[1]; } $link = explode(".", substr($path_file, strlen(explode("/", $path_file)[0] . '/' . explode("/", $path_file)[1]) + 1))[0]; } //info file $fileData = [ 'text' => $path . '/' . $file_name . " " . count($list) . "", 'icon' => 'nf nf-fa-file_code_o', 'numChildren' => count($list), 'repository' => $info['repository']['path'], 'uid' => $path . $file_name, 'file' => X::basename($path_file), 'link' => !empty($link) ? $link : false, 'tab' => !empty($tab) ? $tab : false, 'items' => $list, ]; $result[] = $fileData; //die(var_dump($path.$name_path,$base_rep)); /*if ( !isset($result[$path.$name_path]) ){ //info folder $result[$path.$name_path]= [ 'text' => X::dirname($path.$file_name), 'num' => 1, 'numChildren' => 1, 'items' => [], 'icon' => !empty($info['component']) || ($info['type'] === 'components') ? 'nf nf-mdi-vuejs' : 'nf nf-fa-folder' ]; $result[$path.$name_path]['items'][] = $fileData; } else { $ctrlFile = false; // check if the file where we found one or more search results is not reinserted foreach( $result[$path.$name_path]['items'] as $key => $item ){ if ( $item['file'] === X::dirname($path_file) ){ $ctrlFile = true; } } //if we do not have the file, we will insert it if ( empty($ctrlFile) ){ $result[$path.$name_path]['items'][] = $fileData; $result[$path.$name_path]['num']++; $result[$path.$name_path]['numChildren']++; } }*/ } } } } // file not contained in the folder else { $tot_num_files++; $list = []; if ($typeSearch($this->fs->getContents($v), $info['search'], $info['typeSearch']) !== false) { $path_file = substr($v, Strpos($v, $info['repository']['path'])); $file = new \SplFileObject($v); while (!$file->eof()) { $lineCurrent = $file->current(); if (($typeSearch($lineCurrent, $info['search'], $info['typeSearch']) !== false) && (strpos($lineCurrent, '\n') === false) ) { $lineNumber = $file->key() + 1; $link = explode(".", substr($path_file, strlen(explode("/", $path_file)[0] . '/' . explode("/", $path_file)[1]) + 1))[0]; $name_path = substr(X::dirname($v), Strpos($v, $info['repository']['path'])); $position = $typeSearch($lineCurrent, $info['search'], $info['typeSearch']); $text = "" . 'line ' . $lineNumber . ' : ' . ""; $text .= str_replace($info['search'], "" . $info['search'] . "", $lineCurrent); $occourences = $occourences + substr_count($lineCurrent, $info['search']); //see $path = str_replace($base, (strpos($path_file, $this->getAppPath()) === 0 ? 'app/' : 'lib/'), $path); if (!empty($info['mvc'])) { if (explode("/", $path_file)[1] === "public") { $tab = 'php'; } else { $tab = explode("/", $path_file)[1]; } $link = explode(".", substr($path_file, strlen(explode("/", $path_file)[0] . '/' . explode("/", $path_file)[1]) + 1))[0]; } // info for file $list[] = [ 'text' => strlen($text) > 1000 ? $line . "" . X::_('content too long to be shown') . "" : $text, 'line' => $lineNumber - 1, 'position' => $position, 'code' => true, 'uid' => $path . '/' . $file_name, 'icon' => 'nf nf-fa-code', 'linkPosition' => explode(".", substr($path_file, strlen(explode("/", $path_file)[0] . '/' . explode("/", $path_file)[1]) + 1))[0], 'tab' => !empty($tab) ? $tab : false ]; } $file->next(); } if (count($list) > 0) { $totLines .= count($list); // info for file who contain a code $fileData = [ 'text' => X::basename($path_file), 'icon' => 'nf nf-fa-file_code', 'num' => count($list), 'numChildren' => count($list), 'repository' => $info['repository']['bbn_path'] . '/', 'uid' => $path . '/' . $file_name, 'file' => X::basename($path_file), 'link' => !empty($link) ? $link : false, 'tab' => !empty($tab) ? $tab : false, 'items' => $list ]; $result[] = $fileData; } } } } } } if (!empty($result)) { $totFiles = 0; foreach ($result as $key => $value) { $totFiles = $totFiles + $value['items'][0]['numChildren']; } return [ 'list' => array_values($result), 'occurences' => $occourences, 'totFiles' => $tot_num_files, 'filesFound' => count($result), //$tot_num_files++, 'totLines' => $totLines ]; } } return false; }

BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way

This website uses cookies to ensure you get the best experience on our website.