-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfonts_model.php
executable file
·121 lines (103 loc) · 3.29 KB
/
fonts_model.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
use CFPropertyList\CFPropertyList;
class Fonts_model extends \Model {
function __construct($serial='')
{
parent::__construct('id', 'fonts'); //primary key, tablename
$this->rs['id'] = '';
$this->rs['serial_number'] = $serial;
$this->rs['name'] = '';
$this->rs['enabled'] = 0; // True or False
$this->rs['type_name'] = '';
$this->rs['fullname'] = '';
$this->rs['type_enabled'] = 0; // True or False
$this->rs['valid'] = 0; // True or False
$this->rs['duplicate'] = 0; // True or False
$this->rs['path'] = '';
$this->rs['type'] = '';
$this->rs['family'] = '';
$this->rs['style'] = '';
$this->rs['version'] = '';
$this->rs['embeddable'] = 0; // True or False
$this->rs['outline'] = 0; // True or False
$this->rs['unique_id'] = '';
$this->rs['copyright'] = ''; $this->rt['copyright'] = 'TEXT';
$this->rs['copy_protected'] = 0; // True or False
$this->rs['description'] = ''; $this->rt['description'] = 'TEXT';
$this->rs['vendor'] = ''; $this->rt['vendor'] = 'TEXT';
$this->rs['designer'] = ''; $this->rt['designer'] = 'TEXT';
$this->rs['trademark'] = ''; $this->rt['trademark'] = 'TEXT';
$this->serial_number = $serial;
}
// ------------------------------------------------------------------------
/**
* Get font names for widget
*
**/
public function get_fonts()
{
$out = array();
$sql = "SELECT COUNT(CASE WHEN type_name <> '' AND type_name IS NOT NULL THEN 1 END) AS count, type_name
FROM fonts
LEFT JOIN reportdata USING (serial_number)
".get_machine_group_filter()."
GROUP BY type_name
ORDER BY count DESC";
foreach ($this->query($sql) as $obj) {
if ("$obj->count" !== "0") {
$obj->type_name = $obj->type_name ? $obj->type_name : 'Unknown';
$out[] = $obj;
}
}
return $out;
}
/**
* Process data sent by postflight
*
* @param string data
* @author tuxudo
**/
function process($plist)
{
if ( ! $plist){
throw new Exception("Error Processing Request: No property list found", 1);
}
// Delete previous set
$this->deleteWhere('serial_number=?', $this->serial_number);
$parser = new CFPropertyList();
$parser->parse($plist, CFPropertyList::FORMAT_XML);
$myList = $parser->toArray();
foreach ($myList as $font) {
// Check if we have a name
if( ! array_key_exists("name", $font)){
continue;
}
// Format font type
if (isset($font['type'])){
$font['type'] = str_replace(array('opentype','truetype','postscript','bitmap'), array('OpenType','TrueType','PostScript','Bitmap'), $font['type']);
}
// Format Unique ID
if (isset($font['unique_id'])){
$font['unique_id'] = trim($font['unique_id'], '.');
}
// Format Typeface name
if (isset($font['type_name'])){
$font['type_name'] = trim($font['type_name'], '.');
}
// Format family
if (isset($font['family'])){
$font['family'] = trim($font['family'], '.');
}
foreach ($this->rs as $key => $value) {
$this->rs[$key] = $value;
if(array_key_exists($key, $font))
{
$this->rs[$key] = $font[$key];
}
}
// Save the font
$this->id = '';
$this->save();
}
}
}