Beispiel #1
0
function addUser($args)
{
    global $dbUsers;
    global $Language;
    // Check if the username already exist in db.
    if (Text::isEmpty($args['username'])) {
        Alert::set($Language->g('username-field-is-empty'));
        return false;
    }
    if ($dbUsers->userExists($args['username'])) {
        Alert::set($Language->g('username-already-exists'));
        return false;
    }
    // Validate password.
    if ($args['password'] != $args['confirm-password'] || Text::isEmpty($args['password'])) {
        Alert::set($Language->g('The password and confirmation password do not match'));
        return false;
    }
    // Add the user.
    if ($dbUsers->add($args)) {
        Alert::set($Language->g('user-has-been-added-successfully'));
        return true;
    } else {
        Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to create the account.');
        return false;
    }
}
Beispiel #2
0
 public function add($args)
 {
     $dataForDb = array();
     // This data will be saved in the database
     $dataForFile = array();
     // This data will be saved in the file
     // Generate the database key.
     $key = $this->generateKey($args['slug']);
     // The user is always the one loggued.
     $args['username'] = Session::get('username');
     if (Text::isEmpty($args['username'])) {
         return false;
     }
     // The current unix time stamp.
     if (empty($args['unixTimeCreated'])) {
         $args['unixTimeCreated'] = Date::unixTime();
     }
     // Verify arguments with the database fields.
     foreach ($this->dbFields as $field => $options) {
         if (isset($args[$field])) {
             // Sanitize if will be saved on database.
             if (!$options['inFile']) {
                 $tmpValue = Sanitize::html($args[$field]);
             } else {
                 $tmpValue = $args[$field];
             }
         } else {
             $tmpValue = $options['value'];
         }
         // Check where the field will be written, if in the file or in the database.
         if ($options['inFile']) {
             $dataForFile[$field] = Text::firstCharUp($field) . ': ' . $tmpValue;
         } else {
             // Set type
             settype($tmpValue, gettype($options['value']));
             // Save on database
             $dataForDb[$field] = $tmpValue;
         }
     }
     // Make the directory.
     if (Filesystem::mkdir(PATH_POSTS . $key) === false) {
         Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to create the directory ' . PATH_POSTS . $key);
         return false;
     }
     // Make the index.txt and save the file.
     $data = implode("\n", $dataForFile);
     if (file_put_contents(PATH_POSTS . $key . DS . 'index.txt', $data) === false) {
         Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to put the content in the file index.txt');
         return false;
     }
     // Save the database
     $this->db[$key] = $dataForDb;
     if ($this->save() === false) {
         Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to save the database file.');
         return false;
     }
     return true;
 }
Beispiel #3
0
 public function siteBodyEnd()
 {
     $html = PHP_EOL . '<!-- Google Analytics -->' . PHP_EOL;
     $html .= "<script>\n\t(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){\n\t(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),\n\tm=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)\n\t})(window,document,'script','//www.google-analytics.com/analytics.js','ga');\n\n\tga('create', '" . $this->getDbField('tracking-id') . "', 'auto');\n\tga('send', 'pageview');\n</script>" . PHP_EOL;
     if (Text::isEmpty($this->getDbField('tracking-id'))) {
         return false;
     }
     return $html;
 }
Beispiel #4
0
 public function siteBodyEnd()
 {
     $html = PHP_EOL . '<!-- Yandex.Metrika counter -->' . PHP_EOL;
     $html .= "<script type='text/javascript'>\n    (function (d, w, c) {\n        (w[c] = w[c] || []).push(function() {\n            try {\n                w.yaCounter" . $this->getDbField('yametrika-id') . " = new Ya.Metrika({\n                    id:" . $this->getDbField('yametrika-id') . ",\n                    clickmap:true,\n                    trackLinks:true,\n                    accurateTrackBounce:true\n                });\n            } catch(e) { }\n        });\n\n        var n = d.getElementsByTagName('script')[0],\n            s = d.createElement('script'),\n            f = function () { n.parentNode.insertBefore(s, n); };\n        s.type = 'text/javascript';\n        s.async = true;\n        s.src = 'https://mc.yandex.ru/metrika/watch.js';\n\n        if (w.opera == '[object Opera]') {\n            d.addEventListener('DOMContentLoaded', f, false);\n        } else { f(); }\n    })(document, window, 'yandex_metrika_callbacks');\n</script>\n<noscript><div><img src='https://mc.yandex.ru/watch/" . $this->getDbField('yametrika-id') . "' style='position:absolute; left:-9999px;' alt='' /></div></noscript>" . PHP_EOL;
     if (Text::isEmpty($this->getDbField('yametrika-id'))) {
         return false;
     }
     return $html;
 }
Beispiel #5
0
 public function siteHead()
 {
     $html = PHP_EOL . '<!-- Pinterest Verification -->' . PHP_EOL;
     $html .= '<meta name="p:domain_verify" content="' . $this->getDbField('pinterest-verification-code') . '">' . PHP_EOL;
     if (Text::isEmpty($this->getDbField('pinterest-verification-code'))) {
         return false;
     }
     return $html;
 }
Beispiel #6
0
function setPassword($username, $new_password, $confirm_password)
{
    global $dbUsers;
    global $Language;
    if ($new_password === $confirm_password && !Text::isEmpty($new_password)) {
        if ($dbUsers->setPassword($username, $new_password)) {
            Alert::set($Language->g('The changes have been saved'));
        } else {
            Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to change the user password.');
        }
    } else {
        Alert::set($Language->g('The password and confirmation password do not match'));
        return false;
    }
}
Beispiel #7
0
 /**
  * Renders the tag
  *
  * @return string The HTML string
  */
 public function render()
 {
     $html = new Text();
     $html->append('<')->append($this->getName());
     foreach ($this->attributes as $name => $value) {
         $html->append(' ')->append($name)->append('=')->append('"')->append($value)->append('"');
     }
     if ($this->text->isEmpty()) {
         if ($this->type == self::TYPE_BLOCK) {
             return (string) $html->append('>')->append('</')->append($this->getName())->append('>');
         } else {
             return (string) $html->append($this->emptyTagSuffix);
         }
     }
     return (string) $html->append('>')->append($this->text)->append('</')->append($this->getName())->append('>');
 }
Beispiel #8
0
function addUser($args)
{
    global $dbUsers;
    global $Language;
    // Check empty username
    if (Text::isEmpty($args['new_username'])) {
        Alert::set($Language->g('username-field-is-empty'), ALERT_STATUS_FAIL);
        return false;
    }
    // Check already exist username
    if ($dbUsers->userExists($args['new_username'])) {
        Alert::set($Language->g('username-already-exists'), ALERT_STATUS_FAIL);
        return false;
    }
    // Password length
    if (strlen($args['new_password']) < 6) {
        Alert::set($Language->g('Password must be at least 6 characters long'), ALERT_STATUS_FAIL);
        return false;
    }
    // Check new password and confirm password are equal
    if ($args['new_password'] != $args['confirm_password']) {
        Alert::set($Language->g('The password and confirmation password do not match'), ALERT_STATUS_FAIL);
        return false;
    }
    // Filter form fields
    $tmp = array();
    $tmp['username'] = $args['new_username'];
    $tmp['password'] = $args['new_password'];
    $tmp['role'] = $args['role'];
    // Add the user to the database
    if ($dbUsers->add($tmp)) {
        Alert::set($Language->g('user-has-been-added-successfully'), ALERT_STATUS_OK);
        return true;
    } else {
        Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to create the account.');
        return false;
    }
}
Beispiel #9
0
 public function generateKey($text, $parent = NO_PARENT_CHAR, $returnSlug = false, $oldKey = '')
 {
     if (Text::isEmpty($text)) {
         $text = 'empty';
     }
     if (Text::isEmpty($parent) || $parent == NO_PARENT_CHAR) {
         $newKey = Text::cleanUrl($text);
     } else {
         $newKey = Text::cleanUrl($parent) . '/' . Text::cleanUrl($text);
     }
     if ($newKey !== $oldKey) {
         // Verify if the key is already been used.
         if (isset($this->db[$newKey])) {
             if (!Text::endsWithNumeric($newKey)) {
                 $newKey = $newKey . '-0';
             }
             while (isset($this->db[$newKey])) {
                 $newKey++;
             }
         }
     }
     if ($returnSlug) {
         $explode = explode('/', $newKey);
         if (isset($explode[1])) {
             return $explode[1];
         }
         return $explode[0];
     }
     return $newKey;
 }
Beispiel #10
0
 public function add($args)
 {
     $dataForDb = array();
     // This data will be saved in the database
     $dataForFile = array();
     // This data will be saved in the file
     $currentDate = Date::current(DB_DATE_FORMAT);
     // Generate the database key.
     $key = $this->generateKey($args['slug']);
     // The user is always who is loggued.
     $args['username'] = Session::get('username');
     if (Text::isEmpty($args['username'])) {
         return false;
     }
     // Date
     if (!Valid::date($args['date'], DB_DATE_FORMAT)) {
         $args['date'] = $currentDate;
     }
     // Schedule post?
     if ($args['date'] > $currentDate && $args['status'] == 'published') {
         $args['status'] = 'scheduled';
     }
     // Verify arguments with the database fields.
     foreach ($this->dbFields as $field => $options) {
         // If the field is in the arguments.
         if (isset($args[$field])) {
             if ($field == 'tags') {
                 $tmpValue = $this->generateTags($args['tags']);
             } else {
                 // Sanitize if will be saved on database.
                 if (!$options['inFile']) {
                     $tmpValue = Sanitize::html($args[$field]);
                 } else {
                     $tmpValue = $args[$field];
                 }
             }
         } else {
             $tmpValue = $options['value'];
         }
         // Check where the field will be written, if in the file or in the database.
         if ($options['inFile']) {
             $dataForFile[$field] = Text::firstCharUp($field) . ': ' . $tmpValue;
         } else {
             // Set type
             settype($tmpValue, gettype($options['value']));
             // Save on database
             $dataForDb[$field] = $tmpValue;
         }
     }
     // Make the directory.
     if (Filesystem::mkdir(PATH_POSTS . $key) === false) {
         Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to create the directory ' . PATH_POSTS . $key);
         return false;
     }
     // Make the index.txt and save the file.
     $data = implode("\n", $dataForFile);
     if (file_put_contents(PATH_POSTS . $key . DS . 'index.txt', $data) === false) {
         Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to put the content in the file index.txt');
         return false;
     }
     // Save the database
     $this->db[$key] = $dataForDb;
     // Sort posts before save.
     $this->sortByDate();
     if ($this->save() === false) {
         Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to save the database file.');
         return false;
     }
     return $key;
 }
Beispiel #11
0
 private function getSlugAfterFilter($filter)
 {
     // Remove both slash from the filter
     $filter = trim($filter, '/');
     // Add to the filter the root directory
     $filter = HTML_PATH_ROOT . $filter;
     // Check if the filter is in the uri.
     $position = Text::stringPosition($this->uri, $filter);
     // If the position is FALSE, the filter isn't in the URI.
     if ($position === false) {
         return false;
     }
     // Start position to cut
     $start = $position + Text::length($filter);
     // End position to cut
     $end = $this->uriStrlen;
     // Get the slug from the URI
     $slug = Text::cut($this->uri, $start, $end);
     if (Text::isEmpty($slug)) {
         return '';
     }
     if ($slug[0] == '/') {
         return ltrim($slug, '/');
     }
     if ($filter == HTML_PATH_ROOT) {
         return $slug;
     }
     return false;
 }
Beispiel #12
0
    $Page = $pages[$key];
    $friendlyURL = Text::isEmpty($Url->filters('page')) ? '/' . $Page->key() : '/' . $Url->filters('page') . '/' . $Page->key();
    echo '<tr>';
    echo '<td>';
    echo '<a href="' . HTML_PATH_ADMIN_ROOT . 'edit-page/' . $Page->key() . '">' . ($Page->published() ? '' : '<span class="label-draft">' . $Language->g('Draft') . '</span> ') . ($Page->title() ? $Page->title() : '<span class="label-empty-title">' . $Language->g('Empty title') . '</span> ') . '</a>';
    echo '</td>';
    echo '<td class="uk-text-center">' . $Page->position() . '</td>';
    echo '<td><a target="_blank" href="' . $Page->permalink() . '">' . $friendlyURL . '</a></td>';
    echo '</tr>';
    // If the page has children
    if (isset($pagesParents[$Page->key()])) {
        // Get the children
        $children = $pagesParents[$Page->key()];
        foreach ($children as $keyChildren => $dbChildren) {
            // Parent page
            $Page = $pages[$keyChildren];
            $friendlyURL = Text::isEmpty($Url->filters('page')) ? '/' . $Page->key() : '/' . $Url->filters('page') . '/' . $Page->key();
            echo '<tr class="children">';
            echo '<td class="children">';
            echo '<a href="' . HTML_PATH_ADMIN_ROOT . 'edit-page/' . $Page->key() . '">' . ($Page->published() ? '' : '<span class="label-draft">' . $Language->g('Draft') . '</span> ') . ($Page->title() ? $Page->title() : '<span class="label-empty-title">' . $Language->g('Empty title') . '</span> ') . '</a>';
            echo '</td>';
            echo '<td class="uk-text-center">' . $Page->position() . '</td>';
            echo '<td><a target="_blank" href="' . $Page->permalink() . '">' . $friendlyURL . '</a></td>';
            echo '</tr>';
        }
    }
}
echo '
</tbody>
</table>
';
 /**
  * Enter description here ...
  * 
  * @return	Text
  */
 protected function _findExcerpt()
 {
     $config = $this->getConfig();
     $excerpt = null;
     $SEO_ignFilters = $config->get($config::EXCERPT_SEO_TAGS_IGNORE_FILTERS);
     foreach ($config->get($config::EXCERPT_SEARCH_TAGS) as $tag) {
         switch ($tag) {
             case 'meta og:description':
                 // method: search <meta property="og:description" content="" />
                 // try to find a meta tag with property og:description as according to
                 // open graph protocol (@see http://developers.facebook.com/docs/opengraph/)
                 $elements = $this->_xpath->query('/html/head/meta[@property="og:description"]/@content');
                 foreach ($elements as $elem) {
                     $candidate = new Text($elem->nodeValue, true, $this->_config);
                     if (!$candidate->isEmpty() && ($SEO_ignFilters || $candidate->matches($this->_getFilterOpts(static::FIELD_EXCERPT)))) {
                         // found
                         $excerpt = $candidate;
                         break 3;
                     }
                 }
                 break;
             case 'meta description':
                 // method: search <meta name="description" content="" />
                 $elements = $this->_xpath->query('/html/head/meta[@name="description"]/@content');
                 foreach ($elements as $elem) {
                     $candidate = new Text($elem->nodeValue, true, $this->_config);
                     if (!$candidate->isEmpty() && ($SEO_ignFilters || $candidate->matches($this->_getFilterOpts(static::FIELD_EXCERPT)))) {
                         // found
                         $excerpt = $candidate;
                         break 3;
                     }
                 }
                 break;
             case 'article section':
                 // new html5 method
                 $elements = $this->_xpath->query('/html/body//article/section');
                 foreach ($elements as $elem) {
                     $candidate = new Text($elem->nodeValue, true, $this->_config);
                     if ($candidate->matches($this->_getFilterOpts(static::FIELD_EXCERPT))) {
                         // found
                         $excerpt = $candidate;
                         break 3;
                     }
                 }
                 break;
             default:
                 // default behaviour: search "normal" tags for text
                 $elements = $this->_dom->getElementsByTagName($tag);
                 foreach ($elements as $elem) {
                     $candidate = new Text(Util::DOMinnerHTML($elem), true, $this->_config);
                     if ($candidate->matches($this->_getFilterOpts(static::FIELD_EXCERPT))) {
                         // found
                         $excerpt = $candidate;
                         break 3;
                     }
                 }
         }
         // end switch
     }
     // end foreach
     if ($excerpt instanceof Text) {
         if ($config->get($config::EXCERPT_TRUNCATE)) {
             $excerpt->truncate($config->get($config::EXCERPT_TRUNCATE_LENGTH), $config->get($config::EXCERPT_TRUNCATE_TERMINATOR));
         }
         if ($config->get($config::EXCERPT_LINKIFY)) {
             $excerpt->linkify();
         }
     }
     $this->excerpt = $excerpt;
     return $excerpt;
 }
Beispiel #14
0
 public function domain()
 {
     // If the URL field is not set, try detect the domain.
     if (Text::isEmpty($this->url())) {
         if (!empty($_SERVER['HTTPS'])) {
             $protocol = 'https://';
         } else {
             $protocol = 'http://';
         }
         $domain = $_SERVER['HTTP_HOST'];
         return $protocol . $domain . HTML_PATH_ROOT;
     }
     // Parse the domain from the field URL.
     $parse = parse_url($this->url());
     $domain = $parse['scheme'] . "://" . $parse['host'];
     return $domain;
 }
Beispiel #15
0
	<th>' . $L->g('Friendly URL') . '</th>
	</tr>
</thead>
<tbody>
';
foreach ($posts as $Post) {
    $status = false;
    if ($Post->scheduled()) {
        $status = $Language->g('Scheduled');
    } elseif (!$Post->published()) {
        $status = $Language->g('Draft');
    }
    echo '<tr>';
    echo '<td><a href="' . HTML_PATH_ADMIN_ROOT . 'edit-post/' . $Post->key() . '">' . ($status ? '<span class="label-draft">' . $status . '</span>' : '') . ($Post->title() ? $Post->title() : '<span class="label-empty-title">' . $Language->g('Empty title') . '</span> ') . '</a></td>';
    echo '<td class="uk-text-center">' . $Post->dateRaw() . '</td>';
    $friendlyURL = Text::isEmpty($Url->filters('post')) ? '/' . $Post->key() : '/' . $Url->filters('post') . '/' . $Post->key();
    echo '<td><a target="_blank" href="' . $Post->permalink() . '">' . $friendlyURL . '</a></td>';
    echo '</tr>';
}
echo '
</tbody>
</table>
';
?>

<div id="paginator">
<ul>
<?php 
if (Paginator::get('showNewer')) {
    echo '<li class="previous"><a href="' . HTML_PATH_ADMIN_ROOT . 'manage-posts?page=' . Paginator::get('prevPage') . '">« ' . $Language->g('Prev page') . '</a></li>';
}