1

Тема: Кастомные поля в плагине pages

Приветствую!
Обращаюсь к знатокам данной cms: подскажите, как создать произвольное (новое) поле в Страницах?
То, что рыть надо в pages.admin.php и шаблонах этого плагина я уже понял. Может кто делал такое?

Поделиться

2

Re: Кастомные поля в плагине pages

новое поле типа title и мета теги?

Поделиться

3

Re: Кастомные поля в плагине pages

ravilr пишет:

новое поле типа title и мета теги?

Привет!
Да, например в Друпал это реализовано через админку, можно создать любой тип материала, как например товар, или новость или фотография с подписью, просто создав соответствующий тип материалов и назначив ему поля. например, создаешь новый тип материала с полями:  поле - текст, поле - строка, поле - изображение, поле - чекбокс. И в дальнейшем можешь клонировать/создавать новый тип этого материала уже с заготовленными полями для ввода.

Поделиться

4 (2014-07-03 07:13:47 отредактировано ravilr)

Re: Кастомные поля в плагине pages

Для добавления хоть одного дополнительного поля, необходимо произвести не мало манипуляций с файлами плагина pages, поэтому описывать мне очень лень. Могу конечно выложить измененные файлы для 2.4.0 , но это как то неправильно.

Еще для страниц можно использовать поле теги (конечно если у вас е блог и поле не используется).

Для этого достаточно в файле
\plugins\box\pages\pages.plugin.php
например после

    public static function keywords()
    {
        return Pages::$page['keywords'];
    }

добавить

    public static function tags()
    {
        return Pages::$page['tags'];
    }

ну а в шаблоне выводим так

Поделиться

5

Re: Кастомные поля в плагине pages

спасибо! а не знаешь, как page сделать в формате html, а не в txt? а то для лендинга вещь бесполезная, приходится сниппеты использовать, так бы всю верстку в page вставил...

Поделиться

6

Re: Кастомные поля в плагине pages

Djin
не надо задавать вопросы в теме, которые не по теме!

Поделиться

7

Re: Кастомные поля в плагине pages

ravilr пишет:

Для добавления хоть одного дополнительного поля, необходимо произвести не мало манипуляций с файлами плагина pages, поэтому описывать мне очень лень. Могу конечно выложить измененные файлы для 2.4.0 , но это как то неправильно.

Буду благодарен за такой файлик)

Поделиться

8

Re: Кастомные поля в плагине pages

Всем привет!

попытался добавить новое поле для ввода ссылки на изобр. для соц. сетей, для этого изменил код в соответствующих файлах плагина pages

в pages.admin.php, pages.plugin.php, add.view.php, edit.view.php добавил строки share_img по подобию keywords

pages.admin.php

updateWhere('[slug="'.Request::post('page_slug').'"]', array('expand' => Request::post('page_expand')));
                Request::shutdown();
            } else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); }
        }
    }
    /**
     * Pages admin function
     */
    public static function main()
    {
        $current_theme = Option::get('theme_site_name');
        $site_url = Option::get('siteurl');
        $templates_path = THEMES_SITE;
        $errors = array();
        $pages = new Table('pages');
        PagesAdmin::$pages = $pages;
        $users = new Table('users');
        $user = $users->select('[id='.Session::get('user_id').']', null);
        // Page author
        if ( ! empty($user['firstname'])) {
            $author = (empty($user['lastname'])) ? $user['firstname'] : $user['firstname'].' '.$user['lastname'];
        } else {
            $author = Session::get('user_login');
        }
        $author = Html::toText($author);
        // Status array
        $status_array = array('published' => __('Published', 'pages'),
                              'draft'     => __('Draft', 'pages'));
        // Access array
        $access_array = array('public'      => __('Public', 'pages'),
                              'registered'  => __('Registered', 'pages'));
        // Check for get actions
        // ---------------------------------------------
        if (Request::get('action')) {
            // Switch actions
            // -----------------------------------------
            switch (Request::get('action')) {
                // Clone page
                // -------------------------------------
                case "clone_page":
                    if (Security::check(Request::get('token'))) {
                        // Generate rand page name
                        $rand_page_name = Request::get('name').'_clone_'.date("Ymd_His");
                        // Get original page
                        $orig_page = $pages->select('[slug="'.Request::get('name').'"]', null);
                        // Generate rand page title
                        $rand_page_title = $orig_page['title'].' [copy]';
                        // Clone page
                        if ($pages->insert(array('slug'         => $rand_page_name,
                                                 'template'     => $orig_page['template'],
                                                 'parent'       => $orig_page['parent'],
                                                 'robots_index' => $orig_page['robots_index'],
                                                 'robots_follow'=> $orig_page['robots_follow'],
                                                 'status'       => $orig_page['status'],
                                                 'access'       => (isset($orig_page['access'])) ? $orig_page['access'] : 'public',
                                                 'expand'       => (isset($orig_page['expand'])) ? $orig_page['expand'] : '0',
                                                 'title'        => $rand_page_title,
                                                 'meta_title'   => $orig_page['meta_title'],
                                                 'description'  => $orig_page['description'],
                                                 'keywords'     => $orig_page['keywords'],
                                                 'share_img'    => $orig_page['share_img'],
                                                 'tags'         => $orig_page['tags'],
                                                 'date'         => $orig_page['date'],
                                                 'author'       => $orig_page['author']))) {
                            // Get cloned page ID
                            $last_id = $pages->lastId();
                            // Save cloned page content
                            File::setContent(STORAGE . DS . 'pages' . DS . $last_id . '.page.txt',
                                             File::getContent(STORAGE . DS . 'pages' . DS . $orig_page['id'] . '.page.txt'));
                            // Send notification
                            Notification::set('success', __('The page :page cloned.', 'pages', array(':page' => Security::safeName(Request::get('name'), '-', true))));
                        }
                        // Run add extra actions
                        Action::run('admin_pages_action_clone');
                        // Redirect
                        Request::redirect('index.php?id=pages');
                    } else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); }
                break;
                // Add page
                // -------------------------------------
                case "add_page":
                    // Add page
                    if (Request::post('add_page') || Request::post('add_page_and_exit')) {
                        if (Security::check(Request::post('csrf'))) {
                            // Get parent page
                            if (Request::post('pages') == '0') {
                                $parent_page = '';
                            } else {
                                $parent_page = Request::post('pages');
                            }
                            // Validate
                            //--------------
                            if (trim(Request::post('page_name')) == '') $errors['pages_empty_name'] = __('Required field', 'pages');
                            if (trim(Request::post('page_title')) == '') $errors['pages_empty_title'] = __('Required field', 'pages');
                            if (count($pages->select('[slug="'.Security::safeName(Request::post('page_name'), '-', true).'"]')) != 0) $errors['pages_exists'] = __('This page already exists', 'pages');
                            // Prepare date
                            if (Valid::date(Request::post('page_date'))) {
                                $date = strtotime(Request::post('page_date'));
                            } else {
                                $date = time();
                            }
                            if (Request::post('robots_index'))  $robots_index = 'noindex';   else $robots_index = 'index';
                            if (Request::post('robots_follow')) $robots_follow = 'nofollow'; else $robots_follow = 'follow';
                            // If no errors then try to save
                            if (count($errors) == 0) {
                                // Insert new page
                                if ($pages->insert(array('slug'        => Security::safeName(Request::post('page_name'), '-', true),
                                                        'template'     => Request::post('templates'),
                                                        'parent'       => $parent_page,
                                                        'status'       => Request::post('status'),
                                                        'access'       => Request::post('access'),
                                                        'expand'       => '0',
                                                        'robots_index' => $robots_index,
                                                        'robots_follow'=> $robots_follow,
                                                        'title'        => Request::post('page_title'),
                                                        'meta_title'   => Request::post('page_meta_title'),
                                                        'description'  => Request::post('page_description'),
                                                        'keywords'     => Request::post('page_keywords'),
                                                        'share_img'    => Request::post('page_share_img'),
                                                        'tags'         => Request::post('page_tags'),
                                                        'date'         => $date,
                                                        'author'       => $author))) {
                                    // Get inserted page ID
                                    $last_id = $pages->lastId();
                                    // Save content
                                    File::setContent(STORAGE . DS . 'pages' . DS . $last_id . '.page.txt', XML::safe(Request::post('editor')));
                                    // Send notification
                                    Notification::set('success', __('Your changes to the page :page have been saved.', 'pages', array(':page' => Security::safeName(Request::post('page_title'), '-', true))));
                                }
                                // Run add extra actions
                                Action::run('admin_pages_action_add');
                                // Redirect
                                if (Request::post('add_page_and_exit')) {
                                    Request::redirect('index.php?id=pages');
                                } else {
                                    Request::redirect('index.php?id=pages&action=edit_page&name='.Security::safeName(Request::post('page_name'), '-', true));
                                }
                            }
                        } else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); }
                    }
                    // Get all pages
                    $pages_list = $pages->select('[slug!="error404" and parent=""]');
                    $pages_array[] = '-none-';
                    foreach ($pages_list as $page) {
                        $pages_array[$page['slug']] = $page['title'];
                    }
                    // Get all templates
                    $templates_list = File::scan($templates_path, '.template.php');
                    foreach ($templates_list as $file) {
                        $templates_array[basename($file, '.template.php')] = basename($file, '.template.php');
                    }
                    // Save fields
                    if (Request::post('page_name'))        $post_name        = Request::post('page_name'); else $post_name = '';
                    if (Request::post('page_title'))       $post_title       = Request::post('page_title'); else $post_title = '';
                    if (Request::post('page_meta_title'))  $post_meta_title  = Request::post('page_meta_title'); else $post_meta_title = '';       if (Request::post('page_keywords'))    $post_keywords    = Request::post('page_keywords'); else $post_keywords = '';
                    if (Request::post('page_share_img'))   $post_share_img   = Request::post('page_share_img'); else $post_share_img = '';
                    if (Request::post('page_description')) $post_description = Request::post('page_description'); else $post_description = '';
                    if (Request::post('page_tags'))        $post_tags        = Request::post('page_tags'); else $post_tags = '';
                    if (Request::post('editor'))           $post_content     = Request::post('editor'); else $post_content = '';
                    if (Request::post('templates'))        $post_template    = Request::post('templates'); else $post_template = 'index';
                    if (Request::post('status'))           $post_status      = Request::post('status'); else $post_status = 'published';
                    if (Request::post('access'))           $post_access      = Request::post('access'); else $post_access = 'public';
                    if (Request::post('pages'))            $parent_page      = Request::post('pages'); else if(Request::get('parent_page')) $parent_page = Request::get('parent_page'); else $parent_page = '';
                    if (Request::post('robots_index'))     $post_robots_index = true; else $post_robots_index = false;
                    if (Request::post('robots_follow'))    $post_robots_follow = true; else $post_robots_follow = false;
                    //--------------
                    // Generate date
                    $date = Date::format(time(), 'Y-m-d H:i:s');
                    // Set Tabs State - page
                    Notification::setNow('page', 'page');
                    // Display view
                    View::factory('box/pages/views/backend/add')
                            ->assign('post_name', $post_name)
                            ->assign('post_title', $post_title)
                            ->assign('post_meta_title', $post_meta_title)                            
                            ->assign('post_description', $post_description)
                            ->assign('post_keywords', $post_keywords)
                            ->assign('post_share_img', $post_share_img)
                            ->assign('post_tags', $post_tags)
                            ->assign('post_content', $post_content)
                            ->assign('pages_array', $pages_array)
                            ->assign('parent_page', $parent_page)
                            ->assign('templates_array', $templates_array)
                            ->assign('post_template', $post_template)
                            ->assign('post_status', $post_status)
                            ->assign('post_access', $post_access)
                            ->assign('status_array', $status_array)
                            ->assign('access_array', $access_array)
                            ->assign('date', $date)
                            ->assign('post_robots_index', $post_robots_index)
                            ->assign('post_robots_follow', $post_robots_follow)
                            ->assign('errors', $errors)
                            ->display();
                break;
                // Edit page
                // -------------------------------------
                case "edit_page":
                    if (Request::post('edit_page') || Request::post('edit_page_and_exit')) {
                        if (Security::check(Request::post('csrf'))) {
                            // Get pages parent
                            if (Request::post('pages') == '0') {
                                $parent_page = '';
                            } else {
                                $parent_page = Request::post('pages');
                            }
                            // Save field
                            $post_parent = Request::post('pages');
                            // Validate
                            //--------------
                            if (trim(Request::post('page_name')) == '') $errors['pages_empty_name'] = __('Required field', 'pages');
                            if ((count($pages->select('[slug="'.Security::safeName(Request::post('page_name'), '-', true).'"]')) != 0) and (Security::safeName(Request::post('page_old_name'), '-', true) !== Security::safeName(Request::post('page_name'), '-', true))) $errors['pages_exists'] = __('This page already exists', 'pages');
                            if (trim(Request::post('page_title')) == '') $errors['pages_empty_title'] = __('Required field', 'pages');
                            // Save fields
                            if (Request::post('page_name'))        $post_name        = Request::post('page_name'); else $post_name = '';
                            if (Request::post('page_title'))       $post_title       = Request::post('page_title'); else $post_title = '';
                            if (Request::post('page_meta_title'))  $post_meta_title  = Request::post('page_meta_title'); else $post_meta_title = '';if (Request::post('page_keywords'))    $post_keywords    = Request::post('page_keywords'); else $post_keywords = '';
                            if (Request::post('page_share_img'))   $post_share_img   = Request::post('page_share_img'); else $post_share_img = '';
                            if (Request::post('page_description')) $post_description = Request::post('page_description'); else $post_description = '';
                            if (Request::post('page_tags'))        $post_tags        = Request::post('page_tags'); else $post_tags = '';
                            if (Request::post('editor'))           $post_content     = Request::post('editor'); else $post_content = '';
                            if (Request::post('templates'))        $post_template    = Request::post('templates'); else $post_template = 'index';
                            if (Request::post('status'))           $post_status      = Request::post('status'); else $post_status = 'published';
                            if (Request::post('access'))           $post_access      = Request::post('access'); else $post_access = 'public';
                            if (Request::post('robots_index'))     $post_robots_index = true; else $post_robots_index = false;
                            if (Request::post('robots_follow'))    $post_robots_follow = true; else $post_robots_follow = false;
                            //--------------
                            // Prepare date
                            if (Valid::date(Request::post('page_date'))) {
                                $date = strtotime(Request::post('page_date'));
                            } else {
                                $date = time();
                            }
                            if (Request::post('robots_index'))  $robots_index = 'noindex';   else $robots_index = 'index';
                            if (Request::post('robots_follow')) $robots_follow = 'nofollow'; else $robots_follow = 'follow';
                            if (count($errors) == 0) {
                                // Update parents in all childrens
                                if ((Security::safeName(Request::post('page_name'), '-', true)) !== (Security::safeName(Request::post('page_old_name'), '-', true)) and (Request::post('old_parent') == '')) {
                                    $_pages = $pages->select('[parent="'.Text::translitIt(trim(Request::post('page_old_name'))).'"]');
                                    if ( ! empty($_pages)) {
                                        foreach ($_pages as $_page) {                                            
                                            $pages->updateWhere('[parent="'.$_page['parent'].'"]', array('parent' => Security::safeName(Request::post('page_name'), '-', true)));
                                        }
                                    }
                                    if ($pages->updateWhere('[slug="'.Request::get('name').'"]',
                                                        array('slug'        => Security::safeName(Request::post('page_name'), '-', true),
                                                              'template'    => Request::post('templates'),
                                                              'parent'      => $parent_page,
                                                              'title'       => Request::post('page_title'),
                                                              'meta_title'  => Request::post('page_meta_title'),
                                                              'description' => Request::post('page_description'),
                                                              'keywords'    => Request::post('page_keywords'),
                                                              'share_img'   => Request::post('page_share_img'),
                                                              'tags'        => Request::post('page_tags'),
                                                              'robots_index' => $robots_index,
                                                              'robots_follow'=> $robots_follow,
                                                              'status'      => Request::post('status'),
                                                              'access'      => Request::post('access'),
                                                              'date'        => $date,
                                                              'author'      => $author))) {
                                        File::setContent(STORAGE . DS . 'pages' . DS . Request::post('page_id') . '.page.txt', XML::safe(Request::post('editor')));
                                        Notification::set('success', __('Your changes to the page :page have been saved.', 'pages', array(':page' => Security::safeName(Request::post('page_title'), '-', true))));
                                    }
                                    // Run edit extra actions
                                    Action::run('admin_pages_action_edit');
                                } else {
                                    if ($pages->updateWhere('[slug="'.Request::get('name').'"]',
                                                        array('slug'        => Security::safeName(Request::post('page_name'), '-', true),
                                                              'template'    => Request::post('templates'),
                                                              'parent'      => $parent_page,
                                                              'title'       => Request::post('page_title'),
                                                              'meta_title'  => Request::post('page_meta_title'),
                                                              'description' => Request::post('page_description'),
                                                              'keywords'    => Request::post('page_keywords'),
                                                              'share_img'   => Request::post('page_share_img'),
                                                              'tags'        => Request::post('page_tags'),
                                                              'robots_index' => $robots_index,
                                                              'robots_follow'=> $robots_follow,
                                                              'status'      => Request::post('status'),
                                                              'access'      => Request::post('access'),
                                                              'date'        => $date,
                                                              'author'      => $author))) {
                                        File::setContent(STORAGE . DS . 'pages' . DS . Request::post('page_id') . '.page.txt', XML::safe(Request::post('editor')));
                                        Notification::set('success', __('Your changes to the page :page have been saved.', 'pages', array(':page' => Security::safeName(Request::post('page_title'), '-', true))));
                                    }
                                    // Run edit extra actions
                                    Action::run('admin_pages_action_edit');
                                }
                                // Redirect
                                if (Request::post('edit_page_and_exit')) {
                                    Request::redirect('index.php?id=pages');
                                } else {
                                    Request::redirect('index.php?id=pages&action=edit_page&name='.Security::safeName(Request::post('page_name'), '-', true));
                                }
                            }
                        } else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); }
                    }
                    // Get all pages
                    $pages_list = $pages->select();
                    $pages_array[] = '-none-';
                    // Foreach pages find page whithout parent
                    foreach ($pages_list as $page) {
                        if (isset($page['parent'])) {
                            $c_p = $page['parent'];
                        } else {
                            $c_p = '';
                        }
                        if ($c_p == '') {
                            // error404 is system "constant" and no child for it
                            if ($page['slug'] !== 'error404' && $page['slug'] !== Request::get('name')) {
                                $pages_array[$page['slug']] = $page['title'];
                            }
                        }
                    }
                    // Get all templates
                    $templates_list = File::scan($templates_path,'.template.php');
                    foreach ($templates_list as $file) {
                        $templates_array[basename($file,'.template.php')] = basename($file, '.template.php');
                    }
                    $page = $pages->select('[slug="'.Request::get('name').'"]', null);
                    if ($page) {
                        $page_content = File::getContent(STORAGE . DS . 'pages' . DS . $page['id'] . '.page.txt');
                        // Safe fields or load fields
                        if (Request::post('page_name'))         $slug_to_edit        = Request::post('page_name'); else $slug_to_edit = $page['slug'];
                        if (Request::post('page_title'))        $title_to_edit       = Request::post('page_title'); else $title_to_edit = $page['title'];
                        if (Request::post('page_meta_title'))   $meta_title_to_edit  = Request::post('page_meta_title'); else $meta_title_to_edit = isset($page['meta_title']) ? $page['meta_title'] : '';
                        if (Request::post('page_description'))  $description_to_edit = Request::post('page_description'); else $description_to_edit = $page['description'];
                        if (Request::post('page_keywords'))     $keywords_to_edit    = Request::post('page_keywords'); else $keywords_to_edit = $page['keywords'];
                        if (Request::post('page_share_img'))    $share_img_to_edit   = Request::post('page_share_img'); else $share_img_to_edit = $page['share_img'];
                        if (Request::post('page_tags'))         $tags_to_edit        = Request::post('page_tags'); else $tags_to_edit = isset($page['tags']) ? $page['tags'] : '';;
                        if (Request::post('editor'))            $to_edit             = Request::post('editor'); else $to_edit = Text::toHtml($page_content);
                        if (Request::post('robots_index'))      $post_robots_index  = true; else if ($page['robots_index'] == 'noindex') $post_robots_index = true; else  $post_robots_index = false;
                        if (Request::post('robots_follow'))     $post_robots_follow = true; else if ($page['robots_follow'] == 'nofollow') $post_robots_follow = true; else  $post_robots_follow = false;
                        if (Request::post('pages')) {
                            // Get pages parent
                            if (Request::post('pages') == '-none-') {
                                $parent_page = '';
                            } else {
                                $parent_page = Request::post('pages');
                            }
                            // Save field
                            $parent_page = Request::post('pages');
                        } else {
                            $parent_page = $page['parent'];
                        }
                        if (Request::post('templates')) $template = Request::post('templates'); else $template = $page['template'];
                        if (Request::post('status'))    $status   = Request::post('status');    else $status   = $page['status'];
                        if (Request::post('access'))    $access   = Request::post('access');    else $access   = (isset($page['access'])) ? $page['access'] : 'public';
                        // Generate date
                        $date = Request::post('date') ? Request::post('date') : Date::format($page['date'], 'Y-m-d H:i:s');
                        Notification::setNow('page', 'page');
                        // Display view
                        View::factory('box/pages/views/backend/edit')
                                ->assign('slug_to_edit', $slug_to_edit)
                                ->assign('title_to_edit', $title_to_edit)
                                ->assign('meta_title_to_edit', $meta_title_to_edit)                                
                                ->assign('description_to_edit', $description_to_edit)
                                ->assign('keywords_to_edit', $keywords_to_edit)
                                ->assign('share_img_to_edit', $share_img_to_edit)
                                ->assign('tags_to_edit', $tags_to_edit)
                                ->assign('page', $page)
                                ->assign('to_edit', $to_edit)
                                ->assign('pages_array', $pages_array)
                                ->assign('parent_page', $parent_page)
                                ->assign('templates_array', $templates_array)
                                ->assign('template', $template)
                                ->assign('status_array', $status_array)
                                ->assign('access_array', $access_array)
                                ->assign('status', $status)
                                ->assign('access', $access)
                                ->assign('date', $date)
                                ->assign('post_robots_index', $post_robots_index)
                                ->assign('post_robots_follow', $post_robots_follow)
                                ->assign('errors', $errors)
                                ->display();
                    }
                break;
                // Delete page
                // -------------------------------------
                case "delete_page":
                    // Error 404 page can not be removed
                    if (Request::get('slug') !== 'error404') {
                        if (Security::check(Request::get('token'))) {
                            // Get specific page
                            $page = $pages->select('[slug="'.Request::get('name').'"]', null);
                            //  Delete page and update  fields
                            if ($pages->deleteWhere('[slug="'.$page['slug'].'" ]')) {
                                $_pages = $pages->select('[parent="'.$page['slug'].'"]');
                                if ( ! empty($_pages)) {
                                    foreach ($_pages as $_page) {
                                        $pages->updateWhere('[slug="'.$_page['slug'].'"]', array('parent' => ''));
                                    }
                                }
                                File::delete(STORAGE . DS . 'pages' . DS . $page['id'] . '.page.txt');
                                Notification::set('success', __('Page :page deleted', 'pages', array(':page' => Html::toText($page['title']))));
                            }
                            // Run delete extra actions
                            Action::run('admin_pages_action_delete');
                            // Redirect
                            Request::redirect('index.php?id=pages');
                        } else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); }
                    }
                break;
                // Update page access
                // -------------------------------------
                case "update_access":
                    if (Request::get('slug') !== 'error404') {
                        if (Security::check(Request::get('token'))) {
                            $pages->updateWhere('[slug="'.Request::get('slug').'"]', array('access' => Request::get('access')));
                            // Run delete extra actions
                            Action::run('admin_pages_action_update_access');
                            // Send notification
                            Notification::set('success', __('Your changes to the page :page have been saved.', 'pages', array(':page' => Request::get('slug'))));
                            // Redirect
                            Request::redirect('index.php?id=pages');
                        } else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); }
                    }
                break;
                // Update page status
                // -------------------------------------
                case "update_status":
                    if (Request::get('name') !== 'error404') {
                        if (Security::check(Request::get('token'))) {
                            $pages->updateWhere('[slug="'.Request::get('slug').'"]', array('status' => Request::get('status')));
                            // Run delete extra actions
                            Action::run('admin_pages_action_update_status');
                            // Send notification
                            Notification::set('success', __('Your changes to the page :page have been saved.', 'pages', array(':page' => Request::get('slug'))));
                            // Redirect
                            Request::redirect('index.php?id=pages');
                        } else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); }
                    }
                break;
            }
            // Its mean that you can add your own actions for this plugin
            Action::run('admin_pages_extra_actions');
        } else {
            // Index action
            // -------------------------------------
            // Init vars
            $pages_array = array();
            $count = 0;
            // Get pages
            $pages_list = $pages->select(null, 'all', null, array('slug', 'title', 'status', 'date', 'author', 'expand', 'access', 'parent', 'template', 'tags'));
            // Loop
            foreach ($pages_list as $page) {
                $pages_array[$count]['title']   = $page['title'];
                $pages_array[$count]['meta_title'] = isset($page['meta_title']) ? $page['meta_title'] : '';
                $pages_array[$count]['parent']  = $page['parent'];
                $pages_array[$count]['_status'] = $page['status'];
                $pages_array[$count]['_access'] = $page['access'];
                $pages_array[$count]['status']  = $status_array[$page['status']];
                $pages_array[$count]['access']  = isset($access_array[$page['access']]) ? $access_array[$page['access']] : $access_array['public']; // hack for old Monstra Versions
                $pages_array[$count]['date']    = $page['date'];
                $pages_array[$count]['author']  = $page['author'];
                $pages_array[$count]['expand']  = $page['expand'];
                $pages_array[$count]['slug']    = $page['slug'];
                $pages_array[$count]['tags']    = $page['tags'];
                $pages_array[$count]['template']= $page['template'];
                if (isset($page['parent'])) {
                    $c_p = $page['parent'];
                } else {
                    $c_p = '';
                }
                if ($c_p != '') {
                    $_page = $pages->select('[slug="'.$page['parent'].'"]', null);
                    if (isset($_page['title'])) {
                        $_title = $_page['title'];
                    } else {
                        $_title = '';
                    }
                    $pages_array[$count]['sort'] = $_title . ' ' . $page['title'];
                } else {
                    $pages_array[$count]['sort'] = $page['title'];
                }
                $_title = '';
                $count++;
            }
            // Sort pages
            $pages = Arr::subvalSort($pages_array, 'sort');
            // Display view
            View::factory('box/pages/views/backend/index')
                    ->assign('pages', $pages)
                    ->assign('site_url', $site_url)
                    ->display();
        }
    }
}

pages.plugin.php

select('[slug="'.$requested_page.'"]', null);
    }
    /**
     * Load current page
     *
     * @global string $defpage default page
     * @param  array  $data uri
     * @return string
     */
    public static function lowLoader($data)
    {
        $defpage = Option::get('defaultpage');
        // If data count 2 then it has Parent/Child
        if (count($data) >= 2) {
            // If exists parent file
            if (count(Pages::$pages->select('[slug="'.$data[0].'"]')) !== 0) {
                // Get child file and get parent page name
                $child_page = Pages::$pages->select('[slug="'.$data[1].'"]', null);
                // If child page parent is not empty then get his parent
                if (count($child_page) == 0) {
                    $c_p = '';
                } else {
                    if ($child_page['parent'] != '') {
                        $c_p = $child_page['parent'];
                    } else {
                        $c_p = '';
                    }
                }
                // Hack For old Monstra
                $child_page['access'] = (isset($child_page['access'])) ? $child_page['access'] : 'public' ;
                // Check is child_parent -> request parent
                if ($c_p == $data[0]) {
                    if (count($data) < 3) { // Checking only for the parent and one child, the remaining issue 404
                        if ((($child_page['status'] == 'published') or
                            (Session::exists('user_role') && in_array(Session::get('user_role'), array('admin', 'editor')))) and
                            ($child_page['access'] == 'public')) {
                            $id = $data[1];
                        } elseif (($child_page['access'] == 'registered') and
                                 (Session::exists('user_id')) and
                                 ($child_page['status'] == 'published')) {
                            $id = $data[1];
                        } else {
                            $id = 'error404';
                            Response::status(404);
                        }
                    } else {
                        $id = 'error404';
                        Response::status(404);
                    }
                } else {
                    $id = 'error404';
                    Response::status(404);
                }
            } else {
                $id = 'error404';
                Response::status(404);
            }
        } else { // Only parent page come
            if (empty($data[0])) {
                $id = $defpage;
            } else {
                // Get current page
                $current_page = Pages::$pages->select('[slug="'.$data[0].'"]', null);
                // Hack For old Monstra
                $current_page['access'] = (isset($current_page['access'])) ? $current_page['access'] : 'public' ;
                if (count($current_page) != 0) {
                    if ( ! empty($current_page['parent'])) {
                        $c_p = $current_page['parent'];
                    } else {
                        $c_p = '';
                    }
                } else {
                    $c_p = '';
                }
                // Check if this page has parent
                if ($c_p !== '') {
                    if ($c_p == $data[0]) {
                        if (count(Pages::$pages->select('[slug="'.$data[0].'"]', null)) != 0) {
                            if ((($current_page['status'] == 'published') or
                                (Session::exists('user_role') && in_array(Session::get('user_role'), array('admin', 'editor')))) and
                                ($current_page['access'] == 'public')) {
                                $id = $data[0];
                            } elseif (($current_page['access'] == 'registered') and
                                     (Session::exists('user_id')) and
                                     ($current_page['status'] == 'published')) {
                                $id = $data[0];
                            } else {
                                $id = 'error404';
                                Response::status(404);
                            }
                        } else {
                            $id = 'error404';
                            Response::status(404);
                        }
                    } else {
                        $id = 'error404';
                        Response::status(404);
                    }
                } else {
                    if (count(Pages::$pages->select('[slug="'.$data[0].'"]', null)) != 0) {
                        if ((($current_page['status'] == 'published') or
                            (Session::exists('user_role') && in_array(Session::get('user_role'), array('admin', 'editor')))) and
                            ($current_page['access'] == 'public')) {
                            $id = $data[0];
                        } elseif (($current_page['access'] == 'registered') and
                                 (Session::exists('user_id')) and
                                 ($current_page['status'] == 'published')) {
                            $id = $data[0];
                        } else {
                            $id = 'error404';
                            Response::status(404);
                        }
                    } else {
                        $id = 'error404';
                        Response::status(404);
                    }
                }
            }
        }
        // Return page name/id to load
        return $id;
    }
    /**
     * Get pages template
     *
     * @return string
     */
    public static function template()
    {
        if (Pages::$page['template'] == '') return 'index'; else return Pages::$page['template'];
    }
    /**
     * Get pages contents
     *
     * @return string
     */
    public static function content($slug = '')
    {
        if ( ! empty($slug)) {
            $page = Table::factory('pages')->select('[slug="'.$slug.'"]', null);
            if ( ! empty($page)) {
                $content = Text::toHtml(File::getContent(STORAGE . DS . 'pages' . DS . $page['id'] . '.page.txt'));
                $content = Filter::apply('content', $content);
                return $content;
            } else {
                return '';
            }
        } else {
            return Text::toHtml(File::getContent(STORAGE . DS . 'pages' . DS . Pages::$page['id'] . '.page.txt'));
        }
    }
    /**
     * Get pages title
     *
     *  
     *      echo Page::title();
     *  
     *
     * @return string
     */
    public static function title()
    {
        return !empty(Pages::$page['meta_title']) ? Pages::$page['meta_title'] : Pages::$page['title'];
    }
    /**
     * Get pages Description
     *
     *  
     *      echo Page::description();
     *  
     *
     * @return string
     */
    public static function description()
    {
        return Pages::$page['description'];
    }
    /**
     * Get pages Keywords
     *
     *  
     *      echo Page::keywords();
     *  
     *
     * @return string
     */
    public static function keywords()
    {
        return Pages::$page['keywords'];
    }
    /**
     * Get pages Share images
     *
     *  
     *      echo Page::share_img();
     *  
     *
     * @return string
     */
    public static function share_img()
    {
        return Pages::$page['share_img'];
    }
    /**
     * Get pages
     */
    public static function getPages()
    {
        // Init vars
        $pages_array = array();
        $count = 0;
        // Get pages table
        $pages = new Table('pages');
        // Get Pages List
        $pages_list = $pages->select('[slug!="error404" and status="published"]');
        foreach ($pages_list as $page) {
            $pages_array[$count]['title']   = Html::toText($page['title']);
            $pages_array[$count]['meta_title'] = !empty($page['meta_title']) ? Html::toText($page['meta_title']) : $page['title'];
            $pages_array[$count]['parent']  = $page['parent'];
            $pages_array[$count]['date']    = $page['date'];
            $pages_array[$count]['author']  = $page['author'];
            $pages_array[$count]['slug']    = ($page['slug'] == Option::get('defaultpage')) ? '' : $page['slug'] ;
            if (isset($page['parent'])) {
                $c_p = $page['parent'];
            } else {
                $c_p = '';
            }
            if ($c_p != '') {
                $_page = $pages->select('[slug="'.$page['parent'].'"]', null);
                if (isset($_page['title'])) {
                    $_title = $_page['title'];
                } else {
                    $_title = '';
                }
                $pages_array[$count]['sort'] = $_title . ' ' . $page['title'];
            } else {
                $pages_array[$count]['sort'] = $page['title'];
            }
            $_title = '';
            $count++;
        }
        // Sort pages
        $_pages_list = Arr::subvalSort($pages_array, 'sort');
        // return
        return $_pages_list;
    }
}
/**
 * Page class
 */
class Page extends Pages
{
    /**
     * Get date of current page
     *
     *  
     *      echo Page::date();
     *  
     *
     * @param  string $format Date format
     * @return string
     */
    public static function date($format = 'Y-m-d')
    {
        return Date::format(Pages::$page['date'], $format);
    }
    /**
     * Get author of current page
     *
     *  
     *      echo Page::author();
     *  
     *
     * @return string
     */
    public static function author()
    {
        return Pages::$page['author'];
    }
    /**
     * Get children pages for a specific parent page
     *
     *  
     *      $pages = Page::children('page');
     *  
     *
     * @param  string $parent Parent page
     * @return array
     */
    public static function children($parent)
    {
        return Pages::$pages->select('[parent="'.(string) $parent.'"]', 'all');
    }
    /**
     * Get the available children pages for requested page.
     *
     *  
     *      echo Page::available();
     *  
     *
     */
    public static function available()
    {
        $pages = Pages::$pages->select('[parent="'.Pages::$requested_page.'"]', 'all');
        // Display view
        View::factory('box/pages/views/frontend/available_pages')
                ->assign('pages', $pages)
                ->display();
    }
    /**
     * Get page breadcrumbs
     *
     *  
     *      echo Page::breadcrumbs();
     *  
     *
     */
    public static function breadcrumbs()
    {
        if (Uri::command() == 'pages') {
            $current_page = Pages::$requested_page;
            $parent_page = '';
            if ($current_page !== 'error404') {
                $page = Pages::$pages->select('[slug="'.$current_page.'"]', null);
                if (trim($page['parent']) !== '') {
                    $parent = true;
                    $parent_page = Pages::$pages->select('[slug="'.$page['parent'].'"]', null);
                } else {
                    $parent = false;
                }
            // Display view
            View::factory('box/pages/views/frontend/breadcrumbs')
                    ->assign('current_page', $current_page)
                    ->assign('page', $page)
                    ->assign('parent', $parent)
                    ->assign('parent_page', $parent_page)
                    ->display();
            }
        }    
    }
    /**
     * Get page url
     *
     *  
     *      echo Page::url();
     *  
     *
     */
    public static function url()
    {
        return Option::get('siteurl').'/'.Pages::$page['slug'];
    }
    /**
     * Get page slug
     *
     *  
     *      echo Page::slug();
     *  
     *
     */
    public static function slug()
    {
        return Pages::$page['slug'];
    }
    /**
     * Get page meta robots
     *
     *  
     *      echo Page::robots();
     *  
     *
     */
    public static function robots()
    {
        if (Pages::$page !== null) {
            $_index  = (isset(Pages::$page['robots_index'])) ? Pages::$page['robots_index'] : '';
            $_follow = (isset(Pages::$page['robots_follow'])) ? Pages::$page['robots_follow'] : '';
            $robots  = ( ! empty($_index) && ! empty($_follow)) ? $_index.', '.$_follow : '';
        } else {
            $robots = '';
        }
        return $robots;
    }
    public static function _date($attributes)
    {
        return Page::date((isset($attributes['format'])) ? $attributes['format'] : 'Y-m-d');
    }
    public static function _content($attributes)
    {
        return Pages::content((isset($attributes['name']) ? $attributes['name'] : ''));
    }
}
/**
 * Add new shortcodes {page_author} {page_slug} {page_url} {page_date} {page_content}
 */
Shortcode::add('page_author', 'Page::author');
Shortcode::add('page_slug', 'Page::slug');
Shortcode::add('page_url', 'Page::url');
Shortcode::add('page_content', 'Page::_content');
Shortcode::add('page_date', 'Page::_date');

Поделиться

9

Re: Кастомные поля в плагине pages

add.view.php

(isset($errors['pages_empty_title'])) ? 'form-control error-field' : 'form-control')) ); if (isset($errors['pages_empty_title'])) echo Html::nbsp(3).''.$errors['pages_empty_title'].''; ?>
(isset($errors['pages_empty_name'])) ? 'form-control error-field' : 'form-control')) ); if (isset($errors['pages_exists'])) echo ''.$errors['pages_exists'].''; if (isset($errors['pages_empty_name'])) echo ''.$errors['pages_empty_name'].''; ?>
'form-control')) ); ?>
'form-control')) ); ?>
'form-control')) ); ?>
'form-control')) ); ?>
'form-control')) ); ?>
'form-control')) ); ?>
'form-control')) ); ?>
'form-control')) ); ?>
'form-control')) ); ?>
'btn btn-phone btn-primary')).Html::nbsp(2). Form::submit('add_page', __('Save', 'pages'), array('class' => 'btn btn-phone btn-primary')).Html::nbsp(2). Html::anchor(__('Cancel', 'pages'), 'index.php?id=pages', array('title' => __('Cancel', 'pages'), 'class' => 'btn btn-phone btn-default')) ); ?>
'form-control')); ?>

edit.view.php

(isset($errors['pages_empty_title'])) ? 'form-control error-field' : 'form-control')) ); if (isset($errors['pages_empty_title'])) echo ''.$errors['pages_empty_title'].''; ?>
(isset($errors['pages_empty_name'])) ? 'form-control error-field' : 'form-control')) ); } if (isset($errors['pages_empty_name'])) echo ''.$errors['pages_empty_name'].''; if (isset($errors['pages_exists'])) echo ''.$errors['pages_exists'].''; ?>
'form-control')) ); ?>
'form-control')) ); ?>
'form-control')) ); ?>
'form-control')) ); ?>
'form-control')) ); ?>
'form-control')) ); ?>
'form-control')) ); ?>
'form-control')) ); ?>
'form-control')) ); ?>
'btn btn-phone btn-primary')).Html::nbsp(2). Form::submit('edit_page', __('Save', 'pages'), array('class' => 'btn btn-phone btn-primary')).Html::nbsp(2). Html::anchor(__('Cancel', 'pages'), 'index.php?id=pages', array('title' => __('Cancel', 'pages'), 'class' => 'btn btn-phone btn-default')) ); ?>
'form-control')); ?>

ну и соответственно внес изменения в языковые файлы плагина.

В итоге доп. поле появилось, а сохранять наотрез перестало - создать страницу или внести изменения в существующую невозможно. Други!,  может кто более опытным взглядом глянет на код, может что то неправильно прописал или еще где то чего то надо дописать ...
За ранее благодарен ...

Поделиться

10 (2014-09-10 16:32:36 отредактировано KANekT)

Re: Кастомные поля в плагине pages

а вы сделали апдейтер который в базу это поле добавляет ?

    // Pages Table: add new fields
    $pages = new Table('pages');
    $pages->addField('meta_title');
    $pages->addField('tags');
Site | GitHub | Создание форумов/решений на базе PunBB/Monstra/OGMA

Плагины распространяются по Creative Commons Attribution-NonCommercial 3.0

Сайт KANekT

Поделиться

11

Re: Кастомные поля в плагине pages

нет, вопрос а как его делать?, я особо не селен в пхп, только учу ...

Поделиться

12

Re: Кастомные поля в плагине pages

http://ru.forum.monstra.org/topic/795/pages-fields/

Поделиться

13

Re: Кастомные поля в плагине pages

и чем полезен ваш коммент - кода примера нет!

Site | GitHub | Создание форумов/решений на базе PunBB/Monstra/OGMA

Плагины распространяются по Creative Commons Attribution-NonCommercial 3.0

Сайт KANekT

Поделиться

Сообщений 13

Страницы 1

Чтобы отправить ответ, вы должны войти или зарегистрироваться

Монстра → Вопросы → Кастомные поля в плагине pages