示例#1
0
 /**
  * Returns an array of pages
  * @return array an array of pages
  */
 public static function pages($order_by = '', $where = null, $limit = 50, $offset = 0)
 {
     $module = \jacmoe\mdpages\Module::getInstance();
     if (!is_null($module)) {
         $controller = \Yii::$app->controller;
         if (!is_null($controller)) {
             if ($controller->id == 'page') {
                 $repo = $controller->getFlywheelRepo();
                 if (empty($order_by)) {
                     if (isset($where)) {
                         list($field, $operator, $value) = $where;
                         return $repo->query()->limit($limit, $offset)->where($field, $operator, $value)->execute();
                     } else {
                         return $repo->query()->limit($limit, $offset)->execute();
                     }
                 } else {
                     if (isset($where)) {
                         list($field, $operator, $value) = $where;
                         return $repo->query()->limit($limit, $offset)->where($field, $operator, $value)->orderBy($order_by)->execute();
                     } else {
                         return $repo->query()->limit($limit, $offset)->orderBy($order_by)->execute();
                     }
                 }
             }
             throw new NotSupportedException("Can only be used when active controller is 'page'.");
         }
     }
     throw new NotSupportedException("Can't be called outside of jacmoe\\mdpages module.");
 }
 public function parse($text)
 {
     $text_wo_frontmatter = YII_DEBUG ? $text : $this->removeFrontmatter($text);
     $module = \jacmoe\mdpages\Module::getInstance();
     $snippetParser = new SnippetParser();
     $snippetParser->addSnippets($module->snippets);
     $text_snipped = $snippetParser->parse($text_wo_frontmatter);
     $markup = parent::parse($text_snipped);
     if ($module->generate_page_toc) {
         $markup = $this->applyToc($markup);
     }
     return $markup;
 }
 protected function renderWikilink($block)
 {
     $link = $this->renderAbsy($block[1]);
     $has_title = strpos($link, '|');
     $url = '';
     $title = '';
     if ($has_title === false) {
         $url = $link;
     } else {
         $parts = explode('|', $link);
         $url = $parts[0];
         $title = $parts[1];
     }
     $module = \jacmoe\mdpages\Module::getInstance();
     $repo = $this->getFlywheelRepo($module);
     $page = $repo->query()->where('url', '==', $url)->execute();
     $result = $page->first();
     if ($result != null) {
         return Html::a(empty($title) ? $result->title : $title, Url::to(['/' . $module->id . '/page/view', 'id' => $result->url], $module->absolute_wikilinks));
     } else {
         return '[[' . $link . ']]';
     }
 }
 /**
  * Removes content and data directories
  */
 public function actionClearAll()
 {
     $module = \jacmoe\mdpages\Module::getInstance();
     if ($this->confirm('Delete content and data directories ?')) {
         FileHelper::removeDirectory(Yii::getAlias($module->pages_directory));
         FileHelper::removeDirectory(Yii::getAlias($module->flywheel_config));
         FileHelper::removeDirectory(Yii::getAlias('@app/web') . DIRECTORY_SEPARATOR . 'avatars');
         $this->stdout("\nContent and data and avatars directories deleted.\n", Console::FG_GREEN);
     } else {
         $this->stdout("Nothing was deleted - command interrupted.\n", Console::FG_GREEN);
     }
 }