Example #1
0
 /**
  * process the class
  *
  * @since 3.0.0
  *
  * @return string
  */
 public function process()
 {
     $specialFilter = new Filter\Special();
     $emailFilter = new Filter\Email();
     $urlFilter = new Filter\Url();
     $htmlFilter = new Filter\Html();
     /* process post */
     $postArray = ['author' => $specialFilter->sanitize($this->_request->getPost('author')), 'email' => $emailFilter->sanitize($this->_request->getPost('email')), 'url' => $urlFilter->sanitize($this->_request->getPost('url')), 'text' => $htmlFilter->sanitize($this->_request->getPost('text')), 'article' => $specialFilter->sanitize($this->_request->getPost('article')), 'task' => $this->_request->getPost('task'), 'solution' => $this->_request->getPost('solution')];
     $route = build_route('articles', $postArray['article']);
     /* handle error */
     $messageArray = $this->_validate($postArray);
     if ($messageArray) {
         return $this->_error(['route' => $route, 'message' => $messageArray]);
     }
     /* handle success */
     $createArray = ['author' => $postArray['author'], 'email' => $postArray['email'], 'url' => $postArray['url'], 'text' => $postArray['text'], 'language' => Db::forTablePrefix('articles')->whereIdIs($postArray['article'])->findOne()->language, 'article' => $postArray['article'], 'status' => Db::getSetting('verification') ? 0 : 1];
     $mailArray = ['email' => $postArray['email'], 'url' => $postArray['url'], 'route' => $route, 'author' => $postArray['author'], 'text' => $postArray['text'], 'article' => Db::forTablePrefix('articles')->whereIdIs($postArray['article'])->findOne()->title];
     /* create */
     if (!$this->_create($createArray)) {
         return $this->_error(['route' => $route, 'message' => $this->_language->get('something_wrong')]);
     }
     /* mail */
     if (!$this->_mail($mailArray)) {
         return $this->_warning(['route' => $route, 'message' => $this->_language->get('email_failed')]);
     }
     return $this->_success(['route' => $route, 'timeout' => Db::getSetting('notification') ? 2 : 0, 'message' => Db::getSetting('moderation') ? $this->_language->get('comment_moderation') : $this->_language->get('comment_sent')]);
 }
Example #2
0
 /**
  * @param object $categories
  * @param object $articles
  *
  * @return string
  */
 protected static function _writeXML($categories = null, $articles = null)
 {
     $writer = new XMLWriter();
     $writer->openMemory();
     $writer->setIndent(true);
     $writer->setIndentString('	');
     $writer->startDocument('1.0', Db::getSetting('charset'));
     $writer->startElement('urlset');
     $writer->writeAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
     $writer->startElement('url');
     $writer->writeElement('loc', Registry::get('root'));
     $writer->endElement();
     /* process categories */
     foreach ($categories as $value) {
         $writer->startElement('url');
         $writer->writeElement('loc', Registry::get('root') . Registry::get('parameterRoute') . build_route('categories', $value->id));
         $writer->writeElement('lastmod', date('c', strtotime($value->date)));
         $writer->endElement();
     }
     /* process articles */
     foreach ($articles as $value) {
         $writer->startElement('url');
         $writer->writeElement('loc', Registry::get('root') . Registry::get('parameterRoute') . build_route('articles', $value->id));
         $writer->writeElement('lastmod', date('c', strtotime($value->date)));
         $writer->endElement();
     }
     $writer->endElement();
     $writer->endDocument();
     return $writer->outputMemory(true);
 }
Example #3
0
 /**
  * render
  *
  * @since 2.2.0
  *
  * @return string
  */
 public static function render()
 {
     $output = null;
     $outputItem = null;
     /* html elements */
     $titleElement = new Html\Element();
     $titleElement->init('h3', array('class' => self::$_config['className']['title']));
     $linkElement = new Html\Element();
     $linkElement->init('a');
     $listElement = new Html\Element();
     $listElement->init('ul', array('class' => self::$_config['className']['list']));
     /* fetch articles */
     $articles = Db::forTablePrefix('articles')->where('status', 1)->whereIn('language', array(Registry::get('language'), ''))->orderByDesc('category')->findArray();
     /* process articles */
     if (!$articles) {
         $error = Language::get('article_no') . Language::get('point');
     } else {
         $accessValidator = new Validator\Access();
         $accessDeny = 0;
         $lastCategory = 0;
         foreach ($articles as $value) {
             if ($accessValidator->validate($value['access'], Registry::get('myGroups')) === Validator\ValidatorInterface::PASSED) {
                 $currentCategory = $value['category'];
                 /* collect output */
                 if ($lastCategory != $currentCategory) {
                     if ($lastCategory > 0) {
                         $output .= $listElement->html($outputItem);
                         $outputItem = null;
                     }
                     $output .= $titleElement->text($currentCategory < 1 ? Language::get('uncategorized') : Db::forTablePrefix('categories')->whereIdIs($currentCategory)->findOne()->title);
                 }
                 /* collect item output */
                 $outputItem .= '<li>';
                 $outputItem .= $linkElement->attr(array('href' => $value['category'] < 1 ? $value['alias'] : build_route('articles', $value['id']), 'title' => $value['description'] ? $value['description'] : $value['title']))->text($value['title']);
                 $outputItem .= '</li>';
                 /* collect list output */
                 if (end($articles) === $value) {
                     $output .= $listElement->html($outputItem);
                     $outputItem = null;
                 }
                 $lastCategory = $currentCategory;
             } else {
                 $accessDeny++;
             }
         }
         /* handle access */
         if (count($articles) === $accessDeny) {
             $error = Language::get('access_no') . Language::get('point');
         }
     }
     /* handle error */
     if ($error) {
         $output = $listElement->html('<li>' . $error . '</li>');
     }
     return $output;
 }
Example #4
0
 /**
  * render
  *
  * @since 2.2.0
  *
  * @return string
  */
 public static function render()
 {
     $output = '';
     $outputItem = '';
     /* html elements */
     $titleElement = new Element('h3', array('class' => self::$_config['className']['title']));
     $linkElement = new Element('a');
     $listElement = new Element('ul', array('class' => self::$_config['className']['list']));
     /* fetch articles */
     $articles = Db::forTablePrefix('articles')->selectExpr('*, YEAR(date) as year, MONTH(date) as month')->where('status', 1)->whereIn('language', array(Registry::get('language'), ''))->orderByDesc('date')->findArray();
     /* process articles */
     if (empty($articles)) {
         $error = Language::get('article_no') . Language::get('point');
     } else {
         $accessValidator = new Validator\Access();
         $accessDeny = 0;
         $lastDate = 0;
         foreach ($articles as $value) {
             if ($accessValidator->validate($value['access'], Registry::get('myGroups')) === Validator\ValidatorInterface::PASSED) {
                 $currentDate = $value['month'] + $value['year'];
                 /* collect output */
                 if ($lastDate != $currentDate) {
                     if ($lastDate > 0) {
                         $output .= $listElement->html($outputItem);
                         $outputItem = '';
                     }
                     $output .= $titleElement->text(Language::get($value['month'] - 1, '_month') . ' ' . $value['year']);
                 }
                 /* collect item output */
                 $outputItem .= '<li>';
                 $outputItem .= $linkElement->attr(array('href' => $value['category'] < 1 ? $value['alias'] : build_route('articles', $value['id']), 'title' => $value['description'] ? $value['description'] : $value['title']))->text($value['title']);
                 $outputItem .= '</li>';
                 /* collect list output */
                 if (end($articles) === $value) {
                     $output .= $listElement->html($outputItem);
                     $outputItem = '';
                 }
                 $lastDate = $currentDate;
             } else {
                 $accessDeny++;
             }
         }
         /* handle access */
         if (count($articles) === $accessDeny) {
             $error = Language::get('access_no') . Language::get('point');
         }
     }
     /* handle error */
     if ($error) {
         $output = $listElement->html('<li>' . $error . '</li>');
     }
     return $output;
 }
Example #5
0
 /**
  * render
  *
  * @since 2.2.0
  *
  * @return string
  */
 public static function render()
 {
     $output = null;
     /* html elements */
     $titleElement = new Html\Element();
     $titleElement->init('h3', ['class' => self::$_configArray['className']['title']]);
     $linkElement = new Html\Element();
     $linkElement->init('a');
     $listElement = new Html\Element();
     $listElement->init('ul', ['class' => self::$_configArray['className']['list']]);
     /* query articles */
     $articles = Db::forTablePrefix('articles')->where('status', 1)->whereLanguageIs(Registry::get('language'))->orderByDesc('date')->findMany();
     /* process articles */
     if (!$articles) {
         $error = Language::get('article_no') . Language::get('point');
     } else {
         $accessValidator = new Validator\Access();
         $accessDeny = 0;
         $lastDate = 0;
         foreach ($articles as $value) {
             if ($accessValidator->validate($value->access, Registry::get('myGroups')) === Validator\ValidatorInterface::PASSED) {
                 $month = date('n', strtotime($value->date));
                 $year = date('Y', strtotime($value->date));
                 $currentDate = $month + $year;
                 /* collect output */
                 if ($lastDate != $currentDate) {
                     $output .= $titleElement->text(Language::get($month - 1, '_month') . ' ' . $year);
                 }
                 $lastDate = $currentDate;
                 /* collect item output */
                 $outputItem = '<li>';
                 $outputItem .= $linkElement->attr(['href' => Registry::get('parameterRoute') . build_route('articles', $value->id), 'title' => $value->description ? $value->description : $value->title])->text($value->title);
                 $outputItem .= '</li>';
                 /* collect list output */
                 $output .= $listElement->html($outputItem);
             } else {
                 $accessDeny++;
             }
         }
         /* handle access */
         if (count($articles) === $accessDeny) {
             $error = Language::get('access_no') . Language::get('point');
         }
     }
     /* handle error */
     if ($error) {
         $output = $listElement->html('<li>' . $error . '</li>');
     }
     return $output;
 }
Example #6
0
/**
 * sitemap xml
 *
 * @since 1.2.1
 * @deprecated 2.0.0
 *
 * @package Redaxscript
 * @category Modules
 * @author Henry Ruhs
 */
function sitemap_xml()
{
    /* query categories */
    $categories_query = 'SELECT id, alias, parent FROM ' . PREFIX . 'categories WHERE status = 1 && access = 0 ORDER BY rank ASC';
    $categories_result = mysql_query($categories_query);
    /* collect output */
    $output = '<?xml version="1.0" encoding="' . s('charset') . '"?>' . PHP_EOL;
    $output .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . PHP_EOL;
    $output .= '<url><loc>' . ROOT . '</loc><lastmod>' . TODAY . '</lastmod><changefreq>daily</changefreq><priority>1.0</priority></url>' . PHP_EOL;
    if ($categories_result) {
        while ($r = mysql_fetch_assoc($categories_result)) {
            if ($r) {
                foreach ($r as $key => $value) {
                    ${$key} = stripslashes($value);
                }
            }
            /* build route */
            if ($parent == 0) {
                $route = $alias;
            } else {
                $route = build_route('categories', $id);
            }
            /* collect output */
            $output .= '<url><loc>' . ROOT . '/' . REWRITE_ROUTE . $route . '</loc><lastmod>' . TODAY . '</lastmod><changefreq>weekly</changefreq><priority>0.5</priority></url>' . PHP_EOL;
        }
    }
    /* query articles */
    $articles_query = 'SELECT id, alias, category FROM ' . PREFIX . 'articles WHERE status = 1 && access = 0 ORDER BY rank ASC';
    $articles_result = mysql_query($articles_query);
    /* collect output */
    if ($articles_result) {
        while ($r = mysql_fetch_assoc($articles_result)) {
            if ($r) {
                foreach ($r as $key => $value) {
                    ${$key} = stripslashes($value);
                }
            }
            /* build route */
            if ($category == 0) {
                $route = $alias;
            } else {
                $route = build_route('articles', $id);
            }
            $output .= '<url><loc>' . ROOT . '/' . REWRITE_ROUTE . $route . '</loc><lastmod>' . TODAY . '</lastmod><changefreq>weekly</changefreq><priority>0.5</priority></url>' . PHP_EOL;
        }
    }
    $output .= '</urlset>';
    echo $output;
}
Example #7
0
 /**
  * render the view
  *
  * @since 3.0.0
  *
  * @param array $resultArray array for the result
  *
  * @return string
  */
 public function render($resultArray = [])
 {
     $output = Hook::trigger('resultListStart');
     $accessValidator = new Validator\Access();
     /* html elements */
     $titleElement = new Html\Element();
     $titleElement->init('h2', ['class' => 'rs-title-result']);
     $listElement = new Html\Element();
     $listElement->init('ol', ['class' => 'rs-list-result']);
     $itemElement = new Html\Element();
     $itemElement->init('li');
     $linkElement = new Html\Element();
     $linkElement->init('a', ['class' => 'rs-link-result']);
     $textElement = new Html\Element();
     $textElement->init('span', ['class' => 'rs-text-result-date']);
     /* process result */
     foreach ($resultArray as $table => $result) {
         $outputItem = null;
         if ($result) {
             /* collect item output */
             foreach ($result as $value) {
                 if ($accessValidator->validate($result->access, $this->_registry->get('myGroups')) === Validator\ValidatorInterface::PASSED) {
                     $textDate = date(Db::getSetting('date'), strtotime($value->date));
                     $linkElement->attr('href', $this->_registry->get('parameterRoute') . build_route($table, $value->id))->text($value->title ? $value->title : $value->author);
                     $textElement->text($textDate);
                     $outputItem .= $itemElement->html($linkElement . $textElement);
                 }
             }
             /* collect output */
             if ($outputItem) {
                 $titleElement->text($this->_language->get($table));
                 $listElement->html($outputItem);
                 $output .= $titleElement . $listElement;
             }
         }
     }
     $output .= Hook::trigger('resultListEnd');
     return $output;
 }
Example #8
0
 /**
  * render
  *
  * @since 2.2.0
  *
  * @return string
  */
 public static function render()
 {
     /* fetch categories */
     $categories = Db::forTablePrefix('categories')->where('status', 1)->whereNull('access')->orderByAsc('rank')->findArray();
     /* fetch articles */
     $articles = Db::forTablePrefix('articles')->where('status', 1)->whereNull('access')->orderByAsc('rank')->findArray();
     /* collect output */
     $output = '<?xml version="1.0" encoding="' . Db::getSettings('charset') . '"?>';
     $output .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
     $output .= '<url><loc>' . Registry::get('root') . '</loc></url>';
     /* process categories */
     foreach ($categories as $value) {
         $route = $value['parent'] < 1 ? $value['alias'] : build_route('categories', $value['id']);
         $output .= '<url><loc>' . Registry::get('root') . '/' . Registry::get('rewriteRoute') . $route . '</loc></url>';
     }
     /* process articles */
     foreach ($articles as $value) {
         $route = $value['category'] < 1 ? $value['alias'] : build_route('articles', $value['id']);
         $output .= '<url><loc>' . Registry::get('root') . '/' . Registry::get('rewriteRoute') . $route . '</loc></url>';
     }
     $output .= '</urlset>';
     return $output;
 }
Example #9
0
/**
 * navigation list
 *
 * @since 1.2.1
 * @deprecated 2.0.0
 *
 * @package Redaxscript
 * @category Navigation
 * @author Henry Ruhs
 *
 * @param string $table
 * @param array $options
 */
function navigation_list($table, $options)
{
    $output = Redaxscript\Hook::trigger('navigationStart');
    /* define option variables */
    if (is_array($options)) {
        foreach ($options as $key => $value) {
            $key = 'option_' . $key;
            ${$key} = $value;
        }
    }
    /* fallback */
    if (!$option_order) {
        $option_order = Redaxscript\Db::getSetting('order');
    }
    if (!$option_limit) {
        $option_limit = Redaxscript\Db::getSetting('limit');
    }
    /* switch table */
    switch ($table) {
        case 'categories':
            $wording_single = 'category';
            $query_parent = 'parent';
            break;
        case 'articles':
            $wording_single = 'article';
            $query_parent = 'category';
            break;
        case 'comments':
            $wording_single = 'comment';
            $query_parent = 'article';
            break;
    }
    /* query contents */
    $contents = Redaxscript\Db::forTablePrefix($table)->where('status', 1)->whereLanguageIs(Redaxscript\Registry::get('language'));
    /* setup parent */
    if ($query_parent) {
        if ($option_parent) {
            $contents->where($query_parent, $option_parent);
        } else {
            if ($table == 'categories') {
                $contents->whereNull($query_parent);
            }
        }
    }
    /* setup query filter */
    if ($table == 'categories' || $table == 'articles') {
        /* setup filter alias option */
        if ($option_filter_alias) {
            $contents->whereIn('alias', $option_filter_alias);
        }
        /* setup filter rank option */
        if ($option_filter_rank) {
            $contents->whereIn('rank', $option_filter_rank);
        }
    }
    /* setup rank and limit */
    if ($option_order === 'asc') {
        $contents->orderByAsc('rank');
    } else {
        $contents->orderByDesc('rank');
    }
    $contents->limit($option_limit);
    /* query result */
    $result = $contents->findArray();
    $num_rows = count($result);
    if (!$result || !$num_rows) {
        $error = Redaxscript\Language::get($wording_single . '_no') . Redaxscript\Language::get('point');
    } else {
        if ($result) {
            $accessValidator = new Redaxscript\Validator\Access();
            foreach ($result as $r) {
                $access = $r['access'];
                /* access granted */
                if ($accessValidator->validate($access, Redaxscript\Registry::get('myGroups')) === Redaxscript\Validator\ValidatorInterface::PASSED) {
                    if ($r) {
                        foreach ($r as $key => $value) {
                            ${$key} = stripslashes($value);
                        }
                    }
                    /* build class string */
                    if (Redaxscript\Registry::get('lastParameter') == $alias && $table != 'comments') {
                        $class_string = ' class="rs-item-active"';
                    } else {
                        $class_string = null;
                    }
                    /* prepare metadata */
                    if ($table == 'comments') {
                        $description = $title = $author . Redaxscript\Language::get('colon') . ' ' . strip_tags($text);
                    }
                    if (!$description) {
                        $description = $title;
                    }
                    /* build route */
                    if ($table == 'categories' && $parent == 0 || $table == 'articles' && $category == 0) {
                        $route = $alias;
                    } else {
                        $route = build_route($table, $id);
                    }
                    /* collect item output */
                    $output .= '<li' . $class_string . '><a href="' . Redaxscript\Registry::get('parameterRoute') . $route . '">' . $title . '</a>';
                    /* collect children list output */
                    if ($table == 'categories' && $option_children == 1) {
                        ob_start();
                        navigation_list($table, ['parent' => $id, 'class' => 'rs-list-children']);
                        $output .= ob_get_clean();
                    }
                    $output .= '</li>';
                } else {
                    $counter++;
                }
            }
            /* handle access */
            if ($num_rows == $counter) {
                $error = Redaxscript\Language::get('access_no') . Redaxscript\Language::get('point');
            }
        }
    }
    /* build id string */
    if ($option_id) {
        $id_string = ' id="' . $option_id . '"';
    }
    /* build class string */
    if ($option_class) {
        $class_string = ' class="' . $option_class . '"';
    } else {
        $class_string = ' class="rs-list-' . $table . '"';
    }
    /* handle error */
    if ($error && !$option_parent) {
        $output = '<ul' . $id_string . $class_string . '><li><span>' . $error . '</span></li></ul>';
    } else {
        if ($output) {
            $output = '<ul' . $id_string . $class_string . '>' . $output . '</ul>';
        }
    }
    $output .= Redaxscript\Hook::trigger('navigationEnd');
    echo $output;
}
/**
 * search post
 *
 * @since 1.2.1
 * @deprecated 2.0.0
 *
 * @package Redaxscript
 * @category Search
 * @author Henry Ruhs
 */
function search_post()
{
    /* clean post */
    if (ATTACK_BLOCKED < 10) {
        $search_terms = clean($_POST['search_terms'], 5);
        $table = clean($_POST['table']);
    }
    /* validate post */
    if (strlen($search_terms) < 3 || $search_terms == l('search_terms')) {
        $error = l('input_incorrect');
    } else {
        /* fetch result */
        $result = Redaxscript\Db::forTablePrefix($table)->where('status', 1)->whereIn('language', array(Redaxscript\Registry::get('language'), ''))->whereLikeMany(array('title', 'description', 'keywords', 'text'), array('%' . $search_terms . '%', '%' . $search_terms . '%', '%' . $search_terms . '%', '%' . $search_terms . '%'))->orderByDesc('date')->findArray();
        /* process result */
        $num_rows = count($result);
        if (!$result) {
            $error = l('search_no');
        } else {
            if ($result) {
                $accessValidator = new Redaxscript\Validator\Access();
                $output = '<h2 class="title_content title_search_result">' . l('search') . '</h2>';
                $output .= form_element('fieldset', '', 'set_search_result', '', '', '') . '<ol class="list_search_result">';
                foreach ($result as $r) {
                    $access = $r['access'];
                    /* access granted */
                    if ($accessValidator->validate($access, MY_GROUPS) === Redaxscript\Validator\ValidatorInterface::PASSED) {
                        if ($r) {
                            foreach ($r as $key => $value) {
                                ${$key} = stripslashes($value);
                            }
                        }
                        /* prepare metadata */
                        if ($description == '') {
                            $description = $title;
                        }
                        $date = date(s('date'), strtotime($date));
                        /* build route */
                        if ($table == 'categories' && $parent == 0 || $table == 'articles' && $category == 0) {
                            $route = $alias;
                        } else {
                            $route = build_route($table, $id);
                        }
                        /* collect item output */
                        $output .= '<li class="item_search_result">' . anchor_element('internal', '', 'link_search_result', $title, $route, $description) . '<span class="date_search_result">' . $date . '</span></li>';
                    } else {
                        $counter++;
                    }
                }
                $output .= '</ol></fieldset>';
                /* handle access */
                if ($num_rows == $counter) {
                    $error = l('access_no');
                }
            }
        }
    }
    /* handle error */
    if ($error) {
        notification(l('something_wrong'), $error);
    } else {
        echo $output;
    }
}
Example #11
0
/**
 * feed generator
 *
 * @since 1.2.1
 * @deprecated 2.0.0
 *
 * @package Redaxscript
 * @category Modules
 * @author Henry Ruhs
 *
 * param string $table
 */
function feed_generator($table = '')
{
    if ($_GET['l']) {
        $language = LANGUAGE;
        $language_route = LANGUAGE_ROUTE;
    }
    /* query table contents */
    $query = 'SELECT * FROM ' . PREFIX . $table . ' WHERE (language = \'' . $language . '\' || language = \'all\') && status = 1 && access = 0 ORDER BY rank ' . s('order') . ' LIMIT ' . s('limit');
    $result = mysql_query($query);
    if ($result) {
        /* define variables */
        $title = s('title');
        $description = s('description');
        $author = s('author');
        $email = s('email');
        $copyright = s('copyright');
        $route = ROOT . '/' . REWRITE_ROUTE . FULL_ROUTE . $language_route . $language;
        /* collect feed header output */
        $output = '<?xml version="1.0" encoding="' . s('charset') . '"?>' . PHP_EOL;
        $output .= '<feed xmlns="http://www.w3.org/2005/Atom">' . PHP_EOL;
        $output .= '<id>' . $route . '</id>' . PHP_EOL;
        if ($title) {
            $output .= '<title type="text">' . $title . '</title>' . PHP_EOL;
        }
        if ($description) {
            $output .= '<subtitle type="text">' . $description . '</subtitle>' . PHP_EOL;
        }
        $output .= '<link type="application/atom+xml" href="' . $route . '" rel="self" />' . PHP_EOL;
        $output .= '<updated>' . date('c', strtotime(NOW)) . '</updated>' . PHP_EOL;
        if ($author || $email) {
            $output .= '<author>' . PHP_EOL;
            if ($author) {
                $output .= '<name>' . $author . '</name>' . PHP_EOL;
            }
            if ($email) {
                $output .= '<email>' . $email . '</email>' . PHP_EOL;
            }
            $output .= '</author>' . PHP_EOL;
        }
        if ($copyright) {
            $output .= '<rights>' . $copyright . '</rights>' . PHP_EOL;
        }
        $output .= '<generator>' . l('redaxscript') . ' ' . l('redaxscript_version') . '</generator>' . PHP_EOL . PHP_EOL;
        /* collect feed body output */
        while ($r = mysql_fetch_assoc($result)) {
            if ($r) {
                foreach ($r as $key => $value) {
                    ${$key} = stripslashes($value);
                }
            }
            /* define variables */
            $date = date('c', strtotime($date));
            $text = htmlspecialchars(strip_tags($text));
            if ($table == 'comments') {
                $title = $author;
            }
            /* build route */
            $route = ROOT . '/' . REWRITE_ROUTE;
            if ($table == 'articles' && $category == 0) {
                $route .= $alias;
            } else {
                $route .= build_route($table, $id);
            }
            $route .= $language_route;
            /* collect entry output */
            $output .= '<entry>' . PHP_EOL;
            $output .= '<id>' . $route . '</id>' . PHP_EOL;
            $output .= '<title type="text">' . $title . '</title>' . PHP_EOL;
            $output .= '<link href="' . $route . '" />' . PHP_EOL;
            $output .= '<updated>' . $date . '</updated>' . PHP_EOL;
            if ($description) {
                $output .= '<summary type="text">' . $description . '</summary>' . PHP_EOL;
            }
            $output .= '<content type="html">' . $text . '</content>' . PHP_EOL;
            $output .= '</entry>' . PHP_EOL;
        }
        $output .= '</feed>';
    }
    echo $output;
}
Example #12
0
/**
 * archive
 *
 * @since 1.2.1
 * @deprecated 2.0.0
 *
 * @package Redaxscript
 * @category Modules
 * @author Henry Ruhs
 *
 * @return string
 */
function archive()
{
    $query = 'SELECT id, title, alias, description, date, category, access FROM ' . PREFIX . 'articles WHERE (language = \'' . LANGUAGE . '\' || language = \'\') && status = 1 ORDER BY date DESC';
    $result = mysql_query($query);
    $num_rows = mysql_num_rows($result);
    if ($result == '' || $num_rows == '') {
        $error = l('article_no') . l('point');
    } else {
        if ($result) {
            $accessValidator = new Redaxscript\Validator\Access();
            $month_names = explode(', ', l('month_names'));
            $last = 0;
            while ($r = mysql_fetch_assoc($result)) {
                /* check for access */
                $access = $r['access'];
                $check_access = $accessValidator->validate($access, MY_GROUPS);
                /* if access granted */
                if ($check_access == 1) {
                    if ($r) {
                        foreach ($r as $key => $value) {
                            ${$key} = stripslashes($value);
                        }
                    }
                    if ($description == '') {
                        $description = $title;
                    }
                    $year = substr($date, 0, 4);
                    $month = substr($date, 5, 2) - 1;
                    /* build route */
                    if ($category == 0) {
                        $route = $alias;
                    } else {
                        $route = build_route('articles', $id);
                    }
                    /* collect output */
                    if ($last != $month + $year) {
                        if ($last > 0) {
                            $output .= '</ul></fieldset>';
                        }
                        $output .= form_element('fieldset', '', 'set_archive', '', '', '<span class="title_content_sub title_archive_sub">' . $month_names[$month] . ' ' . $year . '</span>') . '<ul class="list_default list_archive">';
                    }
                    $output .= '<li>' . anchor_element('internal', '', '', $title, $route, $description) . '</li>';
                    $last = $month + $year;
                } else {
                    $counter++;
                }
            }
            /* handle access */
            if ($num_rows == $counter) {
                $error = l('access_no') . l('point');
            }
        }
    }
    /* handle error */
    if ($error) {
        $output = form_element('fieldset', '', 'set_archive', '', '', '<span class="title_content_sub title_archive_sub">' . l('error') . '</span>') . '<ul class="list_default list_archive">';
        $output .= '<li>' . $error . '</li>';
    }
    $output .= '</ul></fieldset>';
    return $output;
}
Example #13
0
/**
 * comment post
 *
 * @since 1.2.1
 * @deprecated 2.0.0
 *
 * @package Redaxscript
 * @category Comments
 * @author Henry Ruhs
 */
function comment_post()
{
    $emailValidator = new Redaxscript\Validator\Email();
    $captchaValidator = new Redaxscript\Validator\Captcha();
    $urlValidator = new Redaxscript\Validator\Url();
    /* clean post */
    if (ATTACK_BLOCKED < 10 && $_SESSION[ROOT . '/comment'] == 'visited') {
        $author = $r['author'] = clean($_POST['author'], 0);
        $email = $r['email'] = clean($_POST['email'], 3);
        $url = $r['url'] = clean($_POST['url'], 4);
        $text = break_up($_POST['text']);
        $text = $r['text'] = clean($text, 1);
        $r['language'] = clean($_POST['language'], 0);
        $r['date'] = clean($_POST['date'], 1);
        $article = $r['article'] = clean($_POST['article'], 0);
        $r['rank'] = query_plumb('rank', 'comments', 'max') + 1;
        $r['access'] = clean($_POST['access'], 0);
        if ($r['access'] == '') {
            $r['access'] = 0;
        }
        $task = $_POST['task'];
        $solution = $_POST['solution'];
        $route = build_route('articles', $article);
    }
    /* validate post */
    if ($author == '') {
        $error = l('author_empty');
    } else {
        if ($email == '') {
            $error = l('email_empty');
        } else {
            if ($text == '') {
                $error = l('comment_empty');
            } else {
                if ($emailValidator->validate($email) == Redaxscript\Validator\Validator::FAILED) {
                    $error = l('email_incorrect');
                } else {
                    if ($url && $urlValidator->validate($url) == Redaxscript\Validator\Validator::FAILED) {
                        $error = l('url_incorrect');
                    } else {
                        if ($captchaValidator->validate($task, $solution) == Redaxscript\Validator\Validator::FAILED) {
                            $error = l('captcha_incorrect');
                        } else {
                            if (COMMENTS_NEW == 0 && s('moderation') == 1) {
                                $r['status'] = 0;
                                $success = l('comment_moderation');
                            } else {
                                $r['status'] = 1;
                                $success = l('comment_sent');
                            }
                            /* send comment notification */
                            if (s('notification') == 1) {
                                /* prepare body parts */
                                $emailLink = anchor_element('email', '', '', $email);
                                if ($url) {
                                    $urlLink = anchor_element('external', '', '', $url);
                                }
                                $articleRoute = ROOT . '/' . REWRITE_ROUTE . $route;
                                $articleLink = anchor_element('external', '', '', $articleRoute, $articleRoute);
                                /* prepare mail inputs */
                                $toArray = array(s('author') => s('email'));
                                $fromArray = array($author => $email);
                                $subject = l('comment_new');
                                $bodyArray = array('<strong>' . l('author') . l('colon') . '</strong> ' . $author . ' (' . MY_IP . ')', '<strong>' . l('email') . l('colon') . '</strong> ' . $emailLink, '<strong>' . l('url') . l('colon') . '</strong> ' . $urlLink, '<br />', '<strong>' . l('comment') . l('colon') . '</strong> ' . $text, '<br />', '<strong>' . l('article') . l('colon') . '</strong> ' . $articleLink);
                                /* mailer object */
                                $mailer = new Redaxscript\Mailer($toArray, $fromArray, $subject, $bodyArray);
                                $mailer->send();
                            }
                            /* build key and value strings */
                            $r_keys = array_keys($r);
                            $last = end($r_keys);
                            foreach ($r as $key => $value) {
                                $key_string .= $key;
                                $value_string .= '\'' . $value . '\'';
                                if ($last != $key) {
                                    $key_string .= ', ';
                                    $value_string .= ', ';
                                }
                            }
                            /* insert comment */
                            $query = 'INSERT INTO ' . PREFIX . 'comments (' . $key_string . ') VALUES (' . $value_string . ')';
                            mysql_query($query);
                        }
                    }
                }
            }
        }
    }
    /* handle error */
    if ($error) {
        if (s('blocker') == 1) {
            $_SESSION[ROOT . '/attack_blocked']++;
        }
        notification(l('error_occurred'), $error, l('back'), $route);
    } else {
        notification(l('operation_completed'), $success, l('continue'), $route);
    }
    $_SESSION[ROOT . '/comment'] = '';
}
Example #14
0
/**
 * navigation list
 *
 * @since 1.2.1
 * @deprecated 2.0.0
 *
 * @package Redaxscript
 * @category Navigation
 * @author Henry Ruhs
 *
 * @param string $table
 * @param array $options
 */
function navigation_list($table = '', $options = '')
{
    $output = Redaxscript\Hook::trigger(__FUNCTION__ . '_start');
    /* define option variables */
    if (is_array($options)) {
        foreach ($options as $key => $value) {
            $key = 'option_' . $key;
            ${$key} = $value;
        }
    }
    /* fallback */
    if ($option_order == '') {
        $option_order = s('order');
    }
    if ($option_limit == '') {
        $option_limit = s('limit');
    }
    /* switch table */
    switch ($table) {
        case 'categories':
            $wording_single = 'category';
            $query_parent = 'parent';
            break;
        case 'articles':
            $wording_single = 'article';
            $query_parent = 'category';
            break;
        case 'comments':
            $wording_single = 'comment';
            $query_parent = 'article';
            break;
    }
    /* query contents */
    $contents = Redaxscript\Db::forTablePrefix($table)->where('status', 1)->whereIn('language', array(Redaxscript\Registry::get('language'), ''));
    /* setup parent */
    if ($query_parent) {
        if ($option_parent) {
            $contents->where($query_parent, $option_parent);
        } else {
            if ($table == 'categories') {
                $contents->where($query_parent, 0);
            }
        }
    }
    /* setup query filter */
    if ($table == 'categories' || $table == 'articles') {
        /* setup filter alias option */
        if ($option_filter_alias) {
            $contents->whereIn('alias', $option_filter_alias);
        }
        /* setup filter rank option */
        if ($option_filter_rank) {
            $contents->whereIn('rank', $option_filter_rank);
        }
    }
    /* setup rank and limit */
    if ($option_order === 'asc') {
        $contents->orderByAsc('rank');
    } else {
        $contents->orderByDesc('rank');
    }
    $contents->limit($option_limit);
    /* query result */
    $result = $contents->findArray();
    $num_rows = count($result);
    if ($result == '' || $num_rows == '') {
        $error = l($wording_single . '_no') . l('point');
    } else {
        if ($result) {
            $accessValidator = new Redaxscript\Validator\Access();
            foreach ($result as $r) {
                $access = $r['access'];
                /* if access granted */
                if ($accessValidator->validate($access, MY_GROUPS) === Redaxscript\Validator\ValidatorInterface::PASSED) {
                    if ($r) {
                        foreach ($r as $key => $value) {
                            ${$key} = stripslashes($value);
                        }
                    }
                    /* build class string */
                    if (LAST_PARAMETER == $alias && $table != 'comments') {
                        $class_string = ' class="item_active"';
                    } else {
                        $class_string = '';
                    }
                    /* prepare metadata */
                    if ($table == 'comments') {
                        $description = $title = truncate($author . l('colon') . ' ' . strip_tags($text), 80, '...');
                    }
                    if ($description == '') {
                        $description = $title;
                    }
                    /* build route */
                    if ($table == 'categories' && $parent == 0 || $table == 'articles' && $category == 0) {
                        $route = $alias;
                    } else {
                        $route = build_route($table, $id);
                    }
                    /* collect item output */
                    $output .= '<li' . $class_string . '>' . anchor_element('internal', '', '', $title, $route, $description);
                    /* collect children list output */
                    if ($table == 'categories' && $option_children == 1) {
                        ob_start();
                        navigation_list($table, array('parent' => $id, 'class' => 'list_children'));
                        $output .= ob_get_clean();
                    }
                    $output .= '</li>';
                } else {
                    $counter++;
                }
            }
            /* handle access */
            if ($num_rows == $counter) {
                $error = l('access_no') . l('point');
            }
        }
    }
    /* build id string */
    if ($option_id) {
        $id_string = ' id="' . $option_id . '"';
    }
    /* build class string */
    if ($option_class) {
        $class_string = ' class="' . $option_class . '"';
    } else {
        $class_string = ' class="list_' . $table . '"';
    }
    /* handle error */
    if ($error && $option_parent == '') {
        $output = '<ul' . $id_string . $class_string . '><li>' . $error . '</li></ul>';
    } else {
        if ($output) {
            $output = '<ul' . $id_string . $class_string . '>' . $output . '</ul>';
        }
    }
    $output .= Redaxscript\Hook::trigger(__FUNCTION__ . '_end');
    echo $output;
}
Example #15
0
/**
 * contents
 *
 * @since 1.2.1
 * @deprecated 2.0.0
 *
 * @package Redaxscript
 * @category Contents
 * @author Henry Ruhs
 */
function contents()
{
    $output = Redaxscript\Hook::trigger(__FUNCTION__ . '_start');
    $aliasValidator = new Redaxscript\Validator\Alias();
    /* query contents */
    $query = 'SELECT id, title, author, text, language, date, headline, infoline, comments, access FROM ' . PREFIX . 'articles WHERE status = 1';
    if (ARTICLE) {
        $query .= ' && id = ' . ARTICLE;
    } else {
        if (CATEGORY) {
            $query .= ' && (language = \'' . LANGUAGE . '\' || language = \'\') && category = ' . CATEGORY . ' ORDER BY rank ' . s('order');
            $result = mysql_query($query);
            if ($result) {
                $num_rows = mysql_num_rows($result);
                $sub_maximum = ceil($num_rows / s('limit'));
                $sub_active = LAST_SUB_PARAMETER;
                /* if sub parameter */
                if (LAST_SUB_PARAMETER > $sub_maximum || LAST_SUB_PARAMETER == '') {
                    $sub_active = 1;
                } else {
                    $offset_string = ($sub_active - 1) * s('limit') . ', ';
                }
            }
            $query .= ' LIMIT ' . $offset_string . s('limit');
        } else {
            $query .= ' LIMIT 0';
        }
    }
    $result = mysql_query($query);
    $num_rows_active = mysql_num_rows($result);
    /* handle error */
    if (DB_CONNECTED == 0) {
        $error = l('database_failed');
    } else {
        if (CATEGORY && $num_rows == '') {
            $error = l('article_no');
        } else {
            if ($result == '' || $num_rows_active == '' || CONTENT_ERROR) {
                $error = l('content_not_found');
            } else {
                if ($result) {
                    $accessValidator = new Redaxscript\Validator\Access();
                    while ($r = mysql_fetch_assoc($result)) {
                        $access = $r['access'];
                        $check_access = $accessValidator->validate($access, MY_GROUPS);
                        /* if access granted */
                        if ($check_access == 1) {
                            if ($r) {
                                foreach ($r as $key => $value) {
                                    ${$key} = stripslashes($value);
                                }
                            }
                            if (LAST_TABLE == 'categories' || FULL_ROUTE == '' || $aliasValidator->validate(FIRST_PARAMETER, Redaxscript\Validator\Alias::MODE_DEFAULT) == Redaxscript\Validator\Validator::PASSED) {
                                $route = build_route('articles', $id);
                            }
                            /* parser object */
                            $parser = new Redaxscript\Parser(Redaxscript\Registry::getInstance(), Redaxscript\Language::getInstance(), $text, $route, array('className' => array('break' => 'link_read_more', 'code' => 'box_code')));
                            /* collect headline output */
                            $output .= Redaxscript\Hook::trigger('article_start', $id);
                            if ($headline == 1) {
                                $output .= '<h2 class="title_content">';
                                if (LAST_TABLE == 'categories' || FULL_ROUTE == '' || $aliasValidator->validate(FIRST_PARAMETER, Redaxscript\Validator\Alias::MODE_DEFAULT) == Redaxscript\Validator\Validator::PASSED) {
                                    $output .= anchor_element('internal', '', '', $title, $route);
                                } else {
                                    $output .= $title;
                                }
                                $output .= '</h2>';
                            }
                            /* collect box output */
                            $output .= '<div class="box_content">' . $parser->getOutput();
                            $output .= '</div>' . Redaxscript\Hook::trigger('article_end', $id);
                            /* prepend admin dock */
                            if (LOGGED_IN == TOKEN && FIRST_PARAMETER != 'logout') {
                                $output .= admin_dock('articles', $id);
                            }
                            /* infoline */
                            if ($infoline == 1) {
                                $output .= infoline('articles', $id, $author, $date);
                            }
                        } else {
                            $counter++;
                        }
                    }
                    /* handle access */
                    if (LAST_TABLE == 'categories') {
                        if ($num_rows_active == $counter) {
                            $error = l('access_no');
                        }
                    } else {
                        if (LAST_TABLE == 'articles' && $counter == 1) {
                            $error = l('access_no');
                        }
                    }
                }
            }
        }
    }
    /* handle error */
    if ($error) {
        notification(l('something_wrong'), $error);
    } else {
        $output .= Redaxscript\Hook::trigger(__FUNCTION__ . '_end');
        echo $output;
        /* call comments as needed */
        if (ARTICLE) {
            /* comments replace */
            if ($comments == 1 && COMMENTS_REPLACE == 1) {
                Redaxscript\Hook::trigger('comments_replace');
            } else {
                if ($comments > 0) {
                    $route = build_route('articles', ARTICLE);
                    comments(ARTICLE, $route);
                    /* comment form */
                    if ($comments == 1 || COMMENTS_NEW == 1 && $comments == 3) {
                        comment_form(ARTICLE, $language, $access);
                    }
                }
            }
        }
    }
    /* call pagination as needed */
    if ($sub_maximum > 1 && s('pagination') == 1) {
        $route = build_route('categories', CATEGORY);
        pagination($sub_active, $sub_maximum, $route);
    }
}
/**
 * comment post
 *
 * @since 1.2.1
 * @deprecated 2.0.0
 *
 * @package Redaxscript
 * @category Comments
 * @author Henry Ruhs
 */
function comment_post()
{
    $emailValidator = new Redaxscript\Validator\Email();
    $captchaValidator = new Redaxscript\Validator\Captcha();
    $urlValidator = new Redaxscript\Validator\Url();
    /* clean post */
    if (ATTACK_BLOCKED < 10 && $_SESSION[ROOT . '/comment'] == 'visited') {
        $author = $r['author'] = clean($_POST['author'], 0);
        $email = $r['email'] = clean($_POST['email'], 3);
        $url = $r['url'] = clean($_POST['url'], 4);
        $text = break_up($_POST['text']);
        $text = $r['text'] = clean($text, 1);
        $r['language'] = clean($_POST['language'], 0);
        $r['date'] = clean($_POST['date'], 5);
        $article = $r['article'] = clean($_POST['article'], 0);
        $r['rank'] = Redaxscript\Db::forTablePrefix('comments')->max('rank') + 1;
        $r['access'] = Redaxscript\Db::forTablePrefix('articles')->whereIdIs($article)->access;
        if ($r['access'] == '') {
            $r['access'] = null;
        }
        $task = $_POST['task'];
        $solution = $_POST['solution'];
        $route = build_route('articles', $article);
    }
    /* validate post */
    if ($author == '') {
        $error = l('author_empty');
    } else {
        if ($email == '') {
            $error = l('email_empty');
        } else {
            if ($text == '') {
                $error = l('comment_empty');
            } else {
                if ($emailValidator->validate($email) == Redaxscript\Validator\ValidatorInterface::FAILED) {
                    $error = l('email_incorrect');
                } else {
                    if ($url && $urlValidator->validate($url) == Redaxscript\Validator\ValidatorInterface::FAILED) {
                        $error = l('url_incorrect');
                    } else {
                        if ($captchaValidator->validate($task, $solution) == Redaxscript\Validator\ValidatorInterface::FAILED) {
                            $error = l('captcha_incorrect');
                        } else {
                            if (COMMENTS_NEW == 0 && s('moderation') == 1) {
                                $r['status'] = 0;
                                $success = l('comment_moderation');
                            } else {
                                $r['status'] = 1;
                                $success = l('comment_sent');
                            }
                            /* send comment notification */
                            if (s('notification') == 1) {
                                /* prepare body parts */
                                $emailLink = anchor_element('email', '', '', $email);
                                if ($url) {
                                    $urlLink = anchor_element('external', '', '', $url);
                                }
                                $articleRoute = ROOT . '/' . REWRITE_ROUTE . $route;
                                $articleLink = anchor_element('external', '', '', $articleRoute, $articleRoute);
                                /* prepare mail inputs */
                                $toArray = array(s('author') => s('email'));
                                $fromArray = array($author => $email);
                                $subject = l('comment_new');
                                $bodyArray = array('<strong>' . l('author') . l('colon') . '</strong> ' . $author, '<br />', '<strong>' . l('email') . l('colon') . '</strong> ' . $emailLink, '<br />', '<strong>' . l('url') . l('colon') . '</strong> ' . $urlLink, '<br />', '<strong>' . l('article') . l('colon') . '</strong> ' . $articleLink, '<br />', '<br />', '<strong>' . l('comment') . l('colon') . '</strong> ' . $text);
                                /* mailer object */
                                $mailer = new Redaxscript\Mailer();
                                $mailer->init($toArray, $fromArray, $subject, $bodyArray);
                                $mailer->send();
                            }
                            /* create comment */
                            Redaxscript\Db::forTablePrefix('comments')->create()->set($r)->save();
                        }
                    }
                }
            }
        }
    }
    /* handle error */
    if ($error) {
        if (s('blocker') == 1) {
            $_SESSION[ROOT . '/attack_blocked']++;
        }
        notification(l('error_occurred'), $error, l('back'), $route);
    } else {
        notification(l('operation_completed'), $success, l('continue'), $route);
    }
    $_SESSION[ROOT . '/comment'] = '';
}
Example #17
0
/**
 * admin contents list
 *
 * @since 1.2.1
 * @deprecated 2.0.0
 *
 * @package Redaxscript
 * @category Admin
 * @author Henry Ruhs
 */
function admin_contents_list()
{
    $output = Redaxscript\Hook::trigger('adminContentListStart');
    /* define access variables */
    $tableParameter = Redaxscript\Registry::get('tableParameter');
    $table_new = Redaxscript\Registry::get('tableNew');
    if ($tableParameter == 'comments') {
        $articles_total = Redaxscript\Db::forTablePrefix('articles')->count();
        $articles_comments_disable = Redaxscript\Db::forTablePrefix('articles')->where('comments', 0)->count();
        if ($articles_total == $articles_comments_disable) {
            $table_new = 0;
        }
    }
    /* switch table */
    switch ($tableParameter) {
        case 'categories':
            $wording_single = 'category';
            $wording_parent = 'category_parent';
            break;
        case 'articles':
            $wording_single = 'article';
            $wording_parent = 'category';
            break;
        case 'extras':
            $wording_single = 'extra';
            break;
        case 'comments':
            $wording_single = 'comment';
            $wording_parent = 'article';
            break;
    }
    /* query contents */
    $result = Redaxscript\Db::forTablePrefix($tableParameter)->orderByAsc('rank')->findArray();
    $num_rows = count($result);
    /* collect listing output */
    $output .= '<h2 class="rs-admin-title-content">' . Redaxscript\Language::get($tableParameter) . '</h2>';
    $output .= '<div class="rs-admin-wrapper-button">';
    if ($table_new == 1) {
        $output .= '<a href="' . Redaxscript\Registry::get('parameterRoute') . 'admin/new/' . Redaxscript\Registry::get('tableParameter') . '" class="rs-admin-button-default rs-admin-button-create">' . Redaxscript\Language::get($wording_single . '_new') . '</a>';
    }
    if (Redaxscript\Registry::get('tableEdit') == 1 && $num_rows) {
        $output .= '<a href="' . Redaxscript\Registry::get('parameterRoute') . 'admin/sort/' . Redaxscript\Registry::get('tableParameter') . '/' . Redaxscript\Registry::get('token') . '" class="rs-admin-button-default">' . Redaxscript\Language::get('sort') . '</a>';
    }
    $output .= '</div><div class="rs-admin-wrapper-table"><table class="rs-admin-table-default rs-admin-table-' . $wording_single . '">';
    /* collect thead */
    $output .= '<thead><tr><th class="rs-admin-col-title">' . Redaxscript\Language::get('title') . '</th><th class="rs-admin-col-alias">';
    if ($tableParameter == 'comments') {
        $output .= Redaxscript\Language::get('identifier');
    } else {
        $output .= Redaxscript\Language::get('alias');
    }
    $output .= '</th>';
    if ($tableParameter != 'extras') {
        $output .= '<th class="rs-admin-col-parent">' . Redaxscript\Language::get($wording_parent) . '</th>';
    }
    $output .= '<th class="rs-admin-col-rank">' . Redaxscript\Language::get('rank') . '</th></tr></thead>';
    /* collect tfoot */
    $output .= '<tfoot><tr><td>' . Redaxscript\Language::get('title') . '</td><td>';
    if ($tableParameter == 'comments') {
        $output .= Redaxscript\Language::get('identifier');
    } else {
        $output .= Redaxscript\Language::get('alias');
    }
    $output .= '</td>';
    if ($tableParameter != 'extras') {
        $output .= '<td>' . Redaxscript\Language::get($wording_parent) . '</td>';
    }
    $output .= '<td class="rs-admin-col-rank">' . Redaxscript\Language::get('rank') . '</td></tr></tfoot>';
    if (!$result || !$num_rows) {
        $error = Redaxscript\Language::get($wording_single . '_no') . Redaxscript\Language::get('point');
    } else {
        if ($result) {
            $accessValidator = new Redaxscript\Validator\Access();
            foreach ($result as $r) {
                $access = $r['access'];
                /* access granted */
                if ($accessValidator->validate($access, Redaxscript\Registry::get('myGroups')) === Redaxscript\Validator\ValidatorInterface::PASSED) {
                    if ($r) {
                        foreach ($r as $key => $value) {
                            ${$key} = stripslashes($value);
                        }
                    }
                    /* prepare name */
                    if ($tableParameter == 'comments') {
                        $name = $author . Redaxscript\Language::get('colon') . ' ' . strip_tags($text);
                    } else {
                        $name = $title;
                    }
                    /* build class string */
                    if ($status == 1) {
                        $class_status = null;
                    } else {
                        $class_status = 'rs-admin-is-disabled';
                    }
                    /* build route */
                    if ($tableParameter != 'extras' && $status == 1) {
                        if ($tableParameter == 'categories' && $parent == 0 || $tableParameter == 'articles' && $category == 0) {
                            $route = $alias;
                        } else {
                            $route = build_route($tableParameter, $id);
                        }
                    } else {
                        $route = null;
                    }
                    /* collect tbody output */
                    if ($tableParameter == 'categories') {
                        if ($before != $parent) {
                            $output .= '<tbody><tr class="rs-admin-row-group"><td colspan="4">';
                            if ($parent) {
                                $output .= Redaxscript\Db::forTablePrefix('categories')->where('id', $parent)->findOne()->title;
                            } else {
                                $output .= Redaxscript\Language::get('none');
                            }
                            $output .= '</td></tr>';
                        }
                        $before = $parent;
                    }
                    if ($tableParameter == 'articles') {
                        if ($before != $category) {
                            $output .= '<tbody><tr class="rs-admin-row-group"><td colspan="4">';
                            if ($category) {
                                $output .= Redaxscript\Db::forTablePrefix('categories')->where('id', $category)->findOne()->title;
                            } else {
                                $output .= Redaxscript\Language::get('uncategorized');
                            }
                            $output .= '</td></tr>';
                        }
                        $before = $category;
                    }
                    if ($tableParameter == 'comments') {
                        if ($before != $article) {
                            $output .= '<tbody><tr class="rs-admin-row-group"><td colspan="4">';
                            if ($article) {
                                $output .= Redaxscript\Db::forTablePrefix('articles')->where('id', $article)->findOne()->title;
                            } else {
                                $output .= Redaxscript\Language::get('none');
                            }
                            $output .= '</td></tr>';
                        }
                        $before = $article;
                    }
                    /* collect table row */
                    $output .= '<tr';
                    if ($alias) {
                        $output .= ' id="' . $alias . '"';
                    }
                    if ($class_status) {
                        $output .= ' class="' . $class_status . '"';
                    }
                    $output .= '><td>';
                    if ($status == 1) {
                        $output .= '<a href="' . Redaxscript\Registry::get('parameterRoute') . $route . '" class="rs-admin-link-view';
                        if ($language) {
                            $output .= ' rs-admin-has-language" data-language="' . $language;
                        }
                        $output .= '">' . $name . '</a>';
                    } else {
                        $output .= $name;
                    }
                    /* collect control output */
                    $output .= admin_control('contents', $tableParameter, $id, $alias, $status, Redaxscript\Registry::get('tableNew'), Redaxscript\Registry::get('tableEdit'), Redaxscript\Registry::get('tableDelete'));
                    /* collect alias and id output */
                    $output .= '</td><td>';
                    if ($tableParameter == 'comments') {
                        $output .= $id;
                    } else {
                        $output .= $alias;
                    }
                    $output .= '</td>';
                    /* collect parent output */
                    if ($tableParameter != 'extras') {
                        $output .= '<td>';
                        if ($tableParameter == 'categories') {
                            if ($parent) {
                                $parent_title = Redaxscript\Db::forTablePrefix('categories')->where('id', $parent)->findOne()->title;
                                $output .= '<a href="' . Redaxscript\Registry::get('parameterRoute') . 'admin/edit/categories/' . $parent . '" class="rs-admin-link-parent">' . $parent_title . '</a>';
                            } else {
                                $output .= Redaxscript\Language::get('none');
                            }
                        }
                        if ($tableParameter == 'articles') {
                            if ($category) {
                                $category_title = Redaxscript\Db::forTablePrefix('categories')->where('id', $category)->findOne()->title;
                                $output .= '<a href="' . Redaxscript\Registry::get('parameterRoute') . 'admin/edit/categories/' . $category . '" class="rs-admin-link-parent">' . $category_title . '</a>';
                            } else {
                                $output .= Redaxscript\Language::get('uncategorized');
                            }
                        }
                        if ($tableParameter == 'comments') {
                            if ($article) {
                                $article_title = Redaxscript\Db::forTablePrefix('articles')->where('id', $article)->findOne()->title;
                                $output .= '<a href="' . Redaxscript\Registry::get('parameterRoute') . 'admin/edit/articles/' . $article . '" class="rs-admin-link-parent">' . $article_title . '</a>';
                            } else {
                                $output .= Redaxscript\Language::get('none');
                            }
                        }
                        $output .= '</td>';
                    }
                    $output .= '<td class="rs-admin-col-rank">';
                    /* collect control output */
                    if (Redaxscript\Registry::get('tableEdit') == 1) {
                        $rank_desc = Redaxscript\Db::forTablePrefix($tableParameter)->max('rank');
                        if ($rank > 1) {
                            $output .= '<a href="' . Redaxscript\Registry::get('parameterRoute') . 'admin/up/' . Redaxscript\Registry::get('tableParameter') . '/' . $id . '/' . Redaxscript\Registry::get('token') . '" class="rs-admin-button-moveup">' . Redaxscript\Language::get('up') . '</a>';
                        } else {
                            $output .= '<a class="rs-admin-button-moveup rs-admin-is-disabled">' . Redaxscript\Language::get('up') . '</a>';
                        }
                        if ($rank < $rank_desc) {
                            $output .= '<a href="' . Redaxscript\Registry::get('parameterRoute') . 'admin/down/' . Redaxscript\Registry::get('tableParameter') . '/' . $id . '/' . Redaxscript\Registry::get('token') . '" class="rs-admin-button-movedown">' . Redaxscript\Language::get('down') . '</a>';
                        } else {
                            $output .= '<a class="rs-admin-button-movedown rs-admin-is-disabled">' . Redaxscript\Language::get('down') . '</a>';
                        }
                        $output .= '</td>';
                    }
                    $output .= '</tr>';
                    /* collect tbody output */
                    if ($tableParameter == 'categories') {
                        if ($before != $parent) {
                            $output .= '</tbody>';
                        }
                    }
                    if ($tableParameter == 'articles') {
                        if ($before != $category) {
                            $output .= '</tbody>';
                        }
                    }
                    if ($tableParameter == 'comments') {
                        if ($before != $article) {
                            $output .= '</tbody>';
                        }
                    }
                } else {
                    $counter++;
                }
            }
            /* handle access */
            if ($num_rows == $counter) {
                $error = Redaxscript\Language::get('access_no') . Redaxscript\Language::get('point');
            }
        }
    }
    /* handle error */
    if ($error) {
        $output .= '<tbody><tr><td colspan="4">' . $error . '</td></tr></tbody>';
    }
    $output .= '</table></div>';
    $output .= Redaxscript\Hook::trigger('adminContentListEnd');
    echo $output;
}
/**
 * contents
 *
 * @since 1.2.1
 * @deprecated 2.0.0
 *
 * @package Redaxscript
 * @category Contents
 * @author Henry Ruhs
 */
function contents()
{
    $output = Redaxscript\Hook::trigger(__FUNCTION__ . '_start');
    $aliasValidator = new Redaxscript\Validator\Alias();
    /* query articles */
    $articles = Redaxscript\Db::forTablePrefix('articles')->where('status', 1);
    $articles->whereIn('language', array(Redaxscript\Registry::get('language'), ''));
    /* handle sibling */
    if (LAST_ID) {
        $sibling = Redaxscript\Db::forTablePrefix(LAST_TABLE)->where('id', LAST_ID)->findOne()->sibling;
        /* query sibling collection */
        $sibling_array = Redaxscript\Db::forTablePrefix(LAST_TABLE)->whereIn('sibling', array(LAST_ID, $sibling > 0 ? $sibling : null))->where('language', Redaxscript\Registry::get('language'))->select('id')->findArrayFlat();
        /* process sibling array */
        foreach ($sibling_array as $value) {
            $id_array[] = $value;
        }
    }
    /* handle article */
    if (ARTICLE) {
        $id_array[] = $sibling;
        $id_array[] = ARTICLE;
        $articles->whereIn('id', $id_array);
    } else {
        if (CATEGORY) {
            if (!$id_array) {
                if ($sibling > 0) {
                    $id_array[] = $sibling;
                } else {
                    $id_array[] = CATEGORY;
                }
            }
            $articles->whereIn('category', $id_array)->orderGlobal('rank');
            /* handle sub parameter */
            $result = $articles->findArray();
            if ($result) {
                $num_rows = count($result);
                $sub_maximum = ceil($num_rows / s('limit'));
                $sub_active = LAST_SUB_PARAMETER;
                /* sub parameter */
                if (LAST_SUB_PARAMETER > $sub_maximum || LAST_SUB_PARAMETER == '') {
                    $sub_active = 1;
                } else {
                    $offset_string = ($sub_active - 1) * s('limit') . ', ';
                }
            }
            $articles->limit($offset_string . s('limit'));
        } else {
            $articles->limit(0);
        }
    }
    /* query result */
    $result = $articles->findArray();
    $num_rows_active = count($result);
    /* handle error */
    if (CATEGORY && $num_rows == '') {
        $error = l('article_no');
    } else {
        if ($result == '' || $num_rows_active == '' || CONTENT_ERROR) {
            $error = l('content_not_found');
        } else {
            if ($result) {
                $accessValidator = new Redaxscript\Validator\Access();
                foreach ($result as $r) {
                    $access = $r['access'];
                    /* access granted */
                    if ($accessValidator->validate($access, MY_GROUPS) === Redaxscript\Validator\ValidatorInterface::PASSED) {
                        if ($r) {
                            foreach ($r as $key => $value) {
                                ${$key} = stripslashes($value);
                            }
                        }
                        if (LAST_TABLE == 'categories' || FULL_ROUTE == '' || $aliasValidator->validate(FIRST_PARAMETER, Redaxscript\Validator\Alias::MODE_DEFAULT) == Redaxscript\Validator\ValidatorInterface::PASSED) {
                            $route = build_route('articles', $id);
                        }
                        /* parser object */
                        $parser = new Redaxscript\Parser(Redaxscript\Registry::getInstance(), Redaxscript\Language::getInstance());
                        $parser->init($text, array('className' => array('readmore' => 'link_read_more', 'codequote' => 'js_code_quote box_code'), 'route' => $route));
                        /* collect headline output */
                        $output .= Redaxscript\Hook::trigger('article_start', $r);
                        if ($headline == 1) {
                            $output .= '<h2 class="title_content" id="article-' . $alias . '">';
                            if (LAST_TABLE == 'categories' || FULL_ROUTE == '' || $aliasValidator->validate(FIRST_PARAMETER, Redaxscript\Validator\Alias::MODE_DEFAULT) == Redaxscript\Validator\ValidatorInterface::PASSED) {
                                $output .= anchor_element('internal', '', '', $title, $route);
                            } else {
                                $output .= $title;
                            }
                            $output .= '</h2>';
                        }
                        /* collect box output */
                        $output .= '<div class="box_content">' . $parser->getOutput();
                        $output .= '</div>' . Redaxscript\Hook::trigger('article_end', $r);
                        /* prepend admin dock */
                        if (LOGGED_IN == TOKEN && FIRST_PARAMETER != 'logout') {
                            $output .= admin_dock('articles', $id);
                        }
                        /* infoline */
                        if ($infoline == 1) {
                            $output .= infoline('articles', $id, $author, $date);
                        }
                    } else {
                        $counter++;
                    }
                }
                /* handle access */
                if (LAST_TABLE == 'categories') {
                    if ($num_rows_active == $counter) {
                        $error = l('access_no');
                    }
                } else {
                    if (LAST_TABLE == 'articles' && $counter == 1) {
                        $error = l('access_no');
                    }
                }
            }
        }
    }
    /* handle error */
    if ($error) {
        notification(l('something_wrong'), $error);
    } else {
        $output .= Redaxscript\Hook::trigger(__FUNCTION__ . '_end');
        echo $output;
        /* call comments as needed */
        if (ARTICLE) {
            /* comments replace */
            if ($comments == 1 && (COMMENTS_REPLACE == 1 || Redaxscript\Registry::get('commentsReplace'))) {
                Redaxscript\Hook::trigger('comments_replace');
            } else {
                if ($comments > 0) {
                    $route = build_route('articles', ARTICLE);
                    comments(ARTICLE, $route);
                    /* comment form */
                    if ($comments == 1 || COMMENTS_NEW == 1 && $comments == 3) {
                        comment_form(ARTICLE, $language);
                    }
                }
            }
        }
    }
    /* call pagination as needed */
    if ($sub_maximum > 1 && s('pagination') == 1) {
        $route = build_route('categories', CATEGORY);
        pagination($sub_active, $sub_maximum, $route);
    }
}
 /**
  * render
  *
  * @since 2.3.0
  *
  * @param string $table
  *
  * @return string
  */
 public static function render($table = 'articles')
 {
     $output = '';
     /* fetch result */
     $result = Db::forTablePrefix($table)->where('status', 1)->where('access', 0)->where('language', Request::getQuery('l') ? Registry::get('language') : '')->orderGlobal('rank')->limitGlobal()->findArray();
     /* process result */
     if ($result) {
         $route = Registry::get('root') . '/' . Registry::get('rewriteRoute') . Registry::get('fullRoute');
         if (Request::getQuery('l')) {
             $route .= Registry::get('languageRoute') . Registry::get('language');
         }
         $title = Db::getSettings('title');
         $description = Db::getSettings('description');
         $author = Db::getSettings('author');
         $copyright = Db::getSettings('copyright');
         /* collect output */
         $output = '<?xml version="1.0" encoding="' . Db::getSettings('charset') . '"?>';
         $output .= '<feed xmlns="http://www.w3.org/2005/Atom">';
         $output .= '<id>' . $route . '</id>';
         $output .= '<link type="application/atom+xml" href="' . $route . '" rel="self" />';
         $output .= '<updated>' . date('c', strtotime(Registry::get('now'))) . '</updated>';
         /* title */
         if ($title) {
             $output .= '<title>' . $title . '</title>';
         }
         /* description */
         if ($description) {
             $output .= '<subtitle>' . $description . '</subtitle>';
         }
         /* author */
         if ($author) {
             $output .= '<author><name>' . $author . '</name></author>';
         }
         /* copyright */
         if ($copyright) {
             $output .= '<rights>' . $copyright . '</rights>';
         }
         /* generator */
         $output .= '<generator>' . Language::get('name', '_package') . ' ' . Language::get('version', '_package') . '</generator>';
         /* collect body output */
         foreach ($result as $value) {
             $route = Registry::get('root') . '/' . Registry::get('rewriteRoute');
             $route .= $value['category'] < 1 ? $value['alias'] : build_route($table, $value['id']);
             /* collect entry output */
             $output .= '<entry>';
             $output .= '<id>' . $route . '</id>';
             $output .= '<link href="' . $route . '" />';
             $output .= '<updated>' . date('c', strtotime($value['date'])) . '</updated>';
             /* title */
             $output .= '<title>' . ($table === 'comments' ? $value['author'] : $value['title']) . '</title>';
             /* description */
             if ($value['description']) {
                 $output .= '<summary>' . $value['description'] . '</summary>';
             }
             /* text */
             $output .= '<content>' . strip_tags($value['text']) . '</content>';
             /* author */
             if ($value['author']) {
                 $output .= '<author><name>' . $value['author'] . '</name></author>';
             }
             $output .= '</entry>';
         }
         $output .= '</feed>';
     }
     return $output;
 }
Example #20
0
/**
 * search post
 *
 * @since 1.2.1
 * @deprecated 2.0.0
 *
 * @package Redaxscript
 * @category Search
 * @author Henry Ruhs
 */
function search_post()
{
    /* clean post */
    if (ATTACK_BLOCKED < 10) {
        $search_terms = clean($_POST['search_terms'], 1);
    }
    /* validate post */
    if (strlen($search_terms) < 3 || $search_terms == l('search_terms')) {
        $error = l('input_incorrect');
    } else {
        $search = array_filter(explode(' ', $search_terms));
        $search_keys = array_keys($search);
        $last = end($search_keys);
        /* query search */
        $query = 'SELECT id, title, alias, description, date, category, access FROM ' . PREFIX . 'articles WHERE (language = \'' . LANGUAGE . '\' || language = \'\') && status = 1';
        if ($search) {
            $query .= ' && (';
            foreach ($search as $key => $value) {
                $query .= 'title LIKE \'%' . $value . '%\' || description LIKE \'%' . $value . '%\' || keywords LIKE \'%' . $value . '%\' || text LIKE \'%' . $value . '%\'';
                if ($last != $key) {
                    $query .= ' || ';
                }
            }
            $query .= ')';
        }
        $query .= ' ORDER BY date DESC LIMIT 50';
        $result = mysql_query($query);
        $num_rows = mysql_num_rows($result);
        if ($result == '' || $num_rows == '') {
            $error = l('search_no');
        } else {
            if ($result) {
                $accessValidator = new Redaxscript\Validator\Access();
                $output = '<h2 class="title_content title_search_result">' . l('search') . '</h2>';
                $output .= form_element('fieldset', '', 'set_search_result', '', '', '<span class="title_content_sub title_search_result_sub">' . l('articles') . '</span>') . '<ol class="list_search_result">';
                while ($r = mysql_fetch_assoc($result)) {
                    $access = $r['access'];
                    $check_access = $accessValidator->validate($access, MY_GROUPS);
                    /* if access granted */
                    if ($check_access == 1) {
                        if ($r) {
                            foreach ($r as $key => $value) {
                                ${$key} = stripslashes($value);
                            }
                        }
                        /* prepare metadata */
                        if ($description == '') {
                            $description = $title;
                        }
                        $date = date(s('date'), strtotime($date));
                        /* build route */
                        if ($category == 0) {
                            $route = $alias;
                        } else {
                            $route = build_route('articles', $id);
                        }
                        /* collect item output */
                        $output .= '<li class="item_search_result">' . anchor_element('internal', '', 'link_search_result', $title, $route, $description) . '<span class="date_search_result">' . $date . '</span></li>';
                    } else {
                        $counter++;
                    }
                }
                $output .= '</ol></fieldset>';
                /* handle access */
                if ($num_rows == $counter) {
                    $error = l('access_no');
                }
            }
        }
    }
    /* handle error */
    if ($error) {
        notification(l('something_wrong'), $error);
    } else {
        echo $output;
    }
}
Example #21
0
/**
 * navigation list
 *
 * @since 1.2.1
 * @deprecated 2.0.0
 *
 * @package Redaxscript
 * @category Navigation
 * @author Henry Ruhs
 *
 * @param string $table
 * @param array $options
 */
function navigation_list($table = '', $options = '')
{
    $output = Redaxscript\Hook::trigger(__FUNCTION__ . '_start');
    /* define option variables */
    if (is_array($options)) {
        foreach ($options as $key => $value) {
            $key = 'option_' . $key;
            ${$key} = $value;
        }
    }
    /* fallback */
    if ($option_order == '') {
        $option_order = s('order');
    }
    if ($option_limit == '') {
        $option_limit = s('limit');
    }
    /* switch table */
    switch ($table) {
        case 'categories':
            $wording_single = 'category';
            $query_parent = 'parent';
            break;
        case 'articles':
            $wording_single = 'article';
            $query_parent = 'category';
            break;
        case 'comments':
            $wording_single = 'comment';
            $query_parent = 'article';
            break;
    }
    /* query contents */
    $query = 'SELECT * FROM ' . PREFIX . $table . ' WHERE (language = \'' . LANGUAGE . '\' || language = \'\') && status = 1';
    /* setup parent */
    if ($query_parent) {
        if ($option_parent) {
            $query .= ' && ' . $query_parent . ' = ' . $option_parent;
        } else {
            if ($table == 'categories') {
                $query .= ' && ' . $query_parent . ' = 0';
            }
        }
    }
    /* setup query filter */
    if ($table == 'categories' || $table == 'articles') {
        /* setup filter alias option */
        if ($option_filter_alias) {
            $query .= ' && alias IN (' . $option_filter_alias . ')';
        }
        /* setup filter rank option */
        if ($option_filter_rank) {
            $query .= ' && rank IN (' . $option_filter_rank . ')';
        }
    }
    /* setup rank and limit */
    $query .= ' ORDER BY rank ' . $option_order . ' LIMIT ' . $option_limit;
    /* query result */
    $result = mysql_query($query);
    $num_rows = mysql_num_rows($result);
    if ($result == '' || $num_rows == '') {
        $error = l($wording_single . '_no') . l('point');
    } else {
        if ($result) {
            $accessValidator = new Redaxscript\Validator\Access();
            while ($r = mysql_fetch_assoc($result)) {
                $access = $r['access'];
                $check_access = $accessValidator->validate($access, MY_GROUPS);
                /* if access granted */
                if ($check_access == 1) {
                    if ($r) {
                        foreach ($r as $key => $value) {
                            ${$key} = stripslashes($value);
                        }
                    }
                    /* build class string */
                    if (LAST_PARAMETER == $alias && $table != 'comments') {
                        $class_string = ' class="item_active"';
                    } else {
                        $class_string = '';
                    }
                    /* prepare metadata */
                    if ($table == 'comments') {
                        $description = $title = truncate($author . l('colon') . ' ' . strip_tags($text), 80, '...');
                    }
                    if ($description == '') {
                        $description = $title;
                    }
                    /* build route */
                    if ($table == 'categories' && $parent == 0 || $table == 'articles' && $category == 0) {
                        $route = $alias;
                    } else {
                        $route = build_route($table, $id);
                    }
                    /* collect item output */
                    $output .= '<li' . $class_string . '>' . anchor_element('internal', '', '', $title, $route, $description);
                    /* collect children list output */
                    if ($table == 'categories' && $option_children == 1) {
                        ob_start();
                        navigation_list($table, array('parent' => $id, 'class' => 'list_children'));
                        $output .= ob_get_clean();
                    }
                    $output .= '</li>';
                } else {
                    $counter++;
                }
            }
            /* handle access */
            if ($num_rows == $counter) {
                $error = l('access_no') . l('point');
            }
        }
    }
    /* build id string */
    if ($option_id) {
        $id_string = ' id="' . $option_id . '"';
    }
    /* build class string */
    if ($option_class) {
        $class_string = ' class="' . $option_class . '"';
    } else {
        $class_string = ' class="list_' . $table . '"';
    }
    /* handle error */
    if ($error && $option_parent == '') {
        $output = '<ul' . $id_string . $class_string . '><li>' . $error . '</li></ul>';
    } else {
        if ($output) {
            $output = '<ul' . $id_string . $class_string . '>' . $output . '</ul>';
        }
    }
    $output .= Redaxscript\Hook::trigger(__FUNCTION__ . '_end');
    echo $output;
}
/**
 * admin contents list
 *
 * @since 1.2.1
 * @deprecated 2.0.0
 *
 * @package Redaxscript
 * @category Admin
 * @author Henry Ruhs
 */
function admin_contents_list()
{
    $output = Redaxscript\Hook::trigger(__FUNCTION__ . '_start');
    /* define access variables */
    $table_new = TABLE_NEW;
    if (TABLE_PARAMETER == 'comments') {
        $articles_total = Redaxscript\Db::forTablePrefix('articles')->count();
        $articles_comments_disable = Redaxscript\Db::forTablePrefix('articles')->where('comments', 0)->count();
        if ($articles_total == $articles_comments_disable) {
            $table_new = 0;
        }
    }
    /* switch table */
    switch (TABLE_PARAMETER) {
        case 'categories':
            $wording_single = 'category';
            $wording_parent = 'category_parent';
            break;
        case 'articles':
            $wording_single = 'article';
            $wording_parent = 'category';
            break;
        case 'extras':
            $wording_single = 'extra';
            break;
        case 'comments':
            $wording_single = 'comment';
            $wording_parent = 'article';
            break;
    }
    /* query contents */
    $result = Redaxscript\Db::forTablePrefix(TABLE_PARAMETER)->orderByAsc('rank')->findArray();
    $num_rows = count($result);
    /* collect listing output */
    $output .= '<h2 class="title_content">' . l(TABLE_PARAMETER) . '</h2>';
    $output .= '<div class="wrapper_button_admin">';
    if ($table_new == 1) {
        $output .= anchor_element('internal', '', 'button_admin button_plus_admin', l($wording_single . '_new'), 'admin/new/' . TABLE_PARAMETER);
    }
    if (TABLE_EDIT == 1 && $num_rows) {
        $output .= anchor_element('internal', '', 'button_admin button_sort_admin', l('sort'), 'admin/sort/' . TABLE_PARAMETER . '/' . TOKEN);
    }
    $output .= '</div><div class="wrapper_table_admin"><table class="table table_admin">';
    /* collect thead */
    $output .= '<thead><tr><th class="s3o6 column_first">' . l('title') . '</th><th class="';
    if (TABLE_PARAMETER != 'extras') {
        $output .= 's1o6';
    } else {
        $output .= 's3o6';
    }
    $output .= ' column_second">';
    if (TABLE_PARAMETER == 'comments') {
        $output .= l('identifier');
    } else {
        $output .= l('alias');
    }
    $output .= '</th>';
    if (TABLE_PARAMETER != 'extras') {
        $output .= '<th class="column_third">' . l($wording_parent) . '</th>';
    }
    $output .= '<th class="column_move column_last">' . l('rank') . '</th></tr></thead>';
    /* collect tfoot */
    $output .= '<tfoot><tr><td class="column_first">' . l('title') . '</td><td class="column_second">';
    if (TABLE_PARAMETER == 'comments') {
        $output .= l('identifier');
    } else {
        $output .= l('alias');
    }
    $output .= '</td>';
    if (TABLE_PARAMETER != 'extras') {
        $output .= '<td class="column_third">' . l($wording_parent) . '</td>';
    }
    $output .= '<td class="column_move column_last">' . l('rank') . '</td></tr></tfoot>';
    if ($result == '' || $num_rows == '') {
        $error = l($wording_single . '_no') . l('point');
    } else {
        if ($result) {
            $accessValidator = new Redaxscript\Validator\Access();
            foreach ($result as $r) {
                $access = $r['access'];
                /* access granted */
                if ($accessValidator->validate($access, MY_GROUPS) === Redaxscript\Validator\ValidatorInterface::PASSED) {
                    if ($r) {
                        foreach ($r as $key => $value) {
                            ${$key} = stripslashes($value);
                        }
                    }
                    /* prepare name */
                    if (TABLE_PARAMETER == 'comments') {
                        $name = truncate($author . l('colon') . ' ' . strip_tags($text), 80, '...');
                    } else {
                        $name = $title;
                    }
                    /* build class string */
                    if ($status == 1) {
                        $class_status = '';
                    } else {
                        $class_status = 'row_disabled';
                    }
                    /* build route */
                    if (TABLE_PARAMETER != 'extras' && $status == 1) {
                        if (TABLE_PARAMETER == 'categories' && $parent == 0 || TABLE_PARAMETER == 'articles' && $category == 0) {
                            $route = $alias;
                        } else {
                            $route = build_route(TABLE_PARAMETER, $id);
                        }
                    } else {
                        $route = '';
                    }
                    /* collect tbody output */
                    if (TABLE_PARAMETER == 'categories') {
                        if ($before != $parent) {
                            $output .= '<tbody><tr class="row_group"><td colspan="4">';
                            if ($parent) {
                                $output .= Redaxscript\Db::forTablePrefix('categories')->where('id', $parent)->findOne()->title;
                            } else {
                                $output .= l('none');
                            }
                            $output .= '</td></tr>';
                        }
                        $before = $parent;
                    }
                    if (TABLE_PARAMETER == 'articles') {
                        if ($before != $category) {
                            $output .= '<tbody><tr class="row_group"><td colspan="4">';
                            if ($category) {
                                $output .= Redaxscript\Db::forTablePrefix('categories')->where('id', $category)->findOne()->title;
                            } else {
                                $output .= l('uncategorized');
                            }
                            $output .= '</td></tr>';
                        }
                        $before = $category;
                    }
                    if (TABLE_PARAMETER == 'comments') {
                        if ($before != $article) {
                            $output .= '<tbody><tr class="row_group"><td colspan="4">';
                            if ($article) {
                                $output .= Redaxscript\Db::forTablePrefix('articles')->where('id', $article)->findOne()->title;
                            } else {
                                $output .= l('none');
                            }
                            $output .= '</td></tr>';
                        }
                        $before = $article;
                    }
                    /* collect table row */
                    $output .= '<tr';
                    if ($alias) {
                        $output .= ' id="' . $alias . '"';
                    }
                    if ($class_status) {
                        $output .= ' class="' . $class_status . '"';
                    }
                    $output .= '><td class="column_first">';
                    if ($language) {
                        $output .= '<span class="icon_flag language_' . $language . '" title="' . l($language) . '">' . $language . '</span>';
                    }
                    if ($status == 1) {
                        $output .= anchor_element('internal', '', 'link_view', $name, $route);
                    } else {
                        $output .= $name;
                    }
                    /* collect control output */
                    $output .= admin_control('contents', TABLE_PARAMETER, $id, $alias, $status, TABLE_NEW, TABLE_EDIT, TABLE_DELETE);
                    /* collect alias and id output */
                    $output .= '</td><td class="column_second">';
                    if (TABLE_PARAMETER == 'comments') {
                        $output .= $id;
                    } else {
                        $output .= $alias;
                    }
                    $output .= '</td>';
                    /* collect parent output */
                    if (TABLE_PARAMETER != 'extras') {
                        $output .= '<td class="column_third">';
                        if (TABLE_PARAMETER == 'categories') {
                            if ($parent) {
                                $parent_title = Redaxscript\Db::forTablePrefix('categories')->where('id', $parent)->findOne()->title;
                                $output .= anchor_element('internal', '', 'link_parent', $parent_title, 'admin/edit/categories/' . $parent);
                            } else {
                                $output .= l('none');
                            }
                        }
                        if (TABLE_PARAMETER == 'articles') {
                            if ($category) {
                                $category_title = Redaxscript\Db::forTablePrefix('categories')->where('id', $category)->findOne()->title;
                                $output .= anchor_element('internal', '', 'link_parent', $category_title, 'admin/edit/categories/' . $category);
                            } else {
                                $output .= l('uncategorized');
                            }
                        }
                        if (TABLE_PARAMETER == 'comments') {
                            if ($article) {
                                $article_title = Redaxscript\Db::forTablePrefix('articles')->where('id', $article)->findOne()->title;
                                $output .= anchor_element('internal', '', 'link_parent', $article_title, 'admin/edit/articles/' . $article);
                            } else {
                                $output .= l('none');
                            }
                        }
                        $output .= '</td>';
                    }
                    $output .= '<td class="column_move column_last">';
                    /* collect control output */
                    if (TABLE_EDIT == 1) {
                        $rank_desc = Redaxscript\Db::forTablePrefix(TABLE_PARAMETER)->max('rank');
                        if ($rank > 1) {
                            $output .= anchor_element('internal', '', 'move_up', l('up'), 'admin/up/' . TABLE_PARAMETER . '/' . $id . '/' . TOKEN);
                        } else {
                            $output .= '<span class="move_up">' . l('up') . '</span>';
                        }
                        if ($rank < $rank_desc) {
                            $output .= anchor_element('internal', '', 'move_down', l('down'), 'admin/down/' . TABLE_PARAMETER . '/' . $id . '/' . TOKEN);
                        } else {
                            $output .= '<span class="move_down">' . l('down') . '</span>';
                        }
                        $output .= '</td>';
                    }
                    $output .= '</tr>';
                    /* collect tbody output */
                    if (TABLE_PARAMETER == 'categories') {
                        if ($before != $parent) {
                            $output .= '</tbody>';
                        }
                    }
                    if (TABLE_PARAMETER == 'articles') {
                        if ($before != $category) {
                            $output .= '</tbody>';
                        }
                    }
                    if (TABLE_PARAMETER == 'comments') {
                        if ($before != $article) {
                            $output .= '</tbody>';
                        }
                    }
                } else {
                    $counter++;
                }
            }
            /* handle access */
            if ($num_rows == $counter) {
                $error = l('access_no') . l('point');
            }
        }
    }
    /* handle error */
    if ($error) {
        $output .= '<tbody><tr><td colspan="4">' . $error . '</td></tr></tbody>';
    }
    $output .= '</table></div>';
    $output .= Redaxscript\Hook::trigger(__FUNCTION__ . '_end');
    echo $output;
}
Example #23
0
/**
 * contents
 *
 * @since 1.2.1
 * @deprecated 2.0.0
 *
 * @package Redaxscript
 * @category Contents
 * @author Henry Ruhs
 */
function contents()
{
    $output = Redaxscript\Hook::trigger('contentStart');
    $aliasValidator = new Redaxscript\Validator\Alias();
    $lastId = Redaxscript\Registry::get('lastId');
    $lastTable = Redaxscript\Registry::get('lastTable');
    $categoryId = Redaxscript\Registry::get('categoryId');
    $articleId = Redaxscript\Registry::get('articleId');
    $firstParameter = Redaxscript\Registry::get('firstParameter');
    /* query articles */
    $articles = Redaxscript\Db::forTablePrefix('articles')->where('status', 1);
    $articles->whereLanguageIs(Redaxscript\Registry::get('language'));
    /* handle sibling */
    if ($lastId) {
        $sibling = Redaxscript\Db::forTablePrefix($lastTable)->where('id', $lastId)->findOne()->sibling;
        /* query sibling collection */
        $sibling_array = Redaxscript\Db::forTablePrefix($lastTable)->whereIn('sibling', [$lastId, $sibling > 0 ? $sibling : null])->where('language', Redaxscript\Registry::get('language'))->select('id')->findFlatArray();
        /* process sibling array */
        foreach ($sibling_array as $value) {
            $id_array[] = $value;
        }
    }
    /* handle article */
    if ($articleId) {
        $id_array[] = $sibling;
        $id_array[] = $articleId;
        $articles->whereIn('id', $id_array);
    } else {
        if ($categoryId) {
            if (!$id_array) {
                if ($sibling > 0) {
                    $id_array[] = $sibling;
                } else {
                    $id_array[] = $categoryId;
                }
            }
            $articles->whereIn('category', $id_array)->orderGlobal('rank');
            /* handle sub parameter */
            $result = $articles->findArray();
            if ($result) {
                $num_rows = count($result);
                $sub_maximum = ceil($num_rows / Redaxscript\Db::getSetting('limit'));
                $sub_active = Redaxscript\Registry::get('lastSubParameter');
                /* sub parameter */
                if (Redaxscript\Registry::get('lastSubParameter') > $sub_maximum || !Redaxscript\Registry::get('lastSubParameter')) {
                    $sub_active = 1;
                } else {
                    $offset_string = ($sub_active - 1) * Redaxscript\Db::getSetting('limit') . ', ';
                }
            }
            $articles->limit($offset_string . Redaxscript\Db::getSetting('limit'));
        } else {
            $articles->limit(0);
        }
    }
    /* query result */
    $result = $articles->findArray();
    $num_rows_active = count($result);
    /* handle error */
    if ($categoryId && !$num_rows) {
        $error = Redaxscript\Language::get('article_no');
    } else {
        if (!$result || !$num_rows_active || Redaxscript\Registry::get('contentError')) {
            $error = Redaxscript\Language::get('content_not_found');
        } else {
            if ($result) {
                $accessValidator = new Redaxscript\Validator\Access();
                foreach ($result as $r) {
                    $access = $r['access'];
                    /* access granted */
                    if ($accessValidator->validate($access, Redaxscript\Registry::get('myGroups')) === Redaxscript\Validator\ValidatorInterface::PASSED) {
                        if ($r) {
                            foreach ($r as $key => $value) {
                                ${$key} = $value;
                            }
                        }
                        if ($lastTable == 'categories' || !Redaxscript\Registry::get('fullRoute') || $aliasValidator->validate($firstParameter, Redaxscript\Validator\Alias::MODE_DEFAULT) == Redaxscript\Validator\ValidatorInterface::PASSED) {
                            $route = build_route('articles', $id);
                        }
                        /* parser */
                        $parser = new Redaxscript\Parser(Redaxscript\Registry::getInstance(), Redaxscript\Language::getInstance());
                        $parser->init($text, ['route' => $route]);
                        /* collect headline output */
                        $output .= Redaxscript\Hook::trigger('contentFragmentStart', $r);
                        if ($headline == 1) {
                            $output .= '<h2 class="rs-title-content" id="article-' . $alias . '">';
                            if ($lastTable == 'categories' || !Redaxscript\Registry::get('fullRoute') || $aliasValidator->validate($firstParameter, Redaxscript\Validator\Alias::MODE_DEFAULT) == Redaxscript\Validator\ValidatorInterface::PASSED) {
                                $output .= '<a href="' . Redaxscript\Registry::get('parameterRoute') . $route . '">' . $title . '</a>';
                            } else {
                                $output .= $title;
                            }
                            $output .= '</h2>';
                        }
                        /* collect box output */
                        $output .= '<div class="rs-box-content">' . $parser->getOutput() . '</div>';
                        if ($byline == 1) {
                            $output .= byline('articles', $id, $author, $date);
                        }
                        $output .= Redaxscript\Hook::trigger('contentFragmentEnd', $r);
                        /* admin dock */
                        if (Redaxscript\Registry::get('loggedIn') == Redaxscript\Registry::get('token') && $firstParameter != 'logout') {
                            $output .= admin_dock('articles', $id);
                        }
                    } else {
                        $counter++;
                    }
                }
                /* handle access */
                if ($lastTable == 'categories') {
                    if ($num_rows_active == $counter) {
                        $error = Language::get('access_no');
                    }
                } else {
                    if ($lastTable == 'articles' && $counter == 1) {
                        $error = Redaxscript\Language::get('access_no');
                    }
                }
            }
        }
    }
    /* handle error */
    if ($error) {
        /* show error */
        $messenger = new Redaxscript\Messenger(Redaxscript\Registry::getInstance());
        echo $messenger->error($error, Redaxscript\Language::get('something_wrong'));
    } else {
        $output .= Redaxscript\Hook::trigger('contentEnd');
        echo $output;
        /* call comments as needed */
        if ($articleId) {
            /* comments replace */
            if ($comments == 1 && Redaxscript\Registry::get('commentReplace')) {
                Redaxscript\Hook::trigger('commentReplace');
            } else {
                if ($comments > 0) {
                    $route = build_route('articles', $articleId);
                    comments($articleId, $route);
                    /* comment form */
                    if ($comments == 1 || Redaxscript\Registry::get('commentNew') && $comments == 3) {
                        $commentForm = new Redaxscript\View\CommentForm(Redaxscript\Registry::getInstance(), Redaxscript\Language::getInstance());
                        echo $commentForm->render($articleId);
                    }
                }
            }
        }
    }
    /* call pagination as needed */
    if ($sub_maximum > 1 && Redaxscript\Db::getSetting('pagination') == 1) {
        $route = build_route('categories', $categoryId);
        pagination($sub_active, $sub_maximum, $route);
    }
}