PageRenderTime 25ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/protected/modules/blog/BlogModule.php

https://gitlab.com/RonLab1987/YupePlusClear
PHP | 469 lines | 331 code | 32 blank | 106 comment | 3 complexity | a9b0cce80185e07426056a6b442f5b10 MD5 | raw file
  1. <?php
  2. /**
  3. * BlogModule основной класс модуля blog
  4. *
  5. * @author yupe team <team@yupe.ru>
  6. * @link http://yupe.ru
  7. * @copyright 2009-2013 amyLabs && Yupe! team
  8. * @package yupe.modules.blog
  9. * @since 0.1
  10. *
  11. */
  12. use yupe\components\WebModule;
  13. /**
  14. * Class BlogModule
  15. */
  16. class BlogModule extends yupe\components\WebModule
  17. {
  18. /**
  19. *
  20. */
  21. const VERSION = '1.0';
  22. /**
  23. * @var
  24. */
  25. public $mainPostCategory;
  26. /**
  27. * @var int
  28. */
  29. public $minSize = 0;
  30. /**
  31. * @var int
  32. */
  33. public $maxSize = 5368709120;
  34. /**
  35. * @var int
  36. */
  37. public $maxFiles = 1;
  38. /**
  39. * @var string
  40. */
  41. public $allowedExtensions = 'jpg,jpeg,png,gif';
  42. /**
  43. * @var string
  44. */
  45. public $mimeTypes = 'image/gif, image/jpeg, image/png';
  46. /**
  47. * @var string
  48. */
  49. public $uploadPath = 'blogs';
  50. /**
  51. * @var int
  52. */
  53. public $rssCount = 10;
  54. /**
  55. * @return array
  56. */
  57. public function getDependencies()
  58. {
  59. return [
  60. 'user',
  61. 'category',
  62. 'comment',
  63. 'image',
  64. 'notify',
  65. ];
  66. }
  67. /**
  68. * @return array|bool
  69. */
  70. public function checkSelf()
  71. {
  72. $messages = [];
  73. // count moderated users
  74. $membersCnt = UserToBlog::model()->count(
  75. 'status = :status',
  76. [':status' => UserToBlog::STATUS_CONFIRMATION]
  77. );
  78. if ($membersCnt) {
  79. $messages[WebModule::CHECK_NOTICE][] = [
  80. 'type' => WebModule::CHECK_NOTICE,
  81. 'message' => Yii::t(
  82. 'BlogModule.blog',
  83. '{count} new members of blog wait for confirmation!',
  84. [
  85. '{count}' => CHtml::link(
  86. $membersCnt,
  87. [
  88. '/blog/userToBlogBackend/index',
  89. 'UserToBlog[status]' => UserToBlog::STATUS_CONFIRMATION,
  90. 'order' => 'id.desc',
  91. ]
  92. ),
  93. ]
  94. ),
  95. ];
  96. }
  97. $postsCount = Post::model()->count('status = :status', [':status' => Post::STATUS_MODERATED]);
  98. if ($postsCount) {
  99. $messages[WebModule::CHECK_NOTICE][] = [
  100. 'type' => WebModule::CHECK_NOTICE,
  101. 'message' => Yii::t(
  102. 'BlogModule.blog',
  103. '{count} new posts wait for moderation!',
  104. [
  105. '{count}' => CHtml::link(
  106. $postsCount,
  107. [
  108. '/blog/postBackend/index',
  109. 'Post[status]' => Post::STATUS_MODERATED,
  110. 'order' => 'id.desc',
  111. ]
  112. ),
  113. ]
  114. ),
  115. ];
  116. }
  117. return (isset($messages[WebModule::CHECK_ERROR]) || isset($messages[WebModule::CHECK_NOTICE])) ? $messages : true;
  118. }
  119. /**
  120. * @return string
  121. */
  122. public function getCategory()
  123. {
  124. return Yii::t('BlogModule.blog', 'Content');
  125. }
  126. /**
  127. * @return string
  128. */
  129. public function getUploadPath()
  130. {
  131. return Yii::getPathOfAlias('webroot').DIRECTORY_SEPARATOR.Yii::app()->getModule(
  132. "yupe"
  133. )->uploadPath.DIRECTORY_SEPARATOR.$this->uploadPath;
  134. }
  135. /**
  136. * @return array
  137. */
  138. public function getParamsLabels()
  139. {
  140. return [
  141. 'mainCategory' => Yii::t('BlogModule.blog', 'Main blog category'),
  142. 'mainPostCategory' => Yii::t('BlogModule.blog', 'Main posts category'),
  143. 'editor' => Yii::t('BlogModule.blog', 'Visual editor'),
  144. 'uploadPath' => Yii::t(
  145. 'BlogModule.blog',
  146. 'File directory (relatively {path})',
  147. [
  148. '{path}' => Yii::getPathOfAlias('webroot').DIRECTORY_SEPARATOR.Yii::app()->getModule(
  149. "yupe"
  150. )->uploadPath,
  151. ]
  152. ),
  153. 'allowedExtensions' => Yii::t('BlogModule.blog', 'Allowed extensions (separated by comma)'),
  154. 'minSize' => Yii::t('BlogModule.blog', 'Minimum size (in bytes)'),
  155. 'maxSize' => Yii::t('BlogModule.blog', 'Maximum size (in bytes)'),
  156. 'rssCount' => Yii::t('BlogModule.blog', 'RSS records count'),
  157. ];
  158. }
  159. /**
  160. * @return array
  161. */
  162. public function getEditableParams()
  163. {
  164. return [
  165. 'editor' => Yii::app()->getModule('yupe')->getEditors(),
  166. 'mainCategory' => CHtml::listData($this->getCategoryList(), 'id', 'name'),
  167. 'mainPostCategory' => CHtml::listData($this->getCategoryList(), 'id', 'name'),
  168. 'uploadPath',
  169. 'allowedExtensions',
  170. 'minSize',
  171. 'maxSize',
  172. 'rssCount',
  173. ];
  174. }
  175. /**
  176. * @return array
  177. */
  178. public function getEditableParamsGroups()
  179. {
  180. return [
  181. '0.category' => [
  182. 'label' => Yii::t('BlogModule.blog', 'Categories'),
  183. 'items' => [
  184. 'mainPostCategory',
  185. 'mainCategory',
  186. ],
  187. ],
  188. '1.images' => [
  189. 'label' => Yii::t('BlogModule.blog', 'Images'),
  190. 'items' => [
  191. 'uploadPath',
  192. 'allowedExtensions',
  193. 'minSize',
  194. 'maxSize',
  195. ],
  196. ],
  197. '2.editor' => [
  198. 'label' => Yii::t('BlogModule.blog', 'Visual editor settings'),
  199. 'items' => [
  200. 'editor',
  201. ],
  202. ],
  203. ];
  204. }
  205. /**
  206. * @return static[]
  207. */
  208. public function getCategoryListForPost()
  209. {
  210. return $this->getCategoryList();
  211. }
  212. /**
  213. * @return array
  214. */
  215. public function getNavigation()
  216. {
  217. return [
  218. ['label' => Yii::t('BlogModule.blog', 'Blogs')],
  219. [
  220. 'icon' => 'fa fa-fw fa-list-alt',
  221. 'label' => Yii::t('BlogModule.blog', 'Blog list'),
  222. 'url' => ['/blog/blogBackend/index'],
  223. ],
  224. [
  225. 'icon' => 'fa fa-fw fa-plus-square',
  226. 'label' => Yii::t('BlogModule.blog', 'New blog'),
  227. 'url' => ['/blog/blogBackend/create'],
  228. ],
  229. [
  230. 'icon' => 'fa fa-fw fa-folder-open',
  231. 'label' => Yii::t('BlogModule.blog', 'Blogs categories'),
  232. 'url' => ['/category/categoryBackend/index', 'Category[parent_id]' => (int)$this->mainCategory],
  233. ],
  234. ['label' => Yii::t('BlogModule.blog', 'Posts')],
  235. [
  236. 'icon' => 'fa fa-fw fa-list-alt',
  237. 'label' => Yii::t('BlogModule.blog', 'Post list'),
  238. 'url' => ['/blog/postBackend/index'],
  239. ],
  240. [
  241. 'icon' => 'fa fa-fw fa-plus-square',
  242. 'label' => Yii::t('BlogModule.blog', 'New post'),
  243. 'url' => ['/blog/postBackend/create'],
  244. ],
  245. [
  246. 'icon' => 'fa fa-fw fa-folder-open',
  247. 'label' => Yii::t('BlogModule.blog', 'Posts categories'),
  248. 'url' => ['/category/categoryBackend/index', 'Category[parent_id]' => (int)$this->mainCategory],
  249. ],
  250. ['label' => Yii::t('BlogModule.blog', 'Members')],
  251. [
  252. 'icon' => 'fa fa-fw fa-list-alt',
  253. 'label' => Yii::t('BlogModule.blog', 'Member list'),
  254. 'url' => ['/blog/userToBlogBackend/index'],
  255. ],
  256. [
  257. 'icon' => 'fa fa-fw fa-plus-square',
  258. 'label' => Yii::t('BlogModule.blog', 'New member'),
  259. 'url' => ['/blog/userToBlogBackend/create'],
  260. ],
  261. ];
  262. }
  263. /**
  264. * @return string
  265. */
  266. public function getVersion()
  267. {
  268. return Yii::t('BlogModule.blog', self::VERSION);
  269. }
  270. /**
  271. * @return string
  272. */
  273. public function getName()
  274. {
  275. return Yii::t('BlogModule.blog', 'Blogs');
  276. }
  277. /**
  278. * @return string
  279. */
  280. public function getDescription()
  281. {
  282. return Yii::t('BlogModule.blog', 'This module allows building a personal blog or a blogging community');
  283. }
  284. /**
  285. * @return string
  286. */
  287. public function getAuthor()
  288. {
  289. return Yii::t('BlogModule.blog', 'yupe team');
  290. }
  291. /**
  292. * @return string
  293. */
  294. public function getAuthorEmail()
  295. {
  296. return Yii::t('BlogModule.blog', 'team@yupe.ru');
  297. }
  298. /**
  299. * @return string
  300. */
  301. public function getUrl()
  302. {
  303. return Yii::t('BlogModule.blog', 'http://yupe.ru');
  304. }
  305. /**
  306. * @return string
  307. */
  308. public function getAdminPageLink()
  309. {
  310. return '/blog/blogBackend/index';
  311. }
  312. /**
  313. * @return string
  314. */
  315. public function getIcon()
  316. {
  317. return "fa fa-fw fa-pencil";
  318. }
  319. /**
  320. * Возвращаем статус, устанавливать ли галку для установки модуля в инсталяторе по умолчанию:
  321. *
  322. * @return bool
  323. **/
  324. public function getIsInstallDefault()
  325. {
  326. return true;
  327. }
  328. /**
  329. *
  330. */
  331. public function init()
  332. {
  333. parent::init();
  334. $this->setImport(
  335. [
  336. 'blog.listeners.*',
  337. 'blog.events.*',
  338. 'blog.models.*',
  339. 'blog.components.*',
  340. 'vendor.yiiext.taggable-behavior.*',
  341. ]
  342. );
  343. }
  344. /**
  345. * @return array
  346. */
  347. public function getAuthItems()
  348. {
  349. return [
  350. [
  351. 'name' => 'Blog.BlogManager',
  352. 'description' => Yii::t('BlogModule.blog', 'Manage blogs'),
  353. 'type' => AuthItem::TYPE_TASK,
  354. 'items' => [
  355. //blogs
  356. [
  357. 'type' => AuthItem::TYPE_OPERATION,
  358. 'name' => 'Blog.BlogBackend.Create',
  359. 'description' => Yii::t('BlogModule.blog', 'Creating blog'),
  360. ],
  361. [
  362. 'type' => AuthItem::TYPE_OPERATION,
  363. 'name' => 'Blog.BlogBackend.Delete',
  364. 'description' => Yii::t('BlogModule.blog', 'Removing blog'),
  365. ],
  366. [
  367. 'type' => AuthItem::TYPE_OPERATION,
  368. 'name' => 'Blog.BlogBackend.Index',
  369. 'description' => Yii::t('BlogModule.blog', 'List of blogs'),
  370. ],
  371. [
  372. 'type' => AuthItem::TYPE_OPERATION,
  373. 'name' => 'Blog.BlogBackend.Update',
  374. 'description' => Yii::t('BlogModule.blog', 'Editing blog'),
  375. ],
  376. [
  377. 'type' => AuthItem::TYPE_OPERATION,
  378. 'name' => 'Blog.BlogBackend.View',
  379. 'description' => Yii::t('BlogModule.blog', 'Viewing blogs'),
  380. ],
  381. //posts
  382. [
  383. 'type' => AuthItem::TYPE_OPERATION,
  384. 'name' => 'Blog.PostBackend.Create',
  385. 'description' => Yii::t('BlogModule.blog', 'Creating post'),
  386. ],
  387. [
  388. 'type' => AuthItem::TYPE_OPERATION,
  389. 'name' => 'Blog.PostBackend.Delete',
  390. 'description' => Yii::t('BlogModule.blog', 'Removing post'),
  391. ],
  392. [
  393. 'type' => AuthItem::TYPE_OPERATION,
  394. 'name' => 'Blog.PostBackend.Index',
  395. 'description' => Yii::t('BlogModule.blog', 'List of posts'),
  396. ],
  397. [
  398. 'type' => AuthItem::TYPE_OPERATION,
  399. 'name' => 'Blog.PostBackend.Update',
  400. 'description' => Yii::t('BlogModule.blog', 'Editing post'),
  401. ],
  402. [
  403. 'type' => AuthItem::TYPE_OPERATION,
  404. 'name' => 'Blog.PostBackend.View',
  405. 'description' => Yii::t('BlogModule.blog', 'Viewing post'),
  406. ],
  407. //members
  408. [
  409. 'type' => AuthItem::TYPE_OPERATION,
  410. 'name' => 'Blog.UserToBlogBackend.Create',
  411. 'description' => Yii::t('BlogModule.blog', 'Creating member'),
  412. ],
  413. [
  414. 'type' => AuthItem::TYPE_OPERATION,
  415. 'name' => 'Blog.UserToBlogBackend.Delete',
  416. 'description' => Yii::t('BlogModule.blog', 'Removing member'),
  417. ],
  418. [
  419. 'type' => AuthItem::TYPE_OPERATION,
  420. 'name' => 'Blog.UserToBlogBackend.Index',
  421. 'description' => Yii::t('BlogModule.blog', 'List of members'),
  422. ],
  423. [
  424. 'type' => AuthItem::TYPE_OPERATION,
  425. 'name' => 'Blog.UserToBlogBackend.Update',
  426. 'description' => Yii::t('BlogModule.blog', 'Editing member'),
  427. ],
  428. [
  429. 'type' => AuthItem::TYPE_OPERATION,
  430. 'name' => 'Blog.UserToBlogBackend.View',
  431. 'description' => Yii::t('BlogModule.blog', 'Viewing member'),
  432. ],
  433. ],
  434. ],
  435. ];
  436. }
  437. }