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\Metas\Tag; use Typecho\Common; use Typecho\Db\Exception; use Type..

Decoded Output download

<?php

namespace Widget\Metas\Tag;

use Typecho\Common;
use Typecho\Db\Exception;
use Typecho\Widget\Helper\Form;
use Widget\Base\Metas;
use Widget\ActionInterface;
use Widget\Metas\EditTrait;
use Widget\Notice;

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

/**
 * 
 *
 * @author qining
 * @category typecho
 * @package Widget
 * @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
 * @license GNU General Public License 2.0
 */
class Edit extends Metas implements ActionInterface
{
    use EditTrait;

    /**
     * 
     */
    public function execute()
    {
        /**  */
        $this->user->pass('editor');
    }

    /**
     * 
     *
     * @param integer $mid 
     * @return boolean
     * @throws Exception
     */
    public function tagExists(int $mid): bool
    {
        $tag = $this->db->fetchRow($this->db->select()
            ->from('table.metas')
            ->where('type = ?', 'tag')
            ->where('mid = ?', $mid)->limit(1));

        return isset($tag);
    }

    /**
     * 
     *
     * @param string $name 
     * @return boolean
     * @throws Exception
     */
    public function nameExists(string $name): bool
    {
        $select = $this->db->select()
            ->from('table.metas')
            ->where('type = ?', 'tag')
            ->where('name = ?', $name)
            ->limit(1);

        if ($this->request->is('mid')) {
            $select->where('mid <> ?', $this->request->filter('int')->get('mid'));
        }

        $tag = $this->db->fetchRow($select);
        return !$tag;
    }

    /**
     * 
     *
     * @param string $name 
     * @return boolean
     * @throws Exception
     */
    public function nameToSlug(string $name): bool
    {
        if (empty($this->request->slug)) {
            $slug = Common::slugName($name);
            if (empty($slug) || !$this->slugExists($name)) {
                return false;
            }
        }

        return true;
    }

    /**
     * 
     *
     * @param string $slug 
     * @return boolean
     * @throws Exception
     */
    public function slugExists(string $slug): bool
    {
        $select = $this->db->select()
            ->from('table.metas')
            ->where('type = ?', 'tag')
            ->where('slug = ?', Common::slugName($slug))
            ->limit(1);

        if ($this->request->is('mid')) {
            $select->where('mid <> ?', $this->request->get('mid'));
        }

        $tag = $this->db->fetchRow($select);
        return !$tag;
    }

    /**
     * 
     *
     * @throws Exception
     */
    public function insertTag()
    {
        if ($this->form('insert')->validate()) {
            $this->response->goBack();
        }

        /**  */
        $tag = $this->request->from('name', 'slug');
        $tag['type'] = 'tag';
        $tag['slug'] = Common::slugName(Common::strBy($tag['slug'] ?? null, $tag['name']));

        /**  */
        $tag['mid'] = $this->insert($tag);
        $this->push($tag);

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

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

        /**  */
        $this->response->redirect(Common::url('manage-tags.php', $this->options->adminUrl));
    }

    /**
     * 
     *
     * @param string|null $action 
     * @return Form
     * @throws Exception
     */
    public function form(?string $action = null): Form
    {
        /**  */
        $form = new Form($this->security->getIndex('/action/metas-tag-edit'), Form::POST_METHOD);

        /**  */
        $name = new Form\Element\Text(
            'name',
            null,
            null,
            _t('') . ' *',
            _t('., "".')
        );
        $form->addInput($name);

        /**  */
        $slug = new Form\Element\Text(
            'slug',
            null,
            null,
            _t(''),
            _t(', .')
        );
        $form->addInput($slug);

        /**  */
        $do = new Form\Element\Hidden('do');
        $form->addInput($do);

        /**  */
        $mid = new Form\Element\Hidden('mid');
        $form->addInput($mid);

        /**  */
        $submit = new Form\Element\Submit();
        $submit->input->setAttribute('class', 'btn primary');
        $form->addItem($submit);

        if ($this->request->is('mid') && 'insert' != $action) {
            /**  */
            $meta = $this->db->fetchRow($this->select()
                ->where('mid = ?', $this->request->get('mid'))
                ->where('type = ?', 'tag')->limit(1));

            if (!$meta) {
                $this->response->redirect(Common::url('manage-tags.php', $this->options->adminUrl));
            }

            $name->value($meta['name']);
            $slug->value($meta['slug']);
            $do->value('update');
            $mid->value($meta['mid']);
            $submit->value(_t(''));
            $_action = 'update';
        } else {
            $do->value('insert');
            $submit->value(_t(''));
            $_action = 'insert';
        }

        if (empty($action)) {
            $action = $_action;
        }

        /**  */
        if ('insert' == $action || 'update' == $action) {
            $name->addRule('required', _t(''));
            $name->addRule([$this, 'nameExists'], _t(''));
            $name->addRule([$this, 'nameToSlug'], _t(''));
            $name->addRule('xssCheck', _t(''));
            $slug->addRule([$this, 'slugExists'], _t(''));
            $slug->addRule('xssCheck', _t(''));
        }

        if ('update' == $action) {
            $mid->addRule('required', _t(''));
            $mid->addRule([$this, 'tagExists'], _t(''));
        }

        return $form;
    }

    /**
     * 
     *
     * @throws Exception
     */
    public function updateTag()
    {
        if ($this->form('update')->validate()) {
            $this->response->goBack();
        }

        /**  */
        $tag = $this->request->from('name', 'slug', 'mid');
        $tag['type'] = 'tag';
        $tag['slug'] = Common::slugName(Common::strBy($tag['slug'] ?? null, $tag['name']));

        /**  */
        $this->update($tag, $this->db->sql()->where('mid = ?', $this->request->filter('int')->get('mid')));
        $this->push($tag);

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

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

        /**  */
        $this->response->redirect(Common::url('manage-tags.php', $this->options->adminUrl));
    }

    /**
     * 
     *
     * @throws Exception
     */
    public function deleteTag()
    {
        $tags = $this->request->filter('int')->getArray('mid');
        $deleteCount = 0;

        if ($tags) {
            foreach ($tags as $tag) {
                if ($this->delete($this->db->sql()->where('mid = ?', $tag))) {
                    $this->db->query($this->db->delete('table.relationships')->where('mid = ?', $tag));
                    $deleteCount++;
                }
            }
        }

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

        /**  */
        $this->response->redirect(Common::url('manage-tags.php', $this->options->adminUrl));
    }

    /**
     * 
     *
     * @throws Exception
     */
    public function mergeTag()
    {
        if (empty($this->request->merge)) {
            Notice::alloc()->set(_t(''));
            $this->response->goBack();
        }

        $merge = $this->scanTags($this->request->get('merge'));
        if (empty($merge)) {
            Notice::alloc()->set(_t(''), 'error');
            $this->response->goBack();
        }

        $tags = $this->request->filter('int')->getArray('mid');

        if ($tags) {
            $this->merge($merge, 'tag', $tags);

            /**  */
            Notice::alloc()->set(_t(''), 'success');
        } else {
            Notice::alloc()->set(_t(''));
        }

        /**  */
        $this->response->redirect(Common::url('manage-tags.php', $this->options->adminUrl));
    }

    /**
     * 
     *
     * @access public
     * @return void
     * @throws Exception
     */
    public function refreshTag()
    {
        $tags = $this->request->filter('int')->getArray('mid');
        if ($tags) {
            foreach ($tags as $tag) {
                $this->refreshCountByTypeAndStatus($tag, 'post');
            }

            // 
            $this->clearTags();

            Notice::alloc()->set(_t(''), 'success');
        } else {
            Notice::alloc()->set(_t(''));
        }

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


    /**
     * 
     *
     * @throws Exception
     */
    public function clearTags()
    {
        // count0
        $tags = array_column($this->db->fetchAll($this->select('mid')
            ->where('type = ? AND count = ?', 'tags', 0)), 'mid');

        foreach ($tags as $tag) {
            // 
            $content = $this->db->fetchRow($this->db->select('cid')
                ->from('table.relationships')->where('mid = ?', $tag)
                ->limit(1));

            if (empty($content)) {
                $this->db->query($this->db->delete('table.metas')
                    ->where('mid = ?', $tag));
            }
        }
    }

    /**
     * ,
     *
     * @access public
     * @return void
     * @throws Exception
     */
    public function action()
    {
        $this->security->protect();
        $this->on($this->request->is('do=insert'))->insertTag();
        $this->on($this->request->is('do=update'))->updateTag();
        $this->on($this->request->is('do=delete'))->deleteTag();
        $this->on($this->request->is('do=merge'))->mergeTag();
        $this->on($this->request->is('do=refresh'))->refreshTag();
        $this->response->redirect($this->options->adminUrl);
    }
}
 ?>

Did this file decode correctly?

Original Code

<?php

namespace Widget\Metas\Tag;

use Typecho\Common;
use Typecho\Db\Exception;
use Typecho\Widget\Helper\Form;
use Widget\Base\Metas;
use Widget\ActionInterface;
use Widget\Metas\EditTrait;
use Widget\Notice;

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

/**
 * 
 *
 * @author qining
 * @category typecho
 * @package Widget
 * @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
 * @license GNU General Public License 2.0
 */
class Edit extends Metas implements ActionInterface
{
    use EditTrait;

    /**
     * 
     */
    public function execute()
    {
        /**  */
        $this->user->pass('editor');
    }

    /**
     * 
     *
     * @param integer $mid 
     * @return boolean
     * @throws Exception
     */
    public function tagExists(int $mid): bool
    {
        $tag = $this->db->fetchRow($this->db->select()
            ->from('table.metas')
            ->where('type = ?', 'tag')
            ->where('mid = ?', $mid)->limit(1));

        return isset($tag);
    }

    /**
     * 
     *
     * @param string $name 
     * @return boolean
     * @throws Exception
     */
    public function nameExists(string $name): bool
    {
        $select = $this->db->select()
            ->from('table.metas')
            ->where('type = ?', 'tag')
            ->where('name = ?', $name)
            ->limit(1);

        if ($this->request->is('mid')) {
            $select->where('mid <> ?', $this->request->filter('int')->get('mid'));
        }

        $tag = $this->db->fetchRow($select);
        return !$tag;
    }

    /**
     * 
     *
     * @param string $name 
     * @return boolean
     * @throws Exception
     */
    public function nameToSlug(string $name): bool
    {
        if (empty($this->request->slug)) {
            $slug = Common::slugName($name);
            if (empty($slug) || !$this->slugExists($name)) {
                return false;
            }
        }

        return true;
    }

    /**
     * 
     *
     * @param string $slug 
     * @return boolean
     * @throws Exception
     */
    public function slugExists(string $slug): bool
    {
        $select = $this->db->select()
            ->from('table.metas')
            ->where('type = ?', 'tag')
            ->where('slug = ?', Common::slugName($slug))
            ->limit(1);

        if ($this->request->is('mid')) {
            $select->where('mid <> ?', $this->request->get('mid'));
        }

        $tag = $this->db->fetchRow($select);
        return !$tag;
    }

    /**
     * 
     *
     * @throws Exception
     */
    public function insertTag()
    {
        if ($this->form('insert')->validate()) {
            $this->response->goBack();
        }

        /**  */
        $tag = $this->request->from('name', 'slug');
        $tag['type'] = 'tag';
        $tag['slug'] = Common::slugName(Common::strBy($tag['slug'] ?? null, $tag['name']));

        /**  */
        $tag['mid'] = $this->insert($tag);
        $this->push($tag);

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

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

        /**  */
        $this->response->redirect(Common::url('manage-tags.php', $this->options->adminUrl));
    }

    /**
     * 
     *
     * @param string|null $action 
     * @return Form
     * @throws Exception
     */
    public function form(?string $action = null): Form
    {
        /**  */
        $form = new Form($this->security->getIndex('/action/metas-tag-edit'), Form::POST_METHOD);

        /**  */
        $name = new Form\Element\Text(
            'name',
            null,
            null,
            _t('') . ' *',
            _t('., "".')
        );
        $form->addInput($name);

        /**  */
        $slug = new Form\Element\Text(
            'slug',
            null,
            null,
            _t(''),
            _t(', .')
        );
        $form->addInput($slug);

        /**  */
        $do = new Form\Element\Hidden('do');
        $form->addInput($do);

        /**  */
        $mid = new Form\Element\Hidden('mid');
        $form->addInput($mid);

        /**  */
        $submit = new Form\Element\Submit();
        $submit->input->setAttribute('class', 'btn primary');
        $form->addItem($submit);

        if ($this->request->is('mid') && 'insert' != $action) {
            /**  */
            $meta = $this->db->fetchRow($this->select()
                ->where('mid = ?', $this->request->get('mid'))
                ->where('type = ?', 'tag')->limit(1));

            if (!$meta) {
                $this->response->redirect(Common::url('manage-tags.php', $this->options->adminUrl));
            }

            $name->value($meta['name']);
            $slug->value($meta['slug']);
            $do->value('update');
            $mid->value($meta['mid']);
            $submit->value(_t(''));
            $_action = 'update';
        } else {
            $do->value('insert');
            $submit->value(_t(''));
            $_action = 'insert';
        }

        if (empty($action)) {
            $action = $_action;
        }

        /**  */
        if ('insert' == $action || 'update' == $action) {
            $name->addRule('required', _t(''));
            $name->addRule([$this, 'nameExists'], _t(''));
            $name->addRule([$this, 'nameToSlug'], _t(''));
            $name->addRule('xssCheck', _t(''));
            $slug->addRule([$this, 'slugExists'], _t(''));
            $slug->addRule('xssCheck', _t(''));
        }

        if ('update' == $action) {
            $mid->addRule('required', _t(''));
            $mid->addRule([$this, 'tagExists'], _t(''));
        }

        return $form;
    }

    /**
     * 
     *
     * @throws Exception
     */
    public function updateTag()
    {
        if ($this->form('update')->validate()) {
            $this->response->goBack();
        }

        /**  */
        $tag = $this->request->from('name', 'slug', 'mid');
        $tag['type'] = 'tag';
        $tag['slug'] = Common::slugName(Common::strBy($tag['slug'] ?? null, $tag['name']));

        /**  */
        $this->update($tag, $this->db->sql()->where('mid = ?', $this->request->filter('int')->get('mid')));
        $this->push($tag);

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

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

        /**  */
        $this->response->redirect(Common::url('manage-tags.php', $this->options->adminUrl));
    }

    /**
     * 
     *
     * @throws Exception
     */
    public function deleteTag()
    {
        $tags = $this->request->filter('int')->getArray('mid');
        $deleteCount = 0;

        if ($tags) {
            foreach ($tags as $tag) {
                if ($this->delete($this->db->sql()->where('mid = ?', $tag))) {
                    $this->db->query($this->db->delete('table.relationships')->where('mid = ?', $tag));
                    $deleteCount++;
                }
            }
        }

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

        /**  */
        $this->response->redirect(Common::url('manage-tags.php', $this->options->adminUrl));
    }

    /**
     * 
     *
     * @throws Exception
     */
    public function mergeTag()
    {
        if (empty($this->request->merge)) {
            Notice::alloc()->set(_t(''));
            $this->response->goBack();
        }

        $merge = $this->scanTags($this->request->get('merge'));
        if (empty($merge)) {
            Notice::alloc()->set(_t(''), 'error');
            $this->response->goBack();
        }

        $tags = $this->request->filter('int')->getArray('mid');

        if ($tags) {
            $this->merge($merge, 'tag', $tags);

            /**  */
            Notice::alloc()->set(_t(''), 'success');
        } else {
            Notice::alloc()->set(_t(''));
        }

        /**  */
        $this->response->redirect(Common::url('manage-tags.php', $this->options->adminUrl));
    }

    /**
     * 
     *
     * @access public
     * @return void
     * @throws Exception
     */
    public function refreshTag()
    {
        $tags = $this->request->filter('int')->getArray('mid');
        if ($tags) {
            foreach ($tags as $tag) {
                $this->refreshCountByTypeAndStatus($tag, 'post');
            }

            // 
            $this->clearTags();

            Notice::alloc()->set(_t(''), 'success');
        } else {
            Notice::alloc()->set(_t(''));
        }

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


    /**
     * 
     *
     * @throws Exception
     */
    public function clearTags()
    {
        // count0
        $tags = array_column($this->db->fetchAll($this->select('mid')
            ->where('type = ? AND count = ?', 'tags', 0)), 'mid');

        foreach ($tags as $tag) {
            // 
            $content = $this->db->fetchRow($this->db->select('cid')
                ->from('table.relationships')->where('mid = ?', $tag)
                ->limit(1));

            if (empty($content)) {
                $this->db->query($this->db->delete('table.metas')
                    ->where('mid = ?', $tag));
            }
        }
    }

    /**
     * ,
     *
     * @access public
     * @return void
     * @throws Exception
     */
    public function action()
    {
        $this->security->protect();
        $this->on($this->request->is('do=insert'))->insertTag();
        $this->on($this->request->is('do=update'))->updateTag();
        $this->on($this->request->is('do=delete'))->deleteTag();
        $this->on($this->request->is('do=merge'))->mergeTag();
        $this->on($this->request->is('do=refresh'))->refreshTag();
        $this->response->redirect($this->options->adminUrl);
    }
}

Function Calls

None

Variables

None

Stats

MD5 45031aa14106265d94ee38881806d04c
Eval Count 0
Decode Time 82 ms