Beispiel #1
0
 protected function getConfig($field)
 {
     if (!($config = entity('store_config')->where('key', '=', $field)->first())) {
         $config = entity('store_config');
     }
     return $config;
 }
Beispiel #2
0
 public function toArray()
 {
     $options = [];
     foreach (entity('category')->whereNull('category_id')->get() as $category) {
         $options[$category->id] = $category->name;
     }
     return $options;
 }
Beispiel #3
0
 public function toArray()
 {
     $options = [];
     foreach (entity('theme')->all() as $theme) {
         $options[$theme->id] = $theme->name;
     }
     return $options;
 }
Beispiel #4
0
 protected function hasItem()
 {
     $cart = entity('cart')->find($this->cart_id);
     if ($cart) {
         return $cart->items()->where('product_id', '=', $this->product_id)->first();
     }
     return false;
 }
 public function getProduct($url_key)
 {
     $product = entity('product')->findByAttribute('url', $url_key);
     if ($product) {
         return view('catalog.product.view')->withProduct($product);
     }
     throw new HttpException(404, 'Product not found.');
 }
Beispiel #6
0
 /**
  * Check the definitions of all entities
  */
 public function testEntityDefinitions()
 {
     foreach (config('entity') as $entity => $data) {
         $model = entity($entity);
         $this->assertObjectHasAttribute('entity', $model);
         $this->assertObjectHasAttribute('table', $model);
         $this->assertInstanceOf('Lavender\\Contracts\\Entity', $model);
     }
 }
Beispiel #7
0
 protected function sample_blog()
 {
     // create store
     $store = entity('store')->create(['theme' => ['theme' => $this->store->theme_id], 'root_category' => ['category' => $this->store->category_id]]);
     // set the current store scope
     $this->store->setStore($store);
     // set config for this store
     $config = entity('store_config')->fill(['key' => 'name', 'value' => 'Lavender Blog']);
     $config->save();
 }
 public function getIndex(Cart $cart)
 {
     // todo detect multiple shipments
     $number = 1;
     if (!($shipment = $cart->getShipment($number))) {
         $shipment = entity('cart_shipment')->create(['number' => $number]);
         $cart->update(['shipments' => [$shipment]]);
     }
     return redirect('cart/shipment/' . $shipment->number);
 }
 public static function toNewsEntity($param = array())
 {
     $id = empty($param['id']) ? null : addslashes_modified($param['id']);
     $title = empty($param['title']) ? null : addslashes_modified($param['title']);
     $content = empty($param['content']) ? null : addslashes_modified($param['content']);
     $author = empty($param['author']) ? null : addslashes_modified($param['author']);
     $from = empty($param['from']) ? null : addslashes_modified($param['from']);
     $dateline = time();
     $objNews = entity("news", null, array("id" => $id, "title" => $title, "content" => $content, "author" => $author, "from" => $from, "dateline" => $dateline));
     return $objNews;
 }
Beispiel #10
0
 /**
  * Execute the command.
  */
 public function handle()
 {
     if ($cart = entity('cart')->find($this->cart_id)) {
         if ($cart_item = $cart->findItem($this->item_id)) {
             if ($this->qty) {
                 $cart_item->update(['qty' => $this->qty]);
             } else {
                 $cart_item->delete();
             }
         }
     }
 }
Beispiel #11
0
 protected function store_selector()
 {
     $backend_stores = menu('header.stores');
     $current = app('App\\Store');
     $stores = entity('store')->all();
     foreach ($stores as $store) {
         if ($store->id == $current->id) {
             continue;
         }
         $backend_stores->add('switch-' . $store->id, ['href' => url('backend/store/switch/' . $store->id), 'text' => 'Switch to store ' . $store->id]);
     }
 }
 public static function getPassword($username = null)
 {
     $pwd = null;
     if (!empty($username)) {
         $objAdmin = entity("admin", array("username", "password"));
         $aryWhere = [["username"], ["="], ['?'], [$username]];
         $res = DBUtil::fetch($objAdmin, $aryWhere);
         if (is_array($res)) {
             $objAdminResult = end($res);
             $pwd = $objAdminResult->getPassword();
         }
     }
     return $pwd;
 }
Beispiel #13
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $success = false;
     while (!$success) {
         $admin = entity('admin');
         $email = $this->option('email');
         $password = $this->option('password');
         $admin->email = $email ?: $this->ask('Enter an email address: (required)');
         $admin->password = $password ?: $this->secret('Enter a password: (required)');
         $admin->password_confirmation = $password ?: $this->secret('Confirm your password: (required)');
         $success = $admin->save();
         if (!$success) {
             $this->error($admin->errors);
         }
     }
 }
 public function newsadd()
 {
     $arrayNews = empty($_POST) ? array() : $_POST;
     if (empty($arrayNews)) {
         View::assign(array("news" => entity("news")));
         //填入空数据
         View::display("admin/newsadd.html");
     } else {
         //如果没有传入ID说明是添加
         $res = empty($arrayNews['id']) ? DAO("news", "addNews", array($arrayNews)) : DAO("news", "updateNews", array($arrayNews));
         if ($res) {
             echo "操作成功";
         } else {
             echo "操作失败";
         }
     }
 }
Beispiel #15
0
 /**
  * @param $entity
  * @param null $id
  * @return Entity
  */
 protected function validateEntity($entity, $id = null)
 {
     if (app()->bound("entity.{$entity}")) {
         $model = entity($entity);
         // passing < 1 will allow new entities
         if ($id > 0) {
             $model = $model->find($id);
         }
         if ($model) {
             return $model;
         } else {
             Message::addError("{$entity} not found in database for id '{$id}'.");
         }
     } else {
         Message::addError("Entity '{$entity}' not found.");
     }
 }
Beispiel #16
0
 /**
  * Run the database seeds.
  */
 public function run()
 {
     // only run this seed if store doesn't exist
     if (!$this->store->exists) {
         // create default store
         $default_store = entity('store')->create(['default' => true]);
         // set the current store scope
         $this->store->setStore($default_store);
         // create default theme
         $theme = entity('theme')->create(['code' => 'default', 'name' => 'Default Theme']);
         // create root category
         $category = entity('category')->create(['name' => 'Root Category']);
         // update store
         $default_store->update(['theme' => $theme, 'root_category' => $category]);
         $this->command->info("Lavender has successfully installed!");
     }
 }
 function setResultQuery($query, $param)
 {
     $array = NULL;
     $pattern = "/FROM (\\w+)\\s*\\S*/i";
     //匹配表名
     preg_match($pattern, $query, $matchs);
     $tableName = empty($matchs[1]) ? null : $matchs[1];
     $objBean = null;
     if (!$this->mysql->connect_errno) {
         $stmt = $this->setStatement($query, $param);
         try {
             if ($stmt != NULL) {
                 if ($stmt->execute()) {
                     // Obtener resultados
                     $stmt->store_result();
                     $variables = array();
                     $data = array();
                     $meta = $stmt->result_metadata();
                     while ($field = $meta->fetch_field()) {
                         $variables[] =& $data[$field->name];
                     }
                     call_user_func_array(array($stmt, 'bind_result'), $variables);
                     $i = 0;
                     while ($stmt->fetch()) {
                         //get a row data by once.
                         $objBean = entity($tableName);
                         foreach ($data as $k => $v) {
                             $method = "set" . ucfirst($k);
                             $objBean->{$method}($v);
                         }
                         $array[] = $objBean;
                         $i++;
                     }
                     $stmt->close();
                 }
             }
         } catch (Exception $e) {
             $array = FALSE;
             //logger
             $this->log->fatal("Message:[{$e->getMessage()}] Function:[" . __FUNCTION__ . "]");
         }
     }
     return $array;
 }
Beispiel #18
0
/**
 * Create Action
 *
 * @param array $entity
 *
 * @return void
 */
function action_create(array $entity) : void
{
    $data = http_post('data');
    if ($data) {
        // Perform save callback and redirect to admin on success
        if (save($entity['id'], $data)) {
            redirect(url('*/admin'));
        }
        $data = array_filter($data, function ($item) {
            return empty($item['_success']);
        });
    } else {
        // Initial create action call
        $data = entity($entity['id'], (int) http_post('create'));
    }
    layout_load();
    vars('content', ['data' => $data, 'title' => $entity['name']]);
    vars('head', ['title' => $entity['name']]);
}
Beispiel #19
0
 /**
  * @param Entity $account
  */
 public function customer_login(Entity $account)
 {
     try {
         // if account login is a customer
         if ($account->getEntityName() == 'customer') {
             $cart = app('App\\Cart');
             // load customer cart
             if ($customer_cart = $account->getCart()) {
                 // if cart ids don't match, we must merge their contents
                 if ($customer_cart->id != $cart->id) {
                     $original_cart = $cart->getCart();
                     foreach ($original_cart->items as $item) {
                         // reassign cart_id to customer's cart
                         $item->cart_id = $customer_cart->id;
                         $this->dispatchFromArray('App\\Commands\\Cart\\AddToCart', $item->getAttributes());
                     }
                     // delete original cart
                     $original_cart->delete();
                     // assign the customers cart
                     $cart->setCart($customer_cart);
                 } else {
                     //do nothing
                 }
             } else {
                 // load the current cart
                 $customer_cart = entity('cart')->find($cart->id);
                 // assign customer to cart
                 $customer_cart->fill(['customer' => $account]);
                 $customer_cart->save();
                 // assign the cart to global scope
                 $cart->setCart($customer_cart);
             }
         }
     } catch (\Exception $e) {
         // todo log exception
         var_dump($e->getMessage());
         die;
     }
 }
Beispiel #20
0
<?php

require __DIR__ . '/../src/mysql.php';
// Routes
$locations = entity('locations');
$meseros = entity('meseros');
$encuestas = entity('encuestas');
$app->get('/api/locations', $locations["findAll"]);
$app->get('/api/locations/[{id}]', $locations["findById"]);
$app->post('/api/locations', $locations["insert"]);
$app->get('/api/meseros', $meseros["findAll"]);
$app->post('/api/meseros', $meseros["insert"]);
$app->post('/api/put/meseros', $meseros["update"]);
$app->get('/api/meseros/[{id}]', $meseros["findById"]);
$app->post('/api/delete/meseros/[{id}]', $meseros["delete"]);
$app->post('/api/picture', function ($request, $response, $args) {
    $storage = new \Upload\Storage\FileSystem('/Users/foxtrot/Documents/code/other/encuesta/public/meseros', true);
    $file = new \Upload\File('picture', $storage);
    $new_filename = $request->getParsedBody()['id'];
    $file->setName($new_filename);
    $file->setExtension("jpg");
    try {
        // Success!
        $file->upload();
    } catch (\Exception $e) {
        // Fail!
        $errors = $file->getErrors();
        error_log("Errors: " . print_r($errors, TRUE));
    }
    return $response->withRedirect('/');
});
Beispiel #21
0
/**
 * feed reader
 *
 * @since 1.2.1
 * @deprecated 2.0.0
 *
 * @package Redaxscript
 * @category Modules
 * @author Henry Ruhs
 *
 * @param string $url
 * @param array $options
 */
function feed_reader($url = '', $options = '')
{
    /* define option variables */
    if (is_array($options)) {
        foreach ($options as $key => $value) {
            $key = 'option_' . $key;
            ${$key} = $value;
        }
    }
    /* fallback */
    if ($option_truncate_title == '') {
        $option_truncate_title = 80;
    }
    if ($option_truncate_text == '') {
        $option_truncate_text = 1000;
    }
    if ($option_limit == '') {
        $option_limit = s('limit');
    }
    /* get contents */
    $contents = file_get_contents($url);
    if ($contents) {
        $feed = new SimpleXMLElement($contents);
        /* detect feed type */
        if ($feed->entry) {
            $type = 'atom';
            $feed_object = $feed->entry;
        } else {
            if ($feed->channel) {
                $type = 'rss';
                $feed_object = $feed->channel->item;
            }
        }
        /* collect output */
        foreach ($feed_object as $value) {
            /* define variables */
            $title = entity(trim($value->title));
            if ($title) {
                $title = truncate(strip_tags($title), $option_truncate_title, '...');
            }
            /* if atom feed */
            if ($type == 'atom') {
                $route = $value->link['href'];
                $time = date(s('time'), strtotime($value->updated));
                $date = date(s('date'), strtotime($value->updated));
                $text = entity(trim($value->content));
            } else {
                if ($type == 'rss') {
                    $route = $value->link;
                    $time = date(s('time'), strtotime($value->pubDate));
                    $date = date(s('date'), strtotime($value->pubDate));
                    $text = entity(trim($value->description));
                }
            }
            if ($text) {
                $text = truncate(strip_tags($text, '<a>'), $option_truncate_text, '...');
            }
            /* if filter is invalid */
            if ($option_filter == '') {
                $filter_no = 1;
            } else {
                $position_title = strpos($title, $option_filter);
                $position_text = strpos($text, $option_filter);
                $filter_no = 0;
            }
            if ($filter_no || $position_title || $position_text) {
                /* break if limit reached */
                if (++$counter > $option_limit) {
                    break;
                }
                /* collect title output */
                if ($title) {
                    $output .= '<h3 class="title_feed_reader clearfix">';
                    if ($route) {
                        $output .= anchor_element('external', '', 'title_first', $title, $route, '', 'rel="nofollow"');
                    } else {
                        $output .= '<span class="title_first">' . $title . '</span>';
                    }
                    /* collect date output */
                    if ($time && $date) {
                        $output .= '<span class="title_second">' . $date . ' ' . l('at') . ' ' . $time . '</span>';
                    }
                    $output .= '</h3>';
                }
                /* collect text output */
                if ($text) {
                    $output .= '<div class="box_feed_reader">' . $text . '</div>';
                }
            }
        }
    }
    echo $output;
}
Beispiel #22
0
function processing()
{
    if (!_ADMIN) {
        echo notification(1, l('error_not_logged_in'), 'home');
    } else {
        $action = clean(cleanXSS($_GET['action']));
        $id = clean(cleanXSS($_GET['id']));
        $commentid = $_POST['commentid'];
        $approved = $_POST['approved'] == 'on' ? 'True' : '';
        $name = clean(entity($_POST['name']));
        $category = !empty($_POST['define_category']) ? $_POST['define_category'] : 0;
        $subcat = $_POST['subcat'];
        $page = $_POST['define_page'];
        $def_extra = $_POST['define_extra'];
        $description = clean(entity($_POST['description']));
        $title = clean(entity($_POST['title']));
        $seftitle = $_POST['seftitle'];
        $url = cleanXSS($_POST['url']);
        $comment = $_POST['editedcomment'];
        $text = clean($_POST['text']);
        $date = date('Y-m-d H:i:s');
        $description_meta = entity($_POST['description_meta']);
        $keywords_meta = entity($_POST['keywords_meta']);
        $display_title = $_POST['display_title'] == 'on' ? 'YES' : 'NO';
        $display_info = $_POST['display_info'] == 'on' ? 'YES' : 'NO';
        $commentable = $_POST['commentable'] == 'on' ? 'YES' : 'NO';
        $freez = $_POST['freeze'] == 'on' ? 'YES' : 'NO';
        if ($freez == 'YES' && $commentable == 'YES') {
            $commentable = 'FREEZ';
        }
        $position = $_POST['position'] > 0 ? $_POST['position'] : 1;
        if ($position == 2) {
            $position = $_POST['cat_dependant'] == 'on' ? 21 : 2;
        }
        $publish_article = $_POST['publish_article'] == 'on' ? 1 : 0;
        $show_in_subcats = $_POST['show_in_subcats'] == 'on' ? 'YES' : 'NO';
        $show_on_home = $_POST['show_on_home'] == 'on' || $position > 1 ? 'YES' : 'NO';
        $publish_category = $_POST['publish'] == 'on' ? 'YES' : 'NO';
        $fpost_enabled = false;
        if ($_POST['fposting'] == 'on') {
            $fpost_enabled = true;
            $date = $_POST['fposting_year'] . '-' . $_POST['fposting_month'] . '-' . $_POST['fposting_day'] . ' ' . $_POST['fposting_hour'] . ':' . $_POST['fposting_minute'] . ':00';
            if (date('Y-m-d H:i:s') < $date) {
                $publish_article = 2;
            }
        }
        $task = clean(cleanXSS($_GET['task']));
        switch ($task) {
            case 'save_settings':
                if (isset($_POST['save'])) {
                    $website_title = $_POST['website_title'];
                    $home_sef = $_POST['home_sef'];
                    $website_description = $_POST['website_description'];
                    $website_keywords = $_POST['website_keywords'];
                    $website_email = $_POST['website_email'];
                    $contact_subject = $_POST['contact_subject'];
                    $language = $_POST['language'];
                    $charset = $_POST['charset'];
                    $date_format = $_POST['date_format'];
                    $article_limit = $_POST['article_limit'];
                    $rss_limit = $_POST['rss_limit'];
                    $display_page = $_POST['display_page'];
                    $display_new_on_home = $_POST['display_new_on_home'];
                    $display_pagination = $_POST['display_pagination'];
                    $num_categories = $_POST['num_categories'];
                    $show_cat_names = $_POST['show_cat_names'];
                    $approve_comments = $_POST['approve_comments'];
                    $mail_on_comments = $_POST['mail_on_comments'];
                    $comments_order = $_POST['comments_order'];
                    $comment_limit = $_POST['comment_limit'];
                    $word_filter_enable = $_POST['word_filter_enable'];
                    $word_filter_file = $_POST['word_filter_file'];
                    $word_filter_change = $_POST['word_filter_change'];
                    $enable_extras = $_POST['enable_extras'] == 'on' ? 'YES' : 'NO';
                    $enable_comments = $_POST['enable_comments'] == 'on' ? 'YES' : 'NO';
                    $comment_repost_timer = is_numeric($_POST['comment_repost_timer']) ? $_POST['comment_repost_timer'] : '15';
                    $freeze_comments = $_POST['freeze_comments'] == 'on' ? 'YES' : 'NO';
                    $file_ext = $_POST['file_ext'];
                    $allowed_file = $_POST['allowed_file'];
                    $allowed_img = $_POST['allowed_img'];
                    $ufield = array('website_title' => $website_title, 'home_sef' => $home_sef, 'website_description' => $website_description, 'website_keywords' => $website_keywords, 'website_email' => $website_email, 'contact_subject' => $contact_subject, 'language' => $language, 'charset' => $charset, 'date_format' => $date_format, 'article_limit' => $article_limit, 'rss_limit' => $rss_limit, 'display_page' => $display_page, 'comments_order' => $comments_order, 'comment_limit' => $comment_limit, 'word_filter_file' => $word_filter_file, 'word_filter_change' => $word_filter_change, 'display_new_on_home' => $display_new_on_home, 'display_pagination' => $display_pagination, 'num_categories' => $num_categories, 'show_cat_names' => $show_cat_names, 'approve_comments' => $approve_comments, 'mail_on_comments' => $mail_on_comments, 'word_filter_enable' => $word_filter_enable, 'enable_extras' => $enable_extras, 'enable_comments' => $enable_comments, 'freeze_comments' => $freeze_comments, 'comment_repost_timer' => $comment_repost_timer, 'file_extensions' => $file_ext, 'allowed_files' => $allowed_file, 'allowed_images' => $allowed_img);
                    while (list($key, $value) = each($ufield)) {
                        mysql_query("UPDATE " . _PRE . 'settings' . " SET VALUE = '{$value}' WHERE name = '{$key}' LIMIT 1");
                    }
                    echo notification(0, '', 'snews_settings');
                }
                break;
            case 'changeup':
                if (isset($_POST['submit_pass'])) {
                    $user = checkUserPass($_POST['uname']);
                    $pass1 = checkUserPass($_POST['pass1']);
                    $pass2 = checkUserPass($_POST['pass2']);
                    if ($user && $pass1 && $pass2 && $pass1 === $pass2) {
                        $uname = md5($user);
                        $pass = md5($pass2);
                        $query = "UPDATE " . _PRE . 'settings' . " SET VALUE=";
                        mysql_query($query . "'{$uname}' WHERE name='username' LIMIT 1");
                        mysql_query($query . "'{$pass}' WHERE name='password' LIMIT 1");
                        echo notification(0, '', 'administration');
                    } else {
                        die(notification(2, l('pass_mismatch'), 'snews_settings'));
                    }
                }
                break;
            case 'admin_groupings':
                switch (true) {
                    case empty($name):
                        echo notification(1, l('err_TitleEmpty') . l('errNote'));
                        form_groupings();
                        break;
                    case empty($seftitle):
                        echo notification(1, l('err_SEFEmpty') . l('errNote'));
                        form_groupings();
                        break;
                    case check_if_unique('group_name', $name, $id, ''):
                        echo notification(1, l('err_TitleExists') . l('errNote'));
                        form_groupings();
                        break;
                    case check_if_unique('group_seftitle', $seftitle, $id, ''):
                        echo notification(1, l('err_SEFExists') . l('errNote'));
                        form_groupings();
                        break;
                    case cleancheckSEF($seftitle) == 'notok':
                        echo notification(1, l('err_SEFIllegal') . l('errNote'));
                        form_groupings();
                        break;
                    default:
                        switch (true) {
                            case isset($_POST['add_groupings']):
                                mysql_query("INSERT INTO " . _PRE . 'extras' . "(name, seftitle, description)\r\n\t\t\t\t\t\t\t\tVALUES('{$name}', '{$seftitle}', '{$description}')");
                                break;
                            case isset($_POST['edit_groupings']):
                                mysql_query("UPDATE " . _PRE . 'extras' . " SET\r\n\t\t\t\t\t\t\t\tname = '{$name}',\r\n\t\t\t\t\t\t\t\tseftitle = '{$seftitle}',\r\n\t\t\t\t\t\t\t\tdescription = '{$description}'\r\n\t\t\t\t\t\t\t\tWHERE id = {$id} LIMIT 1");
                                break;
                            case isset($_POST['delete_groupings']):
                                mysql_query("DELETE FROM " . _PRE . 'extras' . " WHERE id = {$id} LIMIT 1");
                                break;
                        }
                        echo notification(0, '', 'groupings');
                }
                break;
            case 'admin_category':
            case 'admin_subcategory':
                switch (true) {
                    case empty($name):
                        echo notification(1, l('err_TitleEmpty') . l('errNote'));
                        form_categories();
                        break;
                    case empty($seftitle):
                        echo notification(1, l('err_SEFEmpty') . l('errNote'));
                        form_categories();
                        break;
                    case isset($_POST['add_category']) && check_if_unique('subcat_name', $name, '', $subcat):
                        echo notification(1, l('err_TitleExists') . l('errNote'));
                        form_categories();
                        break;
                    case isset($_POST['add_category']) && check_if_unique('subcat_seftitle', $seftitle, '', $subcat):
                        echo notification(1, l('err_SEFExists') . l('errNote'));
                        form_categories();
                        break;
                    case isset($_POST['edit_category']) && $subcat == 0 && check_if_unique('cat_name_edit', $name, $id, ''):
                        echo notification(1, l('err_TitleExists') . l('errNote'));
                        form_categories();
                        break;
                    case isset($_POST['edit_category']) && $subcat == 0 && check_if_unique('cat_seftitle_edit', $seftitle, $id, ''):
                        echo notification(1, l('err_SEFExists') . l('errNote'));
                        form_categories();
                        break;
                    case isset($_POST['edit_category']) && $subcat != 0 && check_if_unique('subcat_name_edit', $name, $id, $subcat):
                        echo notification(1, l('err_TitleExists') . l('errNote'));
                        form_categories();
                        break;
                    case isset($_POST['edit_category']) && $subcat != 0 && check_if_unique('subcat_seftitle_edit', $seftitle, $id, $subcat):
                        echo notification(1, l('err_SEFExists') . l('errNote'));
                        form_categories();
                        break;
                    case cleancheckSEF($seftitle) == 'notok':
                        echo notification(1, l('err_SEFIllegal') . l('errNote'));
                        form_categories();
                        break;
                    case $subcat == $id:
                        echo notification(1, l('errNote'));
                        form_categories();
                        break;
                    default:
                        switch (true) {
                            case isset($_POST['add_category']):
                                $catorder = mysql_fetch_array(mysql_query("SELECT MAX(catorder) as max\r\n\t\t\t\t\t\t\t\tFROM " . _PRE . 'categories' . " WHERE subcat = {$subcat}"));
                                $catorder = $catorder['max'] + 1;
                                mysql_query("INSERT INTO " . _PRE . 'categories' . "\r\n\t\t\t\t\t\t\t\t(name, seftitle, description, published, catorder, subcat)\r\n\t\t\t\t\t\t\t\tVALUES('{$name}', '{$seftitle}', '{$description}', '{$publish_category}', '{$catorder}','{$subcat}')");
                                break;
                            case isset($_POST['edit_category']):
                                $catorder = mysql_fetch_array(mysql_query("SELECT MAX(catorder) as max\r\n\t\t\t\t\t\t\t\tFROM " . _PRE . 'categories' . " WHERE subcat = {$subcat}"));
                                $catorder = isset($_POST['catorder']) ? $_POST['catorder'] : $catorder['max'] + 1;
                                mysql_query("UPDATE " . _PRE . 'categories' . " SET\r\n\t\t\t\t\t\t\t\tname = '{$name}',\r\n\t\t\t\t\t\t\t\tseftitle = '{$seftitle}',\r\n\t\t\t\t\t\t\t\tdescription = '{$description}',\r\n\t\t\t\t\t\t\t\tpublished = '{$publish_category}',\r\n\t\t\t\t\t\t\t\tsubcat='{$subcat}',\r\n\t\t\t\t\t\t\t\tcatorder='{$catorder}'\r\n\t\t\t\t\t\t\t\tWHERE id = {$id} LIMIT 1");
                                break;
                            case isset($_POST['delete_category']):
                                $any_subcats = retrieve('COUNT(id)', 'categories', 'subcat', $id);
                                $any_articles = retrieve('COUNT(id)', 'articles', 'category', $id);
                                if ($any_subcats > 0 || $any_articles > 0) {
                                    echo notification(1, l('warn_catnotempty'), '');
                                    echo '<p><a href="' . _SITE . 'administration/" title="' . l('administration') . '">
									' . l('administration') . '</a>  OR  <a href="' . _SITE . '?action=process&amp;task=delete_category_all&amp;id=' . $id . '" onclick="javascript: return pop(\'x\')" title="' . l('administration') . '">
									' . l('empty_cat') . '</a></p>';
                                    $no_success = true;
                                } else {
                                    delete_cat($id);
                                }
                                break;
                        }
                        $success = isset($no_success) ? '' : notification(0, '', 'snews_categories');
                        echo $success;
                }
                break;
            case 'reorder':
                if (isset($_POST['reorder'])) {
                    switch ($_POST['order']) {
                        case 'snews_articles':
                        case 'extra_contents':
                        case 'snews_pages':
                            $table = 'articles';
                            $order_type = 'artorder';
                            $remove = 'page_';
                            break;
                        case 'snews_categories':
                            $table = 'categories';
                            $order_type = 'catorder';
                            $remove = 'cat_';
                            break;
                    }
                    foreach ($_POST as $key => $value) {
                        $type_id = str_replace($remove, '', $key);
                        $key = clean(cleanXSS(trim($value)));
                        if ($key != 'reorder' && $key != 'order' && $key != $table && $key != l('order_content') && $key != $_POST['order']) {
                            $query = "UPDATE " . _PRE . $table . " SET {$order_type} = {$value} WHERE id = {$type_id} LIMIT 1;";
                            mysql_query($query) or die(mysql_error() . '<br />' . $query);
                        }
                    }
                    echo notification(0, l('please_wait'));
                    echo '<meta http-equiv="refresh" content="1; url=' . _SITE . $_POST['order'] . '/">';
                }
                break;
            case 'admin_article':
                $_SESSION[_SITE . 'temp']['title'] = $title;
                $_SESSION[_SITE . 'temp']['seftitle'] = $seftitle;
                $_SESSION[_SITE . 'temp']['text'] = $text;
                switch (true) {
                    case empty($title):
                        echo notification(1, l('err_TitleEmpty') . l('errNote'));
                        form_articles('');
                        unset($_SESSION[_SITE . 'temp']);
                        break;
                    case empty($seftitle):
                        echo notification(1, l('err_SEFEmpty') . l('errNote'));
                        $_SESSION[_SITE . 'temp']['seftitle'] = $_SESSION[_SITE . 'temp']['title'];
                        form_articles('');
                        unset($_SESSION[_SITE . 'temp']);
                        break;
                    case cleancheckSEF($seftitle) == 'notok':
                        echo notification(1, l('err_SEFIllegal') . l('errNote'));
                        form_articles('');
                        unset($_SESSION[_SITE . 'temp']);
                        break;
                    case $position == 1 && $_POST['article_category'] != $category && isset($_POST['edit_article']) && check_if_unique('article_title', $title, $category, ''):
                        echo notification(1, l('err_TitleExists') . l('errNote'));
                        form_articles('');
                        unset($_SESSION[_SITE . 'temp']);
                        break;
                    case $position == 1 && $_POST['article_category'] != $category && isset($_POST['edit_article']) && check_if_unique('article_seftitle', $seftitle, $category, ''):
                        echo notification(1, l('err_SEFExists') . l('errNote'));
                        form_articles('');
                        unset($_SESSION[_SITE . 'temp']);
                        break;
                    case !isset($_POST['delete_article']) && !isset($_POST['edit_article']) && check_if_unique('article_title', $title, $category, ''):
                        echo notification(1, l('err_TitleExists') . l('errNote'));
                        form_articles('');
                        unset($_SESSION[_SITE . 'temp']);
                        break;
                    case !isset($_POST['delete_article']) && !isset($_POST['edit_article']) && check_if_unique('article_seftitle', $seftitle, $category, ''):
                        echo notification(1, l('err_SEFExists') . l('errNote'));
                        form_articles('');
                        unset($_SESSION[_SITE . 'temp']);
                        break;
                    default:
                        $pos = $position;
                        $sub = !empty($category) ? ' AND category = ' . $category : '';
                        $curr_artorder = retrieve('artorder', 'articles', 'id', $id);
                        if (!$curr_artorder) {
                            $artorder = 1;
                        } else {
                            $artorder = $curr_artorder;
                        }
                        switch ($pos) {
                            case 1:
                                $link = 'snews_articles';
                                break;
                            case 2:
                                $link = 'extra_contents';
                                break;
                            case 3:
                                $link = 'snews_pages';
                                break;
                        }
                        switch (true) {
                            case isset($_POST['add_article']):
                                mysql_query("INSERT INTO " . _PRE . 'articles' . "(\r\n\t\t\t\t\t\t\t\ttitle, seftitle, text, date, category,\r\n\t\t\t\t\t\t\t\tposition, extraid, page_extra, displaytitle,\r\n\t\t\t\t\t\t\t\tdisplayinfo, commentable, published, description_meta,\r\n\t\t\t\t\t\t\t\tkeywords_meta, show_on_home, show_in_subcats, artorder)\r\n\t\t\t\t\t\t\tVALUES('{$title}', '{$seftitle}', '{$text}', '{$date}', '{$category}',\r\n\t\t\t\t\t\t\t\t'{$position}', '{$def_extra}', '{$page}', '{$display_title}',\r\n\t\t\t\t\t\t\t\t'{$display_info}', '{$commentable}', '{$publish_article}',\r\n\t\t\t\t\t\t\t\t'{$description_meta}', '{$keywords_meta}', '{$show_on_home}',\r\n\t\t\t\t\t\t\t\t'{$show_in_subcats}', '{$artorder}')");
                                break;
                            case isset($_POST['edit_article']):
                                $category = $position == 3 ? 0 : $category;
                                $old_pos = retrieve('position', 'articles', 'id', $id);
                                // Only do this if page is changed to art/extra
                                if ($position != $old_pos && $old_pos == 3) {
                                    $chk_extra_query = "SELECT id FROM " . _PRE . 'articles' . "\r\n\t\t\t\t\t\t\t\t\tWHERE position = 2 AND category = -3 AND  page_extra = {$id}";
                                    $chk_extra_sql = mysql_query($chk_extra_query) or die(mysql_error('oops'));
                                    if ($chk_extra_sql) {
                                        while ($xtra = mysql_fetch_array($chk_extra_sql)) {
                                            $xtra_id = $xtra['id'];
                                            mysql_query("UPDATE " . _PRE . 'articles' . " SET\r\n\t\t\t\t\t\t\t\t\t\t\tcategory = '0', page_extra = ''\r\n\t\t\t\t\t\t\t\t\t\t\tWHERE id = {$xtra_id}");
                                        }
                                    }
                                }
                                if ($fpost_enabled == true) {
                                    $future = "date = '{$date}',";
                                    //allows backdating of article
                                    $publish_article = strtotime($date) < time() ? 1 : $publish_article;
                                }
                                mysql_query("UPDATE " . _PRE . 'articles' . " SET\r\n\t\t\t\t\t\t\t\ttitle='{$title}',\r\n\t\t\t\t\t\t\t\tseftitle = '{$seftitle}',\r\n\t\t\t\t\t\t\t\ttext = '{$text}',\r\n\t\t\t\t\t\t\t\t" . $future . "\r\n\t\t\t\t\t\t\t\tcategory = {$category},\r\n\t\t\t\t\t\t\t\tposition = {$position},\r\n\t\t\t\t\t\t\t\textraid = '{$def_extra}',\r\n\t\t\t\t\t\t\t\tpage_extra = '{$page}',\r\n\t\t\t\t\t\t\t\tdisplaytitle = '{$display_title}',\r\n\t\t\t\t\t\t\t\tdisplayinfo = '{$display_info}',\r\n\t\t\t\t\t\t\t\tcommentable = '{$commentable}',\r\n\t\t\t\t\t\t\t\tpublished = {$publish_article},\r\n\t\t\t\t\t\t\t\tdescription_meta = '{$description_meta}',\r\n\t\t\t\t\t\t\t\tkeywords_meta = '{$keywords_meta}',\r\n\t\t\t\t\t\t\t\tshow_on_home='{$show_on_home}',\r\n\t\t\t\t\t\t\t\tshow_in_subcats='{$show_in_subcats}',\r\n\t\t\t\t\t\t\t\tartorder = '{$artorder}'\r\n\t\t\t\t\t\t\t\tWHERE id = {$id} LIMIT 1") or die(mysql_error());
                                break;
                            case isset($_POST['delete_article']):
                                if ($position == 3) {
                                    $chk_extra_query = "SELECT id FROM " . _PRE . 'articles' . "\r\n\t\t\t\t\t\t\t\t\tWHERE position = 2 AND category = -3 AND  page_extra = {$id}";
                                    $chk_extra_sql = mysql_query($chk_extra_query) or die(mysql_error());
                                    if ($chk_extra_sql) {
                                        while ($xtra = mysql_fetch_array($chk_extra_sql)) {
                                            $xtra_id = $xtra['id'];
                                            mysql_query("UPDATE " . _PRE . 'articles' . " SET category = '0',page_extra = ''\tWHERE id = {$xtra_id}");
                                        }
                                    }
                                }
                                mysql_query("DELETE FROM " . _PRE . 'articles' . " WHERE id = {$id}");
                                mysql_query("DELETE FROM " . _PRE . 'comments' . " WHERE articleid = {$id}");
                                if ($id == s('display_page')) {
                                    mysql_query("UPDATE " . _PRE . 'settings' . " SET\r\n\t\t\t\t\t\t\t\t\tVALUE = 0 WHERE name = 'display_page'");
                                }
                                break;
                        }
                        echo notification(0, '', $link);
                        unset($_SESSION[_SITE . 'temp']);
                }
                break;
            case 'editcomment':
                $articleID = retrieve('articleid', 'comments', 'id', $commentid);
                $articleSEF = retrieve('seftitle', 'articles', 'id', $articleID);
                $articleCAT = retrieve('category', 'articles', 'seftitle', $articleSEF);
                $postCat = cat_rel($articleCAT, 'seftitle');
                $link = $postCat . '/' . $articleSEF;
                if (isset($_POST['submit_text'])) {
                    mysql_query("UPDATE " . _PRE . 'comments' . " SET\r\n\t\t\t\t\tname = '{$name}',\r\n\t\t\t\t\turl = '{$url}',\r\n\t\t\t\t\tcomment = '{$comment}',\r\n\t\t\t\t\tapproved = '{$approved}'\r\n\t\t\t\t\tWHERE id = {$commentid}");
                } else {
                    if (isset($_POST['delete_text'])) {
                        mysql_query("DELETE FROM " . _PRE . 'comments' . " WHERE id = {$commentid}");
                    }
                }
                echo notification(0, '', $link);
                break;
            case 'deletecomment':
                $commentid = $_GET['commentid'];
                $articleid = retrieve('articleid', 'comments', 'id', $commentid);
                $articleSEF = retrieve('seftitle', 'articles', 'id', $articleid);
                $articleCAT = retrieve('category', 'articles', 'id', $articleid);
                $postCat = cat_rel($articleCAT, 'seftitle');
                $link = $postCat . '/' . $articleSEF;
                mysql_query("DELETE FROM " . _PRE . 'comments' . " WHERE id = {$commentid}");
                echo notification(0, '', $link);
                echo '<meta http-equiv="refresh" content="1; url=' . _SITE . $postCat . '/' . $articleSEF . '/">';
                break;
            case 'delete_category_all':
                $art_query = mysql_query("SELECT id FROM " . _PRE . 'articles' . " WHERE category = {$id}");
                while ($rart = mysql_fetch_array($art_query)) {
                    mysql_query("DELETE FROM " . _PRE . 'comments' . " WHERE articleid = {$rart['id']}");
                }
                mysql_query("DELETE FROM " . _PRE . 'articles' . " WHERE category = {$id}");
                $sub_query = mysql_query("SELECT id FROM " . _PRE . 'categories' . " WHERE subcat = {$id}");
                while ($rsub = mysql_fetch_array($sub_query)) {
                    $art_query = mysql_query("SELECT id FROM " . _PRE . 'articles' . " WHERE category = {$rsub['id']}");
                    while ($rart = mysql_fetch_array($art_query)) {
                        mysql_query("DELETE FROM " . _PRE . 'comments' . " WHERE articleid = {$rart['id']}");
                    }
                    mysql_query("DELETE FROM " . _PRE . 'articles' . " WHERE category = {$rsub['id']}");
                }
                mysql_query("DELETE FROM " . _PRE . 'categories' . " WHERE subcat = {$id}");
                delete_cat($id);
                echo notification(0, '', 'snews_categories');
                break;
            case 'hide':
            case 'show':
                $id = $_GET['id'];
                $item = $_GET['item'];
                $back = $_GET['back'];
                $no_yes = $task == 'hide' ? 'NO' : 'YES';
                switch ($item) {
                    case 'snews_articles':
                        $order = 'artorder';
                        $link = empty($back) ? 'snews_articles' : $back;
                        break;
                    case 'extra_contents':
                        $order = 'artorder';
                        $link = empty($back) ? 'extra_contents' : $back;
                        break;
                    case 'snews_pages':
                        $order = 'artorder';
                        $link = empty($back) ? 'snews_pages' : $back;
                        break;
                }
                $item = 'articles';
                mysql_query("UPDATE " . _PRE . "{$item} SET visible = '{$no_yes}' WHERE id = '{$id}'");
                echo notification(0, l('please_wait'));
                echo '<meta http-equiv="refresh" content="1; url=' . _SITE . $link . '/">';
                break;
        }
    }
}
Beispiel #23
0
 protected function newCartInstance()
 {
     // create new cart instance
     $cart = entity('cart');
     $cart->save();
     return $cart;
 }
Beispiel #24
0
 public function test_delete_query()
 {
     $name = 'test_delete_query';
     $entity = entity($name);
     if ($entity->exists()) {
         $entity->uninit();
     }
     $entity->init()->create()->save();
     $entity->create()->save();
     test($entity->count() == 2, 'OK', 'ERROR');
     $entity->deleteQuery("id>=2");
     test($entity->count() == 1, 'OK', 'ERROR');
     $entity->uninit();
 }
Beispiel #25
0
 public function getReminder()
 {
     return entity('reminder');
 }
 protected function _autojoin_fields($reverse = FALSE, &$filters = array())
 {
     $id_field = $this->id_field;
     $select = '';
     $tables = $this->_autojoin_tables();
     foreach ($tables as $table) {
         $entity = entity($table);
         $fields = $this->db->list_fields($table);
         foreach ($fields as $field) {
             if (!$reverse) {
                 if ($field != $id_field) {
                     $select .= ", {$table}.{$field} AS {$entity}_{$field}";
                 }
             } elseif (is_array($filters)) {
                 if (isset($filters["{$entity}_{$field}"])) {
                     $filters["{$table}.{$field}"] = $filters["{$entity}_{$field}"];
                     unset($filters["{$entity}_{$field}"]);
                 }
             }
         }
     }
     // avoid join field name collisions
     if ($reverse && is_array($filters)) {
         foreach ($filters as $field => $filter) {
             if (strpos($field, '.') === FALSE) {
                 $filters[$this->table . '.' . $field] = $filter;
                 unset($filters[$field]);
             }
         }
     }
     return $select;
 }
Beispiel #27
0
 /**
  * @param $key
  * @return BelongsTo|BelongsToMany|HasMany|HasOne|null
  * @throws \Exception
  */
 protected function resolveRelationship($key)
 {
     $attribute = null;
     if (isset($this->config['relationships'][$key])) {
         $relationship = $this->config['relationships'][$key];
         $model = entity($relationship['entity']);
         $onEntity = snake_case($relationship['entity']);
         $thisEntity = snake_case($this->entity);
         //todo use entity local/foreign keys
         $localKey = "{$thisEntity}_id";
         $foreignKey = "{$onEntity}_id";
         switch ($relationship['type']) {
             case Relationship::HAS_PIVOT:
                 $attribute = $this->belongsToMany($model, $relationship['table'], $localKey, $foreignKey, "{$localKey}_{$foreignKey}");
                 break;
             case Relationship::HAS_MANY:
                 $attribute = $this->hasMany($model, $localKey);
                 break;
             case Relationship::HAS_ONE:
                 $attribute = $this->hasOne($model, $model->getKeyName());
                 break;
             case Relationship::BELONGS_TO:
                 $attribute = $this->belongsTo($model, $foreignKey, $model->getKeyName(), $key);
                 break;
             default:
                 throw new \Exception(sprintf("Unknown relationship type \"%s\" on entity \"%s\"", $relationship['type'], $relationship['entity']));
                 break;
         }
     }
     return $attribute;
 }
Beispiel #28
0
function entity_cache($entityType)
{
    return entity($entityType)->cacheBin();
}
Beispiel #29
0
 protected function addFk($table, array $keys)
 {
     $result = [];
     foreach ($keys as $fk) {
         $result[$table . '_' . $fk['col'] . '_foreign'] = '$table->foreign("' . $fk['col'] . '")
             ->references("' . $fk['ref_col'] . '")
             ->on("' . entity($fk['ref_table'])->getTable() . '")
             ->onDelete("cascade");';
     }
     return $result;
 }
Beispiel #30
0
 private function createDefaultTable()
 {
     $table = 'test_table';
     $entity = entity($table);
     if ($entity->exists()) {
         $entity->uninit();
     }
     $entity->init()->addColumn('name', 'varchar', 32)->addUniqueKey('name')->addColumn('address', 'varchar')->addIndex('address');
     $entity->create()->set('name', 'JaeHo Song')->set('address', 'KimHae')->save();
     $entity->create()->set('name', 'Eunsu Jung')->set('address', 'KangWonDo')->save();
     $entity->create()->set('name', 'Jack')->set('address', 'United State, Toronto.')->save();
     $entity->create()->set('name', 'Joshua')->set('address', 'United State, Toronto.')->save();
     $entity->create()->set('name', 'Jeimy')->set('address', 'United State, Toronto.')->save();
     $entity->create()->set('name', 'Nobody')->set('address', 'No Where')->save();
     $entity->create()->set('name', 'thruthesky')->set('address', 'Internet')->save();
     return $entity;
 }