Skip to content

Commit aee452d

Browse files
committed
Release
1 parent 74a86ac commit aee452d

File tree

21 files changed

+191
-81
lines changed

21 files changed

+191
-81
lines changed

controllers/fsCMS/AdminMDictionary.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ public function actionSave($param)
9292
$attr = $newXML->createAttribute('name');
9393
$attr->value = fsFunctions::Chpu($original);
9494
foreach($translate[$idx] as $lang => $value) {
95-
$tag = $newXML->createElement($lang, trim($value));
95+
$tag = $newXML->createElement($lang);
96+
$tag->appendChild($newXML->createCDATASection(trim($value)));
9697
$text->appendChild($tag);
9798
}
9899
$text->appendChild($attr);

controllers/fsCMS/AdminMPosts.php

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,15 @@ private function _CheckCategoryData(&$param)
2121
private function _CheckPostData(&$Param)
2222
{
2323
$id_category = $Param->id_category;
24-
if ($Param->title == '' ||
25-
$Param->alt == '' ||
26-
!is_array($id_category) ||
27-
count($id_category) == 0) {
24+
if ($Param->title == '' || $Param->alt == '' || !is_array($id_category) || count($id_category) == 0) {
2825
$this->Message(T('XMLcms_text_need_all_data'));
2926
$this->_Referer();
3027
return false;
3128
}
3229
$Param->alt = strtolower(fsFunctions::Chpu($Param->alt));
3330
$Param->active = $Param->Exists('active') ? 1 : 0;
3431
$Param->auth = $Param->Exists('auth') ? 1 : 0;
32+
$Param->id_user = $Param->Exists('id_user', true) ? $Param->id_user : fsSession::GetArrInstance('AUTH', 'id');
3533
if ($Param->time == '') {
3634
$Param->time = date('H:i:s');
3735
}
@@ -77,7 +75,7 @@ public function Init($request)
7775
public function actionAddPost($Param)
7876
{
7977
$posts_category = new posts_category();
80-
$posts_category = $posts_category->GetAll(true, false, array('name'));
78+
$posts_category = $posts_category->GetAll(true, false, array('id_parent', 'name'), 'id');
8179
if (count($posts_category) < 2) {
8280
$this->Message(T('XMLcms_text_no_category_found'));
8381
return $this->_Referer();
@@ -101,7 +99,7 @@ public function actionEditPost($param)
10199
$templates_short = fsFunctions::DirectoryInfo(PATH_TPL.CMSSettings::GetInstance('template').'/MPosts/', true, false, 'ShortPost', array('php'));
102100
$this->Tag('templates', $templates['NAMES']);
103101
$this->Tag('templates_short', $templates_short['NAMES']);
104-
$this->Tag('categories', $posts_category->GetAll(true, false, array('name')));
102+
$this->Tag('categories', $posts_category->GetAll(true, false, array('id_parent', 'name'), 'id'));
105103
$this->Tag('post', $this->_table->result);
106104
$this->Tag('post_categories', $post_category->GetByPostId($param->key));
107105
}
@@ -117,13 +115,13 @@ public function actionIndex($Param)
117115
{
118116
$posts_category = new posts_category();
119117
$this->Tag('table', $this->_PostsTable($Param));
120-
$this->Tag('categories', $posts_category->GetAll(true, false, array('name')));
118+
$this->Tag('categories', $posts_category->GetAll(true, false, array('name'), 'id'));
121119
}
122120

123121
public function actionCategories($Param)
124122
{
125123
$posts_category = new posts_category();
126-
$this->Tag('categories', $posts_category->GetAll(true, false, array('name')));
124+
$this->Tag('categories', $posts_category->GetAll(true, false, array('name'), 'id'));
127125
}
128126

129127
public function actionAjaxCategoryTemplate($Param)
@@ -141,6 +139,17 @@ public function actionAjaxCategoryTemplate($Param)
141139
$this->Json($result);
142140
}
143141

142+
private function _GetCategoriesAsArray()
143+
{
144+
$c = new posts_category();
145+
$all = $c->GetAll(true, false, array('id_parent', 'name'), 'id');
146+
$result = array();
147+
foreach($all as $c) {
148+
$result[$c['id']] = PostsFunctions::GetFullCategoryName($all, $c);
149+
}
150+
return $result;
151+
}
152+
144153
public function actionAddCategory($Param)
145154
{
146155
$templates = fsFunctions::DirectoryInfo(PATH_TPL.CMSSettings::GetInstance('template').'/MPosts/', true, false, 'Index', array('php'));
@@ -149,15 +158,17 @@ public function actionAddCategory($Param)
149158
$this->Tag('templates', $templates['NAMES']);
150159
$this->Tag('templates_ps', $templates_sp['NAMES']);
151160
$this->Tag('templates_pf', $templates_fp['NAMES']);
161+
$this->Tag('parents', $this->_GetCategoriesAsArray());
152162
}
153163

154-
public function actionEditCategory($Param)
164+
public function actionEditCategory($param)
155165
{
156166
$posts_category = new posts_category();
157-
$posts_category->current = $Param->key;
158-
if ($Param->key != $posts_category->id) {
167+
$this->Tag('parents', $this->_GetCategoriesAsArray());
168+
$posts_category->current = $param->key;
169+
if ($param->key != $posts_category->id) {
159170
return $this->_Referer();
160-
}
171+
}
161172
$templates = fsFunctions::DirectoryInfo(PATH_TPL.CMSSettings::GetInstance('template').'/MPosts/', true, false, 'Index', array('php'));
162173
$templates_sp = fsFunctions::DirectoryInfo(PATH_TPL.CMSSettings::GetInstance('template').'/MPosts/', true, false, 'ShortPost', array('php'));
163174
$templates_fp = fsFunctions::DirectoryInfo(PATH_TPL.CMSSettings::GetInstance('template').'/MPosts/', true, false, 'Post', array('php'));

controllers/fsCMS/MPosts.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,12 @@ public function actionCategory($param)
5353
$template = $param->Exists('in_template') && file_exists($this->_Template('Inline'.$posts_category->result->tpl))
5454
? $this->_Template('Inline'.$posts_category->result->tpl)
5555
: $this->_Template($posts_category->result->tpl);
56-
56+
$this->Tag('childs', $posts_category->GetByParent($posts_category->result->id));
5757
$html = $this->CreateView(array('page' => $page), $template);
5858
if($param->Exists('ajax_pages')) {
5959
$html = '<div id="category-ajax-'.$param->category.'">'.$html.'</div>';
6060
$this->_AddMyScriptsAndStyles(true, false, URL_THEME_JS);
6161
}
62-
6362
return $this->Html($html);
6463
}
6564

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
class PostsFunctions
3+
{
4+
public static function GetFullCategoryName($categories, $category)
5+
{
6+
$name = $category['name'];
7+
while($category['id_parent'] != 0 && isset($categories[$category['id_parent']])) {
8+
$category = $categories[$category['id_parent']];
9+
$name = $category['name'].'\\'.$name;
10+
}
11+
return $name;
12+
}
13+
}

kernel/fsController.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ final protected function _Referer($setRedirect = true)
130130
* Get folder path in template directory
131131
* @api
132132
* @since 1.0.0
133-
* @param string|null $folder (optional) Folder name in template directory. If <b>null</b> will use controller name. Default <b>null</b>.
133+
* @param string $folder (optional) Folder name in template directory. If empty string will use controller name. Default <b>empty string</b>.
134134
* @return string Full path to needed folder.
135135
*/
136-
protected function _TemplatePath($folder = null)
136+
protected function _TemplatePath($folder = '')
137137
{
138-
if ($folder === null) {
138+
if ($folder === '') {
139139
$folder = get_class($this);
140140
}
141141
if (is_dir(PATH_TPL.$folder)) {
@@ -149,13 +149,13 @@ protected function _TemplatePath($folder = null)
149149
* Get path for template file
150150
* @api
151151
* @since 1.0.0
152-
* @param string|null $file (optional) File name in template directory. If <b>null</b> will use controller method name. Default <b>null</b>.
153-
* @param string|null $folder (optional) Folder name in template directory. If <b>null</b> will use controller name. Default <b>null</b>.
152+
* @param string $file (optional) File name in template directory. If empty string will use controller method name. Default <b>empty string</b>.
153+
* @param string $folder (optional) Folder name in template directory. If empty string will use controller name. Default <b>empty string</b>.
154154
* @return string Full path to template file.
155155
*/
156-
protected function _Template($file = null, $folder = null)
156+
protected function _Template($file = '', $folder = '')
157157
{
158-
if ($file === null) {
158+
if ($file === '') {
159159
$file = empty($_REQUEST['method']) ? 'Index' : $_REQUEST['method'];
160160
}
161161
$file = fsFunctions::Slash($file, EXT_TPL);

kernel/fsDBTableExtension.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ class fsDBTableExtension extends fsDBTable
1212
* @param boolean $asArr (optional) Flag for getting rows as array. Default <b>true</b>.
1313
* @param boolean $useLinks (optional) Flag for selecting foreign key values. Default <b>false</b>.
1414
* @param array $order (optional) Fields for order clause.
15+
* @param array $arrIndexKey (optional) Fields for array key if result as array. If empty string generate standart numeric array index. Default <b>empty string</b>.
1516
* @return array|fsDBTableExtension Result of query.
1617
*/
17-
public function GetAll($asArr = true, $useLinks = false, $order = array())
18+
public function GetAll($asArr = true, $useLinks = false, $order = array(), $arrIndexKey = '')
1819
{
1920
$this->Select('*', $useLinks)->Order($order);
2021
if (!$asArr) {
2122
return $this->Execute('', false);
2223
} else {
23-
return $this->ExecuteToArray();
24+
return $this->ExecuteToArray('', $arrIndexKey);
2425
}
2526
}
2627

kernel/fsFunctions.php

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
*/
66
class fsFunctions
77
{
8-
private static $_slash = '/';
9-
108
/**
119
* Check that object exists and not empty.
1210
* @since 1.0.0
@@ -101,7 +99,7 @@ public static function FormatPrint($data)
10199
*/
102100
public static function GetDirectoryFromFullFilePath($filePath)
103101
{
104-
return substr($filePath, 0, strrpos($filePath, self::$_slash, -3) + 1);
102+
return substr($filePath, 0, strrpos($filePath, '/', -3) + 1);
105103
}
106104

107105
/**
@@ -188,14 +186,11 @@ public static function Redirect($url)
188186
* @since 1.0.0
189187
* @api
190188
* @param string $string String for checking.
191-
* @param string $slash (optional) Symbol for check. Default <b>self::$_slash (/)</b>.
189+
* @param string $slash (optional) Symbol for check. Default <b>/</b>.
192190
* @return string
193191
*/
194-
public static function Slash($string, $slash = null)
192+
public static function Slash($string, $slash = '/')
195193
{
196-
if ($slash === null) {
197-
$slash = self::$_slash;
198-
}
199194
return substr($string, -strlen($slash)) != $slash ? $string.$slash : $string;
200195
}
201196

@@ -255,6 +250,33 @@ public static function Mail($to, $subj, $text, $from = '', $file = array(), $con
255250
return mail($to, $subj, $zag, $head);
256251
}
257252

253+
254+
/**
255+
* Get array of RGB(A) from HEX color string.
256+
* @since 1.0.0
257+
* @api
258+
* @param string $hexColor HEX color.
259+
* @param boolean $allowAlpha (optional) Flag for alpha color. Default <b>false</b>.
260+
* @return array RGB(A) array.
261+
*/
262+
public static function RgbFromHex($hexColor, $allowAlpha = false)
263+
{
264+
$result = array(0, 0, 0);
265+
if($allowAlpha) {
266+
$result[] = 255;
267+
}
268+
if(($allowAlpha && strlen($hexColor) != 8) || (!$allowAlpha && strlen($hexColor) != 6)) {
269+
return $result;
270+
}
271+
$result[0] = hexdec(substr($hexColor, 0, 2));
272+
$result[1] = hexdec(substr($hexColor, 2, 2));
273+
$result[2] = hexdec(substr($hexColor, 4, 2));
274+
if($allowAlpha) {
275+
$result[0] = hexdec(substr($hexColor, 6, 2));
276+
}
277+
return $result;
278+
}
279+
258280
/**
259281
* Get files in directory.
260282
* @since 1.0.0
@@ -675,6 +697,29 @@ public static function CheckUploadFiles($name, $mimes = array(), $blacklistForma
675697
return $error;
676698
}
677699

700+
/**
701+
* Get image object
702+
* @since 1.0.0
703+
* @api
704+
* @param string $filePath Image path.
705+
* @return object Image object. If any error return null.
706+
*/
707+
public static function LoadImage($filePath)
708+
{
709+
$type = exif_imagetype($filePath);
710+
$allowedTypes = array(1, 2, 3, 6);
711+
if (!in_array($type, $allowedTypes)) {
712+
return false;
713+
}
714+
switch ($type) {
715+
case 1: return imageCreateFromGif($filePath);
716+
case 2: return imageCreateFromJpeg($filePath);
717+
case 3: return imageCreateFromPng($filePath);
718+
case 6: return imageCreateFromBmp($filePath);
719+
default: return null;
720+
}
721+
}
722+
678723
/**
679724
* Resize image
680725
* @since 1.0.0

kernel/fsLanguage.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ public static function GetInstance()
4343
if (!$isDCACHEFILE || !$isSDCACHEFILE || !$XDCACHEFILE) {
4444
$newXML = new DOMDocument('1.0', 'UTF-8');
4545
$el = $newXML->createElement("dictionary");
46-
$newXML->appendChild($el);
47-
if (!$isXDCACHEFILE) $newXML->save($XDCACHEFILE);
48-
unset($newXML);
4946
foreach ($DT['NAMES'] as $D) {
5047
$TD = explode('-', $D);
5148
if (count($TD) != 3 && $D != 'xml') {
@@ -71,11 +68,10 @@ public static function GetInstance()
7168
if (!isset($res['@attributes']['name']) || !isset($res[fsSession::GetInstance('Language')])) {
7269
continue;
7370
}
74-
$xml = simplexml_load_file($XDCACHEFILE);
75-
$xml->addChild('XML'.$res['@attributes']['name'], $res[fsSession::GetInstance('Language')]);
76-
$xml->asXML($XDCACHEFILE);
71+
$tag = $newXML->createElement('XML'.$res['@attributes']['name']);
72+
$tag->appendChild($newXML->createCDATASection(trim($res[fsSession::GetInstance('Language')])));
73+
$el->appendChild($tag);
7774
}
78-
unset($xml);
7975
}
8076
}
8177
if ($SL || $L) {
@@ -90,6 +86,10 @@ public static function GetInstance()
9086
}
9187
}
9288
}
89+
$newXML->appendChild($el);
90+
if (!$isXDCACHEFILE) {
91+
$newXML->save($XDCACHEFILE);
92+
}
9393
if (!$isDCACHEFILE && count($DICTIONARY) > 0) {
9494
fsFunctions::ArrayToFile($DICTIONARY, 'DICTIONARY', $DCACHEFILE);
9595
}

languages/xml/custom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<dictionary><text name="cms_sample"><en>Sample</en><ru>Пример</ru></text></dictionary>
2+
<dictionary><text name="cms_sample"><en><![CDATA[Sample]]></en><ru><![CDATA[Пример]]></ru></text></dictionary>

languages/xml/en_cms.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
<text name='cms_text_auth_needed'>
2828
<en>Only for authorized users</en>
2929
</text>
30+
<text name='cms_parent'>
31+
<en>Parent</en>
32+
</text>
3033
<text name='cms_text_url_auth_need'>
3134
<en>Page for "only for authorized users" error</en>
3235
</text>

0 commit comments

Comments
 (0)