SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/Helpers/Constants.php

Permission types
  1. <?php
  2. /*
  3.  * Copyright (C) 2017 Karmabunny Pty Ltd.
  4.  *
  5.  * This file is a part of SproutCMS.
  6.  *
  7.  * SproutCMS is free software: you can redistribute it and/or modify it under the terms
  8.  * of the GNU General Public License as published by the Free Software Foundation, either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * For more information, visit <http://getsproutcms.com>.
  12.  */
  13.  
  14. namespace Sprout\Helpers;
  15.  
  16. use ReflectionClass;
  17.  
  18.  
  19. /**
  20. * A bunch of different constants
  21. **/
  22. class Constants
  23. {
  24. /** Permission types */
  25. const PERM_INHERIT = 1;
  26. const PERM_SPECIFIC = 2;
  27.  
  28.  
  29. /** Extra pages **/
  30. // These are now handled by the register helper, and APPPATH/sprout_load
  31. // but these are left for compatibility.
  32. const EXTRAPAGES_404 = 1;
  33. const EXTRAPAGES_ADMIN_LOGIN = 2;
  34.  
  35.  
  36. /** Cron and workers - job status */
  37. public static $job_status = array(
  38. 0 => 'Incomplete',
  39. 1 => 'Complete',
  40. -1 => 'Failed',
  41. );
  42.  
  43.  
  44. /** Relative dates */
  45. public static $relative_dates = array(
  46. 'n1' => 'Newer than 1 month',
  47. 'n3' => 'Newer than 3 months',
  48. 'n12' => 'Newer than 12 months',
  49. 'o12' => 'Older than 12 months',
  50. );
  51.  
  52.  
  53. /** Relative dates */
  54. public static $search_modifiers = array(
  55. 'or' => 'Match any',
  56. 'and' => 'Match all',
  57. );
  58.  
  59.  
  60. /**
  61.   * Labels for the page revision statuses
  62.   */
  63. public static $rev_statuses = [
  64. 'old' => 'Old',
  65. 'wip' => 'Work in progress',
  66. 'need_approval' => 'Needs approval',
  67. 'live' => 'Live',
  68. 'rejected' => 'Rejected',
  69. 'auto_launch' => 'Ready for autolaunch',
  70. ];
  71.  
  72.  
  73. /**
  74.   * Looks for a class constant which has a specific value.
  75.   *
  76.   * @param string $class The class to look for constants in.
  77.   * @param string $prefix The prefix to require a constant to have.
  78.   * @param string $value The value to require a constant to have.
  79.   * @return string The name of the constant, or null if no matching constant was found.
  80.   **/
  81. public static function reverseLookup($class, $prefix, $value)
  82. {
  83. $refl_class = new ReflectionClass($class);
  84.  
  85. $constants = $refl_class->getConstants();
  86. foreach ($constants as $name => $val) {
  87. if (strncasecmp($name, $prefix, strlen($prefix)) == 0 and $val == $value) return $name;
  88. }
  89.  
  90. return null;
  91. }
  92.  
  93.  
  94. /**
  95.   * For the admin 'last modified' refine field
  96.   **/
  97. public static $recent_dates = array(
  98. '1 DAY' => 'Today',
  99. '1 WEEK' => 'This week',
  100. '1 MONTH' => 'This month',
  101. '3 MONTH' => 'This quarter',
  102. '1 YEAR' => 'This year',
  103. );
  104.  
  105.  
  106. /**
  107.   * List of month names
  108.   **/
  109. public static $month_names = array(1 => 'January', 2 => 'February', 3 => 'March', 4 => 'April', 5 => 'May',
  110. 6 => 'June', 7 => 'July', 8 => 'August', 9 => 'September', 10 => 'October', 11 => 'November', 12 => 'December');
  111.  
  112.  
  113. /**
  114.   * Password algorithms
  115.   **/
  116. const PASSWORD_SHA_SALT = 2;
  117. const PASSWORD_BCRYPT12 = 3;
  118. const PASSWORD_SHA_SALT_5000 = 5;
  119.  
  120. // Read-only algorithms, for data migration
  121. const PASSWORD_SHA = 1;
  122. const PASSWORD_PLAIN = 4;
  123.  
  124.  
  125. /**
  126.   * Maximum age of locks (seconds)
  127.   **/
  128. const LOCK_AGE = 120; // two minutes
  129.  
  130.  
  131. /**
  132.   * The different category options in the admin
  133.   **/
  134. const CATEGORIES_CURRENT = 1;
  135. const CATEGORIES_ARCHIVE = 2;
  136. const CATEGORIES_ALL = 3;
  137.  
  138. public static $category_admin_options = array(
  139. self::CATEGORIES_CURRENT => 'Live',
  140. self::CATEGORIES_ARCHIVE => 'Archived',
  141. self::CATEGORIES_ALL => 'All',
  142. );
  143.  
  144. public static $category_admin_where = array(
  145. self::CATEGORIES_CURRENT => 'categories.show_admin = 1',
  146. self::CATEGORIES_ARCHIVE => 'categories.show_admin = 0',
  147. self::CATEGORIES_ALL => '1',
  148. );
  149.  
  150.  
  151. /**
  152.   * This is a list of common extensions and mimetypes
  153.   **/
  154. public static $mimetypes = array(
  155. 'aac' => 'audio/aac',
  156. 'avi' => 'video/vnd.avi',
  157. 'bmp' => 'image/bmp',
  158. 'csv' => 'text/csv',
  159. 'doc' => 'application/msword',
  160. 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
  161. 'flv' => 'video/x-flv',
  162. 'gif' => 'image/gif',
  163. 'jpeg' => 'image/jpeg',
  164. 'jpe' => 'image/jpeg',
  165. 'jpg' => 'image/jpeg',
  166. 'mov' => 'video/quicktime',
  167. 'mp3' => 'audio/mpeg',
  168. 'mp4' => 'application/mp4',
  169. 'mpeg' => 'video/mpeg',
  170. 'mpg' => 'video/mpeg',
  171. 'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
  172. 'odp' => 'application/vnd.oasis.opendocument.presentation',
  173. 'odt' => 'application/vnd.oasis.opendocument.text',
  174. 'oga' => 'audio/ogg',
  175. 'ogv' => 'video/ogg',
  176. 'pdf' => 'application/pdf',
  177. 'png' => 'image/png',
  178. 'pps' => 'application/vnd.ms-powerpoint',
  179. 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
  180. 'ppt' => 'application/powerpoint',
  181. 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
  182. 'rtf' => 'text/rtf',
  183. 'tiff' => 'image/tiff',
  184. 'tif' => 'image/tiff',
  185. 'txt' => 'text/plain',
  186. 'webm' => 'video/webm',
  187. 'wmv' => 'application/vnd.ms-asf',
  188. 'xls' => 'application/excel',
  189. 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  190. 'zip' => 'application/zip',
  191. );
  192.  
  193.  
  194. /**
  195.   * If the first segment of a URL cannot be used because it conflicts with a controller name
  196.   * A similar problem exists for top-level directories
  197.   **/
  198. public static $conflict_page_urls = array(
  199. 'ad', 'admin', 'article', 'action_log', 'advanced_search',
  200. 'cart', 'config', 'content_block', 'captcha', 'category', 'content_subscribe', 'cron_job',
  201. 'dbtools', 'document_search',
  202. 'event', 'extra_page', 'ext_video', 'email_share',
  203. 'file', 'files', 'form', 'forum',
  204. 'galleryfile', 'gallery',
  205. 'home_page',
  206. 'job_advert', 'job_application',
  207. 'list', 'link',
  208. 'man', 'managed', 'media', 'modules', 'mailchimp',
  209. 'newsletter',
  210. 'operator', 'order',
  211. 'page', 'page_feedback', 'payment', 'paypal', 'project', 'product', 'pg',
  212. 'redirect', 'recurring_payment',
  213. 'search', 'skin', 'sprout', 'subsite', 'subscriber', 'secfile', 'sponsor', 'scss',
  214. 'testing', 'tools', 'tree', 'tinymce',
  215. 'user',
  216. 'worker_job',
  217. );
  218.  
  219. }
  220.  
  221.  
  222.