Exemple #1
0
function wpdf_editor_ajax_action_function()
{
    $modules = $_POST["modules"];
    if (get_magic_quotes_gpc()) {
        $keyword = stripslashes($_POST['keyword']);
    } else {
        $keyword = $_POST["keyword"];
    }
    $nonce = $_POST["wpnonce"];
    if (!wp_verify_nonce($nonce, 'wpdf_security_nonce')) {
        echo json_encode(array("error" => "Invalid request."));
        exit;
    }
    if (empty($modules)) {
        echo json_encode(array("error" => "No content source found."));
        exit;
    }
    if (empty($keyword)) {
        echo json_encode(array("error" => "Keyword is empty."));
        exit;
    }
    global $source_infos, $modulearray;
    @(require_once "api.class.php");
    $options = get_option("wpinject_settings");
    $items_per_req = $options["general"]["options"]["items_per_req"]["value"];
    if (empty($items_per_req)) {
        $items_per_req = 30;
    }
    $marray = array();
    foreach ($modules as $module) {
        $mn = $module["name"];
        $modulerun = $module["module_run"];
        $start = 1 + ($modulerun - 1) * $items_per_req;
        $marray[$mn] = array("count" => $items_per_req, "start" => $start);
    }
    $api = new wpdf_API_request();
    //$result = $api->api_content_bulk($keyword, array($module => array("count" => $items_per_req, "start" => $start)));
    $result = $api->api_content_bulk($keyword, $marray);
    if (is_array($result)) {
        foreach ($modules as $module) {
            $mn = $module["name"];
            $result[$mn]["modulerun"] = $module["module_run"];
        }
        echo json_encode(array("result" => $result));
        exit;
    } else {
        echo json_encode(array("error" => "Content search failed"));
        exit;
    }
}
Exemple #2
0
function wpdf_settings_page()
{
    global $source_infos, $modulearray;
    $options = $modulearray;
    $optionsarray = get_option("wpinject_settings");
    if ($_GET["test"] == 1) {
        @(require_once "api.class.php");
        $api = new wpdf_API_request();
        $result = $api->api_content_bulk("fun", array("pixabay" => array("count" => 120, "start" => 1)));
        //print_r($result);
    }
    if ($_POST["save_options"]) {
        foreach ($options as $module => $moduledata) {
            if ($optionsarray[$module]["enabled"] != 2) {
                $optionsarray[$module]["enabled"] = $_POST[$module . "_enabled"];
                if (empty($_POST[$module . "_enabled"])) {
                    $optionsarray[$module]["enabled"] = 0;
                }
                if ($optionsarray[$module]["enabled"] == 1 && empty($optionsarray[$module]["options"])) {
                    $optionsarray[$module] = $options[$module];
                    $optionsarray[$module]["enabled"] = 1;
                }
            }
            if ($optionsarray[$module]["enabled"] == 1 || $optionsarray[$module]["enabled"] == 2) {
                foreach ($moduledata["options"] as $option => $data) {
                    if ($option == "img_template" || $option == "attr_template" || $option == "attr_template_multi") {
                        $_POST[$module . "_" . $option] = stripslashes($_POST[$module . "_" . $option]);
                        if ($option == "attr_template" && (strpos($_POST[$module . "_" . $option], "{link}") === false || strpos($_POST[$module . "_" . $option], "{author}") === false)) {
                            echo '<div class="error"><p><strong>WARNING: </strong> The Attribution Template setting has to contain the {link} and {author} tag with a proper link back to the owner or you will be <strong>in violation of the license</strong> of Flickr photos you insert!</p></div>';
                        }
                    }
                    $optionsarray[$module]["options"][$option]["value"] = $_POST[$module . "_" . $option];
                }
            }
        }
        $result = update_option("wpinject_settings", $optionsarray);
        if ($result) {
            echo '<div class="updated"><p>Options have been updated.</p></div>';
        } else {
            echo '<div class="error"><p>Error: Options could not be updated.</p></div>';
        }
    }
    if (!empty($_POST) && empty($_POST["save_options"])) {
        // VERIFICATION FUNCTION
        foreach ($options as $module => $moduledata) {
            if ($_POST[$module . "_verify"]) {
                @(require_once "api.class.php");
                $api = new wpdf_API_request();
                $result = $api->api_content_bulk("camera", array($module => 1));
                if (empty($result[$module]["error"]) && isset($result[$module][0]["content"])) {
                    if ($module == "amazon") {
                        $options[$module]["options"]["public_key"]["verified"] = 1;
                    } else {
                        $optionsarray[$module]["options"]["appid"]["verified"] = 1;
                    }
                    update_option("wpinject_settings", $optionsarray);
                    echo '<div class="updated"><p>' . $moduledata["name"] . ' has been verified and is working!</p></div>';
                } else {
                    echo '<div class="error"><p>' . $result[$module]["error"] . '</p></div>';
                }
            }
        }
    }
    ?>

<div class="wrap">

	<h2><?php 
    _e("ImageInject Settings", "wpinject");
    ?>
</h2>
	
	<div style="width:28%;float: right;">		
		<div class="wpdf_settings_box">
			<p style="margin-top: 0;">To <strong>insert images</strong> go to the WordPress "<a href="post-new.php">New Post</a>" or "<a href="post-new.php?post_type=page">New Page</a>" screens where you will find the ImageInject metabox to search for great photos!</p>
			
			<p>Please <a href="http://wpscoop.com/wp-inject/#docs" target="_blank"><strong>read my short ImageInject tutorial</strong></a> for more details on all the settings on this page and what exactly they do.</p>
		
			<p>Having problems or found a bug? Please <a href="http://wpscoop.com/contact" target="_blank">contact me</a> or post in the WordPress support forum.</p>

		</div>	
		
		<div class="wpdf_settings_box">		
			<p style="text-align: center;margin: 0;">If you find ImageInject useful <strong>please share!</strong><br/>
				<a title="Share ImageInject on Twitter" target="_blank" class="wpdf_share_twitter" href="https://twitter.com/home?status=This%20%23WordPress%20plugin%20by%20@wpscoop%20makes%20finding%20and%20inserting%20free%20photos%20into%20my%20blog%20posts%20super%20easy:%20http://wpscoop.com/wp-inject"></a>
				<a title="Share ImageInject on Facebook" target="_blank" class="wpdf_share_fb" href="https://www.facebook.com/sharer/sharer.php?u=http://wpscoop.com/wp-inject/"></a>
				<a title="Share ImageInject on Google+" target="_blank" class="wpdf_share_google" href="https://plus.google.com/share?url=http://wpscoop.com/wp-inject/"></a>
			</p>		
		</div>				
	
		<div class="wpdf_settings_box">
			<p style="margin-top: 0;"><strong>Multiple WordPress Sites? No Problem!</strong></p><p>Discover <a href="http://cmscommander.com/" target="_blank">CMS Commander</a> - the best way to manage multiple WordPress sites from a single dashboard. Try it for free now and see how much time you can save!
		</div>	
	
		<div class="wpdf_settings_box">
			<a title="Visit WPscoop!" target="_blank" href="http://wpscoop.com/"><img src="<?php 
    echo plugins_url('', __FILE__);
    ?>
/images/WPscoop-logo.png" alt="WPscoop logo" /></a>	
			<p>Check out <a target="_blank" title="Visit WPscoop!" href="http://wpscoop.com/"><strong>WPscoop.com</strong></a> where I blog about WordPress and publish my free plugins.</p>
		
		</div>		
		
		<div class="wpdf_settings_box">
			<p><strong>Image Sources in ImageInject</strong><br>Click for more information:</p>
			
			<p><a href="http://flickr.com/" target="_blank"><strong>Flickr</strong></a>, the popular photo uploading service by Yahoo, contains more than 200 million creative commons images.</p>
			
			<p><a href="http://pixabay.com/" target="_blank"><strong>Pixabay</strong></a> is a directory for high quality public domain images. They offer more than 150,000 great photos for you to use.</p>
		</div>
	</div>	
	
	<form method="post" name="wpdf_options">	
	<div style="width:71%;">

	<p class="submit"><input class="button-primary" type="submit" name="save_options" value="<?php 
    _e("Save All Settings", "wpinject");
    ?>
" /></p>		

	<?php 
    $num = 0;
    foreach ($options as $module => $moduledata) {
        $num++;
        ?>

		<?php 
        if ($moduledata["enabled"] == 2) {
            ?>
		<h3><?php 
            echo $moduledata["name"];
            ?>
</h3>
		<?php 
        } else {
            ?>
		<h3><input checked style="margin-right: 5px; margin-top: -2px;display:none;" onclick="toggle('#<?php 
            echo $module;
            ?>
', this)" class="button" type="checkbox" id="<?php 
            echo $module . "_enabled";
            ?>
" name="<?php 
            echo $module . "_enabled";
            ?>
" value="1" <?php 
            if (1 == $optionsarray[$module]["enabled"]) {
                echo "checked";
            }
            ?>
/><label for="<?php 
            echo $module . "_enabled";
            ?>
"><?php 
            echo $moduledata["name"];
            ?>
 <?php 
            _e("Settings", "wpinject");
            ?>
</label></h3>
		<?php 
        }
        ?>
		
		<div id="<?php 
        echo $module;
        ?>
">	

		<?php 
        if (empty($moduledata["options"])) {
            ?>
			<p><?php 
            _e("No settings required for this content source. To edit its templates go to the Templates page.", "wpinject");
            ?>
</p>
		<?php 
        } else {
            ?>
		<table class="form-table" style="clear: none !important;">
			<tbody>				
		
				<?php 
            foreach ($moduledata["options"] as $option => $data) {
                if ($option != "title" && $option != "unique" && $option != "error" && $option != "unique_direct" && $option != "title_direct") {
                    if (!empty($optionsarray[$module]["options"][$option]["value"])) {
                        $value = $optionsarray[$module]["options"][$option]["value"];
                    } else {
                        $value = $data["value"];
                    }
                    if ($data["type"] == "checkbox" && empty($optionsarray[$module]["options"][$option]["value"]) && !empty($optionsarray[$module]["options"])) {
                        $value = "";
                    }
                    if ($data["type"] == "text") {
                        // Text Option
                        if ($data["display"] == "none") {
                            $dnon = 'style = "display: none;"';
                        } else {
                            $dnon = "";
                        }
                        ?>
 
							<tr <?php 
                        echo $dnon;
                        ?>
>
								<th scope="row"><label for="<?php 
                        echo $module . "_" . $option;
                        ?>
"><?php 
                        echo $data["name"];
                        ?>
</label></th>
								<td><input class="regular-text" type="text" name="<?php 
                        echo $module . "_" . $option;
                        ?>
" value="<?php 
                        echo $value;
                        ?>
" />
									<!-- VERIFICATION BUTTON DISPLAY -->
									<?php 
                        if ($optionsarray[$module]["options"][$option]["verified"] === 0) {
                            ?>
										<input class="button" type="submit" name="<?php 
                            echo $module . "_verify";
                            ?>
" value="<?php 
                            _e("Verify", "wpinject");
                            ?>
" <?php 
                            if (empty($value)) {
                                echo "disabled";
                            }
                            ?>
 />
										<?php 
                            if (!empty($source_infos["sources"][$module]["signup"])) {
                                ?>
<a href="<?php 
                                echo $source_infos["sources"][$module]["signup"];
                                ?>
" target="_blank">Sign Up</a><?php 
                            }
                            ?>
									<?php 
                        } elseif ($optionsarray[$module]["options"][$option]["verified"] === 1) {
                            ?>
										<?php 
                            echo '<img style="margin-bottom: -3px;" src="' . WP_PLUGIN_URL . '/' . basename(dirname(__FILE__)) . '/images/check.png" /> Verified';
                            ?>
									<?php 
                        }
                        ?>

								</td>	
							</tr>
						<?php 
                    } elseif ($data["type"] == "select") {
                        // Select Option
                        ?>
							<tr>	
								<th scope="row"><label for="<?php 
                        echo $module . "_" . $option;
                        ?>
"><?php 
                        echo $data["name"];
                        ?>
</label></th>
								<td><select name="<?php 
                        echo $module . "_" . $option;
                        ?>
">
									<?php 
                        foreach ($data["values"] as $val => $name) {
                            ?>
									<option value="<?php 
                            echo $val;
                            ?>
" <?php 
                            if ($val == $value) {
                                echo "selected";
                            }
                            ?>
><?php 
                            echo $name;
                            ?>
</option>
									<?php 
                        }
                        ?>
		
								</select></td>	
							</tr>
						<?php 
                    } elseif ($data["type"] == "checkbox") {
                        // checkbox Option
                        ?>
		
							<tr>	
								<th scope="row"><label for="<?php 
                        echo $module . "_" . $option;
                        ?>
"><?php 
                        echo $data["name"];
                        ?>
</label></th>
								<td><input class="button" type="checkbox" id="<?php 
                        echo $module . "_" . $option;
                        ?>
_s" name="<?php 
                        echo $module . "_" . $option;
                        ?>
" value="1" <?php 
                        if (1 == $value) {
                            echo "checked";
                        }
                        ?>
/> <label for="<?php 
                        echo $module . "_" . $option;
                        ?>
_s" style="padding-top: 7px;"><?php 
                        echo $data["info"];
                        ?>
<label>

								</td>	
							</tr>									
						<?php 
                    } elseif ($data["type"] == "textarea") {
                        // textarea Option
                        ?>
		
							<tr>	
								<th scope="row"><label for="<?php 
                        echo $module . "_" . $option;
                        ?>
"><?php 
                        echo $data["name"];
                        ?>
</label></th>
								
								<td>
								<textarea cols="60" rows="1" name="<?php 
                        echo $module . "_" . $option;
                        ?>
"><?php 
                        echo $value;
                        ?>
</textarea>
								</td>	
							</tr>									
						<?php 
                    }
                    ?>
	
						
					<?php 
                }
                ?>
				<?php 
            }
            ?>
		
			</tbody>
		</table>					
		<?php 
        }
        ?>
		</div>	
	<?php 
    }
    ?>
	

	</div>
	
	<p class="submit"><input class="button-primary" type="submit" name="save_options" value="<?php 
    _e("Save All Settings", "wpinject");
    ?>
" /></p>	

	</form>	
	
	<h3>Available Template Tags</h3>
	<p>You can use the following tags in the "<strong>Image Template</strong>" setting field:</p>
	<p>
		<strong>{keyword}</strong> - The keyword you searched for with ImageInject.<br/>
		<strong>{yoast-keyword}</strong> - Inserts the "Focus Keyword" as set in the WordPress SEO by Yoast plugin for the post.<br/>	
		<strong>{title}</strong> - The title of the image on Flickr.<br/>
		<strong>{description}</strong> -  The description of the image on Flickr<br/>
		<strong>{author}</strong> - Flickr name or username of the author.<br/>
		<strong>{link}</strong> - Link to the image page on Flickr<br/>
		<strong>{src}</strong> - The image file in the specified size<br/>
	</p>
	<p>The following tags are available in the "<strong>Attribution Template</strong>" field:</p>	
	<p>
		<strong>{keyword}</strong> - The keyword you searched for with ImageInject.<br/>
		<strong>{author}</strong> - Flickr name or username of the author.<br/>
		<strong>{link}</strong> - Link to the image page on Flickr<br/>
		<strong>{cc_icon}</strong> - A small creative commons icon with a link to the license<br/>
		<strong>{license_name}</strong> - The name of the creative commons license the photo uses<br/>
		<strong>{license_link}</strong> - The link to the creative commons license the photo uses<br/>
	</p>
	<p>The following tags are available in the "<strong>Filename Template</strong>" field:</p>	
	<p>
		<strong>{filename}</strong> - The original filename.<br/>
		<strong>{keyword}</strong> - The keyword you searched for.<br/>
		<strong>{timestamp}</strong> - Timestamp of when the image was uploaded to your blog.<br/>
		<strong>{date}</strong> - Date of when the image was uploaded to your blog.<br/>		
		<strong>{rand}</strong> - A random number.<br/>
	</p>	
<?php 
}