Overview

Namespaces

  • DcGeneral
    • Clipboard
    • Contao
      • Callback
      • Compatibility
      • DataDefinition
        • Definition
      • Dca
        • Builder
          • Legacy
        • Definition
        • Palette
        • Populator
      • Event
      • View
        • Contao2BackendView
          • Event
    • Controller
    • Data
    • DataDefinition
      • Builder
      • Definition
        • Properties
        • View
          • Panel
      • ModelRelationship
      • Palette
        • Builder
          • Event
        • Condition
          • Palette
          • Property
    • EnvironmentPopulator
    • Event
    • Exception
    • Factory
      • Event
    • Panel
    • View
      • Event

Classes

  • BackendBindings
  • InputProvider
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * PHP version 5
  4:  * @package    generalDriver
  5:  * @author     Christian Schiffler <c.schiffler@cyberspectrum.de>
  6:  * @author     Stefan Heimes <stefan_heimes@hotmail.com>
  7:  * @author     Tristan Lins <tristan.lins@bit3.de>
  8:  * @copyright  The MetaModels team.
  9:  * @license    LGPL.
 10:  * @filesource
 11:  */
 12: 
 13: namespace DcGeneral\Contao;
 14: 
 15: use ContaoCommunityAlliance\Contao\Bindings\ContaoEvents;
 16: use ContaoCommunityAlliance\Contao\Bindings\Events\Backend\AddToUrlEvent;
 17: use ContaoCommunityAlliance\Contao\Bindings\Events\Controller\LoadDataContainerEvent;
 18: use ContaoCommunityAlliance\Contao\Bindings\Events\Controller\RedirectEvent;
 19: use ContaoCommunityAlliance\Contao\Bindings\Events\Controller\ReloadEvent;
 20: use ContaoCommunityAlliance\Contao\Bindings\Events\Image\GenerateHtmlEvent;
 21: use ContaoCommunityAlliance\Contao\Bindings\Events\Image\ResizeImageEvent;
 22: use ContaoCommunityAlliance\Contao\Bindings\Events\System\GetReferrerEvent;
 23: use ContaoCommunityAlliance\Contao\Bindings\Events\System\LoadLanguageFileEvent;
 24: use ContaoCommunityAlliance\Contao\Bindings\Events\System\LogEvent;
 25: 
 26: /**
 27:  * Class BackendBindings.
 28:  *
 29:  * This class abstracts the Contao backend methods used within DcGeneral over all Contao versions.
 30:  *
 31:  * This is needed to limit the amount of version_compare() calls to an absolute minimum.
 32:  *
 33:  * @package DcGeneral\Contao
 34:  *
 35:  * @deprecated Use events-contao-bindings package.
 36:  */
 37: class BackendBindings
 38: {
 39:     protected static function dispatch($eventName, $event)
 40:     {
 41:         return $GLOBALS['container']['event-dispatcher']->dispatch($eventName, $event);
 42:     }
 43: 
 44:     /**
 45:      * Log a message to the contao system log.
 46:      *
 47:      * @param string $strText     The message text to add to the log.
 48:      *
 49:      * @param string $strFunction The method/function the message originates from.
 50:      *
 51:      * @param string $strCategory The category under which the message shall be logged.
 52:      *
 53:      * @return void
 54:      */
 55:     public static function log($strText, $strFunction, $strCategory)
 56:     {
 57:         trigger_error(__FILE__ . '::' . __METHOD__ . ' deprecated, use events-contao-bindings.');
 58:         self::dispatch(
 59:             ContaoEvents::SYSTEM_LOG,
 60:             new LogEvent(
 61:                 $strText,
 62:                 $strFunction,
 63:                 $strCategory
 64:             )
 65:         );
 66:     }
 67: 
 68:     /**
 69:      * Redirect the browser to a new location.
 70:      *
 71:      * NOTE: This method exits the script.
 72:      *
 73:      * @param string $strLocation The new URI to which the browser shall get redirected to.
 74:      *
 75:      * @param int    $intStatus   The HTTP status code to use. 301, 302, 303, 307. Defaults to 303.
 76:      *
 77:      * @return void
 78:      */
 79:     public static function redirect($strLocation, $intStatus = 303)
 80:     {
 81:         trigger_error(__FILE__ . '::' . __METHOD__ . ' deprecated, use events-contao-bindings.');
 82:         self::dispatch(
 83:             ContaoEvents::CONTROLLER_REDIRECT,
 84:             new RedirectEvent(
 85:                 $strLocation,
 86:                 $intStatus
 87:             )
 88:         );
 89:     }
 90: 
 91:     /**
 92:      * Reload the current page.
 93:      *
 94:      * NOTE: This method exits the script.
 95:      *
 96:      * @return void
 97:      */
 98:     public static function reload()
 99:     {
100:         trigger_error(__FILE__ . '::' . __METHOD__ . ' deprecated, use events-contao-bindings.');
101:         self::dispatch(
102:             ContaoEvents::CONTROLLER_RELOAD,
103:             new ReloadEvent(
104:             )
105:         );
106:     }
107: 
108:     /**
109:      * Add a request string to the current URI string.
110:      *
111:      * @param string $strRequest The parameters to add to the current URL separated by &.
112:      *
113:      * @return string
114:      */
115:     public static function addToUrl($strRequest)
116:     {
117:         trigger_error(__FILE__ . '::' . __METHOD__ . ' deprecated, use events-contao-bindings.');
118:         return self::dispatch(
119:             ContaoEvents::BACKEND_ADD_TO_URL,
120:             new AddToUrlEvent(
121:                 $strRequest
122:             )
123:         )->getUrl();
124:     }
125: 
126:     /**
127:      * Load a set of language files.
128:      *
129:      * @param string  $strName     The table name.
130:      *
131:      * @param boolean $strLanguage An optional language code.
132:      *
133:      * @param boolean $blnNoCache  If true, the cache will be bypassed.
134:      *
135:      * @return void
136:      *
137:      * @throws \Exception In case a language does not exist.
138:      */
139:     public static function loadLanguageFile($strName, $strLanguage = null, $blnNoCache = false)
140:     {
141:         trigger_error(__FILE__ . '::' . __METHOD__ . ' deprecated, use events-contao-bindings.');
142:         self::dispatch(
143:             ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE,
144:             new LoadLanguageFileEvent(
145:                 $strName,
146:                 $strLanguage,
147:                 $blnNoCache
148:             )
149:         );
150:     }
151: 
152:     /**
153:      * Resize an image and store the resized version in the assets/images folder.
154:      *
155:      * @param string  $image  The image path.
156:      * @param integer $width  The target width.
157:      * @param integer $height The target height.
158:      * @param string  $mode   The resize mode.
159:      * @param string  $target An optional target path.
160:      * @param boolean $force  Override existing target images.
161:      *
162:      * @return string|null The path of the resized image or null.
163:      */
164:     public static function getImage($image, $width, $height, $mode = '', $target = null, $force = false)
165:     {
166:         trigger_error(__FILE__ . '::' . __METHOD__ . ' deprecated, use events-contao-bindings.');
167:         return self::dispatch(
168:             ContaoEvents::IMAGE_RESIZE,
169:             new ResizeImageEvent(
170:                 $image,
171:                 $width,
172:                 $height,
173:                 $mode,
174:                 $target,
175:                 $force
176:             )
177:         )->getResultImage();
178:     }
179: 
180:     /**
181:      * Generate an image tag and return it as string.
182:      *
183:      * @param string $src        The image path.
184:      * @param string $alt        An optional alt attribute.
185:      * @param string $attributes A string of other attributes.
186:      *
187:      * @return string The image HTML tag.
188:      */
189:     public static function generateImage($src, $alt = '', $attributes = '')
190:     {
191:         trigger_error(__FILE__ . '::' . __METHOD__ . ' deprecated, use events-contao-bindings.');
192:         return self::dispatch(
193:             ContaoEvents::IMAGE_GET_HTML,
194:             new GenerateHtmlEvent(
195:                 $src,
196:                 $alt,
197:                 $attributes
198:             )
199:         )->getHtml();
200:     }
201: 
202:     /**
203:      * Return the current referer URL and optionally encode ampersands.
204:      *
205:      * @param boolean $blnEncodeAmpersands If true, ampersands will be encoded.
206:      *
207:      * @param string  $strTable            An optional table name.
208:      *
209:      * @return string The referer URL
210:      */
211:     public static function getReferer($blnEncodeAmpersands = false, $strTable = null)
212:     {
213:         trigger_error(__FILE__ . '::' . __METHOD__ . ' deprecated, use events-contao-bindings.');
214:         return self::dispatch(
215:             ContaoEvents::SYSTEM_GET_REFERRER,
216:             new GetReferrerEvent(
217:                 $blnEncodeAmpersands,
218:                 $strTable
219:             )
220:         )->getReferrerUrl();
221:     }
222: 
223:     /**
224:      * Load a set of DCA files.
225:      *
226:      * @param string  $strTable   The table name.
227:      *
228:      * @param boolean $blnNoCache If true, the cache will be bypassed.
229:      *
230:      * @return void
231:      */
232:     public static function loadDataContainer($strTable, $blnNoCache = false)
233:     {
234:         trigger_error(__FILE__ . '::' . __METHOD__ . ' deprecated, use events-contao-bindings.');
235:         self::dispatch(
236:             ContaoEvents::CONTROLLER_LOAD_DATA_CONTAINER,
237:             new LoadDataContainerEvent(
238:                 $strTable,
239:                 $blnNoCache
240:             )
241:         );
242:     }
243: 
244:     /**
245:      * Parse a date format string and translate textual representations.
246:      *
247:      * @param string  $strFormat    The date format string.
248:      *
249:      * @param integer $intTimestamp An optional timestamp.
250:      *
251:      * @return string The textual representation of the date.
252:      */
253:     public static function parseDate($strFormat, $intTimestamp = null)
254:     {
255:         if (version_compare(VERSION, '3.1', '>='))
256:         {
257:             return \Date::parse($strFormat, $intTimestamp);
258:         }
259: 
260:         return BackendBindingInternal::getInstance()->parseDate($strFormat, $intTimestamp);
261:     }
262: 
263:     /**
264:      * Shorten a HTML string to a certain number of characters.
265:      *
266:      * Shortens a string to a given number of characters preserving words
267:      * (therefore it might be a bit shorter or longer than the number of
268:      * characters specified). Preserves allowed tags.
269:      *
270:      * @param string  $strString        The Html string to cut.
271:      *
272:      * @param integer $intNumberOfChars The amount of chars to preserve.
273:      *
274:      * @return string
275:      */
276:     public static function substrHtml($strString, $intNumberOfChars)
277:     {
278:         if (version_compare(VERSION, '3.1', '>='))
279:         {
280:             return \String::substrHtml($strString, $intNumberOfChars);
281:         }
282: 
283:         return \String::getInstance()->substrHtml($strString, $intNumberOfChars);
284:     }
285: }
286: 
contao-community-alliance/dc-general API documentation generated by ApiGen 2.8.0