Example #1
0
 public function actionSitemapxml()
 {
     echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;
     echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . PHP_EOL;
     $rules = array(array(Page::findByType(), 1), array('News', 0.9), array('Event', 0.9), array('Category', 0.8), array('Business', 0.9, '/directory/business/view/id/{id}', 'monthly'), array('BusinessCategory', 0.8), array('Album', 0.9, '/gallery/album/view/id/{id}'), array('Image', 0.9, '/gallery/image/view/id/{id}'), array('Tag', 0.8, '{link}'));
     foreach ($rules as $rule) {
         $model = $rule[0];
         $link = isset($rule[2]) ? $rule[2] : NULL;
         //if model name is provided, get models
         if (gettype($model) == 'string') {
             $items = $model::model()->findAll();
         } else {
             $items = $model;
         }
         if (isset($items[0])) {
             foreach ($items as $item) {
                 echo "\t<url>" . PHP_EOL;
                 if (get_class($item) == 'Page' && $item->type != 'Page') {
                     continue;
                 }
                 if ($link) {
                     //key replacements
                     $pattern = '/{(.+)}/e';
                     $replace = "self::getAttr(\$item,'\$1')";
                     $l = preg_replace($pattern, $replace, $link);
                     $l = Yii::app()->createAbsoluteUrl($l);
                 } else {
                     //guess the view url
                     if (in_array('page-behavior', array_keys($item->behaviors()))) {
                         $l = $item->getUrl();
                     } else {
                         $l = Yii::app()->createAbsoluteUrl('/' . strtolower(get_class($item)) . '/view', array('id' => $item->id));
                     }
                     //  $l = '/' . strtolower(get_class($item)) . '/view/id/' . $item->id;
                 }
                 echo "\t\t<loc>" . $l . '</loc>' . PHP_EOL;
                 if (isset($item->modified_at) && $item->modified_at) {
                     echo "\t\t<lastmod>" . date('Y-m-d', strtotime($item->modified_at)) . '</lastmod>' . PHP_EOL;
                 }
                 if (isset($rule[3])) {
                     echo "\t\t<changefreq>" . $rule[3] . '</changefreq>' . PHP_EOL;
                 }
                 if (isset($rule[1])) {
                     echo "\t\t<priority>" . $rule[1] . '</priority>' . PHP_EOL;
                 }
                 echo "\t</url>" . PHP_EOL;
             }
         }
     }
     echo '</urlset>';
 }
Example #2
0
    public function run()
    {
        $page = $this->page;
        $form = $this->form;
        foreach ($this->fields as $field) {
            switch ($field) {
                case 'title':
                    ?>
                    <div class="row">
                        <?php 
                    echo $form->labelEx($page, 'title');
                    ?>
                        <?php 
                    echo $form->textField($page, 'title', array('size' => 60, 'maxlength' => 255));
                    ?>
                        <?php 
                    echo $form->error($page, 'title');
                    ?>
                    </div>
                    <?php 
                    break;
                case 'slug':
                    if (!Settings::get('SEO', 'slugs_enabled')) {
                        break;
                    }
                    $baseUrl = Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('application.modules.page.assets'));
                    Yii::app()->getClientScript()->registerScriptFile($baseUrl . '/slug.js');
                    if ($this->scenario == 'insert') {
                        Yii::app()->getClientScript()->registerScriptFile($baseUrl . '/create_slug.js');
                    }
                    ?>
                    <div class="row sticky">
                        <span id="slug_label" style="display:inline;"><strong><?php 
                    echo Yii::t('app', 'Link:');
                    ?>
</strong>
                            <?php 
                    echo 'http://' . $_SERVER['HTTP_HOST'] . Yii::app()->baseUrl . '/';
                    ?>
</span><span id="slug_holder" style="display:inline">
                            <?php 
                    $slug = isset($page->slug->slug) ? $page->slug->slug : '';
                    echo $slug;
                    ?>
                        </span>
                        <?php 
                    echo CHtml::textField("Page[slug]", $slug, array('size' => 65, 'style' => 'display:none;'));
                    ?>
                    </div>
                    <?php 
                    break;
                case 'content':
                    ?>
                    <div class="row">
                        <?php 
                    echo $form->labelEx($page, 'content');
                    ?>
                        <?php 
                    $this->widget('ext.redactor.ERedactorWidget', array("model" => $page, "attribute" => "content", 'options' => array('imageUpload' => Yii::app()->createAbsoluteUrl('/file/redactorUpload'))));
                    ?>
                        <?php 
                    echo $form->error($page, 'content');
                    ?>
                    </div>
                    <?php 
                    break;
                case 'user':
                    if (Yii::app()->getModule('user')->isAdmin()) {
                        if (!isset($page->user)) {
                            $page->user = Yii::app()->user->id;
                        }
                        ?>
                        <div class="row">
                            <?php 
                        echo $form->labelEx($page, 'user_id');
                        ?>
                            <?php 
                        echo $form->dropDownList($page, 'user', CHtml::listData(User::model()->findAll(), 'id', 'username'), array('prompt' => 'None'));
                        ?>
                            <?php 
                        echo $form->error($page, 'user_id');
                        ?>
                        </div>
                        <?php 
                    }
                    break;
                case 'status':
                    ?>
                    <div class="row">
                        <?php 
                    echo $form->labelEx($page, 'status');
                    ?>
                        <?php 
                    echo CHtml::activeDropDownList($page, 'status', array('published' => Yii::t('app', 'Published'), 'trashed' => Yii::t('app', 'Trashed'), 'draft' => Yii::t('app', 'Draft')));
                    ?>
                        <?php 
                    echo $form->error($page, 'status');
                    ?>
                    </div>
                    <?php 
                    break;
                case 'parent':
                    ?>
                    <div class="row">
                        <?php 
                    echo $form->labelEx($page, 'parent_id');
                    ?>
                        <?php 
                    $allModels = Page::findByType(get_class($this->model));
                    foreach ($allModels as $key => $aModel) {
                        if ($aModel->id == $page->id) {
                            unset($allModels[$key]);
                        }
                    }
                    echo $form->dropDownList($page, 'parent', CHtml::listData($allModels, 'id', 'title'), array('prompt' => 'None'));
                    ?>
                        <?php 
                    echo $form->error($page, 'parent_id');
                    ?>
                    </div>
                    <?php 
                    break;
                case 'categories':
                    if (Yii::app()->hasModule('category')) {
                        ?>
                        <div class="row nm_row">
                            <label for="categories"><?php 
                        echo Yii::t('app', 'Categories');
                        ?>
</label>
                            <?php 
                        echo CHtml::checkBoxList('Page[categories]', array_map('Awecms::getPrimaryKey', $page->categories), CHtml::listData(Category::model()->findAll(), 'id', 'name'), array('attributeitem' => 'id', 'checkAll' => 'Select All'));
                        ?>
                        </div>
                        <?php 
                    }
                    break;
                case 'tags':
                    ?>
                    <div class="row">
                        <?php 
                    if (Yii::app()->hasModule('tag')) {
                        Yii::app()->getController()->widget('TagWidget', array('model' => $page));
                    }
                    ?>
                    </div>
                    <?php 
                    break;
                case 'comment_status':
                    ?>
                    <div class="row">
                        <?php 
                    echo $form->labelEx($page, 'Comments');
                    ?>
                        <?php 
                    echo $form->dropDownList($page, 'comment_status', array('enabled' => 'Enabled', 'disabled' => 'Disabled'));
                    ?>
                        <?php 
                    echo $form->error($page, 'comment_status');
                    ?>
                    </div>
                    <?php 
                    break;
                default:
                    break;
            }
        }
    }