コード例 #1
0
 /**
  * @param array $dir
  * @param $files
  * @param \stdClass $category
  * @return void
  */
 protected function addRecipes(array $dir, $files, \stdClass $category)
 {
     foreach ($dir as $value) {
         if ($value != "." && $value != "..") {
             $file = \File::get("{$files}/{$value}");
             $problem = $this->getParseContents('problem', $file);
             $solution = $this->getParseContents('solution', $file);
             $discussion = $this->getParseContents('discussion', $file);
             $credit = $this->getParseContents('credit', $file);
             $title = $this->getParseHeader('title', $file);
             $position = $this->getParseHeader('position', $file);
             $topics = $this->getParseHeader('topics', $file);
             if ($problem && $solution && $discussion && $title) {
                 $array = ['problem' => trim($problem), 'category_id' => $category->category_id, 'solution' => trim($this->convertGfm($solution)), 'discussion' => trim($this->convertGfm($discussion)), 'credit' => trim($this->convertGfm($credit)), 'title' => trim($title), 'position' => trim($position)];
                 try {
                     // new recipes
                     $recipeId = $this->recipe->addRecipe($array);
                     $this->addTags($recipeId, $topics);
                     $this->info("added : {$files}/{$value}");
                 } catch (QueryException $e) {
                     // update recipes
                     $recipe = $this->recipe->getRecipeFromTitle(trim($title));
                     $this->recipe->updateRecipe($recipe->recipe_id, ['problem' => trim($problem), 'category_id' => $category->category_id, 'solution' => trim($this->convertGfm($solution)), 'discussion' => trim($this->convertGfm($discussion)), 'position' => trim($position)]);
                     $this->recipeTag->deleteRecipeTags($recipe->recipe_id);
                     $this->addTags($recipe->recipe_id, $topics);
                     $this->comment("Updated : recipe:{$title} : {$files}/{$value}");
                 }
             }
         }
     }
 }
コード例 #2
0
 /**
  * @param $string
  * @return mixed
  */
 public function convertToRef($string)
 {
     if (preg_match_all("/\\[\\[((.*?))\\]\\]/us", $string, $matches)) {
         foreach ($matches[0] as $key => $match) {
             $recipe = $this->recipe->getRecipeFromTitle($matches[1][$key]);
             if ($recipe) {
                 if (isset($matches[1][$key])) {
                     $replace = $matches[1][$key];
                     $ref = "[{$replace}](" . action('home.recipe', [$recipe->recipe_id]) . ")";
                     $string = str_replace($match, $ref, $string);
                 }
             }
         }
     }
     return $string;
 }