get_results("SHOW TABLES", ARRAY_N);
$tables = array_map(function ($item){ return $item[0]; }, $tables);
// AUTHORS TABLE CHECK
if ( ! in_array(AHMETI_WP_AUTHORS_TABLE, $tables, true) ){
$sql = "CREATE TABLE ".AHMETI_WP_AUTHORS_TABLE." (
`author_id` mediumint unsigned NOT NULL AUTO_INCREMENT,
`author_name` varchar(255) NOT NULL,
`author_slug` varchar(255) NOT NULL,
`author_content` mediumtext NOT NULL,
PRIMARY KEY (`author_id`),
UNIQUE KEY `wp_soz_author_slug` (`author_slug`)
) ".$wpdb->get_charset_collate().";";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta($sql);
}
// QUOTES TABLE CHECK
if ( ! in_array(AHMETI_WP_QUOTES_TABLE, $tables, true) ){
$sql = "CREATE TABLE ".AHMETI_WP_QUOTES_TABLE." (
`quote_id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`quote_author_id` mediumint(8) unsigned NOT NULL,
`quote` mediumtext NOT NULL,
`quote_desc` mediumtext,
PRIMARY KEY (`quote_id`)
) ".$wpdb->get_charset_collate().";";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta($sql);
}
// CREATE SAMPLES
if ( ! in_array(AHMETI_WP_AUTHORS_TABLE, $tables, true) && ! in_array(AHMETI_WP_QUOTES_TABLE, $tables, true) ){
$wpdb->insert(AHMETI_WP_AUTHORS_TABLE, [
'author_id' => 1,
'author_name' => 'Ahmeti',
'author_slug' => 'ahmeti',
'author_content' => '',
]);
$wpdb->insert(AHMETI_WP_QUOTES_TABLE, [
'quote_id' => 1,
'quote_author_id' => 1,
'quote' => 'Hayata karşı keskin olmayın. Gün gelir "Hayatta yapmam!" dedikleriniz alışkanlıklarınıza dönüşür.',
'quote_desc' => 'Bursa sokaklarında yürürken aklıma gelmiş bir söz...',
]);
$wpdb->insert(AHMETI_WP_QUOTES_TABLE, [
'quote_id' => 2,
'quote_author_id' => 1,
'quote' => 'Bugün kendime sordum: "Çalışmak için mi yaşıyorum, yoksa yaşamak için mi çalışıyorum" diye...',
'quote_desc' => '',
]);
$wpdb->insert(AHMETI_WP_QUOTES_TABLE, [
'quote_id' => 3,
'quote_author_id' => 1,
'quote' => 'Günün sonunda kendimize şöyle bir soru sorabiliriz; "Bugün yaptıklarımızın hayatımıza ne faydası oldu."',
'quote_desc' => '',
]);
}
// Ayar Meta Var mı?
if ( get_option('ahmeti_wp_guzel_sozler') == false ){
$options = [
'author_page_name' => 'harika-sozler',
];
add_option('ahmeti_wp_guzel_sozler', serialize($options), '', true);
}
}
function ahmeti_wp_guzel_sozler_admin_head()
{
wp_register_style('AhmetiWpGuzelSozlerAdminCss', plugins_url().'/ahmeti-wp-guzel-sozler/css/style.css');
wp_enqueue_style('AhmetiWpGuzelSozlerAdminCss');
}
function ahmeti_wp_guzel_sozler_admin_menu()
{
/* Admin Menü */
add_action('admin_init', 'ahmeti_wp_guzel_sozler_admin_head' );
add_menu_page('Ahmeti Wp Güzel Sözler', 'Söz Arşivi', 'edit_pages', 'ahmeti_wp_guzel_sozler/index.php', 'ahmeti_index', plugins_url('ahmeti-wp-guzel-sozler/images/ahmeti-icon.png'), 6);
}
function ahmeti_wp_db()
{
global $wpdb;
return $wpdb;
}
function ahmeti_wp_guzel_sozler_sayfala($site_url, $top_sayfa, $page, $limit, $page_url)
{
if( $limit >= $top_sayfa){ return ''; }
echo '
Sayfalar';
$x = 5; // Aktif sayfadan önceki/sonraki sayfa gösterim sayisi
$lastP = ceil($top_sayfa / $limit);
// sayfa 1'i yazdir
if ($page==1){
echo '
1';
}else{
echo '
1';
}
// "..." veya direkt 2
if ( $page -$x > 2 ){
echo '
...';
$i = $page-$x;
}else{
$i = 2;
}
// +/- $x sayfalari yazdir
for ($i; $i <= $page + $x; $i++){
if ( $i == $page ){
echo '
'.$i.'';
}else{
echo '
'.$i.'';
}
if ( $i == $lastP ){
break;
}
}
// "..." veya son sayfa
if ( $page + $x < $lastP - 1 ){
echo '
...';
echo '
'.$lastP.'';
}elseif( $page + $x == $lastP - 1 ){
echo '
'.$lastP.'';
}
echo '
';
}
function ahmeti_wp_guzel_sozler_sef_link($link_yap)
{
$link_yap = trim($link_yap);
$link_yap = html_entity_decode($link_yap, ENT_QUOTES, 'UTF-8');
$link_yap = str_replace('Ç','c', $link_yap);
$link_yap = str_replace('ç','c', $link_yap);
$link_yap = str_replace('Ğ','g', $link_yap);
$link_yap = str_replace('ğ','g', $link_yap);
$link_yap = str_replace('I','i', $link_yap);
$link_yap = str_replace('ı','i', $link_yap);
$link_yap = str_replace('İ','i', $link_yap);
$link_yap = str_replace('Ö','o', $link_yap);
$link_yap = str_replace('ö','o', $link_yap);
$link_yap = str_replace('Ş','s', $link_yap);
$link_yap = str_replace('ş','s', $link_yap);
$link_yap = str_replace('Ü','u', $link_yap);
$link_yap = str_replace('ü','u', $link_yap);
$link_yap = str_replace(' ','-', $link_yap);
$link_yap = preg_replace("@[^A-Za-z0-9\-_]+@i","",$link_yap); // Harfler hariç tüm simgeleri kaldıralım
$link_yap = str_replace('-----','-',$link_yap);
$link_yap = str_replace('----','-',$link_yap);
$link_yap = str_replace('---','-',$link_yap);
$link_yap = str_replace('--','-', $link_yap);
$link_yap = str_replace('--','-', $link_yap);
$link_yap = strtolower($link_yap);
$link_yap = trim($link_yap,'-');
return $link_yap;
}
function ahmeti_wp_guzel_sozler_quotes($columns=[], $orderBy=['quote_id', 'DESC'], $limit = [0, 20])
{
$columns = empty($columns) ? '*' : implode(',', $columns);
global $wpdb;
return $wpdb->get_results($wpdb->prepare(
'SELECT '.$columns.' FROM '.AHMETI_WP_QUOTES_TABLE.' as quote '.
'LEFT JOIN '.AHMETI_WP_AUTHORS_TABLE.' as author ON author.author_id = quote.quote_author_id '.
'ORDER BY '.$orderBy[0].' '.$orderBy[1].' '.
'LIMIT '.$limit[0].', '.$limit[1]
, ['']));
}
function ahmeti_wp_guzel_sozler_authors($columns=[], $orderBy=['author_id', 'DESC'], $limit = [0, 20])
{
$columns = empty($columns) ? '*' : implode(',', $columns);
global $wpdb;
return $wpdb->get_results($wpdb->prepare(
'SELECT '.$columns.' FROM '.AHMETI_WP_AUTHORS_TABLE.' as author '.
'ORDER BY '.$orderBy[0].' '.$orderBy[1].' '.
'LIMIT '.$limit[0].', '.$limit[1]
, ['']));
}
function ahmeti_wp_guzel_sozler_header()
{
$logo = plugins_url('ahmeti-wp-guzel-sozler/images/icon.png');
return
'';
}
function ahmeti_wp_guzel_sozler_get_option($key)
{
$options = get_option('ahmeti_wp_guzel_sozler');
if( empty($options) ){
return null;
}
$options = unserialize($options);
if( ! array_key_exists($key, $options) ){
return null;
}
return $options[$key];
}
// Front Functions
function ahmeti_wp_guzel_sozler_shortcode()
{
$urlSegments = array_values(array_filter(explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))));
$authorSlug = ! empty($_GET['author']) ? $_GET['author'] : null;
if( $authorSlug ){
// Quotes
return ahmeti_wp_guzel_sozler_shortcode_quotes($urlSegments[0], $authorSlug);
}
// Authors
return ahmeti_wp_guzel_sozler_shortcode_authors($urlSegments[0]);
}
function ahmeti_wp_guzel_sozler_shortcode_authors($urlSegment)
{
$authors = ahmeti_wp_guzel_sozler_authors(['author_id', 'author_name', 'author_slug'], ['author_name', 'ASC'], [0, 99999]);
echo '';
}
function ahmeti_wp_guzel_sozler_shortcode_quotes($urlSegment, $authorSlug)
{
global $wpdb;
$author = $wpdb->get_row($wpdb->prepare('SELECT * FROM '.AHMETI_WP_AUTHORS_TABLE.' WHERE author_slug = %s LIMIT 0,1', [$authorSlug]));
if ( empty($author->author_id) ){
echo 'Bu kişi hakkında söz eklenmemiş.';
}else{
?>
author_content) ){
preg_match('/\[gallery.*ids=.(.*).\]/', $author->author_content, $ids);
if ( ! empty($ids) ){
$array_ids = explode(',', $ids[1]);
$i_foreach=0;
foreach($array_ids as $thumb_id){
echo ''.
'- '.
''.
'
'.
''.
' '.
'
';
$i_foreach++;
if ( $i_foreach == 3 ){
$i_foreach=0;
echo '
';
}
}
if( ! empty($thumb_id) ){
echo '
';
}
$author->author_content = str_replace($ids[0], '', $author->author_content);
$author->author_content = str_replace('', '', $author->author_content);
}
echo $author->author_content;
}
$quotes = $wpdb->get_results($wpdb->prepare('SELECT * FROM '.AHMETI_WP_QUOTES_TABLE.' WHERE quote_author_id = %d ORDER BY quote_id DESC', [$author->author_id]));
echo '';
foreach($quotes as $quote){
echo '- '.$quote->quote;
if ( ! empty($quote->quote_desc) ){
echo ' '.$quote->quote_desc.'';
}
echo'
';
}
echo '
';
echo '< Harika Sözler
';
}
}
function ahmeti_wp_guzel_sozler_random($print = false)
{
global $wpdb;
$columns = 'quote_id, author_id, author_name, author_slug, quote, quote_desc';
$quote = $wpdb->get_row($wpdb->prepare('SELECT '.$columns.' FROM '.AHMETI_WP_QUOTES_TABLE.' quote LEFT JOIN '.AHMETI_WP_AUTHORS_TABLE.' as author ON author.author_id = quote.quote_author_id ORDER BY RAND()', ['']));
$quote = (object)[
'quote_id' => isset($quote->quote_id) ? $quote->quote_id : null,
'author_id' => isset($quote->author_id) ? $quote->author_id : null,
'author_name' => isset($quote->author_name) ? $quote->author_name : null,
'author_slug' => isset($quote->author_slug) ? $quote->author_slug : null,
'quote' => isset($quote->quote) ? $quote->quote : null,
'quote_desc' => isset($quote->quote_desc) ? $quote->quote_desc : null,
];
if( $print === false ){
return $quote;
}
echo
''.
'
“'.
'
'.$quote->quote.
(empty($quote->quote_desc) ? '' : ''.$quote->quote_desc.'').
'
'.
'
'.$quote->author_name.'
'.
'
';
}