Ejemplo n.º 1
0
 public static function activate()
 {
     if (!current_user_can('activate_plugins')) {
         return;
     }
     $plugin = isset($_REQUEST['plugin']) ? $_REQUEST['plugin'] : '';
     check_admin_referer('activate-plugin_' . $plugin);
     Quotes_Collection_DB::install_db();
 }
 public function do_shortcode($atts = array())
 {
     $db = new Quotes_Collection_DB();
     extract(shortcode_atts(array('limit' => 0, 'id' => 0, 'author' => '', 'source' => '', 'tags' => '', 'orderby' => 'quote_id', 'order' => 'ASC', 'paging' => false, 'limit_per_page' => 10), $atts));
     // Initialize the variable that holds args to be passed to the DB function to get the quotes
     // And set 'public' argument to 'yes', because we don't want to display private quotes in public
     $db_args = array('public' => 'yes');
     // 'quote_id' is also a valid shortcode parameter synonymous to 'id'
     if (isset($quote_id) && is_numeric($quote_id)) {
         $id = $quote_id;
     }
     // If an id is specified, no need to process other attributes. Simply get the quote and return.
     if ($id && is_numeric($id)) {
         $db_args['quote_id'] = $id;
         if ($quote = Quotes_Collection_Quote::with_condition($db_args)) {
             return $quote->output_format();
         } else {
             return "";
         }
     }
     if ($author) {
         $db_args['author'] = $author;
     }
     if ($source) {
         $db_args['source'] = $source;
     }
     if ($tags) {
         $db_args['tags'] = $tags;
     }
     switch ($orderby) {
         case 'quote_id':
         case 'author':
         case 'source':
         case 'time_added':
         case 'random':
             $db_args['orderby'] = $orderby;
             break;
         case 'date_added':
             $db_args['orderby'] = 'time_added';
             break;
         case 'rand':
             $db_args['orderby'] = 'random';
             break;
         default:
             $db_args['orderby'] = 'quote_id';
     }
     if ($order == 'DESC' || $order == 'desc' || $order == 'Desc') {
         $db_args['order'] = 'DESC';
     } else {
         $db_args['order'] = 'ASC';
     }
     $page_nav = "";
     if ($paging == true || $paging == 1) {
         $num_quotes = $db->count($db_args);
         $total_pages = ceil($num_quotes / $limit_per_page);
         if (!isset($_GET['quotes_page']) || !$_GET['quotes_page'] || !is_numeric($_GET['quotes_page'])) {
             $page = 1;
         } else {
             $page = $_GET['quotes_page'];
         }
         if ($page > $total_pages) {
             $page = $total_pages;
         }
         if ($page_nav = $this->pagenav($total_pages, $page, 0, 'quotes_page')) {
             $page_nav = '<div class="quotescollection_pagenav">' . $page_nav . '</div>';
         }
         $start = ($page - 1) * $limit_per_page;
         $db_args['num_quotes'] = $limit_per_page;
         $db_args['start'] = $start;
     } else {
         if ($limit && is_numeric($limit)) {
             $db_args['num_quotes'] = $limit;
         }
     }
     if ($quotes_data = $db->get_quotes($db_args)) {
         return $page_nav . $this->output_format($quotes_data) . $page_nav;
     } else {
         return "";
     }
 }