コード例 #1
0
 /**
  * @return \Illuminate\Http\Response
  */
 public function getSiteMap()
 {
     $dom = new \DOMDocument();
     $dom->version = "1.0";
     $dom->encoding = "UTF-8";
     $urlset = $dom->appendChild($dom->createElement('urlset'));
     $urlset->setAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
     $urlset->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
     $url = $urlset->appendChild($dom->createElement('url'));
     $url->appendChild($dom->createElement('loc', url()));
     $url->appendChild($dom->createElement('priority', '1.0'));
     $url->appendChild($dom->createElement('changefreq', 'always'));
     $recipes = $this->recipe->all();
     if ($recipes) {
         foreach ($recipes as $recipe) {
             $url = $urlset->appendChild($dom->createElement('url'));
             $url->appendChild($dom->createElement('loc', route('home.recipe', [$recipe->recipe_id])));
             $url->appendChild($dom->createElement('lastmod', date('c', strtotime($recipe->updated_at))));
             $url->appendChild($dom->createElement('priority', '0.5'));
             $url->appendChild($dom->createElement('changefreq', 'never'));
         }
     }
     $dom->formatOutput = true;
     $content = $dom->saveXML();
     return \Response::make($content, 200, ["Content-Type" => "application/xml; charset=UTF-8"]);
 }
コード例 #2
0
 /**
  *
  */
 public function getIndex()
 {
     $requests = \Input::only(['words']);
     $validate = $this->recipe->validate($requests, 'search');
     if (!$validate) {
         return \Redirect::to('/')->withErrors(['words' => '検索キーワードはかならず記入して下さい']);
     }
     $words = preg_split("[  ,]", $requests['words']);
     /** @var \Illuminate\Pagination\Paginator $res */
     $data = ['list' => $this->recipe->getRecipesFromText($words, \Input::get('page', 1), self::PER_PAGE)];
     $this->title("検索: " . implode(',', $words));
     $this->view('home.search.index', $data);
 }
コード例 #3
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}");
                 }
             }
         }
     }
 }
コード例 #4
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;
 }
コード例 #5
0
 /**
  * @param $id
  * @return \Illuminate\Http\JsonResponse
  */
 public function show($id)
 {
     $input = \Input::get('format', 'json');
     $array = [];
     $recipe = $this->recipe->getRecipe($id);
     if ($recipe) {
         $category = $this->category->getCategory($recipe->category_id);
         $array = ['id' => $recipe->recipe_id, 'title' => $recipe->title, 'problem' => $recipe->problem, 'category' => ['description' => $category->description, 'name' => $category->name]];
     }
     // render for hypermedia
     if ($input == 'hal') {
         $this->hal->setUri(route('home.recipe', ['one' => $id]));
         $this->hal->setData($array);
         $array = $this->hal;
     }
     return $this->render($array, $input);
 }
コード例 #6
0
 /**
  * @access private
  * @return mixed
  */
 private function getContentsRanking()
 {
     $result = $this->analytics->getSortedCount(0, 6);
     if ($result) {
         foreach ($result as $row) {
             $recipe = $this->recipe->getRecipe($row->recipe_id);
             $category = $this->category->getCategory($recipe->category_id);
             $row->category_id = isset($recipe->category_id) ? $recipe->category_id : null;
             $row->title = isset($recipe->title) ? $recipe->title : null;
             $row->name = isset($category->name) ? $category->name : null;
         }
     }
     return $result;
 }