Example #1
0
 /**
  * Build navigation cache file.
  *
  * @return	void
  */
 public function buildCache()
 {
     // init
     $navigationTree = '';
     // build tree starting with the root
     $this->buildNavigation(0, $navigationTree);
     // start generating PHP
     $value = '<?php' . "\n";
     $value .= '/**' . "\n";
     $value .= ' *' . "\n";
     $value .= ' * This file is generated by the Backend, it contains' . "\n";
     $value .= ' * more information about the navigation in the backend. Do NOT edit.' . "\n";
     $value .= ' * ' . "\n";
     $value .= ' * @author		Backend' . "\n";
     $value .= ' * @generated	' . date('Y-m-d H:i:s') . "\n";
     $value .= ' */' . "\n";
     $value .= "\n";
     $value .= "\$navigation = array(\n";
     // add navigation tree
     $value .= $navigationTree;
     // close php
     $value .= ");\n";
     $value .= "\n";
     $value .= '?>';
     // store
     SpoonFile::setContent(BACKEND_CACHE_PATH . '/navigation/navigation.php', $value);
 }
Example #2
0
    /**
     * Build the language files
     *
     * @return	void
     * @param	string $language		The language to build the locale-file for.
     * @param	string $application		The application to build the locale-file for.
     */
    public static function buildCache($language, $application)
    {
        // get db
        $db = BackendModel::getDB();
        // get types
        $types = $db->getEnumValues('locale', 'type');
        // get locale for backend
        $locale = (array) $db->getRecords('SELECT type, module, name, value
											FROM locale
											WHERE language = ? AND application = ?
											ORDER BY type ASC, name ASC, module ASC', array((string) $language, (string) $application));
        // start generating PHP
        $value = '<?php' . "\n\n";
        $value .= '/**' . "\n";
        $value .= ' *' . "\n";
        $value .= ' * This file is generated by Fork CMS, it contains' . "\n";
        $value .= ' * more information about the locale. Do NOT edit.' . "\n";
        $value .= ' * ' . "\n";
        $value .= ' * @author		Fork CMS' . "\n";
        $value .= ' * @generated	' . date('Y-m-d H:i:s') . "\n";
        $value .= ' */' . "\n";
        $value .= "\n";
        // loop types
        foreach ($types as $type) {
            // default module
            $modules = array('core');
            // continue output
            $value .= "\n";
            $value .= '// init var' . "\n";
            $value .= '$' . $type . ' = array();' . "\n";
            $value .= '$' . $type . '[\'core\'] = array();' . "\n";
            // loop locale
            foreach ($locale as $i => $item) {
                // types match
                if ($item['type'] == $type) {
                    // new module
                    if (!in_array($item['module'], $modules)) {
                        $value .= '$' . $type . '[\'' . $item['module'] . '\'] = array();' . "\n";
                        $modules[] = $item['module'];
                    }
                    // parse
                    if ($application == 'backend') {
                        $value .= '$' . $type . '[\'' . $item['module'] . '\'][\'' . $item['name'] . '\'] = \'' . str_replace('\\"', '"', addslashes($item['value'])) . '\';' . "\n";
                    } else {
                        $value .= '$' . $type . '[\'' . $item['name'] . '\'] = \'' . str_replace('\\"', '"', addslashes($item['value'])) . '\';' . "\n";
                    }
                    // unset
                    unset($locale[$i]);
                }
            }
        }
        // close php
        $value .= "\n";
        $value .= '?>';
        // store
        SpoonFile::setContent(constant(mb_strtoupper($application) . '_CACHE_PATH') . '/locale/' . $language . '.php', $value);
    }
Example #3
0
    /**
     * Add a GOD-user
     */
    private function addUser()
    {
        // no god user already exists
        // @todo refactor this nasty if statement...
        if (!(bool) $this->getDB()->getVar('SELECT 1
			 FROM users
			 WHERE is_god = ? AND deleted = ? AND active = ?
			 LIMIT 1', array('Y', 'N', 'Y'))) {
            // secret files
            $avatar124x124 = '/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAYEBAQFBAYFBQYJBgUGCQsIBgYICwwKCgsKCgwQDAwMDAwMEAwODxAPDgwTExQUExMcGxsbHCAgICAgICAgICD/2wBDAQcHBw0MDRgQEBgaFREVGiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICD/wAARCAB8AHwDAREAAhEBAxEB/8QAHQAAAgIDAQEBAAAAAAAAAAAABQYEBwIDCAABCf/EAD4QAAEDAgQDBQUGBAUFAAAAAAECAwQFEQAGEiETMUEHIkJRYRQycYGRCBUjJFLRM2KhsRZTcsHxY4KSo/D/xAAaAQACAwEBAAAAAAAAAAAAAAACAwAEBQEG/8QAKhEAAgICAgEEAQQCAwAAAAAAAAECEQMhBBIxEyJBUWEFFDJxI4EzQpH/2gAMAwEAAhEDEQA/AL6hVL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19TwPrbhmOnYPVz91oZHQU7hOXmTyVCC4sRaNmPXGp6JNlOzfqBA8cDkr2tdiqcPiHPYHXtfpNPK/HZ3GtJiNKYWrSW2yPYzF+zLO3WnYdEaxhSR32UrtvxhlQ2XraHW0PwBzdO2D6sLh5IL99rFwyrHJb+wG3YHuz+Bue7H/g4ZpiP2pkiMuYNXEZ2pm1BE+o5HEWIlkhTrgesAy2I32L+mxU9R+h54lxEg/imC/E3HKOMflreJ3qWBFHLY91doyWg3bb1CjDfdQd+FpI966XYRS5NBPe0kcrxaTHZC8bnVEfhrtGpQI0fySfqALbp+76/3wSL0hSfLG9gqGjmFs5RKNf5UqL+Shk3d36wAqEnzsfP3xuNxCiH2WcNYc58jdpCpg3kgntwSQ5O6B0hhZ2M0MCHqIDEDqlJ63/qO3FaOmtyg5KpwFFtQ6arXHhia56MT+kjArJ6a+mZFU90l9vu2Pu+u/lOuhsch2rfiq76b+BwqPR0WZ01pzJay3rtiJJoqn4lpmWKaMSrBMP4j7vv1n+O443Rw32UPzE+8Grsya+0lj9RVYI6k+IztpDUmh6W/wAtdDtH0AyKrk+xl7HurKWB4bkomO+XSiNkIX//2Q==';
            // store files
            SpoonFile::setContent(PATH_WWW . '/frontend/files/backend_users/avatars/source/god.jpg', base64_decode($avatar124x124));
            SpoonFile::setContent(PATH_WWW . '/frontend/files/backend_users/avatars/128x128/god.jpg', base64_decode($avatar124x124));
            SpoonFile::setContent(PATH_WWW . '/frontend/files/backend_users/avatars/64x64/god.jpg', base64_decode($avatar64x64));
            SpoonFile::setContent(PATH_WWW . '/frontend/files/backend_users/avatars/32x32/god.jpg', base64_decode($avatar32x32));
            // get the password strength
            $passwordStrength = $this->checkPassword();
            // build settings
            $settings['nickname'] = serialize('Fork CMS');
            $settings['name'] = serialize('Fork');
            $settings['surname'] = serialize('CMS');
            $settings['interface_language'] = serialize($this->getVariable('default_interface_language'));
            $settings['date_format'] = serialize('j F Y');
            $settings['time_format'] = serialize('H:i');
            $settings['datetime_format'] = serialize(unserialize($settings['date_format']) . ' ' . unserialize($settings['time_format']));
            $settings['number_format'] = serialize('dot_nothing');
            $settings['password_key'] = serialize(uniqid());
            $settings['password_strength'] = serialize($passwordStrength);
            $settings['current_password_change'] = serialize(time());
            $settings['avatar'] = serialize('god.jpg');
            // build user
            $user['email'] = $this->getVariable('email');
            $user['password'] = sha1(md5(unserialize($settings['password_key'])) . md5($this->getVariable('password')));
            $user['active'] = 'Y';
            $user['deleted'] = 'N';
            $user['is_god'] = 'Y';
            // insert user
            $user['id'] = $this->getDB()->insert('users', $user);
            // build group
            $group['group_id'] = $this->getSetting('users', 'default_group');
            $group['user_id'] = $user['id'];
            // insert group
            $this->getDB()->insert('users_groups', $group);
            // loop settings
            foreach ($settings as $name => $value) {
                // insert user settings
                $this->getDB()->insert('users_settings', array('user_id' => $user['id'], 'name' => $name, 'value' => $value));
            }
        }
    }
Example #4
0
 /**
  * Write an error/custom message to the log.
  *
  * @return	void
  * @param	string $message			The messages that should be logged.
  * @param	string[optional] $type	The type of message you want to log, possible values are: error, custom.
  */
 public static function write($message, $type = 'error')
 {
     // milliseconds
     list($milliseconds) = explode(' ', microtime());
     $milliseconds = round($milliseconds * 1000, 0);
     // redefine var
     $message = date('Y-m-d H:i:s') . ' ' . $milliseconds . 'ms | ' . $message . "\n";
     $type = SpoonFilter::getValue($type, array('error', 'custom'), 'error');
     // file
     $file = self::getPath() . '/' . $type . '.log';
     // rename if needed
     if ((int) @filesize($file) >= self::MAX_FILE_SIZE * 1024) {
         // start new log file
         SpoonDirectory::move($file, $file . '.' . date('Ymdhis'));
     }
     // write content
     SpoonFile::setContent($file, $message, true, true);
 }
Example #5
0
 /**
  * Set the busy file
  *
  * @return	void
  */
 protected function setBusyFile()
 {
     // do not set busy file in debug mode
     if (SPOON_DEBUG) {
         return;
     }
     // build path
     $path = BACKEND_CACHE_PATH . '/cronjobs/' . $this->getId() . '.busy';
     // init var
     $isBusy = false;
     // does the busy file already exists.
     if (SpoonFile::exists($path)) {
         $isBusy = true;
         // grab counter
         $counter = (int) SpoonFile::getContent($path);
         // check the counter
         if ($counter > 9) {
             // build class name
             $className = 'Backend' . SpoonFilter::toCamelCase($this->getModule() . '_cronjob_' . $this->getAction());
             // notify user
             throw new BackendException('Cronjob (' . $className . ') is still busy after 10 runs, check it out!');
         }
     } else {
         $counter = 0;
     }
     // increment counter
     $counter++;
     // store content
     SpoonFile::setContent($path, $counter, true, false);
     // if the cronjob is busy we should NOT proceed
     if ($isBusy) {
         exit;
     }
 }
Example #6
0
 /**
  * Write the feed into a file
  *
  * @param	string $path	The path (and filename) where the feed should be written.
  */
 public function parseToFile($path)
 {
     // get xml
     $XML = $this->buildXML();
     // write content
     SpoonFile::setContent((string) $path, $XML, false, true);
 }
Example #7
0
 public static function correct(&$frm)
 {
     if ($frm->getField('photo')->isFilled()) {
         $imagename = uniqid();
         SpoonFile::setContent(IMAGE_PATH . '/' . $imagename . '.' . $frm->getField('photo')->getExtension(), gzcompress(SpoonFile::getContent($frm->getField('photo')->getTempFileName()), 9));
         //create Thumbnail
         $frm->getField('photo')->createThumbnail(IMAGE_PATH . '/' . $imagename . '_thumbnail.' . $frm->getField('photo')->getExtension(), 130, 130);
         SpoonFile::setContent(IMAGE_PATH . '/' . $imagename . '_thumbnail.' . $frm->getField('photo')->getExtension(), gzcompress(SpoonFile::getContent(IMAGE_PATH . '/' . $imagename . '_thumbnail.' . $frm->getField('photo')->getExtension()), 9));
     }
     if ($frm->getField('attachment')->isFilled()) {
         $attachname = uniqid();
         SpoonFile::setContent(ATTACH_PATH . '/' . $attachname . '.' . $frm->getField('attachment')->getExtension(), gzcompress(SpoonFile::getContent($frm->getField('attachment')->getTempFileName()), 9));
     }
     $company = "";
     for ($i = 1; $i < 6; $i++) {
         $company .= $frm->getField('company' . $i)->getValue() . ', ' . $frm->getField('registerno' . $i)->getValue() . ', ' . $frm->getField('companyno' . $i)->getValue() . ', ' . $frm->getField('companyemail' . $i)->getValue() . ', ' . $frm->getField('shareholder' . $i)->getValue() . ', ' . $frm->getField('registeraddr' . $i)->getValue() . ', ' . $frm->getField('businessaddr' . $i)->getValue() . ', ';
     }
     $company = substr($company, 0, -2);
     //company field names
     $values = array();
     for ($i = 1; $i < 6; $i++) {
         $values = array_merge($values, array('company' . $i, 'registerno' . $i, 'companyno' . $i, 'companyemail' . $i, 'shareholder' . $i, 'registeraddr' . $i, 'businessaddr' . $i));
     }
     $values = array_merge($frm->getValues(array_merge(array('form', 'submit', '_utf8'), $values)), $frm->getField('photo')->isFilled() ? array('photo' => $imagename, 'photoext' => $frm->getField('photo')->getExtension()) : array(), $frm->getField('attachment')->isFilled() ? array('attachment' => $attachname, 'attachext' => $frm->getField('attachment')->getExtension()) : array(), array("company" => $company, 'lastupdate' => time()));
     foreach ($values as $key => $value) {
         if ($value == NULL) {
             unset($values[$key]);
         }
     }
     return $values;
 }
Example #8
0
 /**
  * Converts a CSV-formatted string to an array
  *
  * @return	array
  * @param	string $string					The string you wish to convert to an array.
  * @param	array[optional] $columns		The column names you want to use.
  * @param	array[optional] $excludeColumns	The columns to exclude.
  * @param	string[optional] $delimiter		The field delimiter of the CSV.
  * @param	string[optional] $enclosure		The enclosure character of the CSV.
  */
 public static function stringToArray($string, array $columns = array(), array $excludeColumns = null, $delimiter = ',', $enclosure = '"')
 {
     // reset variables
     $string = (string) $string;
     $filename = dirname(__FILE__) . '/' . uniqid();
     // save a tempfile
     SpoonFile::setContent($filename, $string);
     // return the file to array
     $array = self::fileToArray($filename, $columns, $excludeColumns, $delimiter, $enclosure);
     // remove the created file
     SpoonFile::delete($filename);
     // return the array
     return $array;
 }
    /**
     * Execute the action
     *
     * @return	void
     */
    public function execute()
    {
        // no timelimit
        set_time_limit(0);
        // get database
        $db = BackendModel::getDB(true);
        // create log
        $log = new SpoonLog('custom', BACKEND_CACHE_PATH . '/logs/events');
        // get process-id
        $pid = getmypid();
        // store PID
        SpoonFile::setContent(BACKEND_CACHE_PATH . '/hooks/pid', $pid);
        // loop forever
        while (true) {
            // get 1 item
            $item = $db->getRecord('SELECT *
									FROM hooks_queue
									WHERE status = ?
									LIMIT 1', array('queued'));
            // any item?
            if (!empty($item)) {
                // init var
                $processedSuccesfully = true;
                // set item as busy
                $db->update('hooks_queue', array('status' => 'busy'), 'id = ?', array($item['id']));
                // unserialize data
                $item['callback'] = unserialize($item['callback']);
                $item['data'] = unserialize($item['data']);
                // check if the item is callable
                if (!is_callable($item['callback'])) {
                    // in debug mode we want to know if there are errors
                    if (SPOON_DEBUG) {
                        throw new BackendException('Invalid callback.');
                    }
                    // set to error state
                    $db->update('hooks_queue', array('status' => 'error'), 'id = ?', $item['id']);
                    // reset state
                    $processedSuccesfully = false;
                    // logging when we are in debugmode
                    if (SPOON_DEBUG) {
                        $log->write('Callback (' . serialize($item['callback']) . ') failed.');
                    }
                }
                try {
                    // logging when we are in debugmode
                    if (SPOON_DEBUG) {
                        $log->write('Callback (' . serialize($item['callback']) . ') called.');
                    }
                    // call the callback
                    $return = call_user_func($item['callback'], $item['data']);
                    // failed?
                    if ($return === false) {
                        // set to error state
                        $db->update('hooks_queue', array('status' => 'error'), 'id = ?', $item['id']);
                        // reset state
                        $processedSuccesfully = false;
                        // logging when we are in debugmode
                        if (SPOON_DEBUG) {
                            $log->write('Callback (' . serialize($item['callback']) . ') failed.');
                        }
                    }
                } catch (Exception $e) {
                    // set to error state
                    $db->update('hooks_queue', array('status' => 'error'), 'id = ?', $item['id']);
                    // reset state
                    $processedSuccesfully = false;
                    // logging when we are in debugmode
                    if (SPOON_DEBUG) {
                        $log->write('Callback (' . serialize($item['callback']) . ') failed.');
                    }
                }
                // everything went fine so delete the item
                if ($processedSuccesfully) {
                    $db->delete('hooks_queue', 'id = ?', $item['id']);
                }
                // logging when we are in debugmode
                if (SPOON_DEBUG) {
                    $log->write('Callback (' . serialize($item['callback']) . ') finished.');
                }
            } else {
                // remove the file
                SpoonFile::delete(BACKEND_CACHE_PATH . '/hooks/pid');
                // stop the script
                exit;
            }
        }
    }
Example #10
0
 /**
  * Execute the action
  *
  * @return	void
  */
 public function execute()
 {
     // call parent, this will probably add some general CSS/JS or other required files
     parent::execute();
     // get parameters
     $page = trim(SpoonFilter::getPostValue('page', null, ''));
     $identifier = trim(SpoonFilter::getPostValue('identifier', null, ''));
     // validate
     if ($page == '' || $identifier == '') {
         $this->output(self::BAD_REQUEST, null, 'No page provided.');
     }
     // init vars
     $filename = BACKEND_CACHE_PATH . '/analytics/' . $page . '_' . $identifier . '.txt';
     // does the temporary file still exits?
     $status = SpoonFile::getContent($filename);
     // no file - create one
     if ($status === false) {
         // create file with initial counter
         SpoonFile::setContent($filename, 'missing1');
         // return status
         $this->output(self::OK, array('status' => false), 'Temporary file was missing. We created one.');
     }
     // busy status
     if (strpos($status, 'busy') !== false) {
         // get counter
         $counter = (int) substr($status, 4) + 1;
         // file's been busy for more than hundred cycles - just stop here
         if ($counter > 100) {
             // remove file
             SpoonFile::delete($filename);
             // return status
             $this->output(self::ERROR, array('status' => 'timeout'), 'Error while retrieving data - the script took too long to retrieve data.');
         }
         // change file content to increase counter
         SpoonFile::setContent($filename, 'busy' . $counter);
         // return status
         $this->output(self::OK, array('status' => 'busy'), 'Data is being retrieved. (' . $counter . ')');
     }
     // unauthorized status
     if ($status == 'unauthorized') {
         // remove file
         SpoonFile::delete($filename);
         // remove all parameters from the module settings
         BackendModel::setModuleSetting($this->getModule(), 'session_token', null);
         BackendModel::setModuleSetting($this->getModule(), 'account_name', null);
         BackendModel::setModuleSetting($this->getModule(), 'table_id', null);
         BackendModel::setModuleSetting($this->getModule(), 'profile_title', null);
         // remove cache files
         BackendAnalyticsModel::removeCacheFiles();
         // clear tables
         BackendAnalyticsModel::clearTables();
         // return status
         $this->output(self::OK, array('status' => 'unauthorized'), 'No longer authorized.');
     }
     // done status
     if ($status == 'done') {
         // remove file
         SpoonFile::delete($filename);
         // return status
         $this->output(self::OK, array('status' => 'done'), 'Data retrieved.');
     }
     // missing status
     if (strpos($status, 'missing') !== false) {
         // get counter
         $counter = (int) substr($status, 7) + 1;
         // file's been missing for more than ten cycles - just stop here
         if ($counter > 10) {
             // remove file
             SpoonFile::delete($filename);
             // return status
             $this->output(self::ERROR, array('status' => 'missing'), 'Error while retrieving data - file was never created.');
         }
         // change file content to increase counter
         SpoonFile::setContent($filename, 'missing' . $counter);
         // return status
         $this->output(self::OK, array('status' => 'busy'), 'Temporary file was still in status missing. (' . $counter . ')');
     }
     /* FALLBACK - SOMETHING WENT WRONG */
     // remove file
     SpoonFile::delete($filename);
     // return status
     $this->output(self::ERROR, array('status' => 'error'), 'Error while retrieving data.');
 }
Example #11
0
 /**
  * Parse the template to a file.
  */
 public function parseToFile()
 {
     SpoonFile::setContent($this->compileDirectory . '/' . $this->getCompileName($this->template), $this->getContent());
 }
Example #12
0
    /**
     * Write a slideshows helper file for the specified module
     *
     * @param string $module The module to write the helper file for.
     */
    public static function writeHelperFile($module)
    {
        $camelcasedModule = ucwords($module);
        $helperFile = FRONTEND_MODULES_PATH . '/' . $module . '/engine/slideshows.php';
        if (!\SpoonFile::exists($helperFile)) {
            $content = '<?php
						class Frontend' . $camelcasedModule . 'SlideshowsModel
						{
							public static function getImages()
							{
								$db = FrontendModel::getContainer()->get(\'database\');
						
								// This should work with an interface so people know what fields to add.
								// For now, check slideshows/layout/templates/basic.tpl to mimick the array structure.
								$records = array();
						
								return $records;
							}
						}
						';
            \SpoonFile::setContent($helperFile, $content);
        }
    }
Example #13
0
 /**
  * Load the data
  */
 private function getRealData()
 {
     // no search term = no search
     if (!$this->term) {
         return;
     }
     // set url
     $this->pagination['url'] = FrontendNavigation::getURLForBlock('search') . '?form=search&q=' . $this->term;
     $this->pagination['limit'] = FrontendModel::getModuleSetting('search', 'overview_num_items', 20);
     // populate calculated fields in pagination
     $this->pagination['requested_page'] = $this->requestedPage;
     $this->pagination['offset'] = $this->pagination['requested_page'] * $this->pagination['limit'] - $this->pagination['limit'];
     // get items
     $this->items = FrontendSearchModel::search($this->term, $this->pagination['limit'], $this->pagination['offset']);
     // populate count fields in pagination
     // this is done after actual search because some items might be activated/deactivated (getTotal only does rough checking)
     $this->pagination['num_items'] = FrontendSearchModel::getTotal($this->term);
     $this->pagination['num_pages'] = (int) ceil($this->pagination['num_items'] / $this->pagination['limit']);
     // num pages is always equal to at least 1
     if ($this->pagination['num_pages'] == 0) {
         $this->pagination['num_pages'] = 1;
     }
     // redirect if the request page doesn't exist
     if ($this->requestedPage > $this->pagination['num_pages'] || $this->requestedPage < 1) {
         $this->redirect(FrontendNavigation::getURL(404));
     }
     // debug mode = no cache
     if (!SPOON_DEBUG) {
         // set cache content
         SpoonFile::setContent($this->cacheFile, "<?php\n" . '$pagination = ' . var_export($this->pagination, true) . ";\n" . '$items = ' . var_export($this->items, true) . ";\n?>");
     }
 }
Example #14
0
    /**
     * Build the cache
     *
     * @param string[optional] $language The language to build the cache for, if not passes we use the working language.
     */
    public static function buildCache($language = null)
    {
        // redefine
        $language = $language !== null ? (string) $language : BackendLanguage::getWorkingLanguage();
        // get tree
        $levels = self::getTree(array(0), null, 1, $language);
        // get extras
        $extras = (array) BackendModel::getDB()->getRecords('SELECT i.id, i.module, i.action
			 FROM modules_extras AS i
			 WHERE i.type = ? AND i.hidden = ?', array('block', 'N'), 'id');
        // get widgets
        $widgets = (array) BackendModel::getDB()->getRecords('SELECT i.id, i.module, i.action
			 FROM modules_extras AS i
			 WHERE i.type = ? AND i.hidden = ?', array('widget', 'N'), 'id');
        // search sitemap
        $sitemapID = null;
        foreach ($widgets as $id => $row) {
            if ($row['action'] == 'sitemap') {
                $sitemapID = $id;
                break;
            }
        }
        // init vars
        $keys = array();
        $navigation = array();
        // loop levels
        foreach ($levels as $level => $pages) {
            // loop all items on this level
            foreach ($pages as $pageID => $page) {
                // init var
                $parentID = (int) $page['parent_id'];
                // get URL for parent
                $URL = isset($keys[$parentID]) ? $keys[$parentID] : '';
                // home is special
                if ($pageID == 1) {
                    $page['url'] = '';
                }
                // add it
                $keys[$pageID] = trim($URL . '/' . $page['url'], '/');
                // unserialize
                if (isset($page['meta_data'])) {
                    $page['meta_data'] = @unserialize($page['meta_data']);
                }
                // build navigation array
                $temp = array();
                $temp['page_id'] = (int) $pageID;
                $temp['url'] = $page['url'];
                $temp['full_url'] = $keys[$pageID];
                $temp['title'] = addslashes($page['title']);
                $temp['navigation_title'] = addslashes($page['navigation_title']);
                $temp['has_extra'] = (bool) ($page['has_extra'] == 'Y');
                $temp['no_follow'] = (bool) (isset($page['meta_data']['seo_follow']) && $page['meta_data']['seo_follow'] == 'nofollow');
                $temp['hidden'] = (bool) ($page['hidden'] == 'Y');
                $temp['extra_blocks'] = null;
                // any linked extra's?
                if ($page['extra_ids'] !== null) {
                    // get ids
                    $ids = (array) explode(',', $page['extra_ids']);
                    // loop ids
                    foreach ($ids as $id) {
                        // redefine
                        $id = (int) $id;
                        // available in extras, so add it to the temp-array
                        if (isset($extras[$id])) {
                            $temp['extra_blocks'][$id] = $extras[$id];
                        }
                    }
                }
                // calculate tree-type
                $treeType = 'page';
                if ($page['hidden'] == 'Y') {
                    $treeType = 'hidden';
                }
                // homepage should have a special icon
                if ($pageID == 1) {
                    $treeType = 'home';
                } elseif ($pageID == 404) {
                    $treeType = 'error';
                } elseif ($pageID < 404 && substr_count($page['extra_ids'], $sitemapID) > 0) {
                    // get extras
                    $extraIDs = explode(',', $page['extra_ids']);
                    // loop extras
                    foreach ($extraIDs as $id) {
                        // check if this is the sitemap id
                        if ($id == $sitemapID) {
                            // set type
                            $treeType = 'sitemap';
                            // break it
                            break;
                        }
                    }
                }
                // any data?
                if (isset($page['data'])) {
                    // get data
                    $data = unserialize($page['data']);
                    // internal alias?
                    if (isset($data['internal_redirect']['page_id']) && $data['internal_redirect']['page_id'] != '') {
                        $temp['redirect_page_id'] = $data['internal_redirect']['page_id'];
                        $temp['redirect_code'] = $data['internal_redirect']['code'];
                        $treeType = 'redirect';
                    }
                    // external alias?
                    if (isset($data['external_redirect']['url']) && $data['external_redirect']['url'] != '') {
                        $temp['redirect_url'] = $data['external_redirect']['url'];
                        $temp['redirect_code'] = $data['external_redirect']['code'];
                        $treeType = 'redirect';
                    }
                    // direct action?
                    if (isset($data['is_action']) && $data['is_action']) {
                        $treeType = 'direct_action';
                    }
                }
                // add type
                $temp['tree_type'] = $treeType;
                // add it
                $navigation[$page['type']][$page['parent_id']][$pageID] = $temp;
            }
        }
        // order by URL
        asort($keys);
        // write the key-file
        $keysString = '<?php' . "\n\n";
        $keysString .= '/**' . "\n";
        $keysString .= ' * This file is generated by Fork CMS, it contains' . "\n";
        $keysString .= ' * the mapping between a pageID and the URL' . "\n";
        $keysString .= ' * ' . "\n";
        $keysString .= ' * Fork CMS' . "\n";
        $keysString .= ' * @generated	' . date('Y-m-d H:i:s') . "\n";
        $keysString .= ' */' . "\n\n";
        $keysString .= '// init var' . "\n";
        $keysString .= '$keys = array();' . "\n\n";
        // loop all keys
        foreach ($keys as $pageID => $URL) {
            $keysString .= '$keys[' . $pageID . '] = \'' . $URL . '\';' . "\n";
        }
        // end file
        $keysString .= "\n" . '?>';
        // write the file
        SpoonFile::setContent(FRONTEND_CACHE_PATH . '/navigation/keys_' . $language . '.php', $keysString);
        // write the navigation-file
        $navigationString = '<?php' . "\n\n";
        $navigationString .= '/**' . "\n";
        $navigationString .= ' * This file is generated by Fork CMS, it contains' . "\n";
        $navigationString .= ' * more information about the page-structure' . "\n";
        $navigationString .= ' * ' . "\n";
        $navigationString .= ' * Fork CMS' . "\n";
        $navigationString .= ' * @generated	' . date('Y-m-d H:i:s') . "\n";
        $navigationString .= ' */' . "\n\n";
        $navigationString .= '// init var' . "\n";
        $navigationString .= '$navigation = array();' . "\n\n";
        // loop all types
        foreach ($navigation as $type => $pages) {
            // loop all parents
            foreach ($pages as $parentID => $page) {
                // loop all pages
                foreach ($page as $pageID => $properties) {
                    // loop properties
                    foreach ($properties as $key => $value) {
                        // page_id should be an integer
                        if (is_int($value)) {
                            $line = '$navigation[\'' . $type . '\'][' . $parentID . '][' . $pageID . '][\'' . $key . '\'] = ' . $value . ';' . "\n";
                        } elseif (is_bool($value)) {
                            if ($value) {
                                $line = '$navigation[\'' . $type . '\'][' . $parentID . '][' . $pageID . '][\'' . $key . '\'] = true;' . "\n";
                            } else {
                                $line = '$navigation[\'' . $type . '\'][' . $parentID . '][' . $pageID . '][\'' . $key . '\'] = false;' . "\n";
                            }
                        } elseif ($key == 'extra_blocks') {
                            if ($value === null) {
                                $line = '$navigation[\'' . $type . '\'][' . $parentID . '][' . $pageID . '][\'' . $key . '\'] = null;' . "\n";
                            } else {
                                // init var
                                $extras = array();
                                foreach ($value as $row) {
                                    // init var
                                    $temp = 'array(';
                                    // add properties
                                    $temp .= '\'id\' => ' . (int) $row['id'];
                                    $temp .= ', \'module\' => \'' . (string) $row['module'] . '\'';
                                    if ($row['action'] === null) {
                                        $temp .= ', \'action\' => null';
                                    } else {
                                        $temp .= ', \'action\' => \'' . (string) $row['action'] . '\'';
                                    }
                                    $temp .= ')';
                                    // add into extras
                                    $extras[] = $temp;
                                }
                                // set line
                                $line = '$navigation[\'' . $type . '\'][' . $parentID . '][' . $pageID . '][\'' . $key . '\'] = array(' . implode(', ', $extras) . ');' . "\n";
                            }
                        } else {
                            $line = '$navigation[\'' . $type . '\'][' . $parentID . '][' . $pageID . '][\'' . $key . '\'] = \'' . (string) $value . '\';' . "\n";
                        }
                        // add line
                        $navigationString .= $line;
                    }
                    // end
                    $navigationString .= "\n";
                }
            }
        }
        // end file
        $navigationString .= '?>';
        // write the file
        SpoonFile::setContent(FRONTEND_CACHE_PATH . '/navigation/navigation_' . $language . '.php', $navigationString);
        // get the order
        foreach (array_keys($navigation) as $type) {
            $order[$type] = self::getOrder($navigation, $type, 0);
        }
        // write the key-file
        $editorLinkListString = '/**' . "\n";
        $editorLinkListString .= ' * This file is generated by Fork CMS, it contains' . "\n";
        $editorLinkListString .= ' * the links that can be used by the editor' . "\n";
        $editorLinkListString .= ' * ' . "\n";
        $editorLinkListString .= ' * Fork CMS' . "\n";
        $editorLinkListString .= ' * @generated	' . date('Y-m-d H:i:s') . "\n";
        $editorLinkListString .= ' */' . "\n\n";
        $editorLinkListString .= '// init var' . "\n";
        // init var
        $links = array();
        // init var
        $cachedTitles = (array) BackendModel::getDB()->getPairs('SELECT i.id, i.navigation_title
			 FROM pages AS i
			 WHERE i.id IN(' . implode(',', array_keys($keys)) . ')
			 AND i.language = ?', array($language));
        // loop the types in the order we want them to appear
        foreach (array('page', 'meta', 'footer', 'root') as $type) {
            // any pages?
            if (isset($order[$type])) {
                // loop pages
                foreach ($order[$type] as $pageId => $url) {
                    // skip if we don't have a title
                    if (!isset($cachedTitles[$pageId])) {
                        continue;
                    }
                    // get the title
                    $title = $cachedTitles[$pageId];
                    // split into chunks
                    $urlChunks = explode('/', $url);
                    $count = count($urlChunks);
                    // subpage?
                    if ($count > 1) {
                        // loop while we have more then 1 chunk
                        while (count($urlChunks) > 1) {
                            // remove last chunk of the url
                            array_pop($urlChunks);
                            // build the temporary URL, so we can search for an id
                            $tempUrl = implode('/', $urlChunks);
                            // search the pageID
                            $tempPageId = array_search($tempUrl, $keys);
                            // prepend the title
                            if (!isset($cachedTitles[$tempPageId])) {
                                $title = ' > ' . $title;
                            } else {
                                $title = $cachedTitles[$tempPageId] . ' > ' . $title;
                            }
                        }
                    }
                    // add
                    if (SITE_MULTILANGUAGE) {
                        $links[] = array($title, '/' . $language . '/' . $url);
                    } else {
                        $links[] = array($title, '/' . $url);
                    }
                }
            }
        }
        // add JSON-string
        $editorLinkListString .= 'var linkList = ' . json_encode($links) . ';';
        // write the file
        SpoonFile::setContent(FRONTEND_CACHE_PATH . '/navigation/editor_link_list_' . $language . '.js', $editorLinkListString);
        // trigger an event
        BackendModel::triggerEvent('pages', 'after_recreated_cache');
    }
Example #15
0
 /**
  * Get data from analytics
  *
  * @return	void
  * @param	int $startTimestamp			The start timestamp for the data to collect.
  * @param	int $endTimestamp			The end timestamp for the data to collect.
  * @param	bool[optional] $force		Force getting data. Don't rely on cache.
  * @param	string[optional] $page		The page to get data for.
  * @param	string[optional] $pageId	The id of the page to get data for.
  * @param	string[optional] $filename	The name of the cache file.
  */
 private function getData($startTimestamp, $endTimestamp, $force = false, $page = 'all', $pageId = null, $filename = null)
 {
     // try
     try {
         // get data from cache
         $data = BackendAnalyticsModel::getDataFromCache($startTimestamp, $endTimestamp);
         // nothing in cache - fetch from google and set cache
         if (!isset($data['aggregates']) || $force) {
             $data['aggregates'] = BackendAnalyticsHelper::getAggregates($startTimestamp, $endTimestamp);
         }
         // nothing in cache - fetch from google and set cache
         if (!isset($data['aggregates_total']) || $force) {
             $data['aggregates_total'] = BackendAnalyticsHelper::getAggregates(mktime(0, 0, 0, 1, 1, 2005), mktime(0, 0, 0));
         }
         // nothing in cache - fetch from google and set cache
         if (!isset($data['metrics_per_day']) || $force) {
             $data['metrics_per_day']['entries'] = BackendAnalyticsHelper::getMetricsPerDay($startTimestamp, $endTimestamp);
         }
         // traffic sources, top keywords and top referrals on index page
         if ($page == 'all' || $page == 'index') {
             // nothing in cache - fetch from google and set cache
             if (!isset($data['traffic_sources']) || $force) {
                 $data['traffic_sources']['entries'] = BackendAnalyticsHelper::getTrafficSourcesGrouped(array('pageviews'), $startTimestamp, $endTimestamp, 'pageviews');
             }
             // nothing in cache
             if (!isset($data['top_keywords']) || $force) {
                 // fetch from google and use a safe limit
                 $gaResults = BackendAnalyticsHelper::getKeywords('pageviews', $startTimestamp, $endTimestamp, 'pageviews', 50);
                 // set cache
                 $data['top_keywords']['entries'] = $gaResults['entries'];
             }
             // nothing in cache
             if (!isset($data['top_referrals']) || $force) {
                 // fetch from google and use a safe limit
                 $gaResults = BackendAnalyticsHelper::getReferrals('pageviews', $startTimestamp, $endTimestamp, 'pageviews', 50);
                 // init vars
                 $topReferrals = array();
                 // add entries to items
                 foreach ($gaResults['entries'] as $entry) {
                     $topReferrals[] = array('referrer' => $entry['source'] . $entry['referralPath'], 'pageviews' => $entry['pageviews']);
                 }
                 // set cache
                 $data['top_referrals']['entries'] = $topReferrals;
             }
         }
         // top pages on index and content page
         if ($page == 'all' || $page == 'index' || $page == 'content') {
             // nothing in cache
             if (!isset($data['top_pages']) || $force) {
                 // fetch from google and use a safe limit
                 $gaResults = BackendAnalyticsHelper::getPages('pageviews', $startTimestamp, $endTimestamp, 'pageviews', 50);
                 // set cache
                 $data['top_pages']['entries'] = $gaResults['entries'];
             }
         }
         // top exit pages on content page
         if ($page == 'all' || $page == 'content') {
             // nothing in cache
             if (!isset($data['top_exit_pages']) || $force) {
                 // fetch from google
                 $gaResults = BackendAnalyticsHelper::getPages(array('exits', 'pageviews'), $startTimestamp, $endTimestamp, 'exits', 50);
                 // set cache
                 $data['top_exit_pages']['entries'] = $gaResults['entries'];
             }
         }
         // top exit pages on all pages page
         if ($page == 'all' || $page == 'all_pages') {
             // nothing in cache
             if (!isset($data['pages']) || $force) {
                 // fetch from google
                 $gaResults = BackendAnalyticsHelper::getPages(array('bounces', 'entrances', 'exits', 'newVisits', 'pageviews', 'timeOnSite', 'visits'), $startTimestamp, $endTimestamp, 'pageviews', 50);
                 // set cache
                 $data['pages']['entries'] = $gaResults['entries'];
                 $data['pages']['attributes'] = array('totalResults' => $gaResults['totalResults']);
             }
         }
         // exit pages on exit pages page
         if ($page == 'all' || $page == 'exit_pages') {
             // nothing in cache
             if (!isset($data['exit_pages']) || $force) {
                 // fetch from google
                 $gaResults = BackendAnalyticsHelper::getExitPages(array('bounces', 'entrances', 'exits', 'newVisits', 'pageviews', 'timeOnSite', 'visits'), $startTimestamp, $endTimestamp, 'exits', 50);
                 // set cache
                 $data['exit_pages']['entries'] = $gaResults['entries'];
             }
         }
         // detail page
         if ($page == 'detail_page') {
             // nothing in cache
             if (!isset($data['page' . $pageId]) || $force) {
                 // fetch from google
                 $gaResults = BackendAnalyticsHelper::getDataForPage($pageId, $startTimestamp, $endTimestamp);
                 // set cache
                 $data['page_' . $pageId] = $gaResults;
             }
         }
         // update cache file
         BackendAnalyticsModel::writeCacheFile($data, $startTimestamp, $endTimestamp);
     } catch (Exception $e) {
         // set file content to indicate something went wrong if needed
         if (isset($filename)) {
             SpoonFile::setContent($filename, 'error');
         } else {
             throw new SpoonException('Something went wrong while getting data.');
         }
     }
     // remove temporary file if needed
     if (isset($filename)) {
         SpoonFile::setContent($filename, 'done');
     }
 }
Example #16
0
 }
 if (!in_array($frm->getField('blood')->getValue(), array('', 'O+', 'A+', 'B+', 'AB+', 'O-', 'A-', 'B-', 'AB-'))) {
     $frm->getField('blood')->setError('Please choose from the list only!');
 }
 if ($frm->getField('height')->isFilled()) {
     $frm->getField('height')->isNumeric('Digits only please! eg: 180');
     //it needs to be numeric!
 }
 if ($frm->getField('weight')->isFilled()) {
     $frm->getField('weight')->isNumeric('Digits only please! eg: 80');
     //it needs to be numeric!
 }
 if ($frm->isCorrect()) {
     if ($frm->getField('photo')->isFilled()) {
         $imagename = uniqid();
         SpoonFile::setContent(IMAGE_PATH . '/' . $imagename . '.' . $frm->getField('photo')->getExtension(), SpoonFile::getContent($frm->getField('photo')->getTempFileName()));
         //create Thumbnail
         $frm->getField('photo')->createThumbnail(IMAGE_PATH . '/' . $imagename . '_thumbnail.' . $frm->getField('photo')->getExtension(), 130, 130);
     }
     $company = "";
     for ($i = 1; $i < 6; $i++) {
         $company .= $frm->getField('company' . $i)->getValue() . ', ' . $frm->getField('registerno' . $i)->getValue() . ', ' . $frm->getField('companyno' . $i)->getValue() . ', ' . $frm->getField('companyemail' . $i)->getValue() . ', ' . $frm->getField('shareholder' . $i)->getValue() . ', ' . $frm->getField('registeraddr' . $i)->getValue() . ', ' . $frm->getField('businessaddr' . $i)->getValue();
         if ($i < 6) {
             $company .= ', ';
         }
     }
     //get values from form
     $values = array();
     for ($i = 1; $i < 6; $i++) {
         $values = array_merge($values, array('company' . $i, 'shareholder' . $i, 'registerno' . $i, 'companyno' . $i, 'companyemail' . $i, 'registeraddr' . $i, 'businessaddr' . $i));
     }
Example #17
0
 /**
  * Minify a javascript-file
  *
  * @return	string
  * @param	string $file	The file to be minified.
  */
 private function minifyJavascript($file)
 {
     // create unique filename
     $fileName = md5($file) . '.js';
     $finalURL = FRONTEND_CACHE_URL . '/minified_js/' . $fileName;
     $finalPath = FRONTEND_CACHE_PATH . '/minified_js/' . $fileName;
     // file already exists (if SPOON_DEBUG is true, we should reminify every time
     if (SpoonFile::exists($finalPath) && !SPOON_DEBUG) {
         return $finalURL;
     }
     // grab content
     $content = SpoonFile::getContent(PATH_WWW . $file);
     // remove comments
     $content = preg_replace('/\\/\\*(.*)\\*\\//iUs', '', $content);
     $content = preg_replace('/([\\t\\w]{1,})\\/\\/.*/i', '', $content);
     // remove tabs
     $content = preg_replace('/\\t/i', ' ', $content);
     // remove faulty newlines
     $content = preg_replace('/\\r/iU', '', $content);
     // remove empty lines
     $content = preg_replace('/(^[\\r\\n]*|[\\r\\n]+)[\\s\\t]*[\\r\\n]+/', "\n", $content);
     // store
     SpoonFile::setContent($finalPath, $content);
     // return
     return $finalURL;
 }
Example #18
0
 /**
  * Executes this step.
  */
 public function execute()
 {
     // extend execution limit
     set_time_limit(0);
     // validate all previous steps
     if (!$this->validateForm()) {
         SpoonHTTP::redirect('index.php?step=1');
     }
     // delete cached data
     $this->deleteCachedData();
     // create configuration files
     $this->createConfigurationFiles();
     // init database
     $this->initDatabase();
     // define paths
     $this->definePaths();
     // install modules
     $this->installModules();
     // create locale cache
     $this->createLocaleFiles();
     // already installed
     SpoonFile::setContent(dirname(__FILE__) . '/../cache/installed.txt', date('Y-m-d H:i:s'));
     // show success message
     $this->showSuccess();
     // clear session
     SpoonSession::destroy();
     // show output
     $this->tpl->display('layout/templates/step_7.tpl');
 }
Example #19
0
 /**
  * Function to store the actual content for either HTML or plain text.
  *
  * @param	string $content			The body of the e-mail you wish to send.
  * @param	array $variables		The variables to parse into the content.
  * @param	string[optional] $type	The e-mail type. Either 'html' or 'plain'.
  */
 private function processContent($content, $variables, $type = 'html')
 {
     // check for type
     $type = SpoonFilter::getValue($type, array('html', 'plain'), 'html');
     // exploded string
     $exploded = explode('/', str_replace('\\', '/', $content));
     $filename = end($exploded);
     // check if the string provided is a formatted as a file
     if (SpoonFilter::isFilename($filename) && preg_match('/^[\\S]+\\.\\w{2,3}[\\S]$/', $filename) && !strstr($filename, ' ')) {
         // check if template exists
         if (!SpoonFile::exists($content)) {
             throw new SpoonEmailException('Template not found. (' . $content . ')');
         }
         // store content
         $this->content[$type] = (string) $this->getTemplateContent($content, $variables);
     } else {
         // set the name for the temporary file
         $tempFile = $this->compileDirectory . '/' . md5(uniqid()) . '.tpl';
         // write temp file
         SpoonFile::setContent($tempFile, $content);
         // store content
         $this->content[$type] = (string) $this->getTemplateContent($tempFile, $variables);
         // delete the temporary
         SpoonFile::delete($tempFile);
     }
 }
Example #20
0
 /**
  * Write data to cache file
  *
  * @return	void
  * @param	array $data			The data to write to the cache file.
  * @param	int $startTimestamp		The start timestamp for the cache file.
  * @param	int $endTimestamp		The end timestamp for the cache file.
  */
 public static function writeCacheFile(array $data, $startTimestamp, $endTimestamp)
 {
     // build xml string from data
     $xml = "<?xml version='1.0' encoding='UTF-8'?>\n";
     $xml .= "<analytics start_timestamp=\"" . $startTimestamp . "\" end_timestamp=\"" . $endTimestamp . "\">\n";
     // loop data
     foreach ($data as $type => $records) {
         // init vars
         $attributes = array();
         // there are some attributes
         if (isset($records['attributes']) && !empty($records['attributes'])) {
             // loop em
             foreach ($records['attributes'] as $key => $value) {
                 // add to the attributes string
                 $attributes[] = $key . '="' . $value . '"';
             }
         }
         // build xml
         $xml .= "\t<" . $type . (!empty($attributes) ? ' ' . implode(' ', $attributes) : '') . ">\n";
         // we're not dealing with a page detail
         if (strpos($type, 'page_') === false) {
             // get items
             $items = isset($records['entries']) ? $records['entries'] : $records;
             // loop data
             foreach ($items as $key => $value) {
                 // skip empty items
                 if (is_array($value) && empty($value) || trim((string) $value) === '') {
                     continue;
                 }
                 // value contains an array
                 if (is_array($value)) {
                     // there are values
                     if (!empty($value)) {
                         // build xml
                         $xml .= "\t\t<entry>\n";
                         // loop data
                         foreach ($value as $entryKey => $entryValue) {
                             // build xml
                             $xml .= "\t\t\t<" . $entryKey . "><![CDATA[" . $entryValue . "]]></" . $entryKey . ">\n";
                         }
                         // end xml element
                         $xml .= "\t\t</entry>\n";
                     }
                 } else {
                     $xml .= "\t\t<" . $key . ">" . $value . "</" . $key . ">\n";
                 }
             }
         } else {
             // loop data
             foreach ($records as $subkey => $subitems) {
                 // build xml
                 $xml .= "\t\t<" . $subkey . ">\n";
                 // subitems is an array
                 if (is_array($subitems)) {
                     // loop data
                     foreach ($subitems as $key => $value) {
                         // skip empty items
                         if (is_array($value) && empty($value) || trim((string) $value) === '') {
                             continue;
                         }
                         // value contains an array
                         if (is_array($value)) {
                             // there are values
                             if (!empty($value)) {
                                 // build xml
                                 $xml .= "\t\t\t<entry>\n";
                                 // loop data
                                 foreach ($value as $entryKey => $entryValue) {
                                     // build xml
                                     $xml .= "\t\t\t\t<" . $entryKey . "><![CDATA[" . $entryValue . "]]></" . $entryKey . ">\n";
                                 }
                                 // end xml element
                                 $xml .= "\t\t\t</entry>\n";
                             }
                         } else {
                             $xml .= "\t\t<" . $key . ">" . $value . "</" . $key . ">\n";
                         }
                     }
                 } else {
                     $xml .= "<![CDATA[" . (string) $subitems . "]]>";
                 }
                 // end xml element
                 $xml .= "\t\t</" . $subkey . ">\n";
             }
         }
         // end xml element
         $xml .= "\t</" . $type . ">\n";
     }
     // end xml string
     $xml .= "</analytics>";
     // perform checks for valid xml and throw exception if needed
     $simpleXml = @simplexml_load_string($xml);
     if ($simpleXml === false) {
         throw new BackendException('The xml of the cache file is invalid.');
     }
     // get filename
     $filename = $startTimestamp . '_' . $endTimestamp . '.xml';
     // all is well
     SpoonFile::setContent(BACKEND_CACHE_PATH . '/analytics/' . $filename, $xml);
 }
Example #21
0
 /**
  * Write a message to the log.
  *
  * @return	SpoonLog
  * @param	string $message		the message that should be logged.
  */
 public function write($message)
 {
     // milliseconds
     list($milliseconds) = explode(' ', microtime());
     $milliseconds = round($milliseconds * 1000, 0);
     // redefine var
     $message = date('Y-m-d H:i:s') . ' ' . $milliseconds . 'ms | ' . $message . PHP_EOL;
     // file
     $file = $this->getPath() . '/' . $this->type . '.log';
     // rename if needed
     if (SpoonFile::exists($file) && (int) @filesize($file) >= $this->maxLogSize * 1024 * 1024) {
         // start new log file
         $this->rotate();
     }
     // write content
     SpoonFile::setContent($file, $message, true, true);
     // self
     return $this;
 }