Esempio n. 1
0
 /**
  * How to display the widget on the screen.
  */
 function widget($args, $instance)
 {
     global $wpdb;
     extract($args);
     /* Our variables from the widget settings. */
     $title = apply_filters('widget_title', $instance['title']);
     $cnt = $instance['cnt'];
     /* Before widget (defined by themes). */
     echo $before_widget;
     /* Display the widget title if one was input (before and after defined by themes). */
     if ($title) {
         echo $before_title . $title . $after_title;
     }
     /* Display name from widget settings if one was input. */
     if ($cnt > 0) {
         $creds = new RP_Credentials();
         $creds->set_prefix($wpdb->prefix);
         $transaction = new RP_Transaction($creds, false);
         $rows = RP_Dao_Factory::get_rp_persona_dao($wpdb->prefix)->get_top_x_surnames($cnt);
         $rCnt = count($rows);
         if ($rCnt > 0) {
             for ($idx = 0; $idx < $rCnt; $idx++) {
                 //echo '<div style="margin-left:10px;">' . $rows[$idx]['surname'] . ' (' . $rows[$idx]['cnt'] . ')</div>';
                 echo '<div style="margin-left:10px;"><a href="' . get_home_url(null, '/?s=' . $rows[$idx]['surname'] . '&posttype=page&widget=advanced-search-widget-3') . '" rel="nofollow">' . $rows[$idx]['surname'] . '</a> (' . $rows[$idx]['cnt'] . ')</div>';
             }
         }
         $transaction->close();
     }
     /* After widget (defined by themes). */
     echo $after_widget;
 }
 /**
  * @todo Description of function Transaction
  * @param  $credentials
  * @param  $isQuery[optional]        default value : false
  * @return
  */
 public function __construct($credentials, $is_query = false)
 {
     //error_log("connection opened " . RP_Persona_Helper::trace_caller(),0);
     $this->connection = new RP_Connection($credentials);
     if (!RP_Transaction::$transactions) {
         RP_Transaction::$transactions = new RP_Array_List();
     }
     RP_Transaction::$transactions->add($this);
     if (!$is_query) {
         $this->connection->execute_query('BEGIN');
     }
 }
 /**
  * Wykonaniew zapytania do bazy
  *
  * @param sqlQuery obiekt typu SqlQuery
  * @return wynik zapytania
  */
 public static function query_for_string($sql_query, $credentials = null)
 {
     $transaction = RP_Transaction::get_current_transaction();
     if (!$transaction) {
         $connection = new RP_Connection($credentials);
     } else {
         $connection = $transaction->get_connection();
     }
     $result = $connection->execute_query($sql_query->get_query());
     if (!$result) {
         throw new Exception(is_object($GLOBALS["___mysqli_ston"]) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false));
     }
     $row = mysqli_fetch_array($result);
     return $row[0];
 }
 /**
  *
  * @param string $plugin_dir
  * @param string $version
  * @param array $options
  * @param string $prefix
  */
 function persona_upgrade($plugin_dir, $version, $options, $prefix)
 {
     global $wpdb;
     if ($options['version'] < '2.0.3') {
         unset($options['evidence_page']);
         unset($options['index_page']);
     }
     if ($options['version'] < '2.2.0') {
         $options['hide_descendancy'] = 0;
     }
     if ($options['version'] < '3.0.0') {
         $stmt = "CREATE TABLE IF NOT EXISTS rp_indi_seq (id INT NOT NULL)";
         if ($prefix != null) {
             $stmt = str_replace('rp_', $prefix . 'rp_', $stmt);
         }
         $result = $wpdb->query($stmt);
         if ($result === false) {
             $wpdb->print_error();
             throw new Exception($stmt);
         }
         $stmt = "INSERT INTO rp_indi_seq VALUES (100000)";
         if ($prefix != null) {
             $stmt = str_replace('INTO rp_', 'INTO ' . $prefix . 'rp_', $stmt);
         }
         $result = $wpdb->query($stmt);
         if ($result === false) {
             $wpdb->print_error();
             //throw new Exception( $stmt );
         }
         $stmt = "CREATE TABLE IF NOT EXISTS rp_fam_seq (id INT NOT NULL)";
         if ($prefix != null) {
             $stmt = str_replace('rp_', $prefix . 'rp_', $stmt);
         }
         $result = $wpdb->query($stmt);
         if ($result === false) {
             $wpdb->print_error();
             throw new Exception($stmt);
         }
         $stmt = "INSERT INTO rp_fam_seq VALUES (100000)";
         if ($prefix != null) {
             $stmt = str_replace('INTO rp_', 'INTO ' . $prefix . 'rp_', $stmt);
         }
         $result = $wpdb->query($stmt);
         if ($result === false) {
             $wpdb->print_error();
             //throw new Exception( $stmt );
         }
     }
     // support table recreation on activation
     try {
         $credentials = new RP_Credentials();
         $credentials->set_prefix($wpdb->prefix);
         $transaction = new RP_Transaction($credentials, true);
         RP_Dao_Factory::get_rp_persona_dao($credentials->prefix)->get_batch_ids();
         $transaction->close();
     } catch (Exception $e) {
         if (strpos($e->getMessage(), "doesn't exist") >= 0) {
             $creator = new RP_Table_Creator();
             $creator->update_tables($this->sql_file_to_create_tables, $prefix);
         } else {
             error_log($e->getMessage() . "::" . RP_Persona_Helper::trace_caller(), 0);
             throw $e;
         }
     }
     $options['version'] = $version;
     update_option('persona_plugin', $options);
 }