Docs   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 64
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A show() 0 5 1
A getPages() 0 7 2
A exportData() 0 29 2
1
<?php
2
3
if (!defined('BASEPATH')) {
4
    exit('No direct script access allowed');
5
}
6
7
/**
8
 * Image CMS
9
 *
10
 * Backup Class
11
 *
12
 */
13
class Docs extends BaseAdminController
14
{
15
16
    protected $jsonListFile;
17
18
    protected $docsPath;
19
20
    public function __construct() {
21
        parent::__construct();
22
        $this->docsPath = PUBPATH . 'manual/';
23
        $this->jsonListFile = $this->docsPath . 'list.json';
24
25
        $this->load->library('DX_Auth');
26
        admin_or_redirect();
27
28
        $this->load->library('lib_admin');
29
        $this->lib_admin->init_settings();
30
    }
31
32
    public function show($pageName) {
33
        $page = file_get_contents($this->docsPath . "$pageName.html");
34
        $this->template->add_array(['page' => $page, 'd_b' => true, 'active_docs_page' => $pageName]);
35
        $this->template->show('docs', TRUE);
36
    }
37
38
    public function getPages() {
39
        $pages = (array) json_decode(file_get_contents($this->jsonListFile));
40
        foreach ($pages as $key => $page) {
41
            $pages[$key]->full_url = site_url('admin/docs/show/' . $page->full_url);
42
        }
43
        return $pages;
44
    }
45
46
    private function exportData() {
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
47
        $dsn = 'mysqli://root:root@localhost/premmerce';
48
        $db = $this->load->database($dsn, true);
49
50
        $result = $db->select(['title', 'url', 'full_text'])
51
            ->where(['lang' => '3', 'category' => 92, 'post_status' => 'publish'])
52
            ->order_by('position')
53
            ->get('content')->result_array();
54
        //        dd($result);
55
56
        $jsonsDataArray = [];
57
        foreach ($result as $pageFromDatabase) {
58
            $jsonsDataArray[] = [
59
                                 'full_url' => $pageFromDatabase['url'],
60
                                 'title'    => $pageFromDatabase['title'],
61
                                ];
62
63
            $pageTitle = '<div class="title-default-main"><div class="title">'
64
                    . $pageFromDatabase['title'] . '</div></div>';
65
66
            $pageFromDatabase['full_text'] = str_replace('/academy/start-s-nyla/filling-store', '/admin/docs/show', $pageFromDatabase['full_text']);
67
            $cont = $pageTitle . $pageFromDatabase['full_text'];
68
            $path = $this->docsPath . $pageFromDatabase['url'] . '.html';
69
70
            echo nl2br($path . "\n");
71
            $pageFromDatabase = file_put_contents($path, $cont);
72
        }
73
        file_put_contents($this->jsonListFile, json_encode($jsonsDataArray));
74
    }
75
76
}