Ejemplo n.º 1
8
 public function query($query, $parameters = array())
 {
     if (!empty($parameters)) {
         $query = str_replace('?', '%s', $query);
         $query = $this->wpdb->prepare($query, $parameters);
     }
     return $this->wpdb->query($query);
 }
 public function launchkey_cron()
 {
     $table_name = $this->wpdb->prefix . 'launchkey_sso_sessions';
     $dt = new DateTime("- 1 hour");
     $dt->setTimezone(new DateTimeZone("UTC"));
     $this->wpdb->query($this->wpdb->prepare("DELETE FROM {$table_name} WHERE seen < %s", $dt->format("Y-m-d H:i:s")));
 }
Ejemplo n.º 3
0
function site_get_avatar($avatar, $id_or_email, $size, $default, $alt)
{
    $email = '';
    if (is_numeric($id_or_email)) {
        $id = (int) $id_or_email;
        $user = get_userdata($id);
        if ($user) {
            $email = $user->user_email;
        }
    } elseif (is_object($id_or_email)) {
        $email = $id_or_email->comment_author_email;
    }
    $forum_db = '';
    $img_folder = '';
    // No trailing slash
    $img_path = $img_folder . '/image.php?u=';
    $my_wpdb = new wpdb(DB_USER, DB_PASSWORD, $forum_db, DB_HOST);
    $myrows = $my_wpdb->get_var($my_wpdb->prepare("SELECT userid\n    FROM " . $forum_db . ".vb_user\n    WHERE email = %s LIMIT 1", array($email)));
    if ($myrows != '') {
        $img = $img_path . $myrows;
    } elseif ($avatar) {
        return $avatar;
    } else {
        $img = $default;
    }
    $my_avatar = '<img src="' . $img . '" alt="' . $alt . '" height="' . $size . '" width="' . $size . '" class="avatar avatar-50 photo grav-hashed grav-hijack" />';
    return $my_avatar;
}
Ejemplo n.º 4
0
 private static function staticInitialization()
 {
     self::$testConfig = TestConfig::createDefaultConfig();
     self::$wpAutomation = new WpAutomation(self::$testConfig->testSite, self::$testConfig->wpCliVersion);
     $yamlDir = self::$wpAutomation->getPluginsDir() . '/versionpress/.versionpress';
     $schemaFile = $yamlDir . '/schema.yml';
     $shortcodeFile = $yamlDir . '/shortcodes.yml';
     /** @var $wp_db_version */
     require self::$wpAutomation->getAbspath() . '/wp-includes/version.php';
     if (!function_exists('get_shortcode_regex')) {
         require_once self::$wpAutomation->getAbspath() . '/wp-includes/shortcodes.php';
     }
     self::$schemaInfo = new DbSchemaInfo([$schemaFile], self::$testConfig->testSite->dbTablePrefix, $wp_db_version);
     $rawTaxonomies = self::$wpAutomation->runWpCliCommand('taxonomy', 'list', ['format' => 'json', 'fields' => 'name']);
     $taxonomies = array_column(json_decode($rawTaxonomies, true), 'name');
     $dbHost = self::$testConfig->testSite->dbHost;
     $dbUser = self::$testConfig->testSite->dbUser;
     $dbPassword = self::$testConfig->testSite->dbPassword;
     $dbName = self::$testConfig->testSite->dbName;
     $dbPrefix = self::$testConfig->testSite->dbTablePrefix;
     self::$database = new \mysqli($dbHost, $dbUser, $dbPassword, $dbName);
     self::$wpdb = new \wpdb($dbUser, $dbPassword, $dbName, $dbHost);
     self::$wpdb->set_prefix($dbPrefix);
     self::$vp_database = new Database(self::$wpdb);
     $shortcodesInfo = new ShortcodesInfo([$shortcodeFile]);
     self::$vpidRepository = new VpidRepository(self::$vp_database, self::$schemaInfo);
     self::$shortcodesReplacer = new ShortcodesReplacer($shortcodesInfo, self::$vpidRepository);
     $vpdbPath = self::$wpAutomation->getVpdbDir();
     $tableSchemaRepository = new TableSchemaStorage(self::$vp_database, $vpdbPath . '/.schema');
     self::$storageFactory = new StorageFactory($vpdbPath, self::$schemaInfo, self::$vp_database, $taxonomies, null, $tableSchemaRepository);
     require self::$wpAutomation->getPluginsDir() . '/versionpress/.versionpress/hooks.php';
     self::defineGlobalVariables();
 }
Ejemplo n.º 5
0
function tgp_get_products()
{
    // Connect to the database
    $db = new wpdb(get_option('db_user'), get_option('db_pass'), get_option('db_name'), get_option('db_host'));
    // Get values
    $store_url = get_option('store_url');
    $img_folder = get_option('img_folder');
    $num_products = get_option('num_products');
    // Get Products
    $products = $db->get_results("SELECT * FROM products LIMIT " . $num_products);
    // Build Output
    $output = '';
    if ($products) {
        foreach ($products as $product) {
            $output .= '<div class="tgp_product">';
            $output .= '<h3>' . $product->title . '</h3>';
            $output .= '<img src="' . $store_url . '/' . $img_folder . '/' . $product->image . '" alt="' . $product->title . '">';
            $output .= '<div class="price">' . $product->price . '</div>';
            $output .= '<div class="desc">' . wp_trim_words($product->description, 10) . '</div>';
            $output .= '<a href="' . $store_url . 'products/details/' . $product->id . '">Buy Now</a>';
        }
    } else {
        $output .= 'No products to list';
    }
    return $output;
}
Ejemplo n.º 6
0
 function connect_s9ydb()
 {
     $s9ydb = new wpdb(get_option('s9yuser'), get_option('s9ypass'), get_option('s9yname'), get_option('s9yhost'));
     $s9ydb->set_charset($s9ydb->dbh, get_option('s9ycharset'));
     set_magic_quotes_runtime(0);
     return $s9ydb;
 }
Ejemplo n.º 7
0
 function __toString()
 {
     // if the playlist are saved to db, i load it from db
     $playlist = $this->wpdb->get_row("SELECT ID, url, playlist FROM " . $this->table_name . " WHERE url = '" . $this->url . "'");
     if ($this->wpdb->num_rows > 0) {
         $playlist = unserialize($playlist->playlist);
     } else {
         $playlist = array();
         $code = implode("", file($this->url));
         if ($code == "") {
             $this->errors->add('no_content', __('The url $url are not valid!'));
         }
         preg_match_all("/section-row-track(.+)/", $code, $results);
         for ($i = 0; $i < sizeof($results[0]); $i++) {
             preg_match("/class=\"tracklisttrackname mx-link\">(.+)<\\/a>/U", $results[0][$i], $match);
             $title = $match[1];
             preg_match("/class=\"tracklistartistname mx-link\">(.+)<\\/a>/U", $results[0][$i], $match);
             $artist = $match[1];
             if ($title != "" || $artist != "") {
                 $playlist[] = array("title" => $title, "artist" => $artist);
             }
         }
         $this->wpdb->show_errors();
         // save to db the playlist for this url
         $this->wpdb->insert($this->table_name, array("url" => $this->url, "playlist" => serialize($playlist)), array("%s", "%s"));
     }
     $code = "<h3>Playlist</h3><ul class='mixcloud-embed-playlist'>";
     for ($i = 0; $i < count($playlist); $i++) {
         $code .= "<li><span class='mixcloud-embed-position'>" . ($i + 1) . "</span>";
         $code .= "<span class='mixcloud-embed-artist'>" . $playlist[$i]["artist"] . "</span>";
         $code .= "<span class='mixcloud-embed-title'>" . $playlist[$i]["title"] . "</span></li>";
     }
     $code .= "</ul>";
     return $code;
 }
Ejemplo n.º 8
0
 protected function createChangeInfo($oldEntity, $newEntity, $action = null)
 {
     if ($action === 'edit') {
         $diff = EntityUtils::getDiff($oldEntity, $newEntity);
     }
     if (isset($diff['comment_approved'])) {
         // determine more specific edit action
         if ($oldEntity['comment_approved'] === 'trash' && $newEntity['comment_approved'] === 'post-trashed' || $oldEntity['comment_approved'] === 'post-trashed' && $newEntity['comment_approved'] === 'trash') {
             $action = 'edit';
             // trash -> post-trashed and post-trashed -> trash are not interesting action for us
         } elseif ($diff['comment_approved'] === 'trash') {
             $action = 'trash';
         } elseif ($oldEntity['comment_approved'] === 'trash') {
             $action = 'untrash';
         } elseif ($diff['comment_approved'] === 'spam') {
             $action = 'spam';
         } elseif ($oldEntity['comment_approved'] === 'spam') {
             $action = 'unspam';
         } elseif ($oldEntity['comment_approved'] == 0 && $newEntity['comment_approved'] == 1) {
             $action = 'approve';
         } elseif ($oldEntity['comment_approved'] == 1 && $newEntity['comment_approved'] == 0) {
             $action = 'unapprove';
         }
     }
     if ($action === 'create' && $newEntity['comment_approved'] == 0) {
         $action = 'create-pending';
     }
     $author = $newEntity["comment_author"];
     $postTable = $this->database->prefix . 'posts';
     $vpIdTable = $this->database->prefix . 'vp_id';
     $result = $this->database->get_row("SELECT post_title FROM {$postTable} JOIN {$vpIdTable} ON {$postTable}.ID = {$vpIdTable}.id WHERE vp_id = UNHEX('{$newEntity['vp_comment_post_ID']}')");
     $postTitle = $result->post_title;
     return new CommentChangeInfo($action, $newEntity["vp_id"], $author, $postTitle);
 }
 public function remove_db_tables()
 {
     $table = $this->wpdb->prefix . 'icl_string_pages';
     $this->wpdb->query('DROP TABLE IF EXISTS ' . $table);
     $table = $this->wpdb->prefix . 'icl_string_urls';
     $this->wpdb->query('DROP TABLE IF EXISTS ' . $table);
 }
function musicmate_get_store_products($product_cnt = 1)
{
    //Connect to the OSCommerce database
    $storedatabase = new wpdb(get_option('oscimp_dbuser'), get_option('oscimp_dbpwd'), get_option('oscimp_dbname'), get_option('oscimp_dbhost'));
    $prodVal = '';
    for ($i = 0; $i < $product_cnt; $i++) {
        //Get a random product
        $product_count = 0;
        while ($product_count == 0) {
            $product_id = rand(0, 30);
            $product_count = $storedatabase->get_var("SELECT COUNT(*) FROM products WHERE products_id={$product_id} AND products_status=1");
        }
        //Get product image, name and URL
        $product_image = $storedatabase->get_var("SELECT products_image FROM products WHERE products_id={$product_id}");
        $product_name = $storedatabase->get_var("SELECT products_name FROM products_description WHERE products_id={$product_id}");
        $store_url = get_option('oscimp_store_url');
        $image_folder = get_option('oscimp_prod_img_folder');
        //Build the HTML code
        $prodVal .= '<div class="store_product">';
        $prodVal .= '<a href="' . $store_url . 'product_info.php?products_id=' . $product_id . '"><img src="' . $image_folder . $product_image . '" /></a><br />';
        $prodVal .= '<a href="' . $store_url . 'product_info.php?products_id=' . $product_id . '">' . $product_name . '</a>';
        $prodVal .= '</div>';
    }
    return $prodVal;
}
Ejemplo n.º 11
0
function fleet_roster_handler($atts)
{
    extract(shortcode_atts(array('prefix' => ''), $atts));
    $response = '';
    if ($prefix) {
        $novadb = new wpdb('<username>', '<user password>', '<database>', '<server>');
        if ($novadb->show_errors()) {
            return $novadb->show_errors();
        }
        $response = '';
        $query = "SELECT pos_name, pos_open from " . $prefix . "_positions_sto where pos_open > 0 order by pos_dept, pos_order;";
        $rows = $novadb->get_results($query);
        if (!$novadb->num_rows) {
            return "No Positions available at this time.";
        }
        $i = 0;
        foreach ($rows as $row) {
            $response .= $row->pos_name;
            if ($row->pos_open > 1) {
                $response .= ' (' . $row->pos_open . ' open)';
            }
            $i++;
            if ($i < $novadb->num_rows) {
                $response .= ' - ';
            }
        }
        return $response;
    }
    return 'Please enter a Command Prefix Code.';
}
Ejemplo n.º 12
0
 function __construct($parent)
 {
     global $cache_db, $wpdb, $table_prefix;
     $this->advance_cache_tpl = plugin_dir_path(dirname(__FILE__)) . 'advanced_cache_tpl/advanced-cache.tpl';
     $this->regex_include_tpl = plugin_dir_path(dirname(__FILE__)) . 'advanced_cache_tpl/regex_include.tpl';
     $this->parent = $parent;
     if (defined('CACHE_DB_NAME') && defined('CACHE_DB_USER') && defined('CACHE_DB_PASSWORD') && defined('CACHE_DB_HOST')) {
         $cache_db = new wpdb(CACHE_DB_USER, CACHE_DB_PASSWORD, CACHE_DB_NAME, CACHE_DB_HOST);
         $cache_db->set_prefix($table_prefix);
     } else {
         $cache_db = $wpdb;
     }
     if (is_admin()) {
         add_action('admin_menu', array($this, 'add_setting_menu'));
         add_action('load-wp-sitemanager_page_wp-sitemanager-cache', array($this, 'update_cache_setting'));
         //		add_action( 'theme_switcher/device_updated'                , array( $this, 'clear_all_cache' ) );
         add_action('theme_switcher/device_updated', array($this, 'generate_advanced_cache_file'));
         //		add_action( 'theme_switcher/device_group_updated'          , array( $this, 'clear_all_cache' ) );
         add_action('theme_switcher/device_group_updated', array($this, 'generate_advanced_cache_file'));
         add_action('transition_post_status', array($this, 'post_publish_clear_cache'), 10, 3);
         //		add_action( 'delete_term'                                  , array( $this, 'clear_all_cache' ) );
         //		add_action( 'edited_term'                                  , array( $this, 'clear_all_cache' ) );
         //		add_action( 'deleted_user'                                 , array( $this, 'clear_all_cache' ) );
         //		add_action( 'profile_update'                               , array( $this, 'clear_all_cache' ) );
     } else {
         add_action('init', array($this, 'buffer_start'));
         //		add_action( 'template_redirect'                            , array( $this, 'check_vars' ) );
     }
     add_action('init', array($this, 'check_installed'));
     //	add_action( 'transition_comment_status'                        , array( $this, 'transition_comment_status' ), 10, 3 );
     //	add_action( 'comment_post'                                     , array( $this, 'new_comment' ), 10, 2 );
 }
Ejemplo n.º 13
0
 /**
  * Constructor
  *
  * @param  array  $tables Table names as keys, columns as value arrays
  * @param  string $from   String to find, will be escaped.
  * @param  string $replacement     String to use as replacement, will be escaped.
  * @param  wpdb   $wpdb
  */
 public function __construct(array $tables, $from, $replacement, wpdb $wpdb)
 {
     $this->tables = $tables;
     $this->from = $wpdb->_real_escape($from);
     $this->replacement = $wpdb->_real_escape($replacement);
     $this->wpdb = $wpdb;
 }
Ejemplo n.º 14
0
 /**
  *
  * Given the sql array and the search manager, this method will update the query
  *
  * @param AbstractSearch $searchManager
  * @param array $sql
  * @param \wpdb $databaseAdapter
  * @return array
  * @author Tim Perry
  */
 public function updateQuery(AbstractSearch $searchManager, array $sql, \wpdb $databaseAdapter)
 {
     if (!$searchManager->queryVarExists(self::QUERY_VAR_KEYWORDS)) {
         return $sql;
     }
     $keywords = $searchManager->getQueryVar(self::QUERY_VAR_KEYWORDS);
     if (empty($keywords)) {
         return $sql;
     }
     if ($keywordsArray = explode(" ", $keywords)) {
         $sql["select"] .= ", ";
         $sql["where"] .= " and ( ";
         foreach ($keywordsArray as $keyword) {
             $sql["select"] .= $databaseAdapter->prepare("case when p.post_title like '%%%s%%' then 5 else 0 end + ", $keyword);
             $sql["select"] .= $databaseAdapter->prepare("case when p.post_content like '%%%s%%'  then 1 else 0 end + ", $keyword);
             $sql["where"] .= $databaseAdapter->prepare("p.post_title like '%%%s%%'  or ", $keyword);
             $sql["where"] .= $databaseAdapter->prepare("p.post_content like '%%%s%%'  or ", $keyword);
         }
         $sql["where"] = rtrim($sql["where"], "or ");
         $sql["where"] .= ") ";
         $sql["select"] = rtrim($sql["select"], "+ ");
         $sql["select"] .= " as matches";
         $sql["orderby"] = "order by matches desc, post_date desc";
     }
     return $sql;
 }
Ejemplo n.º 15
0
 public function getResults($query, $parameters = array())
 {
     if (!empty($parameters)) {
         $query = str_replace('?', '%s', $query);
         $query = $this->wpdb->prepare($query, $parameters);
     }
     return $this->wpdb->get_results($query, ARRAY_A);
 }
Ejemplo n.º 16
0
 /**
  * Delete a specfic ruleset from database.
  *
  * @param int $rulesetId Primary key of the ruleset.
  * @return bool True if ruleset was deleted or false otherwise.
  */
 public function deleteRuleset($rulesetId)
 {
     if (empty($rulesetId)) {
         return false;
     }
     $deleteResult = $this->wpdb->delete($this->wpdb->rulesets, array('id' => (int) $rulesetId));
     return $deleteResult === false ? false : true;
 }
Ejemplo n.º 17
0
function getMediciByTratament($idtratament)
{
    $dbname = 'wpdemo1_medici';
    $conn = new wpdb('root', '', $dbname, 'localhost');
    $query = "select medici.nume_medic, tratamente.nume_tratament from medici inner join medici_tratamente on medici.id = medici_tratamente.id_medic inner join tratamente on tratamente.id = medici_tratamente.id_tratament where tratamente.id = " . $idtratament;
    $results = $conn->get_results($query, ARRAY_A);
    return $results;
}
Ejemplo n.º 18
0
 /**
  * Deletes all plugin terms.
  *
  * @return void
  */
 private function delete_terms()
 {
     $query = "\nSELECT term_id\nFROM {$this->wpdb->term_taxonomy}\nWHERE taxonomy = %s\nLIMIT 500";
     $query = $this->wpdb->prepare($query, $this->taxonomy);
     while ($term_ids = $this->wpdb->get_col($query)) {
         foreach ($term_ids as $term_id) {
             wp_delete_term($term_id, $this->taxonomy);
         }
     }
 }
Ejemplo n.º 19
0
 /**
  * Uninstalls all plugin data.
  *
  * @return void
  */
 public function uninstall()
 {
     if (is_multisite()) {
         foreach ($this->wpdb->get_col("SELECT blog_id FROM {$this->wpdb->blogs}") as $blog_id) {
             switch_to_blog($blog_id);
             $this->delete_options();
             restore_current_blog();
         }
     } else {
         $this->delete_options();
     }
 }
Ejemplo n.º 20
0
 /**
  *
  * Given the sql array and the search manager, this method will update the query
  *
  * @param AbstractSearch $searchManager
  * @param array $sql
  * @param \wpdb $databaseAdapter
  * @return array
  * @author Tim Perry
  */
 public function updateQuery(AbstractSearch $searchManager, array $sql, \wpdb $databaseAdapter)
 {
     if (!$searchManager->queryVarExists(self::QUERY_VAR_DATE) || !$searchManager->queryVarExists(self::QUERY_VAR_DATE_MODIFIER)) {
         return $sql;
     }
     $dateSearch = $searchManager->getQueryVar(self::QUERY_VAR_DATE);
     $dateSearchModifier = $searchManager->getQueryVar(self::QUERY_VAR_DATE_MODIFIER);
     if (!empty($dateSearch)) {
         $modifierOperand = $dateSearchModifier === self::QUERY_VAR_DATE_MODIFIER ? "<" : ">";
         $sql["where"] .= $databaseAdapter->prepare("and p.post_date " . $modifierOperand . " %s ", $dateSearch);
     }
     return $sql;
 }
 /**
  * Deletes all remote MultilingualPress nav menu items linking to the (to-be-deleted) site with the given ID.
  *
  * @param int $deleted_site_id The ID of the to-be-deleted site.
  *
  * @return void
  */
 public function delete_items_for_deleted_site($deleted_site_id)
 {
     $query = "\nSELECT blog_id\nFROM {$this->wpdb->blogs}\nWHERE blog_id != %d";
     $query = $this->wpdb->prepare($query, $deleted_site_id);
     foreach ($this->wpdb->get_col($query) as $site_id) {
         switch_to_blog($site_id);
         $query = "\nSELECT p.ID\nFROM {$this->wpdb->posts} p\nINNER JOIN {$this->wpdb->postmeta} pm\nON p.ID = pm.post_id\nWHERE pm.meta_key = %s\n\tAND pm.meta_value = %s";
         $query = $this->wpdb->prepare($query, $this->meta_key, $deleted_site_id);
         foreach ($this->wpdb->get_col($query) as $post_id) {
             wp_delete_post($post_id, true);
         }
         restore_current_blog();
     }
 }
Ejemplo n.º 22
0
 /**
  * Creates a connection and returns it
  * @return Instance of WPDB
  */
 private function createConnection()
 {
     if (!empty($this->connectionConfig)) {
         //TO DO: Use the provided connection config
         $connectionConfig = $this->connectionConfig;
         $password = $this->decryptString($connectionConfig['password']);
         $newWpdb = new wpdb($connectionConfig['user'], $password, $connectionConfig['name'], $connectionConfig['hostname']);
         $newWpdb->set_prefix($connectionConfig['base_prefix']);
         return $newWpdb;
     } else {
         global $wpdb;
         return $wpdb;
     }
 }
Ejemplo n.º 23
0
 public function tearDown()
 {
     // Remove test tables.
     $this->wpdb->query('SET FOREIGN_KEY_CHECKS = 0');
     $this->wpdb->query('DROP TABLE `test_types`');
     $this->wpdb->query('DROP TABLE `test_table`');
     $this->wpdb->query('SET FOREIGN_KEY_CHECKS = 1');
     // Uninstall
     if (!defined('WP_UNINSTALL_PLUGIN')) {
         define('WP_UNINSTALL_PLUGIN', 'tabulate/tabulate.php');
     }
     require __DIR__ . '/../uninstall.php';
     parent::tearDown();
 }
 /**
  * @param string $query
  * @param array $args
  * @param int $elements_num
  *
  * @return array
  */
 public function retrieve($query, $args, $elements_num)
 {
     $result = array();
     $offset = 0;
     while ($offset < $elements_num) {
         $new_query = $query . sprintf(' LIMIT %d OFFSET %s', $this->chunk_size, $offset);
         $new_query = $this->wpdb->prepare($new_query, $args);
         $rowset = $this->wpdb->get_results($new_query, ARRAY_A);
         if (is_array($rowset) && count($rowset)) {
             $result = array_merge($result, $rowset);
         }
         $offset += $this->chunk_size;
     }
     return $result;
 }
 public function prepare_deleteOrphanedMenuItems()
 {
     $dbHost = self::$testConfig->testSite->dbHost;
     $dbUser = self::$testConfig->testSite->dbUser;
     $dbPassword = self::$testConfig->testSite->dbPassword;
     $dbName = self::$testConfig->testSite->dbName;
     $wpdb = new \wpdb($dbUser, $dbPassword, $dbName, $dbHost);
     $wpdb->set_prefix(self::$testConfig->testSite->dbTablePrefix);
     $deleteOrphanedFilesSeconds = Reverter::DELETE_ORPHANED_POSTS_SECONDS;
     $database = new Database($wpdb);
     $database->query($wpdb->prepare("UPDATE {$database->postmeta} SET meta_value = meta_value - {$deleteOrphanedFilesSeconds} " . "WHERE meta_key='_menu_item_orphaned' ORDER BY meta_id DESC LIMIT 1", []));
     $pluginsDir = self::$wpAutomation->getPluginsDir();
     $updateConfigArgs = ['VERSIONPRESS_GUI', 'html', 'require' => $pluginsDir . '/versionpress/src/Cli/vp-internal.php'];
     self::$wpAutomation->runWpCliCommand('vp-internal', 'update-config', $updateConfigArgs);
 }
Ejemplo n.º 26
0
 /**
  * Uninstalls all plugin data.
  *
  * @return void
  */
 public function uninstall()
 {
     $option_name = $this->option->get_name();
     if (is_multisite()) {
         foreach ($this->wpdb->get_col("SELECT blog_id FROM {$this->wpdb->blogs}") as $blog_id) {
             switch_to_blog($blog_id);
             delete_option($this->version_option_name);
             delete_option($option_name);
         }
         restore_current_blog();
     } else {
         delete_option($this->version_option_name);
         delete_option($option_name);
     }
 }
 /**
  * @param string   $cms_id
  * @param bool|TranslationProxy_Service $translation_service
  *
  * @return int|null translation id for the given cms_id's target
  */
 public function get_translation_id($cms_id, $translation_service = false)
 {
     list($post_type, $element_id, , $target_lang) = $this->parse_cms_id($cms_id);
     $translation = $this->wpdb->get_row($this->wpdb->prepare("\n\t\t\t\t\t\t\t\t\t\t\t\t\tSELECT t.translation_id, j.job_id, t.element_id\n\t\t\t\t\t\t\t\t\t\t\t\t\tFROM {$this->wpdb->prefix}icl_translations t\n\t\t\t\t\t\t\t\t\t\t\t\t\tJOIN {$this->wpdb->prefix}icl_translations o\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tON o.trid = t.trid\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND o.element_type = t.element_type\n\t\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN {$this->wpdb->prefix}icl_translation_status st\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tON st.translation_id = t.translation_id\n\t\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN {$this->wpdb->prefix}icl_translate_job j\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tON j.rid = st.rid\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE o.element_id=%d\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND t.language_code=%s\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND o.element_type LIKE %s\n\t\t\t\t\t\t\t\t\t\t\t\t\tLIMIT 1", $element_id, $target_lang, '%_' . $post_type));
     $translation_id = $this->maybe_cleanup_broken_row($translation, $translation_service);
     if ($translation_service && !isset($translation_id) && $translation_service) {
         $job_id = $this->job_factory->create_local_post_job($element_id, $target_lang);
         $job = $this->job_factory->get_translation_job($job_id, false, false, true);
         $translation_id = $job ? $job->get_translation_id() : 0;
         if ($translation_id) {
             $this->tm_records->icl_translation_status_by_translation_id($translation_id)->update(array('status' => ICL_TM_IN_PROGRESS, 'translation_service' => $translation_service->id));
         }
     }
     return $translation_id;
 }
Ejemplo n.º 28
0
function create_client($subdomain, $client_name, $client_username, $client_email, $client_password)
{
    if ($db = create_db($subdomain) !== false) {
        try {
            $con = new wpdb(MYSQL_ROUTING_USER, MYSQL_ROUTING_PASSWORD, MYSQL_ROUTING_DB, MYSQL_ROUTING_HOST);
            $result = $con->insert('client', array('subdomain' => $subdomain, 'email' => $client_email, 'name' => $client_name, 'admin_username' => $client_username, 'admin_password' => base64_encode($client_password), 'status' => 0, 'db_driver' => 'mysql', 'db_host' => 'localhost', 'db_name' => $db["db_name"], 'db_user' => $db["db_user"], 'db_pass' => $db["db_pass"], 'db_charset' => 'utf8', 'db_collation' => 'utf8_unicode_ci', 'db_prefix' => '', 'created_at' => date("Y-m-d H:i:s")), array('%s', '%s', '%s', '%s', '%s', '%d', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s'));
            if ($result) {
                return true;
            }
        } catch (Exception $e) {
            return false;
        }
    }
    return false;
}
 private function persist()
 {
     foreach (array_chunk($this->data, self::INSERT_CHUNK_SIZE) as $chunk) {
         $query = "INSERT IGNORE INTO {$this->wpdb->prefix}icl_strings " . '(`language`, `context`, `gettext_context`, `domain_name_context_md5`, `name`, `value`, `status`) VALUES ';
         $i = 0;
         foreach ($chunk as $string) {
             if ($i > 0) {
                 $query .= ',';
             }
             $query .= $this->wpdb->prepare("('%s', '%s', '%s', '%s', '%s', '%s', %d)", $this->get_source_lang($string['name'], $string['domain']), $string['domain'], $string['gettext_context'], md5($string['domain'] . $string['name'] . $string['gettext_context']), $string['name'], $string['value'], ICL_TM_NOT_TRANSLATED);
             $i++;
         }
         $this->wpdb->query($query);
     }
 }
Ejemplo n.º 30
-1
 /**
  * Get a list of tables that the current user can read.
  * @return string[] The table names.
  */
 public function get_table_names()
 {
     if (!$this->table_names) {
         $this->table_names = array();
         foreach ($this->wpdb->get_col('SHOW TABLES') as $table_name) {
             if (Grants::current_user_can(Grants::READ, $table_name)) {
                 $this->table_names[] = $table_name;
             }
         }
     }
     return $this->table_names;
 }