PHP 8.3.27
Preview: class.page.php Size: 10.59 KB
/home7/doctorbruno/public_html/taeionline.com/support/include/class.page.php
<?php
/*********************************************************************
    class.page.php

    Page class

    Copyright (c)  2006-2013 osTicket
    http://www.osticket.com

    Released under the GNU General Public License WITHOUT ANY WARRANTY.
    See LICENSE.TXT for details.

    vim: expandtab sw=4 ts=4 sts=4:
**********************************************************************/

class Page extends VerySimpleModel {

    static $meta = array(
        'table' => PAGE_TABLE,
        'pk' => array('id'),
        'ordering' => array('name'),
        'defer' => array('body'),
        'joins' => array(
            'topics' => array(
                'reverse' => 'Topic.page',
            ),
            'attachments' => array(
                'constraint' => array(
                    "'P'" => 'Attachment.type',
                    'id' => 'Attachment.object_id',
                ),
                'list' => true,
                'null' => true,
                'broker' => 'GenericAttachments',
            ),
        ),
    );

    var $_local;

    function getId() {
        return $this->id;
    }

    function getHashtable() {
        $base = $this->ht;
        unset($base['topics']);
        unset($base['attachments']);
        return $base;
    }

    function getType() {
        return $this->type;
    }

    function getName() {
        return $this->name;
    }
    function getLocalName($lang=false) {
        return $this->_getLocal('name', $lang);
    }
    function getNameAsSlug() {
        return urlencode(Format::slugify($this->name));
    }

    function getBody() {
        return $this->body;
    }
    function getLocalBody($lang=false) {
        return $this->_getLocal('body', $lang);
    }
    function getBodyWithImages() {
        return Format::viewableImages($this->getLocalBody(), ['type' => 'P']);
    }

    function _getLocal($what, $lang=false) {
        if (!$lang) {
            $lang = Internationalization::getCurrentLanguage();
        }
        $translations = $this->getAllTranslations();
        foreach ($translations as $t) {
            if ($lang == $t->lang) {
                $data = $t->getComplex();
                if (isset($data[$what]))
                    return $data[$what];
            }
        }
        return $this->ht[$what];
    }

    function getAllTranslations() {
        if (!isset($this->_local)) {
            $tag = $this->getTranslateTag('name:body');
            $this->_local = CustomDataTranslation::allTranslations($tag, 'article');
        }
        return $this->_local;
    }

    function getNotes() {
        return $this->notes;
    }

    function isActive() {
        return ($this->isactive);
    }

    function isInUse() {
        global $cfg;

        return  ($this->getNumTopics()
                    || in_array($this->getId(), $cfg->getDefaultPages()));
    }


    function getCreateDate() {
        return $this->created;
    }

    function getUpdateDate() {
        return $this->updated;
    }

    function getNumTopics() {
        return $this->topics->count();
    }

    function getTranslateTag($subtag) {
        return _H(sprintf('page.%s.%s', $subtag, $this->getId()));
    }
    function getLocal($subtag) {
        $tag = $this->getTranslateTag($subtag);
        $T = CustomDataTranslation::translate($tag);
        return $T != $tag ? $T : $this->ht[$subtag];
    }

    function disable() {

        if(!$this->isActive())
            return true;

        if($this->isInUse())
            return false;


        $this->isactive = 0;
        return $this->save();
    }

    function delete() {

        if ($this->isInUse())
            return false;

        if (!parent::delete())
            return false;

        $type = array('type' => 'deleted');
        Signal::send('object.deleted', $this, $type);
        return true;
    }

    function save($refetch=false) {
        if ($this->dirty)
            $this->updated = SqlFunction::NOW();
        return parent::save($refetch || $this->dirty);
    }

    /* ------------------> Static methods <--------------------- */

    static function create($vars=false) {
        $page = new static($vars);
        $page->created = SqlFunction::NOW();
        return $page;
    }

    function add($vars, &$errors) {
        if(!($id=self::create($vars, $errors)))
            return false;

        return self::lookup($id);
    }

    static function getPages($criteria=array()) {
        $pages = self::objects();
        if(isset($criteria['active']))
            $pages = $pages->filter(array('isactive'=>$criteria['active']));
        if(isset($criteria['type']))
            $pages = $pages->filter(array('type'=>$criteria['type']));

        return $pages;
    }

    static function getActivePages($criteria=array()) {

        $criteria = array_merge($criteria, array('active'=>true));

        return self::getPages($criteria);
    }

    static function getActiveThankYouPages() {
        return self::getActivePages(array('type' => 'thank-you'));
    }

    static function lookup($id, $lang=false) {
        try {
            $qs = self::objects()->filter(is_array($id) ? $id : array('id'=>$id));
            if ($lang)
                $qs = $qs->filter(array('lang'=>$lang));
            return $qs->one();
        }
        catch (DoesNotExist $ex) {
            return null;
        }
    }

    static function getIdByName($name, $lang=false) {
        try {
            $qs = self::objects()->filter(array('name'=>$name))
                ->values_flat('id');
            list($id) = $qs->one();
            return $id;
        }
        catch (DoesNotExist $ex) {
            return null;
        }
        catch (InconsistentModelException $ex) {
            // This largely happens on upgrades, and may specifically cause
            // the staff login box to crash
            return null;
        }
    }

    static function lookupByType($type, $lang=false) {
        try {
            return self::objects()->filter(array('type'=>$type))->one();
        }
        catch (DoesNotExist | InconsistentModelException $ex) {
            return null;
        }
    }

    function update($vars, &$errors, $allowempty=false) {
        //Cleanup.
        $vars['name']=Format::striptags(trim($vars['name']));

        //validate
        if (isset($this->id) && !$vars['isactive'] && $this->isInUse()) {
            $errors['err'] = __('A page currently in-use CANNOT be disabled!');
            $errors['isactive'] = __('Page is in-use!');
        }

        if (isset($this->id) && $this->getId() != $vars['id'])
            $errors['err'] = sprintf('%s - %s', __('Internal error occurred'), __('Please try again!'));

        if(!$vars['type'])
            $errors['type'] = __('Type is required');

        if(!$vars['name'])
            $errors['name'] = __('Name is required');
        elseif(($pid=self::getIdByName($vars['name'])) && $pid!=$this->getId())
            $errors['name'] = __('Name already exists');

        if(!$vars['body'] && !$allowempty)
            $errors['body'] = __('Page body is required');

        if($errors) return false;

        $this->type = $vars['type'];
        $this->name = $vars['name'];
        $this->body = Format::sanitize($vars['body']);
        $this->isactive = (bool) $vars['isactive'];
        $this->notes = Format::sanitize($vars['notes']);

        $isnew = !isset($this->id);
        $rv = $this->save();
        if (!$isnew)
            $rv = $this->saveTranslations($vars, $errors);

        // Attach inline attachments from the editor
        $keepers = Draft::getAttachmentIds($vars['body']);
        $keepers = array_flip(array_map(function($i) { return $i['id']; }, $keepers));
        $this->attachments->keepOnlyFileIds($keepers, true);

        if ($rv)
            return $rv;

        $errors['err']=sprintf(__('Unable to update %s.'), __('this site page'));
        return false;
    }

    function saveTranslations($vars, &$errors) {
        global $thisstaff;

        $tag = $this->getTranslateTag('name:body');
        $translations = CustomDataTranslation::allTranslations($tag, 'article');
        foreach ($translations as $t) {
            $title = @$vars['trans'][$t->lang]['title'];
            $body = @$vars['trans'][$t->lang]['body'];
            if (!$title && !$body)
                continue;

            // Content is not new and shouldn't be added below
            unset($vars['trans'][$t->lang]['title']);
            unset($vars['trans'][$t->lang]['body']);
            $content = array('name' => $title, 'body' => Format::sanitize($body));

            // Don't update content which wasn't updated
            if ($content == $t->getComplex())
                continue;

            $t->text = $content;
            $t->agent_id = $thisstaff->getId();
            $t->updated = SqlFunction::NOW();
            if (!$t->save())
                return false;
        }
        // New translations (?)
        foreach ($vars['trans'] ?: array() as $lang=>$parts) {
            $content = array('name' => @$parts['title'], 'body' => Format::sanitize(@$parts['body']));
            if (!array_filter($content))
                continue;
            $t = CustomDataTranslation::create(array(
                'type'      => 'article',
                'object_hash' => $tag,
                'lang'      => $lang,
                'text'      => $content,
                'revision'  => 1,
                'agent_id'  => $thisstaff->getId(),
                'updated'   => SqlFunction::NOW(),
            ));
            if (!$t->save())
                return false;
        }
        return true;
    }

    static function getContext($type) {
        $context = array(
        'thank-you' => array('ticket'),
        'registration-staff' => array(
            // 'token' => __('Special authentication token'),
            'staff' => array('class' => 'Staff', 'desc' => __('Message recipient')),
            'recipient' => array('class' => 'Staff', 'desc' => __('Message recipient')),
            'link',
        ),
        'pwreset-staff' => array(
            'staff' => array('class' => 'Staff', 'desc' => __('Message recipient')),
            'recipient' => array('class' => 'Staff', 'desc' => __('Message recipient')),
            'link',
        ),
        'registration-client' => array(
            // 'token' => __('Special authentication token'),
            'recipient' => array('class' => 'User', 'desc' => __('Message recipient')),
            'link', 'user',
        ),
        'pwreset-client' => array(
            'recipient' => array('class' => 'User', 'desc' => __('Message recipient')),
            'link', 'user',
        ),
        'access-link' => array('ticket', 'recipient'),
        );

        return $context[$type];
    }
}
?>

Directory Contents

Dirs: 11 × Files: 132
Name Size Perms Modified Actions
cli DIR
- drwxr-xr-x 2026-10-02 10:08:28
Edit Download
client DIR
- drwxr-xr-x 2026-10-02 10:08:28
Edit Download
config DIR
- drwxr-xr-x 2017-09-15 04:26:55
Edit Download
fpdf DIR
- drwxr-xr-x 2026-10-02 10:08:28
Edit Download
i18n DIR
- drwxr-xr-x 2026-10-02 10:08:28
Edit Download
- drwxr-xr-x 2026-10-02 10:08:28
Edit Download
mpdf DIR
- drwxr-xr-x 2026-10-02 10:08:28
Edit Download
pear DIR
- drwxr-xr-x 2026-10-02 10:08:29
Edit Download
plugins DIR
- drwxr-xr-x 2026-10-02 10:08:29
Edit Download
staff DIR
- drwxr-xr-x 2026-10-02 10:08:29
Edit Download
upgrader DIR
- drwxr-xr-x 2026-10-02 10:08:29
Edit Download
14 B lrw-r--r-- 2025-02-04 09:58:56
Edit Download
194.97 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
7.29 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
4.61 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
9.76 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
13.03 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
2.33 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
1006 B lrw-r--r-- 2025-02-04 09:58:56
Edit Download
874 B lrw-r--r-- 2025-02-04 09:58:56
Edit Download
13.84 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
5.10 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
2.93 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
2.05 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
11.73 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
2.15 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
4.29 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
12.72 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
3.20 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
11.62 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
33.87 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
8.81 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
79.70 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
1.66 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
2.24 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
18.33 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
1.06 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
10.36 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
7.76 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
1.45 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
15.31 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
1.49 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
6.95 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
50.73 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
6.44 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
2.58 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
4.07 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
7.08 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
9.05 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
1.73 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
11.14 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
3.41 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
9.48 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
15.39 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
5.65 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
2.65 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
60.36 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
1.15 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
3.60 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
18.92 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
2.38 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
33.21 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
7.12 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
6.23 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
64.98 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
49.00 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
1.69 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
32.92 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
15.05 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
34.59 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
31.90 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
23.67 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
44.30 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
195.58 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
7.16 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
24.28 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
6.90 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
2.71 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
5.80 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
42.00 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
4.05 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
1.55 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
35.76 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
25.75 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
9.72 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
30.99 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
6.42 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
5.20 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
7.50 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
2.30 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
14.15 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
2.39 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
4.04 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
22.45 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
120.90 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
20.64 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
21.86 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
10.59 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
5.53 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
1.21 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
3.83 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
36.13 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
1.81 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
103.51 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
11.76 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
11.27 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
46.28 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
61.66 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
7.27 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
19.25 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
3.55 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
4.16 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
9.11 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
60.21 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
56.21 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
12.31 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
23.45 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
108.96 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
17.08 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
167.39 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
21.94 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
20.06 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
34.79 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
13.76 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
43.40 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
7.55 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
10.07 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
12.94 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
11.93 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
3.23 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
1.15 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
33.71 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
53.53 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
37 B lrw-r--r-- 2025-02-04 09:58:56
Edit Download
44 B lrw-r--r-- 2026-10-02 10:08:28
Edit Download
33.13 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
9.55 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
5.63 KB lr--r--r-- 2017-09-16 04:37:08
Edit Download
6.24 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
6.92 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
31.74 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
19.82 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
8.61 KB lrw-r--r-- 2025-02-04 09:58:56
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).