Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php namespace Widget\Contents\Page; use Typecho\Common; use Typecho\Date; use Typecho\..

Decoded Output download

<?php

namespace Widget\Contents\Page;

use Typecho\Common;
use Typecho\Date;
use Typecho\Db\Exception as DbException;
use Typecho\Widget\Exception;
use Widget\Base\Contents;
use Widget\Contents\EditTrait;
use Widget\ActionInterface;
use Widget\Contents\PrepareEditTrait;
use Widget\Notice;
use Widget\Service;

if (!defined('__TYPECHO_ROOT_DIR__')) {
    exit;
}

/**
 * 
 *
 * @property-read array $draft
 */
class Edit extends Contents implements ActionInterface
{
    use PrepareEditTrait;
    use EditTrait;

    /**
     * 
     *
     * @access public
     * @return void
     * @throws Exception
     * @throws DbException
     */
    public function execute()
    {
        /**  */
        $this->user->pass('editor');
    }

    /**
     * 
     */
    public function writePage()
    {
        $contents = $this->request->from(
            'text',
            'template',
            'allowComment',
            'allowPing',
            'allowFeed',
            'slug',
            'order',
            'visibility'
        );

        $contents['title'] = $this->request->get('title', _t(''));
        $contents['created'] = $this->getCreated();
        $contents['visibility'] = ('hidden' == $contents['visibility'] ? 'hidden' : 'publish');
        $contents['parent'] = $this->getParent();

        if ($this->request->is('markdown=1') && $this->options->markdown) {
            $contents['text'] = '<!--markdown-->' . $contents['text'];
        }

        $contents = self::pluginHandle()->call('write', $contents, $this);

        if ($this->request->is('do=publish')) {
            /**  */
            $contents['type'] = 'page';
            $this->publish($contents, false);

            // 
            self::pluginHandle()->call('finishPublish', $contents, $this);

            /** ping */
            Service::alloc()->sendPing($this);

            /**  */
            Notice::alloc()->set(
                _t(' "<a href="%s">%s</a>" ', $this->permalink, $this->title),
                'success'
            );

            /**  */
            Notice::alloc()->highlight($this->theId);

            /**  */
            $this->response->redirect(Common::url('manage-pages.php'
                . ($this->parent ? '?parent=' . $this->parent : ''), $this->options->adminUrl));
        } else {
            /**  */
            $contents['type'] = 'page_draft';
            $draftId = $this->save($contents, false);

            // 
            self::pluginHandle()->call('finishSave', $contents, $this);

            /**  */
            Notice::alloc()->highlight($this->cid);

            if ($this->request->isAjax()) {
                $created = new Date($this->options->time);
                $this->response->throwJson([
                    'success' => 1,
                    'time'    => $created->format('H:i:s A'),
                    'cid'     => $this->cid,
                    'draftId' => $draftId
                ]);
            } else {
                /**  */
                Notice::alloc()->set(_t(' "%s" ', $this->title), 'success');

                /**  */
                $this->response->redirect(Common::url('write-page.php?cid=' . $this->cid, $this->options->adminUrl));
            }
        }
    }

    /**
     * 
     *
     * @throws DbException
     */
    public function markPage()
    {
        $status = $this->request->get('status');
        $statusList = [
            'publish' => _t(''),
            'hidden'  => _t('')
        ];

        if (!isset($statusList[$status])) {
            $this->response->goBack();
        }

        $pages = $this->request->filter('int')->getArray('cid');
        $markCount = 0;

        foreach ($pages as $page) {
            // 
            self::pluginHandle()->call('mark', $status, $page, $this);
            $condition = $this->db->sql()->where('cid = ?', $page);

            if ($this->db->query($condition->update('table.contents')->rows(['status' => $status]))) {
                // 
                $draft = $this->db->fetchRow($this->db->select('cid')
                    ->from('table.contents')
                    ->where('table.contents.parent = ? AND table.contents.type = ?', $page, 'revision')
                    ->limit(1));

                if (!empty($draft)) {
                    $this->db->query($this->db->update('table.contents')->rows(['status' => $status])
                        ->where('cid = ?', $draft['cid']));
                }

                // 
                self::pluginHandle()->call('finishMark', $status, $page, $this);

                $markCount++;
            }

            unset($condition);
        }

        /**  */
        Notice::alloc()
            ->set(
                $markCount > 0 ? _t('<strong>%s</strong>', $statusList[$status]) : _t(''),
                $markCount > 0 ? 'success' : 'notice'
            );

        /**  */
        $this->response->goBack();
    }

    /**
     * 
     *
     * @throws DbException
     */
    public function deletePage()
    {
        $pages = $this->request->filter('int')->getArray('cid');
        $deleteCount = 0;

        foreach ($pages as $page) {
            // 
            self::pluginHandle()->call('delete', $page, $this);
            $parent = $this->db->fetchObject($this->select()->where('cid = ?', $page))->parent;

            if ($this->delete($this->db->sql()->where('cid = ?', $page))) {
                /**  */
                $this->db->query($this->db->delete('table.comments')
                    ->where('cid = ?', $page));

                /**  */
                $this->unAttach($page);

                /**  */
                if ($this->options->frontPage == 'page:' . $page) {
                    $this->db->query($this->db->update('table.options')
                        ->rows(['value' => 'recent'])
                        ->where('name = ?', 'frontPage'));
                }

                /**  */
                $draft = $this->db->fetchRow($this->db->select('cid')
                    ->from('table.contents')
                    ->where('table.contents.parent = ? AND table.contents.type = ?', $page, 'revision')
                    ->limit(1));

                /**  */
                $this->deleteFields($page);

                if ($draft) {
                    $this->deleteContent($draft['cid'], false);
                    $this->deleteFields($draft['cid']);
                }

                // update parent
                $this->update(
                    ['parent' => $parent],
                    $this->db->sql()->where('parent = ?', $page)
                        ->where('type = ? OR type = ?', 'page', 'page_draft')
                );

                // 
                self::pluginHandle()->call('finishDelete', $page, $this);

                $deleteCount++;
            }
        }

        /**  */
        Notice::alloc()
            ->set(
                $deleteCount > 0 ? _t('') : _t(''),
                $deleteCount > 0 ? 'success' : 'notice'
            );

        /**  */
        $this->response->goBack();
    }

    /**
     * 
     *
     * @throws DbException
     */
    public function deletePageDraft()
    {
        $pages = $this->request->filter('int')->getArray('cid');
        $deleteCount = 0;

        foreach ($pages as $page) {
            /**  */
            $draft = $this->db->fetchRow($this->db->select('cid')
                ->from('table.contents')
                ->where('table.contents.parent = ? AND table.contents.type = ?', $page, 'revision')
                ->limit(1));

            if ($draft) {
                $this->deleteContent($draft['cid'], false);
                $this->deleteFields($draft['cid']);
                $deleteCount++;
            }
        }

        /**  */
        Notice::alloc()
            ->set(
                $deleteCount > 0 ? _t('') : _t(''),
                $deleteCount > 0 ? 'success' : 'notice'
            );

        /**  */
        $this->response->goBack();
    }

    /**
     * 
     *
     * @throws DbException
     */
    public function sortPage()
    {
        $pages = $this->request->filter('int')->getArray('cid');

        if ($pages) {
            foreach ($pages as $sort => $cid) {
                $this->db->query($this->db->update('table.contents')->rows(['order' => $sort + 1])
                    ->where('cid = ?', $cid));
            }
        }

        if (!$this->request->isAjax()) {
            /**  */
            $this->response->goBack();
        } else {
            $this->response->throwJson(['success' => 1, 'message' => _t('')]);
        }
    }

    /**
     * @return $this
     * @throws DbException
     * @throws Exception
     */
    public function prepare(): self
    {
        return $this->prepareEdit('page', true, _t(''));
    }

    /**
     * 
     *
     * @return void
     * @throws DbException
     * @throws Exception
     */
    public function action()
    {
        $this->security->protect();
        $this->on($this->request->is('do=publish') || $this->request->is('do=save'))
            ->prepare()->writePage();
        $this->on($this->request->is('do=delete'))->deletePage();
        $this->on($this->request->is('do=mark'))->markPage();
        $this->on($this->request->is('do=deleteDraft'))->deletePageDraft();
        $this->on($this->request->is('do=sort'))->sortPage();
        $this->response->redirect($this->options->adminUrl);
    }

    /**
     * 
     *
     * @return string
     */
    public function getMenuTitle(): string
    {
        $this->prepare();

        if ($this->have()) {
            return _t(' %s', $this->title);
        }

        if ($this->request->is('parent')) {
            $page = $this->db->fetchRow($this->select()
                ->where('table.contents.type = ? OR table.contents.type', 'page', 'page_draft')
                ->where('table.contents.cid = ?', $this->request->filter('int')->get('parent')));

            if (!empty($page)) {
                return _t(' %s ', $page['title']);
            }
        }

        throw new Exception(_t(''), 404);
    }


    /**
     * @return int
     */
    public function getParent(): int
    {
        if ($this->request->is('parent')) {
            $parent = $this->request->filter('int')->get('parent');

            if (!$this->have() || $this->cid != $parent) {
                $parentPage = $this->db->fetchRow($this->select()
                    ->where('table.contents.type = ? OR table.contents.type = ?', 'page', 'page_draft')
                    ->where('table.contents.cid = ?', $parent));

                if (!empty($parentPage)) {
                    return $parent;
                }
            }
        }

        return 0;
    }

    /**
     * @return string
     */
    protected function getThemeFieldsHook(): string
    {
        return 'themePageFields';
    }
}
 ?>

Did this file decode correctly?

Original Code

<?php

namespace Widget\Contents\Page;

use Typecho\Common;
use Typecho\Date;
use Typecho\Db\Exception as DbException;
use Typecho\Widget\Exception;
use Widget\Base\Contents;
use Widget\Contents\EditTrait;
use Widget\ActionInterface;
use Widget\Contents\PrepareEditTrait;
use Widget\Notice;
use Widget\Service;

if (!defined('__TYPECHO_ROOT_DIR__')) {
    exit;
}

/**
 * 
 *
 * @property-read array $draft
 */
class Edit extends Contents implements ActionInterface
{
    use PrepareEditTrait;
    use EditTrait;

    /**
     * 
     *
     * @access public
     * @return void
     * @throws Exception
     * @throws DbException
     */
    public function execute()
    {
        /**  */
        $this->user->pass('editor');
    }

    /**
     * 
     */
    public function writePage()
    {
        $contents = $this->request->from(
            'text',
            'template',
            'allowComment',
            'allowPing',
            'allowFeed',
            'slug',
            'order',
            'visibility'
        );

        $contents['title'] = $this->request->get('title', _t(''));
        $contents['created'] = $this->getCreated();
        $contents['visibility'] = ('hidden' == $contents['visibility'] ? 'hidden' : 'publish');
        $contents['parent'] = $this->getParent();

        if ($this->request->is('markdown=1') && $this->options->markdown) {
            $contents['text'] = '<!--markdown-->' . $contents['text'];
        }

        $contents = self::pluginHandle()->call('write', $contents, $this);

        if ($this->request->is('do=publish')) {
            /**  */
            $contents['type'] = 'page';
            $this->publish($contents, false);

            // 
            self::pluginHandle()->call('finishPublish', $contents, $this);

            /** ping */
            Service::alloc()->sendPing($this);

            /**  */
            Notice::alloc()->set(
                _t(' "<a href="%s">%s</a>" ', $this->permalink, $this->title),
                'success'
            );

            /**  */
            Notice::alloc()->highlight($this->theId);

            /**  */
            $this->response->redirect(Common::url('manage-pages.php'
                . ($this->parent ? '?parent=' . $this->parent : ''), $this->options->adminUrl));
        } else {
            /**  */
            $contents['type'] = 'page_draft';
            $draftId = $this->save($contents, false);

            // 
            self::pluginHandle()->call('finishSave', $contents, $this);

            /**  */
            Notice::alloc()->highlight($this->cid);

            if ($this->request->isAjax()) {
                $created = new Date($this->options->time);
                $this->response->throwJson([
                    'success' => 1,
                    'time'    => $created->format('H:i:s A'),
                    'cid'     => $this->cid,
                    'draftId' => $draftId
                ]);
            } else {
                /**  */
                Notice::alloc()->set(_t(' "%s" ', $this->title), 'success');

                /**  */
                $this->response->redirect(Common::url('write-page.php?cid=' . $this->cid, $this->options->adminUrl));
            }
        }
    }

    /**
     * 
     *
     * @throws DbException
     */
    public function markPage()
    {
        $status = $this->request->get('status');
        $statusList = [
            'publish' => _t(''),
            'hidden'  => _t('')
        ];

        if (!isset($statusList[$status])) {
            $this->response->goBack();
        }

        $pages = $this->request->filter('int')->getArray('cid');
        $markCount = 0;

        foreach ($pages as $page) {
            // 
            self::pluginHandle()->call('mark', $status, $page, $this);
            $condition = $this->db->sql()->where('cid = ?', $page);

            if ($this->db->query($condition->update('table.contents')->rows(['status' => $status]))) {
                // 
                $draft = $this->db->fetchRow($this->db->select('cid')
                    ->from('table.contents')
                    ->where('table.contents.parent = ? AND table.contents.type = ?', $page, 'revision')
                    ->limit(1));

                if (!empty($draft)) {
                    $this->db->query($this->db->update('table.contents')->rows(['status' => $status])
                        ->where('cid = ?', $draft['cid']));
                }

                // 
                self::pluginHandle()->call('finishMark', $status, $page, $this);

                $markCount++;
            }

            unset($condition);
        }

        /**  */
        Notice::alloc()
            ->set(
                $markCount > 0 ? _t('<strong>%s</strong>', $statusList[$status]) : _t(''),
                $markCount > 0 ? 'success' : 'notice'
            );

        /**  */
        $this->response->goBack();
    }

    /**
     * 
     *
     * @throws DbException
     */
    public function deletePage()
    {
        $pages = $this->request->filter('int')->getArray('cid');
        $deleteCount = 0;

        foreach ($pages as $page) {
            // 
            self::pluginHandle()->call('delete', $page, $this);
            $parent = $this->db->fetchObject($this->select()->where('cid = ?', $page))->parent;

            if ($this->delete($this->db->sql()->where('cid = ?', $page))) {
                /**  */
                $this->db->query($this->db->delete('table.comments')
                    ->where('cid = ?', $page));

                /**  */
                $this->unAttach($page);

                /**  */
                if ($this->options->frontPage == 'page:' . $page) {
                    $this->db->query($this->db->update('table.options')
                        ->rows(['value' => 'recent'])
                        ->where('name = ?', 'frontPage'));
                }

                /**  */
                $draft = $this->db->fetchRow($this->db->select('cid')
                    ->from('table.contents')
                    ->where('table.contents.parent = ? AND table.contents.type = ?', $page, 'revision')
                    ->limit(1));

                /**  */
                $this->deleteFields($page);

                if ($draft) {
                    $this->deleteContent($draft['cid'], false);
                    $this->deleteFields($draft['cid']);
                }

                // update parent
                $this->update(
                    ['parent' => $parent],
                    $this->db->sql()->where('parent = ?', $page)
                        ->where('type = ? OR type = ?', 'page', 'page_draft')
                );

                // 
                self::pluginHandle()->call('finishDelete', $page, $this);

                $deleteCount++;
            }
        }

        /**  */
        Notice::alloc()
            ->set(
                $deleteCount > 0 ? _t('') : _t(''),
                $deleteCount > 0 ? 'success' : 'notice'
            );

        /**  */
        $this->response->goBack();
    }

    /**
     * 
     *
     * @throws DbException
     */
    public function deletePageDraft()
    {
        $pages = $this->request->filter('int')->getArray('cid');
        $deleteCount = 0;

        foreach ($pages as $page) {
            /**  */
            $draft = $this->db->fetchRow($this->db->select('cid')
                ->from('table.contents')
                ->where('table.contents.parent = ? AND table.contents.type = ?', $page, 'revision')
                ->limit(1));

            if ($draft) {
                $this->deleteContent($draft['cid'], false);
                $this->deleteFields($draft['cid']);
                $deleteCount++;
            }
        }

        /**  */
        Notice::alloc()
            ->set(
                $deleteCount > 0 ? _t('') : _t(''),
                $deleteCount > 0 ? 'success' : 'notice'
            );

        /**  */
        $this->response->goBack();
    }

    /**
     * 
     *
     * @throws DbException
     */
    public function sortPage()
    {
        $pages = $this->request->filter('int')->getArray('cid');

        if ($pages) {
            foreach ($pages as $sort => $cid) {
                $this->db->query($this->db->update('table.contents')->rows(['order' => $sort + 1])
                    ->where('cid = ?', $cid));
            }
        }

        if (!$this->request->isAjax()) {
            /**  */
            $this->response->goBack();
        } else {
            $this->response->throwJson(['success' => 1, 'message' => _t('')]);
        }
    }

    /**
     * @return $this
     * @throws DbException
     * @throws Exception
     */
    public function prepare(): self
    {
        return $this->prepareEdit('page', true, _t(''));
    }

    /**
     * 
     *
     * @return void
     * @throws DbException
     * @throws Exception
     */
    public function action()
    {
        $this->security->protect();
        $this->on($this->request->is('do=publish') || $this->request->is('do=save'))
            ->prepare()->writePage();
        $this->on($this->request->is('do=delete'))->deletePage();
        $this->on($this->request->is('do=mark'))->markPage();
        $this->on($this->request->is('do=deleteDraft'))->deletePageDraft();
        $this->on($this->request->is('do=sort'))->sortPage();
        $this->response->redirect($this->options->adminUrl);
    }

    /**
     * 
     *
     * @return string
     */
    public function getMenuTitle(): string
    {
        $this->prepare();

        if ($this->have()) {
            return _t(' %s', $this->title);
        }

        if ($this->request->is('parent')) {
            $page = $this->db->fetchRow($this->select()
                ->where('table.contents.type = ? OR table.contents.type', 'page', 'page_draft')
                ->where('table.contents.cid = ?', $this->request->filter('int')->get('parent')));

            if (!empty($page)) {
                return _t(' %s ', $page['title']);
            }
        }

        throw new Exception(_t(''), 404);
    }


    /**
     * @return int
     */
    public function getParent(): int
    {
        if ($this->request->is('parent')) {
            $parent = $this->request->filter('int')->get('parent');

            if (!$this->have() || $this->cid != $parent) {
                $parentPage = $this->db->fetchRow($this->select()
                    ->where('table.contents.type = ? OR table.contents.type = ?', 'page', 'page_draft')
                    ->where('table.contents.cid = ?', $parent));

                if (!empty($parentPage)) {
                    return $parent;
                }
            }
        }

        return 0;
    }

    /**
     * @return string
     */
    protected function getThemeFieldsHook(): string
    {
        return 'themePageFields';
    }
}

Function Calls

None

Variables

None

Stats

MD5 6416c09de7d923d6c9097ef8ccf41a8d
Eval Count 0
Decode Time 81 ms