예제 #1
0
파일: errors.php 프로젝트: shgysk8zer0/core
 /**
  * Registers the PDOStatement to execute in DBErrorException
  *
  * @param PDOStatement $stm     Prepared statement to store errors to database
  * @param array        $binders Array or keys to bind to when executing $stm
  * @return self
  */
 public function registerPDOStatement(API\Interfaces\PDOStatement $stm = null, array $binders = array())
 {
     if (is_null($stm)) {
         $this->error_stm = Core\PDO::load(PDO::DEFAULT_CON)->prepare(self::PDO_QUERY);
     } else {
         $this->error_stm = $stm;
     }
     if (array_keys($binders) === array_keys($this->binders)) {
         $this->binders = $binders;
     }
     return $this;
 }
예제 #2
0
    /**
     * Where all of the parsing and setting of data is handled.
     * Switches on type of page request, and sets various properties
     * accordingly.
     *
     * @return void
     * @uses \shgsyk8zer0\Template
     */
    private function getContent()
    {
        $login = Core\Login::load();
        $DB = Core\PDO::load('connect.json');
        switch ($this->type) {
            case 'posts':
                $data = get_object_vars($this->data);
                array_map(function ($name, $value) {
                    $this->{$name} = $value;
                }, array_keys($data), array_values($data));
                unset($data);
                $post = Core\Template::load('posts');
                $comments = Core\Template::load('comments');
                $comments_section = Core\Template::load('comments_section');
                $comments_section->title($this->data->title)->home(URL)->comments(null);
                $results = $DB->prepare('SELECT
						`comment`,
						`author`,
						`author_url`,
						`time`
					FROM `comments`
					WHERE `post` = :post;')->execute(['post' => end($this->request_path)])->getResults();
                if (is_array($results)) {
                    foreach ($results as $comment) {
                        $time = strtotime($comment->time);
                        $comments->comment($comment->comment)->author(strlen($comment->author_url) ? "<a href=\"{$comment->author_url}\" target=\"_blank\">{$comment->author}</a>" : $comment->author)->time(date('l, F jS Y h:i A', $time));
                        $comments_section->comments .= "{$comments}";
                    }
                }
                foreach (explode(',', $this->data->keywords) as $tag) {
                    $post->tags .= '<a href="' . URL . 'tags/' . urlencode(trim($tag)) . '" rel="tag">' . trim($tag) . "</a>";
                }
                $license = new Core\Creative_Commons_License();
                $license->title = $this->data->title;
                $license->author = $this->data->author;
                $license->author_url = "{$this->data->author_url}?rel=author";
                $license->time = $this->data->created;
                $license->use_svg = true;
                $license->share_alike = true;
                $post->title($this->data->title)->content($this->data->content)->home(URL)->comments("{$comments_section}")->url($this->data->url)->license($license);
                $this->content = "{$post}";
                break;
            case 'tags':
                $this->title = 'Tags';
                $this->description = "Tags search results for {$this->request_path[1]}";
                $this->keywords = "Keywords, tags, search, {$this->request_path[1]}";
                $this->content = '<div class="tags">';
                $template = Core\Template::load('tags');
                array_map(function (\stdClass $post) use(&$template) {
                    if (!isset($post->title)) {
                        return;
                    }
                    $template->title($post->title)->description($post->description)->author($post->author)->author_url($post->author_url)->url($post->url === '' ? URL : URL . 'posts/' . $post->url)->date(date('D M jS, Y \\a\\t h:iA', strtotime($post->created)));
                    $this->content .= "{$template}";
                }, array_filter($this->data, 'is_object'));
                $this->content .= '</div>';
                break;
        }
    }
<?php

error_reporting(0);
define('PARAM', 'query');
if (!array_key_exists(PARAM, $_REQUEST)) {
    http_response_code(400);
    exit;
}
$PDO = \shgysk8zer0\Core\PDO::load('connect.json');
if (!$PDO->connected) {
    http_response_code(500);
    exit;
}
header('Content-Type: application/json');
$matches = $PDO->prepare('SELECT DISTINCT(`keywords`) as `tags` FROM `posts` WHERE `keywords` LIKE :tags');
$matches->tags = '%' . str_replace(' ', '%', $_REQUEST[PARAM]) . '%';
$results = array_reduce($matches->execute()->getResults(), 'reduce_tags', array());
exit(json_encode($results));
/**
 * Reduce an array of results from PDO query into a unique array
 *
 * @param  array    $results  Carried array of unique results
 * @param  stdClass $tags     Single row item
 * @return array              Array of unique results
 */
function reduce_tags(array $results = array(), \stdClass $post)
{
    foreach (explode(',', $post->tags) as $tag) {
        $tag = trim(strtolower($tag));
        if (!in_array(['phrase' => $tag], $results) and preg_match('/^' . preg_quote($tag) . '/i', $_REQUEST[PARAM])) {
            array_push($results, ['phrase' => $tag]);
예제 #4
0
 /**
  * Stores data array to database
  *
  * @param  mixed  $con   Database credentials
  * @param  string $table Table to use
  * @return void
  */
 private function _storeData($con, $table)
 {
     $pdo = PDO::load($con);
     $stm = $pdo->prepare(str_replace('%TABLE%', $table, self::SQL));
     $stm->execute($this->{self::MAGIC_PROPERTY});
 }
예제 #5
0
/**
 * Builds a <datalist> for the request, each result being a <option>
 *
 * @param  string $list Requested datalist
 * @return string       Results as a <datalist>
 * @uses \DOMDocument
 * @uses \DOMElement
 */
function get_datalist($list)
{
    $pdo = \shgysk8zer0\Core\PDO::load('connect.json');
    if (!$pdo->connected) {
        return;
    }
    switch (strtolower($list)) {
        case 'tags':
            $options = get_all_tags();
            break;
        case 'php_errors_files':
            $options = array_map(function (\stdClass $option) {
                return preg_replace('/^' . preg_quote(BASE . DIRECTORY_SEPARATOR, '/') . '/', null, $option->file);
            }, $pdo->fetchArray("SELECT DISTINCT(`file`) FROM `PHP_errors`;"));
            break;
        default:
            return [];
    }
    $datalist = array_reduce($options, function (\DOMElement $list, $item) {
        $list->option = ['@value' => $item];
        return $list;
    }, new \shgysk8zer0\Core\HTML_El('datalist', null, null, true));
    $datalist->{'@id'} = "{$list}";
    return "{$datalist}";
}
예제 #6
0
파일: cron.php 프로젝트: shgysk8zer0/core
 /**
  * Updates `last_ran` column for all executed jobs
  *
  * @return void
  */
 private function update_last_ran(\shgysk8zer0\Core\PDO &$pdo)
 {
     $pdo->prepare("UPDATE `cron`\n\t\t\t\tSET `last_ran` = :time\n\t\t\t\tWHERE `function` = :function\n\t\t\t");
     //Update all jobs which completed with new last_run
     foreach ($this->jobs as $job) {
         $pdo->bind(['time' => date('Y-m-d H:i', $this->time) . ':00', 'function' => $job->function])->execute();
     }
 }